Add ISUPPORT

This commit is contained in:
Nova Cat 2024-12-08 20:02:59 -08:00
parent 97062c2297
commit 596f5cfb40
2 changed files with 91 additions and 82 deletions

View file

@ -1,6 +1,6 @@
# IRCat Configuration # IRCat Configuration
# Used as the server/network's display name. # Used as the server/network's display name. MUST NOT CONTAIN SPACES!
name: foo name: foo
# The hostname the server should go by, such as ircserver1.example.com # The hostname the server should go by, such as ircserver1.example.com

View file

@ -1,5 +1,5 @@
#!/usr/bin/python3 #!/usr/bin/python3
__version__ = 0 __version__ = "0.0.1-preview"
print(f"INTERNET RELAY CAT v{__version__}") print(f"INTERNET RELAY CAT v{__version__}")
print("Welcome! /ᐠ ˵> ⩊ <˵マ") print("Welcome! /ᐠ ˵> ⩊ <˵マ")
import socket, time, threading, traceback, sys, os, yaml import socket, time, threading, traceback, sys, os, yaml
@ -27,9 +27,12 @@ channels_list = {}
flags_list = {} flags_list = {}
print("Now listening on port 6667") print("Now listening on port 6667")
def session(connection, client): def session(connection, client):
pending = None pending = None # The nickname of the client
already_set = False already_set = False # If the client gave the server a NICK packet
ready = False ready = False # If the client gave the server a USER packet
finished = False # If the server gave the client its information, indicating it's ready.
username = "oreo"
hostname = client[0]
try: try:
print("Connected to client IP: {}".format(client)) print("Connected to client IP: {}".format(client))
connection.sendall(bytes(f":{server} NOTICE * :*** Looking for your hostname...\r\n","UTF-8")) connection.sendall(bytes(f":{server} NOTICE * :*** Looking for your hostname...\r\n","UTF-8"))
@ -51,14 +54,20 @@ def session(connection, client):
pending = None pending = None
else: else:
if not already_set: if not already_set:
connection.sendall(bytes(f":{server} 001 {pending} :Welcome to the {displayname} Internet Relay Chat Network {pending}\r\n", "UTF-8"))
connection.sendall(bytes(f":{server} 002 {pending} :Your host is {server}[{ip}/6667], running version IRCat-v{__version__}\r\n", "UTF-8"))
connection.sendall(bytes(f":{pending} MODE {pending} +iw\r\n","UTF-8"))
nickname_list[pending] = connection nickname_list[pending] = connection
already_set = True already_set = True
if text.split(" ")[0] == "USER": elif text.split(" ")[0] == "USER":
if not ready: if not ready:
username = text.split(" ")[1] username = text.split(" ")[1]
elif (ready and already_set) and not finished:
connection.sendall(bytes(f":{server} 001 {pending} :Welcome to the {displayname} Internet Relay Chat Network {pending}\r\n", "UTF-8"))
connection.sendall(bytes(f":{server} 002 {pending} :Your host is {server}[{ip}/6667], running version IRCat-v{__version__}\r\n", "UTF-8"))
connection.sendall(bytes(f":{server} 004 {pending} {server} IRCat-{__version__} iow ovmsitnlbkq\r\n", "UTF-8"))
connection.sendall(bytes(f":{server} 005 {pending} CHANMODES=bq NETWORK={displayname} :are supported by this server\r\n", "UTF-8"))
connection.sendall(bytes(f":{pending} MODE {pending} +iw\r\n","UTF-8"))
finished = True
elif (ready and already_set) and finished:
if text.split(" ")[0] == "JOIN": if text.split(" ")[0] == "JOIN":
channel = text.split(" ")[1] channel = text.split(" ")[1]
success = True success = True
@ -73,14 +82,14 @@ def session(connection, client):
print(channels_list) print(channels_list)
for i in channels_list[channel]: for i in channels_list[channel]:
try: try:
nickname_list[i].sendall(bytes(f":{pending}!~oreo@{client[0]} JOIN {channel}\r\n","UTF-8")) nickname_list[i].sendall(bytes(f":{pending}!~{username}@{client[0]} JOIN {channel}\r\n","UTF-8"))
except: except:
pass pass
if text.split(" ")[0] == "PART": if text.split(" ")[0] == "PART":
channel = text.split(" ")[1] channel = text.split(" ")[1]
for i in channels_list[channel]: for i in channels_list[channel]:
try: try:
nickname_list[i].sendall(bytes(f":{pending}!~oreo@{client[0]} {text}\r\n","UTF-8")) nickname_list[i].sendall(bytes(f":{pending}!~{username}@{client[0]} {text}\r\n","UTF-8"))
except: except:
pass pass
try: try:
@ -101,11 +110,11 @@ def session(connection, client):
for i in channels_list[channel]: for i in channels_list[channel]:
try: try:
if i != pending: if i != pending:
nickname_list[i].sendall(bytes(f":{pending}!~oreo@{client[0]} {text}\r\n","UTF-8")) nickname_list[i].sendall(bytes(f":{pending}!~{username}@{hostname} {text}\r\n","UTF-8"))
except: except:
pass pass
elif target in nickname_list: elif target in nickname_list:
nickname_list[target].sendall(bytes(f":{pending}!~oreo@{client[0]} {text}\r\n","UTF-8")) nickname_list[target].sendall(bytes(f":{pending}!~{username}@{hostname} {text}\r\n","UTF-8"))
else: else:
nickname_list[target].sendall(bytes(f":{server} 401 {pending} {target} :No such nick/channel\r\n","UTF-8")) nickname_list[target].sendall(bytes(f":{server} 401 {pending} {target} :No such nick/channel\r\n","UTF-8"))
nickname_list[i].sendall(bytes(f":{server} 366 {pending} {channel} :End of /NAMES list.\r\n","UTF-8")) nickname_list[i].sendall(bytes(f":{server} 366 {pending} {channel} :End of /NAMES list.\r\n","UTF-8"))
@ -124,7 +133,7 @@ def session(connection, client):
if pending in users: if pending in users:
for j in users: for j in users:
if j != pending and not j in done: if j != pending and not j in done:
nickname_list[j].sendall(bytes(f":{pending}!~oreo@{client[0]} {text}\r\n","UTF-8")) nickname_list[j].sendall(bytes(f":{pending}!~{username}@{client[0]} {text}\r\n","UTF-8"))
done.append(j) done.append(j)
# Remove the quitting user from the channel. # Remove the quitting user from the channel.
try: try:
@ -132,7 +141,7 @@ def session(connection, client):
except: except:
print(traceback.format_exc()) print(traceback.format_exc())
# Finally, confirm that the client quitted by mirroring the QUIT message. # Finally, confirm that the client quitted by mirroring the QUIT message.
connection.sendall(bytes(f":{pending}!~oreo@{client[0]} {text}\r\nERROR :Closing Link: {client[0]} ({msg})\r\n","UTF-8")) connection.sendall(bytes(f":{pending}!~{username}@{client[0]} {text}\r\nERROR :Closing Link: {client[0]} ({msg})\r\n","UTF-8"))
break break
except: except:
print(traceback.format_exc()) print(traceback.format_exc())