aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDedicatedTest/masterserver.cpp
diff options
context:
space:
mode:
authorBobTheBob <32057864+BobTheBob9@users.noreply.github.com>2021-11-07 22:06:19 +0000
committerBobTheBob <32057864+BobTheBob9@users.noreply.github.com>2021-11-07 22:06:19 +0000
commitae09e612ea33cb105a47996c4ae3bf8651119042 (patch)
tree91c46140555d3a85c0e6bceb1da3d1c031ae40be /NorthstarDedicatedTest/masterserver.cpp
parent916f4f53ad839d6f8e565e50bb310429a3e115f3 (diff)
downloadNorthstarLauncher-ae09e612ea33cb105a47996c4ae3bf8651119042.tar.gz
NorthstarLauncher-ae09e612ea33cb105a47996c4ae3bf8651119042.zip
beginning work on new auth
Diffstat (limited to 'NorthstarDedicatedTest/masterserver.cpp')
-rw-r--r--NorthstarDedicatedTest/masterserver.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/NorthstarDedicatedTest/masterserver.cpp b/NorthstarDedicatedTest/masterserver.cpp
index 80d606eb..9ac88667 100644
--- a/NorthstarDedicatedTest/masterserver.cpp
+++ b/NorthstarDedicatedTest/masterserver.cpp
@@ -67,6 +67,62 @@ void MasterServerManager::ClearServerList()
m_requestingServerList = false;
}
+void MasterServerManager::AuthenticateOriginWithMasterServer(char* uid, char* originToken)
+{
+ if (m_bOriginAuthWithMasterServerInProgress)
+ return;
+
+ // do this here so it's instantly set
+ m_bOriginAuthWithMasterServerInProgress = true;
+ std::string uidStr(uid);
+ std::string tokenStr(originToken);
+
+ std::thread requestThread([this, uidStr, tokenStr]()
+ {
+ httplib::Client http(Cvar_ns_masterserver_hostname->m_pszString, Cvar_ns_masterserver_port->m_nValue);
+ http.set_connection_timeout(10);
+
+ spdlog::info("Trying to authenticate with northstar masterserver for user {} {}", uidStr, tokenStr);
+
+ if (auto result = http.Get(fmt::format("/client/origin_auth?uid={}&token={}", uidStr, tokenStr).c_str()))
+ {
+ m_successfullyConnected = true;
+
+ rapidjson::Document originAuthInfo;
+ originAuthInfo.Parse(result->body.c_str());
+
+ if (originAuthInfo.HasParseError())
+ {
+ spdlog::error("Failed reading origin auth info response: encountered parse error \{}\"", rapidjson::GetParseError_En(originAuthInfo.GetParseError()));
+ goto REQUEST_END_CLEANUP;
+ }
+
+ if (!originAuthInfo.IsObject() || !originAuthInfo.HasMember("success"))
+ {
+ spdlog::error("Failed reading origin auth info response: malformed response object {}", result->body);
+ goto REQUEST_END_CLEANUP;
+ }
+
+ if (originAuthInfo["success"].IsTrue())
+ spdlog::info("Northstar origin authentication completed successfully!");
+ else
+ spdlog::error("Northstar origin authentication failed");
+ }
+ else
+ {
+ spdlog::error("Failed performing northstar origin auth: error {}", result.error());
+ m_successfullyConnected = false;
+ }
+
+ // we goto this instead of returning so we always hit this
+ REQUEST_END_CLEANUP:
+ m_bOriginAuthWithMasterServerInProgress = false;
+ m_bOriginAuthWithMasterServerDone = true;
+ });
+
+ requestThread.detach();
+}
+
void MasterServerManager::RequestServerList()
{
// do this here so it's instantly set on call for scripts