def getCurrentPlayer(self): ''' Get current player @return: Player who has control of the board. @see: L{pyscrabble.game.player.Player} ''' return Player(self.currentPlayer.Value())
def getPlayer(self, player): ''' Get a player out of the game @param player: Player @return: Player in the game, or None if player is not in the game. @see: L{pyscrabble.game.player.Player} ''' for _playerName in self.players.Members(): if player.getUsername() == _playerName: return Player(_playerName, self.name) return None
def getPlayers(self): ''' Return a copy of the list of Players @return: List of Players @see: L{pyscrabble.game.player.Player} ''' #return self.players.Members() result = [] for playerName in self.players.Members(): result.append(Player(playerName, self.name)) return result
def getNextPlayer(self): ''' Get the next player who has control of the board. @return: Next Player who has control of the board. @see: L{pyscrabble.game.player.Player} ''' if (self.players.Size() == 0): return None self.currentPlayer.Set(self.players.Value(0)) self.players.Erase(0) self.players.Append(self.currentPlayer.Value()) return Player(self.currentPlayer.Value())
def handleLoginCommand(self, command): ''' Handle a login command Callback to the Factory to authenticate the user @param command: LoginCommand @see: L{pyscrabble.command.helper.LoginCommand} ''' if (command.getCommand() == constants.LOGIN_INIT): # Check version version = command.getData() if (version is '' or version < constants.REQUIRED_VERSION): command.setCommand(constants.LOGIN_DENIED) command.setData( ServerMessage([REQ_VERSION, constants.REQUIRED_VERSION])) else: player = Player(command.getUsername()) if (self.factory.authenticate(command.getUsername(), command.getPassword())): if (self.factory.isLoggedIn(player)): c = self.factory.getPlayerClient(player) if c is not None: self.factory.removeClient(c) c.transport.loseConnection() self.username = command.getUsername() command.setCommand(constants.LOGIN_OK) self.factory.loginUser(player, self) else: command.setData(ServerMessage([INVALID_USERNAME_PASSWORD])) command.setCommand(constants.LOGIN_DENIED) self.writeCommand(command) if (command.getCommand() == constants.NEW_USER): self.factory.createNewUser(command, self) return
def dec_player_type(data): obj = Player() obj.__dict__ = dec_dict_type(data) return obj