Пример #1
0
        public void SendPacket(Packet packet)
        {
            if (packet.PacketId == -1)
            {
                throw new Exception();
            }

            byte[] encodedPacket;
            using (MemoryStream ms = new MemoryStream())
            {
                using (MinecraftStream mc = new MinecraftStream(ms))
                {
                    mc.WriteVarInt(packet.PacketId);
                    packet.Encode(mc);

                    encodedPacket = ms.ToArray();

                    mc.Position = 0;
                    mc.SetLength(0);

                    if (CompressionEnabled)
                    {
                        if (encodedPacket.Length >= CompressionThreshold)
                        {
                            byte[] compressed;
                            CompressData(encodedPacket, out compressed);

                            mc.WriteVarInt(encodedPacket.Length);
                            mc.Write(compressed);
                        }
                        else                         //Uncompressed
                        {
                            mc.WriteVarInt(0);
                            mc.Write(encodedPacket);
                        }

                        encodedPacket = ms.ToArray();
                    }
                }
            }

            PacketWriteQueue.Add(encodedPacket);

            /*using (MemoryStream ms = new MemoryStream())
             * {
             *      using (MinecraftStream mc = new MinecraftStream(ms))
             *      {
             *              if (EncryptionInitiated)
             *              {
             *                      mc.InitEncryption(SharedSecret);
             *              }
             *
             *                  mc.WriteVarInt(encodedPacket.Length);
             *                  mc.Write(encodedPacket);
             *          }
             *          SendDataInternal(ms.ToArray());
             * }*/
        }
Пример #2
0
        public void SendPacket(Packet packet)
        {
            if (packet.PacketId == -1)
            {
                throw new Exception();
            }

            //if (packet.Log)
            //	Log.Info($"Sending packet ({CompressionEnabled}:{EncryptionInitiated}): {packet} 0x{packet.PacketId:X2}");
//if (packet.PacketId == 14) Log.Debug($"PACKET = {packet.ToString()}");
            PacketWriteQueue.Add(new EnqueuedPacket(packet, EncryptionInitiated, CompressionEnabled));
        }
Пример #3
0
        public void SendPacket(Packet packet)
        {
            if (PacketWriteQueue.IsAddingCompleted)
            {
                // Log.Warn($"Tried to write packet after WriteQueue has been marked as complete!");
                return;
            }

            if (packet.PacketId == -1)
            {
                throw new Exception();
            }

            //if (packet.Log)
            //	Log.Info($"Sending packet ({CompressionEnabled}:{EncryptionInitiated}): {packet} 0x{packet.PacketId:X2}");
//if (packet.PacketId == 14) Log.Debug($"PACKET = {packet.ToString()}");
            PacketWriteQueue.Add(new EnqueuedPacket(packet, CompressionEnabled));
        }