aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBobTheBob <32057864+BobTheBob9@users.noreply.github.com>2021-10-11 23:35:40 +0100
committerBobTheBob <32057864+BobTheBob9@users.noreply.github.com>2021-10-11 23:35:40 +0100
commitc5cf48bba33159fc268904688f29ed20c14b11b3 (patch)
tree88aa6d01bf204f93ece63e50d3f1b9b4ca263094
parentcb386ef4857f5a0f13998d1813cfa7d57a00af7d (diff)
downloadNorthstarLauncher-c5cf48bba33159fc268904688f29ed20c14b11b3.tar.gz
NorthstarLauncher-c5cf48bba33159fc268904688f29ed20c14b11b3.zip
add server script early persistence writes
-rw-r--r--NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj2
-rw-r--r--NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters6
-rw-r--r--NorthstarDedicatedTest/dllmain.cpp2
-rw-r--r--NorthstarDedicatedTest/masterserver.cpp3
-rw-r--r--NorthstarDedicatedTest/masterserver.h10
-rw-r--r--NorthstarDedicatedTest/modlocalisation.cpp5
-rw-r--r--NorthstarDedicatedTest/modmanager.cpp5
-rw-r--r--NorthstarDedicatedTest/serverauthentication.cpp3
-rw-r--r--NorthstarDedicatedTest/serverauthentication.h1
-rw-r--r--NorthstarDedicatedTest/serverscriptpersistence.cpp30
-rw-r--r--NorthstarDedicatedTest/serverscriptpersistence.h1
-rw-r--r--NorthstarDedicatedTest/squirrel.cpp5
-rw-r--r--NorthstarDedicatedTest/squirrel.h4
13 files changed, 72 insertions, 5 deletions
diff --git a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj
index 43eda97a..f0d10de3 100644
--- a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj
+++ b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj
@@ -316,6 +316,7 @@
<ClInclude Include="modmanager.h" />
<ClInclude Include="pch.h" />
<ClInclude Include="playlist.h" />
+ <ClInclude Include="serverscriptpersistence.h" />
<ClInclude Include="securitypatches.h" />
<ClInclude Include="scriptmodmenu.h" />
<ClInclude Include="scriptserverbrowser.h" />
@@ -357,6 +358,7 @@
<ClCompile Include="scriptserverbrowser.cpp" />
<ClCompile Include="scriptsrson.cpp" />
<ClCompile Include="serverauthentication.cpp" />
+ <ClCompile Include="serverscriptpersistence.cpp" />
<ClCompile Include="sigscanning.cpp" />
<ClCompile Include="sourceconsole.cpp" />
<ClCompile Include="sourceinterface.cpp" />
diff --git a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters
index 8908df5f..8d39b3bd 100644
--- a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters
+++ b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters
@@ -576,6 +576,9 @@
<ClInclude Include="misccommands.h">
<Filter>Header Files\Shared\Convar</Filter>
</ClInclude>
+ <ClInclude Include="serverscriptpersistence.h">
+ <Filter>Header Files\Server</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="dllmain.cpp">
@@ -665,6 +668,9 @@
<ClCompile Include="misccommands.cpp">
<Filter>Source Files\Shared\Convar</Filter>
</ClCompile>
+ <ClCompile Include="serverscriptpersistence.cpp">
+ <Filter>Source Files\Server</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="include\spdlog\fmt\bundled\LICENSE.rst">
diff --git a/NorthstarDedicatedTest/dllmain.cpp b/NorthstarDedicatedTest/dllmain.cpp
index 7bf1c091..cb3477e0 100644
--- a/NorthstarDedicatedTest/dllmain.cpp
+++ b/NorthstarDedicatedTest/dllmain.cpp
@@ -20,6 +20,7 @@
#include "modlocalisation.h"
#include "playlist.h"
#include "securitypatches.h"
+#include "serverscriptpersistence.h"
bool initialised = false;
@@ -91,6 +92,7 @@ void InitialiseNorthstar()
AddDllLoadCallback("server.dll", InitialiseServerSquirrel);
AddDllLoadCallback("engine.dll", InitialiseServerAuthentication);
AddDllLoadCallback("engine.dll", InitialiseSharedMasterServer);
+ AddDllLoadCallback("server.dll", InitialiseServerScriptPersistence);
AddDllLoadCallback("engine.dll", InitialisePlaylistHooks);
diff --git a/NorthstarDedicatedTest/masterserver.cpp b/NorthstarDedicatedTest/masterserver.cpp
index d7f966db..36b360a1 100644
--- a/NorthstarDedicatedTest/masterserver.cpp
+++ b/NorthstarDedicatedTest/masterserver.cpp
@@ -5,6 +5,7 @@
#include "hookutils.h"
#include "httplib.h"
#include "serverauthentication.h"
+#include "gameutils.h"
#include "rapidjson/document.h"
#include "rapidjson/error/en.h"
@@ -560,7 +561,7 @@ void CHostState__State_NewGameHook(CHostState* hostState)
Cbuf_AddText(Cbuf_GetCurrentPlayer(), "exec autoexec_ns_server", cmd_source_t::kCommandSrcCode);
Cbuf_Execute();
- g_MasterServerManager->AddSelfToServerList(Cvar_hostport->m_nValue, Cvar_ns_player_auth_port->m_nValue, Cvar_ns_server_name->m_pszString, Cvar_ns_server_desc->m_pszString, hostState->m_levelName, (char*)GetCurrentPlaylistName(), 16, Cvar_ns_server_password->m_pszString);
+ g_MasterServerManager->AddSelfToServerList(Cvar_hostport->m_nValue, Cvar_ns_player_auth_port->m_nValue, Cvar_ns_server_name->m_pszString, Cvar_ns_server_desc->m_pszString, hostState->m_levelName, (char*)GetCurrentPlaylistName(), std::stoi(GetCurrentPlaylistVar("max_players", true)), Cvar_ns_server_password->m_pszString);
g_ServerAuthenticationManager->StartPlayerAuthServer();
CHostState__State_NewGame(hostState);
diff --git a/NorthstarDedicatedTest/masterserver.h b/NorthstarDedicatedTest/masterserver.h
index d7dcf485..67f9a96f 100644
--- a/NorthstarDedicatedTest/masterserver.h
+++ b/NorthstarDedicatedTest/masterserver.h
@@ -2,6 +2,13 @@
#include "convar.h"
#include <WinSock2.h>
+struct RemoteServerModInfo
+{
+public:
+ std::string modName;
+ std::string modServer;
+};
+
class RemoteServerInfo
{
public:
@@ -12,6 +19,7 @@ public:
std::string description;
char map[32];
char playlist[16];
+ std::vector<RemoteServerModInfo> requiredMods;
int playerCount;
int maxPlayers;
@@ -37,12 +45,12 @@ class MasterServerManager
private:
bool m_requestingServerList = false;
bool m_authenticatingWithGameServer = false;
- bool m_savingPersistentData = false;
public:
char m_ownServerId[33];
bool m_bRequireClientAuth = false;
+ bool m_savingPersistentData = false;
bool m_scriptRequestingServerList = false;
bool m_successfullyConnected = true;
diff --git a/NorthstarDedicatedTest/modlocalisation.cpp b/NorthstarDedicatedTest/modlocalisation.cpp
index d8168d0c..91f0416a 100644
--- a/NorthstarDedicatedTest/modlocalisation.cpp
+++ b/NorthstarDedicatedTest/modlocalisation.cpp
@@ -22,8 +22,9 @@ bool AddLocalisationFileHook(void* g_pVguiLocalize, const char* path, const char
loadModLocalisationFiles = false;
for (Mod* mod : g_ModManager->m_loadedMods)
- for (std::string& localisationFile : mod->LocalisationFiles)
- AddLocalisationFile(g_pVguiLocalize, localisationFile.c_str(), pathId, unknown);
+ if (mod->Enabled)
+ for (std::string& localisationFile : mod->LocalisationFiles)
+ AddLocalisationFile(g_pVguiLocalize, localisationFile.c_str(), pathId, unknown);
loadModLocalisationFiles = true;
diff --git a/NorthstarDedicatedTest/modmanager.cpp b/NorthstarDedicatedTest/modmanager.cpp
index b561c03b..42ad0545 100644
--- a/NorthstarDedicatedTest/modmanager.cpp
+++ b/NorthstarDedicatedTest/modmanager.cpp
@@ -245,6 +245,11 @@ void ModManager::LoadMods()
if (mod->wasReadSuccessfully)
{
spdlog::info("Loaded mod {} successfully", mod->Name);
+ if (mod->Enabled)
+ spdlog::info("Mod {} is enabled", mod->Name);
+ else
+ spdlog::info("Mod {} is disabled", mod->Name);
+
m_loadedMods.push_back(mod);
}
else
diff --git a/NorthstarDedicatedTest/serverauthentication.cpp b/NorthstarDedicatedTest/serverauthentication.cpp
index fed4eb82..fe3c6183 100644
--- a/NorthstarDedicatedTest/serverauthentication.cpp
+++ b/NorthstarDedicatedTest/serverauthentication.cpp
@@ -257,7 +257,8 @@ void CBaseClient__DisconnectHook(void* self, uint32_t unknownButAlways1, const c
if (strcmp(reason, "Connection closing"))
{
// dcing, write persistent data
- g_ServerAuthenticationManager->WritePersistentData(self);
+ if (!g_ServerAuthenticationManager->m_additionalPlayerData[self].needPersistenceWriteOnLeave)
+ g_ServerAuthenticationManager->WritePersistentData(self);
g_ServerAuthenticationManager->RemovePlayerAuthData(self); // won't do anything 99% of the time, but just in case
}
diff --git a/NorthstarDedicatedTest/serverauthentication.h b/NorthstarDedicatedTest/serverauthentication.h
index 38008e9b..c0f4bea2 100644
--- a/NorthstarDedicatedTest/serverauthentication.h
+++ b/NorthstarDedicatedTest/serverauthentication.h
@@ -17,6 +17,7 @@ struct AdditionalPlayerData
{
bool usingLocalPdata;
size_t pdataSize;
+ bool needPersistenceWriteOnLeave = true;
double lastClientCommandQuotaStart = 0;
int numClientCommandsInQuota = 0;
diff --git a/NorthstarDedicatedTest/serverscriptpersistence.cpp b/NorthstarDedicatedTest/serverscriptpersistence.cpp
new file mode 100644
index 00000000..4f7bba88
--- /dev/null
+++ b/NorthstarDedicatedTest/serverscriptpersistence.cpp
@@ -0,0 +1,30 @@
+#include "pch.h"
+#include "serverscriptpersistence.h"
+#include "squirrel.h"
+#include "masterserver.h"
+#include "serverauthentication.h"
+
+// void function NSEarlyWritePlayerPersistenceForLeave( entity player )
+SQInteger SQ_EarlyWritePlayerPersistenceForLeave(void* sqvm)
+{
+ void* player;
+ if (!ServerSq_getentity(sqvm, &player) || !g_ServerAuthenticationManager->m_additionalPlayerData.count(player))
+ return 0;
+
+ g_ServerAuthenticationManager->m_additionalPlayerData[player].needPersistenceWriteOnLeave = false;
+ g_ServerAuthenticationManager->WritePersistentData(player);
+ return 0;
+}
+
+// bool function NSIsWritingPlayerPersistence()
+SQInteger SQ_IsWritingPlayerPersistence(void* sqvm)
+{
+ ServerSq_pushbool(sqvm, g_MasterServerManager->m_savingPersistentData);
+ return 1;
+}
+
+void InitialiseServerScriptPersistence(HMODULE baseAddress)
+{
+ g_ServerSquirrelManager->AddFuncRegistration("void", "NSEarlyWritePlayerPersistenceForLeave", "entity player", "", SQ_EarlyWritePlayerPersistenceForLeave);
+ g_ServerSquirrelManager->AddFuncRegistration("bool", "NSIsWritingPlayerPersistence", "", "", SQ_IsWritingPlayerPersistence);
+} \ No newline at end of file
diff --git a/NorthstarDedicatedTest/serverscriptpersistence.h b/NorthstarDedicatedTest/serverscriptpersistence.h
new file mode 100644
index 00000000..c4eb863f
--- /dev/null
+++ b/NorthstarDedicatedTest/serverscriptpersistence.h
@@ -0,0 +1 @@
+void InitialiseServerScriptPersistence(HMODULE baseAddress); \ No newline at end of file
diff --git a/NorthstarDedicatedTest/squirrel.cpp b/NorthstarDedicatedTest/squirrel.cpp
index dfeb1805..f8d8cd33 100644
--- a/NorthstarDedicatedTest/squirrel.cpp
+++ b/NorthstarDedicatedTest/squirrel.cpp
@@ -84,6 +84,9 @@ sq_getfloatType ServerSq_getfloat;
sq_getboolType ClientSq_getbool;
sq_getboolType ServerSq_getbool;
+sq_getentityType ClientSq_getentity;
+sq_getentityType ServerSq_getentity;
+
template<Context context> void ExecuteCodeCommand(const CCommand& args);
@@ -134,6 +137,7 @@ void InitialiseClientSquirrel(HMODULE baseAddress)
ClientSq_getinteger = (sq_getintegerType)((char*)baseAddress + 0x60E0);
ClientSq_getfloat = (sq_getfloatType)((char*)baseAddress + 0x6100);
ClientSq_getbool = (sq_getboolType)((char*)baseAddress + 0x6130);
+ ClientSq_getentity = (sq_getentityType)((char*)baseAddress + 0x12F80);
ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x26130, &CreateNewVMHook<CLIENT>, reinterpret_cast<LPVOID*>(&ClientCreateNewVM)); // client createnewvm function
ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x26E70, &DestroyVMHook<CLIENT>, reinterpret_cast<LPVOID*>(&ClientDestroyVM)); // client destroyvm function
@@ -164,6 +168,7 @@ void InitialiseServerSquirrel(HMODULE baseAddress)
ServerSq_getinteger = (sq_getintegerType)((char*)baseAddress + 0x60C0);
ServerSq_getfloat = (sq_getfloatType)((char*)baseAddress + 0x60E0);
ServerSq_getbool = (sq_getboolType)((char*)baseAddress + 0x6110);
+ ServerSq_getentity = (sq_getentityType)((char*)baseAddress + 0x203B0);
ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x1FE90, &SQPrintHook<SERVER>, reinterpret_cast<LPVOID*>(&ServerSQPrint)); // server print function
ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x260E0, &CreateNewVMHook<SERVER>, reinterpret_cast<LPVOID*>(&ServerCreateNewVM)); // server createnewvm function
diff --git a/NorthstarDedicatedTest/squirrel.h b/NorthstarDedicatedTest/squirrel.h
index 5ccab090..48eba539 100644
--- a/NorthstarDedicatedTest/squirrel.h
+++ b/NorthstarDedicatedTest/squirrel.h
@@ -118,6 +118,10 @@ typedef SQBool(*sq_getboolType)(void*, SQInteger stackpos);
extern sq_getboolType ClientSq_getbool;
extern sq_getboolType ServerSq_getbool;
+typedef SQBool(*sq_getentityType)(void*, void** entity);
+extern sq_getentityType ClientSq_getentity;
+extern sq_getentityType ServerSq_getentity;
+
template<Context context> class SquirrelManager
{