diff options
author | Jesusaves <cpntb1@ymail.com> | 2020-12-31 11:09:06 -0300 |
---|---|---|
committer | Jesusaves <cpntb1@ymail.com> | 2020-12-31 11:09:06 -0300 |
commit | b34aa7437e55577953a50b6a0e65debcb930f253 (patch) | |
tree | 11db0c47a2f6772644bf133ed7155746a197293e | |
parent | c67dcb3dbaf3efb888d25e6c17f4d62b9ccedc12 (diff) | |
download | server-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.py | 1 | ||||
-rw-r--r-- | protocol.py | 2 | ||||
-rw-r--r-- | security.py | 11 | ||||
-rwxr-xr-x | server.py | 3 |
4 files changed, 14 insertions, 3 deletions
@@ -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 @@ -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: |