From 9882da3af32ebc45cee321d76204f18c4ae2ac1b Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Sun, 15 Jun 2014 22:29:33 +0200 Subject: [PATCH] Combine user login in profile and gamestats. --- gamespy/gs_utility.py | 35 +++++++++++++++++++++ gamespy_gamestats_server.py | 61 ++--------------------------------- gamespy_profile_server.py | 63 ++----------------------------------- 3 files changed, 40 insertions(+), 119 deletions(-) diff --git a/gamespy/gs_utility.py b/gamespy/gs_utility.py index 3b5d6a7..9fb39c0 100644 --- a/gamespy/gs_utility.py +++ b/gamespy/gs_utility.py @@ -71,6 +71,41 @@ def prepare_rc4_base64(_key, _data): def parse_authtoken(authtoken, db): return db.get_nas_login(authtoken) +def login_profile_via_parsed_authtoken(authtoken_parsed, db): + console = 0 + userid = authtoken_parsed['userid'] + + csnum = authtoken_parsed.get('csnum', '') # Wii: Serial number + cfc = authtoken_parsed.get('cfc', '') # Wii: Friend code + bssid = authtoken_parsed.get('bssid', '') # NDS: Wifi network's BSSID + devname = authtoken_parsed.get('devname', '') # NDS: Device name + birth = authtoken_parsed.get('birth', '') # NDS: User's birthday + + # The Wii does not use passwd, so take another uniquely generated string as the password. + if "passwd" in authtoken_parsed: + password = authtoken_parsed['passwd'] + else: + password = authtoken_parsed['gsbrcd'] + console = 1 + + gsbrcd = authtoken_parsed['gsbrcd'] + gameid = gsbrcd[:4] + uniquenick = utils.base32_encode(int(userid)) + gsbrcd + email = uniquenick + "@nds" # The Wii also seems to use @nds. + + if "csnum" in authtoken_parsed: + console = 1 + if "cfc" in authtoken_parsed: + console = 1 + + valid_user = db.check_user_exists(userid, gsbrcd) + if valid_user == False: + profileid = db.create_user(userid, password, email, uniquenick, gsbrcd, console, csnum, cfc, bssid, devname, birth, gameid) + else: + profileid = db.perform_login(userid, password, gsbrcd) + + return userid, profileid, gsbrcd, uniquenick + def generate_response(challenge, ac_challenge, secretkey, authtoken): md5 = hashlib.md5() md5.update(ac_challenge) diff --git a/gamespy_gamestats_server.py b/gamespy_gamestats_server.py index b84bcb0..90d36a1 100644 --- a/gamespy_gamestats_server.py +++ b/gamespy_gamestats_server.py @@ -163,65 +163,7 @@ class Gamestats(LineReceiver): if "lid" in data_parsed: self.lid = data_parsed['lid'] - # Track what console is connecting and save it in the database during user creation just in case we can use - # the information in the future. - console = 0 # 0 = NDS, 1 = Wii - - # get correct information - userid = authtoken_parsed['userid'] - - # The Wii does not use passwd, so take another uniquely generated string as the password. - if "passwd" in authtoken_parsed: - password = authtoken_parsed['passwd'] - else: - password = authtoken_parsed['gsbrcd'] - console = 1 - - gsbrcd = authtoken_parsed['gsbrcd'] - gameid = gsbrcd[:4] - uniquenick = utils.base32_encode(int(userid)) + gsbrcd - email = uniquenick + "@nds" # The Wii also seems to use @nds. - - # Wii: Serial number - if "csnum" in authtoken_parsed: - csnum = authtoken_parsed['csnum'] - console = 1 - else: - csnum = "" - - # Wii: Friend code - if "cfc" in authtoken_parsed: - cfc = authtoken_parsed['cfc'] - console = 1 - else: - cfc = "" - - # NDS: Wifi network's BSSID - if "bssid" in authtoken_parsed: - bssid = authtoken_parsed['bssid'] - else: - bssid = "" - - # NDS: Device name - if "devname" in authtoken_parsed: - devname = authtoken_parsed['devname'] - else: - devname = "" - - # NDS: User's birthday - if "birth" in authtoken_parsed: - birth = authtoken_parsed['birth'] - else: - birth = "" - - valid_user = self.db.check_user_exists(userid, gsbrcd) - profileid = None - if valid_user: - profileid = self.db.perform_login(userid, password, gsbrcd) - - if profileid == None: - # Handle case where the user is invalid - self.log(logging.ERROR, "Invalid password") + userid, profileid, gsbrcd, uniquenick = gs_utils.login_profile_via_parsed_authtoken(authtoken_parsed, self.db) if profileid != None: # Successfully logged in or created account, continue creating session. @@ -236,6 +178,7 @@ class Gamestats(LineReceiver): ]) else: # login failed + self.log(logging.WARNING, "Invalid password") msg = gs_query.create_gamespy_message([ ('__cmd__', "pauthr"), ('__cmd_val__', -3), diff --git a/gamespy_profile_server.py b/gamespy_profile_server.py index 1051c30..be28df1 100644 --- a/gamespy_profile_server.py +++ b/gamespy_profile_server.py @@ -179,57 +179,6 @@ class PlayerSession(LineReceiver): authtoken_parsed = gs_utils.parse_authtoken(data_parsed['authtoken'], self.db) #print authtoken_parsed - # Track what console is connecting and save it in the database during user creation just in case we can use - # the information in the future. - console = 0 # 0 = NDS, 1 = Wii - - # get correct information - userid = authtoken_parsed['userid'] - - # The Wii does not use passwd, so take another uniquely generated string as the password. - if "passwd" in authtoken_parsed: - password = authtoken_parsed['passwd'] - else: - password = authtoken_parsed['gsbrcd'] - console = 1 - - gsbrcd = authtoken_parsed['gsbrcd'] - gameid = gsbrcd[:4] - uniquenick = utils.base32_encode(int(userid)) + gsbrcd - email = uniquenick + "@nds" # The Wii also seems to use @nds. - - # Wii: Serial number - if "csnum" in authtoken_parsed: - csnum = authtoken_parsed['csnum'] - console = 1 - else: - csnum = "" - - # Wii: Friend code - if "cfc" in authtoken_parsed: - cfc = authtoken_parsed['cfc'] - console = 1 - else: - cfc = "" - - # NDS: Wifi network's BSSID - if "bssid" in authtoken_parsed: - bssid = authtoken_parsed['bssid'] - else: - bssid = "" - - # NDS: Device name - if "devname" in authtoken_parsed: - devname = authtoken_parsed['devname'] - else: - devname = "" - - # NDS: User's birthday - if "birth" in authtoken_parsed: - birth = authtoken_parsed['birth'] - else: - birth = "" - if 'sdkrevision' in data_parsed: self.sdkrevision = data_parsed['sdkrevision'] @@ -240,15 +189,7 @@ class PlayerSession(LineReceiver): proof = gs_utils.generate_proof(self.challenge, authtoken_parsed['challenge'], data_parsed['challenge'], data_parsed['authtoken']) - valid_user = self.db.check_user_exists(userid, gsbrcd) - if valid_user == False: - profileid = self.db.create_user(userid, password, email, uniquenick, gsbrcd, console, csnum, cfc, bssid, devname, birth, gameid) - else: - profileid = self.db.perform_login(userid, password, gsbrcd) - - if profileid == None: - # Handle case where the user is invalid - self.log(logging.ERROR, "Invalid password") + userid, profileid, gsbrcd, uniquenick = gs_utils.login_profile_via_parsed_authtoken(authtoken_parsed, self.db) if profileid != None: # Successfully logged in or created account, continue creating session. @@ -327,6 +268,8 @@ class PlayerSession(LineReceiver): # if profile != None: # self.statstring = profile['stat'] # self.locstring = profile['loc'] + else: + self.log(logging.WARNING, "Invalid password") def perform_logout(self, data_parsed): self.log(logging.INFO, "Session %s has logged off" % (data_parsed['sesskey']))