コード例 #1
0
    def errback(self, data):
        '''
        Errback

        @param data:
        '''
        if isinstance(data, exceptions.ProxyAuthorizationRequiredException):
            if not self._sendCredentials:
                self._sendCredentials = True
                self.makeConnection()
                return
        self._client.errback(util.ErrorMessage(data.getErrorMessage()))
コード例 #2
0
    def joinGame(self, gameName):
        '''
        Attempt to join a game

        @param gameName: Game name
        '''
        if (self.mainwindow.hasJoinedGame(gameName)):
            self.error(
                util.ErrorMessage(_("You have already joined that game.")),
                True)
            return
        else:
            self.client.joinGame(gameName)
コード例 #3
0
ファイル: chat.py プロジェクト: ackeri/DCAP-Diamond
    def createGameHelper(self, gameId, options):
        if len(gameId) > constants.MAX_NAME_LENGTH:

            gobject.idle_add(
                self.error,
                util.ErrorMessage(
                    ServerMessage([
                        GAME_NAME_MUST_BE_LESS_THAN,
                        str(constants.MAX_NAME_LENGTH), CHARACTERS
                    ])))
            return

        alreadyExists = self.globalGamesSet.InSet(gameId)
        if not alreadyExists:
            game = ScrabbleGame(gameId, options)
            game.reset()
            game.setCreator(self.username)
            self.globalGamesSet.Add(gameId)
        if alreadyExists:
            gobject.idle_add(
                self.error,
                util.ErrorMessage(ServerMessage([GAME_ALREADY_EXISTS])))
コード例 #4
0
ファイル: chat.py プロジェクト: ackeri/DCAP-Diamond
 def joinGame(self, gameName):
     '''
     Attempt to join a game
     
     @param gameName: Game name
     '''
     if (self.mainwindow.hasJoinedGame(gameName)):
         self.error(
             util.ErrorMessage(_("You have already joined that game.")),
             True)
         return
     else:
         ReactiveManager.txn_execute(self.joinGameHelper, gameName)
コード例 #5
0
ファイル: chat.py プロジェクト: ackeri/DCAP-Diamond
 def spectateGame(self, button):
     '''
     Callback when 'Watch Game' button is clicked.  Send request to the server to watch the game.
     
     @param button: Button that was clicked to call this handler.
     '''
     
     self.setGameButtonsState(False)
     
     sel = self.gameView.get_selection()
     model, iter = sel.get_selected()
     if (iter == None):
         self.error(util.ErrorMessage(_("Please select a game to join.")),True)
         return
     
     gameName = model.get(iter, 0)[0]
     
     if (self.mainwindow.hasJoinedGame(gameName)):
         self.error(util.ErrorMessage(_("You have already joined that game.")),True)
         return
     else:
         self.client.spectateGame(gameName)
コード例 #6
0
 def createNewUserHelper(self, username, password):
     hashedPassword = util.hashPassword(password)
     
     users = DStringList();
     DStringList.Map(users, "global:users")
     
     if username.upper() in map(upper, users.Members()):
         self.error(util.ErrorMessage(ServerMessage([USER_ALREADY_EXISTS])))
     
     if username in constants.RESERVED_NAMES:
         self.error(util.ErrorMessage(ServerMessage([USERNAME_NOT_ALLOWED])))
     
     if (len(username) > constants.MAX_NAME_LENGTH):
         self.error(util.ErrorMessage(ServerMessage([USERNAME_MUST_BE_LESS_THAN])))
     
     users.Append(username)
     
     pwString = DString()
     DString.Map(pwString, "user:"******":hashedpw")
     pwString.Set(hashedPassword)
     
     gobject.idle_add(self.loginWindow.populateFields_cb, username, password, "DEBUG")
     gobject.idle_add(self.destroy)
コード例 #7
0
    def connect(self):
        '''
        Initiate the connection
        '''
        if (self.isUsingProxy()):
            self._proxyHost, port = self.getProxyHost().split(':')
            try:
                self._proxyPort = int(port)
            except ValueError:
                self._client.errback(
                    util.ErrorMessage(_("Proxy Host must be: Hostname:Port.")))
                return

        if self._user is None or self._password is None:
            self._sendCredentials = True
        self.makeConnection()
