def handlePacket(self): packet = self.server.readThreadToMainPacket() if packet is None: return if len(packet) > 0: id = ord(packet[0]) offset = 1 if id == PyRakLib.PACKET_ENCAPSULATED: offset += 1 length = ord(packet[offset]) identifier = packet[offset:offset + length] offset += length + 1 flags = ord(packet[offset]) buffer = packet[offset:] self.instance.handleEncapsulated( identifier, EncapsulatedPacket.fromBinary(buffer, True), flags) elif id == PyRakLib.PACKET_RAW: length = ord(packet[offset]) offset += 1 address = packet[offset:offset + length] offset += length port = Binary.readShort(packet[offset:offset + 2]) offset += 2 payload = packet[offset:] self.instance.handleRaw(address, port, payload) elif id == PyRakLib.PACKET_SET_OPTION: length = ord(packet[offset]) offset += 1 name = packet[offset:offset + length] offset += length value = packet[offset:] self.instance.handleOption(name, value) elif id == PyRakLib.PACKET_OPEN_SESSION: offset += 1 length = ord(packet[offset]) identifier = packet[offset:offset + length] offset += length + 1 length = ord(packet[offset]) address = packet[offset:offset + length] offset += len port = Binary.readShort(packet[offset:offset + 2]) offset += 2 clientID = Binary.readLong(packet[offset:offset + 8]) self.instance.openSession(identifier, address, port, clientID) elif id == PyRakLib.PACKET_CLOSE_SESSION: length = ord(packet[offset]) offset += 1 identifier = packet[offset:offset + length] offset += length length = ord(packet[offset]) offset += 1 reason = packet[offset:offset + length] self.instance.closeSession(identifier, reason) elif id == PyRakLib.PACKET_INVALID_SESSION: offset += 1 length = ord(packet[offset]) identifier = packet[offset:offset + length] self.instance.closeSession(identifier, "Invalid session") elif id == PyRakLib.PACKET_ACK_NOTIFICATION: offset += 1 length = ord(packet[offset]) identifier = packet[offset:offset + length] offset += length identifierACK = Binary.readInt(packet[offset:offset + 4]) self.instance.notifyACK(identifier, identifierACK) return True return False
def getLong(self) -> int: return Binary.readLong(self.get(8))
def handlePacket(self): packet = self.server.readThreadToMainPacket() if packet == None: return if len(packet) > 0: id = ord(packet[0]) offset = 1 if id == PyRakLib.PACKET_ENCAPSULATED: offset += 1 length = ord(packet[offset]) identifier = packet[offset:offset+length] offset += length + 1 flags = ord(packet[offset]) buffer = packet[offset:] self.instance.handleEncapsulated(identifier, EncapsulatedPacket.fromBinary(buffer, True), flags) elif id == PyRakLib.PACKET_RAW: length = ord(packet[offset]) offset += 1 address = packet[offset:offset+length] offset += length port = Binary.readShort(packet[offset:offset+2]) offset += 2 payload = packet[offset:] self.instance.handleRaw(address, port, payload) elif id == PyRakLib.PACKET_SET_OPTION: length = ord(packet[offset]) offset += 1 name = packet[offset:offset+length] offset += length value = packet[offset:] self.instance.handleOption(name, value) elif id == PyRakLib.PACKET_OPEN_SESSION: offset += 1 length = ord(packet[offset]) identifier = packet[offset:offset+length] offset += length + 1 length = ord(packet[offset]) address = packet[offset:offset+length] offset += len port = Binary.readShort(packet[offset:offset+2]) offset += 2 clientID = Binary.readLong(packet[offset:offset+8]) self.instance.openSession(identifier, address, port, clientID) elif id == PyRakLib.PACKET_CLOSE_SESSION: length = ord(packet[offset]) offset += 1 identifier = packet[offset:offset+length] offset += length length = ord(packet[offset]) offset += 1 reason = packet[offset:offset+length] self.instance.closeSession(identifier, reason) elif id == PyRakLib.PACKET_INVALID_SESSION: offset += 1 length = ord(packet[offset]) identifier = packet[offset:offset+length] self.instance.closeSession(identifier, "Invalid session") elif id == PyRakLib.PACKET_ACK_NOTIFICATION: offset += 1 length = ord(packet[offset]) identifier = packet[offset:offset+length] offset += length identifierACK = Binary.readInt(packet[offset:offset+4]) self.instance.notifyACK(identifier, identifierACK) return True return False
from pyraklib.protocol.UNCONNECTED_PONG import UNCONNECTED_PONG data = Binary.writeLTriad(32) print(Binary.readLTriad(data)) data = Binary.writeByte(32) print(Binary.readByte(data)) data = Binary.writeShort(256) print(Binary.readShort(data)) data = Binary.writeInt(32) print(Binary.readInt(data)) data = Binary.writeLong(32) print(Binary.readLong(data)) data = Binary.writeFloat(32.54) print(Binary.readFloat(data)) data = Binary.writeDouble(32.3232) print(Binary.readDouble(data)) print(type(Binary.writeLong(23))) ping = UNCONNECTED_PING() ping.pingID = 1234 ping.encode() p = EncapsulatedPacket() p.reliability = 2