Example #1
0
 def handle_update(self, message):
     update = message["update"]
     if not util.developer():
         logger.warn("Server says that Updating is needed.")
         self.progress.close()
         self.state = ClientState.OUTDATED
         fa.updater.fetchClientUpdate(update)
Example #2
0
 def handle_update(self, message):
     update = message["update"]
     if not util.developer():
         logger.warn("Server says that Updating is needed.")
         self.progress.close()
         self.state = ClientState.OUTDATED
         fa.updater.fetchClientUpdate(update)        
Example #3
0
    def writeToServer(self, action, *args, **kw):
        '''
        This method is the workhorse of the client, and is used to send messages, queries and commands to the server.
        '''
        logger.debug("Client: " + action)

        block = QtCore.QByteArray()
        out = QtCore.QDataStream(block, QtCore.QIODevice.ReadWrite)
        out.setVersion(QtCore.QDataStream.Qt_4_2)

        out.writeUInt32(0)
        out.writeQString(action)

        for arg in args:
            if type(arg) is IntType:
                out.writeInt(arg)
            elif isinstance(arg, basestring):
                out.writeQString(arg)
            elif type(arg) is FloatType:
                out.writeFloat(arg)
            elif type(arg) is ListType:
                out.writeQVariantList(arg)
            elif type(arg) is DictType:
                out.writeQString(json.dumps(arg))
            elif type(arg) is QtCore.QFile:
                arg.open(QtCore.QIODevice.ReadOnly)
                fileDatas = QtCore.QByteArray(arg.readAll())
                #seems that that logger doesn't work
                #logger.debug("file size ", int(fileDatas.size()))
                out.writeInt(fileDatas.size())
                out.writeRawData(fileDatas)

                # This may take a while. We display the progress bar so the user get a feedback
                self.sendFile = True
                self.progress.setLabelText("Sending file to server")
                self.progress.setCancelButton(None)
                self.progress.setWindowFlags(QtCore.Qt.CustomizeWindowHint
                                             | QtCore.Qt.WindowTitleHint)
                self.progress.setAutoClose(True)
                self.progress.setMinimum(0)
                self.progress.setMaximum(100)
                self.progress.setModal(1)
                self.progress.setWindowTitle("Uploading in progress")

                self.progress.show()
                arg.close()
            else:
                logger.warn("Uninterpreted Data Type: " + str(type(arg)) +
                            " sent as str: " + str(arg))
                out.writeQString(str(arg))

        out.device().seek(0)
        out.writeUInt32(block.size() - 4)
        self.bytesToSend = block.size() - 4

        self.socket.write(block)
Example #4
0
    def writeToServer(self, action, *args, **kw):
        '''
        This method is the workhorse of the client, and is used to send messages, queries and commands to the server.
        '''
        logger.debug("Client: " + action)
        
        block = QtCore.QByteArray()
        out = QtCore.QDataStream(block, QtCore.QIODevice.ReadWrite)
        out.setVersion(QtCore.QDataStream.Qt_4_2)

        out.writeUInt32(0)
        out.writeQString(action)
   
        
        for arg in args :
            if type(arg) is IntType:
                out.writeInt(arg)
            elif isinstance(arg, basestring):
                out.writeQString(arg)
            elif type(arg) is FloatType:
                out.writeFloat(arg)
            elif type(arg) is ListType:
                out.writeQVariantList(arg)
            elif type(arg) is DictType:
                out.writeQString(json.dumps(arg))                                
            elif type(arg) is QtCore.QFile :       
                arg.open(QtCore.QIODevice.ReadOnly)
                fileDatas = QtCore.QByteArray(arg.readAll())
                #seems that that logger doesn't work
                #logger.debug("file size ", int(fileDatas.size()))
                out.writeInt(fileDatas.size())
                out.writeRawData(fileDatas)

                # This may take a while. We display the progress bar so the user get a feedback
                self.sendFile = True
                self.progress.setLabelText("Sending file to server")
                self.progress.setCancelButton(None)
                self.progress.setWindowFlags(QtCore.Qt.CustomizeWindowHint | QtCore.Qt.WindowTitleHint)
                self.progress.setAutoClose(True)
                self.progress.setMinimum(0)
                self.progress.setMaximum(100)
                self.progress.setModal(1)
                self.progress.setWindowTitle("Uploading in progress")
 
                self.progress.show()
                arg.close()
            else:
                logger.warn("Uninterpreted Data Type: " + str(type(arg)) + " sent as str: " + str(arg))
                out.writeQString(str(arg))

        out.device().seek(0)        
        out.writeUInt32(block.size() - 4)
        self.bytesToSend = block.size() - 4
    
        self.socket.write(block)
