예제 #1
0
    def run(self):
        prnt("RaidServer: Booting up...")

        self.port = net.node.bind("swap:raid")

        self.centralSock.setblocking(False)
        while not self.stoppedEvent.isSet():
            now = time()

            # Central server
            r, w, e = select([self.centralSock], [self.centralSock], [], 0)
            if r:
                data = self.centralSock.recv(1024)
                stream = ByteStream(data)
                packetType = stream.readByte()

            if self.port.connectionPending():
                conn = self.port.accept()
                self.clientList.append({'conn': conn, 'playerInfo': None})

            for client in self.clientList:
                conn = client['conn']
                if conn.recvPending():
                    data = conn.recv()
                    if data == None:
                        playerName = client['playerInfo']['name'] if client[
                            'playerInfo'] else "<NoInfo>"
                        prnt("Client (%s) left raid, reason=%s" %
                             (playerName, fuzion.formatError(
                                 conn.closedReason)))
                        self.lastRaidUpdatePoke = time()
                        self.clientList.remove(client)
                        continue
                    packetType = data.readByte()
                    if packetType == pkt.PLAYER_UPDATE:
                        self.processPlayerUpdate(client, data)

            if now - self.lastRaidUpdateSent > 2 and now - self.lastRaidUpdatePoke < 5:
                self.sendRaidUpdate()
                self.lastRaidUpdateSent = now

            sleep(0.1)

        self.port.close()

        for client in self.clientList:
            conn = client['conn']
            conn.close()

        self.centralSock.close()

        prnt("RaidServer: Shutting down...")
예제 #2
0
    def run(self):
        prnt("RaidServer: Booting up...")

        self.port = net.node.bind("swap:raid")

        self.centralSock.setblocking(False)
        while not self.stoppedEvent.isSet():
            now = time()

            # Central server
            r, w, e = select([self.centralSock], [self.centralSock], [], 0)
            if r:
                data = self.centralSock.recv(1024)
                stream = ByteStream(data)
                packetType = stream.readByte()

            if self.port.connectionPending():
                conn = self.port.accept()
                self.clientList.append({ 'conn': conn, 'playerInfo': None })

            for client in self.clientList:
                conn = client['conn']
                if conn.recvPending():
                    data = conn.recv()
                    if data == None:
                        playerName = client['playerInfo']['name'] if client['playerInfo'] else "<NoInfo>"
                        prnt("Client (%s) left raid, reason=%s"%(playerName, fuzion.formatError(conn.closedReason)))
                        self.lastRaidUpdatePoke = time()
                        self.clientList.remove(client)
                        continue
                    packetType = data.readByte()
                    if packetType == pkt.PLAYER_UPDATE:
                        self.processPlayerUpdate(client, data)

            if now - self.lastRaidUpdateSent > 2 and now - self.lastRaidUpdatePoke < 5:
                self.sendRaidUpdate()
                self.lastRaidUpdateSent = now

            sleep(0.1)

        self.port.close()

        for client in self.clientList:
            conn = client['conn']
            conn.close()

        self.centralSock.close()

        prnt("RaidServer: Shutting down...")
예제 #3
0
    def run(self):
        prnt("RaidClient: Booting up...")

        self.conn = net.node.connect(self.serverNode, "swap:raid")
        if not self.conn or self.conn.state != fuzion.CS_CONNECTED:
            raid.leaveRaid()
            wx.CallAfter(self.failureFunc, "node_connect_failed")
            prnt("RaidClient: Connection failed, shutting down...")
            return

        # Inform the UI of raid join success.
        wx.CallAfter(self.successFunc)

        while not self.stoppedEvent.isSet():
            if self.pausedEvent.isSet():
                sleep(0.4)
                continue

            if self.conn.recvPending():
                data = self.conn.recv()
                if data == None:
                    if self.conn.closedReason != 0:
                        # If we're paused, we don't want to reconnect yet.
                        if self.pausedEvent.isSet():
                            continue

                        prnt("RaidClient: Connection lost, reason=%s"%fuzion.formatError(self.conn.closedReason))

                        # Fetch new raid info
                        self.serverNode = None
                        self.conn = None
                        while self.serverNode == None or self.conn == None:
                            prnt("RaidClient: Reconnecting...")
                            self.serverNode = raid.getNewServerNode()
                            if self.serverNode == None:
                                prnt("RaidClient: Failed to get new server node...")
                                sleep(2)
                                continue
                            conn = net.node.connect(self.serverNode, "swap:raid")
                            if conn.state == fuzion.CS_CONNECTED:
                                self.conn = conn
                                self.lastTicks = 2
                                continue
                            else:
                                prnt("RaidClient: Failed to connect to new node! Connection state = %d"%conn.state)
                            sleep(2)
                    continue
                packet = data.readByte()
                if packet == pkt.RAID_UPDATE:
                    self.gotRaidUpdate(data)

            now = time()
            if now - self.lastUpdateSent >= 2 and (log_parser.get().inCombat or self.lastTicks >= 1):
                if not log_parser.get().inCombat:
                    self.lastTicks -= 1
                else:
                    self.lastTicks = 2
                self.sendPlayerUpdate()
                self.lastUpdateSent = now
            sleep(0.1)

        self.conn.close()

        prnt("RaidClient: Shutting down...")
예제 #4
0
    def run(self):
        prnt("RaidClient: Booting up...")

        self.conn = net.node.connect(self.serverNode, "swap:raid")
        if not self.conn or self.conn.state != fuzion.CS_CONNECTED:
            raid.leaveRaid()
            wx.CallAfter(self.failureFunc, "node_connect_failed")
            prnt("RaidClient: Connection failed, shutting down...")
            return

        # Inform the UI of raid join success.
        wx.CallAfter(self.successFunc)

        while not self.stoppedEvent.isSet():
            if self.pausedEvent.isSet():
                sleep(0.4)
                continue

            if self.conn.recvPending():
                data = self.conn.recv()
                if data == None:
                    if self.conn.closedReason != 0:
                        # If we're paused, we don't want to reconnect yet.
                        if self.pausedEvent.isSet():
                            continue

                        prnt("RaidClient: Connection lost, reason=%s" %
                             fuzion.formatError(self.conn.closedReason))

                        # Fetch new raid info
                        self.serverNode = None
                        self.conn = None
                        while self.serverNode == None or self.conn == None:
                            prnt("RaidClient: Reconnecting...")
                            self.serverNode = raid.getNewServerNode()
                            if self.serverNode == None:
                                prnt(
                                    "RaidClient: Failed to get new server node..."
                                )
                                sleep(2)
                                continue
                            conn = net.node.connect(self.serverNode,
                                                    "swap:raid")
                            if conn.state == fuzion.CS_CONNECTED:
                                self.conn = conn
                                self.lastTicks = 2
                                continue
                            else:
                                prnt(
                                    "RaidClient: Failed to connect to new node! Connection state = %d"
                                    % conn.state)
                            sleep(2)
                    continue
                packet = data.readByte()
                if packet == pkt.RAID_UPDATE:
                    self.gotRaidUpdate(data)

            now = time()
            if now - self.lastUpdateSent >= 2 and (log_parser.get().inCombat
                                                   or self.lastTicks >= 1):
                if not log_parser.get().inCombat:
                    self.lastTicks -= 1
                else:
                    self.lastTicks = 2
                self.sendPlayerUpdate()
                self.lastUpdateSent = now
            sleep(0.1)

        self.conn.close()

        prnt("RaidClient: Shutting down...")