h1-mod/src/client/component/dedicated_info.cpp

67 lines
1.7 KiB
C++
Raw Normal View History

2022-03-01 13:00:35 -05:00
#include <std_include.hpp>
#include "loader/component_loader.hpp"
#include "game/game.hpp"
#include "scheduler.hpp"
#include <utils\string.hpp>
namespace dedicated_info
{
class component final : public component_interface
{
public:
void post_unpack() override
{
if (!game::environment::is_dedi())
{
return;
}
scheduler::loop([]()
2022-03-01 13:03:13 -05:00
{
auto* sv_running = game::Dvar_FindVar("sv_running");
2022-05-21 06:26:30 -04:00
if (!sv_running || !sv_running->current.enabled || (*game::mp::svs_clients) == nullptr)
2022-03-01 13:00:35 -05:00
{
SetConsoleTitle("H1-Mod Dedicated Server");
2022-03-01 13:03:13 -05:00
return;
}
2022-03-01 13:00:35 -05:00
2022-03-01 13:03:13 -05:00
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");
2022-03-01 13:00:35 -05:00
2022-03-01 13:03:13 -05:00
auto bot_count = 0;
auto client_count = 0;
2022-03-01 13:00:35 -05:00
2022-05-21 06:26:30 -04:00
const auto svs_clients = *game::mp::svs_clients;
for (auto i = 0; i < *game::mp::svs_numclients; i++)
2022-03-01 13:03:13 -05:00
{
2022-05-21 06:26:30 -04:00
const auto client = svs_clients[i];
2022-03-01 13:03:13 -05:00
auto* self = &game::mp::g_entities[i];
2022-03-01 13:00:35 -05:00
2022-05-21 06:26:30 -04:00
if (client.header.state >= 1 && self && self->client)
2022-03-01 13:03:13 -05:00
{
client_count++;
if (game::SV_BotIsBot(i))
2022-03-01 13:00:35 -05:00
{
2022-03-01 13:03:13 -05:00
++bot_count;
2022-03-01 13:00:35 -05:00
}
}
2022-03-01 13:03:13 -05:00
}
2022-03-01 13:00:35 -05:00
2022-03-01 13:03:13 -05:00
std::string cleaned_hostname;
cleaned_hostname.resize(static_cast<int>(strlen(sv_hostname->current.string) + 1));
2022-03-01 13:00:35 -05:00
2022-03-01 13:03:13 -05:00
utils::string::strip(sv_hostname->current.string, cleaned_hostname.data(),
static_cast<int>(strlen(sv_hostname->current.string)) + 1);
2022-03-01 13:00:35 -05:00
SetConsoleTitle(utils::string::va("%s on %s [%d/%d] (%d)", cleaned_hostname.data(),
2022-05-21 06:26:30 -04:00
mapname->current.string, client_count,
sv_maxclients->current.integer, bot_count)
);
2022-03-01 13:03:13 -05:00
}, scheduler::pipeline::main, 1s);
2022-03-01 13:00:35 -05:00
}
};
}
REGISTER_COMPONENT(dedicated_info::component)