Exemple #1
0
        private async void OnClick(object sender, EventArgs e)
        {
            if (sender == btnApplyGeneralSettings)
            {
                ButtonApplyGeneralSettings();
            }
            else if (sender == btnRunUpdater)
            {
                UpdateControls(EState.Updating);
                var updateForm = new UpdateForm(_server);
                updateForm.FormClosed += (sender_, e_) => UpdateControls(EState.Stopped);
                updateForm.Show();
            }
            else if (sender == btnStart)
            {
                if (Program.Settings.Network.AutoPortMapping)
                {
                    UpdateControls(EState.PortMapping);

                    if (!await NetworkHelper.TryCreatePortMappingAsync(_server))
                    {
                        this.ShowError("Unable to create port mapping, either your router is not available or has port mapping disabled/unsupported. " +
                                       "To fix this issue you might need to make a port forward in your router configuration (find a tutorial for your router online). " +
                                       "People outside of your local network will be unable to join your server without a port mapping/forward. " +
                                       "You can disable automatic port mapping in Help > Settings > Network.", "Port Mapping Failed");
                    }
                }

                UpdateControls(EState.Running);
                _serverRunner.StartProcess();
            }
            else if (sender == btnStop)
            {
                _serverRunner.KillProcess();
            }
            else if (sender == btnConnect)
            {
                var address = _server.Address;

                if (address.Equals(IPAddress.Any))
                {
                    if ((address = NetworkHelper.GetActiveLocalAddress()) == null)
                    {
                        this.ShowError("Unable to connect because your local ip address could not be determined.", "Missing Local Address");
                        return;
                    }
                }

                Process.Start($"steam://connect/{address}:{_server.Port}");
            }
            else if (sender == btnHideShowConsole)
            {
                if (btnHideShowConsole.Text == HIDE_CONSOLE_TEXT)
                {
                    _serverRunner.HideConsole();
                    btnHideShowConsole.Text = SHOW_CONSOLE_TEXT;
                }
                else
                {
                    _serverRunner.ShowConsole();
                    btnHideShowConsole.Text = HIDE_CONSOLE_TEXT;
                }
            }
        }