def registerPlayer(self, client, playerData): playerId = playerData['_id'] # See if playerId is in game. candidatePlayer = self.getPlayerById(playerId) if candidatePlayer: # If candidate is linkdead, reconnect if candidatePlayer.isLinkdead(): print '{name} has reconnected.'.format(name=candidatePlayer.name) candidatePlayer.client = client candidatePlayer.sendToClient('Reconnecting.') candidatePlayer.linkdead = 0 for mobile in [mobile for mobile in self.mobiles if mobile is not candidatePlayer]: mobile.sendToClient('@g{name} has reconnected.@x'.format(name=candidatePlayer.getName(mobile))) # And return candidatePlayer to attach to the browser return candidatePlayer else: return False else: # Make a new mobile name = playerData['name'].capitalize() stats = playerData['stats'] if 'stats' in playerData else {} newMobile = Mobile(name, self, {'stats': stats}) newMobile.client = client newMobile.is_player = True self.mobiles.append(newMobile) newMobile.id = playerId if 'room' in playerData: newMobile.room = self.rooms[playerData['room']] else: newMobile.room = self.rooms[0] if 'stats' in playerData: for stat in playerData['stats']: newMobile.stats[stat] = playerData['stats'][stat] newMobile.sendToClient('@uWelcome to Redemption, {name}@x.'.format(name=newMobile.name)) for mobile in [mobile for mobile in self.mobiles if mobile is not newMobile]: mobile.sendToClient('@g{name} has connected.@x'.format(name=newMobile.getName(mobile))) return newMobile
def registerPlayer(self, client, playerData): playerId = playerData['_id'] # See if playerId is in game. candidatePlayer = self.getPlayerById(playerId) if candidatePlayer: # If candidate is linkdead, reconnect if candidatePlayer.isLinkdead(): print 'Reconnecting to player {name}'.format(name=candidatePlayer.name) candidatePlayer.client = client candidatePlayer.sendToClient('Reconnecting.') candidatePlayer.processCommand('look') candidatePlayer.linkdead = 0 # And return candidatePlayer to attach to the browser return candidatePlayer else: return False else: # Make a new mobile name = playerData['name'] newMobile = Mobile(name, self, {'charClass': 'warrior'}) newMobile.client = client self.mobiles.append(newMobile) newMobile.id = playerId if 'room' in playerData: newMobile.room = self.rooms[playerData['room']] else: newMobile.room = self.rooms[0] if 'stats' in playerData: for stat in playerData['stats']: newMobile.stats[stat] = playerData['stats'][stat] newMobile.sendToClient('@uWelcome to Redemption, {name}@x.'.format(name=newMobile.name)) return newMobile