From 6c1a890670a30d0319e18423fff96589598ba707 Mon Sep 17 00:00:00 2001 From: swee Date: Thu, 12 Dec 2024 13:35:02 -0800 Subject: [PATCH] Update server.py --- server.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/server.py b/server.py index 4e04113..26a65f9 100644 --- a/server.py +++ b/server.py @@ -66,15 +66,17 @@ def pinger(nick, connection): global property_list while nick in property_list: if (time.time() - property_list[nick]["last_ping"]) > 60 and not property_list[nick]["ping_pending"]: - print("Sent ping message to " + nick) - property_list[nick]["ping_pending"] = True - time.sleep(0.5) - connection.sendall(bytes(f"PING {server}\r\n","UTF-8")) + if nick in property_list: + print("Sent ping message to " + nick) + property_list[nick]["ping_pending"] = True + time.sleep(0.5) + connection.sendall(bytes(f"PING {server}\r\n","UTF-8")) elif property_list[nick]["ping_pending"] and ((time.time() - property_list[nick]["last_ping"]) > 255): - property_list[nick]["cause"] = "Ping timeout: 255 seconds" - connection.shutdown(socket.SHUT_WR) - connection.close() - break + if nick in property_list: + property_list[nick]["cause"] = "Ping timeout: 255 seconds" + connection.shutdown(socket.SHUT_WR) + connection.close() + break def session(connection, client): pending = "*" # The nickname of the client already_set = False # If the client gave the server a NICK packet