public override void Write(BigEndianStream stream) { stream.Write(EntityId); stream.Write(Unknown); stream.Write(X); stream.Write(Y); stream.Write(Z); }
public override void Read(BigEndianStream stream) { EntityId = stream.ReadInt(); Unknown = stream.ReadBool(); X = stream.ReadDoublePacked(); Y = stream.ReadDoublePacked(); Z = stream.ReadDoublePacked(); }
internal ItemStack(BigEndianStream stream) { Type = stream.ReadShort(); if (Type >= 0) { Count = stream.ReadSByte(); Durability = stream.ReadShort(); } }
public PacketHandler(Server server, BigEndianStream stream) { Server = server; Net = stream; QueueThread = new Thread(QueueProc); QueueThread.IsBackground = true; QueueThread.Start(); }
internal ItemStack(BigEndianStream stream) { Type = stream.ReadShort(); if (Type >= 0) { Count = stream.ReadSByte(); Durability = stream.ReadShort(); // TODO: Implement extra data read (enchantment) and items if (Durability > 0 || IsEnchantable()) stream.ReadShort(); } }
public override void Write(BigEndianStream stream) { stream.Write(X); stream.Write(Y); stream.Write(Z); stream.Write(SizeX); stream.Write(SizeY); stream.Write(SizeZ); int o = 16 * 16 * 128; byte[] data = new byte[o * 5 / 2]; int i = 0; for (int x = 0; x < 16; x++) { for (int z = 0; z < 16; z++) { for (int y = 0; y < 128; y++) { int s = ((i + 1) & 1) * 4; int ofst = i; data[ofst] = Chunk[x, y, z]; ofst = i / 2 + o * 2 / 2; data[ofst] = unchecked((byte)(data[ofst] | (Chunk.GetData(x, y, z) << s))); ofst = i / 2 + o * 3 / 2; data[ofst] = unchecked((byte)(data[ofst] | (Chunk.GetBlockLight(x, y, z) << s))); ofst = i / 2 + o * 4 / 2; data[ofst] = unchecked((byte)(data[ofst] | (Chunk.GetSkyLight(x, y, z) << s))); i++; } } } byte[] comp = new byte[o * 5]; int len; Deflater deflater = new Deflater(0); try { deflater.setInput(data); deflater.finish(); len = deflater.deflate(comp); } finally { deflater.end(); } stream.Write(len); stream.Write(comp, 0, len); }
internal MetaData(BigEndianStream rx) { byte x; while ((x = rx.ReadByte()) != 0x7f) { switch (x >> 5) { case 0: Data[x & 0x1f] = rx.ReadByte(); break; case 1: Data[x & 0x1f] = rx.ReadShort(); break; case 2: Data[x & 0x1f] = rx.ReadInt(); break; case 3: Data[x & 0x1f] = rx.ReadFloat(); break; case 4: Data[x & 0x1f] = rx.ReadString16(64); break; default: Data[x & 0x1f] = null; break; } } }
public override void Read(BigEndianStream stream) { int posX = stream.ReadInt(); short posY = stream.ReadShort(); int posZ = stream.ReadInt(); byte sizeX = (byte)(stream.ReadByte() + 1); byte sizeY = (byte)(stream.ReadByte() + 1); byte sizeZ = (byte)(stream.ReadByte() + 1); int o = sizeX * sizeY * sizeZ; Chunk = new Chunk(null, posX, posZ); int len = stream.ReadInt(); byte[] comp = new byte[len]; byte[] data = new byte[o * 5 / 2]; len = stream.Read(comp, 0, len); }
protected virtual void LoadExtraData(BigEndianStream stream) { }
protected virtual void DoSave(int slotStart, int slotsCount, string dataFile) { string file = Path.Combine(ContainerFolder, dataFile); if (IsEmpty) { File.Delete(file); return; } try { using (FileStream fileStream = File.Create(file + ".tmp")) { using (BigEndianStream bigEndianStream = new BigEndianStream(fileStream, StreamRole.Server)) { ItemStack stack = ItemStack.Void; for (int i = slotStart; i < slotsCount; i++) { stack = Slots[i]; if (stack != null) { stack.Write(bigEndianStream); } else { ItemStack.Void.Write(bigEndianStream); } } SaveExtraData(bigEndianStream); } } } finally { File.Delete(file); File.Move(file + ".tmp", file); } }
protected virtual void DoLoad(int slotStart, int slotsCount, string dataFile) { string file = Path.Combine(ContainerFolder, dataFile); if (File.Exists(file)) { using (FileStream containerStream = File.Open(file, FileMode.Open, FileAccess.Read)) { using (BigEndianStream bigEndian = new BigEndianStream(containerStream, StreamRole.Server)) { for (int i = slotStart; i < slotsCount; i++) Slots[i] = new ItemStack(bigEndian); LoadExtraData(bigEndian); } } } }
protected virtual void DoSaveToFile(ItemStack[] itemStack, string file) { if (this.IsEmpty()) { File.Delete(file); } else { try { using (FileStream fileStream = File.Create(file + ".tmp")) { using (BigEndianStream bigEndian = new BigEndianStream(fileStream, StreamRole.Server)) { foreach (ItemStack stack in itemStack) { if (stack != null) { stack.Write(bigEndian); } else { ItemStack.Void.Write(bigEndian); } } } } } finally { File.Delete(file); File.Move(file + ".tmp", file); } } }
public static ItemInventory GetInstance(BigEndianStream stream) { ItemInventory item = Void; Type itemClass; short type = stream.ReadShort(); if (type >= 0) { if (_itemClasses.TryGetValue(type, out itemClass)) { item = (ItemInventory) itemClass.GetConstructor(Type.EmptyTypes).Invoke(null); item.Count = stream.ReadSByte(); item.Durability = stream.ReadShort(); // TODO: Implement extra data read (enchantment) and items //if (item.Durability > 0 || item.IsEnchantable) stream.ReadShort(); } } return item; }
internal static ItemStack Read(BigEndianStream stream) { ItemStack retval = new ItemStack(stream.ReadShort()); if (retval.Type >= 0) { retval.Count = stream.ReadSByte(); retval.Durability = stream.ReadShort(); } return retval; }
internal void Write(BigEndianStream stream) { stream.Write(Type > 0 ? Type : (short)-1); if (Type > 0) { stream.Write(Count); stream.Write(Durability); } }
protected virtual void DoLoadFromFile(ItemStack[] itemStack, string file) { if (File.Exists(file)) { using (FileStream containerStream = File.Open(file, FileMode.Open, FileAccess.Read)) { using (BigEndianStream bigEndian = new BigEndianStream(containerStream, StreamRole.Server)) { for (int i = 0; i < itemStack.Length; i++) { itemStack[i] = new ItemStack(bigEndian); } } } } }
internal void WriteEnchantmentsToNBT(BigEndianStream stream) { // TODO: Implement this /* Gzip the nbt representing enchantments * write the gzipped output length * write output */ }
internal void Write(BigEndianStream stream) { stream.Write(Type > 0 ? Type : (short)-1); if (Type > 0) { stream.Write(Count); stream.Write(Durability); //if (Durability > 0 || IsEnchantable()) stream.Write((short)-1); // TODO: Remove the two lines above and implement items and enchantments write /* * if (Item.CanBeDamaged()) * { * if(_enchantments != null) * WriteEnchantmentsToNBT(stream); * else * stream.Write(-1); * } */ } }
public override void Write(BigEndianStream stream) { stream.Write(Statistic); stream.Write(Amount); }
protected virtual void SaveExtraData(BigEndianStream stream) { }
internal void Write(BigEndianStream tx) { try // I can't work out how it set this from SpawnAnimal. { foreach (int k in Data.Keys) { Type type = Data[k].GetType(); if (type == typeof(byte)) { tx.WriteByte((byte)k); tx.Write((byte)Data[k]); } else if (type == typeof(short)) { tx.WriteByte((byte)(0x20 | k)); tx.Write((short)Data[k]); } else if (type == typeof(int)) { tx.WriteByte((byte)(0x40 | k)); tx.Write((int)Data[k]); } else if (type == typeof(float)) { tx.WriteByte((byte)(0x60 | k)); tx.Write((float)Data[k]); } else if (type == typeof(string)) { tx.WriteByte((byte)(0x80 | k)); tx.Write((string)Data[k]); } } } catch { } finally { tx.WriteByte(0x7f); } }
public override void Write(BigEndianStream stream) { stream.WriteByte((byte)Reason); }
public override void Read(BigEndianStream stream) { Reason = (InvalidReason)stream.ReadByte(); }
internal void ReadEnchantmentsFromNBT(BigEndianStream stream) { // TODO: Implement this and choose return value }
public override void Read(BigEndianStream stream) { Statistic = stream.ReadInt(); Amount = stream.ReadByte(); }