From f9f2a825470f4fcfeca2ff5a92b52b64cbf3693b Mon Sep 17 00:00:00 2001 From: Skull Merlin <86374920+skkuull@users.noreply.github.com> Date: Tue, 1 Mar 2022 20:00:35 +0200 Subject: [PATCH] dedicated information --- src/client/component/dedicated_info.cpp | 65 +++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/client/component/dedicated_info.cpp diff --git a/src/client/component/dedicated_info.cpp b/src/client/component/dedicated_info.cpp new file mode 100644 index 00000000..382e8c36 --- /dev/null +++ b/src/client/component/dedicated_info.cpp @@ -0,0 +1,65 @@ +#include +#include "console.hpp" +#include "loader/component_loader.hpp" +#include "game/game.hpp" +#include "scheduler.hpp" +#include + +namespace dedicated_info +{ + class component final : public component_interface + { + public: + void post_unpack() override + { + if (!game::environment::is_dedi()) + { + return; + } + + scheduler::loop([]() + { + auto* sv_running = game::Dvar_FindVar("sv_running"); + if (!sv_running || !sv_running->current.enabled) + { + console::set_title("H1-Mod Dedicated Server"); + return; + } + + auto* const sv_hostname = game::Dvar_FindVar("sv_hostname"); + auto* const sv_maxclients = game::Dvar_FindVar("sv_maxclients"); + auto* const mapname = game::Dvar_FindVar("mapname"); + + auto bot_count = 0; + auto client_count = 0; + + for (auto i = 0; i < sv_maxclients->current.integer; i++) + { + auto* client = &game::mp::svs_clients[i]; + auto* self = &game::mp::g_entities[i]; + + if (client->header.state >= 1 && self && self->client) + { + client_count++; + if (game::SV_BotIsBot(i)) + { + ++bot_count; + } + } + } + + std::string cleaned_hostname; + cleaned_hostname.resize(static_cast(strlen(sv_hostname->current.string) + 1)); + + utils::string::strip(sv_hostname->current.string, cleaned_hostname.data(), + static_cast(strlen(sv_hostname->current.string)) + 1); + + console::set_title(utils::string::va("%s on %s [%d/%d] (%d)", cleaned_hostname.data(), + mapname->current.string, client_count, + sv_maxclients->current.integer, bot_count)); + }, scheduler::pipeline::main, 1s); + } + }; +} + +REGISTER_COMPONENT(dedicated_info::component) \ No newline at end of file