diff options
Diffstat (limited to 'protocol.py')
-rw-r--r-- | protocol.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/protocol.py b/protocol.py index 33ff203..5401e1c 100644 --- a/protocol.py +++ b/protocol.py @@ -26,18 +26,23 @@ from consts import ERR_BAD, ERR_DONE, PACKET_NACK, PACKET_ACK # self.data structure: <Token> ; <Message> ; <JSON Arguments> def parse(packet, conn): ########################################################################## - # Maybe it is a RAW packet + # Maybe it is a DEBUG packet if (packet.lower() == "ping"): return [PACKET_ACK, "PONG"] ########################################################################## - # Not a raw packet, so it must adhere to the convention + # Not a debug packet, so it must adhere to the convention data=packet.split(';') if (len(data) != 3): return [PACKET_NACK, "Invalid packet (RAW)"] t=data[0] ########################################################################## + # Maybe it is a raw packet which doesn't requires auth + if (data[1] == "PING"): + return [PACKET_ACK, "PONG"] + + ########################################################################## # Maybe it is an honest login attempt, or a registration attempt if data[1] == "login": # TODO: Create a token @@ -63,6 +68,8 @@ def parse(packet, conn): return [PACKET_NACK, "Invalid packet (TOKENF)"] # TODO: Now validate the token itself + if data[0] != conn.token: + return [PACKET_NACK, "Invalid packet (TOKENC)"] ########################################################################## # Top level protocols |