Skip to content

Commit

Permalink
Add X-Northstar-Server-Id header to auth server responses
Browse files Browse the repository at this point in the history
This will allow Atlas to verify the correct auth server for the
gameserver is listening on the expected port.
  • Loading branch information
pg9182 committed Nov 27, 2022
1 parent 02a473e commit b47f1d4
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions NorthstarDLL/serverauthentication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,28 @@ void ServerAuthenticationManager::StartPlayerAuthServer()
m_PlayerAuthServer.Get(
"/verify",
[](const httplib::Request& request, httplib::Response& response)
{ response.set_content(AUTHSERVER_VERIFY_STRING, "text/plain"); });
{
if (g_pMasterServerManager && *g_pMasterServerManager->m_sOwnServerId)
response.set_header("X-Northstar-Server-Id", g_pMasterServerManager->m_sOwnServerId);

response.set_content(AUTHSERVER_VERIFY_STRING, "text/plain");
});

m_PlayerAuthServer.Post(
"/authenticate_incoming_player",
[this](const httplib::Request& request, httplib::Response& response)
{
if (!request.has_param("id") || !request.has_param("authToken") || request.body.size() >= R2::PERSISTENCE_MAX_SIZE ||
!request.has_param("serverAuthToken") ||
if (!g_pMasterServerManager || !request.has_param("id") || !request.has_param("authToken") ||
request.body.size() >= R2::PERSISTENCE_MAX_SIZE || !request.has_param("serverAuthToken") ||
strcmp(g_pMasterServerManager->m_sOwnServerAuthToken, request.get_param_value("serverAuthToken").c_str()))
{
response.set_content("{\"success\":false}", "application/json");
return;
}

if (*g_pMasterServerManager->m_sOwnServerId)
response.set_header("X-Northstar-Server-Id", g_pMasterServerManager->m_sOwnServerId);

RemoteAuthData newAuthData {};
strncpy_s(newAuthData.uid, sizeof(newAuthData.uid), request.get_param_value("id").c_str(), sizeof(newAuthData.uid) - 1);
strncpy_s(
Expand Down

0 comments on commit b47f1d4

Please sign in to comment.