From b2cd0841552aa6157d646a02fcc3dec8dafaffa7 Mon Sep 17 00:00:00 2001 From: BlackYps Date: Mon, 13 Sep 2021 15:12:48 +0200 Subject: [PATCH 1/2] Serialize faction as string in game launch message --- server/ladder_service.py | 2 +- server/types.py | 2 +- tests/integration_tests/test_matchmaker.py | 2 +- tests/integration_tests/test_teammatchmaker.py | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/server/ladder_service.py b/server/ladder_service.py index a89714e3b..a56a6f680 100644 --- a/server/ladder_service.py +++ b/server/ladder_service.py @@ -442,7 +442,7 @@ def get_player_mean(player): def game_options(player: Player) -> GameLaunchOptions: return options._replace( team=game.get_player_option(player.id, "Team"), - faction=player.faction, + faction=player.faction.name, map_position=game.get_player_option(player.id, "StartSpot") ) diff --git a/server/types.py b/server/types.py index 75136505f..5106d6f03 100644 --- a/server/types.py +++ b/server/types.py @@ -24,7 +24,7 @@ class GameLaunchOptions(NamedTuple): mapname: Optional[str] = None team: Optional[int] = None - faction: Optional[int] = None + faction: Optional[str] = None expected_players: Optional[int] = None map_position: Optional[int] = None diff --git a/tests/integration_tests/test_matchmaker.py b/tests/integration_tests/test_matchmaker.py index ffddc2edc..0b9a8c4ac 100644 --- a/tests/integration_tests/test_matchmaker.py +++ b/tests/integration_tests/test_matchmaker.py @@ -37,7 +37,7 @@ async def test_game_launch_message(lobby_server): assert msg1["mapname"] == msg2["mapname"] assert msg1["team"] == 2 assert msg2["team"] == 3 - assert msg1["faction"] == msg2["faction"] == 1 # faction 1 is uef + assert msg1["faction"] == msg2["faction"] == "uef" assert msg1["expected_players"] == msg2["expected_players"] == 2 assert msg1["map_position"] == 1 assert msg2["map_position"] == 2 diff --git a/tests/integration_tests/test_teammatchmaker.py b/tests/integration_tests/test_teammatchmaker.py index 62f297081..ef8a4e8ef 100644 --- a/tests/integration_tests/test_teammatchmaker.py +++ b/tests/integration_tests/test_teammatchmaker.py @@ -98,7 +98,7 @@ async def test_game_matchmaking(lobby_server): assert msg["expected_players"] == 4 assert msg["team"] in (2, 3) assert msg["map_position"] in (1, 2, 3, 4) - assert msg["faction"] == 1 + assert msg["faction"] == "uef" @fast_forward(15) @@ -143,7 +143,7 @@ async def test_game_matchmaking_multiqueue(lobby_server): assert msg["expected_players"] == 4 assert msg["team"] in (2, 3) assert msg["map_position"] in (1, 2, 3, 4) - assert msg["faction"] == 2 + assert msg["faction"] == "aeon" @fast_forward(10) @@ -221,7 +221,7 @@ async def test_game_matchmaking_with_parties(lobby_server): assert msg["expected_players"] == 4 assert msg["team"] in (2, 3) assert msg["map_position"] in (1, 2, 3, 4) - assert msg["faction"] == i + 1 + assert msg["faction"] == "uef" if i == 0 else "aeon" if i == 1 else "cybran" if i == 2 else "seraphim" @fast_forward(30) From 7411a0ae340072e3d725914e0a28efff45820d30 Mon Sep 17 00:00:00 2001 From: BlackYps Date: Wed, 15 Sep 2021 23:43:57 +0200 Subject: [PATCH 2/2] Fix test --- tests/integration_tests/test_teammatchmaker.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/integration_tests/test_teammatchmaker.py b/tests/integration_tests/test_teammatchmaker.py index ef8a4e8ef..e960e8f4d 100644 --- a/tests/integration_tests/test_teammatchmaker.py +++ b/tests/integration_tests/test_teammatchmaker.py @@ -9,6 +9,7 @@ leaderboard_rating, leaderboard_rating_journal ) +from server.factions import Faction from tests.utils import fast_forward from .conftest import connect_and_sign_in, read_until, read_until_command @@ -470,7 +471,7 @@ async def test_game_ratings(lobby_server): proto, [player_id, "Army", slot], [player_id, "Color", slot], - [player_id, "Faction", msg["faction"]], + [player_id, "Faction", Faction.from_string(msg["faction"])], [player_id, "StartSpot", slot], [player_id, "Team", msg["team"]], )