summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesusaves <cpntb1@ymail.com>2020-12-27 22:22:52 -0300
committerJesusaves <cpntb1@ymail.com>2020-12-27 22:22:52 -0300
commit636cb4deb4b82ed88ce608cb9f45c59e77614a9d (patch)
tree84bc89bd90e3722c53c5dbdf341907e7ce822704
parentddbf494719658dbb421401f2bdc2429db0df5a2d (diff)
downloadserver-636cb4deb4b82ed88ce608cb9f45c59e77614a9d.tar.gz
server-636cb4deb4b82ed88ce608cb9f45c59e77614a9d.tar.bz2
server-636cb4deb4b82ed88ce608cb9f45c59e77614a9d.tar.xz
server-636cb4deb4b82ed88ce608cb9f45c59e77614a9d.zip
Manually casting ban or kline will now disconnect sessions as well
-rw-r--r--security.py2
-rwxr-xr-xserver.py16
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):
diff --git a/server.py b/server.py
index f57f02f..fa3b240 100755
--- a/server.py
+++ b/server.py
@@ -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.")