diff options
author | BobTheBob <32057864+BobTheBob9@users.noreply.github.com> | 2023-02-22 23:08:44 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-22 23:08:44 +0000 |
commit | 6aaac4cd452878acc59d9748bcd2d0e072d2a432 (patch) | |
tree | ea1d643962b2740d9bd5ec1480666a42c01b15b7 /NorthstarDLL | |
parent | 8468f509d4ede30e0c457db4448c83909464e83c (diff) | |
download | NorthstarLauncher-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')
-rw-r--r-- | NorthstarDLL/NorthstarDLL.vcxproj | 8 | ||||
-rw-r--r-- | NorthstarDLL/NorthstarDLL.vcxproj.filters | 14 | ||||
-rw-r--r-- | NorthstarDLL/dedicated/dedicated.cpp | 4 | ||||
-rw-r--r-- | NorthstarDLL/dedicated/dedicatedlogtoclient.cpp | 49 | ||||
-rw-r--r-- | NorthstarDLL/dedicated/dedicatedlogtoclient.h | 11 |
5 files changed, 79 insertions, 7 deletions
diff --git a/NorthstarDLL/NorthstarDLL.vcxproj b/NorthstarDLL/NorthstarDLL.vcxproj index bb28d575..7aa68841 100644 --- a/NorthstarDLL/NorthstarDLL.vcxproj +++ b/NorthstarDLL/NorthstarDLL.vcxproj @@ -413,6 +413,7 @@ <ClInclude Include="core\structs.h" />
<ClInclude Include="core\tier0.h" />
<ClInclude Include="dedicated\dedicated.h" />
+ <ClInclude Include="dedicated\dedicatedlogtoclient.h" />
<ClInclude Include="dllmain.h" />
<ClInclude Include="engine\hoststate.h" />
<ClInclude Include="engine\r2engine.h" />
@@ -449,7 +450,7 @@ <ClInclude Include="squirrel\squirreldatatypes.h" />
<ClInclude Include="util\utils.h" />
<ClInclude Include="util\version.h" />
- <ClInclude Include="util\wininfo.h" />
+ <ClInclude Include="util\wininfo.h" />
</ItemGroup>
<ItemGroup>
<None Include="..\include\spdlog\fmt\bundled\LICENSE.rst" />
@@ -483,6 +484,7 @@ <ClCompile Include="core\sourceinterface.cpp" />
<ClCompile Include="core\tier0.cpp" />
<ClCompile Include="dedicated\dedicated.cpp" />
+ <ClCompile Include="dedicated\dedicatedlogtoclient.cpp" />
<ClCompile Include="dedicated\dedicatedmaterialsystem.cpp" />
<ClCompile Include="dllmain.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Use</PrecompiledHeader>
@@ -540,7 +542,7 @@ <ClCompile Include="util\printmaps.cpp" />
<ClCompile Include="util\utils.cpp" />
<ClCompile Include="util\version.cpp" />
- <ClCompile Include="util\wininfo.cpp" />
+ <ClCompile Include="util\wininfo.cpp" />
</ItemGroup>
<ItemGroup>
<MASM Include="audio_asm.asm" />
@@ -549,4 +551,4 @@ <ImportGroup Label="ExtensionTargets">
<Import Project="$(VCTargetsPath)\BuildCustomizations\masm.targets" />
</ImportGroup>
-</Project>
+</Project>
\ No newline at end of file diff --git a/NorthstarDLL/NorthstarDLL.vcxproj.filters b/NorthstarDLL/NorthstarDLL.vcxproj.filters index d8437ba5..bb880580 100644 --- a/NorthstarDLL/NorthstarDLL.vcxproj.filters +++ b/NorthstarDLL/NorthstarDLL.vcxproj.filters @@ -1173,12 +1173,15 @@ <ClInclude Include="core\macros.h">
<Filter>Header Files\core</Filter>
</ClInclude>
- <ClInclude Include="util\wininfo.h">
- <Filter>Header Files</Filter>
+ <ClInclude Include="util\wininfo.h">
+ <Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="util\utils.h">
<Filter>Header Files\util</Filter>
</ClInclude>
+ <ClInclude Include="dedicated\dedicatedlogtoclient.h">
+ <Filter>Header Files\dedicated</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\include\spdlog\fmt\bundled\LICENSE.rst">
@@ -1429,10 +1432,13 @@ <ClCompile Include="util\utils.cpp">
<Filter>Source Files\util</Filter>
</ClCompile>
+ <ClCompile Include="dedicated\dedicatedlogtoclient.cpp">
+ <Filter>Source Files\dedicated</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<MASM Include="audio_asm.asm">
- <Filter>Source Files</Filter>
+ <Filter>Source Files\client</Filter>
</MASM>
</ItemGroup>
-</Project>
+</Project>
\ No newline at end of file diff --git a/NorthstarDLL/dedicated/dedicated.cpp b/NorthstarDLL/dedicated/dedicated.cpp index 267fbe92..1aff0f34 100644 --- a/NorthstarDLL/dedicated/dedicated.cpp +++ b/NorthstarDLL/dedicated/dedicated.cpp @@ -1,4 +1,5 @@ #include "dedicated.h" +#include "dedicatedlogtoclient.h" #include "core/tier0.h" #include "playlist.h" #include "engine/r2engine.h" @@ -226,6 +227,9 @@ ON_DLL_LOAD_DEDI_RELIESON("engine.dll", DedicatedServer, ServerPresence, (CModul DedicatedConsoleServerPresence* presenceReporter = new DedicatedConsoleServerPresence; g_pServerPresence->AddPresenceReporter(presenceReporter); + // setup dedicated printing to client + RegisterCustomSink(std::make_shared<DedicatedServerLogToClientSink>()); + // Disable Quick Edit mode to reduce chance of user unintentionally hanging their server by selecting something. if (!Tier0::CommandLine()->CheckParm("-bringbackquickedit")) { 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*, ...)>(); +} diff --git a/NorthstarDLL/dedicated/dedicatedlogtoclient.h b/NorthstarDLL/dedicated/dedicatedlogtoclient.h new file mode 100644 index 00000000..16f1e584 --- /dev/null +++ b/NorthstarDLL/dedicated/dedicatedlogtoclient.h @@ -0,0 +1,11 @@ +#pragma once +#include "logging/logging.h" +#include "core/convar/convar.h" + +class DedicatedServerLogToClientSink : public CustomSink +{ + protected: + void custom_sink_it_(const custom_log_msg& msg); + void sink_it_(const spdlog::details::log_msg& msg) override; + void flush_() override; +}; |