private void FormChooseServer_FormClosing(object sender, FormClosingEventArgs e) { Helper.Instance.loadedServer = formChooseServer.Server; if (Helper.Instance.loadedServer != null) { server = ServerQuery.GetServerInstance(EngineType.Source, Helper.Instance.loadedServer.getQueryIPEndPoint()); Helper.Instance.rcon = ServerQuery.GetServerInstance(EngineType.Source, Helper.Instance.loadedServer.getRCONIPEndPoint()).GetControl(Helper.Instance.loadedServer.RCONpw); panelMain.Visible = true; toolStripBtnConnect.Visible = false; toolStripBtnDisconnect.Visible = true; toolStripBtnServerSettings.Visible = true; toolStripSeparator1.Visible = true; //Elemente im Toolstrip, Reiter Aufgaben einblenden toolStripSchedules.Visible = true; toolStripBtnDeleteTask.Visible = true; loadTasks(); toolStripStatusLabelStatus.Text = "Connected"; } Enabled = true; }
public async Task SendInfo() { if (PermissionManager.GetPerms(Context.Message.Author.Id) < PermissionConfig.User) { await Context.Channel.SendMessageAsync("Not authorised to run this command."); return; } try { QueryMaster.Server server1 = ServerQuery.GetServerInstance(EngineType.Source, "54.36.229.194", 27015); QueryMaster.ServerInfo s1Info = server1.GetInfo(); QueryMaster.Server server3 = ServerQuery.GetServerInstance(EngineType.Source, "51.81.120.22", 27015); QueryMaster.ServerInfo s3Info = server3.GetInfo(); EmbedBuilder eb = new EmbedBuilder(); EmbedFooterBuilder fb = new EmbedFooterBuilder(); fb.WithText($"Called by {Context.Message.Author.Username}"); fb.WithIconUrl(Context.Message.Author.GetAvatarUrl()); eb.WithTitle($"Server Info"); eb.AddField("Server 1", $"[{s1Info.Players}/{s1Info.MaxPlayers}](http://s1.nickgor.com)", true); eb.AddField("Server 3", $"[{s3Info.Players}/{s3Info.MaxPlayers}](http://s3.nickgor.com)", true); eb.WithColor(Color.Blue); eb.WithFooter(fb); await ReplyAsync("", false, eb.Build()); await Utilities.StatusMessage("online", Context); } catch (Exception) { await ReplyAsync("A connection could not be made to one or more ZARP servers. Please try again later."); await Utilities.StatusMessage("online", Context); return; } }
private bool UpdateServerInfo(UpdateRequest request, ServerRow row, Server server) { bool ok = ExecuteUpdate(request, row, server, retryCallback => { row.ServerInfo = server.GetInfo(retryCallback); }); if (!ok) row.ServerInfo = null; return ok; }
private void UpdateRules(UpdateRequest request, ServerRow row, Server server) { if (!request.QueryServerRules) return; bool ok = ExecuteUpdate(request, row, server, retryCallback => { row.Rules = new List<Rule>(server.GetRules(retryCallback)); }); if (!ok) row.Rules = null; }
private void UpdatePlayers(UpdateRequest request, ServerRow row, Server server) { bool ok = ExecuteUpdate(request, row, server, retryCallback => { var players = server.GetPlayers(retryCallback); row.Players = players == null ? null : new List<Player>(players); }); if (!ok) row.Players = null; }
/// <summary> /// Template method for common code needed in UpdateServerInfo, UpdatePlayers and UpdateRules /// </summary> private bool ExecuteUpdate(UpdateRequest request, ServerRow row, Server server, Action<Action<int>> updater) { if (request.IsCancelled) return false; try { row.Status = "updating " + row.Retries; request.DataModified = 1; updater(retry => { if (request.IsCancelled) throw new OperationCanceledException(); if (row.Retries == 0) Interlocked.Increment(ref request.TasksWithRetries); row.Status = "updating " + (++row.Retries + 1); request.DataModified = 1; }); return true; } catch (TimeoutException) { return false; } catch { return true; } }
private static void RunUpdate(bool noDelay) { var endpoint = new IPEndPoint(IPAddress.Parse(ServerIP), RCONPort); server = ServerQuery.GetServerInstance(QueryMaster.EngineType.Source, endpoint); // // Find the process // var runningProcesses = Process.GetProcessesByName("ShooterGameServer.exe"); var expectedExePath = ServerUpdater.NormalizePath(Path.Combine(InstallDirectory, "ShooterGame", "Binaries", "Win64", "ShooterGameServer.exe")); Process process = null; foreach (var runningProcess in runningProcesses) { var runningPath = ServerUpdater.NormalizePath(runningProcess.Modules[0].FileName); if (String.Equals(expectedExePath, runningPath)) { process = runningProcess; break; } } if (process == null) { Console.WriteLine("ERROR: Unable to find process for " + InstallDirectory); Environment.Exit(-1); } var serverCommandLine = ServerUpdater.GetCommandLineForProcess(process.Id); if (String.IsNullOrEmpty(serverCommandLine)) { Console.WriteLine("ERROR: Unable to retrieve command-line for process " + process.Id); Environment.Exit(-1); } // // Stop the server // Console.WriteLine("Stopping the server..."); process.EnableRaisingEvents = true; if (process.ProcessName == "ShooterGameServer.exe") { TaskCompletionSource <bool> ts = new TaskCompletionSource <bool>(); EventHandler handler = (s, e) => ts.TrySetResult(true); process.Exited += handler; process.CloseMainWindow(); if (!process.HasExited) { ts.Task.Wait(); } } if (!UpdateCache()) { Environment.Exit(-1); } Console.WriteLine("Re-launching the server"); process = Process.Start(serverCommandLine); if (process == null) { Console.WriteLine("Failed to restart server."); Environment.Exit(-1); } // // Re-schedule updater // Console.WriteLine("TODO: Reschedule update"); Environment.Exit(0); }
private bool UpdateServerInfo(UpdateRequest request, ServerRow row, Server server) { bool ok = ExecuteUpdate(request, row, server, retryCallback => { row.ServerInfo = server.GetInfo(retryCallback); if (row.ServerInfo == null) return false; var gameId = row.ServerInfo.Extra?.GameId ?? 0; if (gameId == 0) gameId = row.ServerInfo.Id; if (gameId == 0) gameId = (int)request.AppId; var extension = this.gameExtensions.Get((Game)gameId); row.GameExtension = extension; row.QueryPlayers = extension.SupportsPlayersQuery(row); row.QueryRules = extension.SupportsRulesQuery(row); return true; }); if (!ok) row.ServerInfo = null; return ok; }
private void UpdateRules(UpdateRequest request, ServerRow row, Server server) { if (!row.QueryRules) return; bool ok = ExecuteUpdate(request, row, server, retryCallback => { var rules = server.GetRules(retryCallback); if (rules == null) return false; row.Rules = new List<Rule>(rules); return true; }); if (!ok) { row.Rules = null; row.QueryRules = false; } }
private void UpdatePlayers(UpdateRequest request, ServerRow row, Server server) { if (!row.QueryPlayers) return; bool ok = ExecuteUpdate(request, row, server, retryCallback => { var players = server.GetPlayers(retryCallback); if (players == null) return false; row.Players =new List<Player>(players); return true; }); if (!ok) { row.Players = null; row.QueryPlayers = false; } }
/// <summary> /// Template method for common code needed in UpdateServerInfo, UpdatePlayers and UpdateRules /// </summary> private bool ExecuteUpdate(UpdateRequest request, ServerRow row, Server server, Func<Action<int>, bool> updater) { if (request.IsCancelled) return false; try { row.Status = "updating " + row.Retries; request.SetDataModified(); bool ok = updater(retry => { if (request.IsCancelled) throw new OperationCanceledException(); if (row.Retries == 0) Interlocked.Increment(ref request.TasksWithRetries); row.Status = "updating " + (++row.Retries + 1); request.SetDataModified(); }); if (ok) return true; Interlocked.Increment(ref request.TasksWithTimeout); } catch { } return false; }