def serialize(self, stream: bitstream.WriteStream) -> None: key_num = len(self._keys) stream.write(bitstream.c_uint(key_num)) for key in self._keys: name = key[0] value = key[1] value_type = key[2] stream.write(bitstream.c_uint8(len(name) * 2)) for char in name: stream.write(char.encode('latin1')) stream.write(b'\0') stream.write(bitstream.c_ubyte(value_type)) if value_type == 0: stream.write(value, length_type=bitstream.c_uint) elif value_type == 1: stream.write(bitstream.c_int(value)) elif value_type == 3: stream.write(bitstream.c_float(value)) elif value_type == 5: stream.write(bitstream.c_uint(value)) elif value_type == 7: stream.write(bitstream.c_bool(value)) elif value_type == 8 or value_type == 9: stream.write(bitstream.c_int64(value)) elif value_type == 13: xml_str = bytes(ElementTree.tostring(value)) xml_str = b'<?xml version="1.0">' + xml_str stream.write(bitstream.c_ulong(xml_str.__len__())) stream.write(xml_str)
def serialize(self, stream): """ Serializes the packet """ stream.write(c_int64(self.objid)) stream.write(c_uint32(self.unknown1)) stream.write(self.character_name, allocated_length=33) stream.write(self.character_unapproved_name, allocated_length=33) stream.write(c_bool(self.is_name_rejected)) stream.write(c_bool(self.free_to_play)) stream.write(self.unknown2) stream.write(c_uint32(self.shirt_color)) stream.write(c_uint32(self.shirt_style)) stream.write(c_uint32(self.pants_color)) stream.write(c_uint32(self.hair_style)) stream.write(c_uint32(self.hair_color)) stream.write(c_uint32(self.lh)) stream.write(c_uint32(self.rh)) stream.write(c_uint32(self.eyebrows)) stream.write(c_uint32(self.eyes)) stream.write(c_uint32(self.mouth)) stream.write(c_uint32(self.unknown3)) stream.write(c_uint16(self.last_zone)) stream.write(c_uint16(self.last_instance)) stream.write(c_uint32(self.last_clone)) stream.write(c_uint64(self.last_login)) stream.write(c_uint16(len(self.equipped_items))) for item in self.equipped_items: stream.write(c_uint32(item))
def serialize(self, stream): """ Serializes the game message """ super().serialize(stream) stream.write(c_int64(self.objid)) stream.write(c_uint16(self.message_id)) if self.extra_data: if isinstance(self.extra_data, bytes): stream.write(self.extra_data) else: stream.write(bytes(self.extra_data))
def post_creation(self, stream): """ Writes part 2 of data """ stream.write(c_bit(True)) stream.write(c_bit(self.pvp)) stream.write(c_bit(self.gm)) stream.write(c_uint8(self.gmlevel)) stream.write(c_bit(False)) # NOTE: unknown stream.write(c_uint8(0)) # NOTE: unknown stream.write(c_bit(True)) stream.write(c_uint32(1 if self.glowing_head else 0)) stream.write(c_bit(self.guild)) if self.guild: stream.write(c_int64(self.guild_id)) stream.write(self.guild_name, allocated_length=33) stream.write(c_bit(True)) # NOTE: unknown stream.write(c_int32(-1)) # NOTE: unknown
def pre_creation(self, stream): """ Writes part 1 of data """ stream.write(c_bit(True)) stream.write(c_bit(self.vehicle)) if self.vehicle: stream.write(c_int64(self.vehicle_id)) stream.write(c_uint8(0)) # NOTE: unknown stream.write(c_bit(self.level)) if self.level: stream.write(c_uint32(self.level_num)) stream.write(c_bit(True)) stream.write(c_bit(False)) stream.write(c_bit(True))
def request_use(self, packet, conn: Connection, stream: ReadStream): """ Handles the request use game message """ session = self.server.handle_until_return('session:get_session', conn.get_address()) clone = self.server.handle_until_return('world:get_clone', session.clone) char = self.server.handle_until_return( 'char:front_char', session.account.character_set.all()) char_missions = self.server.handle_until_return( 'char:get_missions', char.pk) multiinteract = stream.read(c_bit) multiinteract_id = stream.read(c_uint32) multiinteract_type = stream.read(c_int) objid = stream.read(c_int64) secondary = stream.read(c_bit) print(f'Multi interact: {multiinteract}') print(f'Multi interact ID: {multiinteract_id}') print(f'Multi interact type: {multiinteract_type}') print(f'Object ID: {objid}') print(f'Secondary: {secondary}') objs = [x for x in clone.objects if x.objid == objid] if objs: obj = objs[0] if char_missions: missions = self.server.handle_until_return( 'world:missions_for_lot_target', obj.lot) for char_mission in [x for x in char_missions if x.state == 2]: missions2 = [ x for x in missions if x[0] == char_mission.mission ] if missions2: mission = missions2[0] self.server.handle('char:complete_mission', char.pk, mission[0]) msg = ServerGameMessage( packet.objid, GameMessageID.OFFER_MISSION, c_int(mission[0]) + c_int64(objid)) conn.send(msg) return missions = self.server.handle_until_return( 'world:missions_for_lot', obj.lot) missions = [ x for x in missions if x[0] not in [y.mission for y in char_missions if y.state == 8] ] if missions: mission = missions[0] msg = ServerGameMessage(packet.objid, GameMessageID.OFFER_MISSION, c_int(mission[0]) + c_int64(objid)) conn.send(msg)
def serialize(self, stream): stream.write(c_bit(True)) # NOTE: unknown stream.write(c_int64(0))