public static void ReadKeepAlive(TestClient client, PacketReader reader) { KeepAlivePacket ka = new KeepAlivePacket(); ka.Read(reader); if (!reader.Failed) TestClient.HandlePacketKeepAlive(client, ka); }
internal ItemStack(PacketReader stream) { Type = stream.ReadShort(); if (Type >= 0) { Count = stream.ReadSByte(); Durability = stream.ReadShort(); } }
internal ItemStack(PacketReader 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(); } }
internal MetaData(PacketReader 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 static void ReadUpdateHealth(TestClient client, PacketReader reader) { UpdateHealthPacket uh = new UpdateHealthPacket(); uh.Read(reader); }
public static void ReadEntityTeleport(TestClient client, PacketReader reader) { EntityTeleportPacket et = new EntityTeleportPacket(); et.Read(reader); }
public static void ReadTimeUpdate(TestClient client, PacketReader reader) { TimeUpdatePacket tu = new TimeUpdatePacket(); tu.Read(reader); }
public static void ReadEntityMetadata(TestClient client, PacketReader reader) { EntityMetadataPacket em = new EntityMetadataPacket(); em.Read(reader); }
public static void ProcessReadQueue() { int count = RecvClientQueue.Count; Parallel.For(0, count, i => { Client client; if (!RecvClientQueue.TryDequeue(out client)) return; if (!client.Running) return; Interlocked.Exchange(ref client.TimesEnqueuedForRecv, 0); ByteQueue bufferToProcess = client.GetBufferToProcess(); int length = client.FragPackets.Size + bufferToProcess.Size; while (length > 0) { byte packetType = 0; if (client.FragPackets.Size > 0) packetType = client.FragPackets.GetPacketID(); else packetType = bufferToProcess.GetPacketID(); //client.Logger.Log(Chraft.Logger.LogLevel.Info, "Reading packet {0}", ((PacketType)packetType).ToString()); PacketHandler handler = PacketHandlers.GetHandler((PacketType)packetType); if (handler == null) { byte[] unhandledPacketData = GetBufferToBeRead(bufferToProcess, client, length); // TODO: handle this case, writing on the console a warning and/or writing it plus the bytes on a log client.Logger.Log(Chraft.Logger.LogLevel.Caution, "Unhandled packet arrived, id: {0}", unhandledPacketData[0]); client.Logger.Log(Chraft.Logger.LogLevel.Warning, "Data:\r\n {0}", BitConverter.ToString(unhandledPacketData, 1)); length = 0; } else if (handler.Length == 0) { byte[] data = GetBufferToBeRead(bufferToProcess, client, length); if (length >= handler.MinimumLength) { PacketReader reader = new PacketReader(data, length, StreamRole.Server); handler.OnReceive(client, reader); // If we failed it's because the packet isn't complete if (reader.Failed) { EnqueueFragment(client, data); length = 0; } else { bufferToProcess.Enqueue(data, reader.Index, data.Length - reader.Index); length = bufferToProcess.Length; } } else EnqueueFragment(client, data); } else if (length >= handler.Length) { byte[] data = GetBufferToBeRead(bufferToProcess, client, handler.Length); PacketReader reader = new PacketReader(data, handler.Length, StreamRole.Server); handler.OnReceive(client, reader); // If we failed it's because the packet isn't complete if (reader.Failed) { EnqueueFragment(client, data); length = 0; } else length = bufferToProcess.Length; } else { byte[] data = GetBufferToBeRead(bufferToProcess, client, length); EnqueueFragment(client, data); length = 0; } } }); }
public static void ReadAnimation(TestClient client, PacketReader reader) { AnimationPacket ap = new AnimationPacket(); ap.Read(reader); }
public static void ReadEntityRelativeMove(TestClient client, PacketReader reader) { EntityRelativeMovePacket er = new EntityRelativeMovePacket(); er.Read(reader); }
public static void ReadNewInvalidState(TestClient client, PacketReader reader) { NewInvalidStatePacket ni = new NewInvalidStatePacket(); ni.Read(reader); }
public static void ReadPickupSpawn(TestClient client, PacketReader reader) { SpawnItemPacket si = new SpawnItemPacket(); si.Read(reader); }
public static void ReadMultiBlockChange(TestClient client, PacketReader reader) { MultiBlockChangePacket mbc = new MultiBlockChangePacket(); mbc.Read(reader); }
public static void ReadNamedEntitySpawn(TestClient client, PacketReader reader) { NamedEntitySpawnPacket bc = new NamedEntitySpawnPacket(); bc.Read(reader); }
public static void ReadMobSpawn(TestClient client, PacketReader reader) { MobSpawnPacket ms = new MobSpawnPacket(); ms.Read(reader); }
public static void ReadMapChunk(TestClient client, PacketReader reader) { MapChunkPacket mc = new MapChunkPacket(); mc.Read(reader); }
public static void ReadLoginRequest(TestClient client, PacketReader reader) { LoginRequestPacket lr = new LoginRequestPacket(); lr.Read(reader); if (!reader.Failed) TestClient.HandlePacketLoginRequest(client, lr); }
public static void ReadUpdateSign(TestClient client, PacketReader reader) { UpdateSignPacket us = new UpdateSignPacket(); us.Read(reader); }
public static void ReadPlayerListItem(TestClient client, PacketReader reader) { PlayerListItemPacket pl = new PlayerListItemPacket(); pl.Read(reader); }
public static void ReadUpdateWindowProperty(TestClient client, PacketReader reader) { UpdateWindowPropertyPacket up = new UpdateWindowPropertyPacket(); up.Read(reader); }
public static void ReadPlayerPositionRotation(TestClient client, PacketReader reader) { PlayerPositionRotationPacket ppr = new PlayerPositionRotationPacket(); ppr.Read(reader); if (!reader.Failed) TestClient.HandlePacketPlayerPositionRotation(client, ppr); }
internal static ItemStack Read(PacketReader stream) { ItemStack retval = new ItemStack(stream.ReadShort()); if (retval.Type >= 0) { retval.Count = stream.ReadSByte(); retval.Durability = stream.ReadShort(); // TODO: Implement extra data read (enchantment) and items if (retval.Durability > 0 || retval.IsEnchantable()) stream.ReadShort(); } return retval; }
public static void ReadEntityLookAndRelativeMove(TestClient client, PacketReader reader) { EntityLookAndRelativeMovePacket ela = new EntityLookAndRelativeMovePacket(); ela.Read(reader); }
internal static ItemStack Read(PacketReader stream) { ItemStack retval = new ItemStack(stream.ReadShort()); if (retval.Type >= 0) { retval.Count = stream.ReadSByte(); retval.Durability = stream.ReadShort(); } return retval; }
public static void ReadSoundEffect(TestClient client, PacketReader reader) { SoundOrParticleEffectPacket se = new SoundOrParticleEffectPacket(); se.Read(reader); }
public static ItemInventory GetInstance(PacketReader stream) { ItemInventory item = null; Type itemClass; short type = stream.ReadShort(); sbyte count; short durability; if (type >= 0) { count = stream.ReadSByte(); durability = stream.ReadShort(); if (_itemClasses.TryGetValue(type, out itemClass)) { item = (ItemInventory)itemClass.GetConstructor(Type.EmptyTypes).Invoke(null); item.Count = count; item.Durability = durability; // TODO: Implement extra data read (enchantment) and items //if (durability > 0 || item.IsEnchantable) stream.ReadShort(); } } return item; }
public static void ReadSpawnPosition(TestClient client, PacketReader reader) { SpawnPositionPacket si = new SpawnPositionPacket(); si.Read(reader); if (!reader.Failed) TestClient.HandlePacketSpawnPosition(client, si); }
public static void ReadSetSlot(TestClient client, PacketReader reader) { SetSlotPacket ss = new SetSlotPacket(); ss.Read(reader); }
public static void ReadEntityStatus(TestClient client, PacketReader reader) { EntityStatusPacket es = new EntityStatusPacket(); es.Read(reader); }