Automatically trigger map rotation

This maybe fixes #129
This commit is contained in:
momo5502 2023-02-12 10:51:15 +01:00
parent 54b15224dd
commit 21b0e419bd
5 changed files with 60 additions and 29 deletions

View File

@ -3,6 +3,7 @@
#include "loader/component_loader.hpp"
#include "game/game.hpp"
#include "game/utils.hpp"
#include "command.hpp"
#include "network.hpp"
#include "scheduler.hpp"
@ -35,6 +36,17 @@ namespace dedicated
}
}
void trigger_map_rotation()
{
scheduler::once([]
{
if (!game::get_dvar_string("sv_maprotation").empty())
{
game::Cbuf_AddText(0, "map_rotate\n");
}
}, scheduler::pipeline::main, 1s);
}
struct component final : server_component
{
void post_unpack() override
@ -48,6 +60,9 @@ namespace dedicated
scheduler::loop(send_heartbeat, scheduler::pipeline::server, 10min);
command::add("heartbeat", send_heartbeat);
// Hook GScr_ExitLevel
utils::hook::jump(0x1402D1AA0_g, trigger_map_rotation);
}
};
}

View File

@ -12,35 +12,15 @@
#include <version.hpp>
#include "game/utils.hpp"
namespace getinfo
{
namespace
{
std::string get_dvar_string(const char* dvar_name)
{
const auto dvar = game::Dvar_FindVar(dvar_name);
if (!dvar)
{
return {};
}
return game::Dvar_GetString(dvar);
}
int get_dvar_int(const char* dvar_name)
{
const auto dvar = game::Dvar_FindVar(dvar_name);
if (!dvar)
{
return {};
}
return game::Dvar_GetInt(dvar);
}
int get_max_client_count()
{
return get_dvar_int("com_maxclients");
return game::get_dvar_int("com_maxclients");
}
int get_client_count()
@ -83,13 +63,13 @@ namespace getinfo
utils::info_string info{};
info.set("challenge", std::string(data.begin(), data.end()));
info.set("gamename", "T7");
info.set("hostname", get_dvar_string(game::is_server() ? "live_steam_server_name" : "sv_hostname"));
info.set("gametype", get_dvar_string("g_gametype"));
info.set("hostname", game::get_dvar_string(game::is_server() ? "live_steam_server_name" : "sv_hostname"));
info.set("gametype", game::get_dvar_string("g_gametype"));
//info.set("sv_motd", get_dvar_string("sv_motd"));
info.set("description", game::is_server() ? get_dvar_string("live_steam_server_description") : "");
info.set("description", game::is_server() ? game::get_dvar_string("live_steam_server_description") : "");
info.set("xuid", utils::string::va("%llX", steam::SteamUser()->GetSteamID().bits));
info.set("mapname", get_dvar_string("mapname"));
info.set("isPrivate", get_dvar_string("g_password").empty() ? "0" : "1");
info.set("mapname", game::get_dvar_string("mapname"));
info.set("isPrivate", game::get_dvar_string("g_password").empty() ? "0" : "1");
info.set("clients", utils::string::va("%i", get_client_count()));
info.set("bots", utils::string::va("%i", /*get_bot_count()*/0));
info.set("sv_maxclients", utils::string::va("%i", get_max_client_count()));

View File

@ -190,7 +190,7 @@ namespace party
//const auto hostname = info.get("sv_hostname");
const auto playmode = info.get("playmode");
const auto mode = game::eModes(std::atoi(playmode.data()));
const auto mode = static_cast<game::eModes>(std::atoi(playmode.data()));
//const auto xuid = strtoull(info.get("xuid").data(), nullptr, 16);
scheduler::once([=]

29
src/client/game/utils.cpp Normal file
View File

@ -0,0 +1,29 @@
#include <std_include.hpp>
#include "game.hpp"
#include "utils.hpp"
namespace game
{
std::string get_dvar_string(const char* dvar_name)
{
const auto dvar = Dvar_FindVar(dvar_name);
if (!dvar)
{
return {};
}
return Dvar_GetString(dvar);
}
int get_dvar_int(const char* dvar_name)
{
const auto dvar = Dvar_FindVar(dvar_name);
if (!dvar)
{
return {};
}
return Dvar_GetInt(dvar);
}
}

View File

@ -0,0 +1,7 @@
#pragma once
namespace game
{
std::string get_dvar_string(const char* dvar_name);
int get_dvar_int(const char* dvar_name);
}