def test_readfloat(self): inputs = ( b"\xF1\x00\xF1\x00\xF1\x00\xF1\x00", bytes(b"\xF1\x00\xF1\x00\xF1\x00\xF1\x00"), bytearray([0xF1, 0x00, 0xF1, 0x00, 0xF1, 0x00, 0xF1, 0x00]), ) for i in inputs: reader = ByteReader(i) self.assertEqual(reader.readFloat(False), 2.2132692287005784e-38) self.assertEqual(reader.readFloat(True), -6.384869180745487e+29)
def test_readbyte(self): inputs = ( b"\xF1\xF1\xF1", bytes(b"\xF1\xF1\xF1"), bytearray([0xF1, 0xF1, 0xF1]), ) for i in inputs: reader = ByteReader(i) self.assertEqual(reader.readByte(False), -15) self.assertEqual(reader.readByte(True), 241)
def test_read(self): inputs = ( b"\x00\xF0\xFF", bytes(b"\x00\xF0\xFF"), bytearray([0x00, 0xF0, 0xFF]), ) for i in inputs: reader = ByteReader(i) self.assertEqual(reader.read(1), b"\x00") self.assertEqual(reader.read(), b"\xF0\xFF")
def loader_received(self, loader): if self.player_id is not None: # atleast player spawned if not self.completed_version_challenge: data = ByteReader(loader.data) packet_id = data.readByte(True) if packet_id == HandShakeReturn.id: handshake_return = HandShakeReturn() handshake_return.read(data) if handshake_return.challenge_passed == 1: self.on_handshake_answer() return None elif packet_id == VersionSend.id: versend = VersionSend() versend.read(data) self.on_version_answer(versend) return None return connection.loader_received(self, loader)
def loader_received(self, loader): # work around the on_shoot_set event only firing with weapon or spade # on_primary_fire_set should be added in server.py, some day if self.sculpting: if self.player_id is not None: contained = load_client_packet(ByteReader(loader.data)) if self.hp: if contained.id == loaders.WeaponInput.id: primary = contained.primary if self.world_object.primary_fire != primary: self.on_primary_fire_set(primary) return connection.loader_received(self, loader)
def test_readint(self): inputs = ( b"\xF1\x00\xF1\x00\xF1\x00\xF1\x00", bytes(b"\xF1\x00\xF1\x00\xF1\x00\xF1\x00"), bytearray([0xF1, 0x00, 0xF1, 0x00, 0xF1, 0x00, 0xF1, 0x00]), ) for i in inputs: reader = ByteReader(i) self.assertEqual(reader.readInt(False), -251596544) self.assertEqual(reader.readInt(True), 4043370752) # Small endian reader = ByteReader(i) self.assertEqual(reader.readInt(False, False), 15794417) self.assertEqual(reader.readInt(True, False), 15794417)
def test_readshort(self): inputs = ( b"\xF1\x00\xF1\x00", bytes(b"\xF1\x00\xF1\x00"), bytearray([0xF1, 0x00, 0xF1, 0x00]), ) for i in inputs: reader = ByteReader(i) self.assertEqual(reader.readShort(False), -3840) self.assertEqual(reader.readShort(True), 61696) # Small endian reader = ByteReader(i) self.assertEqual(reader.readShort(False, False), 241) self.assertEqual(reader.readShort(True, False), 241)