95 lines
3.6 KiB
Python
95 lines
3.6 KiB
Python
"""Source-level contract for the production clientless player reset command."""
|
|
from pathlib import Path
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[2]
|
|
COMMANDS = (ROOT / "src/server/scripts/Custom/viano_bot_commands.cpp").read_text()
|
|
BEHAVIOR = (ROOT / "src/server/game/World/AdventureBehaviorMgr.cpp").read_text()
|
|
HEADER = (ROOT / "src/server/game/World/AdventureBehaviorMgr.h").read_text()
|
|
|
|
|
|
def section(source: str, start: str, end: str) -> str:
|
|
begin = source.index(start)
|
|
return source[begin:source.index(end, begin)]
|
|
|
|
|
|
def test_command_contract_supports_guid_and_all():
|
|
command = section(
|
|
COMMANDS,
|
|
"static bool HandleClientlessPlayerReset(",
|
|
"static bool HandleClientlessLogout(",
|
|
)
|
|
assert 'argument == "all"' in command
|
|
assert "GetAllClientlessSessions()" in command
|
|
assert "FindClientlessSession(guid)" in command
|
|
assert "sClientlessPlayerMgr->IsManaged" in command
|
|
assert "sAdventureBehaviorMgr->ResetPlayer(player, detail)" in command
|
|
assert '{ "reset", rbac::RBAC_PERM_COMMAND_GM' in COMMANDS
|
|
assert '{ "player", rbac::RBAC_PERM_COMMAND_GM' in COMMANDS
|
|
|
|
|
|
def test_reset_validates_capital_before_mutating_player():
|
|
reset = section(
|
|
BEHAVIOR,
|
|
"bool AdventureBehaviorMgr::ResetPlayer(",
|
|
"void AdventureBehaviorMgr::Offline(",
|
|
)
|
|
validation = reset.index("AdventureGroupPolicy::Capital")
|
|
first_mutation = reset.index("FinishInstance(player, record->second)")
|
|
assert validation < first_mutation
|
|
assert '"Stormwind" : "Orgrimmar"' in reset
|
|
assert "AllowsPosition(player, city->mapId, destination)" in reset
|
|
assert "GetStaticHeight" in reset
|
|
|
|
|
|
def test_reset_clears_transient_owners_and_restarts_behavior():
|
|
reset = section(
|
|
BEHAVIOR,
|
|
"bool AdventureBehaviorMgr::ResetPlayer(",
|
|
"void AdventureBehaviorMgr::Offline(",
|
|
)
|
|
required = [
|
|
"ClearQueuedActions(guid)",
|
|
"sClientlessActionExecutorMgr->Clear(guid)",
|
|
"sClientlessFlightMgr->Clear(guid)",
|
|
"sAdventureGroupTravelMgr->Clear(player)",
|
|
"sClientlessTravelMgr->CancelTravel(guid)",
|
|
"sClientlessTransportMgr->Cancel(guid, player)",
|
|
"sAdventureSupplyMgr->Offline(player)",
|
|
"sAdventureCombatMgr->Offline(player)",
|
|
"sAdventureInteractionMgr->Offline(player)",
|
|
"ClientlessTravelTelemetry::Clear(player)",
|
|
"_records.erase(guid)",
|
|
"Online(player)",
|
|
"sAdventureSupplyMgr->Online(player)",
|
|
]
|
|
for operation in required:
|
|
assert operation in reset
|
|
assert reset.index("_records.erase(guid)") < reset.index("Online(player)")
|
|
|
|
|
|
def test_reset_restores_native_player_state_and_persists_it():
|
|
reset = section(
|
|
BEHAVIOR,
|
|
"bool AdventureBehaviorMgr::ResetPlayer(",
|
|
"void AdventureBehaviorMgr::Offline(",
|
|
)
|
|
assert "CombatStop(true)" in reset
|
|
assert "ResurrectPlayer(1.0f, false)" in reset
|
|
assert "SpawnCorpseBones()" in reset
|
|
assert "CleanupAfterTaxiFlight()" in reset
|
|
assert "TeleportTo(city->mapId" in reset
|
|
assert "SetStandState(UNIT_STAND_STATE_STAND)" in reset
|
|
assert "SetFullHealth()" in reset
|
|
assert "SetFullPower(POWER_MANA)" in reset
|
|
assert "SaveToDB()" in reset
|
|
assert "bool ResetPlayer(Player* player, std::string& detail);" in HEADER
|
|
|
|
|
|
if __name__ == "__main__":
|
|
test_command_contract_supports_guid_and_all()
|
|
test_reset_validates_capital_before_mutating_player()
|
|
test_reset_clears_transient_owners_and_restarts_behavior()
|
|
test_reset_restores_native_player_state_and_persists_it()
|
|
print("Clientless player reset command and full-state cleanup contract PASS")
|