Пример #1
0
        public void AddPacketBatchQueue(MinecraftPacket packet, int reliability, int flags = RakNetProtocol.FlagNormal)
        {
            packet.Encode();

            byte[] buffer = packet.ToArray();

            BinaryStream st = new BinaryStream();

            st.WriteVarInt((int)buffer.Length);
            st.WriteBytes(buffer);

            if (Server.Instance.Config.PacketDebug)
            {
                Logger.Debug("%server.network.minecraft.sendPacket", packet.PacketID.ToString("X"), packet.Length);
            }

            BatchPacket pk = new BatchPacket();

            if (packet is FullChunkDataPacket)
            {
                pk.CompressionLevel = CompressionLevel.Optimal;
            }

            pk.Payload = st.ToArray();

            string endPointStr = this.EndPoint.ToString();
            Player player      = null;

            Server.Instance.Network.Players.TryGetValue(endPointStr, out player);
            if (player == null)
            {
                return;
            }

            RakNetBatchPacketSendEventArgs ev = new RakNetBatchPacketSendEventArgs(this, player, pk);

            Server.Instance.Event.Network.OnRakNetBatchPacketSend(this, ev);

            if (ev.IsCancel)
            {
                return;
            }

            pk = ev.Packet;

            this.QueueConnectedPacket(pk, reliability, packet.OrderChannel, flags);
        }
Пример #2
0
 public void OnRakNetBatchPacketSend(object sender, RakNetBatchPacketSendEventArgs e)
 {
     this.RakNetBatchPacketSend?.Invoke(sender, e);
 }