Skip to content

Commit

Permalink
Changed logic to send closed game states rather thant new game list
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamin-lawson committed Sep 11, 2024
1 parent 6fa0ee7 commit 0913092
Showing 1 changed file with 46 additions and 14 deletions.
60 changes: 46 additions & 14 deletions server/lobbyconnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,15 +316,6 @@ async def send_game_list(self):
]
})

async def send_game_list_to_player(self, player: Player):
await player.send_message({
"command": "game_info",
"games": [
game.to_dict() for game in self.game_service.open_games
if game.is_visible_to_player(player)
]
})

async def command_social_remove(self, message):
if "friend" in message:
subject_id = message["friend"]
Expand All @@ -345,9 +336,30 @@ async def command_social_remove(self, message):
with contextlib.suppress(KeyError):
player_attr.remove(subject_id)

if self.player.game is None:
return

subject_player = self.player_service.get_player(int(subject_id))
with contextlib.suppress(DisconnectedError):
self.send_game_list_to_player(subject_player)
game_info = self.player.game.to_dict()

if "foe" in message:
with contextlib.suppress(DisconnectedError):
await subject_player.send_message({
"command": "game_info",
"games": [
game_info
]
})

if "friend" in message and self.player.game.visibility == VisibilityState.FRIENDS:
with contextlib.suppress(DisconnectedError):
game_info["state"] = "closed"
await subject_player.send_message({
"command": "game_info",
"games": [
game_info
]
})

async def command_social_add(self, message):
if "friend" in message:
Expand All @@ -371,11 +383,31 @@ async def command_social_add(self, message):
subject_id=subject_id,
))

player_attr.add(subject_id)
if self.player.game is None:
return

player_attr.add(subject_id)
subject_player = self.player_service.get_player(int(subject_id))
with contextlib.suppress(DisconnectedError):
self.send_game_list_to_player(subject_player)

game_info = self.player.game.to_dict()
if "foe" in message:
game_info['state'] = 'closed'

Check warning on line 394 in server/lobbyconnection.py

View workflow job for this annotation

GitHub Actions / flake8

Single quotes found but double quotes preferred

Check warning on line 394 in server/lobbyconnection.py

View workflow job for this annotation

GitHub Actions / flake8

Single quotes found but double quotes preferred
with contextlib.suppress(DisconnectedError):
await subject_player.send_message({
"command": "game_info",
"games": [
game_info
]
})

if "friend" in message and self.player.game.visibility == VisibilityState.FRIENDS:
with contextlib.suppress(DisconnectedError):
await subject_player.send_message({
"command": "game_info",
"games": [
game_info
]
})

async def kick(self):
await self.send({
Expand Down

0 comments on commit 0913092

Please sign in to comment.