public void LoadPlayer() { string savename = ServerSettings.OnlineMode ? Uuid : Username; if (File.Exists("Players/" + savename + ".pdata")) { byte[] data = File.ReadAllBytes("Players/" + savename + ".pdata"); data = Globals.Decompress(data); DataBuffer reader = new DataBuffer(data); double x = reader.ReadDouble(); double y = reader.ReadDouble(); double z = reader.ReadDouble(); float yaw = reader.ReadFloat(); float pitch = reader.ReadFloat(); bool onGround = reader.ReadBool(); KnownPosition = new PlayerLocation(x, y, z) {Yaw = yaw, Pitch = pitch, OnGround = onGround}; Gamemode = (Gamemode) reader.ReadVarInt(); int healthLength = reader.ReadVarInt(); byte[] healthData = reader.Read(healthLength); int inventoryLength = reader.ReadVarInt(); byte[] inventoryData = reader.Read(inventoryLength); HealthManager.Import(healthData); Inventory.Import(inventoryData); } else { KnownPosition = Level.GetSpawnPoint(); } Loaded = true; }
private bool ReadUncompressed(ClientWrapper client, NetworkStream clientStream, int dlength) { var buffie = new byte[dlength]; int receivedData; receivedData = clientStream.Read(buffie, 0, buffie.Length); if (receivedData > 0) { var buf = new DataBuffer(client); if (client.Decrypter != null) { var date = new byte[4096]; client.Decrypter.TransformBlock(buffie, 0, buffie.Length, date, 0); buf.BufferedData = date; } else { buf.BufferedData = buffie; } buf.BufferedData = buffie; buf.Size = dlength; var packid = buf.ReadVarInt(); if (!new PackageFactory(client, buf).Handle(packid)) { ConsoleFunctions.WriteWarningLine("Unknown packet received! \"0x" + packid.ToString("X2") + "\""); } buf.Dispose(); return true; } else { return false; } }