Code I did while mostly asleep
This commit is contained in:
parent
e2f905fc55
commit
8248df5907
1 changed files with 72 additions and 36 deletions
108
server.py
108
server.py
|
@ -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,41 +283,77 @@ 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])
|
||||||
while 1:
|
try:
|
||||||
try:
|
while 1:
|
||||||
rawMsg = await asyncio.wait_for(reader.read(967), 0.1)
|
try:
|
||||||
buffer = raw(rawMsg.decode("utf8"))
|
rawMsg = await asyncio.wait_for(reader.read(967), 0.1)
|
||||||
match buffer[0]:
|
buffer = raw(rawMsg.decode("utf8"))
|
||||||
case "S":
|
match buffer[0]:
|
||||||
G.msgs.extend([log(buffer[2:])])
|
case "S":
|
||||||
writer.write(b"I Mmm... Blueberries\n")
|
G.msgs.extend([log(buffer[2:])])
|
||||||
case "I":
|
writer.write(b"I Mmm... Blueberries\n")
|
||||||
pass
|
case "I":
|
||||||
case "+":
|
pass
|
||||||
cName = buffer[2:]
|
case "+":
|
||||||
if cName not in G.clientsConnected:
|
cName = buffer[2:]
|
||||||
G.msgs.append(log(f"{cName} has connected from {rID}"))
|
if cName not in G.clientsConnected:
|
||||||
G.servers[rID].append(cName)
|
G.msgs.append(log(f"{cName} has connected from {rID}"))
|
||||||
G.clientsConnected.append(cName)
|
G.servers[rID].append(cName)
|
||||||
writer.write(b"I Mmm... Pineapples\n")
|
G.clientsConnected.append(cName)
|
||||||
else:
|
writer.write(b"I Mmm... Pineapples\n")
|
||||||
writer.write(f"K {cName}\n".encode("utf8"))
|
else:
|
||||||
case "-":
|
writer.write(f"K {cName}\n".encode("utf8"))
|
||||||
cName = buffer[2:]
|
case "-":
|
||||||
G.msgs.append(log(f"{cName} has disconnected from {sName}"))
|
cName = buffer[2:]
|
||||||
G.servers[rID].remove(cName)
|
G.msgs.append(log(f"{cName} has disconnected from {sName}"))
|
||||||
G.clientsConnected.remove(cName)
|
G.servers[rID].remove(cName)
|
||||||
case "M":
|
G.clientsConnected.remove(cName)
|
||||||
cName = buffer[2:].split("|", 1)[0]
|
case "M":
|
||||||
message = buffer[2:].split("|", 1)[1]
|
cName = buffer[2:].split("|", 1)[0]
|
||||||
G.msgs.append(log(f" {cName}: {message}"))
|
message = buffer[2:].split("|", 1)[1]
|
||||||
writer.write(
|
G.msgs.append(log(f" {cName}: {message}"))
|
||||||
b"I Get these damn heretic ghost clients out of my store so i can buy my cult candles in peace."
|
writer.write(
|
||||||
)
|
b"I Get these damn heretic ghost clients out of my store so i can buy my cult candles in peace."
|
||||||
case _:
|
)
|
||||||
pass
|
case "A":
|
||||||
except Exception:
|
cName = buffer[2:].split("|", 1)[0]
|
||||||
pass
|
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):
|
async def runServer(port: int):
|
||||||
|
|
Loading…
Reference in a new issue