aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDedicatedTest
diff options
context:
space:
mode:
authorKawe Mazidjatari <48657826+Mauler125@users.noreply.github.com>2022-03-13 21:56:13 +0100
committerGitHub <noreply@github.com>2022-03-13 21:56:13 +0100
commitd6bf4b105aaac9bd061990a8eb455cbfcac25de4 (patch)
tree01a0ce2e14c5a1be591adfe37c434500bb41e6ef /NorthstarDedicatedTest
parent80ec6ee8d51e3361487fc90138e25a98be059c0a (diff)
parent5df2346ba1414fd43d80fc2919c2f880b7f8aeaf (diff)
downloadNorthstarLauncher-d6bf4b105aaac9bd061990a8eb455cbfcac25de4.tar.gz
NorthstarLauncher-d6bf4b105aaac9bd061990a8eb455cbfcac25de4.zip
Merge branch 'main' into NetCon
Diffstat (limited to 'NorthstarDedicatedTest')
-rw-r--r--NorthstarDedicatedTest/serverauthentication.cpp28
-rw-r--r--NorthstarDedicatedTest/serverauthentication.h2
2 files changed, 30 insertions, 0 deletions
diff --git a/NorthstarDedicatedTest/serverauthentication.cpp b/NorthstarDedicatedTest/serverauthentication.cpp
index 9ec66b9f..d766514d 100644
--- a/NorthstarDedicatedTest/serverauthentication.cpp
+++ b/NorthstarDedicatedTest/serverauthentication.cpp
@@ -111,6 +111,9 @@ void ServerAuthenticationManager::StartPlayerAuthServer()
strncpy(newAuthData.uid, request.get_param_value("id").c_str(), sizeof(newAuthData.uid));
newAuthData.uid[sizeof(newAuthData.uid) - 1] = 0;
+ strncpy(newAuthData.username, request.get_param_value("username").c_str(), sizeof(newAuthData.username));
+ newAuthData.username[sizeof(newAuthData.username) - 1] = 0;
+
newAuthData.pdataSize = request.body.size();
newAuthData.pdata = new char[newAuthData.pdataSize];
memcpy(newAuthData.pdata, request.body.c_str(), newAuthData.pdataSize);
@@ -139,6 +142,27 @@ void ServerAuthenticationManager::StopPlayerAuthServer()
m_playerAuthServer.stop();
}
+char* ServerAuthenticationManager::VerifyPlayerName(void* player, char* authToken, char* name)
+{
+ std::lock_guard<std::mutex> guard(m_authDataMutex);
+
+ if (!m_authData.empty() && m_authData.count(std::string(authToken)))
+ {
+ AuthData authData = m_authData[authToken];
+
+ bool nameAccepted = (!*authData.username || !strcmp(name, authData.username));
+
+ if (!nameAccepted && g_MasterServerManager->m_bRequireClientAuth && !CVar_ns_auth_allow_insecure->GetInt())
+ {
+ // limit name length to 64 characters just in case something changes, this technically shouldn't be needed given the master
+ // server gets usernames from origin but we have it just in case
+ strncpy(name, authData.username, 64);
+ name[63] = 0;
+ }
+ }
+ return name;
+}
+
bool ServerAuthenticationManager::AuthenticatePlayer(void* player, int64_t uid, char* authToken)
{
std::string strUid = std::to_string(uid);
@@ -149,6 +173,7 @@ bool ServerAuthenticationManager::AuthenticatePlayer(void* player, int64_t uid,
{
// use stored auth data
AuthData authData = m_authData[authToken];
+
if (!strcmp(strUid.c_str(), authData.uid)) // connecting client's uid is the same as auth's uid
{
authFail = false;
@@ -295,6 +320,9 @@ void* CBaseServer__ConnectClientHook(
bool CBaseClient__ConnectHook(void* self, char* name, __int64 netchan_ptr_arg, char b_fake_player_arg, __int64 a5, char* Buffer, void* a7)
{
+ // try changing name before all else
+ name = g_ServerAuthenticationManager->VerifyPlayerName(self, nextPlayerToken, name);
+
// try to auth player, dc if it fails
// we connect irregardless of auth, because returning bad from this function can fuck client state p bad
bool ret = CBaseClient__Connect(self, name, netchan_ptr_arg, b_fake_player_arg, a5, Buffer, a7);
diff --git a/NorthstarDedicatedTest/serverauthentication.h b/NorthstarDedicatedTest/serverauthentication.h
index 4bcc70ce..8822d1e2 100644
--- a/NorthstarDedicatedTest/serverauthentication.h
+++ b/NorthstarDedicatedTest/serverauthentication.h
@@ -6,6 +6,7 @@
struct AuthData
{
char uid[33];
+ char username[64];
// pdata
char* pdata;
@@ -85,6 +86,7 @@ class ServerAuthenticationManager
void StartPlayerAuthServer();
void StopPlayerAuthServer();
bool AuthenticatePlayer(void* player, int64_t uid, char* authToken);
+ char* VerifyPlayerName(void* player, char* authToken, char* name);
bool RemovePlayerAuthData(void* player);
void WritePersistentData(void* player);
bool CheckPlayerChatRatelimit(void* player);