diff options
-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: |