Exemple #1
0
    def pollRequests(self):

        while self.requestDetails:
            replayId = self.requestDetails.pop()
            if not replayId in self.replayPlayers:
                logger.info('Request info for replay %d (%d in queue) ...' % (replayId, len(self.requestDetails)))
                self.replayswidget.connectToModVault()
                self.replayswidget.send(dict(command="info_replay", uid=replayId))
                return

        while self.requestReplaysByPlayer:
            playerName = self.requestReplaysByPlayer.pop()
            playerName0 = self.cachePlayerAlias(playerName)

            if (playerName0 != playerName) and (playerName0 not in self.alreadySearchedPlayers):
                self.requestReplaysByPlayer.add(playerName0)
            
            if playerName not in self.alreadySearchedPlayers:
                logger.info('Request replays for player "%s" (%d in queue) ...' % (playerName, len(self.requestReplaysByPlayer)))
                self.replayswidget.connectToModVault()
                self.replayswidget.send(dict(
                    command="search",
                    rating=self.replayswidget.minRating.value(),
                    map=self.replayswidget.mapName.text(),
                    player=playerName,
                    mod=self.replayswidget.modList.currentText()
                ))
                self.alreadySearchedPlayers.add(playerName)
                return
Exemple #2
0
    def pollRequests(self):

        while self.requestDetails:
            replayId = self.requestDetails.pop()
            if not replayId in self.replayPlayers:
                logger.info("Request info for replay %d (%d in queue) ..." % (replayId, len(self.requestDetails)))
                self.replayswidget.connectToModVault()
                self.replayswidget.send(dict(command="info_replay", uid=replayId))
                return

        while self.requestReplaysByPlayer:
            playerName = self.requestReplaysByPlayer.pop()
            playerName0 = self.cachePlayerAlias(playerName)

            if (playerName0 != playerName) and (playerName0 not in self.alreadySearchedPlayers):
                self.requestReplaysByPlayer.add(playerName0)

            if playerName not in self.alreadySearchedPlayers:
                logger.info(
                    'Request replays for player "%s" (%d in queue) ...' % (playerName, len(self.requestReplaysByPlayer))
                )
                self.replayswidget.connectToModVault()
                self.replayswidget.send(
                    dict(
                        command="search",
                        rating=self.replayswidget.minRating.value(),
                        map=self.replayswidget.mapName.text(),
                        player=playerName,
                        mod=self.replayswidget.modList.currentText(),
                    )
                )
                self.alreadySearchedPlayers.add(playerName)
                return
Exemple #3
0
    def onHeartbeatTimer(self):

        self.heartbeat -= 1
        self.savecountdown -= 1

        # take this opportunity to save everything to disk
        if self.heartbeat < 0 or self.savecountdown < 0:
            self.savecountdown = 300
            logger.info('Saving replay dump ...')
            with open('d:/replaydumper.json','w') as fp:
                fp.write(json.dumps({
                    'replays':self.replays,
                    'replayPlayers':self.replayPlayers,
                    'playerAliases':self.playerAliases
                }))

        # detect and deal with a dead polling cycle
        if self.heartbeat < 0 and (self.requestDetails or self.requestReplaysByPlayer):
            logger.info('Dead poll loop. restarting')
            self.heartbeat = 20
            self.pollRequests()

        # keep going as long as the heart beat hasn't expired
        if self.heartbeat >= 0:
            QtCore.QTimer.singleShot(1000, self.onHeartbeatTimer)
Exemple #4
0
 def onReplays(self, replays):
     self.heartbeat = 20
     allReplays = { replay['id']:replay for replay in replays }
     logger.info('Received %d replays' % len(allReplays))
     self.replays.update(allReplays)
     self.requestDetails.update(allReplays.keys())
     QtCore.QTimer.singleShot(10, self.pollRequests)
Exemple #5
0
    def onHeartbeatTimer(self):

        self.heartbeat -= 1
        self.savecountdown -= 1

        # take this opportunity to save everything to disk
        if self.heartbeat < 0 or self.savecountdown < 0:
            self.savecountdown = 300
            logger.info("Saving replay dump ...")
            with open("d:/replaydumper.json", "w") as fp:
                fp.write(
                    json.dumps(
                        {
                            "replays": self.replays,
                            "replayPlayers": self.replayPlayers,
                            "playerAliases": self.playerAliases,
                        }
                    )
                )

        # detect and deal with a dead polling cycle
        if self.heartbeat < 0 and (self.requestDetails or self.requestReplaysByPlayer):
            logger.info("Dead poll loop. restarting")
            self.heartbeat = 20
            self.pollRequests()

        # keep going as long as the heart beat hasn't expired
        if self.heartbeat >= 0:
            QtCore.QTimer.singleShot(1000, self.onHeartbeatTimer)