コード例 #8
0
ファイル: chat.py プロジェクト: ackeri/DCAP-Diamond
    def createGame(self, button, centerOption, rankedOption, showCountOption,
                   combo, timedOption, timeControl, limitOption, limitControl,
                   moveTimeOption, moveTimeControl):
        '''
        Create a game
        
        @param button: Widget that was clicked to activate this handler.
        @param centerOption: Option widget
        @param rankedOption: Option widget
        param showCountOption: Option widget
        @param combo: Rules widget
        @param timedOption: Time option
        @param timeControl: Time control widget
        @param limitOption: Time limit option
        @param limitControl: Time limit control
        @param moveTimeOption: Move time option
        @param moveTimeControl: Move time control
        '''

        gameId = self.createGameEntry.get_text()
        if len(gameId) == 0:
            self.error(
                util.ErrorMessage(
                    _("Please enter a Game ID of at least one character.")))
            return

        model = combo.get_model()
        iter = combo.get_active_iter()
        opt = model.get_value(iter, 1)

        options = {}
        options[lookup.OPTION_CENTER_TILE] = centerOption.get_active()
        options[lookup.OPTION_SHOW_COUNT] = showCountOption.get_active()
        options[lookup.OPTION_RANKED] = rankedOption.get_active()
        options[lookup.OPTION_RULES] = opt
        if timedOption.get_active():
            options[lookup.OPTION_TIMED_GAME] = long(
                timeControl.get_value_as_int())
        if limitOption.get_active():
            options[lookup.OPTION_TIMED_LIMIT] = long(
                limitControl.get_value_as_int())
        if moveTimeOption.get_active():
            options[lookup.OPTION_MOVE_TIME] = long(
                moveTimeControl.get_value_as_int())

        self.gamedialog.destroy()
        ReactiveManager.txn_execute(self.createGameHelper, gameId, options)
コード例 #9
0
ファイル: chat.py プロジェクト: ackeri/DCAP-Diamond
 def changePassword(self, button, oldpassword, password1, password2, dialog):
     '''
     Ask server to change password
     
     @param button: Widget that was clicked to activate this handler
     @param oldpassword: Old password widget
     @param password1: New Password widget
     @param password2: New Password Confirmation widget
     @param dialog: Change Password dialog widget
     '''
     
     if password1.get_text() != password2.get_text():
         self.error(util.ErrorMessage(_("Passwords don't match.")))
         return
     
     self.client.changePassword(util.hashPassword(oldpassword.get_text()), util.hashPassword(password1.get_text()))
     dialog.destroy()
