summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTest_User <hax@andrewyu.org>2022-04-09 22:48:18 -0400
committerTest_User <hax@andrewyu.org>2022-04-09 22:48:18 -0400
commit1b60aa9b97c9aea9aa842da3f8dea8816721ad3d (patch)
treefa8dd437af03d1773e124f8415bbb1f9578d67be
parent530882d32cb328f6a59d891198ae8ee509bc82af (diff)
downloadcoupserv-1b60aa9b97c9aea9aa842da3f8dea8816721ad3d.tar.gz
coupserv-1b60aa9b97c9aea9aa842da3f8dea8816721ad3d.zip
yay
-rwxr-xr-xCoupServ.py275
1 files changed, 73 insertions, 202 deletions
diff --git a/CoupServ.py b/CoupServ.py
index 0bfbb87..51780fe 100755
--- a/CoupServ.py
+++ b/CoupServ.py
@@ -10,7 +10,7 @@ import sys
import os
def send(msg):
- return s.sendall(msg.encode("UTF-8", "surrogateescape"))
+ return s.sendall(msg.encode("UTF-8", "surrogateescape")+b"\n")
def recv():
return s.recv(1024).decode("UTF-8", "surrogateescape")
@@ -27,11 +27,11 @@ except FileNotFoundError:
print("No config found! Please make one then try again")
exit()
-s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+s=ssl.wrap_socket(socket.socket(socket.AF_INET, socket.SOCK_STREAM))
-s.connect(("irc.andrewyu.org", 6666))
+s.connect(("irc.andrewyu.org", 7005))
-send("PASS "+config['send_password']+" TS 6 1HC\r\nCAPAB BAN CHW CLUSTER ECHO ENCAP EOPMOD EUID EX IE KLN KNOCK MLOCK QS RSFNC SAVE SERVICES TB UNKLN\r\nSERVER coup.irc.andrewyu.org 0 :Coup Server\r\nSVINFO 6 6 0 :"+str(math.floor(time.time()))+"\r\n")
+send("SERVER hax.irc.andrewyu.org "+config["send_password"]+" 0 1HC :HaxServ")
msg = ""
@@ -41,6 +41,8 @@ servlist = {}
userlist = {}
chanlist = {}
+usercount = 0
+
def read_and_send():
for line in sys.stdin:
try:
@@ -56,13 +58,13 @@ try:
if newmsg == "":
break
msg += newmsg
- split_msg = msg.split("\r\n")
+ split_msg = msg.split("\n")
if len(split_msg) < 2:
continue
commands = split_msg[0:-1]
msg = split_msg[-1]
for command in commands:
- print(command)
+ print(command.encode("UTF-8", "surrogateescape"))
source = ""
if command.startswith(":"):
@@ -72,214 +74,83 @@ try:
lastarg = " :".join(command.split(" :")[1:])
args = command.split(" :")[0].split(" ")[1:]
args.append(lastarg)
- command = command.split(" :")[0].split(" ")[0]
+ command = command.split(" :")[0].split(" ")[0].upper()
- if command.upper() == "PING":
- try:
- send(args[1]+" PONG "+args[0]+"\r\n")
- except IndexError:
- send(":1HC PONG "+args[0]+"\r\n")
- elif command.upper() == "PASS":
- if source != "":
- print("Received PASS from another source!")
- continue
- if connected_server != "":
- print("Received PASS from the server more than once!")
- continue
- if args[0] != config['accept_password']:
- print("Invalid password given by the server!")
- exit()
- connected_server = args[3]
- elif command.upper() == "SERVER":
+ if command == "PING":
+ send(":"+args[1]+" PONG "+args[1]+" "+source)
+ elif command == "SERVER":
if source != "":
print("Received SERVER from another source!")
continue
- if connected_server == "":
- print("Server sent SERVER before PASS!")
+ if config["recv_password"] != args[1]:
+ print("Received invalid password from the server!")
exit()
- servlist[connected_server] = {"server name": args[0], "hopcount": args[1], "server description": args[2]}
-
- send("EUID "+config["nick"]+" 0 "+str(math.floor(time.time()))+" +SZio CoupServ hax/CoupServ 127.0.0.1 1HC000001 localhost * :CoupServ\r\n:1HC000001 OPER "+config["nick"]+" admin\r\n")
- send("EUID SpamServ 0 "+str(math.floor(time.time()))+" +Zi SpamServ hax/SpamServ 0.0.0.0 1HC000002 0.0.0.0 * :SpamServ\r\n")
+ send("BURST "+str(math.floor(time.time())))
+ send("UID 1HC000000 "+str(math.floor(time.time()))+" "+config["nick"]+" hax.irc.andrewyu.org LibreIRC/services/HaxServ™ HaxServ 192.168.1.1 "+str(math.floor(time.time()))+" +BHILkrio :HaxServ")
+ send(":1HC000000 OPERTYPE Admin")
for channel in config["channels"]:
- send(":1HC000001 JOIN "+str(math.floor(time.time()))+" "+channel+" +\r\n:1HC MODE "+channel+" +ov 1HC000001 1HC000001\r\n")
- elif command.upper() == "SID":
- servlist[args[2]] = {"server name": args[0], "hopcount": args[1], "server description": args[3]}
- elif command.upper() == "EUID":
- userlist[args[7]] = {"nickname": args[0], "hopcount": args[1], "nickTS": args[2], "umodes": args[3], "username": args[4], "visible hostname": args[5], "IP address": args[6], "real hostname": args[8], "account name": args[9], "gecos": args[10]}
- elif command.upper() == "SJOIN":
- chanlist[args[1]] = {"channelTS": args[0], "simple modes": args[2], "mode params": args[3:-1], "nicklist": {}}
- for uid in args[-1].split(" "):
- mode = {"@": False, "+": False}
- if uid.startswith("@"):
- mode["@"] = True
- uid = uid[1:]
- if uid.startswith("+"):
- mode["+"] = True
- uid = uid[1:]
- chanlist[args[1]]["nicklist"][uid] = mode
- elif command.upper() == "NICK":
- if len(source) == 9:
- userlist[source]["nickname"] = args[0]
- userlist[source]["nickTS"] = args[1]
- elif command.upper() == "QUIT":
+ send("FJOIN "+channel+" "+str(math.floor(time.time()))+" + :,1HC000000")
+ send("MODE "+channel+" +o 1HC000000")
+ send("ENDBURST")
+ elif command == "UID":
+ userlist[args[0]] = {
+ "server": source,
+ "nick_ts": args[1],
+ "nick": args[2],
+ "hostname": args[3],
+ "vhost": args[4],
+ "ident": args[5],
+ "ip": args[6],
+ "user_ts": args[7],
+ "umodes": args[8],
+ "realname": args[9],
+
+ "opertype": None
+ }
+ elif command == "OPERTYPE":
try:
- del userlist[source]
+ userlist[source]["opertype"] = args[0]
except KeyError:
- continue
- for channel in chanlist:
- try:
- del chanlist[channel]["nicklist"][source]
- except KeyError:
- pass
- elif command.upper() == "KILL":
+ print("Unable to find oper!\r\n")
+ elif command == "NICK":
try:
- del userlist[args[0]]
+ userlist[source]["nick"] = args[0]
+ userlist[source]["nick_ts"] = args[1]
except KeyError:
- continue
- for channel in chanlist:
- try:
- del chanlist[channel]["nicklist"][args[0]]
- except KeyError:
- pass
- elif command.upper() == "TMODE":
- if int(args[0]) <= int(chanlist[args[1]]["channelTS"]):
- modechanges = []
-
- dir = "-"
- for i in range(0, len(args[2])):
- if args[2][i] == "+":
- dir = "+"
- elif args[2][i] == "-":
- dir = "-"
- elif args[2][i] == 'o':
- if args[3] == "1HC000001" and dir == "-":
- modechanges.append(["+", "o", args[3]])
- try:
- chanlist[args[1]]["nicklist"][args[3]]['@'] = (dir == "+")
- except KeyError:
- pass
- del args[3]
- elif args[2][i] == 'v':
- if args[3] == "1HC000001" and dir == "-":
- modechanges.append(["+", "v", args[3]])
- try:
- chanlist[args[1]]["nicklist"][args[3]]['+'] = (dir == "+")
- except KeyError:
- pass
- del args[3]
- elif args[2][i] in ['e', 'I', 'b', 'q', 'k', 'f', 'l', 'j']:
- del args[3]
-
- while len(modechanges) > 0:
- modechange = [" "]
- dir = ""
- for change in modechanges[:4]:
- if change[0] != dir:
- modechange[0]+=change[0]
- dir = change[0]
- modechange[0]+=change[1]
- modechange.append(change[2])
- send(":1HC000001 MODE "+args[1]+" ".join(modechange)+"\r\n")
- modechanges = modechanges[4:]
- elif command.upper() == "JOIN":
- if len(args) == 1:
- if args[0] == '0':
- for channel in chanlist:
- try:
- del chanlist[channel]["nicklist"][source]
- except KeyError:
- pass
- else:
- chanlist[args[1]]["nicklist"][source] = {'@': False, '+': False}
- elif command.upper() == "PRIVMSG":
- if [userlist[source]["username"], userlist[source]["IP address"]] in config["trusted_IDs"]:
- if args[0] == "1HC000001" or (args[0].startswith("#") and args[1].startswith("-")):
- if args[0] != "1HC000001":
- args[1] = args[1][1:]
-
- if args[1] == "print userlist":
- print(userlist)
- elif args[1] == "print chanlist":
- print(chanlist)
- elif args[1] == "print servlist":
- print(servlist)
- elif args[1].startswith("join "):
- chan = args[1].split(" ")[1]
- if chan not in config["channels"]:
- config["channels"].append(chan)
- print("New channel list", config["channels"])
- save()
- send(":1HC000001 JOIN "+str(math.floor(time.time()))+" "+chan+" +\r\n")
- elif args[1].startswith("part "):
- chan = args[1].split(" ")[1]
- if chan in config["channels"]:
- config["channels"] = [c for c in config["channels"] if c != chan]
- save()
- send(":1HC000001 PART "+chan+"\r\n")
- elif args[1].startswith("sanick "):
- current = args[1].split(" ")[1]
- target = args[1].split(" ")[2]
- for id in userlist:
- if userlist[id]["nickname"] == current:
- current = id
- break
- try:
- send(":1HC ENCAP * RSFNC "+current+" "+target+" "+str(math.floor(time.time()))+" :"+userlist[current]["nickTS"]+"\r\n")
- except KeyError:
- continue
- elif args[1].startswith("coup "):
- chan = args[1].split(" ")[1]
- modechanges = []
- for user in chanlist[chan]["nicklist"]:
- if [userlist[user]["username"], userlist[user]["IP address"]] in config["trusted_IDs"]:
- if not chanlist[chan]["nicklist"][user]["@"]:
- chanlist[chan]["nicklist"][user]["@"] = True
- modechanges.append(["+", "o", user])
- else:
- if chanlist[chan]["nicklist"][user]["@"]:
- chanlist[chan]["nicklist"][user]["@"] = False
- modechanges.append(["-", "o", user])
-
- while len(modechanges) > 0:
- modechange = [" "]
- dir = ""
- for change in modechanges[:4]:
- if change[0] != dir:
- modechange[0]+=change[0]
- dir = change[0]
- modechange[0]+=change[1]
- modechange.append(change[2])
- send(":1HC000001 MODE "+chan+" ".join(modechange)+"\r\n")
- modechanges = modechanges[4:]
- elif args[1].startswith("spam "):
- chan = args[1].split(" ")[1]
- count = int(args[1].split(" ")[2])
- msg = " ".join(args[1].split(" ")[3:])
- send(":1HC000002 JOIN "+str(math.floor(time.time()))+" "+chan+" +\r\n")
- for _ in range(count):
- send(":1HC000002 PRIVMSG "+chan+" :"+msg+"\r\n")
- send(":1HC000002 PART "+chan+"\r\n")
- elif args[1].startswith("userspam "):
- count = args[1].split(" ")[1]
- for i in range(3, max(0, min(int(count), 1000))+3):
- send("EUID 1HC"+str(i).zfill(6)+" 0 "+str(math.floor(time.time()))+" +Zi "+str(i)+" hax/SpamServ 0.0.0.0 1HC"+str(i).zfill(6)+" 0.0.0.0 * :SpamServ\r\n:1HC"+str(i).zfill(6)+" JOIN "+str(math.floor(time.time()))+" #spam +\r\n")
- elif args[1].startswith("nick "):
- nick = args[1].split(" ")[1]
- config["nick"] = nick
- save()
- send(":1HC000001 NICK "+nick+" "+str(math.floor(time.time()))+"\r\n")
- elif args[1].startswith("mode "):
- send(args[1]+"\r\n")
- elif args[1].startswith("echo "):
- if args[0] == "1HC000001":
- dest = source
+ print("Unable to find nick!\r\n")
+ elif command == "PRIVMSG":
+ try:
+ if userlist[source]["opertype"] == "Admin":
+ if args[0] == "1HC000000" or (args[0][0] == "#" and args[1][0] == "-"):
+ if args[0][0] == "#":
+ chan = args[0]
+ resp = chan
+ args[1] = args[1][1:]
else:
- dest = args[0]
- send(":1HC000001 PRIVMSG "+dest+" :"+" ".join(args[1].split(" ")[1:])+"\r\n")
+ resp = source
+ chan = False
+
+ cmd = args[1].split(" ")[0]
+ argv = args[1].split(" ")[1:]
+
+ send(":1HC000000 PRIVMSG "+config["log_chan"]+" :"+userlist[source]["nick"]+" executed command: "+args[1])
+
+ if cmd[0] == ":":
+ send(args[1])
+ elif cmd == "get":
+ if argv[0] == "uid":
+ try:
+ send(":1HC000000 PRIVMSG "+resp+" :"+[key for key in userlist if userlist[key]["nick"] == argv[1]][0])
+ except IndexError:
+ send(":1HC000000 PRIVMSG "+resp+" :Nick not found!")
+ elif argv[0] == "ts":
+ try:
+ send(":1HC000000 PRIVMSG "+resp+" :"+userlist[argv[1]]["nick_ts"])
+ except KeyError:
+ send(":1HC000000 PRIVMSG "+resp+" :UID not found!")
+ except KeyError:
+ pass
- elif args[1].startswith(":"):
- send(args[1]+"\r\n")
except Exception as e:
config_file.close()
raise e