Ejemplo n.º 1
0
        public void SendPacket(Packet packet)
        {
            if (!backwardMaps[(int)ChannelState].TryGetValue(packet.GetType(), out var id))
            {
                Logger.Error($"Packet {packet.GetType().Name} cant be send to server! Check packet ids settings");
                return;
            }

            Task.Run(() =>
            {
                Monitor.Enter(PacketBuffer);
                PacketBuffer.WriteVarInt(id);
                packet.WritePacketData(PacketBuffer);

                var buffer = PacketBuffer.GetBlob();
                PacketBuffer.Clear();
                Monitor.Exit(PacketBuffer);

                streamWrapper.WriteVarInt(buffer.Length);
                streamWrapper.WriteBytes(buffer);
            });
        }
Ejemplo n.º 2
0
 protected static void WriteItem(StreamWrapper buff, ItemStack itemStack)
 {
     if (itemStack == null || itemStack.Item.Id < 0)
     {
         buff.WriteShort(-1);
     }
     else
     {
         buff.WriteShort((short)itemStack.Item.Id);
         buff.WriteByte(itemStack.ItemCount);
         buff.WriteShort(itemStack.ItemDamage);
         if (itemStack.NbtRoot != null)
         {
             buff.WriteShort((short)itemStack.NbtData.Length);
             buff.WriteBytes(itemStack.NbtData);
         }
         else
         {
             buff.WriteShort(-1);
         }
     }
 }