From 294203b160a21d7907d7a0bc70325ad48aa822e0 Mon Sep 17 00:00:00 2001 From: ASpoonPlaysGames <66967891+ASpoonPlaysGames@users.noreply.github.com> Date: Sat, 10 Jun 2023 13:23:27 +0100 Subject: [PATCH 1/6] launch er code for showing error dialog on failed auth --- NorthstarDLL/NorthstarDLL.vcxproj | 1 + NorthstarDLL/NorthstarDLL.vcxproj.filters | 3 ++ NorthstarDLL/masterserver/masterserver.cpp | 22 ++++++++++++ NorthstarDLL/masterserver/masterserver.h | 4 +++ NorthstarDLL/scriptoriginauth.cpp | 35 +++++++++++++++++++ .../scripts/client/scriptserverbrowser.cpp | 6 ---- 6 files changed, 65 insertions(+), 6 deletions(-) create mode 100644 NorthstarDLL/scriptoriginauth.cpp diff --git a/NorthstarDLL/NorthstarDLL.vcxproj b/NorthstarDLL/NorthstarDLL.vcxproj index 464c0b589..d27ec8b49 100644 --- a/NorthstarDLL/NorthstarDLL.vcxproj +++ b/NorthstarDLL/NorthstarDLL.vcxproj @@ -509,6 +509,7 @@ + diff --git a/NorthstarDLL/NorthstarDLL.vcxproj.filters b/NorthstarDLL/NorthstarDLL.vcxproj.filters index 7c6de46ed..6b6901115 100644 --- a/NorthstarDLL/NorthstarDLL.vcxproj.filters +++ b/NorthstarDLL/NorthstarDLL.vcxproj.filters @@ -1453,6 +1453,9 @@ Source Files\server + + Source Files\scripts\client + diff --git a/NorthstarDLL/masterserver/masterserver.cpp b/NorthstarDLL/masterserver/masterserver.cpp index 015670e78..615cf92c7 100644 --- a/NorthstarDLL/masterserver/masterserver.cpp +++ b/NorthstarDLL/masterserver/masterserver.cpp @@ -95,6 +95,10 @@ void MasterServerManager::AuthenticateOriginWithMasterServer(const char* uid, co std::string uidStr(uid); std::string tokenStr(originToken); + m_bOriginAuthWithMasterServerSuccessful = false; + m_sOriginAuthWithMasterServerErrorCode = ""; + m_sOriginAuthWithMasterServerErrorMessage = ""; + std::thread requestThread( [this, uidStr, tokenStr]() { @@ -142,9 +146,26 @@ void MasterServerManager::AuthenticateOriginWithMasterServer(const char* uid, co originAuthInfo["token"].GetString(), sizeof(m_sOwnClientAuthToken) - 1); spdlog::info("Northstar origin authentication completed successfully!"); + m_bOriginAuthWithMasterServerSuccessful = true; } else + { spdlog::error("Northstar origin authentication failed"); + + if (originAuthInfo.HasMember("error") && originAuthInfo["error"].IsObject()) + { + + if (originAuthInfo["error"].HasMember("enum") && originAuthInfo["error"]["enum"].IsString()) + { + m_sOriginAuthWithMasterServerErrorCode = originAuthInfo["error"]["enum"].GetString(); + } + + if (originAuthInfo["error"].HasMember("msg") && originAuthInfo["error"]["msg"].IsString()) + { + m_sOriginAuthWithMasterServerErrorMessage = originAuthInfo["error"]["msg"].GetString(); + } + } + } } else { @@ -156,6 +177,7 @@ void MasterServerManager::AuthenticateOriginWithMasterServer(const char* uid, co REQUEST_END_CLEANUP: m_bOriginAuthWithMasterServerInProgress = false; m_bOriginAuthWithMasterServerDone = true; + curl_easy_cleanup(curl); }); diff --git a/NorthstarDLL/masterserver/masterserver.h b/NorthstarDLL/masterserver/masterserver.h index e87b31a25..c4fa56c21 100644 --- a/NorthstarDLL/masterserver/masterserver.h +++ b/NorthstarDLL/masterserver/masterserver.h @@ -96,6 +96,10 @@ class MasterServerManager bool m_bOriginAuthWithMasterServerDone = false; bool m_bOriginAuthWithMasterServerInProgress = false; + bool m_bOriginAuthWithMasterServerSuccessful = false; + std::string m_sOriginAuthWithMasterServerErrorCode = ""; + std::string m_sOriginAuthWithMasterServerErrorMessage = ""; + bool m_bSavingPersistentData = false; bool m_bScriptRequestingServerList = false; diff --git a/NorthstarDLL/scriptoriginauth.cpp b/NorthstarDLL/scriptoriginauth.cpp new file mode 100644 index 000000000..420c48720 --- /dev/null +++ b/NorthstarDLL/scriptoriginauth.cpp @@ -0,0 +1,35 @@ +#include "squirrel/squirrel.h" +#include "masterserver/masterserver.h" +#include "engine/r2engine.h" +#include "client/r2client.h" + +ADD_SQFUNC("bool", NSIsMasterServerAuthenticated, "", "", ScriptContext::UI) +{ + g_pSquirrel->pushbool(sqvm, g_pMasterServerManager->m_bOriginAuthWithMasterServerDone); + return SQRESULT_NOTNULL; +} + +/* +global struct MasterServerAuthResult +{ + bool success + string errorCode + string errorMessage +} +*/ + +ADD_SQFUNC("MasterServerAuthResult", NSGetMasterServerAuthResult, "", "", ScriptContext::UI) +{ + g_pSquirrel->pushnewstructinstance(sqvm, 3); + + g_pSquirrel->pushbool(sqvm, g_pMasterServerManager->m_bOriginAuthWithMasterServerSuccessful); + g_pSquirrel->sealstructslot(sqvm, 0); + + g_pSquirrel->pushstring(sqvm, g_pMasterServerManager->m_sOriginAuthWithMasterServerErrorCode.c_str(), -1); + g_pSquirrel->sealstructslot(sqvm, 1); + + g_pSquirrel->pushstring(sqvm, g_pMasterServerManager->m_sOriginAuthWithMasterServerErrorMessage.c_str(), -1); + g_pSquirrel->sealstructslot(sqvm, 2); + + return SQRESULT_NOTNULL; +} diff --git a/NorthstarDLL/scripts/client/scriptserverbrowser.cpp b/NorthstarDLL/scripts/client/scriptserverbrowser.cpp index ff6da6e29..1945b3dc9 100644 --- a/NorthstarDLL/scripts/client/scriptserverbrowser.cpp +++ b/NorthstarDLL/scripts/client/scriptserverbrowser.cpp @@ -6,12 +6,6 @@ // functions for viewing server browser -ADD_SQFUNC("bool", NSIsMasterServerAuthenticated, "", "", ScriptContext::UI) -{ - g_pSquirrel->pushbool(sqvm, g_pMasterServerManager->m_bOriginAuthWithMasterServerDone); - return SQRESULT_NOTNULL; -} - ADD_SQFUNC("void", NSRequestServerList, "", "", ScriptContext::UI) { g_pMasterServerManager->RequestServerList(); From 9dc366216e3b8ccbf7bff8b58e6afd55d0411929 Mon Sep 17 00:00:00 2001 From: ASpoonPlaysGames <66967891+ASpoonPlaysGames@users.noreply.github.com> Date: Sat, 10 Jun 2023 13:23:27 +0100 Subject: [PATCH 2/6] launcher code for showing error dialog on failed auth --- NorthstarDLL/NorthstarDLL.vcxproj | 1 + NorthstarDLL/NorthstarDLL.vcxproj.filters | 3 ++ NorthstarDLL/masterserver/masterserver.cpp | 21 +++++++++++ NorthstarDLL/masterserver/masterserver.h | 4 +++ NorthstarDLL/scriptoriginauth.cpp | 35 +++++++++++++++++++ .../scripts/client/scriptserverbrowser.cpp | 6 ---- 6 files changed, 64 insertions(+), 6 deletions(-) create mode 100644 NorthstarDLL/scriptoriginauth.cpp diff --git a/NorthstarDLL/NorthstarDLL.vcxproj b/NorthstarDLL/NorthstarDLL.vcxproj index 464c0b589..d27ec8b49 100644 --- a/NorthstarDLL/NorthstarDLL.vcxproj +++ b/NorthstarDLL/NorthstarDLL.vcxproj @@ -509,6 +509,7 @@ + diff --git a/NorthstarDLL/NorthstarDLL.vcxproj.filters b/NorthstarDLL/NorthstarDLL.vcxproj.filters index 7c6de46ed..6b6901115 100644 --- a/NorthstarDLL/NorthstarDLL.vcxproj.filters +++ b/NorthstarDLL/NorthstarDLL.vcxproj.filters @@ -1453,6 +1453,9 @@ Source Files\server + + Source Files\scripts\client + diff --git a/NorthstarDLL/masterserver/masterserver.cpp b/NorthstarDLL/masterserver/masterserver.cpp index 015670e78..312bfc486 100644 --- a/NorthstarDLL/masterserver/masterserver.cpp +++ b/NorthstarDLL/masterserver/masterserver.cpp @@ -95,6 +95,10 @@ void MasterServerManager::AuthenticateOriginWithMasterServer(const char* uid, co std::string uidStr(uid); std::string tokenStr(originToken); + m_bOriginAuthWithMasterServerSuccessful = false; + m_sOriginAuthWithMasterServerErrorCode = ""; + m_sOriginAuthWithMasterServerErrorMessage = ""; + std::thread requestThread( [this, uidStr, tokenStr]() { @@ -142,9 +146,26 @@ void MasterServerManager::AuthenticateOriginWithMasterServer(const char* uid, co originAuthInfo["token"].GetString(), sizeof(m_sOwnClientAuthToken) - 1); spdlog::info("Northstar origin authentication completed successfully!"); + m_bOriginAuthWithMasterServerSuccessful = true; } else + { spdlog::error("Northstar origin authentication failed"); + + if (originAuthInfo.HasMember("error") && originAuthInfo["error"].IsObject()) + { + + if (originAuthInfo["error"].HasMember("enum") && originAuthInfo["error"]["enum"].IsString()) + { + m_sOriginAuthWithMasterServerErrorCode = originAuthInfo["error"]["enum"].GetString(); + } + + if (originAuthInfo["error"].HasMember("msg") && originAuthInfo["error"]["msg"].IsString()) + { + m_sOriginAuthWithMasterServerErrorMessage = originAuthInfo["error"]["msg"].GetString(); + } + } + } } else { diff --git a/NorthstarDLL/masterserver/masterserver.h b/NorthstarDLL/masterserver/masterserver.h index e87b31a25..c4fa56c21 100644 --- a/NorthstarDLL/masterserver/masterserver.h +++ b/NorthstarDLL/masterserver/masterserver.h @@ -96,6 +96,10 @@ class MasterServerManager bool m_bOriginAuthWithMasterServerDone = false; bool m_bOriginAuthWithMasterServerInProgress = false; + bool m_bOriginAuthWithMasterServerSuccessful = false; + std::string m_sOriginAuthWithMasterServerErrorCode = ""; + std::string m_sOriginAuthWithMasterServerErrorMessage = ""; + bool m_bSavingPersistentData = false; bool m_bScriptRequestingServerList = false; diff --git a/NorthstarDLL/scriptoriginauth.cpp b/NorthstarDLL/scriptoriginauth.cpp new file mode 100644 index 000000000..420c48720 --- /dev/null +++ b/NorthstarDLL/scriptoriginauth.cpp @@ -0,0 +1,35 @@ +#include "squirrel/squirrel.h" +#include "masterserver/masterserver.h" +#include "engine/r2engine.h" +#include "client/r2client.h" + +ADD_SQFUNC("bool", NSIsMasterServerAuthenticated, "", "", ScriptContext::UI) +{ + g_pSquirrel->pushbool(sqvm, g_pMasterServerManager->m_bOriginAuthWithMasterServerDone); + return SQRESULT_NOTNULL; +} + +/* +global struct MasterServerAuthResult +{ + bool success + string errorCode + string errorMessage +} +*/ + +ADD_SQFUNC("MasterServerAuthResult", NSGetMasterServerAuthResult, "", "", ScriptContext::UI) +{ + g_pSquirrel->pushnewstructinstance(sqvm, 3); + + g_pSquirrel->pushbool(sqvm, g_pMasterServerManager->m_bOriginAuthWithMasterServerSuccessful); + g_pSquirrel->sealstructslot(sqvm, 0); + + g_pSquirrel->pushstring(sqvm, g_pMasterServerManager->m_sOriginAuthWithMasterServerErrorCode.c_str(), -1); + g_pSquirrel->sealstructslot(sqvm, 1); + + g_pSquirrel->pushstring(sqvm, g_pMasterServerManager->m_sOriginAuthWithMasterServerErrorMessage.c_str(), -1); + g_pSquirrel->sealstructslot(sqvm, 2); + + return SQRESULT_NOTNULL; +} diff --git a/NorthstarDLL/scripts/client/scriptserverbrowser.cpp b/NorthstarDLL/scripts/client/scriptserverbrowser.cpp index ff6da6e29..1945b3dc9 100644 --- a/NorthstarDLL/scripts/client/scriptserverbrowser.cpp +++ b/NorthstarDLL/scripts/client/scriptserverbrowser.cpp @@ -6,12 +6,6 @@ // functions for viewing server browser -ADD_SQFUNC("bool", NSIsMasterServerAuthenticated, "", "", ScriptContext::UI) -{ - g_pSquirrel->pushbool(sqvm, g_pMasterServerManager->m_bOriginAuthWithMasterServerDone); - return SQRESULT_NOTNULL; -} - ADD_SQFUNC("void", NSRequestServerList, "", "", ScriptContext::UI) { g_pMasterServerManager->RequestServerList(); From fab3c726e89ea63b924b2e4372e543368075961c Mon Sep 17 00:00:00 2001 From: ASpoonPlaysGames <66967891+ASpoonPlaysGames@users.noreply.github.com> Date: Sat, 10 Jun 2023 13:27:17 +0100 Subject: [PATCH 3/6] why didnt you actually make the change that i said to make, github --- NorthstarDLL/masterserver/masterserver.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/NorthstarDLL/masterserver/masterserver.cpp b/NorthstarDLL/masterserver/masterserver.cpp index 615cf92c7..312bfc486 100644 --- a/NorthstarDLL/masterserver/masterserver.cpp +++ b/NorthstarDLL/masterserver/masterserver.cpp @@ -177,7 +177,6 @@ void MasterServerManager::AuthenticateOriginWithMasterServer(const char* uid, co REQUEST_END_CLEANUP: m_bOriginAuthWithMasterServerInProgress = false; m_bOriginAuthWithMasterServerDone = true; - curl_easy_cleanup(curl); }); From ed227696516f3d4aa31e740cf817dd1e46334de5 Mon Sep 17 00:00:00 2001 From: ASpoonPlaysGames <66967891+ASpoonPlaysGames@users.noreply.github.com> Date: Mon, 26 Jun 2023 11:53:03 +0100 Subject: [PATCH 4/6] move scriptoriginauth.cpp to correct folder --- NorthstarDLL/{ => scripts/client}/scriptoriginauth.cpp | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename NorthstarDLL/{ => scripts/client}/scriptoriginauth.cpp (100%) diff --git a/NorthstarDLL/scriptoriginauth.cpp b/NorthstarDLL/scripts/client/scriptoriginauth.cpp similarity index 100% rename from NorthstarDLL/scriptoriginauth.cpp rename to NorthstarDLL/scripts/client/scriptoriginauth.cpp From 0b6c3b403854271b7fe8593252590aea99bd6a92 Mon Sep 17 00:00:00 2001 From: ASpoonPlaysGames <66967891+ASpoonPlaysGames@users.noreply.github.com> Date: Mon, 26 Jun 2023 11:53:55 +0100 Subject: [PATCH 5/6] add scriptoriginauth.cpp --- NorthstarDLL/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/NorthstarDLL/CMakeLists.txt b/NorthstarDLL/CMakeLists.txt index f9d61a2c4..d75608260 100644 --- a/NorthstarDLL/CMakeLists.txt +++ b/NorthstarDLL/CMakeLists.txt @@ -85,6 +85,7 @@ add_library(NorthstarDLL SHARED "scripts/client/scriptbrowserhooks.cpp" "scripts/client/scriptmainmenupromos.cpp" "scripts/client/scriptmodmenu.cpp" + "scripts/client/scriptoriginauth.cpp" "scripts/client/scriptserverbrowser.cpp" "scripts/client/scriptservertoclientstringcommand.cpp" "scripts/server/miscserverfixes.cpp" From f16c11db8e86f7f46a9cd1886840105d8bbb1dfe Mon Sep 17 00:00:00 2001 From: Jack <66967891+ASpoonPlaysGames@users.noreply.github.com> Date: Sun, 9 Jul 2023 21:11:57 +0100 Subject: [PATCH 6/6] Fix indentation --- NorthstarDLL/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NorthstarDLL/CMakeLists.txt b/NorthstarDLL/CMakeLists.txt index 02512b409..3979df8d4 100644 --- a/NorthstarDLL/CMakeLists.txt +++ b/NorthstarDLL/CMakeLists.txt @@ -85,7 +85,7 @@ add_library(NorthstarDLL SHARED "scripts/client/scriptbrowserhooks.cpp" "scripts/client/scriptmainmenupromos.cpp" "scripts/client/scriptmodmenu.cpp" - "scripts/client/scriptoriginauth.cpp" + "scripts/client/scriptoriginauth.cpp" "scripts/client/scriptserverbrowser.cpp" "scripts/client/scriptservertoclientstringcommand.cpp" "scripts/server/miscserverfixes.cpp"