Remove useless stat, implement a /stats command

This commit is contained in:
Firepup Sixfifty 2024-07-16 17:44:02 +00:00
parent 2fefe27858
commit d4b0aa11d9
Signed by: Firepup650
SSH key fingerprint: SHA256:U0Zp8EhEe3CMqFSrC79CqatzaEiL4sjta80/RSX2XrY

View file

@ -9,7 +9,6 @@ class Globals: ...
G = Globals() G = Globals()
G.uniqueClients = 0 G.uniqueClients = 0
G.serverLinks = 0
G.servers = {} G.servers = {}
G.clientsConnected = {} G.clientsConnected = {}
port = 65048 port = 65048
@ -155,9 +154,22 @@ async def handleClient(reader, writer):
/afk [reason] - Optional reason, short hand for `/me is afk [to [reason]]` /afk [reason] - Optional reason, short hand for `/me is afk [to [reason]]`
/h, /help - Triggers this command listing /h, /help - Triggers this command listing
/back - Shorthand for `/me is back` /back - Shorthand for `/me is back`
/stats - Sends you some server stats
/quit - Disconnects you from the server\n""" /quit - Disconnects you from the server\n"""
) )
await writer.drain() await writer.drain()
elif request.startswith("/stats"):
writer.write(
f"""Server stats:
Linked servers: {len(G.servers)}
Connected clients: {G.uniqueClients}
Total Clients: {len(G.connectedClients)}
Messages sent: {len(msgs)}
Please note that this is not network level statistics.\n""".encode(
"utf8"
)
)
elif request.startswith("/quit"): elif request.startswith("/quit"):
break break
elif request.startswith("/afk"): elif request.startswith("/afk"):
@ -207,7 +219,6 @@ async def handleClient(reader, writer):
await writer.wait_closed() await writer.wait_closed()
return # drop "us" return # drop "us"
G.msgs.append(log(f"{sName} has linked to the network")) G.msgs.append(log(f"{sName} has linked to the network"))
G.serverLinks += 1
G.servers[sName] = {} G.servers[sName] = {}
msgIndex = 0 msgIndex = 0
writer.write(b"I am awaiting your client listing.\n") writer.write(b"I am awaiting your client listing.\n")
@ -342,7 +353,6 @@ async def handleClient(reader, writer):
G.msgs.append(log(f"{cName}'s server is going down")) G.msgs.append(log(f"{cName}'s server is going down"))
G.S2SLogs.append(("-", cName, sName)) G.S2SLogs.append(("-", cName, sName))
del G.clientsConnected[cName.lower()] del G.clientsConnected[cName.lower()]
G.serverLinks -= 1
del G.servers[sName] del G.servers[sName]
G.msgs.append(log(f"{sName} has de-linked from the network")) G.msgs.append(log(f"{sName} has de-linked from the network"))
except ( except (
@ -363,7 +373,6 @@ async def handleClient(reader, writer):
G.S2SLogs.append(("-", cName, name[4:])) G.S2SLogs.append(("-", cName, name[4:]))
except Exception: # Crash during connection sequence? except Exception: # Crash during connection sequence?
pass pass
G.serverLinks -= 1
del G.servers[name[4:]] del G.servers[name[4:]]
G.msgs.append(log(f"{name[4:]} has de-linked from the network")) G.msgs.append(log(f"{name[4:]} has de-linked from the network"))
@ -400,7 +409,6 @@ async def connectServer(hostname: str, port: int):
await writer.wait_closed() await writer.wait_closed()
return return
G.msgs.append(log(f"{rID} has linked to the network")) G.msgs.append(log(f"{rID} has linked to the network"))
G.serverLinks += 1
G.servers[rID] = {} G.servers[rID] = {}
writer.write(b"I recieved your remote ID, now awaiting client listing\n") writer.write(b"I recieved your remote ID, now awaiting client listing\n")
await writer.drain() await writer.drain()
@ -513,7 +521,6 @@ async def connectServer(hostname: str, port: int):
for cName in G.servers[rID]: for cName in G.servers[rID]:
G.msgs.append(log(f"{cName}'s server is going down")) G.msgs.append(log(f"{cName}'s server is going down"))
del G.clientsConnected[cName.lower()] del G.clientsConnected[cName.lower()]
G.serverLinks -= 1
del G.servers[rID] del G.servers[rID]
G.msgs.append(log(f"{rID} has de-linked from the network")) G.msgs.append(log(f"{rID} has de-linked from the network"))
except (ConnectionResetError, BrokenPipeError, IndexError): except (ConnectionResetError, BrokenPipeError, IndexError):
@ -523,7 +530,6 @@ async def connectServer(hostname: str, port: int):
del G.clientsConnected[cName.lower()] del G.clientsConnected[cName.lower()]
except Exception: except Exception:
pass pass
G.serverLinks -= 1
del G.servers[rID] del G.servers[rID]
G.msgs.append(log(f"{rID} has de-linked from the network")) G.msgs.append(log(f"{rID} has de-linked from the network"))