summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesusaves <cpntb1@ymail.com>2020-12-31 11:09:06 -0300
committerJesusaves <cpntb1@ymail.com>2020-12-31 11:09:06 -0300
commitb34aa7437e55577953a50b6a0e65debcb930f253 (patch)
tree11db0c47a2f6772644bf133ed7155746a197293e
parentc67dcb3dbaf3efb888d25e6c17f4d62b9ccedc12 (diff)
downloadserver-b34aa7437e55577953a50b6a0e65debcb930f253.tar.gz
server-b34aa7437e55577953a50b6a0e65debcb930f253.tar.bz2
server-b34aa7437e55577953a50b6a0e65debcb930f253.tar.xz
server-b34aa7437e55577953a50b6a0e65debcb930f253.zip
Registration failure now only gives 2 lame points.
This means each connection can attempt up to three registrations. Raise to 3 in case of attack :p
-rw-r--r--consts.py1
-rw-r--r--protocol.py2
-rw-r--r--security.py11
-rwxr-xr-xserver.py3
4 files changed, 14 insertions, 3 deletions
diff --git a/consts.py b/consts.py
index fd2f0ff..85ff644 100644
--- a/consts.py
+++ b/consts.py
@@ -130,6 +130,7 @@ ERR_OK =200
ERR_LOGIN =5000
# Packet result
+PACKET_REGX =-1
PACKET_NACK =0
PACKET_ACK =1
diff --git a/protocol.py b/protocol.py
index 44e647c..f6a2905 100644
--- a/protocol.py
+++ b/protocol.py
@@ -61,7 +61,7 @@ def parse(packet, conn):
elif data[1] == "register":
r=player.register(data[2], t)
if r is ERR_BAD:
- return [PACKET_NACK, "Invalid registration attempt"]
+ return [PACKET_REGX, "Invalid registration attempt"]
else:
return [PACKET_ACK, r]
diff --git a/security.py b/security.py
index 59a3efc..112f636 100644
--- a/security.py
+++ b/security.py
@@ -84,6 +84,17 @@ def unban_ip(ip):
stdout("%s is not banned." % (ip))
return
+def get_score(proto):
+ if (proto == PACKET_REGX):
+ return 2
+ elif proto == PACKET_NACK:
+ return 5
+ elif proto == PACKET_ACK:
+ return 0
+ else
+ stdout("\"%s\" is not a valid packet reply code" % str(proto))
+ return 0
+
def score(conn, score):
#print("Score request: %d" % score)
conn.MS_score += score
diff --git a/server.py b/server.py
index 7f22789..011ab4a 100755
--- a/server.py
+++ b/server.py
@@ -60,8 +60,7 @@ class WebSocketConn(WebSocket):
stdout("%s - %s" % (self.address[0], r[1]))
syslog.syslog(LOG_AUTH, "%s - %s" % (self.address[0], r[1]))
self.send_message("NACK\n")
- # FIXME: Parse the packet error score
- security.score(self, 5)
+ security.score(self, security.get_score(r[0]))
else:
self.send_message(r[1])
except: