From 660062b934ac98077f08fde9a18f795be0b58b0f Mon Sep 17 00:00:00 2001 From: GeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com> Date: Sat, 25 Jun 2022 21:58:54 +0200 Subject: Log all clientcommands if `ns_should_log_all_clientcommands` is set (#209) * Log all clientcommands if responding convar is set * Also log UID * Formatting * Use `GetBool()` instead of `GetInt()` * Adjust output print format as suggested in review --- NorthstarDedicatedTest/serverauthentication.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/NorthstarDedicatedTest/serverauthentication.cpp b/NorthstarDedicatedTest/serverauthentication.cpp index 2ef26479..ac1985cf 100644 --- a/NorthstarDedicatedTest/serverauthentication.cpp +++ b/NorthstarDedicatedTest/serverauthentication.cpp @@ -18,6 +18,9 @@ const char* AUTHSERVER_VERIFY_STRING = "I am a northstar server!"; +// This convar defines whether to log all client commands +ConVar* Cvar_ns_should_log_all_clientcommands; + // hook types typedef void* (*CBaseServer__ConnectClientType)( @@ -480,6 +483,12 @@ CCommand__TokenizeType CCommand__Tokenize; char CGameClient__ExecuteStringCommandHook(void* self, uint32_t unknown, const char* pCommandString) { + // Only log clientcommands if the convar `ns_should_log_all_clientcommands` equals 1 + if (Cvar_ns_should_log_all_clientcommands->GetBool()) + { + spdlog::info("{} (UID: {}) executed command: \"{}\"", (char*)self + 0x16, (char*)self + 0xF500, pCommandString); + } + if (CVar_sv_quota_stringcmdspersecond->GetInt() != -1) { // note: this isn't super perfect, legit clients can trigger it in lobby, mostly good enough tho imo @@ -672,6 +681,8 @@ void InitialiseServerAuthentication(HMODULE baseAddress) "100", FCVAR_GAMEDLL, "Netchannel processing is limited to so many milliseconds, abort connection if exceeding budget"); + Cvar_ns_should_log_all_clientcommands = + new ConVar("ns_should_log_all_clientcommands", "0", FCVAR_NONE, "Whether to log all clientcommands"); Cvar_ns_player_auth_port = new ConVar("ns_player_auth_port", "8081", FCVAR_GAMEDLL, ""); Cvar_sv_querylimit_per_sec = new ConVar("sv_querylimit_per_sec", "15", FCVAR_GAMEDLL, ""); Cvar_sv_max_chat_messages_per_sec = new ConVar("sv_max_chat_messages_per_sec", "5", FCVAR_GAMEDLL, ""); -- cgit v1.2.3