From 56baaaf0f5506e4508192cf0ffcbf750979fc6d6 Mon Sep 17 00:00:00 2001 From: Edo Date: Tue, 15 Nov 2022 16:18:00 -0600 Subject: [PATCH] [Chat] Add missing server is not running warning (#567) * [Dedicated] Is running function * [Dedicated]: Better func --- src/Components/Modules/Bans.cpp | 4 ++-- src/Components/Modules/Chat.cpp | 32 +++++++++++++++++++++++---- src/Components/Modules/Dedicated.cpp | 8 ++++++- src/Components/Modules/Dedicated.hpp | 1 + src/Components/Modules/Download.cpp | 2 +- src/Components/Modules/Party.cpp | 4 ++-- src/Components/Modules/ServerInfo.cpp | 4 ++-- 7 files changed, 43 insertions(+), 12 deletions(-) diff --git a/src/Components/Modules/Bans.cpp b/src/Components/Modules/Bans.cpp index 8973036e..e6674800 100644 --- a/src/Components/Modules/Bans.cpp +++ b/src/Components/Modules/Bans.cpp @@ -227,7 +227,7 @@ namespace Components { Command::Add("banClient", [](Command::Params* params) { - if (!(*Game::com_sv_running)->current.enabled) + if (!Dedicated::IsRunning()) { Logger::Print("Server is not running.\n"); return; @@ -271,7 +271,7 @@ namespace Components Command::Add("unbanClient", [](Command::Params* params) { - if (!(*Game::com_sv_running)->current.enabled) + if (!Dedicated::IsRunning()) { Logger::Print("Server is not running.\n"); return; diff --git a/src/Components/Modules/Chat.cpp b/src/Components/Modules/Chat.cpp index ebfc6c38..924cb498 100644 --- a/src/Components/Modules/Chat.cpp +++ b/src/Components/Modules/Chat.cpp @@ -296,9 +296,9 @@ namespace Components { Command::AddSV("muteClient", [](Command::Params* params) { - if (!(*Game::com_sv_running)->current.enabled) + if (!Dedicated::IsRunning()) { - Logger::Print("Server is not running.\n"); + Logger::Print(Game::CON_CHANNEL_SERVER, "Server is not running.\n"); return; } @@ -319,9 +319,9 @@ namespace Components Command::AddSV("unmute", [](Command::Params* params) { - if (!(*Game::com_sv_running)->current.enabled) + if (!Dedicated::IsRunning()) { - Logger::Print("Server is not running.\n"); + Logger::Print(Game::CON_CHANNEL_SERVER, "Server is not running.\n"); return; } @@ -356,6 +356,12 @@ namespace Components Command::AddSV("say", [](Command::Params* params) { + if (!Dedicated::IsRunning()) + { + Logger::Print(Game::CON_CHANNEL_SERVER, "Server is not running.\n"); + return; + } + if (params->size() < 2) return; auto message = params->join(1); @@ -375,6 +381,12 @@ namespace Components Command::AddSV("tell", [](Command::Params* params) { + if (!Dedicated::IsRunning()) + { + Logger::Print(Game::CON_CHANNEL_SERVER, "Server is not running.\n"); + return; + } + if (params->size() < 3) return; const auto client = std::atoi(params->get(1)); @@ -395,6 +407,12 @@ namespace Components Command::AddSV("sayraw", [](Command::Params* params) { + if (!Dedicated::IsRunning()) + { + Logger::Print(Game::CON_CHANNEL_SERVER, "Server is not running.\n"); + return; + } + if (params->size() < 2) return; auto message = params->join(1); @@ -404,6 +422,12 @@ namespace Components Command::AddSV("tellraw", [](Command::Params* params) { + if (!Dedicated::IsRunning()) + { + Logger::Print(Game::CON_CHANNEL_SERVER, "Server is not running.\n"); + return; + } + if (params->size() < 3) return; const auto client = atoi(params->get(1)); diff --git a/src/Components/Modules/Dedicated.cpp b/src/Components/Modules/Dedicated.cpp index 929375b7..547ac20b 100644 --- a/src/Components/Modules/Dedicated.cpp +++ b/src/Components/Modules/Dedicated.cpp @@ -19,6 +19,12 @@ namespace Components return flag.value(); } + bool Dedicated::IsRunning() + { + assert(*Game::com_sv_running); + return *Game::com_sv_running && (*Game::com_sv_running)->current.enabled; + } + void Dedicated::InitDedicatedServer() { static const char* fastfiles[7] = @@ -261,7 +267,7 @@ namespace Components Scheduler::Loop([] { - if ((*Game::com_sv_running)->current.enabled) + if (Dedicated::IsRunning()) { Dedicated::TransmitGuids(); } diff --git a/src/Components/Modules/Dedicated.hpp b/src/Components/Modules/Dedicated.hpp index d76d0f0a..236ce7f2 100644 --- a/src/Components/Modules/Dedicated.hpp +++ b/src/Components/Modules/Dedicated.hpp @@ -12,6 +12,7 @@ namespace Components static Dvar::Var COMLogFilter; static bool IsEnabled(); + static bool IsRunning(); static void Heartbeat(); diff --git a/src/Components/Modules/Download.cpp b/src/Components/Modules/Download.cpp index d6cce21e..9283045e 100644 --- a/src/Components/Modules/Download.cpp +++ b/src/Components/Modules/Download.cpp @@ -423,7 +423,7 @@ namespace Components playerInfo["ping"] = 0; playerInfo["name"] = ""; - if ((*Game::com_sv_running)->current.enabled) + if (Dedicated::IsRunning()) { if (Game::svs_clients[i].header.state < Game::CS_CONNECTED) continue; diff --git a/src/Components/Modules/Party.cpp b/src/Components/Modules/Party.cpp index 153129cb..fbf30e6c 100644 --- a/src/Components/Modules/Party.cpp +++ b/src/Components/Modules/Party.cpp @@ -138,7 +138,7 @@ namespace Components bool Party::IsInLobby() { - return (!(*Game::com_sv_running)->current.enabled && PartyEnable.get() && Dvar::Var("party_host").get()); + return (!Dedicated::IsRunning() && PartyEnable.get() && Dvar::Var("party_host").get()); } bool Party::IsInUserMapLobby() @@ -351,7 +351,7 @@ namespace Components info.set("isPrivate", (Dvar::Var("g_password").get().size() ? "1" : "0")); info.set("hc", (Dvar::Var("g_hardcore").get() ? "1" : "0")); info.set("securityLevel", Utils::String::VA("%i", Dvar::Var("sv_securityLevel").get())); - info.set("sv_running", ((*Game::com_sv_running)->current.enabled ? "1" : "0")); + info.set("sv_running", (Dedicated::IsRunning() ? "1" : "0")); info.set("aimAssist", (Gamepad::sv_allowAimAssist.get() ? "1" : "0")); info.set("voiceChat", (Voice::SV_VoiceEnabled() ? "1" : "0")); diff --git a/src/Components/Modules/ServerInfo.cpp b/src/Components/Modules/ServerInfo.cpp index f3b43abf..ff90f9b4 100644 --- a/src/Components/Modules/ServerInfo.cpp +++ b/src/Components/Modules/ServerInfo.cpp @@ -162,7 +162,7 @@ namespace Components { info.set("matchtype", "1"); } - else if ((*Game::com_sv_running)->current.enabled) // Match hosting + else if (Dedicated::IsRunning()) // Match hosting { info.set("matchtype", "2"); } @@ -206,7 +206,7 @@ namespace Components auto ping = 0; std::string name; - if ((*Game::com_sv_running)->current.enabled) + if (Dedicated::IsRunning()) { if (Game::svs_clients[i].header.state < Game::CS_CONNECTED) continue;