acctcreate returns next userid

This commit is contained in:
smtddr
2015-01-18 05:42:43 +00:00
parent af35d9fff1
commit 7957896573
2 changed files with 13 additions and 0 deletions

View File

@@ -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.

View File

@@ -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)