diff options
author | Jack <66967891+ASpoonPlaysGames@users.noreply.github.com> | 2023-12-27 00:32:01 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-27 01:32:01 +0100 |
commit | f5ab6fb5e8be7b73e6003d4145081d5e0c0ce287 (patch) | |
tree | 90f2c6a4885dbd181799e2325cf33588697674e1 /primedev/dedicated/dedicatedlogtoclient.cpp | |
parent | bb8ed59f6891b1196c5f5bbe7346cd171c8215fa (diff) | |
download | NorthstarLauncher-f5ab6fb5e8be7b73e6003d4145081d5e0c0ce287.tar.gz NorthstarLauncher-f5ab6fb5e8be7b73e6003d4145081d5e0c0ce287.zip |
Folder restructuring from primedev (#624)v1.21.2-rc3v1.21.2
Copies of over the primedev folder structure for easier cherry-picking of further changes
Co-authored-by: F1F7Y <filip.bartos07@proton.me>
Diffstat (limited to 'primedev/dedicated/dedicatedlogtoclient.cpp')
-rw-r--r-- | primedev/dedicated/dedicatedlogtoclient.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/primedev/dedicated/dedicatedlogtoclient.cpp b/primedev/dedicated/dedicatedlogtoclient.cpp new file mode 100644 index 00000000..bf2cf77a --- /dev/null +++ b/primedev/dedicated/dedicatedlogtoclient.cpp @@ -0,0 +1,48 @@ +#include "dedicatedlogtoclient.h" +#include "engine/r2engine.h" + +void (*CGameClient__ClientPrintf)(CBaseClient* pClient, const char* fmt, ...); + +void DedicatedServerLogToClientSink::custom_sink_it_(const custom_log_msg& msg) +{ + if (*g_pServerState == server_state_t::ss_dead) + return; + + enum class eSendPrintsToClient + { + NONE = -1, + FIRST, + ALL + }; + + static const ConVar* Cvar_dedi_sendPrintsToClient = g_pCVar->FindVar("dedi_sendPrintsToClient"); + eSendPrintsToClient eSendPrints = static_cast<eSendPrintsToClient>(Cvar_dedi_sendPrintsToClient->GetInt()); + if (eSendPrints == eSendPrintsToClient::NONE) + return; + + std::string sLogMessage = fmt::format("[DEDICATED SERVER] [{}] {}", level_names[msg.level], msg.payload); + for (int i = 0; i < g_pGlobals->m_nMaxClients; i++) + { + CBaseClient* pClient = &g_pClientArray[i]; + + if (pClient->m_Signon >= eSignonState::CONNECTED) + { + CGameClient__ClientPrintf(pClient, sLogMessage.c_str()); + + if (eSendPrints == eSendPrintsToClient::FIRST) + break; + } + } +} + +void DedicatedServerLogToClientSink::sink_it_(const spdlog::details::log_msg& msg) +{ + throw std::runtime_error("sink_it_ called on DedicatedServerLogToClientSink with pure log_msg. This is an error!"); +} + +void DedicatedServerLogToClientSink::flush_() {} + +ON_DLL_LOAD_DEDI("engine.dll", DedicatedServerLogToClient, (CModule module)) +{ + CGameClient__ClientPrintf = module.Offset(0x1016A0).RCast<void (*)(CBaseClient*, const char*, ...)>(); +} |