From 7957896573edd0a26f4dc86a0eb2f85e89d77b49 Mon Sep 17 00:00:00 2001 From: smtddr Date: Sun, 18 Jan 2015 05:42:43 +0000 Subject: [PATCH] acctcreate returns next userid --- gamespy/gs_database.py | 12 ++++++++++++ nas_server.py | 1 + 2 files changed, 13 insertions(+) diff --git a/gamespy/gs_database.py b/gamespy/gs_database.py index f5d2e18..eec64b4 100644 --- a/gamespy/gs_database.py +++ b/gamespy/gs_database.py @@ -404,6 +404,18 @@ class GamespyDatabase(object): else: return json.loads(r["data"]) + def get_next_available_userid(self): + with Transaction(self.conn) as tx: + row = tx.queryone("SELECT max(userid) FROM users") + r = self.get_dict(row) + if r == None: + return '0000000000002'#Because all zeroes means Dolphin. Don't wanna get confused during debugging later. + else: + userid = str(int(json.loads(r['max(userid)'])) + 1) + while len(userid) < 13: + userid = "0"+userid + return userid + def generate_authtoken(self, userid, data): # Since the auth token passed back to the game will be random, we can make it small enough that there # should never be a crash due to the size of the token. diff --git a/nas_server.py b/nas_server.py index 3e845fd..994e858 100644 --- a/nas_server.py +++ b/nas_server.py @@ -102,6 +102,7 @@ class NasHTTPServerHandler(BaseHTTPServer.BaseHTTPRequestHandler): if action == "acctcreate": # TODO: test for duplicate accounts ret["returncd"] = "002" + ret['userid'] = self.server.db.get_next_available_userid() logger.log(logging.DEBUG, "acctcreate response to %s", self.client_address) logger.log(logging.DEBUG, ret)