From 6fa0ee7edcf0bff565f9f09a6134e13149a861a0 Mon Sep 17 00:00:00 2001 From: benjamin-lawson Date: Fri, 6 Sep 2024 10:55:05 -0400 Subject: [PATCH 1/2] Fix issue where players added or removed from friend or foe lists did not have games updated --- .pre-commit-config.yaml | 8 ++++---- server/lobbyconnection.py | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 793f83142..7bd9dff9f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,19 +1,19 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.0.1 + rev: v4.6.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer - id: check-docstring-first - repo: https://github.com/PyCQA/flake8 - rev: 3.9.2 + rev: 7.1.1 hooks: - id: flake8 - repo: https://github.com/pre-commit/mirrors-autopep8 - rev: v1.5.7 + rev: v2.0.4 hooks: - id: autopep8 - repo: https://github.com/PyCQA/isort - rev: 5.9.3 + rev: 5.13.2 hooks: - id: isort diff --git a/server/lobbyconnection.py b/server/lobbyconnection.py index c50c10964..6cd4c5392 100644 --- a/server/lobbyconnection.py +++ b/server/lobbyconnection.py @@ -316,6 +316,15 @@ 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"] @@ -336,6 +345,10 @@ async def command_social_remove(self, message): with contextlib.suppress(KeyError): player_attr.remove(subject_id) + subject_player = self.player_service.get_player(int(subject_id)) + with contextlib.suppress(DisconnectedError): + self.send_game_list_to_player(subject_player) + async def command_social_add(self, message): if "friend" in message: status = "FRIEND" @@ -360,6 +373,10 @@ async def command_social_add(self, message): 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) + async def kick(self): await self.send({ "command": "notice", From 09130928c4c6a03ac3a41440f3838713ea194f06 Mon Sep 17 00:00:00 2001 From: benjamin-lawson Date: Wed, 11 Sep 2024 10:28:21 -0400 Subject: [PATCH 2/2] Changed logic to send closed game states rather thant new game list --- server/lobbyconnection.py | 60 ++++++++++++++++++++++++++++++--------- 1 file changed, 46 insertions(+), 14 deletions(-) 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({