summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTest_User <hax@andrewyu.org>2024-06-19 04:06:31 -0400
committerTest_User <hax@andrewyu.org>2024-06-19 04:06:31 -0400
commitad5daa4049874de9a6e646e2b634535e6e0fd902 (patch)
treeaeef99890f6acb49760b6defc3c7446ed6b26407
parent74cf63cbbfdff606d010a95f31b39fd454b139cf (diff)
downloadpy_coupserv-ad5daa4049874de9a6e646e2b634535e6e0fd902.tar.gz
py_coupserv-ad5daa4049874de9a6e646e2b634535e6e0fd902.zip
Yay python is definitely not annoying
-rwxr-xr-xCoupServ.py144
1 files changed, 73 insertions, 71 deletions
diff --git a/CoupServ.py b/CoupServ.py
index 363ddc8..0e5cbfd 100755
--- a/CoupServ.py
+++ b/CoupServ.py
@@ -40,10 +40,10 @@ import sys
import os
def send(msg):
- return s.sendall(msg.encode("UTF-8", "surrogateescape")+b"\n")
+ return s.sendall(msg+b"\n")
def recv():
- return s.recv(1024).decode("UTF-8", "surrogateescape")
+ return s.recv(1024)
def save():
with open("CoupServTmp.json", "w") as config_file:
@@ -57,7 +57,7 @@ except FileNotFoundError:
print("No config found! Please make one then try again")
exit()
-rickroll = """We're no strangers to love
+rickroll = b"""We're no strangers to love
You know the rules, and so do I
A full commitment is what I'm thinking of
You wouldn't get this from any other guy
@@ -122,15 +122,17 @@ Never gonna make you cry
Never gonna say goodbye
never gonna tell a lie, and hurt you"""
-s=ssl.wrap_socket(socket.socket(socket.AF_INET, socket.SOCK_STREAM))
+s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+if config["tls"]:
+ s=ssl.wrap_socket(s)
-s.connect(("localhost", 7021))
+s.connect(("localhost", 7031))
-send("SERVER py.hax.irc.andrewyu.org "+config["send_password"]+" 0 "+config["sid"]+" :HaxServ")
+send(b"SERVER py.hax.irc.andrewyu.org "+config["send_password"].encode("UTF-8")+b" 0 "+config["sid"].encode("UTF-8")+b" :HaxServ")
-msg = ""
+msg = b""
-connected_server = ""
+connected_server = b""
servlist = {}
userlist = {}
@@ -143,7 +145,7 @@ usercount = 0
def read_and_send():
for line in sys.stdin:
try:
- send(line.rstrip("\n"))
+ send(line.rstrip(b"\n"))
except Exception:
pass
@@ -154,7 +156,7 @@ def detect_broken():
while True:
for key in servlist:
if servlist[key]["distance"] == 1:
- send(":"+config["sid"]+" PING "+config["sid"]+" :"+key)
+ send(b":"+config["sid"].encode("UTF-8")+b" PING "+config["sid"].encode("UTF-8")+b" :"+key)
break
time.sleep(15)
except exception as e:
@@ -166,48 +168,48 @@ threading.Thread(target=detect_broken, daemon=True).start()
try:
while True:
newmsg = recv()
- if newmsg == "":
+ if newmsg == b"":
os._exit(1)
msg += newmsg
- split_msg = msg.split("\n")
+ split_msg = msg.split(b"\n")
if len(split_msg) < 2:
continue
commands = split_msg[0:-1]
msg = split_msg[-1]
for command in commands:
- print(command.encode("UTF-8", "surrogateescape"))
+ print(command)
- source = ""
- if command.startswith(":"):
- source = command.split(" ")[0][1:]
- command = " ".join(command.split(" ")[1:])
+ source = b""
+ if command.startswith(b":"):
+ source = command.split(b" ")[0][1:]
+ command = b" ".join(command.split(b" ")[1:])
- lastarg = " :".join(command.split(" :")[1:])
- args = command.split(" :")[0].split(" ")[1:]
+ lastarg = b" :".join(command.split(b" :")[1:])
+ args = command.split(b" :")[0].split(b" ")[1:]
args.append(lastarg)
- command = command.split(" :")[0].split(" ")[0].upper()
+ command = command.split(b" :")[0].split(b" ")[0].upper()
- if command == "PING":
- send(":"+args[1]+" PONG "+args[1]+" "+source)
- elif command == "SERVER":
- if source != "":
+ if command == b"PING":
+ send(b":"+args[1]+b" PONG "+args[1]+b" "+source)
+ elif command == b"SERVER":
+ if source != b"":
servlist[args[3]] = {"attached_to": source, "address": args[0], "distance": servlist[source]["distance"] + 1, "name": args[4]}
else:
- if config["recv_password"] != args[1]:
+ if config["recv_password"].encode("UTF-8") != args[1]:
print("Received invalid password from the server!")
os._exit()
- send("BURST "+str(math.floor(time.time())))
- send("UID "+config["sid"]+"000000 "+str(math.floor(time.time()))+" "+config["nick"]+" hax.irc.andrewyu.org LibreIRC/services/HaxServ™ HaxServ 192.168.1.1 "+str(math.floor(time.time()))+" +Bk :HaxServ")
- send(":"+config["sid"]+"000000 OPERTYPE Admin")
+ send(b"BURST "+str(math.floor(time.time())).encode("UTF-8"))
+ send(b"UID "+config["sid"].encode("UTF-8")+b"000000 "+str(math.floor(time.time())).encode("UTF-8")+b" "+config["nick"].encode("UTF-8")+b" hax.irc.andrewyu.org LibreIRC/services/HaxServ\xe2\x84\xa2 HaxServ 192.168.1.1 "+str(math.floor(time.time())).encode("UTF-8")+b" +Bk :HaxServ")
+ send(b":"+config["sid"].encode("UTF-8")+b"000000 OPERTYPE Admin")
for channel in config["channels"]:
- send("FJOIN "+channel+" "+str(math.floor(time.time()))+" + :,"+config["sid"]+"000000")
- send("MODE "+channel+" +o "+config["sid"]+"000000")
- send("ENDBURST")
+ send(b"FJOIN "+channel.encode("UTF-8")+b" "+str(math.floor(time.time())).encode("UTF-8")+b" + :,"+config["sid"].encode("UTF-8")+b"000000")
+ send(b"MODE "+channel.encode("UTF-8")+b" +o "+config["sid"].encode("UTF-8")+b"000000")
+ send(b"ENDBURST")
servlist[args[3]] = {"attached_to": config["sid"], "address": args[0], "distance": 1, "name": args[4]}
- elif command == "SQUIT":
+ elif command == b"SQUIT":
if args[0] in jupe_list:
- send(":"+config["sid"]+" SERVER "+jupe_list[args[0]]+" * 0 "+args[0]+" :No")
- elif command == "UID":
+ send(b":"+config["sid"].encode("UTF-8")+b" SERVER "+jupe_list[args[0]]+b" * 0 "+args[0]+b" :No")
+ elif command == b"UID":
userlist[args[0]] = {
"server": source,
"nick_ts": args[1],
@@ -222,22 +224,22 @@ try:
"opertype": None
}
- elif command == "OPERTYPE":
+ elif command == b"OPERTYPE":
try:
userlist[source]["opertype"] = args[0]
except KeyError:
print("Unable to find oper!\r\n")
- elif command == "NICK":
+ elif command == b"NICK":
try:
userlist[source]["nick"] = args[0]
userlist[source]["nick_ts"] = args[1]
except KeyError:
print("Unable to find nick!\r\n")
- elif command == "PRIVMSG":
+ elif command == b"PRIVMSG":
try:
- if userlist[source]["opertype"] == "NetAdmin":
- if args[0] == config["sid"]+"000000" or (args[0][0] == "#" and args[1][0] == "-"):
- if args[0][0] == "#":
+ if userlist[source]["opertype"] == b"NetAdmin":
+ if args[0] == config["sid"].encode("UTF-8")+b"000000" or (args[0][0] == b"#" and args[1][0] == b"-"):
+ if args[0][0] == b"#":
chan = args[0]
resp = chan
args[1] = args[1][1:]
@@ -245,64 +247,64 @@ try:
resp = source
chan = False
- cmd = args[1].split(" ")[0].lower()
- argv = args[1].split(" ")[1:]
+ cmd = args[1].split(b" ")[0].lower()
+ argv = args[1].split(b" ")[1:]
- send(":"+config["sid"]+"000000 PRIVMSG "+config["log_chan"]+" :"+userlist[source]["nick"]+" executed command: "+args[1])
+ send(b":"+config["sid"].encode("UTF-8")+b"000000 PRIVMSG "+config["log_chan"].encode("UTF-8")+b" :"+userlist[source]["nick"].encode("UTF-8")+b" executed command: "+args[1])
if len(cmd) == 0:
continue
- elif cmd[0] == ":":
+ elif cmd[0] == b":":
send(args[1])
- elif cmd == "get":
- if argv[0] == "uid":
+ elif cmd == b"get":
+ if argv[0] == b"uid":
try:
- send(":"+config["sid"]+"000000 PRIVMSG "+resp+" :"+[key for key in userlist if userlist[key]["nick"] == argv[1]][0])
+ send(b":"+config["sid"].encode("UTF-8")+b"000000 PRIVMSG "+resp+b" :"+[key for key in userlist if userlist[key]["nick"] == argv[1]][0])
except IndexError:
- send(":"+config["sid"]+"000000 PRIVMSG "+resp+" :Nick not found!")
- elif argv[0] == "ts":
+ send(b":"+config["sid"].encode("UTF-8")+b"000000 PRIVMSG "+resp+b" :Nick not found!")
+ elif argv[0] == b"ts":
try:
- send(":"+config["sid"]+"000000 PRIVMSG "+resp+" :"+userlist[argv[1]]["nick_ts"])
+ send(b":"+config["sid"].encode("UTF-8")+b"000000 PRIVMSG "+resp+b" :"+userlist[argv[1]]["nick_ts"])
except KeyError:
- send(":"+config["sid"]+"000000 PRIVMSG "+resp+" :UID not found!")
- elif cmd == "jupe":
+ send(b":"+config["sid"].encode("UTF-8")+b"000000 PRIVMSG "+resp+b" :UID not found!")
+ elif cmd == b"jupe":
found = 0
for key in servlist:
if servlist[key]["address"] == argv[0]:
- send("RSQUIT "+argv[0]+" :")
+ send(b"RSQUIT "+argv[0]+b" :")
jupe_list[key] = argv[0]
break
- elif cmd == "sanick":
- send(":"+config["sid"]+"000000 SANICK "+argv[0]+" :"+" ".join(argv[1:]))
- elif cmd == "nggyu":
- for line in rickroll.split("\n"):
- send(":"+config["sid"]+"000000 PRIVMSG "+argv[0]+" :"+line)
- elif cmd == "spam":
+ elif cmd == b"sanick":
+ send(b":"+config["sid"].encode("UTF-8")+b"000000 SANICK "+argv[0]+b" :"+b"\xe2\x80\x82".join(argv[1:]))
+ elif cmd == b"nggyu":
+ for line in rickroll.split(b"\n"):
+ send(b":"+config["sid"].encode("UTF-8")+"000000 PRIVMSG "+argv[0]+" :"+line)
+ elif cmd == b"spam":
for _ in range(0, int(argv[1])):
- send(":"+config["sid"]+" PRIVMSG "+argv[0]+" :"+" ".join(argv[2:]))
- elif cmd == "join":
- send(":"+config["sid"]+"000000 FJOIN "+argv[0]+" "+str(math.floor(time.time()))+" + :,"+config["sid"]+"000000")
+ send(b":"+config["sid"].encode("UTF-8")+b" PRIVMSG "+argv[0]+b" :"+b" ".join(argv[2:]))
+ elif cmd == b"join":
+ send(b":"+config["sid"].encode("UTF-8")+b"000000 FJOIN "+argv[0]+b" "+str(math.floor(time.time()))+b" + :,"+config["sid"].encode("UTF-8")+b"000000")
config["channels"][argv[0]] = True # actual value doesn't matter
save()
- elif cmd == "part":
- send(":"+config["sid"]+"000000 PART "+resp)
+ elif cmd == b"part":
+ send(b":"+config["sid"].encode("UTF-8")+b"000000 PART "+resp)
del config["channels"][resp]
save()
- elif cmd == "op":
+ elif cmd == b"op":
if chan:
try:
- send(":"+config["sid"]+"000000 MODE "+chan+" +o "+argv[0])
+ send(b":"+config["sid"].encode("UTF-8")+b"000000 MODE "+chan+b" +o "+argv[0])
except IndexError:
- send(":"+config["sid"]+"000000 MODE "+chan+" +o "+source)
+ send(b":"+config["sid"].encode("UTF-8")+b"000000 MODE "+chan+b" +o "+source)
- if args[1] == "nggyu":
- if args[0][0] == "#":
+ if args[1] == b"nggyu":
+ if args[0][0] == b"#":
resp = args[0]
else:
resp = source
- for line in rickroll.split("\n"):
- send(":"+config["sid"]+"000000 PRIVMSG "+resp+" :"+line)
+ for line in rickroll.split(b"\n"):
+ send(b":"+config["sid"].encode("UTF-8")+b"000000 PRIVMSG "+resp+b" :"+line)
except KeyError:
pass