Example #5
0
    def disconnectedFromServer(self):
        logger.warn("Disconnected from lobby server.")
        
        if self.state == ClientState.ACCEPTED:
            QtGui.QMessageBox.warning(QtGui.QApplication.activeWindow(), "Disconnected from Galactic War", "The lobby lost the connection to the Galactic War server.<br/><b>You might still be able to chat.<br/>To play, try reconnecting a little later!</b>", QtGui.QMessageBox.Close)
            self.initDone   = False
            self.client.mainTabs.setCurrentIndex(0)

            self.client.mainTabs.setTabEnabled(self.client.mainTabs.indexOf(self.client.galacticwarTab  ), False)
            self.client.mainTabs.setTabText(self.client.mainTabs.indexOf(self.client.galacticwarTab  ), "offline")
                
        self.state = ClientState.DROPPED             
Example #6
0
    def doLogin(self):
        """ login in the GW server 
            We are using the main login and session to check legitimity of the client.
        """

        self.progress.setLabelText("Gating in...")
        self.progress.reset()
        self.progress.show()

        logger.info("Attempting to gate as: " + str(self.client.login))
        self.state = ClientState.NONE

        self.send(
            dict(
                command="hello",
                version=util.VERSION_STRING,
                port=self.client.gamePort,
                login=self.client.login,
                session=self.client.session,
            )
        )

        while (not self.state) and self.progress.isVisible():
            QtGui.QApplication.processEvents()

        if self.progress.wasCanceled():
            logger.warn("Gating aborted by user.")
            return False

        self.progress.close()

        if self.state == ClientState.ACCEPTED:
            logger.info("Gating accepted.")
            self.progress.close()
            self.client.actionGalacticWar.triggered.connect(self.updateOptions)
            self.client.actionGalacticWar.setEnabled(True)
            return True
            # self.connected.emit()

        elif self.state == ClientState.REJECTED:
            logger.warning("Gating rejected.")
            return False
        else:
            # A more profound error has occurrect (cancellation or disconnection)
            return False
Example #7
0
    def finishRequest(self, reply):
        filename = reply.url().toString().rsplit('/',1)[1]
        root, _ = os.path.splitext(filename)
        
        toFile = os.path.join(GW_TEXTURE_DIR, filename)
        writeFile = QtCore.QFile(toFile)
        if(writeFile.open(QtCore.QIODevice.WriteOnly)) :
                writeFile.write(reply.readAll())
                writeFile.close()                
        else:
            logger.warn("%s is not writeable in in %s. Skipping." % (filename, GW_TEXTURE_DIR))

        if root in self.texturelist :
            del self.texturelist[root]
            
        if len(self.texturelist) == 0:
            self.setup()
            self.progress.close()
Example #8
0
    def finishRequest(self, reply):
        filename = reply.url().toString().rsplit('/', 1)[1]
        root, _ = os.path.splitext(filename)

        toFile = os.path.join(GW_TEXTURE_DIR, filename)
        writeFile = QtCore.QFile(toFile)
        if (writeFile.open(QtCore.QIODevice.WriteOnly)):
            writeFile.write(reply.readAll())
            writeFile.close()
        else:
            logger.warn("%s is not writeable in in %s. Skipping." %
                        (filename, GW_TEXTURE_DIR))

        if root in self.texturelist:
            del self.texturelist[root]

        if len(self.texturelist) == 0:
            self.setup()
            self.progress.close()
Example #9
0
    def doLogin(self):
        ''' login in the GW server 
            We are using the main login and session to check legitimity of the client.
        '''

        self.progress.setLabelText("Gating in...")
        self.progress.reset()
        self.progress.show()

        logger.info("Attempting to gate as: " + str(self.client.login))
        self.state = ClientState.NONE

        self.send(
            dict(command="hello",
                 version=util.VERSION_STRING,
                 port=self.client.gamePort,
                 login=self.client.login,
                 session=self.client.session))

        while (not self.state) and self.progress.isVisible():
            QtGui.QApplication.processEvents()

        if self.progress.wasCanceled():
            logger.warn("Gating aborted by user.")
            return False

        self.progress.close()

        if self.state == ClientState.ACCEPTED:
            logger.info("Gating accepted.")
            self.progress.close()
            self.client.actionGalacticWar.triggered.connect(self.updateOptions)
            self.client.actionGalacticWar.setEnabled(True)
            return True
            #self.connected.emit()

        elif self.state == ClientState.REJECTED:
            logger.warning("Gating rejected.")
            return False
        else:
            # A more profound error has occurrect (cancellation or disconnection)
            return False
