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 login_profile_via_parsed_authtoken(authtoken_parsed, db): """Return login profile via parsed authtoken. authtoken_parsed MUST HAVE userid field and can't be None! """ if authtoken_parsed is None or 'userid' not in authtoken_parsed: return None, None, None, None 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 if "passwd" not in authtoken_parsed: console = 1 gamecd = authtoken_parsed['gamecd'] password = authtoken_parsed['gsbrcd'] gsbrcd = authtoken_parsed['gsbrcd'] gameid = gsbrcd[:4] macadr = authtoken_parsed['macadr'] 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, uniquenick) if valid_user is False: profileid = db.create_user(userid, password, email, uniquenick, gsbrcd, console, csnum, cfc, bssid, devname, birth, gameid, macadr, gamecd) else: profileid = db.perform_login(userid, password, gsbrcd, uniquenick) return userid, profileid, gsbrcd, uniquenick
def login_profile_via_parsed_authtoken(authtoken_parsed, db): """Return login profile via parsed authtoken. authtoken_parsed MUST HAVE userid field and can't be None! """ if authtoken_parsed is None or 'userid' not in authtoken_parsed: return None, None, None, None 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 if "passwd" not in authtoken_parsed: console = 1 password = authtoken_parsed['gsbrcd'] gsbrcd = authtoken_parsed['gsbrcd'] gameid = gsbrcd[:4] macadr = authtoken_parsed['macadr'] 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 is False: profileid = db.create_user(userid, password, email, uniquenick, gsbrcd, console, csnum, cfc, bssid, devname, birth, gameid, macadr) else: profileid = db.perform_login(userid, password, gsbrcd) return userid, profileid, gsbrcd, uniquenick
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 if not "passwd" in authtoken_parsed: console = 1 password = authtoken_parsed['gsbrcd'] 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 perform_login(self, data_parsed): 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 = "" # Verify the client's response valid_response = gs_utils.generate_response( self.challenge, authtoken_parsed['challenge'], data_parsed['challenge'], data_parsed['authtoken']) if data_parsed['response'] != valid_response: self.log( logging.ERROR, "ERROR: Got invalid response. Got %s, expected %s" % (data_parsed['response'], valid_response)) 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") if profileid != None: # Successfully logged in or created account, continue creating session. sesskey = self.db.create_session(profileid) self.sessions[profileid] = self msg_d = [] msg_d.append(('__cmd__', "lc")) msg_d.append(('__cmd_val__', "2")) msg_d.append(('sesskey', sesskey)) msg_d.append(('proof', proof)) msg_d.append(('userid', userid)) msg_d.append(('profileid', profileid)) msg_d.append(('uniquenick', uniquenick)) msg_d.append( ('lt', gs_utils.base64_encode(utils.generate_random_str(16))) ) # Some kind of token... don't know it gets used or generated, but it doesn't seem to have any negative effects if it's not properly generated. msg_d.append(('id', data_parsed['id'])) msg = gs_query.create_gamespy_message(msg_d) # Take the first 4 letters of gsbrcd instead of gamecd because they should be consistent across game # regions. For example, the US version of Metroid Prime Hunters has the gamecd "AMHE" and the first 4 letters # of gsbrcd are "AMHE". However, the Japanese version of Metroid Prime Hunters has the gamecd "AMHJ" with # the first 4 letters of bsbrcd as "AMHE". Tetris DS is the other way, with the first 4 letters as the # Japanese version (ATRJ) while the gamecd is region specific (ATRE for US and ATRJ for JP). # gameid is used to send all people on the player's friends list a status updates, so don't make it region # specific. self.gameid = gsbrcd[0:4] self.profileid = int(profileid) self.log(logging.DEBUG, "SENDING: %s" % msg) self.transport.write(bytes(msg)) self.buddies = self.db.get_buddy_list(self.profileid) self.blocked = self.db.get_blocked_list(self.profileid) # Get pending messages. self.get_pending_messages() # Send any friend statuses when the user logs in. # This will allow the user to see if their friends are hosting a game as soon as they log in. self.get_status_from_friends() self.send_status_to_friends()
def perform_login(self, data_parsed): 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 = "" # Verify the client's response valid_response = gs_utils.generate_response(self.challenge, authtoken_parsed['challenge'], data_parsed['challenge'], data_parsed['authtoken']) if data_parsed['response'] != valid_response: self.log(logging.ERROR, "ERROR: Got invalid response. Got %s, expected %s" % (data_parsed['response'], valid_response)) 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") if profileid != None: # Successfully logged in or created account, continue creating session. loginticket = gs_utils.base64_encode(utils.generate_random_str(16)) self.sesskey = self.db.create_session(profileid, loginticket) self.sessions[profileid] = self msg_d = [] msg_d.append(('__cmd__', "lc")) msg_d.append(('__cmd_val__', "2")) msg_d.append(('sesskey', self.sesskey)) msg_d.append(('proof', proof)) msg_d.append(('userid', userid)) msg_d.append(('profileid', profileid)) msg_d.append(('uniquenick', uniquenick)) msg_d.append(('lt', loginticket)) # Some kind of token... don't know it gets used or generated, but it doesn't seem to have any negative effects if it's not properly generated. msg_d.append(('id', data_parsed['id'])) msg = gs_query.create_gamespy_message(msg_d) # Take the first 4 letters of gsbrcd instead of gamecd because they should be consistent across game # regions. For example, the US version of Metroid Prime Hunters has the gamecd "AMHE" and the first 4 letters # of gsbrcd are "AMHE". However, the Japanese version of Metroid Prime Hunters has the gamecd "AMHJ" with # the first 4 letters of bsbrcd as "AMHE". Tetris DS is the other way, with the first 4 letters as the # Japanese version (ATRJ) while the gamecd is region specific (ATRE for US and ATRJ for JP). # gameid is used to send all people on the player's friends list a status updates, so don't make it region # specific. self.gameid = gsbrcd[0:4] self.profileid = int(profileid) self.log(logging.DEBUG, "SENDING: %s" % msg) self.transport.write(bytes(msg)) self.buddies = self.db.get_buddy_list(self.profileid) self.blocked = self.db.get_blocked_list(self.profileid) # Get pending messages. self.get_pending_messages() # Send any friend statuses when the user logs in. # This will allow the user to see if their friends are hosting a game as soon as they log in. self.get_status_from_friends() self.send_status_to_friends()
def perform_authp(self, data_parsed): authtoken_parsed = gs_utils.parse_authtoken(data_parsed['authtoken'], self.db) #print authtoken_parsed 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") if profileid != None: # Successfully logged in or created account, continue creating session. sesskey = self.db.create_session(profileid) self.sessions[profileid] = self msg_d = [] msg_d.append(('__cmd__', "pauthr")) msg_d.append(('__cmd_val__', profileid)) msg_d.append(('lid', self.lid)) msg = gs_query.create_gamespy_message(msg_d) self.profileid = int(profileid) self.log(logging.DEBUG, "SENDING: '%s'..." % msg) msg = self.crypt(msg) self.transport.write(bytes(msg)) else: # Return error pass