Exemple #1
0
        public MinecraftPacket GetMinecraftPacket(int msgId, byte[] buffer = null)
        {
            MinecraftPacket pk = null;

            MineNET_Registries.MinecraftPacket.TryGetValue(msgId, out pk);
            pk = pk?.Clone();

            if (pk != null && buffer != null)
            {
                pk.SetBuffer(buffer);
                pk.Decode();
            }

            return(pk);
        }
Exemple #2
0
        public void HandleMinecraftPacket(BatchPacket pk, Player player)
        {
            using (BinaryStream stream = new BinaryStream(pk.Payload))
            {
                while (!stream.EndOfStream)
                {
                    int             len    = stream.ReadVarInt();
                    byte[]          buffer = stream.ReadBytes(len);
                    MinecraftPacket packet = this.Manager.GetMinecraftPacket(buffer[0], buffer);
                    if (packet != null)
                    {
                        /*DataPacketReceiveArgs args = new DataPacketReceiveArgs(player, pk);
                         * ServerEvents.OnPacketReceive(args);
                         *
                         * if (args.IsCancel)
                         * {
                         *  return;
                         * }*/

                        if (Server.Instance.Config.PacketDebug)
                        {
                            Logger.Debug("%server.network.minecraft.receivePacket", buffer[0].ToString("X"),
                                         buffer.Length);
                        }


                        Server.Instance.Invoke(() => player.OnPacketHandle(packet.Clone()));
                    }
                    else
                    {
                        if (Server.Instance.Config.PacketDebug)
                        {
                            Logger.Debug("%server.network.minecraft.notHandle", buffer[0].ToString("X"));
                        }
                    }
                }
            }
        }