client: now displays when clients leave the lobby
This commit is contained in:
+8
-3
@@ -104,13 +104,15 @@ class LobbyManager:
|
||||
|
||||
def leave_lobby(self, lobby_id, client_id) -> None:
|
||||
try:
|
||||
# get client name BEFORE deleting the client...
|
||||
client_name = self.get_client_name(lobby_id, client_id)
|
||||
del self.active_lobbies[lobby_id].connected_clients[client_id]
|
||||
self.broadcast_message(
|
||||
lobby_id,
|
||||
json.dumps({
|
||||
"response": "leave_lobby",
|
||||
"response": "client_left_lobby",
|
||||
"status": "ok",
|
||||
"client_id": client_id,
|
||||
"client_name": client_name,
|
||||
}),
|
||||
)
|
||||
if self.get_lobby_player_count(lobby_id) == 0:
|
||||
@@ -121,6 +123,9 @@ class LobbyManager:
|
||||
|
||||
def get_lobby_player_count(self, lobby_id) -> int:
|
||||
return len(self.active_lobbies[lobby_id].connected_clients)
|
||||
|
||||
def get_client_name(self, lobby_id, client_id) -> str:
|
||||
return self.active_lobbies[lobby_id].connected_clients[client_id].client_name
|
||||
|
||||
def get_lobby_host_client_id(self, lobby_id) -> str:
|
||||
return self.active_lobbies[lobby_id].host_client_id
|
||||
@@ -247,7 +252,7 @@ class ClientConnection:
|
||||
json.dumps({
|
||||
"response": "receive_chat_message",
|
||||
"message": data_object["message"],
|
||||
"client_name": self.lobby_manager.active_lobbies[data_object["lobby_id"]].connected_clients[data_object["client_id"]].client_name,
|
||||
"client_name": self.lobby_manager.get_client_name(data_object["lobby_id"], data_object["client_id"]),
|
||||
})
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user