Skip to content

Commit

Permalink
Send game configuration options to the client in game_launch (#517)
Browse files Browse the repository at this point in the history
* Send game configuration options to the client in game_launch

* Add comment
  • Loading branch information
Askaholic authored Jan 25, 2020
1 parent 4c92fae commit e9edac2
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 16 deletions.
22 changes: 17 additions & 5 deletions server/lobbyconnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
8 changes: 4 additions & 4 deletions server/protocol/gpgnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand All @@ -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)

Expand Down
21 changes: 14 additions & 7 deletions tests/unit_tests/test_lobbyconnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)

Expand All @@ -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
Expand All @@ -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)

Expand Down

0 comments on commit e9edac2

Please sign in to comment.