Skip to content

Commit

Permalink
Make sure game_info messages are sent when GameOptions change
Browse files Browse the repository at this point in the history
  • Loading branch information
Askaholic committed Dec 29, 2023
1 parent 0e20b6c commit 36907fa
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 14 deletions.
3 changes: 2 additions & 1 deletion server/gameconnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ async def handle_game_option(self, key: str, value: Any):
elif key == "Title":
with contextlib.suppress(ValueError):
self.game.name = value
self._mark_dirty()

self._mark_dirty()

async def handle_game_mods(self, mode: Any, args: list[Any]):
if not self.is_host():
Expand Down
67 changes: 54 additions & 13 deletions tests/integration_tests/test_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,52 @@ async def send_player_options(proto, *options):
})


async def send_game_options(proto, *options):
for option in options:
await proto.send_message({
"target": "game",
"command": "GameOption",
"args": list(option)
})


@fast_forward(20)
async def test_game_info_message_updates(lobby_server):
_, _, proto = await connect_and_sign_in(
("test", "test_password"), lobby_server
)
game_id = await host_game(proto)
await read_until_command(proto, "game_info", uid=game_id, timeout=5)

await send_game_options(proto, ["Title", "Test GameOptions"])
msg = await read_until_command(proto, "game_info", uid=game_id, timeout=5)
assert msg["title"] == "Test GameOptions"

await send_game_options(proto, ["Slots", "7"])
msg = await read_until_command(proto, "game_info", uid=game_id, timeout=5)
assert msg["max_players"] == 7

await send_game_options(proto, ["ScenarioFile", "/maps/foobar/scenario.lua"])
msg = await read_until_command(proto, "game_info", uid=game_id, timeout=5)
assert msg["mapname"] == "foobar"
assert msg["map_file_path"] == "maps/foobar.zip"

await send_game_options(proto, ["RestrictedCategories", "1"])
msg = await read_until_command(proto, "game_info", uid=game_id, timeout=5)
assert "bad_unit_restrictions" in msg["validity"]

await send_game_options(proto, ["Unranked", "Yes"])
msg = await read_until_command(proto, "game_info", uid=game_id, timeout=5)
assert "host_set_unranked" in msg["validity"]

await send_game_options(proto, ["Victory", "eradication"])
msg = await read_until_command(proto, "game_info", uid=game_id, timeout=5)
assert "wrong_victory_condition" in msg["validity"]

# TODO: Some options don't need to trigger game info updates. Pruning these
# could help with performance and reduce network bandwidth


@fast_forward(20)
async def test_game_validity_states(lobby_server):
host_id, _, host_proto = await connect_and_sign_in(
Expand All @@ -283,14 +329,10 @@ async def test_game_validity_states(lobby_server):
assert msg["validity"] == ["uneven_teams_not_ranked", "single_player"]

# Change the map to an unranked map
await host_proto.send_message({
"target": "game",
"command": "GameOption",
"args": [
"ScenarioFile",
"/maps/neroxis_map_generator_sneaky_map/sneaky_map_scenario.lua"
]
})
await send_game_options(host_proto, [
"ScenarioFile",
"/maps/neroxis_map_generator_sneaky_map/sneaky_map_scenario.lua"
])
msg = await read_until_command(host_proto, "game_info", uid=game_id, timeout=5)
assert msg["validity"] == [
"bad_map",
Expand All @@ -305,11 +347,10 @@ async def test_game_validity_states(lobby_server):
assert msg["validity"] == ["bad_map"]

# Change the map to a ranked map
await host_proto.send_message({
"target": "game",
"command": "GameOption",
"args": ["ScenarioFile", "/maps/scmp_001/scmp_001_scenario.lua"]
})
await send_game_options(host_proto, [
"ScenarioFile",
"/maps/scmp_001/scmp_001_scenario.lua"
])

msg = await read_until_command(host_proto, "game_info", uid=game_id, timeout=5)
assert msg["validity"] == ["valid"]
Expand Down

0 comments on commit 36907fa

Please sign in to comment.