Пример #1
0
        /// <summary>
        /// Disconnects from the Minecraft server.
        /// </summary>
        public void Disconnect()
        {
            if (Nh != null)
            {
                Nh.Stop();
            }

            // -- Reset all variables to default so we can make a new connection.

            Running        = false;
            ServerState    = 0;
            Nh             = null;
            MinecraftWorld = null;
            ThisPlayer     = null;
            Players        = null;

            RaiseDebug(this, "Variables reset, disconnected from server.");
        }
Пример #2
0
        public PacketEventHandler(NetworkHandler nh) {
            // -- Login packets
            nh.RegisterLoginHandler(0, new NetworkHandler.PacketHandler(HandleLoginDisconnect));
            nh.RegisterLoginHandler(1, new NetworkHandler.PacketHandler(HandleEncryptionRequest));
            nh.RegisterLoginHandler(2, new NetworkHandler.PacketHandler(HandleLoginSuccess));

            // -- Status Packets
            nh.RegisterStatusHandler(0, new NetworkHandler.PacketHandler(HandleStatusResponse));
            nh.RegisterStatusHandler(1, new NetworkHandler.PacketHandler(HandleStatusPing));

            // -- Play packets
            nh.RegisterPlayHandler(0, new NetworkHandler.PacketHandler(HandleKeepAlive));
            nh.RegisterPlayHandler(0x01, new NetworkHandler.PacketHandler(HandleJoinGame));
            nh.RegisterPlayHandler(0x02, new NetworkHandler.PacketHandler(HandleChat));
            nh.RegisterPlayHandler(0x04, new NetworkHandler.PacketHandler(HandleEntityEquipment));
            nh.RegisterPlayHandler(0x07, new NetworkHandler.PacketHandler(HandleRespawn));
            nh.RegisterPlayHandler(0x09, new NetworkHandler.PacketHandler(HandleHeldItemChange));
            nh.RegisterPlayHandler(0x0B, new NetworkHandler.PacketHandler(HandleAnimation));
            nh.RegisterPlayHandler(0x0D, new NetworkHandler.PacketHandler(HandleCollectItem));
            nh.RegisterPlayHandler(0x12, new NetworkHandler.PacketHandler(HandleEntityVelocity));
            nh.RegisterPlayHandler(0x13, new NetworkHandler.PacketHandler(HandleDestroyEntities));
            nh.RegisterPlayHandler(0x15, new NetworkHandler.PacketHandler(HandleEntityRelMove));
            nh.RegisterPlayHandler(0x16, new NetworkHandler.PacketHandler(HandleEntityLook));
            nh.RegisterPlayHandler(0x17, new NetworkHandler.PacketHandler(HandleLookEntityRelMove));
            nh.RegisterPlayHandler(0x18, new NetworkHandler.PacketHandler(HandleEntityTeleport));
            nh.RegisterPlayHandler(0x19, new NetworkHandler.PacketHandler(HandleEntityHeadLook));
            nh.RegisterPlayHandler(0x1A, new NetworkHandler.PacketHandler(HandleEntityStatus));
            nh.RegisterPlayHandler(0x1B, new NetworkHandler.PacketHandler(AttachEntity));
            nh.RegisterPlayHandler(0x1D, new NetworkHandler.PacketHandler(HandleEntityEffect));
            nh.RegisterPlayHandler(0x21, new NetworkHandler.PacketHandler(HandleChunkData));
            nh.RegisterPlayHandler(0x23, new NetworkHandler.PacketHandler(BlockChange));
            nh.RegisterPlayHandler(0x24, new NetworkHandler.PacketHandler(BlockAction));
            nh.RegisterPlayHandler(0x25, new NetworkHandler.PacketHandler(BlockBreakAnimation));
            nh.RegisterPlayHandler(0x26, new NetworkHandler.PacketHandler(HandleMapChunkBulk));
            nh.RegisterPlayHandler(0x27, new NetworkHandler.PacketHandler(HandleExplosion));
            nh.RegisterPlayHandler(0x28, new NetworkHandler.PacketHandler(HandleEffects));
            nh.RegisterPlayHandler(0x2B, new NetworkHandler.PacketHandler(ChangeGameState));
            nh.RegisterPlayHandler(0x2E, new NetworkHandler.PacketHandler(HandleCloseWindow));
            nh.RegisterPlayHandler(0x32, new NetworkHandler.PacketHandler(HandleConfirmTransaction));
            nh.RegisterPlayHandler(0x3D, new NetworkHandler.PacketHandler(HandleDisplayScoreboard));
            nh.RegisterPlayHandler(0x40, new NetworkHandler.PacketHandler(HandleDisconnect));
            
        }
Пример #3
0
        /// <summary>
        /// Connects to the MinecraftClient Server.
        /// </summary>
        public void Connect()
        {
            if (Nh != null)
            {
                Disconnect();
            }

            Players = new Dictionary <string, short>();

            Nh = new NetworkHandler(this);

            // -- Register our event handlers.
            Nh.InfoMessage   += NetworkInfo;
            Nh.DebugMessage  += NetworkDebug;
            Nh.SocketError   += NetworkError;
            Nh.PacketHandled += RaisePacketHandled;

            // -- Connect to the server and begin reading packets.

            Nh.Start();

            RaiseDebug(this, "Network handler created, Connecting to server...");
        }
Пример #4
0
        /// <summary>
        /// Disconnects from the Minecraft server.
        /// </summary>
        public void Disconnect() {
            if (nh != null)
                nh.Stop();

            // -- Reset all variables to default so we can make a new connection.

            Running = false;
            ServerState = 0;
            nh = null;
            MinecraftWorld = null;
            ThisPlayer = null;
            Players = null;

            RaiseDebug(this, "Variables reset, disconnected from server.");
        }
Пример #5
0
        /// <summary>
        /// Connects to the MinecraftClient Server.
        /// </summary>
        public void Connect() {
            if (nh != null)
                Disconnect();

            Players = new Dictionary<string,short>();

            nh = new NetworkHandler(this);

            // -- Register our event handlers.
            nh.InfoMessage += NetworkInfo;
            nh.DebugMessage += NetworkDebug;
            nh.SocketError += NetworkError;
            nh.PacketHandled += RaisePacketHandled;

            // -- Connect to the server and begin reading packets.

            nh.Start();

            RaiseDebug(this, "Network handler created, Connecting to server...");
        }