Update server.py

This commit is contained in:
Nova Cat 2025-02-03 22:30:19 -08:00
parent edb448a143
commit 87c3e1021e

View file

@ -25,7 +25,7 @@ motd_file = None
ping_timeout = 255 ping_timeout = 255
restrict_ip = '' restrict_ip = ''
def isalphanumeric(text:str, channel=False): def isalphanumeric(text:str, channel=False):
alphanumericity = list("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890+=-_[]{};$%^*\\|'\",.<>?/`~" + ("#" if channel else "")) alphanumericity = list("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890+-_[]^\\|<>?`" + ("$%*,./~'\"{};#=" if channel else ""))
for i in text: for i in text:
if not i in alphanumericity: if not i in alphanumericity:
return False return False
@ -295,7 +295,7 @@ def session(connection, client, ip, isssl=False):
if command == "NICK" and not finished: if command == "NICK" and not finished:
pending = text.split(" ")[1] pending = text.split(" ")[1]
if pending[0] == ":": pending = pending[1:] if pending[0] == ":": pending = pending[1:]
if "!" in pending or ":" in pending or "#" in pending or "*" in pending: if not isalphanumeric(pending):
connection.sendall(bytes(f":{server} 432 * {pending} :Erroneus nickname\r\n","UTF-8")) connection.sendall(bytes(f":{server} 432 * {pending} :Erroneus nickname\r\n","UTF-8"))
pending = "*" pending = "*"
elif pending.lower() in lower_nicks: elif pending.lower() in lower_nicks:
@ -415,6 +415,7 @@ def session(connection, client, ip, isssl=False):
channels = channels[1:] channels = channels[1:]
for channelt in channels.split(","): for channelt in channels.split(","):
channel = channelt.strip() channel = channelt.strip()
if isalphanumeric(channel, True):
if channel.lower() in lower_chans: if channel.lower() in lower_chans:
channel = lower_chans[channel.lower()] channel = lower_chans[channel.lower()]
success = True success = True
@ -445,6 +446,8 @@ def session(connection, client, ip, isssl=False):
connection.sendall(bytes(f":{server} 353 {pending} = {channel} :{users}\r\n","UTF-8")) connection.sendall(bytes(f":{server} 353 {pending} = {channel} :{users}\r\n","UTF-8"))
connection.sendall(bytes(f":{server} 366 {pending} {channel} :End of /NAMES list.\r\n","UTF-8")) connection.sendall(bytes(f":{server} 366 {pending} {channel} :End of /NAMES list.\r\n","UTF-8"))
print("Successfully pre-loaded /NAMES list") print("Successfully pre-loaded /NAMES list")
else:
connection.sendall(bytes(f":{server} 479 {pending} {channel} :Channel has erroneus characters\r\n","UTF-8"))
elif command == "LIST": elif command == "LIST":
connection.sendall(bytes(f":{server} 321 {pending} Channel :Users Name\r\n","UTF-8")) connection.sendall(bytes(f":{server} 321 {pending} Channel :Users Name\r\n","UTF-8"))
for key, value in topic_list.items(): for key, value in topic_list.items():
@ -465,7 +468,7 @@ def session(connection, client, ip, isssl=False):
else: else:
pending2 = text.split(" ")[1] pending2 = text.split(" ")[1]
if pending2[0] == ":": pending2 = pending2[1:] if pending2[0] == ":": pending2 = pending2[1:]
if "!" in pending2 or ":" in pending2 or "#" in pending2 or "*" in pending2: if not isalphanumeric(pending2):
connection.sendall(bytes(f":{server} 432 {pending} {pending2} :Erroneus nickname\r\n","UTF-8")) connection.sendall(bytes(f":{server} 432 {pending} {pending2} :Erroneus nickname\r\n","UTF-8"))
elif pending2.lower() in lower_nicks: elif pending2.lower() in lower_nicks:
connection.sendall(bytes(f":{server} 433 {pending} {pending2} :Nickname is already in use.\r\n","UTF-8")) connection.sendall(bytes(f":{server} 433 {pending} {pending2} :Nickname is already in use.\r\n","UTF-8"))