From 8c8ae655088e029f3864251c46459d09399badee Mon Sep 17 00:00:00 2001 From: Askaholic Date: Wed, 27 Dec 2023 19:48:09 +0000 Subject: [PATCH] deploy: d0152dabf38388cd711a21a9ec5e204965cf9a65 --- index.html | 8 ++- player_service.html | 11 ++- players.html | 170 ++++++++++++++++++++++---------------------- 3 files changed, 102 insertions(+), 87 deletions(-) diff --git a/index.html b/index.html index 935ed5c3f..cad1d5d9f 100644 --- a/index.html +++ b/index.html @@ -6294,8 +6294,11 @@

Inherited members

def remove_player(self, player: Player): if player.id in self._players: + # This signals that the player is now disconnected + del player.lobby_connection del self._players[player.id] metrics.players_online.set(len(self._players)) + self.mark_dirty(player) async def has_permission_role(self, player: Player, role_name: str) -> bool: async with self._db.acquire() as conn: @@ -6589,8 +6592,11 @@

Methods

def remove_player(self, player: Player):
     if player.id in self._players:
+        # This signals that the player is now disconnected
+        del player.lobby_connection
         del self._players[player.id]
-        metrics.players_online.set(len(self._players))
+ metrics.players_online.set(len(self._players)) + self.mark_dirty(player)
diff --git a/player_service.html b/player_service.html index 3d153f404..0d236fd24 100644 --- a/player_service.html +++ b/player_service.html @@ -177,8 +177,11 @@

Module server.player_service

def remove_player(self, player: Player): if player.id in self._players: + # This signals that the player is now disconnected + del player.lobby_connection del self._players[player.id] metrics.players_online.set(len(self._players)) + self.mark_dirty(player) async def has_permission_role(self, player: Player, role_name: str) -> bool: async with self._db.acquire() as conn: @@ -407,8 +410,11 @@

Classes

def remove_player(self, player: Player): if player.id in self._players: + # This signals that the player is now disconnected + del player.lobby_connection del self._players[player.id] metrics.players_online.set(len(self._players)) + self.mark_dirty(player) async def has_permission_role(self, player: Player, role_name: str) -> bool: async with self._db.acquire() as conn: @@ -702,8 +708,11 @@

Methods

def remove_player(self, player: Player):
     if player.id in self._players:
+        # This signals that the player is now disconnected
+        del player.lobby_connection
         del self._players[player.id]
-        metrics.players_online.set(len(self._players))
+ metrics.players_online.set(len(self._players)) + self.mark_dirty(player)
diff --git a/players.html b/players.html index 2d15dedde..29eb0358e 100644 --- a/players.html +++ b/players.html @@ -159,37 +159,37 @@

Module server.players

