Compare commits

...

2 commits

Author SHA1 Message Date
af5cd6b741 Simple modes 2024-12-09 21:43:11 -08:00
33823a63c1 your own modes 2024-12-09 19:31:48 -08:00

View file

@ -79,7 +79,10 @@ def session(connection, client):
if command == "NICK":
pending = text.split(" ")[1]
if pending[0] == ":": pending[1:]
if pending.lower() in lower_nicks or pending in reserved:
if "!" in pending or ":" in pending or "#" in pending or "*" in pending:
connection.sendall(bytes(f":{server} 432 * {pending} :Erroneus nickname\r\n","UTF-8"))
pending = "*"
elif pending.lower() in lower_nicks or pending in reserved:
connection.sendall(bytes(f":{server} 433 * {pending} :Nickname is already in use.\r\n","UTF-8"))
pending = "*"
else:
@ -189,10 +192,16 @@ def session(connection, client):
who_user = property_list[target]["username"]
who_realname = property_list[target]["realname"]
who_host = property_list[target]["host"]
try:
who_flags = property_list[target]["modes"]
except:
who_flags = None
connection.sendall(bytes(f":{server} 311 {pending} {target} ~{who_user} {who_host} * :{who_realname}\r\n","UTF-8"))
connection.sendall(bytes(f":{server} 312 {pending} {target} {server} :{identifier}\r\n","UTF-8"))
#connection.sendall(bytes(f":{server} 313 {target} :is an IRC operator\r\n","UTF-8")) # I haven't implemented modes yet.
#connection.sendall(bytes(f":{server} 317 {target} {time} :seconds idle\r\n","UTF-8")) # I haven't implemented idle time yet.
if who_flags != None and who_flags != "iw":
connection.sendall(bytes(f":{server} 379 {pending} {target} :Is using modes +{who_flags}\r\n","UTF-8"))
connection.sendall(bytes(f":{server} 318 {pending} {target} :End of /WHOIS list\r\n","UTF-8"))
else:
connection.sendall(bytes(f":{server} 401 {pending} {target} :No such nick/channel\r\n","UTF-8"))
@ -270,11 +279,37 @@ def session(connection, client):
try:
connection.sendall(bytes(f":{pending}!~{username}@{hostname} {text}\r\n","UTF-8"))
connection.sendall(bytes(f"ERROR :Closing Link: {hostname} ({msg})\r\n","UTF-8"))
except:
break
finally:
connection.close()
safe_quit = True
break
elif command == "MODE":
if len(args) == 0:
connection.sendall(bytes(f":{server} {pending} 461 {command} :Not enough parameters\r\n","UTF-8"))
elif len(args) == 1:
if args[0] == pending:
yourmodes = property_list[pending]["modes"]
connection.sendall(bytes(f":{server} {pending} 221 +{yourmodes}\r\n","UTF-8"))
elif args[0] in channels_list:
target = args[0]
if args[0] in property_list:
if "modes" in property_list[args[0]]:
# Get the modes + parameters, then print them out.
modes = property_list[args[0]]["modes"]
params = property_list[args[0]]["params"]
connection.sendall(bytes(f":{server} {pending} {target} +{modes} {params}\r\n","UTF-8"))
else:
# Default channel mode
connection.sendall(bytes(f":{server} {pending} {target} +n\r\n","UTF-8"))
else:
# Default channel mode
connection.sendall(bytes(f":{server} {pending} {target} +n\r\n","UTF-8"))
else:
if args[0][0] == "#":
connection.sendall(bytes(f":{server} 403 {pending} {target} :No such channel\r\n","UTF-8"))
else:
connection.sendall(bytes(f":{server} {pending} 505 :Cant change mode for other users\r\n","UTF-8"))
elif command == "GITSERV":
if len(args) == 0:
connection.sendall(bytes(f":{server} {pending} 461 {command} :Not enough parameters\r\n","UTF-8"))