forked from Firepup650/python-talk
Code I did while mostly asleep
This commit is contained in:
parent
e2f905fc55
commit
8248df5907
1 changed files with 72 additions and 36 deletions
38
server.py
38
server.py
|
@ -220,7 +220,7 @@ async def handleClient(reader, writer):
|
|||
writer.write(b"I Mmm... Blood\n")
|
||||
case _:
|
||||
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()
|
||||
except TimeoutError:
|
||||
|
@ -283,6 +283,7 @@ async def connectServer(hostname: str, port: int):
|
|||
G.msgs.append(log(f"{client} has connected from {rID}"))
|
||||
G.servers[rID].append(client)
|
||||
G.clientsConnected.extend(G.servers[rID])
|
||||
try:
|
||||
while 1:
|
||||
try:
|
||||
rawMsg = await asyncio.wait_for(reader.read(967), 0.1)
|
||||
|
@ -314,10 +315,45 @@ async def connectServer(hostname: str, port: int):
|
|||
writer.write(
|
||||
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 _:
|
||||
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
|
||||
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:
|
||||
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):
|
||||
|
|
Loading…
Reference in a new issue