Exemple #6
0
 def onReplays(self, replays):
     self.heartbeat = 20
     allReplays = {replay["id"]: replay for replay in replays}
     logger.info("Received %d replays" % len(allReplays))
     self.replays.update(allReplays)
     self.requestDetails.update(allReplays.keys())
     QtCore.QTimer.singleShot(10, self.pollRequests)
Exemple #7
0
    def cachePlayerAlias(self,player):
        
        if player in self.playerAliases:
            return self.playerAliases[player]

        else:
            player0 = getPlayerOriginalName(player)
            self.playerAliases[player] = player0
            logger.info('Player %s known as %s' % (player, player0))
            return player0
Exemple #8
0
    def cachePlayerAlias(self, player):

        if player in self.playerAliases:
            return self.playerAliases[player]

        else:
            player0 = getPlayerOriginalName(player)
            self.playerAliases[player] = player0
            logger.info("Player %s known as %s" % (player, player0))
            return player0
Exemple #9
0
    def __init__(self, client):
        super(BaseClass, self).__init__()

        self.setupUi(self)

        #self.replayVault.setVisible(False)
        self.client = client
        client.replaysTab.layout().addWidget(self)

        client.gameInfo.connect(self.processGameInfo)
        client.replayVault.connect(self.replayVault)

        self.onlineReplays = {}
        self.onlineTree.setItemDelegate(ReplayItemDelegate(self))
        self.replayDownload = QNetworkAccessManager()
        self.replayDownload.finished.connect(self.finishRequest)

        # sending request to replay vault
        self.searchButton.pressed.connect(self.searchVault)
        self.playerName.returnPressed.connect(self.searchVault)
        self.mapName.returnPressed.connect(self.searchVault)

        self.myTree.itemDoubleClicked.connect(self.myTreeDoubleClicked)
        self.myTree.itemPressed.connect(self.myTreePressed)
        self.myTree.header().setResizeMode(0,
                                           QtGui.QHeaderView.ResizeToContents)
        self.myTree.header().setResizeMode(1,
                                           QtGui.QHeaderView.ResizeToContents)
        self.myTree.header().setResizeMode(2, QtGui.QHeaderView.Stretch)
        self.myTree.header().setResizeMode(3,
                                           QtGui.QHeaderView.ResizeToContents)

        self.liveTree.itemDoubleClicked.connect(self.liveTreeDoubleClicked)
        self.liveTree.itemPressed.connect(self.liveTreePressed)
        self.liveTree.header().setResizeMode(
            0, QtGui.QHeaderView.ResizeToContents)
        self.liveTree.header().setResizeMode(1, QtGui.QHeaderView.Stretch)
        self.liveTree.header().setResizeMode(
            2, QtGui.QHeaderView.ResizeToContents)

        self.games = {}

        self.onlineTree.itemDoubleClicked.connect(self.onlineTreeDoubleClicked)
        self.onlineTree.itemPressed.connect(self.onlineTreeClicked)

        # replay vault connection to server
        self.searching = False
        self.blockSize = 0
        self.replayVaultSocket = QtNetwork.QTcpSocket()
        self.replayVaultSocket.error.connect(self.handleServerError)
        self.replayVaultSocket.readyRead.connect(self.readDataFromServer)
        self.replayVaultSocket.disconnected.connect(self.disconnected)
        self.replayVaultSocket.error.connect(self.errored)

        logger.info("Replays Widget instantiated.")
    def __init__(self, client):
        super(BaseClass, self).__init__()

        self.setupUi(self)

        #self.replayVault.setVisible(False)
        self.client = client
        client.replaysTab.layout().addWidget(self)
        
        client.gameInfo.connect(self.processGameInfo)
        client.replayVault.connect(self.replayVault)    
        
        self.onlineReplays = {}
        self.onlineTree.setItemDelegate(ReplayItemDelegate(self))
        self.replayDownload = QNetworkAccessManager()
        self.replayDownload.finished.connect(self.finishRequest)
        
        # sending request to replay vault
        self.searchButton.pressed.connect(self.searchVault)
        self.playerName.returnPressed.connect(self.searchVault)
        self.mapName.returnPressed.connect(self.searchVault)
        
        self.myTree.itemDoubleClicked.connect(self.myTreeDoubleClicked)
        self.myTree.itemPressed.connect(self.myTreePressed)
        self.myTree.header().setResizeMode(0, QtGui.QHeaderView.ResizeToContents)
        self.myTree.header().setResizeMode(1, QtGui.QHeaderView.ResizeToContents)
        self.myTree.header().setResizeMode(2, QtGui.QHeaderView.Stretch)
        self.myTree.header().setResizeMode(3, QtGui.QHeaderView.ResizeToContents)
        
        self.liveTree.itemDoubleClicked.connect(self.liveTreeDoubleClicked)
        self.liveTree.itemPressed.connect(self.liveTreePressed)
        self.liveTree.header().setResizeMode(0, QtGui.QHeaderView.ResizeToContents)
        self.liveTree.header().setResizeMode(1, QtGui.QHeaderView.Stretch)
        self.liveTree.header().setResizeMode(2, QtGui.QHeaderView.ResizeToContents)
        
        self.games = {}
        
        self.onlineTree.itemDoubleClicked.connect(self.onlineTreeDoubleClicked)
        self.onlineTree.itemPressed.connect(self.onlineTreeClicked)
        
        # replay vault connection to server
        self.searching = False
        self.blockSize = 0
        self.replayVaultSocket = QtNetwork.QTcpSocket()
        self.replayVaultSocket.error.connect(self.handleServerError)
        self.replayVaultSocket.readyRead.connect(self.readDataFromServer)
        self.replayVaultSocket.disconnected.connect(self.disconnected)
        self.replayVaultSocket.error.connect(self.errored) 

        
        logger.info("Replays Widget instantiated.")
