diff --git a/server/lobbyconnection.py b/server/lobbyconnection.py index 6cd4c5392..bf85eff14 100644 --- a/server/lobbyconnection.py +++ b/server/lobbyconnection.py @@ -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"] @@ -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: @@ -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' + 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({