Add ISUPPORT
This commit is contained in:
parent
97062c2297
commit
596f5cfb40
2 changed files with 91 additions and 82 deletions
|
@ -1,6 +1,6 @@
|
|||
# IRCat Configuration
|
||||
|
||||
# Used as the server/network's display name.
|
||||
# Used as the server/network's display name. MUST NOT CONTAIN SPACES!
|
||||
name: foo
|
||||
|
||||
# The hostname the server should go by, such as ircserver1.example.com
|
||||
|
|
37
server.py
37
server.py
|
@ -1,5 +1,5 @@
|
|||
#!/usr/bin/python3
|
||||
__version__ = 0
|
||||
__version__ = "0.0.1-preview"
|
||||
print(f"INTERNET RELAY CAT v{__version__}")
|
||||
print("Welcome! /ᐠ ˵> ⩊ <˵マ")
|
||||
import socket, time, threading, traceback, sys, os, yaml
|
||||
|
@ -27,9 +27,12 @@ channels_list = {}
|
|||
flags_list = {}
|
||||
print("Now listening on port 6667")
|
||||
def session(connection, client):
|
||||
pending = None
|
||||
already_set = False
|
||||
ready = False
|
||||
pending = None # The nickname of the client
|
||||
already_set = False # If the client gave the server a NICK packet
|
||||
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:
|
||||
print("Connected to client IP: {}".format(client))
|
||||
connection.sendall(bytes(f":{server} NOTICE * :*** Looking for your hostname...\r\n","UTF-8"))
|
||||
|
@ -51,14 +54,20 @@ def session(connection, client):
|
|||
pending = None
|
||||
else:
|
||||
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
|
||||
already_set = True
|
||||
if text.split(" ")[0] == "USER":
|
||||
elif text.split(" ")[0] == "USER":
|
||||
if not ready:
|
||||
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":
|
||||
channel = text.split(" ")[1]
|
||||
success = True
|
||||
|
@ -73,14 +82,14 @@ def session(connection, client):
|
|||
print(channels_list)
|
||||
for i in channels_list[channel]:
|
||||
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:
|
||||
pass
|
||||
if text.split(" ")[0] == "PART":
|
||||
channel = text.split(" ")[1]
|
||||
for i in channels_list[channel]:
|
||||
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:
|
||||
pass
|
||||
try:
|
||||
|
@ -101,11 +110,11 @@ def session(connection, client):
|
|||
for i in channels_list[channel]:
|
||||
try:
|
||||
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:
|
||||
pass
|
||||
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:
|
||||
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"))
|
||||
|
@ -124,7 +133,7 @@ def session(connection, client):
|
|||
if pending in users:
|
||||
for j in users:
|
||||
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)
|
||||
# Remove the quitting user from the channel.
|
||||
try:
|
||||
|
@ -132,7 +141,7 @@ def session(connection, client):
|
|||
except:
|
||||
print(traceback.format_exc())
|
||||
# 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
|
||||
except:
|
||||
print(traceback.format_exc())
|
||||
|
|
Loading…
Reference in a new issue