def __eq__(self, other): ''' Check if this Letter equals another Letter. @param other: Other letter @return: True if the Letter strings are the same ''' if isinstance(other, Letter): a = util.getUnicode(self.getLetter()) b = util.getUnicode(other.getLetter()) if a == b: return True return False
def getUsername(self): ''' @return: Player's username ''' return util.getUnicode(self.username)
def clickLogin(self, widget, data=None): ''' Callback when the user clicks the login button. @param widget: Button that was clicked @param data: ''' username = util.getUnicode(self.username.get_text()) password = util.hashPassword(self.password.get_text()) if (self.hostname.get_child().get_text().find(':') == -1): self.error( util.ErrorMessage(_("Hostname value must be hostname:port."))) return (host, port) = self.hostname.get_child().get_text().split(':') try: port = int(port) except ValueError: self.error(util.ErrorMessage(_("Port must be a number."))) return self.client = ScrabbleClient(host, port, self) self.client.login(username, password, VERSION) widget.set_sensitive(False)
def getUsername(self): ''' @return: Username ''' return util.getUnicode(self.username)
def loginOK(self): ''' Callback from server if the user is authenticated. Start the MainWindow ''' h = self.hostname.get_child().get_text() if h not in self.history: self.history.append(h) r = manager.ResourceManager() history_file = file(r["config"][SERVER_HISTORY], 'w+') for host in self.history: history_file.write('%s\n' % host) history_file.close() o = manager.OptionManager() if o.get_default_bool_option(OPTION_SAVE_LOGIN, True): o.set_option(OPTION_SAVE_UNAME, self.username.get_text()) o.set_option(OPTION_SAVE_PWORD, self.password.get_text()) o.set_option(OPTION_SAVE_HOST, h) MainWindow(self.client, util.getUnicode(self.username.get_text())) self.destroy()
def clickLogin(self, widget, data=None): ''' Callback when the user clicks the login button. @param widget: Button that was clicked @param data: ''' username = util.getUnicode(self.username.get_text()) password = util.hashPassword( self.password.get_text() ) if (self.hostname.get_child().get_text().find(':') == -1): self.error(util.ErrorMessage(_("Hostname value must be hostname:port."))) return (host, port) = self.hostname.get_child().get_text().split(':') try: port = int(port) except ValueError: self.error(util.ErrorMessage(_("Port must be a number."))) return self.client = ScrabbleClient(host, port, self) self.client.login( username, password, VERSION ) widget.set_sensitive(False)
def requestUserInfo(self, widget, username): ''' Request user information @param widget: Widget that activated this callback @param username: Username ''' self.client.requestUserInfo(util.getUnicode(username))
def __eq__(self, other): ''' Check if this Letter equals another Letter. @param other: Other letter @return: True if the Letter strings are the same ''' if isinstance(other, Letter): a = util.getUnicode(self.getLetter()) b = util.getUnicode(other.getLetter()) if a == b: return True elif ((a != b) and (self.isBlank() == True and other.isBlank() == True)): return True return False
def sendPrivateMessage(self, widget, username, data=None): u = util.getUnicode(username) if not self.messages.has_key(u): self.createPrivateMessageWindow(u) if data is not None: self.messages[u].receiveChatMessage(data)
def getUser(self, username): ''' Get a user @param username: Username @return: User obect or not ''' u = util.getUnicode(username) if self.db.users.has_key(u): return self.db.users[u] else: return None
def privateMessage(self, recipient, message): ''' Current user sends a private message @param recipient: Username of recipient @param message: Message text ''' command = self.command.createPrivateMessageCommand( '', util.getUnicode(recipient), message) self.defer.addCallbacks(self.sendCommand, callbackArgs=[command], errback=self.chatWin.error)
def authenticate(self, username, password): ''' Authenticate a user @param username: @param password: ''' u = util.getUnicode(username) if self.db.users.has_key(u): user = self.db.users[u] if user.getPassword() == password: return True return False
def gameSendMove(self, gameId, onboard, moves, client): ''' User sends moves to the game @param gameId: Game ID @param onboard: Move containing letters put on the board @param moves: List of Moves formed @param client: ScrabbleServer Protocol ''' game = self.gameList[gameId] player = game.getPlayer(self.clients[client]) if not player == game.getCurrentPlayer(): return if (game.isPaused()): client.gameError(gameId, ServerMessage([MOVE_GAME_PAUSED])) return if (not game.isInProgress()): client.gameError(gameId, ServerMessage([NOT_IN_PROGRESS])) return # Validate word in dictionary and not on the board alread words = [] for move in moves: word = util.getUnicode(move.getWord()) if word not in self.dicts['en']: client.gameError(gameId, ServerMessage([word, NOT_IN_DICT])) return words.append(word) client.acceptMove(gameId) score = self.getMovesScore(game, moves) letters = self.getLettersFromMove(onboard) player.removeLetters(letters) player.addScore(score) self.removeModifiers(game, moves) game.addMoves(moves, player) game.resetPassCount() # If the player used all 7 of his/her letters, give them an extra 50 if onboard.length() == 7: player.addScore(constants.BINGO_BONUS_SCORE) for p in game.getPlayers(): c = self.getPlayerClient(p) c.sendMoves(gameId, moves) # If the player used all his/her letters and there are no more letters in the bag, the game is over if (len(player.getLetters()) == 0 and game.isBagEmpty()): # Subtract everyones letter points # Give points to the person who went out players = game.getPlayers() for p in players: if p == player: continue # Skip winner letters = p.getLetters() for letter in letters: p.addScore(letter.getScore() * -1) player.addScore(letter.getScore()) self.sendGameScores(game.getGameId()) self.gameOver(game) return letters = game.getLetters(player.getNumberOfLettersNeeded()) if (len(letters) > 0): player.addLetters(letters) client.sendLetters(gameId, player.getLetters()) self.sendGameScores(game.getGameId()) if game.isBagEmpty() or game.getCountLetters() < 7: for p in game.getPlayers(): c = self.getPlayerClient(p) c.gameBagEmpty(gameId) # Next player self.doGameTurn(gameId)