Example #10
0
    def doConnect(self):
        logger.debug("Connecting to server")
        if self.client.state == ClientState.ACCEPTED:

            self.progress.setCancelButtonText("Cancel")
            self.progress.setWindowFlags(QtCore.Qt.CustomizeWindowHint
                                         | QtCore.Qt.WindowTitleHint)
            self.progress.setAutoClose(False)
            self.progress.setAutoReset(False)
            self.progress.setModal(1)
            self.progress.setWindowTitle("Galactic War Network...")
            self.progress.setLabelText("Gating in ...")
            self.progress.show()

            #            self.login = self.client.login.strip()
            #            logger.info("Attempting to gate as: " + str(self.client.login))
            self.state = ClientState.NONE

            # Begin connecting.
            self.socket.connectToHost(LOBBY_HOST, LOBBY_PORT)

            while (self.socket.state() !=
                   QtNetwork.QAbstractSocket.ConnectedState
                   ) and self.progress.isVisible():
                QtGui.QApplication.processEvents()

    #        #Perform Version Check first
            if not self.socket.state(
            ) == QtNetwork.QAbstractSocket.ConnectedState:

                self.progress.close()  # in case it was still showing...
                # We either cancelled or had a TCP error, meaning the connection failed..
                if self.progress.wasCanceled():
                    logger.warn("doConnect() aborted by user.")
                else:
                    logger.error("doConnect() failed with clientstate " +
                                 str(self.state) + ", socket errorstring: " +
                                 self.socket.errorString())
                return False
            else:

                return True
Example #11
0
    def disconnectedFromServer(self):
        logger.warn("Disconnected from lobby server.")

        if self.state == ClientState.ACCEPTED:
            QtGui.QMessageBox.warning(
                QtGui.QApplication.activeWindow(),
                "Disconnected from Galactic War",
                "The lobby lost the connection to the Galactic War server.<br/><b>You might still be able to chat.<br/>To play, try reconnecting a little later!</b>",
                QtGui.QMessageBox.Close)
            self.initDone = False
            self.client.mainTabs.setCurrentIndex(0)

            self.client.mainTabs.setTabEnabled(
                self.client.mainTabs.indexOf(self.client.galacticwarTab),
                False)
            self.client.mainTabs.setTabText(
                self.client.mainTabs.indexOf(self.client.galacticwarTab),
                "offline")

        self.state = ClientState.DROPPED
Example #12
0
    def doConnect(self):
        logger.debug("Connecting to server")
        if self.client.state == ClientState.ACCEPTED:

            self.progress.setCancelButtonText("Cancel")
            self.progress.setWindowFlags(QtCore.Qt.CustomizeWindowHint | QtCore.Qt.WindowTitleHint)
            self.progress.setAutoClose(False)
            self.progress.setAutoReset(False)
            self.progress.setModal(1)
            self.progress.setWindowTitle("Galactic War Network...")
            self.progress.setLabelText("Gating in ...")
            self.progress.show()

            #            self.login = self.client.login.strip()
            #            logger.info("Attempting to gate as: " + str(self.client.login))
            self.state = ClientState.NONE

            # Begin connecting.
            self.socket.connectToHost(LOBBY_HOST, LOBBY_PORT)

            while (self.socket.state() != QtNetwork.QAbstractSocket.ConnectedState) and self.progress.isVisible():
                QtGui.QApplication.processEvents()

            #        #Perform Version Check first
            if not self.socket.state() == QtNetwork.QAbstractSocket.ConnectedState:

                self.progress.close()  # in case it was still showing...
                # We either cancelled or had a TCP error, meaning the connection failed..
                if self.progress.wasCanceled():
                    logger.warn("doConnect() aborted by user.")
                else:
                    logger.error(
                        "doConnect() failed with clientstate "
                        + str(self.state)
                        + ", socket errorstring: "
                        + self.socket.errorString()
                    )
                return False
            else:

                return True