diff options
-rw-r--r-- | security.py | 2 | ||||
-rwxr-xr-x | server.py | 16 |
2 files changed, 17 insertions, 1 deletions
diff --git a/security.py b/security.py index 0424712..b494542 100644 --- a/security.py +++ b/security.py @@ -73,7 +73,7 @@ def ban_ip(ip, until=INT_MAX): global blacklist blacklist.append([ip, until]) stdout("%s has been banned until %d." % (ip, until)) - # TODO: kick users when they are banned or klined + # TODO: kick users when they are banned or klined? return def unban_ip(ip): @@ -143,6 +143,16 @@ def sendmsg(m, t="raw"): c.send_message(msg) return +# Disconnect function +def disconnect(ip): + global clients + totaldc=0 + for c in clients: + if c.address[0] == ip: + c.close(status=1000, reason="Remote host closed connection.") + totaldc+=1 + return totaldc + ############################################################### # Begin stuff stdout("Starting at: T-%d" % (now())) @@ -164,6 +174,9 @@ try: sendmsg("NOTICE:" + com) elif cmd in ["ban", "nuke"]: security.ban_ip(com) + totaldc=disconnect(com) + stdout("BAN: Disconnected %d clients." % totaldc) + del totaldc elif cmd in ["unban"]: security.unban_ip(com) elif cmd in ["permaban", "block", "kline"]: @@ -172,6 +185,9 @@ try: f.write(com+"\n") f.close() stdout("%s has been K-Lined." % com) + totaldc=disconnect(com) + stdout("Disconnected %d clients." % totaldc) + del totaldc elif cmd in ["exit", "quit", "close", "term", "end"]: stdout("Preparing to close server...") sendmsg("NOTICE:Server is going down for scheduled maintenance. Please close, wait five minutes, and then re-open the app.") |