Exemple #11
0
    def __init__(self, replayswidget):

        logger.info('Creating replay dumper ...')
        self.replayswidget = replayswidget
        
        self.replays = { }
        self.replayPlayers = { }
        self.playerAliases = { }

        self.heartbeat = 20
        self.savecountdown = 300
        QtCore.QTimer.singleShot(1000, self.onHeartbeatTimer)

        self.requestDetails = set()
        self.requestReplaysByPlayer = set()
        self.alreadySearchedPlayers = set()
Exemple #12
0
    def __init__(self, replayswidget):

        logger.info("Creating replay dumper ...")
        self.replayswidget = replayswidget

        self.replays = {}
        self.replayPlayers = {}
        self.playerAliases = {}

        self.heartbeat = 20
        self.savecountdown = 300
        QtCore.QTimer.singleShot(1000, self.onHeartbeatTimer)

        self.requestDetails = set()
        self.requestReplaysByPlayer = set()
        self.alreadySearchedPlayers = set()
Exemple #13
0
    def resume(self):
        with open('d:/replaydumper.json') as fp:
            dump = json.load(fp)
            dump = byteify(dump)

        self.replays = { int(k):v for k,v in dump['replays'].iteritems() }
        self.replayPlayers = { int(k):v for k,v in dump['replayPlayers'].iteritems() }
        self.playerAliases = { } #dump['playerAliases']

        for replayid,players in self.replayPlayers.iteritems():
            for player in players:
                self.requestReplaysByPlayer.add(player['name'])

        logger.info('Resuming search: %d replays retrieved, %d player names to search' % (
            len(self.replays), len(self.requestReplaysByPlayer)
        ))
        self.pollRequests()
Exemple #14
0
    def resume(self):
        with open("d:/replaydumper.json") as fp:
            dump = json.load(fp)
            dump = byteify(dump)

        self.replays = {int(k): v for k, v in dump["replays"].iteritems()}
        self.replayPlayers = {int(k): v for k, v in dump["replayPlayers"].iteritems()}
        self.playerAliases = {}  # dump['playerAliases']

        for replayid, players in self.replayPlayers.iteritems():
            for player in players:
                self.requestReplaysByPlayer.add(player["name"])

        logger.info(
            "Resuming search: %d replays retrieved, %d player names to search"
            % (len(self.replays), len(self.requestReplaysByPlayer))
        )
        self.pollRequests()
    def handleServerError(self, socketError):
        if socketError == QtNetwork.QAbstractSocket.RemoteHostClosedError:
            logger.info("Replay Server down: The server is down for maintenance, please try later.")

        elif socketError == QtNetwork.QAbstractSocket.HostNotFoundError:
            logger.info("Connection to Host lost. Please check the host name and port settings.")
            
        elif socketError == QtNetwork.QAbstractSocket.ConnectionRefusedError:
            logger.info("The connection was refused by the peer.")
        else:
            logger.info("The following error occurred: %s." % self.replayVaultSocket.errorString())    
Exemple #16
0
    def handleServerError(self, socketError):
        if socketError == QtNetwork.QAbstractSocket.RemoteHostClosedError:
            logger.info(
                "Replay Server down: The server is down for maintenance, please try later."
            )

        elif socketError == QtNetwork.QAbstractSocket.HostNotFoundError:
            logger.info(
                "Connection to Host lost. Please check the host name and port settings."
            )

        elif socketError == QtNetwork.QAbstractSocket.ConnectionRefusedError:
            logger.info("The connection was refused by the peer.")
        else:
            logger.info("The following error occurred: %s." %
                        self.replayVaultSocket.errorString())