chat messages are now sent and relayed. server: handling host client leaving correctly
This commit is contained in:
@@ -227,6 +227,7 @@ class ClientConnection:
|
||||
# client is host; close lobby
|
||||
lobby_clients = self.lobby_manager.get_lobby(lobby_id).connected_clients.copy()
|
||||
# for client_id in lobby_clients:
|
||||
self.lobby_manager.leave_lobby(lobby_id, data_object["client_id"])
|
||||
self.lobby_manager.broadcast_message(
|
||||
lobby_id,
|
||||
json.dumps({
|
||||
@@ -238,6 +239,17 @@ class ClientConnection:
|
||||
else:
|
||||
# client is not host; client leaves only
|
||||
self.lobby_manager.leave_lobby(lobby_id, data_object["client_id"])
|
||||
|
||||
elif data_object["response"] == "send_chat_message":
|
||||
print("relaying chat message")
|
||||
self.lobby_manager.broadcast_message(
|
||||
data_object["lobby_id"],
|
||||
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,
|
||||
})
|
||||
)
|
||||
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) < 2:
|
||||
|
||||
Reference in New Issue
Block a user