コード例 #1
0
 def handle_set_shard_callback(self, do_id, old_parent_id, old_zone_id,
                               new_parent_id, new_zone_id):
     datagram = io.NetworkDatagram()
     datagram.add_uint16(types.CLIENT_GET_STATE_RESP)
     self.handle_send_datagram(datagram)
コード例 #2
0
 def __handle_set_name_pattern_resp(self, avatar_id):
     datagram = io.NetworkDatagram()
     datagram.add_uint16(types.CLIENT_SET_NAME_PATTERN_ANSWER)
     datagram.add_uint32(avatar_id)
     datagram.add_uint8(0)
     self.handle_send_datagram(datagram)
コード例 #3
0
 def handle_get_shard_list_resp(self, di):
     datagram = io.NetworkDatagram()
     datagram.add_uint16(types.CLIENT_GET_SHARD_LIST_RESP)
     datagram.append_data(di.get_remaining_bytes())
     self.handle_send_datagram(datagram)
コード例 #4
0
    def handle_get_shard_list(self):
        datagram = io.NetworkDatagram()
        datagram.add_header(types.STATESERVER_CHANNEL, self.channel,
                            types.STATESERVER_GET_SHARD_ALL)

        self.network.handle_send_connection_datagram(datagram)
コード例 #5
0
    def handle_object_get_all(self, sender, di):
        context = di.get_uint32()
        do_id = di.get_uint32()
        file_object = self._backend.open_file(
            self._backend.get_filename(do_id))

        if not file_object:
            self.notify.warning(
                'Failed to get fields for object: %d context: %d, unknown object!'
                % (do_id, context))

            return

        dc_name = file_object.get_value('dclass')
        dc_class = self.dc_loader.dclasses_by_name.get(dc_name)

        if not dc_class:
            self.notify.warning(
                'Failed to query object: %d context: %d, unknown dclass: %s!' %
                (do_id, context, dc_name))

            return

        fields = file_object.get_value('fields')

        if not fields:
            self.notify.warning(
                'Failed to query object: %d context %d, invalid fields!' %
                (do_id, context))

            return

        datagram = io.NetworkDatagram()
        datagram.add_header(sender, self.channel,
                            types.DBSERVER_OBJECT_GET_ALL_RESP)

        datagram.add_uint32(context)
        datagram.add_uint8(1)

        field_packer = DCPacker()
        field_count = 0
        for field_name, field_args in fields.items():
            field = dc_class.get_field_by_name(field_name)

            if not field:
                self.notify.warning(
                    'Failed to query object %d context: %d, unknown field: %s'
                    % (do_id, context, field_name))

                return

            field_packer.raw_pack_uint16(field.get_number())
            field_packer.begin_pack(field)
            field.pack_args(field_packer, field_args)
            field_packer.end_pack()
            field_count += 1

        self._backend.close_file(file_object)

        datagram.add_uint16(dc_class.get_number())
        datagram.add_uint16(field_count)
        datagram.append_data(field_packer.get_string())
        self.handle_send_connection_datagram(datagram)
コード例 #6
0
    def handle_create_object(self, sender, di):
        context = di.get_uint32()
        dc_id = di.get_uint16()
        field_count = di.get_uint16()
        dc_class = self.dc_loader.dclasses_by_number.get(dc_id)

        if not dc_class:
            self.notify.error(
                'Failed to create object: %d context: %d, unknown dclass!' %
                (dc_id, context))

        do_id = self._backend.allocator.allocate()
        file_object = self._backend.open_file(
            self._backend.get_filename(do_id))

        file_object.set_value('dclass', dc_class.get_name())
        file_object.set_value('do_id', do_id)

        fields = {}
        field_packer = DCPacker()
        field_packer.set_unpack_data(di.get_remaining_bytes())

        for _ in xrange(field_count):
            field_id = field_packer.raw_unpack_uint16()
            field = dc_class.get_field_by_index(field_id)

            if not field:
                self.notify.error(
                    'Failed to unpack field: %d dclass: %s, invalid field!' %
                    (field_id, dc_class.get_name()))

            field_packer.begin_unpack(field)
            field_args = field.unpack_args(field_packer)
            field_packer.end_unpack()

            if not field_args:
                self.notify.error(
                    'Failed to unpack field args for field: %d dclass: %s, invalid result!'
                    % (field.get_name(), dc_class.get_name()))

            fields[field.get_name()] = field_args

        for index in xrange(dc_class.get_num_inherited_fields()):
            field_packer = DCPacker()
            field = dc_class.get_inherited_field(index)

            if not field:
                continue

            if field.get_name() in fields:
                continue

            if not field.is_db() or not field.has_default_value():
                continue

            field_packer.set_unpack_data(field.get_default_value())
            field_packer.begin_unpack(field)
            field_args = field.unpack_args(field_packer)
            field_packer.end_unpack()

            if not field_args:
                self.notify.error(
                    'Failed to unpack field args for field: %d dclass: %s, invalid result!'
                    % (field.get_name(), dc_class.get_name()))

            fields[field.get_name()] = field_args

        file_object.set_value('fields', fields)

        self._backend.close_file(file_object)
        self._backend.tracker.set_value('next', do_id + 1)

        datagram = io.NetworkDatagram()
        datagram.add_header(sender, self.channel,
                            types.DBSERVER_CREATE_OBJECT_RESP)

        datagram.add_uint32(context)
        datagram.add_uint32(do_id)
        self.handle_send_connection_datagram(datagram)