def send_raw(self, address: str, port: int, payload: bytes): buffer = b"" buffer += chr(PyRakLib.PACKET_RAW) buffer += chr(len(address)) buffer += address buffer += Binary.write_short(port) buffer += payload self.server.push_main_to_thread_packet(buffer)
def stream_raw(self, address: InternetAddress, payload: bytes): buffer = b"" buffer += chr(PyRakLib.PACKET_RAW).encode("UTF-8") buffer += chr(len(address.get_ip())).encode("UTF-8") buffer += address.get_ip().encode("UTF-8") buffer += Binary.write_short(address.port) buffer += payload self.server.push_thread_to_main_packet(buffer)
def to_binary(self): buffer = b"" buffer += chr((self.reliability << self.RELIABILITY_SHIFT) | ( self.SPLIT_FLAG if self.has_split else 0)).encode("UTF-8") buffer += Binary.write_short(len(self.buffer) << 3) buffer += Binary.write_l_triad( self.message_index) if PacketReliability.is_reliable( self.reliability) else b"" buffer += Binary.write_l_triad( self.sequence_index) if PacketReliability.is_sequenced( self.reliability) else b"" buffer += Binary.write_l_triad(self.order_index + chr( self.order_channel)) if PacketReliability.is_sequenced_or_ordered( self.reliability) else b"" buffer += Binary.write_int(self.split_count) + Binary.write_short( self.split_id) + Binary.write_int( self.split_index) if self.has_split else b"" return buffer + self.buffer
def stream_open(self, session): buffer = b"" address = session.get_address() identifier = address.to_string() buffer += chr(PyRakLib.PACKET_OPEN_SESSION) buffer += chr(len(identifier)) buffer += identifier buffer += chr(len(address.ip)) buffer += Binary.write_short(address.port) buffer += Binary.write_long(session.get_id()) self.server.push_thread_to_main_packet(buffer)
def from_random(self): return self.from_data( Binary.write_int(int(time.time())), Binary.write_short(os.getpid()), Binary.write_short(os.geteuid()), Binary.write_int(random.randint(-0x7fffffff, 0x7fffffff)), Binary.write_int(random.randint(-0x7fffffff, 0x7fffffff)))
def put_short(self, v: int): self.buffer += Binary.write_short(v)