aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDLL/dedicated/dedicatedlogtoclient.cpp
diff options
context:
space:
mode:
authorBobTheBob <32057864+BobTheBob9@users.noreply.github.com>2023-02-22 23:08:44 +0000
committerGitHub <noreply@github.com>2023-02-22 23:08:44 +0000
commit6aaac4cd452878acc59d9748bcd2d0e072d2a432 (patch)
treeea1d643962b2740d9bd5ec1480666a42c01b15b7 /NorthstarDLL/dedicated/dedicatedlogtoclient.cpp
parent8468f509d4ede30e0c457db4448c83909464e83c (diff)
downloadNorthstarLauncher-6aaac4cd452878acc59d9748bcd2d0e072d2a432.tar.gz
NorthstarLauncher-6aaac4cd452878acc59d9748bcd2d0e072d2a432.zip
Implement `dedi_sendPrintsToClient` (#418)
* add CGlobals class and g_pGlobals, and update scripts to support * don't automatically enable antispeedhack (oops) * add dedicated.cpp * format * bad push oops * reformat again * implement dedi_sendPrintsToClient * update formatting
Diffstat (limited to 'NorthstarDLL/dedicated/dedicatedlogtoclient.cpp')
-rw-r--r--NorthstarDLL/dedicated/dedicatedlogtoclient.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/NorthstarDLL/dedicated/dedicatedlogtoclient.cpp b/NorthstarDLL/dedicated/dedicatedlogtoclient.cpp
new file mode 100644
index 00000000..bb62cb36
--- /dev/null
+++ b/NorthstarDLL/dedicated/dedicatedlogtoclient.cpp
@@ -0,0 +1,49 @@
+#include "pch.h"
+#include "dedicatedlogtoclient.h"
+#include "engine/r2engine.h"
+
+void (*CGameClient__ClientPrintf)(R2::CBaseClient* pClient, const char* fmt, ...);
+
+void DedicatedServerLogToClientSink::custom_sink_it_(const custom_log_msg& msg)
+{
+ if (*R2::g_pServerState == R2::server_state_t::ss_dead)
+ return;
+
+ enum class eSendPrintsToClient
+ {
+ NONE = -1,
+ FIRST,
+ ALL
+ };
+
+ static const ConVar* Cvar_dedi_sendPrintsToClient = R2::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 < R2::g_pGlobals->m_nMaxClients; i++)
+ {
+ R2::CBaseClient* pClient = &R2::g_pClientArray[i];
+
+ if (pClient->m_Signon >= R2::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).As<void (*)(R2::CBaseClient*, const char*, ...)>();
+}