private void buttonAddServer_Click(object sender, EventArgs e) { WolfServer server; if (ServerToEdit != null) { server = ServerToEdit; } else { server = NewServer = new WolfServer(); } server.Name = tbServerName.Text; server.Ip = mtbServerIp.Text; server.WolfPort = (ushort)nudWolfPort.Value; server.SshPort = (ushort)nudSshPort.Value; server.SshUsername = tbSshUsername.Text; server.SshPassword = tbSshPassword.Text; server.GameDirectory = tbGameDirectory.Text; server.ConfigName = tbConfigName.Text; server.MaxClientSlots = (int)nudMaxClients.Value; server.ExecutableName = tbExecutableName.Text; server.PrivatePassword = tbPrivatePassword.Text; server.PrivateClients = (int)nudPrivateSlots.Value; server.RconPassword = tbRconPassword.Text; server.PureServer = (int)nudPureServer.Value; DialogResult = DialogResult.OK; Close(); }
private void dgvServerList_Click(object sender, EventArgs e) { var mouseEventArgs = e as MouseEventArgs; if (mouseEventArgs == null) { return; } if (mouseEventArgs.Button == MouseButtons.XButton1) { if (SelectedServer != null) { tsbBack_Click(tsbBack, e); } } else if (mouseEventArgs.Button == MouseButtons.XButton2) { if (SelectedServer == null) { if (PreviousServer != null) { var ServerIndex = ServerList.IndexOf(PreviousServer); if (ServerIndex == -1) { PreviousServer = null; return; } dgvServerList_CellDoubleClick(dgvServerList, new DataGridViewCellEventArgs(0, ServerIndex)); } } } }
private void DisableColumnButtons(WolfServer server) { if (SelectedServer != null) { return; } Invoke(new Action(() => { var serverIndex = ServerList.IndexOf(server); var startButtonCell = GetStartButton(serverIndex); if (startButtonCell != null) { startButtonCell.Enabled = false; } var editButtonCell = GetEditButton(serverIndex); if (editButtonCell != null) { editButtonCell.Enabled = false; } if (server.ConnectionEstablished) { startButtonCell.Value = ButtonStopServerName; } else { startButtonCell.Value = ButtonStartServerName; } dgvServerList.InvalidateRow(serverIndex); })); }
private void tsbBack_Click(object sender, EventArgs e) { PreviousServer = SelectedServer; lblServerName.Visible = false; tsbBack.Visible = false; tsbRefreshPlayers.Visible = false; tsbRefreshServers.Visible = true; tsbAddServer.Visible = true; SelectedServer = null; tbRcon.Visible = false; btnRcon.Visible = false; DataGridViewAddButtonColumns(); BindDataSources(ServerList); DataGridViewForceColumnDisplayIndexes(); DataGridViewSetStartButtonNames(); // restore disabled rows.. (refreshing/ssh command executing..) foreach (var Server in ServerList) { if (Server.InUse()) { DisableColumnButtons(Server); } } }
private void UpdateServer_Complete(WolfServer server) { Log.Debug($"UpdateServer_Complete: {server}"); if (server.WolfClient != null && !server.WolfClient.SocketClosed) { server.WolfClient.DestroyClient(); } EnableColumnButtons(server); }
private void SaveServerListToFile(string filePath) { try { WolfServer.ToJson(ServerList, filePath); } catch (Exception ex) { Log.Info($"Failed to store current server list to {filePath}. Exception: {ex}"); } }
public WolfClient(WolfServer remoteServer, TimeSpan?timeout = null) { Server = remoteServer; InitializeClient(); AsyncTimer = new Timer() { Interval = timeout == null ? DefaultTimeoutMilliseconds : ((TimeSpan)timeout).TotalMilliseconds, AutoReset = false }; AsyncTimer.Elapsed += (sender, e) => { DestroyClient(); }; }
private async Task RefreshServer(WolfServer server) { Log.Debug("RefreshServer_Begin"); DisableColumnButtons(server); try { server.WolfClient = new WolfClient(server); await server.WolfClient.UpdatedServerAsync(UpdateServer_Complete); } catch (Exception ex) { UpdateServer_Complete(server); Log.Debug("RefreshServer:\n" + ex.Message); } Log.Debug("RefreshServer_End"); }
public AddServerForm(WolfServer server) : this() { ServerToEdit = server; tbServerName.Text = ServerToEdit.Name; mtbServerIp.Text = ServerToEdit.Ip; nudWolfPort.Value = ServerToEdit.WolfPort; nudSshPort.Value = ServerToEdit.SshPort; tbSshUsername.Text = ServerToEdit.SshUsername; tbSshPassword.Text = ServerToEdit.SshPassword; tbGameDirectory.Text = ServerToEdit.GameDirectory; tbConfigName.Text = ServerToEdit.ConfigName; nudMaxClients.Value = ServerToEdit.MaxClientSlots; tbExecutableName.Text = ServerToEdit.ExecutableName; tbPrivatePassword.Text = ServerToEdit.PrivatePassword; nudPrivateSlots.Value = ServerToEdit.PrivateClients; tbRconPassword.Text = ServerToEdit.RconPassword; nudPureServer.Value = ServerToEdit.PureServer; Text = buttonAddServer.Text = "Edit Server"; }
private void dgvServerList_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex == -1) { return; } if (SelectedServer != null) { return; } var startButton = GetStartButton(e.RowIndex); if (!startButton.Enabled) { return; } var server = ServerList[e.RowIndex]; if (server.MapName != WolfServer.Unknown) { BindDataSources(server.Players); DataGridViewRemoveButtonColumns(); tsbBack.Visible = true; tsbRefreshPlayers.Visible = true; tsbRefreshServers.Visible = false; tsbAddServer.Visible = false; SelectedServer = server; lblServerName.Visible = true; tbRcon.Visible = true; btnRcon.Visible = true; UpdateServerStatusLabel(); } }
private void LoadServerListFromFile(string filePath) { try { using (var sr = new StreamReader(filePath)) { var serversInFile = WolfServer.FromJson(sr.ReadToEnd()); if (serversInFile != null) { foreach (var server in serversInFile) { if (!ServerList.Contains(server)) { ServerList.Add(server); } } } } } catch (Exception ex) { Log.Info($"Failed to load current server list from {filePath}. Exception: {ex}"); } }
private void ShowServerFailureMessageBox(WolfServer server, string text) { MessageBox.Show(this, server.ServerDisplayName + ": " + text, "Error", MessageBoxButtons.OK); server.SshException = null; }