예제 #1
0
    def to_socket(self, session_cipher = None):
        """ Return ready-to-send bytes, possibly encrypted, from the packet. """
        if DEBUG:
            print(">>>", self.opcode)
            print(dump_data(self.data), end = "")

        opcode_bytes = self.OUTGOING_OPCODE_BIN.pack(self.opcode.value)
        packet = opcode_bytes + self.data
        size_bytes = self.OUTGOING_SIZE_BIN.pack(len(packet))
        packet = size_bytes + packet

        if session_cipher is not None:
            packet = session_cipher.encrypt(packet)

        return packet
예제 #2
0
    def to_socket(self, session_cipher = None):
        """ Return ready-to-send bytes, possibly encrypted, from the packet. """
        if DEBUG:
            print(">>>", self.opcode)
            print(dump_data(self.data), end = "")

        opcode_bytes = self.OUTGOING_OPCODE_BIN.pack(self.opcode.value)
        packet = opcode_bytes + self.data
        size_bytes = self.OUTGOING_SIZE_BIN.pack(len(packet))
        packet = size_bytes + packet

        if session_cipher is not None:
            packet = session_cipher.encrypt(packet)

        return packet
예제 #3
0
    def get_next_packet(self):
        """ Return a received WorldPacket.

        It captures when a connection get closed (recv returns None), and return
        None as well, but it doesn't capture other network exceptions like
        ConnectionResetError.
        """
        try:
            self._get_header()
            self._get_content()
        except WorldPacketReceiverException:
            return None

        if DEBUG:
            if self.opcode is not None:
                print("<<<", self.opcode)
            print(dump_data(self.content), end = "")

        packet = WorldPacket(self.opcode, self.content)
        self.clean()
        return packet
예제 #4
0
    def get_next_packet(self):
        """ Return a received WorldPacket.

        It captures when a connection get closed (recv returns None), and return
        None as well, but it doesn't capture other network exceptions like
        ConnectionResetError.
        """
        try:
            self._get_header()
            self._get_content()
        except WorldPacketReceiverException:
            return None

        if DEBUG:
            if self.opcode is not None:
                print("<<<", self.opcode)
            print(dump_data(self.content), end = "")

        packet = WorldPacket(self.opcode, self.content)
        self.clean()
        return packet