S2S protocol work

This commit is contained in:
Firepup Sixfifty 2024-07-05 01:44:35 -05:00
parent d740b26e2b
commit 53b0665411
Signed by: Firepup650
GPG key ID: 7C92E2ABBBFAB9BA

View file

@ -124,34 +124,63 @@ async def handle_client(reader, writer):
G.servers[sName] = [] G.servers[sName] = []
msgIndex = 0 msgIndex = 0
while 1: while 1:
client = await reader.read(967) client = raw((await reader.read(967)).decode("utf8"))
if client == f"END OF CLIENT LISTING FROM {sName}": if client == f"END OF CLIENT LISTING FROM {sName}":
break break
G.msgs.extend([log(f"{client} has connected from {sName}")]) G.msgs.extend([log(f"{client} has connected from {sName}")])
G.servers[sName].append(client) G.servers[sName].append(client)
G.clientsConnected.extend(G.servers[sName]) G.clientsConnected.extend(G.servers[sName])
while 1: while 1:
buffer = await asyncio.wait_for(reader.read(967), 0.1) try:
request = raw(buffer.decode("utf8")) rawMsg = await asyncio.wait_for(reader.read(967), 0.1)
match buffer[0]: buffer = raw(rawMsg.decode("utf8"))
case "S": # Server notice match buffer[0]:
G.msgs.extend([log(buffer[2:])]) case "S": # Server notice
writer.write(b"I Mmm... Blueberries\n") G.msgs.extend([log(buffer[2:])])
await writer.drain() writer.write(b"I Mmm... Blueberries\n")
case "I": await writer.drain()
pass case "I":
case "+": pass
cName = buffer[2:] case "+":
G.msgs.extend([log(f"{cName} has connected from {sName}")]) cName = buffer[2:]
G.clientsConnected.extend([cName]) G.msgs.extend([log(f"{cName} has connected from {sName}")])
writer.write(b"I Mmm... Pineapples"\n") G.clientsConnected.extend([cName])
await writer.drain() writer.write(b"I Mmm... Pineapples\n")
case "-": await writer.drain()
cName = buffer[2:] case "-":
G.clientsConnected.remove(cName) cName = buffer[2:]
await writer.drain() G.msgs.extend([log(f"{cName} has dissconected from {sName}")])
G.clientsConnected.remove(cName)
writer.write(b"I Mmm... Bananas\n")
await writer.drain()
case "M":
cName = buffer[2:].split("|", 1)[0]
message = buffer[2:].split("|", 1)[1]
G.msgs.extend([log(f" {cName}: {message}")])
writer.write(b'I Get these damn heretic ghost clients out of my store so i can buy my cult candles in peace.')
await writer.drain()
case "A":
cName = buffer[2:].split("|", 1)[0]
message = buffer[2:].split("|", 1)[1]
G.msgs.extend([log(f"* {cName} {message}")])
writer.write(b'I Mmm... Strawberries\n')
await writer.drain()
case "Q":
break
case _:
writer.write(b'S Your server is doing drugs over here, sending me bullshit messages man - A fellow server\n')
await writer.drain()
except TimeoutError:
pass
for cName in G.serverLinks[sName]:
G.msgs.extend([log(f"{cName}'s server is going down")])
G.clientsConnected.remove(cName)
G.serverLinks -= 1
G.servers.remove(sName)
G.msgs.extend([log(f"{sName} has de-linked from the network")])
except ConnectionResetError: except ConnectionResetError:
if not name.startswith("S2S-"): if not name.startswith("S2S-"):
G.uniqueClients -= 1
G.msgs.extend([log(f"{name} has disconnected from the server.")]) G.msgs.extend([log(f"{name} has disconnected from the server.")])
G.clientsConnected.remove(name) G.clientsConnected.remove(name)
else: else: