Ejemplo n.º 1
0
 public void Disconnect()
 {
     if (this.serverConnection != null)
     {
         this.serverConnection.Disconnect();
         serverConnection = null;
     }
 }
Ejemplo n.º 2
0
        public void Connect()
        {
            string address = "192.168.1.102";
            int    port    = 23;

            try
            {
                Interface.StatusText.Text = "Attempting a connection to " + address + ", port " + port.ToString() + "...";
                this.serverConnection     = new MUDServerConnection(address, port, PlayerName);
            }
            catch (Exception)
            {
                Interface.StatusText.Text = "Connection failed.  Please verify your internet connectivity and server information, then try again.";
                return;
            }

            Interface.StatusText.Text              = "Connected.";
            this.serverConnection.serverMessage   += new MUDServerConnection.serverMessageEventHandler(serverConnection_serverMessage);
            this.serverConnection.disconnected    += new MUDServerConnection.disconnectionEventHandler(serverConnection_disconnected);
            this.Interface.ConnectButton.IsChecked = true;
        }
Ejemplo n.º 3
0
        //when the main window loads, prompt the user for connection info
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            bool successfulConnection;
            do
            {
                //prompts
                string address = TextInputDialog.PromptUser("Server Address", "Input a MUD server address:");
                string portString = TextInputDialog.PromptUser("Server Port", "Enter the server's port number:");

                //convert port to int, default to port=23 in the event of any parsing issue
                int port;
                if (!int.TryParse(portString, out port))
                    port = 23;

                //attempt a connection
                successfulConnection = true;
                try
                {
                    //tell the user what we're doing first
                    this.appendText("Attempting a connection to " + address + ", port " + port.ToString() + "...");

                    //then give it a shot
                    this.serverConnection = new MUDServerConnection(address, port);
                }

                //if there's any problem, start over with prompts again
                catch (Exception)
                {
                    this.appendText("Connection failed.  Please verify your internet connectivity and server information, then try again.");
                    successfulConnection = false;
                }
            }
            while (!successfulConnection);

            //now that we've connected, start listening for messages and disconnections
            this.serverConnection.serverMessage += new MUDServerConnection.serverMessageEventHandler(serverConnection_serverMessage);
            this.serverConnection.disconnected += new MUDServerConnection.disconnectionEventHandler(serverConnection_disconnected);
            this.serverConnection.telnetMessage += new MUDServerConnection.serverTelnetEventHandler(serverConnection_telnetMessage);
        }
Ejemplo n.º 4
0
 void serverConnection_disconnected()
 {
     Interface.StatusText.Text = "Disconnected.";
     serverConnection          = null;
     this.Interface.ConnectButton.IsChecked = false;
 }