BF2Statistics.MainForm.LaunchServerBtn_Click C# (CSharp) Method

LaunchServerBtn_Click() private method

Server Launcher Button Click
private LaunchServerBtn_Click ( object sender, EventArgs e ) : void
sender object
e EventArgs
return void
        private async void LaunchServerBtn_Click(object sender, EventArgs e)
        {
            // Show the loading icon
            ServerStatusPic.Image = Resources.loading;

            // === Starting Server
            if (!BF2Server.IsRunning)
            {
                // We are going to test the ASP stats service here if stats are enabled. 
                // I coded this because it sucks to get ingame and everyone's stats are reset
                // because you forgot to start the stats server, or some kind of error.
                // The BF2 server will continue to load, even if it cant connect
                if (StatsPython.Installed && StatsPython.Config.StatsEnabled)
                {
                    // Loopback for the Retry Button
                    CheckAsp:
                    {
                        try
                        {
                            // Check ASP service
                            await Task.Run(() => StatsManager.ValidateASPService("http://" + StatsPython.Config.AspAddress));
                        }
                        catch (Exception Ex)
                        {
                            // ALert user
                            DialogResult Res = MessageBox.Show(
                                "Unable to connect to the Stats ASP webservice defined in the BF2Statistics config! "
                                + "Please double check your Asp Server settings and check that your ASP server is running."
                                + Environment.NewLine.Repeat(1)
                                + "Server Address: http://" + StatsPython.Config.AspAddress + Environment.NewLine
                                + "Error Message: " + Ex.Message,
                                "Stats Server Connection Failure",
                                MessageBoxButtons.AbortRetryIgnore,
                                MessageBoxIcon.Warning
                            );

                            // User Button Selection
                            if (Res == DialogResult.Retry)
                            {
                                goto CheckAsp;
                            }
                            else if (Res == DialogResult.Abort || Res != DialogResult.Ignore)
                            {
                                // Reset image
                                ServerStatusPic.Image = Resources.error;
                                return;
                            }

                        }
                    }
                }

                // Use the global server settings file?
                string Arguments = "";
                if (GlobalServerSettings.Checked)
                    Arguments += " +config \"" + Path.Combine(Program.RootPath, "Python", "GlobalServerSettings.con") + "\"";

                // Moniter Con Files?
                if (FileMoniter.Checked)
                    Arguments += " +fileMonitor 1";

                // Force AI Bots?
                if (ForceAiBots.Checked)
                    Arguments += " +ai 1";

                // Start the server
                try
                {
                    BF2Server.Start(SelectedMod, Arguments, ShowConsole.Checked, MinimizeConsole.Checked);
                }
                catch (Exception Ex)
                {
                    MessageBox.Show("Unable to start the BF2 server process!"
                        + Environment.NewLine.Repeat(1) + Ex.Message,
                        "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                try
                {
                    // Prevent button spam
                    LoadingForm.ShowScreen(this);
                    SetNativeEnabled(false);
                    BF2Server.Stop();
                }
                catch (Exception E)
                {
                    MessageBox.Show("Unable to stop the BF2 server process!"
                        + Environment.NewLine.Repeat(1) + E.Message,
                        "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
MainForm