Update server.py
This commit is contained in:
parent
7e40c8a422
commit
fd38daa28d
1 changed files with 53 additions and 22 deletions
75
server.py
75
server.py
|
@ -78,15 +78,15 @@ print("Now listening on port 6667")
|
||||||
def pinger(nick, connection):
|
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"]) > 30 and not property_list[nick]["ping_pending"]:
|
||||||
if nick in property_list:
|
if nick in property_list:
|
||||||
print("Sent ping message to " + nick)
|
print("Sent ping message to " + nick)
|
||||||
property_list[nick]["ping_pending"] = True
|
property_list[nick]["ping_pending"] = True
|
||||||
time.sleep(0.5)
|
time.sleep(0.5)
|
||||||
connection.sendall(bytes(f"PING {server}\r\n","UTF-8"))
|
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"]) > ping_timeout):
|
||||||
if nick in property_list:
|
if nick in property_list:
|
||||||
property_list[nick]["cause"] = "Ping timeout: 255 seconds"
|
property_list[nick]["cause"] = f"Ping timeout: {ping_timeout} seconds"
|
||||||
print("SHUTTING DOWN FOR " + nick)
|
print("SHUTTING DOWN FOR " + nick)
|
||||||
connection.shutdown(socket.SHUT_WR)
|
connection.shutdown(socket.SHUT_WR)
|
||||||
connection.close()
|
connection.close()
|
||||||
|
@ -147,6 +147,7 @@ def session(connection, client):
|
||||||
if args[0] == "LS":
|
if args[0] == "LS":
|
||||||
connection.sendall(bytes(f":{server} CAP * LS :ircat.xyz/foo\r\n", "UTF-8"))
|
connection.sendall(bytes(f":{server} CAP * LS :ircat.xyz/foo\r\n", "UTF-8"))
|
||||||
elif (ready and already_set) and not finished:
|
elif (ready and already_set) and not finished:
|
||||||
|
cleanup_manual()
|
||||||
print(f"User {pending} successfully logged in.")
|
print(f"User {pending} successfully logged in.")
|
||||||
nickname_list[pending] = connection
|
nickname_list[pending] = connection
|
||||||
property_list[pending] = {"host": hostname, "username": username, "realname": realname, "modes": "iw", "last_ping": time.time(), "ping_pending": False}
|
property_list[pending] = {"host": hostname, "username": username, "realname": realname, "modes": "iw", "last_ping": time.time(), "ping_pending": False}
|
||||||
|
@ -492,25 +493,55 @@ def session(connection, client):
|
||||||
break
|
break
|
||||||
finally:
|
finally:
|
||||||
connection.close()
|
connection.close()
|
||||||
if "cause" in property_list[pending]:
|
try:
|
||||||
cause = property_list[pending]["cause"]
|
if "cause" in property_list[pending]:
|
||||||
if pending != "*":
|
cause = property_list[pending]["cause"]
|
||||||
del nickname_list[pending]
|
if pending != "*":
|
||||||
del property_list[pending]
|
del nickname_list[pending]
|
||||||
del lower_nicks[pending.lower()]
|
del property_list[pending]
|
||||||
if not safe_quit:
|
del lower_nicks[pending.lower()]
|
||||||
done = []
|
if not safe_quit:
|
||||||
for i, users in channels_list.items():
|
done = []
|
||||||
if pending in users:
|
for i, users in channels_list.items():
|
||||||
for j in users:
|
if pending in users:
|
||||||
if j != pending and not j in done:
|
for j in users:
|
||||||
nickname_list[j].sendall(bytes(f":{pending}!~{username}@{hostname} QUIT :{cause}\r\n","UTF-8"))
|
if j != pending and not j in done:
|
||||||
done.append(j)
|
nickname_list[j].sendall(bytes(f":{pending}!~{username}@{hostname} QUIT :{cause}\r\n","UTF-8"))
|
||||||
# Remove the quitting user from the channel.
|
done.append(j)
|
||||||
try:
|
# Remove the quitting user from the channel.
|
||||||
channels_list[i].remove(pending)
|
try:
|
||||||
except:
|
channels_list[i].remove(pending)
|
||||||
print(traceback.format_exc())
|
except:
|
||||||
|
print(traceback.format_exc())
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
cleanup_manual()
|
||||||
|
def cleanup():
|
||||||
|
global channels_list
|
||||||
|
global property_list
|
||||||
|
while True:
|
||||||
|
time.sleep(15)
|
||||||
|
print("Cleaning up...")
|
||||||
|
for i, j in channels_list.items():
|
||||||
|
for h in i:
|
||||||
|
if not h in property_list:
|
||||||
|
print("Found a detached connection: " + h)
|
||||||
|
i.remove(h)
|
||||||
|
for k in channels_list[j]:
|
||||||
|
if k != h and k in nickname_list:
|
||||||
|
nickname[k].sendall(f":{h}!~DISCONNECTED@DISCONNECTED PART {j} :IRCat Cleanup: Found missing connection!!\r\n")
|
||||||
|
def cleanup_manual():
|
||||||
|
global channels_list
|
||||||
|
global property_list
|
||||||
|
print("Cleaning up...")
|
||||||
|
for i, j in channels_list.items():
|
||||||
|
for h in i:
|
||||||
|
if not h in property_list:
|
||||||
|
print("Found a detached connection: " + h)
|
||||||
|
i.remove(h)
|
||||||
|
for k in channels_list[j]:
|
||||||
|
if k != h and k in nickname_list:
|
||||||
|
nickname[k].sendall(f":{h}!~DISCONNECTED@DISCONNECTED PART {j} :IRCat Cleanup: Found missing connection!!\r\n")
|
||||||
try:
|
try:
|
||||||
while opened:
|
while opened:
|
||||||
print("Waiting for connection...")
|
print("Waiting for connection...")
|
||||||
|
|
Loading…
Reference in a new issue