From db552e7bcf5b1c6b01dd655163e1dc0a9d840ab0 Mon Sep 17 00:00:00 2001 From: BobTheBob <32057864+BobTheBob9@users.noreply.github.com> Date: Sat, 11 Dec 2021 22:24:13 +0000 Subject: write_persistence fixes and custom mainmenupromos --- .../NorthstarDedicatedTest.vcxproj | 2 + .../NorthstarDedicatedTest.vcxproj.filters | 6 + NorthstarDedicatedTest/dllmain.cpp | 2 + NorthstarDedicatedTest/masterserver.cpp | 103 +++++++++++++- NorthstarDedicatedTest/masterserver.h | 25 ++++ NorthstarDedicatedTest/scriptmainmenupromos.cpp | 152 +++++++++++++++++++++ NorthstarDedicatedTest/scriptmainmenupromos.h | 3 + NorthstarDedicatedTest/scriptmodmenu.cpp | 20 +-- NorthstarDedicatedTest/scriptserverbrowser.cpp | 2 +- 9 files changed, 303 insertions(+), 12 deletions(-) create mode 100644 NorthstarDedicatedTest/scriptmainmenupromos.cpp create mode 100644 NorthstarDedicatedTest/scriptmainmenupromos.h diff --git a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj index 5c7689dc..2e7053ea 100644 --- a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj +++ b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj @@ -325,6 +325,7 @@ + @@ -364,6 +365,7 @@ + diff --git a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters index 4acfac46..f1856a7c 100644 --- a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters +++ b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters @@ -588,6 +588,9 @@ Header Files\Shared + + Header Files\Client + @@ -689,6 +692,9 @@ Source Files\Shared + + Source Files\Client + diff --git a/NorthstarDedicatedTest/dllmain.cpp b/NorthstarDedicatedTest/dllmain.cpp index 9d8dc9a7..f0265f67 100644 --- a/NorthstarDedicatedTest/dllmain.cpp +++ b/NorthstarDedicatedTest/dllmain.cpp @@ -22,6 +22,7 @@ #include "miscserverscript.h" #include "clientauthhooks.h" #include "scriptbrowserhooks.h" +#include "scriptmainmenupromos.h" #include "memalloc.h" bool initialised = false; @@ -100,6 +101,7 @@ void InitialiseNorthstar() AddDllLoadCallback("localize.dll", InitialiseModLocalisation); AddDllLoadCallback("engine.dll", InitialiseClientAuthHooks); AddDllLoadCallback("engine.dll", InitialiseScriptExternalBrowserHooks); + AddDllLoadCallback("client.dll", InitialiseScriptMainMenuPromos); } AddDllLoadCallback("server.dll", InitialiseServerSquirrel); diff --git a/NorthstarDedicatedTest/masterserver.cpp b/NorthstarDedicatedTest/masterserver.cpp index 4b4b9e2c..4798a9b5 100644 --- a/NorthstarDedicatedTest/masterserver.cpp +++ b/NorthstarDedicatedTest/masterserver.cpp @@ -259,6 +259,102 @@ void MasterServerManager::RequestServerList() requestThread.detach(); } +void MasterServerManager::RequestMainMenuPromos() +{ + m_bHasMainMenuPromoData = false; + + std::thread requestThread([this]() + { + while (m_bOriginAuthWithMasterServerInProgress || !m_bOriginAuthWithMasterServerDone) + Sleep(500); + + httplib::Client http(Cvar_ns_masterserver_hostname->m_pszString, Cvar_ns_masterserver_port->m_nValue); + http.set_connection_timeout(20); + + if (auto result = http.Get("/client/mainmenupromos")) + { + m_successfullyConnected = true; + + rapidjson::Document mainMenuPromoJson; + mainMenuPromoJson.Parse(result->body.c_str()); + + if (mainMenuPromoJson.HasParseError()) + { + spdlog::error("Failed reading masterserver main menu promos response: encountered parse error \"{}\"", rapidjson::GetParseError_En(mainMenuPromoJson.GetParseError())); + goto REQUEST_END_CLEANUP; + } + + if (!mainMenuPromoJson.IsObject()) + { + spdlog::error("Failed reading masterserver main menu promos response: root object is not an object"); + goto REQUEST_END_CLEANUP; + } + + if (mainMenuPromoJson.HasMember("error")) + { + spdlog::error("Failed reading masterserver response: got fastify error response"); + spdlog::error(result->body); + goto REQUEST_END_CLEANUP; + } + + if (!mainMenuPromoJson.HasMember("newInfo") || !mainMenuPromoJson["newInfo"].IsObject() || + !mainMenuPromoJson["newInfo"].HasMember("Title1") || !mainMenuPromoJson["newInfo"]["Title1"].IsString() || + !mainMenuPromoJson["newInfo"].HasMember("Title2") || !mainMenuPromoJson["newInfo"]["Title2"].IsString() || + !mainMenuPromoJson["newInfo"].HasMember("Title3") || !mainMenuPromoJson["newInfo"]["Title3"].IsString() || + + !mainMenuPromoJson.HasMember("largeButton") || !mainMenuPromoJson["largeButton"].IsObject() || + !mainMenuPromoJson["largeButton"].HasMember("Title") || !mainMenuPromoJson["largeButton"]["Title"].IsString() || + !mainMenuPromoJson["largeButton"].HasMember("Text") || !mainMenuPromoJson["largeButton"]["Text"].IsString() || + !mainMenuPromoJson["largeButton"].HasMember("Url") || !mainMenuPromoJson["largeButton"]["Url"].IsString() || + !mainMenuPromoJson["largeButton"].HasMember("ImageIndex") || !mainMenuPromoJson["largeButton"]["ImageIndex"].IsNumber() || + + !mainMenuPromoJson.HasMember("smallButton1") || !mainMenuPromoJson["smallButton1"].IsObject() || + !mainMenuPromoJson["smallButton1"].HasMember("Title") || !mainMenuPromoJson["smallButton1"]["Title"].IsString() || + !mainMenuPromoJson["smallButton1"].HasMember("Url") || !mainMenuPromoJson["smallButton1"]["Url"].IsString() || + !mainMenuPromoJson["smallButton1"].HasMember("ImageIndex") || !mainMenuPromoJson["smallButton1"]["ImageIndex"].IsNumber() || + + !mainMenuPromoJson.HasMember("smallButton2") || !mainMenuPromoJson["smallButton2"].IsObject() || + !mainMenuPromoJson["smallButton2"].HasMember("Title") || !mainMenuPromoJson["smallButton2"]["Title"].IsString() || + !mainMenuPromoJson["smallButton2"].HasMember("Url") || !mainMenuPromoJson["smallButton2"]["Url"].IsString() || + !mainMenuPromoJson["smallButton2"].HasMember("ImageIndex") || !mainMenuPromoJson["smallButton2"]["ImageIndex"].IsNumber()) + { + spdlog::error("Failed reading masterserver main menu promos response: malformed json object"); + goto REQUEST_END_CLEANUP; + } + + m_MainMenuPromoData.newInfoTitle1 = mainMenuPromoJson["newInfo"]["Title1"].GetString(); + m_MainMenuPromoData.newInfoTitle2 = mainMenuPromoJson["newInfo"]["Title2"].GetString(); + m_MainMenuPromoData.newInfoTitle3 = mainMenuPromoJson["newInfo"]["Title3"].GetString(); + + m_MainMenuPromoData.largeButtonTitle = mainMenuPromoJson["largeButton"]["Title"].GetString(); + m_MainMenuPromoData.largeButtonText = mainMenuPromoJson["largeButton"]["Text"].GetString(); + m_MainMenuPromoData.largeButtonUrl = mainMenuPromoJson["largeButton"]["Url"].GetString(); + m_MainMenuPromoData.largeButtonImageIndex = mainMenuPromoJson["largeButton"]["ImageIndex"].GetInt(); + + m_MainMenuPromoData.smallButton1Title = mainMenuPromoJson["smallButton1"]["Title"].GetString(); + m_MainMenuPromoData.smallButton1Url = mainMenuPromoJson["smallButton1"]["Url"].GetString(); + m_MainMenuPromoData.smallButton1ImageIndex = mainMenuPromoJson["smallButton1"]["ImageIndex"].GetInt(); + + m_MainMenuPromoData.smallButton2Title = mainMenuPromoJson["smallButton2"]["Title"].GetString(); + m_MainMenuPromoData.smallButton2Url = mainMenuPromoJson["smallButton2"]["Url"].GetString(); + m_MainMenuPromoData.smallButton2ImageIndex = mainMenuPromoJson["smallButton2"]["ImageIndex"].GetInt(); + + m_bHasMainMenuPromoData = true; + } + else + { + spdlog::error("Failed requesting main menu promos: error {}", result.error()); + m_successfullyConnected = false; + } + + REQUEST_END_CLEANUP: + // nothing lol + return; + }); + + requestThread.detach(); +} + void MasterServerManager::AuthenticateWithOwnServer(char* uid, char* playerToken) { // dont wait, just stop if we're trying to do 2 auth requests at once @@ -620,6 +716,11 @@ void MasterServerManager::WritePlayerPersistentData(char* playerId, char* pdata, { // still call this if we don't have a server id, since lobbies that aren't port forwarded need to be able to call it m_savingPersistentData = true; + if (!pdataSize) + { + spdlog::warn("attempted to write pdata of size 0!"); + return; + } std::string playerIdTemp(playerId); std::thread requestThread([this, playerIdTemp, pdata, pdataSize] { @@ -631,7 +732,7 @@ void MasterServerManager::WritePlayerPersistentData(char* playerId, char* pdata, }; // we dont process this at all atm, maybe do later, but atm not necessary - if (auto result = http.Post(fmt::format("/accounts/write_persistence?id={}?serverId={}", playerIdTemp, m_ownServerId).c_str(), requestItems)) + if (auto result = http.Post(fmt::format("/accounts/write_persistence?id={}&serverId={}", playerIdTemp, m_ownServerId).c_str(), requestItems)) { m_successfullyConnected = true; } diff --git a/NorthstarDedicatedTest/masterserver.h b/NorthstarDedicatedTest/masterserver.h index 97f5bdce..5bb3549a 100644 --- a/NorthstarDedicatedTest/masterserver.h +++ b/NorthstarDedicatedTest/masterserver.h @@ -40,6 +40,27 @@ public: int port; }; +struct MainMenuPromoData +{ +public: + std::string newInfoTitle1; + std::string newInfoTitle2; + std::string newInfoTitle3; + + std::string largeButtonTitle; + std::string largeButtonText; + std::string largeButtonUrl; + int largeButtonImageIndex; + + std::string smallButton1Title; + std::string smallButton1Url; + int smallButton1ImageIndex; + + std::string smallButton2Title; + std::string smallButton2Url; + int smallButton2ImageIndex; +}; + class MasterServerManager { private: @@ -68,9 +89,13 @@ public: std::vector m_remoteServers; + bool m_bHasMainMenuPromoData = false; + MainMenuPromoData m_MainMenuPromoData; + public: void ClearServerList(); void RequestServerList(); + void RequestMainMenuPromos(); void AuthenticateOriginWithMasterServer(char* uid, char* originToken); void AuthenticateWithOwnServer(char* uid, char* playerToken); void AuthenticateWithServer(char* uid, char* playerToken, char* serverId, char* password); diff --git a/NorthstarDedicatedTest/scriptmainmenupromos.cpp b/NorthstarDedicatedTest/scriptmainmenupromos.cpp new file mode 100644 index 00000000..fcee9643 --- /dev/null +++ b/NorthstarDedicatedTest/scriptmainmenupromos.cpp @@ -0,0 +1,152 @@ +#include "pch.h" +#include "scriptmainmenupromos.h" +#include "squirrel.h" +#include "masterserver.h" +#include "dedicated.h" + +// mirror this in script +enum eMainMenuPromoDataProperty +{ + newInfoTitle1, + newInfoTitle2, + newInfoTitle3, + + largeButtonTitle, + largeButtonText, + largeButtonUrl, + largeButtonImageIndex, + + smallButton1Title, + smallButton1Url, + smallButton1ImageIndex, + + smallButton2Title, + smallButton2Url, + smallButton2ImageIndex +}; + +// void function NSRequestCustomMainMenuPromos() +SQRESULT SQ_RequestCustomMainMenuPromos(void* sqvm) +{ + g_MasterServerManager->RequestMainMenuPromos(); + return SQRESULT_NULL; +} + +// bool function NSHasCustomMainMenuPromoData() +SQRESULT SQ_HasCustomMainMenuPromoData(void* sqvm) +{ + ClientSq_pushbool(sqvm, g_MasterServerManager->m_bHasMainMenuPromoData); + return SQRESULT_NOTNULL; +} + +// var function NSGetCustomMainMenuPromoData( int promoDataKey ) +SQRESULT SQ_GetCustomMainMenuPromoData(void* sqvm) +{ + if (!g_MasterServerManager->m_bHasMainMenuPromoData) + return SQRESULT_NULL; + + switch (ClientSq_getinteger(sqvm, 1)) + { + case eMainMenuPromoDataProperty::newInfoTitle1: + { + ClientSq_pushstring(sqvm, g_MasterServerManager->m_MainMenuPromoData.newInfoTitle1.c_str(), -1); + break; + } + + case eMainMenuPromoDataProperty::newInfoTitle2: + { + ClientSq_pushstring(sqvm, g_MasterServerManager->m_MainMenuPromoData.newInfoTitle2.c_str(), -1); + break; + } + + case eMainMenuPromoDataProperty::newInfoTitle3: + { + ClientSq_pushstring(sqvm, g_MasterServerManager->m_MainMenuPromoData.newInfoTitle3.c_str(), -1); + break; + } + + case eMainMenuPromoDataProperty::largeButtonTitle: + { + ClientSq_pushstring(sqvm, g_MasterServerManager->m_MainMenuPromoData.largeButtonTitle.c_str(), -1); + break; + } + + case eMainMenuPromoDataProperty::largeButtonText: + { + ClientSq_pushstring(sqvm, g_MasterServerManager->m_MainMenuPromoData.largeButtonText.c_str(), -1); + break; + } + + case eMainMenuPromoDataProperty::largeButtonUrl: + { + ClientSq_pushstring(sqvm, g_MasterServerManager->m_MainMenuPromoData.largeButtonUrl.c_str(), -1); + break; + } + + case eMainMenuPromoDataProperty::largeButtonImageIndex: + { + ClientSq_pushinteger(sqvm, g_MasterServerManager->m_MainMenuPromoData.largeButtonImageIndex); + break; + } + + + case eMainMenuPromoDataProperty::smallButton1Title: + { + ClientSq_pushstring(sqvm, g_MasterServerManager->m_MainMenuPromoData.smallButton1Title.c_str(), -1); + break; + } + + { + ClientSq_pushstring(sqvm, g_MasterServerManager->m_MainMenuPromoData.smallButton1Text.c_str(), -1); + break; + } + + case eMainMenuPromoDataProperty::smallButton1Url: + { + ClientSq_pushstring(sqvm, g_MasterServerManager->m_MainMenuPromoData.smallButton1Url.c_str(), -1); + break; + } + + case eMainMenuPromoDataProperty::smallButton1ImageIndex: + { + ClientSq_pushinteger(sqvm, g_MasterServerManager->m_MainMenuPromoData.smallButton1ImageIndex); + break; + } + + + case eMainMenuPromoDataProperty::smallButton2Title: + { + ClientSq_pushstring(sqvm, g_MasterServerManager->m_MainMenuPromoData.smallButton2Title.c_str(), -1); + break; + } + + { + ClientSq_pushstring(sqvm, g_MasterServerManager->m_MainMenuPromoData.smallButton2Text.c_str(), -1); + break; + } + + case eMainMenuPromoDataProperty::smallButton2Url: + { + ClientSq_pushstring(sqvm, g_MasterServerManager->m_MainMenuPromoData.smallButton2Url.c_str(), -1); + break; + } + + case eMainMenuPromoDataProperty::smallButton2ImageIndex: + { + ClientSq_pushinteger(sqvm, g_MasterServerManager->m_MainMenuPromoData.smallButton2ImageIndex); + break; + } + } + + return SQRESULT_NOTNULL; +} + +void InitialiseScriptMainMenuPromos(HMODULE baseAddress) +{ + if (IsDedicated()) + return; + + g_UISquirrelManager->AddFuncRegistration("void", "NSRequestCustomMainMenuPromos", "", "", SQ_RequestCustomMainMenuPromos); + g_UISquirrelManager->AddFuncRegistration("bool", "NSHasCustomMainMenuPromoData", "", "", SQ_HasCustomMainMenuPromoData); + g_UISquirrelManager->AddFuncRegistration("var", "NSGetCustomMainMenuPromoData", "int promoDataKey", "", SQ_GetCustomMainMenuPromoData); +} \ No newline at end of file diff --git a/NorthstarDedicatedTest/scriptmainmenupromos.h b/NorthstarDedicatedTest/scriptmainmenupromos.h new file mode 100644 index 00000000..2719e647 --- /dev/null +++ b/NorthstarDedicatedTest/scriptmainmenupromos.h @@ -0,0 +1,3 @@ +#pragma once + +void InitialiseScriptMainMenuPromos(HMODULE baseAddress); \ No newline at end of file diff --git a/NorthstarDedicatedTest/scriptmodmenu.cpp b/NorthstarDedicatedTest/scriptmodmenu.cpp index d7c675ea..47fa971d 100644 --- a/NorthstarDedicatedTest/scriptmodmenu.cpp +++ b/NorthstarDedicatedTest/scriptmodmenu.cpp @@ -4,7 +4,7 @@ #include "squirrel.h" #include "dedicated.h" -// array NSGetModNames() +// array function NSGetModNames() SQRESULT SQ_GetModNames(void* sqvm) { ClientSq_newarray(sqvm, 0); @@ -18,7 +18,7 @@ SQRESULT SQ_GetModNames(void* sqvm) return SQRESULT_NOTNULL; } -// bool NSIsModEnabled(string modName) +// bool function NSIsModEnabled(string modName) SQRESULT SQ_IsModEnabled(void* sqvm) { const SQChar* modName = ClientSq_getstring(sqvm, 1); @@ -36,7 +36,7 @@ SQRESULT SQ_IsModEnabled(void* sqvm) return SQRESULT_NULL; } -// void NSSetModEnabled(string modName, bool enabled) +// void function NSSetModEnabled(string modName, bool enabled) SQRESULT SQ_SetModEnabled(void* sqvm) { const SQChar* modName = ClientSq_getstring(sqvm, 1); @@ -55,7 +55,7 @@ SQRESULT SQ_SetModEnabled(void* sqvm) return SQRESULT_NULL; } -// string NSGetModDescriptionByModName(string modName) +// string function NSGetModDescriptionByModName(string modName) SQRESULT SQ_GetModDescription(void* sqvm) { const SQChar* modName = ClientSq_getstring(sqvm, 1); @@ -73,7 +73,7 @@ SQRESULT SQ_GetModDescription(void* sqvm) return SQRESULT_NULL; } -// string NSGetModVersionByModName(string modName) +// string function NSGetModVersionByModName(string modName) SQRESULT SQ_GetModVersion(void* sqvm) { const SQChar* modName = ClientSq_getstring(sqvm, 1); @@ -91,7 +91,7 @@ SQRESULT SQ_GetModVersion(void* sqvm) return SQRESULT_NULL; } -// string NSGetModDownloadLinkByModName(string modName) +// string function NSGetModDownloadLinkByModName(string modName) SQRESULT SQ_GetModDownloadLink(void* sqvm) { const SQChar* modName = ClientSq_getstring(sqvm, 1); @@ -109,7 +109,7 @@ SQRESULT SQ_GetModDownloadLink(void* sqvm) return SQRESULT_NULL; } -// int NSGetModLoadPriority(string modName) +// int function NSGetModLoadPriority(string modName) SQRESULT SQ_GetModLoadPriority(void* sqvm) { const SQChar* modName = ClientSq_getstring(sqvm, 1); @@ -127,7 +127,7 @@ SQRESULT SQ_GetModLoadPriority(void* sqvm) return SQRESULT_NULL; } -// bool NSIsModRequiredOnClient(string modName) +// bool function NSIsModRequiredOnClient(string modName) SQRESULT SQ_IsModRequiredOnClient(void* sqvm) { const SQChar* modName = ClientSq_getstring(sqvm, 1); @@ -145,7 +145,7 @@ SQRESULT SQ_IsModRequiredOnClient(void* sqvm) return SQRESULT_NULL; } -// array NSGetModConvarsByModName(string modName) +// array function NSGetModConvarsByModName(string modName) SQRESULT SQ_GetModConvars(void* sqvm) { const SQChar* modName = ClientSq_getstring(sqvm, 1); @@ -169,7 +169,7 @@ SQRESULT SQ_GetModConvars(void* sqvm) return SQRESULT_NOTNULL; // return empty array } -// void NSReloadMods() +// void function NSReloadMods() SQRESULT SQ_ReloadMods(void* sqvm) { g_ModManager->LoadMods(); diff --git a/NorthstarDedicatedTest/scriptserverbrowser.cpp b/NorthstarDedicatedTest/scriptserverbrowser.cpp index 1cc4e62e..476c1b37 100644 --- a/NorthstarDedicatedTest/scriptserverbrowser.cpp +++ b/NorthstarDedicatedTest/scriptserverbrowser.cpp @@ -8,7 +8,7 @@ // functions for viewing server browser -// void NSRequestServerList() +// void function NSRequestServerList() SQRESULT SQ_RequestServerList(void* sqvm) { g_MasterServerManager->RequestServerList(); -- cgit v1.2.3