Changes server console title

- Separate function
- Changing the window title when the server is not running
This commit is contained in:
BrentVL-1952840 2023-02-18 10:22:19 +01:00
parent ab4f918909
commit c2dca8c081

View File

@ -11,18 +11,20 @@
namespace dedicated_info namespace dedicated_info
{ {
class component final : public server_component namespace
{ {
public: void set_server_info_in_console_title()
void post_unpack() override
{
scheduler::loop([]()
{ {
const auto sv_running = game::Dvar_FindVar("sv_running"); const auto sv_running = game::Dvar_FindVar("sv_running");
if (sv_running && sv_running->current.enabled)
{
const auto server_name = game::get_dvar_string("live_steam_server_name"); const auto server_name = game::get_dvar_string("live_steam_server_name");
if (!sv_running || !sv_running->current.enabled)
{
std::string idle_text = server_name + " - not running";
console::set_title(idle_text);
return;
}
const auto mapname = game::get_dvar_string("mapname"); const auto mapname = game::get_dvar_string("mapname");
std::string window_text = utils::string::va("%s on %s [%d/%d] (%d)", std::string window_text = utils::string::va("%s on %s [%d/%d] (%d)",
@ -34,6 +36,15 @@ namespace dedicated_info
console::set_title(window_text); console::set_title(window_text);
} }
}
class component final : public server_component
{
public:
void post_unpack() override
{
scheduler::loop([]()
{
set_server_info_in_console_title();
}, scheduler::pipeline::main, 1s); }, scheduler::pipeline::main, 1s);
} }
}; };