示例#1
0
    def toBinary(self, internal=False):
        payload = bytearray()
        if self.hasSplit:
            payload += (Binary.writeByte((self.reliability << 5) | 0b00010000))
        else:
            payload += (Binary.writeByte(self.reliability << 5))

        if internal:
            payload += (Binary.writeInt(len(self.buffer)))
            payload += (Binary.writeInt(self.identifierACK))
        else:
            payload += (Binary.writeShort(len(self.buffer) << 3))

        if self.reliability > 0:
            if (self.reliability > 2
                    or self.reliability == 2) and self.reliability is not 5:
                payload += (Binary.writeLTriad(self.messageIndex))
            if (self.reliability < 4
                    or self.reliability == 4) and self.reliability is not 2:
                payload += (Binary.writeLTriad(self.orderIndex))
                payload += (Binary.writeByte(self.orderChannel))

        if self.hasSplit:
            payload += (Binary.writeInt(self.splitCount))
            payload += (Binary.writeShort(self.splitID))
            payload += (Binary.writeInt(self.splitIndex))

        payload += (self.buffer)

        return payload
示例#2
0
 def sendRaw(self, address: str, port: int, payload: bytearray):
     buffer = chr(PyRakLib.PACKET_RAW) + chr(len(address)) + address + str(
         Binary.writeShort(port)) + payload
     self.server.pushMainToThreadPacket(buffer)
示例#3
0
 def putString(self, string: str):
     self.buffer += Binary.writeShort(len(string))
     self.buffer += bytes(string, "UTF-8")
示例#4
0
 def putShort(self, s: int):
     self.buffer += Binary.writeShort(s)
示例#5
0
 def streamRaw(self, address, port, payload):
     buffer = chr(PyRakLib.PACKET_RAW) + chr(len(address)) + address + Binary.writeShort(port) + payload
     self.server.pushThreadToMainPacket(buffer)