コード例 #1
0
        void ILidgrenClientEvents.OnDisconnect(string reason)
        {
            //Set the lidgren client to null
            lidgrenClient = null;

            //Update the UI
            buttonConnectDisconnect.Text    = connectText;
            buttonConnectDisconnect.Enabled = true;
            textBoxHostName.Enabled         = true;
            textBoxPlayerName.Enabled       = true;
        }
コード例 #2
0
        private void AttemptToConnect()
        {
            //Check there isn't already a networking object
            if (lidgrenClient != null)
            {
                LogMessage("Error, new attempt to connect to server but there already exists an connection attempt");
            }

            //Check the hostname and playername
            if (string.IsNullOrWhiteSpace(textBoxHostName.Text))
            {
                LogMessage("Host name is null, empty or whitespace");
                return;
            }
            if (string.IsNullOrWhiteSpace(textBoxPlayerName.Text))
            {
                LogMessage("Player name is null, empty or whitespace");
                return;
            }

            //Store the names in the config (so it can be written to disk on application close)
            config.ServerHostName = textBoxHostName.Text;
            config.PlayerName     = textBoxPlayerName.Text;

            //Lock the UI
            textBoxPlayerName.Enabled       = false;
            textBoxHostName.Enabled         = false;
            buttonConnectDisconnect.Enabled = false;

            //Update the button text
            buttonConnectDisconnect.Text = connectingText;

            //Get the configuration of the client
            if (string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["AppIdentifier"]))
            {
                LogMessage("Error, could not start server because AppIdentifier is null empty or whitespace");
                return;
            }
            if (!int.TryParse(ConfigurationManager.AppSettings["Port"], out int port))
            {
                LogMessage("Error, could not start server because Port could not be parsed from config");
                return;
            }

            //Create the client
            lidgrenClient = new LidgrenClient(ConfigurationManager.AppSettings["AppIdentifier"], this,
                                              this, config.ServerHostName, port);

            //Try to connect to the server
            lidgrenClient.AttemptToConnectToServer();
        }