private void SaveButton_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(NameBox.Text)) { MessageBox.Show("You must enter a server name."); return; } if (string.IsNullOrEmpty(IPBox.Text) || !IPAddress.TryParse(IPBox.Text, out IPAddress ipAddress)) { MessageBox.Show("You must enter a (valid) IP address."); return; } if (string.IsNullOrEmpty(PasswordBox.Text)) { MessageBox.Show("You must enter a password."); return; } ServerItem serverItem = new ServerItem(NameBox.Text, ipAddress.ToString(), (int)ServerPort.Value, (int)RCONPort.Value, PasswordBox.Text, ConnectOnStartupCheck.Checked); var search = DataFileSystem.Data.AllServers.Where(x => x.Name == serverItem.Name); if (search.Any()) { DataFileSystem.Data.AllServers.Remove(search.First()); } DataFileSystem.Data.AllServers.Add(serverItem); DataFileSystem.SaveData(); RefreshServerList(); }
private void DeleteButton_Click(object sender, EventArgs e) { string currentItem = ServerList.Text; if (string.IsNullOrEmpty(currentItem)) { MessageBox.Show("There is no server to delete."); return; } ServerItem item = DataFileSystem.Data.AllServers.FirstOrDefault(x => x.Name == currentItem); if (item == null) { RefreshServerList(); return; } DataFileSystem.Data.AllServers.Remove(item); DataFileSystem.SaveData(); RefreshServerList(); }
private static void ProcessExit(object sender, EventArgs e) { DataFileSystem.SaveData(); ServerManager.ConnectedServers.ForEach(x => x.Disconnect()); }