forked from Firepup650/python-talk
S2S protocol work
This commit is contained in:
parent
d740b26e2b
commit
53b0665411
1 changed files with 49 additions and 20 deletions
37
server.py
37
server.py
|
@ -124,15 +124,16 @@ 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)
|
||||||
|
buffer = raw(rawMsg.decode("utf8"))
|
||||||
match buffer[0]:
|
match buffer[0]:
|
||||||
case "S": # Server notice
|
case "S": # Server notice
|
||||||
G.msgs.extend([log(buffer[2:])])
|
G.msgs.extend([log(buffer[2:])])
|
||||||
|
@ -144,14 +145,42 @@ async def handle_client(reader, writer):
|
||||||
cName = buffer[2:]
|
cName = buffer[2:]
|
||||||
G.msgs.extend([log(f"{cName} has connected from {sName}")])
|
G.msgs.extend([log(f"{cName} has connected from {sName}")])
|
||||||
G.clientsConnected.extend([cName])
|
G.clientsConnected.extend([cName])
|
||||||
writer.write(b"I Mmm... Pineapples"\n")
|
writer.write(b"I Mmm... Pineapples\n")
|
||||||
await writer.drain()
|
await writer.drain()
|
||||||
case "-":
|
case "-":
|
||||||
cName = buffer[2:]
|
cName = buffer[2:]
|
||||||
|
G.msgs.extend([log(f"{cName} has dissconected from {sName}")])
|
||||||
G.clientsConnected.remove(cName)
|
G.clientsConnected.remove(cName)
|
||||||
|
writer.write(b"I Mmm... Bananas\n")
|
||||||
await writer.drain()
|
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:
|
||||||
|
|
Loading…
Reference in a new issue