Skip to content

Commit

Permalink
feat(messaging): game join failed command
Browse files Browse the repository at this point in the history
 * When player fails to join a game, instead of "notice", a new "game_join_failed" event is being sent, so the consumer can programmatically handle the exceptional behaviour
  • Loading branch information
Ivan-Shaml committed Feb 9, 2025
1 parent 5244d42 commit fa72e8a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
15 changes: 9 additions & 6 deletions server/lobbyconnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -965,9 +965,10 @@ async def command_game_join(self, message):
game = self.game_service[uuid]
except KeyError:
await self.send({
"command": "notice",
"command": "game_join_failed",
"style": "info",
"text": "The host has left the game."
"text": "The host has left the game.",
"uid": uuid
})
return

Expand All @@ -977,9 +978,10 @@ async def command_game_join(self, message):
if not game or game.state is not GameState.LOBBY:
self._logger.debug("Game not in lobby state: %s state %s", game, game.state)
await self.send({
"command": "notice",
"command": "game_join_failed",
"style": "info",
"text": "The game you are trying to join is not ready."
"text": "The game you are trying to join is not ready.",
"uid": uuid
})
return

Expand All @@ -988,9 +990,10 @@ async def command_game_join(self, message):

if game.password != password:
await self.send({
"command": "notice",
"command": "game_join_failed",
"style": "info",
"text": "Bad password (it's case sensitive)."
"text": "Bad password (it's case sensitive).",
"uid": uuid
})
return

Expand Down
15 changes: 9 additions & 6 deletions tests/unit_tests/test_lobbyconnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,9 +416,10 @@ async def test_command_game_join_without_password(
**test_game_info
})
lobbyconnection.send.assert_called_once_with({
"command": "notice",
"command": "game_join_failed",
"style": "info",
"text": "Bad password (it's case sensitive)."
"text": "Bad password (it's case sensitive).",
"uid": 42
})


Expand All @@ -439,9 +440,10 @@ async def test_command_game_join_game_not_found(
**test_game_info
})
lobbyconnection.send.assert_called_once_with({
"command": "notice",
"command": "game_join_failed",
"style": "info",
"text": "The host has left the game."
"text": "The host has left the game.",
"uid": 42
})


Expand All @@ -468,9 +470,10 @@ async def test_command_game_join_game_bad_init_mode(
**test_game_info
})
lobbyconnection.send.assert_called_once_with({

Check failure on line 472 in tests/unit_tests/test_lobbyconnection.py

View workflow job for this annotation

GitHub Actions / unit-test

test_command_game_join_game_bad_init_mode AssertionError: expected call not found. Expected: mock({'command': 'game_join_failed', 'style': 'error', 'text': 'The game cannot be joined in this way.', 'uid': 42}) Actual: mock({'command': 'notice', 'style': 'error', 'text': 'The game cannot be joined in this way.'}) pytest introspection follows: Args: assert ({'command': ... this way.'},) == ({'command': ..., 'uid': 42},) At index 0 diff: {'command': 'notice', 'style': 'error', 'text': 'The game cannot be joined in this way.'} != {'command': 'game_join_failed', 'style': 'error', 'text': 'The game cannot be joined in this way.', 'uid': 42} Full diff: ( { - 'command': 'game_join_failed', + 'command': 'notice', 'style': 'error', 'text': 'The game cannot be joined in this way.', - 'uid': 42, }, )
"command": "notice",
"command": "game_join_failed",
"style": "error",
"text": "The game cannot be joined in this way."
"text": "The game cannot be joined in this way.",
"uid": 42
})


Expand Down

0 comments on commit fa72e8a

Please sign in to comment.