Update server.py

This commit is contained in:
Nova Cat 2024-12-12 13:35:02 -08:00
parent 2730cfa6c5
commit 6c1a890670

View file

@ -66,15 +66,17 @@ def pinger(nick, connection):
global property_list global property_list
while nick in property_list: while nick in property_list:
if (time.time() - property_list[nick]["last_ping"]) > 60 and not property_list[nick]["ping_pending"]: if (time.time() - property_list[nick]["last_ping"]) > 60 and not property_list[nick]["ping_pending"]:
print("Sent ping message to " + nick) if nick in property_list:
property_list[nick]["ping_pending"] = True print("Sent ping message to " + nick)
time.sleep(0.5) property_list[nick]["ping_pending"] = True
connection.sendall(bytes(f"PING {server}\r\n","UTF-8")) 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): elif property_list[nick]["ping_pending"] and ((time.time() - property_list[nick]["last_ping"]) > 255):
property_list[nick]["cause"] = "Ping timeout: 255 seconds" if nick in property_list:
connection.shutdown(socket.SHUT_WR) property_list[nick]["cause"] = "Ping timeout: 255 seconds"
connection.close() connection.shutdown(socket.SHUT_WR)
break connection.close()
break
def session(connection, client): def session(connection, client):
pending = "*" # The nickname of the client pending = "*" # The nickname of the client
already_set = False # If the client gave the server a NICK packet already_set = False # If the client gave the server a NICK packet