Ejemplo n.º 1
0
    def serialize(self, stream):
        stream.write(c_uint8(len(self.key) * 2))

        for char in self.key:
            stream.write(char.encode('latin1'))
            stream.write(b'\0')

        if not self.data_num:
            if isinstance(self.data, ElementTree.Element):
                stream.write(c_uint8(13))

                txt = b'<?xml version="1.0">' + ElementTree.tostring(self.data)

                stream.write(c_uint32(len(txt)))
                stream.write(txt)
            else:
                stream.write(c_uint8(LEGO_DATA_TYPES[self.data_type]))

                if self.data_type == str:
                    stream.write(self.data, length_type=c_uint)
                else:
                    stream.write(self.data_type(self.data))
        else:
            stream.write(c_uint8(self.data_num))
            stream.write(self.data)
Ejemplo n.º 2
0
    def serialize(self, stream):
        """
        Serializes the packet
        """
        super().serialize(stream)

        stream.write(c_uint8(len(self.characters)))
        stream.write(c_uint8(self.front_char_id))

        for character in self.characters:
            stream.write(character)
Ejemplo n.º 3
0
 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)
Ejemplo n.º 4
0
    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
Ejemplo n.º 5
0
    def collected(self, packet, conn: Connection, stream: ReadStream):
        """
        Handles the has been collected game message
        """

        objid = stream.read(c_int64)

        print(f'Collected object')
        print(f'ID: {packet.objid}')
        print(f'Player: {objid}')

        session = self.server.handle_until_return('session:get_session',
                                                  conn.get_address())
        char = self.server.handle_until_return(
            'char:characters',
            session.account.user.id)[session.account.front_character]
        clone = self.server.handle_until_return('world:get_clone',
                                                session.clone)
        char_missions = self.server.handle_until_return(
            'char:get_missions', char.pk)

        objs = [x for x in clone.objects if x.objid == packet.objid]

        if objs:
            obj = objs[0]

            for char_mission in [x for x in char_missions if x.state == 2]:
                tasks = self.server.handle_until_return(
                    'world:get_mission_tasks', char_mission.mission)

                for task in tasks:
                    if task[3] == obj.lot and task[2] == 3:
                        char_mission.progress += 1
                        char_mission.save()

                        wstr = WriteStream()

                        wstr.write(c_int(char_mission.mission))
                        wstr.write(c_int(1 << (tasks.index(task) + 1)))
                        wstr.write(c_uint8(1))
                        wstr.write(
                            c_float(char_mission.progress + (clone.zone << 8)))

                        msg = ServerGameMessage(
                            objid, GameMessageID.NOTIFY_MISSION_TASK, wstr)

                        conn.send(msg)

                        return
Ejemplo n.º 6
0
    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))
Ejemplo n.º 7
0
    def __init__(self, *args):
        super().__init__(*args)
        self.luz = LUZReader(ZONE_LUZ[ZONE_IDS[self.server.type]], self.server.type)
        for scene in self.luz.scenes:
            for obj in scene.objects:
                if obj.spawner is not None:
                    trigger = obj.config.get('renderDisabled')
                    components = obj.components

                    if trigger:
                        trigger_comp = Trigger()

                        components.append(trigger_comp)

                    replica = BaseData(obj.objid, obj.lot, obj.name, trigger=trigger, spawner=obj.spawner, scale=obj.scale, components=components)

                    wstr = WriteStream()
                    wstr.write(c_uint8(0x24))
                    wstr.write(c_bit(True))
                    wstr.write(c_uint16(0))
                    replica.write_construction(wstr)

                    self.server.repman.construct(replica, True)
Ejemplo n.º 8
0
 def serialize(self, stream: WriteStream):
     """
     Serializes the packet
     """
     super().serialize(stream)
     stream.write(c_uint8(self.auth_status_code))
     stream.write(CString(self.unknown, allocated_length=33))
     stream.write(CString(self.unknown1, allocated_length=33*7))
     stream.write(self.client_version)
     stream.write(self.auth_token, allocated_length=33)
     stream.write(CString(self.char_ip, allocated_length=33))
     stream.write(CString(self.chat_ip, allocated_length=33))
     stream.write(c_uint16(self.char_port))
     stream.write(c_uint16(self.chat_port))
     stream.write(CString(self.unknown2, allocated_length=33))
     stream.write(CString(self.unknown3, allocated_length=37))
     stream.write(c_uint32(self.unknown4))
     stream.write(CString(self.localization, allocated_length=3))
     stream.write(c_bool(self.new_subscriber))
     stream.write(c_bool(self.is_ftp))
     stream.write(c_uint64(self.unknown5))
     stream.write(self.permission_error, length_type=c_uint16)
     # TODO: Implement stamps
     stream.write(c_uint32(4))
Ejemplo n.º 9
0
 def serialize(self, stream):
     stream.write(c_uint8(0x53))
     stream.write(c_uint16(self.remote_conn_id))
     stream.write(c_uint32(self.packet_id))
     stream.write(c_uint8(0x00))