コード例 #10
0
    def showBlankLetterDialog(self):
        '''
        Show a dialog box where the user can enter a blank letter

        @return: The letter the user entered or ""
        '''
        s = _("Blank Letter")
        dialog = gtk.Dialog(title="%s" % s,
                            parent=None,
                            buttons=(gtk.STOCK_OK, gtk.RESPONSE_OK,
                                     gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
        dialog.set_default_response(gtk.RESPONSE_OK)
        dialog.vbox.set_spacing(10)

        s = _("Enter value for Blank Letter")
        header = gtk.Label()
        header.set_markup("<b><big>%s:</big></b>" % s)
        dialog.vbox.pack_start(header)

        entry = gtk.Entry()
        entry.set_width_chars(5)
        entry.connect("key-press-event", self.blankDialogKeyPress_cb, dialog)
        dialog.vbox.pack_start(entry)

        dialog.show_all()
        response = dialog.run()

        ret = ""
        if response == gtk.RESPONSE_OK:
            data = unicode(entry.get_text(), 'utf-8')
            l = data.upper()

            if (not manager.LettersManager().isValidLetter(
                    self.gameOptions[OPTION_RULES], l)):
                self.error(
                    util.ErrorMessage(
                        _("Letter is not a valid scrabble letter")))
            else:
                ret = l

        dialog.destroy()
        return ret
コード例 #11
0
    def tradeLetters(self, button):
        '''
        Allow the user to trade letters in.  This counts as a turn

        @param button: Button that was clicked
        '''

        l = []
        for letter in self.letterBox.get_children():
            if isinstance(letter, GameLetter):
                if letter.get_active():
                    l.append(letter.getLetter())

        if len(l) > 0:
            self.client.tradeLetters(self.currentGameId, l)
        else:
            self.error(
                util.ErrorMessage(
                    _("Please Click on the Letters you wish to trade")))

        self.clearCurrentMove()
コード例 #12
0
    def get_protocol(self):
        '''
        Get the appropriate protocol
        '''
        o = manager.OptionManager()
        if (self.isUsingProxy()):
            type = self.getProxyType()
            if (type == OPTION_PROXY_HTTP):
                if not self._sendCredentials:
                    return protocol.ClientCreator(reactor, HttpProxyProtocol,
                                                  self, self._host, self._port,
                                                  None, None)
                else:
                    return protocol.ClientCreator(reactor, HttpProxyProtocol,
                                                  self, self._host, self._port,
                                                  self._user, self._password)
            else:
                self._client.errback(util.ErrorMessage(
                    _("Invalid proxy type")))

        return protocol.ClientCreator(reactor, DefaultProtocol, self)
コード例 #13
0
ファイル: chat.py プロジェクト: ackeri/DCAP-Diamond
 def joinGame_cb(self, button):
     '''
     Callback when 'Join Game' button is clicked.  Send request to the server to join the game.
     
     @param button: Button that was clicked to call this handler.
     '''
     self.setGameButtonsState(False)
     
     sel = self.gameView.get_selection()
     model, iter = sel.get_selected()
     if (iter == None):
         self.error(util.ErrorMessage(_("Please select a game to join.")), True)
         return
     
     # If the user clicks on one of the sub items, we need to get the root iter, which is the gameId
     parent = model.iter_parent(iter)
     if parent is not None:
         iter = parent
         
     gameName = model.get(iter, 0)[0]
     self.joinGame( gameName )
コード例 #14
0
    def defaultCallback(self, data):
        '''
        Callback from the Client Protocol.

        This is called whenever we receive data from the server.

        Parse the data into a Command object and figure out what to do with it

        @param data: Text data that was received from the server
        @see: L{pyscrabble.command.helper.helper.Command}
        '''

        # Callback to MainWindow, it should always be available.  Errors occur when the connection
        # to the server is lost.
        if (isinstance(data, Failure)):
            if isinstance(data.value,
                          error.ConnectionDone):  # Connection closed cleanly
                self.mainWin.stopReactor()
            else:
                self.mainWin.fatalError(
                    util.ErrorMessage("Connection to server has been lost"))
            return

        command = serialize.loads(data)

        if (isinstance(command, LoginCommand)):
            self.processLoginCommand(command)
            return

        if (isinstance(command, ChatCommand)):
            self.processChatCommand(command)
            return

        if (isinstance(command, GameCommand)):
            self.processGameCommand(command)
            return

        if (isinstance(command, PrivateMessageCommand)):
            self.processPrivateMessageCommand(command)
            return
コード例 #15
0
    def processGameCommand(self, command):
        '''
        Process a GameCommand

        @param command: GameCommand
        @see: L{pyscrabble.command.helper.GameCommand}
        '''

        try:
            if (command.getCommand() == GAME_GET_LETTERS):
                self.gameWins[command.getGameId()].showLetters(
                    command.getData())

            if (command.getCommand() == GAME_LIST):
                self.chatWin.showGameList(command.getData())

            if (command.getCommand() == GAME_USER_LIST):
                self.gameWins[command.getGameId()].refreshUserList(
                    command.getData())

            if (command.getCommand() == GAME_JOIN_OK):
                self.chatWin.newGame(command.getGameId(), False,
                                     command.getData())

            if (command.getCommand() == GAME_SPECTATE_JOIN_OK):
                self.chatWin.newGame(command.getGameId(), True,
                                     command.getData())

            if (command.getCommand() == GAME_JOIN_DENIED):
                self.chatWin.error(util.ErrorMessage(command.getData()), True)

            if (command.getCommand() == GAME_TURN_CURRENT):
                self.gameWins[command.getGameId()].setCurrentTurn(
                    command.getData())

            if (command.getCommand() == GAME_TURN_OTHER):
                self.gameWins[command.getGameId()].otherTurn(command.getData())

            if (command.getCommand() == GAME_ERROR):
                self.gameWins[command.getGameId()].error(
                    util.ErrorMessage(command.getData()))

            if (command.getCommand() == GAME_SEND_MOVE):
                self.gameWins[command.getGameId()].applyMoves(
                    command.getData())

            if (command.getCommand() == GAME_ACCEPT_MOVE):
                self.gameWins[command.getGameId()].acceptMove()

            if (command.getCommand() == GAME_INFO):
                #type, msg = command.getData()
                log = command.getData()
                #self.gameWins[command.getGameId()].info( type,msg )
                self.gameWins[command.getGameId()].info(log)

            if (command.getCommand() == GAME_LEAVE):
                self.gameWins[command.getGameId()].leaveGame(
                    None, clientLeaveGame=False, disableChat=command.getData())

            if (command.getCommand() == GAME_BOOT):
                self.gameWins[command.getGameId()].leaveGame(
                    None, clientLeaveGame=True, disableChat=True)

            if (command.getCommand() == GAME_PAUSE):
                self.gameWins[command.getGameId()].pauseGame()

            if (command.getCommand() == GAME_UNPAUSE):
                self.gameWins[command.getGameId()].unpauseGame()

            if (command.getCommand() == GAME_SPECTATOR_CHAT_SET):
                self.gameWins[command.getGameId()].enableSpectatorChat(
                    command.getData())

            if (command.getCommand() == GAME_SPECTATOR_SET):
                self.gameWins[command.getGameId()].enableSpectators(
                    command.getData())

            if (command.getCommand() == GAME_SEND_STATS):
                self.gameWins[command.getGameId()].refreshStats(
                    command.getData())

            if (command.getCommand() == GAME_BAG_EMPTY):
                self.gameWins[command.getGameId()].gameBagEmpty()

            if (command.getCommand() == GAME_SEND_SPECTATORS):
                self.gameWins[command.getGameId()].refreshSpecs(
                    command.getData())

            if (command.getCommand() == GAME_SEND_OPTIONS):
                self.gameWins[command.getGameId()].showOptions(
                    command.getData())

            if (command.getCommand() == GAME_OVER):
                self.gameWins[command.getGameId()].gameOver()

            if (command.getCommand() == GAME_DISTRIBUTION):
                self.gameWins[command.getGameId()].showDistribution(
                    command.getData())

        except KeyError:
            pass