コード例 #1
0
ファイル: server.py プロジェクト: sms-hosting/cuwo
    def update(self):
        self.scripts.call('update')

        # entity updates
        for entity_id, entity in self.entities.iteritems():
            entity_packet.set_entity(entity, entity_id, entity.mask)
            entity.mask = 0
            self.broadcast_packet(entity_packet)
        self.broadcast_packet(update_finished_packet)

        # other updates
        update_packet = self.update_packet
        if self.items_changed:
            for chunk, items in self.chunk_items.iteritems():
                item_list = ChunkItems()
                item_list.chunk_x, item_list.chunk_y = chunk
                item_list.items = items
                update_packet.chunk_items.append(item_list)
        self.broadcast_packet(update_packet)
        update_packet.reset()

        # reset drop times
        if self.items_changed:
            for items in self.chunk_items.values():
                for item in items:
                    item.drop_time = 0
            self.items_changed = False

        # time update
        time_packet.time = self.get_time()
        time_packet.day = self.get_day()
        self.broadcast_packet(time_packet)
コード例 #2
0
    def update(self):
        self.scripts.call('update')

        # entity updates
        for entity_id, entity in self.entities.iteritems():
            entity_packet.set_entity(entity, entity_id, entity.mask)
            entity.mask = 0
            self.broadcast_packet(entity_packet)
        self.broadcast_packet(update_finished_packet)

        # other updates
        update_packet = self.update_packet
        if self.items_changed:
            for chunk, items in self.chunk_items.iteritems():
                item_list = ChunkItems()
                item_list.chunk_x, item_list.chunk_y = chunk
                item_list.items = items
                update_packet.chunk_items.append(item_list)
        self.broadcast_packet(update_packet)
        update_packet.reset()

        # reset drop times
        if self.items_changed:
            for items in self.chunk_items.values():
                for item in items:
                    item.drop_time = 0
            self.items_changed = False

        # time update
        time_packet.time = self.get_time()
        time_packet.day = self.get_day()
        self.broadcast_packet(time_packet)
コード例 #3
0
ファイル: server.py プロジェクト: Jakky89/cuwo
    def update(self):
        self.scripts.call('update')

        uxtime = reactor.seconds()
        if self.last_secondly_check:
            update_seconds_delta = uxtime - self.last_secondly_check
        else:
            update_seconds_delta = 0

        if update_seconds_delta < 1:
            self.updates_since_last_second += 1
        else:
            ups = math.floor((self.updates_per_second + (self.updates_since_last_second / update_seconds_delta)) / 2)
            self.updates_since_last_second = 0
            if ups != self.updates_per_second:
                dus = ups - self.updates_per_second
                self.updates_per_second = ups
                if dus > 0:
                    print "\rUpdates/s: %s (+%s)" % (ups, dus)
                elif dus < 0:
                    print "\rUpdates/s: %s (-%s)" % (ups, dus)
            for player in self.players.values():
                if player.packet_count > 0:
                    ppr = math.ceil( ( player.packet_rate + ( player.packet_count / update_seconds_delta ) ) / 2 )
                    player.packet_count = 0
                    if ppr != player.packet_rate:
                        dpr = ppr - player.packet_rate
                        player.packet_rate = ppr
                        if dpr > 0:
                            print "\rPackets/s for %s: %s (+%s)" % (player.name, player.packet_rate, dpr)
                        elif dpr < 0:
                            print "\rPackets/s for %s: %s (-%s)" % (player.name, player.packet_rate, dpr)

        # entity updates
        for entity_id, entity in self.entities.iteritems():
            entity_packet.set_entity(entity, entity_id, entity.mask)
            entity.mask = 0
            self.broadcast_packet(entity_packet)
        self.broadcast_packet(update_finished_packet)

        # other updates
        update_packet = self.update_packet
        if self.items_changed:
            for chunk in self.world.chunks.values():
                item_list = ChunkItems()
                item_list.chunk_x = chunk.chunk_x
                item_list.chunk_y = chunk.chunk_y
                item_list.items = chunk.item_list
                update_packet.chunk_items.append(item_list)
                for item in chunk.item_list:
                    item.drop_time = 0
            self.items_changed = False
        self.broadcast_packet(update_packet)
        update_packet.reset()

        if update_seconds_delta != 0:
            for player in self.players.values():
                if player.time_last_packet >= (uxtime - constants.CLIENT_RECV_TIMEOUT):
                    if player.entity_data.changed:
                        player.entity_data.changed = False
                        ret = player.do_anticheat_actions()
                        if (not ret) and player.login_id:
                            database.update_player(self.db_con, player.login_id, player.name)
                else:
                    print '[WARNING] Connection timed out for Player %s #%s' % (player.entity_data.name, player.entity_id)
                    player.kick('Connection timed out')
        self.broadcast_time()
コード例 #4
0
ファイル: world.py プロジェクト: UserXXX/CuBolt
 def on_update(self, update_packet):
     item_list = ChunkItems()
     item_list.chunk_x, item_list.chunk_y = self.pos
     item_list.items = self.items
     update_packet.chunk_items.append(item_list)