Log RCON on demand with a dvar

This commit is contained in:
Louvenarde 2021-07-15 21:45:46 +02:00
parent 2ad1d4a682
commit 5162c0c381

View File

@ -29,7 +29,8 @@ namespace Components
if (!RCon::Password.empty()) if (!RCon::Password.empty())
{ {
Network::Address target(addr); Network::Address target(addr);
if (!target.isValid()) { if (!target.isValid())
{
target = Party::Target(); target = Party::Target();
} }
@ -75,6 +76,7 @@ namespace Components
Dvar::OnInit([]() Dvar::OnInit([]()
{ {
Dvar::Register<const char*>("rcon_password", "", Game::dvar_flag::DVAR_FLAG_NONE, "The password for rcon"); Dvar::Register<const char*>("rcon_password", "", Game::dvar_flag::DVAR_FLAG_NONE, "The password for rcon");
Dvar::Register<bool>("log_rcon_requests", true, Game::dvar_flag::DVAR_FLAG_NONE, "Print remote commands in the output log");
}); });
Network::Handle("rcon", [](Network::Address address, const std::string& _data) Network::Handle("rcon", [](Network::Address address, const std::string& _data)
@ -111,7 +113,12 @@ namespace Components
static std::string outputBuffer; static std::string outputBuffer;
outputBuffer.clear(); outputBuffer.clear();
Logger::Print("Executing RCon request from %s: %s\n", address.getCString(), command.data()); #ifndef DEBUG
if (Dvar::Var("log_rcon_requests").get<bool>())
#endif
{
Logger::Print("Executing RCon request from %s: %s\n", address.getCString(), command.data());
}
Logger::PipeOutput([](const std::string& output) Logger::PipeOutput([](const std::string& output)
{ {