Ejemplo n.º 1
0
        protected virtual void Dispose(bool disposing)
        {
            if (!this.disposed)
            {

                if (DataThread != null)
                {
                    DataThread.Abort();
                }
                if (disposing)
                {
                    // Dispose managed resources.
                    if (Stream != null)
                    {
                        Stream.Dispose();
                    }
                    if (MainSocket != null)
                    {
                        MainSocket.Dispose();
                    }
                    if (PositionTimer != null)
                    {
                        PositionTimer.Dispose();
                    }
                }

                DataThread = null;
                ServerAddress = null;
                Server = null;
                disposed = true;

            }
        }
Ejemplo n.º 2
0
        public void Connect()
        {
            if (UseAuthentication)
            {
                this.SessionID = Authenticate();
                if (this.SessionID == "")
                {
                    Debug.Severe(new MinecraftClientConnectException("Authentication Failed."));
                    return;
                }
            }

            this.MainSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            while (!MainSocket.Connected)
            {
                try
                {
                    this.MainSocket.Connect(ServerAddress);
                }
                catch (Exception e) { Debug.Severe(e); }
            }

            this.Stream = new NetworkStream(MainSocket);
            this.Server = new MinecraftServer(MainSocket);
            this.Server.Password = "******";

            if (!SendInitialPackets())
            {
                Debug.Severe(new MinecraftClientConnectException());
                return;
            }

            this.Connected = true;
            this.PlayerLocation = new Location(0D, 0D, 0D, 0D + 1.65);
            this.PlayerRotation = new Rotation(0F, 0F);

            DataThread = new Thread(HandleData);
            DataThread.Start();

            PositionTimer = new System.Timers.Timer(100);
            PositionTimer.Elapsed += new ElapsedEventHandler(PositionTimer_Elapsed);
        }