diff --git a/server/lobbyconnection.py b/server/lobbyconnection.py index 825efd15d..84e29c124 100644 --- a/server/lobbyconnection.py +++ b/server/lobbyconnection.py @@ -840,13 +840,25 @@ async def launch_game(self, game, is_host=False, use_map=None): self.player.game = game cmd = { "command": "game_launch", - "mod": game.game_mode, + "args": ["/numgames", self.player.game_count[RatingType.GLOBAL]], "uid": game.id, - "args": ["/numgames " + str(self.player.game_count[RatingType.GLOBAL])] + "mod": game.game_mode, + "mapname": use_map, + # Following parameters are not used by the client yet. They are + # needed for setting up auto-lobby style matches such as ladder, gw, + # and team machmaking where the server decides what these game + # options are. Currently, options for ladder are hardcoded into the + # client. + "name": game.name, + "team": game.get_player_option(self.player, "Team"), + "faction": game.get_player_option(self.player, "Faction"), + "expected_players": len(game.players) or None, + "map_position": game.get_player_option(self.player, "StartSpot"), + "init_mode": game.init_mode.value, } - if use_map: - cmd['mapname'] = use_map - await self.send(cmd) + + # Remove args with None value + await self.send({k: v for k, v in cmd.items() if v is not None}) async def command_modvault(self, message): type = message["type"] diff --git a/server/protocol/gpgnet.py b/server/protocol/gpgnet.py index 41af9ccc5..31b71b76a 100644 --- a/server/protocol/gpgnet.py +++ b/server/protocol/gpgnet.py @@ -22,12 +22,12 @@ async def send_JoinGame(self, remote_player_name: str, remote_player_uid: int): """ await self.send_gpgnet_message('JoinGame', [remote_player_name, remote_player_uid]) - async def send_HostGame(self, map): + async def send_HostGame(self, map_path): """ Tells the game to start listening for incoming connections as a host - :param map: Which scenario to use + :param map_path: Which scenario to use """ - await self.send_gpgnet_message('HostGame', [str(map)]) + await self.send_gpgnet_message('HostGame', [str(map_path)]) async def send_DisconnectFromPeer(self, id: int): """ @@ -38,7 +38,7 @@ async def send_DisconnectFromPeer(self, id: int): """ await self.send_gpgnet_message('DisconnectFromPeer', [id]) - async def send_gpgnet_message(self, command_id, arguments): + async def send_gpgnet_message(self, command_id: str, arguments: List[Union[int, str, bool]]): message = {"command": command_id, "args": arguments} await self.send_message(message) diff --git a/tests/unit_tests/test_lobbyconnection.py b/tests/unit_tests/test_lobbyconnection.py index 56a8db93a..165ac284f 100644 --- a/tests/unit_tests/test_lobbyconnection.py +++ b/tests/unit_tests/test_lobbyconnection.py @@ -7,6 +7,7 @@ from aiohttp import web from asynctest import CoroutineMock from server import GameState, VisibilityState +from server.abc.base_game import InitMode from server.db.models import ban, friends_and_foes from server.game_service import GameService from server.gameconnection import GameConnection @@ -242,11 +243,12 @@ async def test_command_game_join_calls_join_game(mocker, players, game_stats_service): lobbyconnection.game_service = game_service - game = mock.create_autospec(Game(42, database, game_service, game_stats_service)) + game = Game(42, database, game_service, game_stats_service) game.state = GameState.LOBBY game.password = None game.game_mode = 'faf' game.id = 42 + game.name = "Test Game Name" game_service.games[42] = game lobbyconnection.player = players.hosting test_game_info['uid'] = 42 @@ -256,10 +258,12 @@ async def test_command_game_join_calls_join_game(mocker, **test_game_info }) expected_reply = { - 'command': 'game_launch', - 'mod': 'faf', - 'uid': 42, - 'args': ['/numgames {}'.format(players.hosting.game_count[RatingType.GLOBAL])] + "command": "game_launch", + "args": ["/numgames", players.hosting.game_count[RatingType.GLOBAL]], + "uid": 42, + "mod": "faf", + "name": "Test Game Name", + "init_mode": InitMode.NORMAL_LOBBY.value, } lobbyconnection.protocol.send_message.assert_called_with(expected_reply) @@ -272,11 +276,12 @@ async def test_command_game_join_uid_as_str(mocker, players, game_stats_service): lobbyconnection.game_service = game_service - game = mock.create_autospec(Game(42, database, game_service, game_stats_service)) + game = Game(42, database, game_service, game_stats_service) game.state = GameState.LOBBY game.password = None game.game_mode = 'faf' game.id = 42 + game.name = "Test Game Name" game_service.games[42] = game lobbyconnection.player = players.hosting test_game_info['uid'] = '42' # Pass in uid as string @@ -287,9 +292,11 @@ async def test_command_game_join_uid_as_str(mocker, }) expected_reply = { 'command': 'game_launch', + 'args': ['/numgames', players.hosting.game_count[RatingType.GLOBAL]], 'mod': 'faf', 'uid': 42, - 'args': ['/numgames {}'.format(players.hosting.game_count[RatingType.GLOBAL])] + 'name': 'Test Game Name', + 'init_mode': InitMode.NORMAL_LOBBY.value, } lobbyconnection.protocol.send_message.assert_called_with(expected_reply)