示例#1
0
        public static void ReadKeepAlive(TestClient client, PacketReader reader)
        {
            KeepAlivePacket ka = new KeepAlivePacket();
            ka.Read(reader);

            if (!reader.Failed)
                TestClient.HandlePacketKeepAlive(client, ka);
        }
示例#2
0
 internal ItemStack(PacketReader stream)
 {
     Type = stream.ReadShort();
     if (Type >= 0)
     {
         Count = stream.ReadSByte();
         Durability = stream.ReadShort();
     }
 }
示例#3
0
        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();
            }
        }
示例#4
0
 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;
         }
     }
 }
示例#5
0
 public static void ReadUpdateHealth(TestClient client, PacketReader reader)
 {
     UpdateHealthPacket uh = new UpdateHealthPacket();
     uh.Read(reader);
 }
示例#6
0
 public static void ReadEntityTeleport(TestClient client, PacketReader reader)
 {
     EntityTeleportPacket et = new EntityTeleportPacket();
     et.Read(reader);
 }
示例#7
0
 public static void ReadTimeUpdate(TestClient client, PacketReader reader)
 {
     TimeUpdatePacket tu = new TimeUpdatePacket();
     tu.Read(reader);
 }
示例#8
0
 public static void ReadEntityMetadata(TestClient client, PacketReader reader)
 {
     EntityMetadataPacket em = new EntityMetadataPacket();
     em.Read(reader);
 }
示例#9
0
文件: Server.cs 项目: IdentErr/c-raft
        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;
                    }
                }
            });
        }
示例#10
0
 public static void ReadAnimation(TestClient client, PacketReader reader)
 {
     AnimationPacket ap = new AnimationPacket();
     ap.Read(reader);
 }
示例#11
0
 public static void ReadEntityRelativeMove(TestClient client, PacketReader reader)
 {
     EntityRelativeMovePacket er = new EntityRelativeMovePacket();
     er.Read(reader);
 }
示例#12
0
 public static void ReadNewInvalidState(TestClient client, PacketReader reader)
 {
     NewInvalidStatePacket ni = new NewInvalidStatePacket();
     ni.Read(reader);
 }
示例#13
0
 public static void ReadPickupSpawn(TestClient client, PacketReader reader)
 {
     SpawnItemPacket si = new SpawnItemPacket();
     si.Read(reader);
 }
示例#14
0
 public static void ReadMultiBlockChange(TestClient client, PacketReader reader)
 {
     MultiBlockChangePacket mbc = new MultiBlockChangePacket();
     mbc.Read(reader);
 }
示例#15
0
 public static void ReadNamedEntitySpawn(TestClient client, PacketReader reader)
 {
     NamedEntitySpawnPacket bc = new NamedEntitySpawnPacket();
     bc.Read(reader);
 }
示例#16
0
 public static void ReadMobSpawn(TestClient client, PacketReader reader)
 {
     MobSpawnPacket ms = new MobSpawnPacket();
     ms.Read(reader);
 }
示例#17
0
 public static void ReadMapChunk(TestClient client, PacketReader reader)
 {
     MapChunkPacket mc = new MapChunkPacket();
     mc.Read(reader);
 }
示例#18
0
        public static void ReadLoginRequest(TestClient client, PacketReader reader)
        {
            LoginRequestPacket lr = new LoginRequestPacket();
            lr.Read(reader);

            if (!reader.Failed)
                TestClient.HandlePacketLoginRequest(client, lr);
        }
示例#19
0
 public static void ReadUpdateSign(TestClient client, PacketReader reader)
 {
     UpdateSignPacket us = new UpdateSignPacket();
     us.Read(reader);
 }
示例#20
0
 public static void ReadPlayerListItem(TestClient client, PacketReader reader)
 {
     PlayerListItemPacket pl = new PlayerListItemPacket();
     pl.Read(reader);
 }
示例#21
0
 public static void ReadUpdateWindowProperty(TestClient client, PacketReader reader)
 {
     UpdateWindowPropertyPacket up = new UpdateWindowPropertyPacket();
     up.Read(reader);
 }
示例#22
0
        public static void ReadPlayerPositionRotation(TestClient client, PacketReader reader)
        {
            PlayerPositionRotationPacket ppr = new PlayerPositionRotationPacket();
            ppr.Read(reader);

            if (!reader.Failed)
                TestClient.HandlePacketPlayerPositionRotation(client, ppr);
        }
示例#23
0
        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;
        }
示例#24
0
 public static void ReadEntityLookAndRelativeMove(TestClient client, PacketReader reader)
 {
     EntityLookAndRelativeMovePacket ela = new EntityLookAndRelativeMovePacket();
     ela.Read(reader);
 }
示例#25
0
 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;
 }
示例#26
0
 public static void ReadSoundEffect(TestClient client, PacketReader reader)
 {
     SoundOrParticleEffectPacket se = new SoundOrParticleEffectPacket();
     se.Read(reader);
 }
示例#27
0
        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;
        }
示例#28
0
        public static void ReadSpawnPosition(TestClient client, PacketReader reader)
        {
            SpawnPositionPacket si = new SpawnPositionPacket();
            si.Read(reader);

            if (!reader.Failed)
                TestClient.HandlePacketSpawnPosition(client, si);
        }
示例#29
0
 public static void ReadSetSlot(TestClient client, PacketReader reader)
 {
     SetSlotPacket ss = new SetSlotPacket();
     ss.Read(reader);
 }
示例#30
0
 public static void ReadEntityStatus(TestClient client, PacketReader reader)
 {
     EntityStatusPacket es = new EntityStatusPacket();
     es.Read(reader);
 }