2022-11-24 17:25:37 +01:00
|
|
|
#include <std_include.hpp>
|
2023-02-08 18:27:30 +01:00
|
|
|
#include "dedicated.hpp"
|
2022-11-24 17:25:37 +01:00
|
|
|
#include "loader/component_loader.hpp"
|
|
|
|
|
2023-01-02 13:57:00 +01:00
|
|
|
#include "game/game.hpp"
|
2023-02-12 10:51:15 +01:00
|
|
|
#include "game/utils.hpp"
|
2023-02-05 19:39:44 +01:00
|
|
|
#include "command.hpp"
|
|
|
|
#include "network.hpp"
|
|
|
|
#include "scheduler.hpp"
|
|
|
|
#include "server_list.hpp"
|
2023-01-02 13:57:00 +01:00
|
|
|
|
2022-11-24 17:25:37 +01:00
|
|
|
#include <utils/hook.hpp>
|
|
|
|
|
|
|
|
namespace dedicated
|
|
|
|
{
|
|
|
|
namespace
|
|
|
|
{
|
2023-02-08 18:27:30 +01:00
|
|
|
void sv_con_tell_f_stub(game::client_s* cl_0, game::svscmd_type type, [[maybe_unused]] const char* fmt,
|
|
|
|
[[maybe_unused]] int c, char* text)
|
2023-01-09 16:53:51 +01:00
|
|
|
{
|
|
|
|
game::SV_SendServerCommand(cl_0, type, "%c \"GAME_SERVER\x15: %s\"", 79, text);
|
|
|
|
}
|
2023-02-12 11:33:33 +01:00
|
|
|
|
|
|
|
void send_heartbeat_packet()
|
|
|
|
{
|
|
|
|
game::netadr_t target{};
|
|
|
|
if (server_list::get_master_server(target))
|
|
|
|
{
|
|
|
|
network::send(target, "heartbeat", "T7");
|
|
|
|
}
|
|
|
|
}
|
2023-02-08 18:27:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void send_heartbeat()
|
|
|
|
{
|
|
|
|
if (!game::is_server())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2023-02-05 19:39:44 +01:00
|
|
|
|
2023-02-12 14:11:24 +01:00
|
|
|
scheduler::once(send_heartbeat_packet, scheduler::pipeline::main, 5s);
|
2022-11-24 17:25:37 +01:00
|
|
|
}
|
|
|
|
|
2023-02-12 10:51:15 +01:00
|
|
|
void trigger_map_rotation()
|
|
|
|
{
|
|
|
|
scheduler::once([]
|
|
|
|
{
|
|
|
|
if (!game::get_dvar_string("sv_maprotation").empty())
|
|
|
|
{
|
|
|
|
game::Cbuf_AddText(0, "map_rotate\n");
|
2023-02-12 14:11:24 +01:00
|
|
|
send_heartbeat();
|
2023-02-12 10:51:15 +01:00
|
|
|
}
|
|
|
|
}, scheduler::pipeline::main, 1s);
|
|
|
|
}
|
|
|
|
|
2023-01-01 21:51:04 +01:00
|
|
|
struct component final : server_component
|
2022-11-24 17:25:37 +01:00
|
|
|
{
|
|
|
|
void post_unpack() override
|
|
|
|
{
|
2023-01-02 13:57:00 +01:00
|
|
|
// Ignore "bad stats"
|
2023-02-05 19:08:47 +01:00
|
|
|
//utils::hook::set<uint8_t>(0x14052D523_g, 0xEB);
|
|
|
|
//utils::hook::nop(0x14052D4E4_g, 2);
|
2023-01-09 16:53:51 +01:00
|
|
|
|
|
|
|
// Fix tell command for IW4M
|
|
|
|
utils::hook::call(0x14052A8CF_g, sv_con_tell_f_stub);
|
2023-02-05 19:39:44 +01:00
|
|
|
|
2023-02-12 14:11:24 +01:00
|
|
|
scheduler::loop(send_heartbeat, scheduler::pipeline::main, 5min);
|
2023-02-05 19:39:44 +01:00
|
|
|
command::add("heartbeat", send_heartbeat);
|
2023-02-12 10:51:15 +01:00
|
|
|
|
|
|
|
// Hook GScr_ExitLevel
|
|
|
|
utils::hook::jump(0x1402D1AA0_g, trigger_map_rotation);
|
2022-11-24 17:25:37 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
REGISTER_COMPONENT(dedicated::component)
|