private void StartStopServerButton_Click(object sender, EventArgs e) { if (MainServer == null) { //Load Server Settings if (!File.Exists("SwitchboardServer.cfg")) { //Show a brief little welcome message! MessageBox.Show("Server is not configured! Run Server Settings at least once before starting server!", "Welcome!", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } else { try { String[] Settings = File.ReadAllLines("SwitchboardServer.cfg")[0].Split(':'); IP = Settings[0]; Port = int.Parse(Settings[1]); AllowAnon = bool.Parse(Settings[2]); AllowMulti = bool.Parse(Settings[3]); } catch (Exception d) { MessageBox.Show("There was a problem interpretting your config file. Default values were loaded instead. \n\n" + d.Message + "\n" + d.StackTrace, "oopsie", MessageBoxButtons.OK, MessageBoxIcon.Error);; LoadDefault(); } } //Load Welcome Message if (File.Exists("Welcome.txt")) { Welcome = File.ReadAllText("Welcome.txt"); } else { Welcome = SwitchboardConfiguration.DefaultWelcome; } //Server is not started StatusLabel.Text = "Status: Online"; StartStopServerButton.Text = "Stop"; ConnectionsListView.Enabled = Enabled; ServerBWorker.RunWorkerAsync(); } else { ServerBWorker.CancelAsync(); } //server is started, cancel it. }
private void DisconnectButton_Click(object sender, EventArgs e) { //Make sure there is at least one connection selected. //Well, there will only ever be one because we disabled multi-select but shh its ok. if (ConnectionsListView.SelectedIndices.Count == 0) { MessageBox.Show("Please select a connection to see its details", "n o", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //Get the connection index int ConnectionIndex = ConnectionsListView.SelectedIndices[0]; //Ask the user DialogResult Result = MessageBox.Show("Are you sure you want to disconnect this user?", "Are you sure", MessageBoxButtons.YesNo, MessageBoxIcon.Question); //if yes close the connection if (Result == DialogResult.Yes) { MainServer.GetConnections()[ConnectionIndex].Close(); ServerBWorker.ReportProgress(0); } }