with suppress(DisconnectedError): self.lobby_connection.write(message) - def to_dict(self): + def to_dict(self) -> dict: """ Return a dictionary representing this player object """ - - def filter_none(t): - _, v = t - return v is not None - - return dict( - filter( - filter_none, ( - ("id", self.id), - ("login", self.login), - ("avatar", self.avatar), - ("country", self.country), - ("clan", self.clan), - ("ratings", { - rating_type: { - "rating": self.ratings[rating_type], - "number_of_games": self.game_count[rating_type] - } - for rating_type in self.ratings - }), - # Deprecated - ("global_rating", self.ratings[RatingType.GLOBAL]), - ("ladder_rating", self.ratings[RatingType.LADDER_1V1]), - ("number_of_games", self.game_count[RatingType.GLOBAL]), - ) - ) - ) + assert self.state is not None and self.state.value is not None + + cmd = { + "id": self.id, + "login": self.login, + "avatar": self.avatar, + "country": self.country, + "clan": self.clan, + # NOTE: We are only sending an 'offline' state for now to signal to + # the client when a player disconnects. However, this could be + # expanded in the future to expose more of the internal state + # tracking to the client to make the UI for showing players in game + # more correct. + "state": None if self.lobby_connection else "offline", + "ratings": { + rating_type: { + "rating": self.ratings[rating_type], + "number_of_games": self.game_count[rating_type] + } + for rating_type in self.ratings + }, + # DEPRECATED: Use ratings instead + "global_rating": self.ratings[RatingType.GLOBAL], + "ladder_rating": self.ratings[RatingType.LADDER_1V1], + "number_of_games": self.game_count[RatingType.GLOBAL], + } + return {k: v for k, v in cmd.items() if v is not None} def __str__(self) -> str: return (f"Player({self.login}, {self.id}, " @@ -330,37 +330,37 @@

Classes

with suppress(DisconnectedError): self.lobby_connection.write(message) - def to_dict(self): + def to_dict(self) -> dict: """ Return a dictionary representing this player object """ - - def filter_none(t): - _, v = t - return v is not None - - return dict( - filter( - filter_none, ( - ("id", self.id), - ("login", self.login), - ("avatar", self.avatar), - ("country", self.country), - ("clan", self.clan), - ("ratings", { - rating_type: { - "rating": self.ratings[rating_type], - "number_of_games": self.game_count[rating_type] - } - for rating_type in self.ratings - }), - # Deprecated - ("global_rating", self.ratings[RatingType.GLOBAL]), - ("ladder_rating", self.ratings[RatingType.LADDER_1V1]), - ("number_of_games", self.game_count[RatingType.GLOBAL]), - ) - ) - ) + assert self.state is not None and self.state.value is not None + + cmd = { + "id": self.id, + "login": self.login, + "avatar": self.avatar, + "country": self.country, + "clan": self.clan, + # NOTE: We are only sending an 'offline' state for now to signal to + # the client when a player disconnects. However, this could be + # expanded in the future to expose more of the internal state + # tracking to the client to make the UI for showing players in game + # more correct. + "state": None if self.lobby_connection else "offline", + "ratings": { + rating_type: { + "rating": self.ratings[rating_type], + "number_of_games": self.game_count[rating_type] + } + for rating_type in self.ratings + }, + # DEPRECATED: Use ratings instead + "global_rating": self.ratings[RatingType.GLOBAL], + "ladder_rating": self.ratings[RatingType.LADDER_1V1], + "number_of_games": self.game_count[RatingType.GLOBAL], + } + return {k: v for k, v in cmd.items() if v is not None} def __str__(self) -> str: return (f"Player({self.login}, {self.id}, " @@ -509,7 +509,7 @@

Errors

-def to_dict(self) +def to_dict(self) ‑> dict

Return a dictionary representing this player object

@@ -517,37 +517,37 @@

Errors

Expand source code -
def to_dict(self):
+
def to_dict(self) -> dict:
     """
     Return a dictionary representing this player object
     """
-
-    def filter_none(t):
-        _, v = t
-        return v is not None
-
-    return dict(
-        filter(
-            filter_none, (
-                ("id", self.id),
-                ("login", self.login),
-                ("avatar", self.avatar),
-                ("country", self.country),
-                ("clan", self.clan),
-                ("ratings", {
-                    rating_type: {
-                        "rating": self.ratings[rating_type],
-                        "number_of_games": self.game_count[rating_type]
-                    }
-                    for rating_type in self.ratings
-                }),
-                # Deprecated
-                ("global_rating", self.ratings[RatingType.GLOBAL]),
-                ("ladder_rating", self.ratings[RatingType.LADDER_1V1]),
-                ("number_of_games", self.game_count[RatingType.GLOBAL]),
-            )
-        )
-    )
+ assert self.state is not None and self.state.value is not None + + cmd = { + "id": self.id, + "login": self.login, + "avatar": self.avatar, + "country": self.country, + "clan": self.clan, + # NOTE: We are only sending an 'offline' state for now to signal to + # the client when a player disconnects. However, this could be + # expanded in the future to expose more of the internal state + # tracking to the client to make the UI for showing players in game + # more correct. + "state": None if self.lobby_connection else "offline", + "ratings": { + rating_type: { + "rating": self.ratings[rating_type], + "number_of_games": self.game_count[rating_type] + } + for rating_type in self.ratings + }, + # DEPRECATED: Use ratings instead + "global_rating": self.ratings[RatingType.GLOBAL], + "ladder_rating": self.ratings[RatingType.LADDER_1V1], + "number_of_games": self.game_count[RatingType.GLOBAL], + } + return {k: v for k, v in cmd.items() if v is not None}