Code I did while mostly asleep

This commit is contained in:
Firepup Sixfifty 2024-07-14 04:12:40 +00:00
parent e2f905fc55
commit 8248df5907
Signed by: Firepup650
SSH key fingerprint: SHA256:U0Zp8EhEe3CMqFSrC79CqatzaEiL4sjta80/RSX2XrY

View file

@ -220,7 +220,7 @@ async def handleClient(reader, writer):
writer.write(b"I Mmm... Blood\n") writer.write(b"I Mmm... Blood\n")
case _: case _:
writer.write( writer.write(
b"S Your server is doing drugs over here, sending me bullshit messages man - A fellow server\n" f"S Your server is doing drugs over here, sending me bullshit messages man - {G.remoteID}, A fellow server\n".encode("utf8")
) )
await writer.drain() await writer.drain()
except TimeoutError: except TimeoutError:
@ -283,6 +283,7 @@ async def connectServer(hostname: str, port: int):
G.msgs.append(log(f"{client} has connected from {rID}")) G.msgs.append(log(f"{client} has connected from {rID}"))
G.servers[rID].append(client) G.servers[rID].append(client)
G.clientsConnected.extend(G.servers[rID]) G.clientsConnected.extend(G.servers[rID])
try:
while 1: while 1:
try: try:
rawMsg = await asyncio.wait_for(reader.read(967), 0.1) rawMsg = await asyncio.wait_for(reader.read(967), 0.1)
@ -314,10 +315,45 @@ async def connectServer(hostname: str, port: int):
writer.write( writer.write(
b"I Get these damn heretic ghost clients out of my store so i can buy my cult candles in peace." b"I Get these damn heretic ghost clients out of my store so i can buy my cult candles in peace."
) )
case "A":
cName = buffer[2:].split("|", 1)[0]
message = buffer[2:].split("|", 1)[1]
G.msgs.append(log(f"* {cName} {message}"))
writer.write(b"I Mmm... Strawberries\n")
case "Q":
break
case "K":
cName = buffer[2:]
G.killList[cName] = True
writer.write(b"I Mmm... Blood\n")
case _: case _:
writer.write(
f"S Your server is doing drugs over here, sending me bullshit messages man - {G.remoteID}, A fellow server\n".encode(
"utf8"
)
)
await writer.drain()
except TimeoutError:
pass pass
await writer.drain()
writer.close()
await writer.wait_closed()
for cName in G.servers[rID]:
G.msgs.append(log(f"{cName}'s server is going down"))
G.clientsConnected.remove(cName)
G.serverLinks -= 1
G.servers.remove(rID)
G.msgs.append(log(f"{rID} has de-linked from the network"))
except (ConnectionResetError, BrokenPipeError):
for cName in G.servers[rID]:
G.msgs.append(log(f"{cName}'s server is going down"))
try:
G.clientsConnected.remove(cName)
except Exception: except Exception:
pass pass
G.serverLinks -= 1
G.servers.remove(rID)
G.msgs.append(log(f"{rID} has de-linked from the network"))
async def runServer(port: int): async def runServer(port: int):