From 4835dc8a7792e135719558a1982354d9eb213a42 Mon Sep 17 00:00:00 2001 From: Jesusaves Date: Sat, 19 Dec 2020 17:12:38 -0300 Subject: Add token field to connection. Send connection to protocol parser. Add new constants for the results (non-boolean) so laterâ„¢ score can be smart. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- protocol.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'protocol.py') diff --git a/protocol.py b/protocol.py index 9f2154d..33ff203 100644 --- a/protocol.py +++ b/protocol.py @@ -21,20 +21,20 @@ import utils import player import battle.main as battle -from consts import ERR_BAD, ERR_DONE +from consts import ERR_BAD, ERR_DONE, PACKET_NACK, PACKET_ACK # self.data structure: ; ; -def parse(packet): +def parse(packet, conn): ########################################################################## # Maybe it is a RAW packet if (packet.lower() == "ping"): - return [True, "PONG"] + return [PACKET_ACK, "PONG"] ########################################################################## # Not a raw packet, so it must adhere to the convention data=packet.split(';') if (len(data) != 3): - return [False, "Invalid packet (RAW)"] + return [PACKET_NACK, "Invalid packet (RAW)"] t=data[0] ########################################################################## @@ -45,21 +45,22 @@ def parse(packet): t=utils.create_token() r=player.get_data(data[2], t) if r is ERR_BAD: - return [False, "Login error"] + return [PACKET_NACK, "Login error"] else: - return [True, r] + conn.token = t + return [PACKET_ACK, r] elif data[1] == "register": r=player.register(data[2], t) if r is ERR_BAD: - return [False, "Invalid registration attempt"] + return [PACKET_NACK, "Invalid registration attempt"] else: - return [True, r] + return [PACKET_ACK, r] ########################################################################## # It is not, so Validate token format print("Data0: %s | Alpnum: %s" % (str(data[0]), str(data[0].isalnum()) )) if not data[0].isalnum(): - return [False, "Invalid packet (TOKENF)"] + return [PACKET_NACK, "Invalid packet (TOKENF)"] # TODO: Now validate the token itself @@ -76,7 +77,7 @@ def parse(packet): try: r=battle.reload_battle(t) except: - r=[True, "CANCELLED"] + r=[PACKET_ACK, "CANCELLED"] elif data[1] == "begin_quest": r=battle.begin_quest(data[2], t) elif data[1] == "get_party": @@ -85,7 +86,7 @@ def parse(packet): r=ERR_BAD if r == ERR_BAD: - return [True, "ACK"] + return [PACKET_NACK, "Invalid Protocol (400)"] else: - return [True, r] + return [PACKET_ACK, r] -- cgit v1.2.3-70-g09d2