aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NorthstarDedicatedTest/masterserver.cpp8
-rw-r--r--NorthstarDedicatedTest/masterserver.h1
-rw-r--r--NorthstarDedicatedTest/misccommands.cpp24
-rw-r--r--NorthstarDedicatedTest/miscserverscript.cpp16
-rw-r--r--NorthstarDedicatedTest/scriptmodmenu.cpp38
-rw-r--r--NorthstarDedicatedTest/scriptserverbrowser.cpp146
-rw-r--r--NorthstarDedicatedTest/serverauthentication.cpp4
-rw-r--r--NorthstarDedicatedTest/serverauthentication.h1
-rw-r--r--NorthstarDedicatedTest/squirrel.h4
9 files changed, 137 insertions, 105 deletions
diff --git a/NorthstarDedicatedTest/masterserver.cpp b/NorthstarDedicatedTest/masterserver.cpp
index 3072b6b2..b3b14c8a 100644
--- a/NorthstarDedicatedTest/masterserver.cpp
+++ b/NorthstarDedicatedTest/masterserver.cpp
@@ -287,6 +287,13 @@ void MasterServerManager::AuthenticateWithOwnServer(char* uid, char* playerToken
REQUEST_END_CLEANUP:
m_authenticatingWithGameServer = false;
m_scriptAuthenticatingWithGameServer = false;
+
+ if (m_bNewgameAfterSelfAuth)
+ {
+ // pretty sure this is threadsafe?
+ Cbuf_AddText(Cbuf_GetCurrentPlayer(), "ns_end_reauth_and_leave_to_lobby", cmd_source_t::kCommandSrcCode);
+ m_bNewgameAfterSelfAuth = false;
+ }
});
requestThread.detach();
@@ -621,6 +628,7 @@ void CHostState__State_NewGameHook(CHostState* hostState)
g_ServerAuthenticationManager->StartPlayerAuthServer();
CHostState__State_NewGame(hostState);
+ g_ServerAuthenticationManager->m_bNeedLocalAuthForNewgame = false;
}
void CHostState__State_ChangeLevelMPHook(CHostState* hostState)
diff --git a/NorthstarDedicatedTest/masterserver.h b/NorthstarDedicatedTest/masterserver.h
index a2a6d1f2..d1033336 100644
--- a/NorthstarDedicatedTest/masterserver.h
+++ b/NorthstarDedicatedTest/masterserver.h
@@ -55,6 +55,7 @@ public:
bool m_scriptRequestingServerList = false;
bool m_successfullyConnected = true;
+ bool m_bNewgameAfterSelfAuth = false;
bool m_scriptAuthenticatingWithGameServer = false;
bool m_successfullyAuthenticatedWithGameServer = false;
diff --git a/NorthstarDedicatedTest/misccommands.cpp b/NorthstarDedicatedTest/misccommands.cpp
index c03ba713..27dbbbc4 100644
--- a/NorthstarDedicatedTest/misccommands.cpp
+++ b/NorthstarDedicatedTest/misccommands.cpp
@@ -2,6 +2,8 @@
#include "misccommands.h"
#include "concommand.h"
#include "gameutils.h"
+#include "masterserver.h"
+#include "serverauthentication.h"
void ForceLoadMapCommand(const CCommand& arg)
{
@@ -12,17 +14,29 @@ void ForceLoadMapCommand(const CCommand& arg)
strncpy(g_pHostState->m_levelName, arg.Arg(1), sizeof(g_pHostState->m_levelName));
}
-void LeaveToLobbyCommand(const CCommand& arg)
+void SelfAuthAndLeaveToLobbyCommand(const CCommand& arg)
{
- SetCurrentPlaylist("tdm");
+ // hack for special case where we're on a local server, so we erase our own newly created auth data on disconnect
- // note: for host, this will kick all clients, since it hits HS_GAME_SHUTDOWN
- g_pHostState->m_iNextState = HS_NEW_GAME;
+ g_MasterServerManager->m_bNewgameAfterSelfAuth = true;
+ g_MasterServerManager->AuthenticateWithOwnServer(g_LocalPlayerUserID, (char*)"");
+}
+
+void EndSelfAuthAndLeaveToLobbyCommand(const CCommand& arg)
+{
+ Cbuf_AddText(Cbuf_GetCurrentPlayer(), fmt::format("serverfilter {}", g_ServerAuthenticationManager->m_authData.begin()->first).c_str(), cmd_source_t::kCommandSrcCode);
+ Cbuf_Execute();
+
+ g_ServerAuthenticationManager->m_bNeedLocalAuthForNewgame = true;
+ SetCurrentPlaylist("tdm");
strcpy(g_pHostState->m_levelName, "mp_lobby");
+ g_pHostState->m_iNextState = HS_NEW_GAME;
}
void AddMiscConCommands()
{
RegisterConCommand("force_newgame", ForceLoadMapCommand, "forces a map load through directly setting g_pHostState->m_iNextState to HS_NEW_GAME", FCVAR_NONE);
- RegisterConCommand("ns_leave_to_lobby", LeaveToLobbyCommand, "called by the server, used to return the player to lobby when leaving a game", FCVAR_SERVER_CAN_EXECUTE);
+ RegisterConCommand("ns_start_reauth_and_leave_to_lobby", SelfAuthAndLeaveToLobbyCommand, "called by the server, used to reauth and return the player to lobby when leaving a game", FCVAR_SERVER_CAN_EXECUTE);
+ // this is a concommand because we make a deferred call to it from another thread
+ RegisterConCommand("ns_end_reauth_and_leave_to_lobby", EndSelfAuthAndLeaveToLobbyCommand, "", FCVAR_NONE);
} \ No newline at end of file
diff --git a/NorthstarDedicatedTest/miscserverscript.cpp b/NorthstarDedicatedTest/miscserverscript.cpp
index dd4c7101..bc4b43c0 100644
--- a/NorthstarDedicatedTest/miscserverscript.cpp
+++ b/NorthstarDedicatedTest/miscserverscript.cpp
@@ -19,7 +19,7 @@ void* GetPlayerByIndex(int playerIndex)
}
// void function NSEarlyWritePlayerIndexPersistenceForLeave( int playerIndex )
-SQInteger SQ_EarlyWritePlayerIndexPersistenceForLeave(void* sqvm)
+SQRESULT SQ_EarlyWritePlayerIndexPersistenceForLeave(void* sqvm)
{
int playerIndex = ServerSq_getinteger(sqvm, 1);
void* player = GetPlayerByIndex(playerIndex);
@@ -27,34 +27,34 @@ SQInteger SQ_EarlyWritePlayerIndexPersistenceForLeave(void* sqvm)
if (!g_ServerAuthenticationManager->m_additionalPlayerData.count(player))
{
ServerSq_pusherror(sqvm, fmt::format("Invalid playerindex {}", playerIndex).c_str());
- return -1;
+ return SQRESULT_ERROR;
}
g_ServerAuthenticationManager->m_additionalPlayerData[player].needPersistenceWriteOnLeave = false;
g_ServerAuthenticationManager->WritePersistentData(player);
- return 0;
+ return SQRESULT_NULL;
}
// bool function NSIsWritingPlayerPersistence()
-SQInteger SQ_IsWritingPlayerPersistence(void* sqvm)
+SQRESULT SQ_IsWritingPlayerPersistence(void* sqvm)
{
ServerSq_pushbool(sqvm, g_MasterServerManager->m_savingPersistentData);
- return 1;
+ return SQRESULT_NOTNULL;
}
// bool function NSIsPlayerIndexLocalPlayer( int playerIndex )
-SQInteger SQ_IsPlayerIndexLocalPlayer(void* sqvm)
+SQRESULT SQ_IsPlayerIndexLocalPlayer(void* sqvm)
{
int playerIndex = ServerSq_getinteger(sqvm, 1);
void* player = GetPlayerByIndex(playerIndex);
if (!g_ServerAuthenticationManager->m_additionalPlayerData.count(player))
{
ServerSq_pusherror(sqvm, fmt::format("Invalid playerindex {}", playerIndex).c_str());
- return -1;
+ return SQRESULT_ERROR;
}
ServerSq_pushbool(sqvm, !strcmp(g_LocalPlayerUserID, (char*)player + 0xF500));
- return 1;
+ return SQRESULT_NOTNULL;
}
void InitialiseMiscServerScriptCommand(HMODULE baseAddress)
diff --git a/NorthstarDedicatedTest/scriptmodmenu.cpp b/NorthstarDedicatedTest/scriptmodmenu.cpp
index c17b23db..88a5c773 100644
--- a/NorthstarDedicatedTest/scriptmodmenu.cpp
+++ b/NorthstarDedicatedTest/scriptmodmenu.cpp
@@ -15,7 +15,7 @@ SQInteger SQ_GetModNames(void* sqvm)
ClientSq_arrayappend(sqvm, -2);
}
- return 1;
+ return SQRESULT_NOTNULL;
}
// bool NSIsModEnabled(string modName)
@@ -29,11 +29,11 @@ SQInteger SQ_IsModEnabled(void* sqvm)
if (!mod->Name.compare(modName))
{
ClientSq_pushbool(sqvm, mod->Enabled);
- return 1;
+ return SQRESULT_NOTNULL;
}
}
- return 0; // return null
+ return SQRESULT_NULL;
}
// void NSSetModEnabled(string modName, bool enabled)
@@ -48,11 +48,11 @@ SQInteger SQ_SetModEnabled(void* sqvm)
if (!mod->Name.compare(modName))
{
mod->Enabled = enabled;
- return 0; // return null
+ return SQRESULT_NULL;
}
}
- return 0; // return null
+ return SQRESULT_NULL;
}
// string NSGetModDescriptionByModName(string modName)
@@ -66,11 +66,11 @@ SQInteger SQ_GetModDescription(void* sqvm)
if (!mod->Name.compare(modName))
{
ClientSq_pushstring(sqvm, mod->Description.c_str(), -1);
- return 1;
+ return SQRESULT_NOTNULL;
}
}
- return 0; // return null
+ return SQRESULT_NULL;
}
// string NSGetModVersionByModName(string modName)
@@ -84,11 +84,11 @@ SQInteger SQ_GetModVersion(void* sqvm)
if (!mod->Name.compare(modName))
{
ClientSq_pushstring(sqvm, mod->Version.c_str(), -1);
- return 1;
+ return SQRESULT_NOTNULL;
}
}
- return 0; // return null
+ return SQRESULT_NULL;
}
// string NSGetModDownloadLinkByModName(string modName)
@@ -102,11 +102,11 @@ SQInteger SQ_GetModDownloadLink(void* sqvm)
if (!mod->Name.compare(modName))
{
ClientSq_pushstring(sqvm, mod->DownloadLink.c_str(), -1);
- return 1;
+ return SQRESULT_NOTNULL;
}
}
- return 0; // return null
+ return SQRESULT_NULL;
}
// int NSGetModLoadPriority(string modName)
@@ -120,11 +120,11 @@ SQInteger SQ_GetModLoadPriority(void* sqvm)
if (!mod->Name.compare(modName))
{
ClientSq_pushinteger(sqvm, mod->LoadPriority);
- return 1;
+ return SQRESULT_NOTNULL;
}
}
- return 0; // return null
+ return SQRESULT_NULL;
}
// bool NSIsModRequiredOnClient(string modName)
@@ -138,11 +138,11 @@ SQInteger SQ_IsModRequiredOnClient(void* sqvm)
if (!mod->Name.compare(modName))
{
ClientSq_pushbool(sqvm, mod->RequiredOnClient);
- return 1;
+ return SQRESULT_NOTNULL;
}
}
- return 0; // return null
+ return SQRESULT_NULL;
}
// array<string> NSGetModConvarsByModName(string modName)
@@ -162,18 +162,18 @@ SQInteger SQ_GetModConvars(void* sqvm)
ClientSq_arrayappend(sqvm, -2);
}
- return 1;
+ return SQRESULT_NOTNULL;
}
}
- return 1; // return empty array
+ return SQRESULT_NOTNULL; // return empty array
}
// void NSReloadMods()
-SQInteger SQ_ReloadMods(void* sqvm)
+SQRESULT SQ_ReloadMods(void* sqvm)
{
g_ModManager->LoadMods();
- return 0;
+ return SQRESULT_NULL;
}
void InitialiseScriptModMenu(HMODULE baseAddress)
diff --git a/NorthstarDedicatedTest/scriptserverbrowser.cpp b/NorthstarDedicatedTest/scriptserverbrowser.cpp
index de2b3281..096e84df 100644
--- a/NorthstarDedicatedTest/scriptserverbrowser.cpp
+++ b/NorthstarDedicatedTest/scriptserverbrowser.cpp
@@ -9,61 +9,61 @@
// functions for viewing server browser
// void NSRequestServerList()
-SQInteger SQ_RequestServerList(void* sqvm)
+SQRESULT SQ_RequestServerList(void* sqvm)
{
g_MasterServerManager->RequestServerList();
- return 0;
+ return SQRESULT_NULL;
}
// bool function NSIsRequestingServerList()
-SQInteger SQ_IsRequestingServerList(void* sqvm)
+SQRESULT SQ_IsRequestingServerList(void* sqvm)
{
ClientSq_pushbool(sqvm, g_MasterServerManager->m_scriptRequestingServerList);
- return 1;
+ return SQRESULT_NOTNULL;
}
// bool function NSMasterServerConnectionSuccessful()
-SQInteger SQ_MasterServerConnectionSuccessful(void* sqvm)
+SQRESULT SQ_MasterServerConnectionSuccessful(void* sqvm)
{
ClientSq_pushbool(sqvm, g_MasterServerManager->m_successfullyConnected);
- return 1;
+ return SQRESULT_NOTNULL;
}
// int function NSGetServerCount()
-SQInteger SQ_GetServerCount(void* sqvm)
+SQRESULT SQ_GetServerCount(void* sqvm)
{
ClientSq_pushinteger(sqvm, g_MasterServerManager->m_remoteServers.size());
- return 1;
+ return SQRESULT_NOTNULL;
}
// string function NSGetServerName( int serverIndex )
-SQInteger SQ_GetServerName(void* sqvm)
+SQRESULT SQ_GetServerName(void* sqvm)
{
SQInteger serverIndex = ClientSq_getinteger(sqvm, 1);
if (serverIndex >= g_MasterServerManager->m_remoteServers.size())
{
- spdlog::warn("Tried to get name of server index {} when only {} servers are available", serverIndex, g_MasterServerManager->m_remoteServers.size());
- return 0;
+ ClientSq_pusherror(sqvm, fmt::format("Tried to get name of server index {} when only {} servers are available", serverIndex, g_MasterServerManager->m_remoteServers.size()).c_str());
+ return SQRESULT_ERROR;
}
ClientSq_pushstring(sqvm, g_MasterServerManager->m_remoteServers[serverIndex].name, -1);
- return 1;
+ return SQRESULT_NOTNULL;
}
// string function NSGetServerDescription( int serverIndex )
-SQInteger SQ_GetServerDescription(void* sqvm)
+SQRESULT SQ_GetServerDescription(void* sqvm)
{
SQInteger serverIndex = ClientSq_getinteger(sqvm, 1);
if (serverIndex >= g_MasterServerManager->m_remoteServers.size())
{
- spdlog::warn("Tried to get description of server index {} when only {} servers are available", serverIndex, g_MasterServerManager->m_remoteServers.size());
- return 0;
+ ClientSq_pusherror(sqvm, fmt::format("Tried to get description of server index {} when only {} servers are available", serverIndex, g_MasterServerManager->m_remoteServers.size()).c_str());
+ return SQRESULT_ERROR;
}
ClientSq_pushstring(sqvm, g_MasterServerManager->m_remoteServers[serverIndex].description.c_str(), -1);
- return 1;
+ return SQRESULT_NOTNULL;
}
// string function NSGetServerMap( int serverIndex )
@@ -73,168 +73,168 @@ SQInteger SQ_GetServerMap(void* sqvm)
if (serverIndex >= g_MasterServerManager->m_remoteServers.size())
{
- spdlog::warn("Tried to get map of server index {} when only {} servers are available", serverIndex, g_MasterServerManager->m_remoteServers.size());
- return 0;
+ ClientSq_pusherror(sqvm, fmt::format("Tried to get map of server index {} when only {} servers are available", serverIndex, g_MasterServerManager->m_remoteServers.size()).c_str());
+ return SQRESULT_ERROR;
}
ClientSq_pushstring(sqvm, g_MasterServerManager->m_remoteServers[serverIndex].map, -1);
- return 1;
+ return SQRESULT_NOTNULL;
}
// string function NSGetServerPlaylist( int serverIndex )
-SQInteger SQ_GetServerPlaylist(void* sqvm)
+SQRESULT SQ_GetServerPlaylist(void* sqvm)
{
SQInteger serverIndex = ClientSq_getinteger(sqvm, 1);
if (serverIndex >= g_MasterServerManager->m_remoteServers.size())
{
- spdlog::warn("Tried to get playlist of server index {} when only {} servers are available", serverIndex, g_MasterServerManager->m_remoteServers.size());
- return 0;
+ ClientSq_pusherror(sqvm, fmt::format("Tried to get playlist of server index {} when only {} servers are available", serverIndex, g_MasterServerManager->m_remoteServers.size()).c_str());
+ return SQRESULT_ERROR;
}
ClientSq_pushstring(sqvm, g_MasterServerManager->m_remoteServers[serverIndex].playlist, -1);
- return 1;
+ return SQRESULT_NOTNULL;
}
// int function NSGetServerPlayerCount( int serverIndex )
-SQInteger SQ_GetServerPlayerCount(void* sqvm)
+SQRESULT SQ_GetServerPlayerCount(void* sqvm)
{
SQInteger serverIndex = ClientSq_getinteger(sqvm, 1);
if (serverIndex >= g_MasterServerManager->m_remoteServers.size())
{
- spdlog::warn("Tried to get playercount of server index {} when only {} servers are available", serverIndex, g_MasterServerManager->m_remoteServers.size());
- return 0;
+ ClientSq_pusherror(sqvm, fmt::format("Tried to get playercount of server index {} when only {} servers are available", serverIndex, g_MasterServerManager->m_remoteServers.size()).c_str());
+ return SQRESULT_ERROR;
}
ClientSq_pushinteger(sqvm, g_MasterServerManager->m_remoteServers[serverIndex].playerCount);
- return 1;
+ return SQRESULT_NOTNULL;
}
// int function NSGetServerMaxPlayerCount( int serverIndex )
-SQInteger SQ_GetServerMaxPlayerCount(void* sqvm)
+SQRESULT SQ_GetServerMaxPlayerCount(void* sqvm)
{
SQInteger serverIndex = ClientSq_getinteger(sqvm, 1);
if (serverIndex >= g_MasterServerManager->m_remoteServers.size())
{
- spdlog::warn("Tried to get max playercount of server index {} when only {} servers are available", serverIndex, g_MasterServerManager->m_remoteServers.size());
- return 0;
+ ClientSq_pusherror(sqvm, fmt::format("Tried to get max playercount of server index {} when only {} servers are available", serverIndex, g_MasterServerManager->m_remoteServers.size()).c_str());
+ return SQRESULT_ERROR;
}
ClientSq_pushinteger(sqvm, g_MasterServerManager->m_remoteServers[serverIndex].maxPlayers);
- return 1;
+ return SQRESULT_NOTNULL;
}
// string function NSGetServerID( int serverIndex )
-SQInteger SQ_GetServerID(void* sqvm)
+SQRESULT SQ_GetServerID(void* sqvm)
{
SQInteger serverIndex = ClientSq_getinteger(sqvm, 1);
if (serverIndex >= g_MasterServerManager->m_remoteServers.size())
{
- spdlog::warn("Tried to get id of server index {} when only {} servers are available", serverIndex, g_MasterServerManager->m_remoteServers.size());
- return 0;
+ ClientSq_pusherror(sqvm, fmt::format("Tried to get id of server index {} when only {} servers are available", serverIndex, g_MasterServerManager->m_remoteServers.size()).c_str());
+ return SQRESULT_ERROR;
}
ClientSq_pushstring(sqvm, g_MasterServerManager->m_remoteServers[serverIndex].id, -1);
- return 1;
+ return SQRESULT_NOTNULL;
}
// bool function NSServerRequiresPassword( int serverIndex )
-SQInteger SQ_ServerRequiresPassword(void* sqvm)
+SQRESULT SQ_ServerRequiresPassword(void* sqvm)
{
SQInteger serverIndex = ClientSq_getinteger(sqvm, 1);
if (serverIndex >= g_MasterServerManager->m_remoteServers.size())
{
- spdlog::warn("Tried to get hasPassword of server index {} when only {} servers are available", serverIndex, g_MasterServerManager->m_remoteServers.size());
- return 0;
+ ClientSq_pusherror(sqvm, fmt::format("Tried to get hasPassword of server index {} when only {} servers are available", serverIndex, g_MasterServerManager->m_remoteServers.size()).c_str());
+ return SQRESULT_ERROR;
}
ClientSq_pushbool(sqvm, g_MasterServerManager->m_remoteServers[serverIndex].requiresPassword);
- return 1;
+ return SQRESULT_NOTNULL;
}
// int function NSGetServerRequiredModsCount( int serverIndex )
-SQInteger SQ_GetServerRequiredModsCount(void* sqvm)
+SQRESULT SQ_GetServerRequiredModsCount(void* sqvm)
{
SQInteger serverIndex = ClientSq_getinteger(sqvm, 1);
if (serverIndex >= g_MasterServerManager->m_remoteServers.size())
{
- spdlog::warn("Tried to get required mods count of server index {} when only {} servers are available", serverIndex, g_MasterServerManager->m_remoteServers.size());
- return 0;
+ ClientSq_pusherror(sqvm, fmt::format("Tried to get required mods count of server index {} when only {} servers are available", serverIndex, g_MasterServerManager->m_remoteServers.size()).c_str());
+ return SQRESULT_ERROR;
}
ClientSq_pushinteger(sqvm, g_MasterServerManager->m_remoteServers[serverIndex].requiredMods.size());
- return 1;
+ return SQRESULT_NOTNULL;
}
// string function NSGetServerRequiredModName( int serverIndex, int modIndex )
-SQInteger SQ_GetServerRequiredModName(void* sqvm)
+SQRESULT SQ_GetServerRequiredModName(void* sqvm)
{
SQInteger serverIndex = ClientSq_getinteger(sqvm, 1);
SQInteger modIndex = ClientSq_getinteger(sqvm, 2);
if (serverIndex >= g_MasterServerManager->m_remoteServers.size())
{
- spdlog::warn("Tried to get hasPassword of server index {} when only {} servers are available", serverIndex, g_MasterServerManager->m_remoteServers.size());
- return 0;
+ ClientSq_pusherror(sqvm, fmt::format("Tried to get hasPassword of server index {} when only {} servers are available", serverIndex, g_MasterServerManager->m_remoteServers.size()).c_str());
+ return SQRESULT_ERROR;
}
if (modIndex >= g_MasterServerManager->m_remoteServers[serverIndex].requiredMods.size())
{
- spdlog::warn("Tried to get required mod name of mod index {} when only {} mod are available", modIndex, g_MasterServerManager->m_remoteServers[serverIndex].requiredMods.size());
- return 0;
+ ClientSq_pusherror(sqvm, fmt::format("Tried to get required mod name of mod index {} when only {} mod are available", modIndex, g_MasterServerManager->m_remoteServers[serverIndex].requiredMods.size()).c_str());
+ return SQRESULT_ERROR;
}
ClientSq_pushstring(sqvm, g_MasterServerManager->m_remoteServers[serverIndex].requiredMods[modIndex].Name.c_str(), -1);
- return 1;
+ return SQRESULT_NOTNULL;
}
// string function NSGetServerRequiredModVersion( int serverIndex, int modIndex )
-SQInteger SQ_GetServerRequiredModVersion(void* sqvm)
+SQRESULT SQ_GetServerRequiredModVersion(void* sqvm)
{
SQInteger serverIndex = ClientSq_getinteger(sqvm, 1);
SQInteger modIndex = ClientSq_getinteger(sqvm, 2);
if (serverIndex >= g_MasterServerManager->m_remoteServers.size())
{
- spdlog::warn("Tried to get required mod version of server index {} when only {} servers are available", serverIndex, g_MasterServerManager->m_remoteServers.size());
- return 0;
+ ClientSq_pusherror(sqvm, fmt::format("Tried to get required mod version of server index {} when only {} servers are available", serverIndex, g_MasterServerManager->m_remoteServers.size()).c_str());
+ return SQRESULT_ERROR;
}
if (modIndex >= g_MasterServerManager->m_remoteServers[serverIndex].requiredMods.size())
{
- spdlog::warn("Tried to get required mod version of mod index {} when only {} mod are available", modIndex, g_MasterServerManager->m_remoteServers[serverIndex].requiredMods.size());
- return 0;
+ ClientSq_pusherror(sqvm, fmt::format("Tried to get required mod version of mod index {} when only {} mod are available", modIndex, g_MasterServerManager->m_remoteServers[serverIndex].requiredMods.size()).c_str());
+ return SQRESULT_ERROR;
}
ClientSq_pushstring(sqvm, g_MasterServerManager->m_remoteServers[serverIndex].requiredMods[modIndex].Version.c_str(), -1);
- return 1;
+ return SQRESULT_NOTNULL;
}
// void function NSClearRecievedServerList()
-SQInteger SQ_ClearRecievedServerList(void* sqvm)
+SQRESULT SQ_ClearRecievedServerList(void* sqvm)
{
g_MasterServerManager->ClearServerList();
- return 0;
+ return SQRESULT_NULL;
}
// functions for authenticating with servers
// void function NSTryAuthWithServer( int serverIndex, string password = "" )
-SQInteger SQ_TryAuthWithServer(void* sqvm)
+SQRESULT SQ_TryAuthWithServer(void* sqvm)
{
SQInteger serverIndex = ClientSq_getinteger(sqvm, 1);
const SQChar* password = ClientSq_getstring(sqvm, 2);
if (serverIndex >= g_MasterServerManager->m_remoteServers.size())
{
- spdlog::warn("Tried to auth with server index {} when only {} servers are available", serverIndex, g_MasterServerManager->m_remoteServers.size());
- return 0;
+ ClientSq_pusherror(sqvm, fmt::format("Tried to auth with server index {} when only {} servers are available", serverIndex, g_MasterServerManager->m_remoteServers.size()).c_str());
+ return SQRESULT_ERROR;
}
// send off persistent data first, don't worry about server/client stuff, since m_additionalPlayerData should only have entries when we're a local server
@@ -245,30 +245,30 @@ SQInteger SQ_TryAuthWithServer(void* sqvm)
// do auth
g_MasterServerManager->AuthenticateWithServer(g_LocalPlayerUserID, (char*)"", g_MasterServerManager->m_remoteServers[serverIndex].id, (char*)password);
- return 0;
+ return SQRESULT_NULL;
}
// bool function NSIsAuthenticatingWithServer()
-SQInteger SQ_IsAuthComplete(void* sqvm)
+SQRESULT SQ_IsAuthComplete(void* sqvm)
{
ClientSq_pushbool(sqvm, g_MasterServerManager->m_scriptAuthenticatingWithGameServer);
- return 1;
+ return SQRESULT_NOTNULL;
}
// bool function NSWasAuthSuccessful()
-SQInteger SQ_WasAuthSuccessful(void* sqvm)
+SQRESULT SQ_WasAuthSuccessful(void* sqvm)
{
ClientSq_pushbool(sqvm, g_MasterServerManager->m_successfullyAuthenticatedWithGameServer);
- return 1;
+ return SQRESULT_NOTNULL;
}
// void function NSConnectToAuthedServer()
-SQInteger SQ_ConnectToAuthedServer(void* sqvm)
+SQRESULT SQ_ConnectToAuthedServer(void* sqvm)
{
if (!g_MasterServerManager->m_hasPendingConnectionInfo)
{
- spdlog::error("Tried to connect to authed server before any pending connection info was available");
- return 0;
+ ClientSq_pusherror(sqvm, fmt::format("Tried to connect to authed server before any pending connection info was available").c_str());
+ return SQRESULT_ERROR;
}
RemoteServerConnectionInfo info = g_MasterServerManager->m_pendingConnectionInfo;
@@ -279,26 +279,26 @@ SQInteger SQ_ConnectToAuthedServer(void* sqvm)
Cbuf_AddText(Cbuf_GetCurrentPlayer(), fmt::format("connect {}.{}.{}.{}:{}", info.ip.S_un.S_un_b.s_b1, info.ip.S_un.S_un_b.s_b2, info.ip.S_un.S_un_b.s_b3, info.ip.S_un.S_un_b.s_b4, info.port).c_str(), cmd_source_t::kCommandSrcCode);
g_MasterServerManager->m_hasPendingConnectionInfo = false;
- return 0;
+ return SQRESULT_NULL;
}
// void function NSTryAuthWithLocalServer()
-SQInteger SQ_TryAuthWithLocalServer(void* sqvm)
+SQRESULT SQ_TryAuthWithLocalServer(void* sqvm)
{
// do auth request
g_MasterServerManager->AuthenticateWithOwnServer(g_LocalPlayerUserID, (char*)"");
- return 0;
+ return SQRESULT_NULL;
}
// void function NSCompleteAuthWithLocalServer()
-SQInteger SQ_CompleteAuthWithLocalServer(void* sqvm)
+SQRESULT SQ_CompleteAuthWithLocalServer(void* sqvm)
{
// literally just set serverfilter
// note: this assumes we have no authdata other than our own
Cbuf_AddText(Cbuf_GetCurrentPlayer(), fmt::format("serverfilter {}", g_ServerAuthenticationManager->m_authData.begin()->first).c_str(), cmd_source_t::kCommandSrcCode);
- return 0;
+ return SQRESULT_NULL;
}
void InitialiseScriptServerBrowser(HMODULE baseAddress)
diff --git a/NorthstarDedicatedTest/serverauthentication.cpp b/NorthstarDedicatedTest/serverauthentication.cpp
index d7fb1542..52e376f6 100644
--- a/NorthstarDedicatedTest/serverauthentication.cpp
+++ b/NorthstarDedicatedTest/serverauthentication.cpp
@@ -159,6 +159,10 @@ bool ServerAuthenticationManager::RemovePlayerAuthData(void* player)
if (!Cvar_ns_erase_auth_info->m_nValue)
return false;
+ // hack for special case where we're on a local server, so we erase our own newly created auth data on disconnect
+ if (m_bNeedLocalAuthForNewgame && !strcmp((char*)player + 0xF500, g_LocalPlayerUserID))
+ return false;
+
// we don't have our auth token at this point, so lookup authdata by uid
for (auto& auth : m_authData)
{
diff --git a/NorthstarDedicatedTest/serverauthentication.h b/NorthstarDedicatedTest/serverauthentication.h
index c0f4bea2..7979d2fe 100644
--- a/NorthstarDedicatedTest/serverauthentication.h
+++ b/NorthstarDedicatedTest/serverauthentication.h
@@ -33,6 +33,7 @@ public:
std::unordered_map<std::string, AuthData> m_authData;
std::unordered_map<void*, AdditionalPlayerData> m_additionalPlayerData;
bool m_runningPlayerAuthThread = false;
+ bool m_bNeedLocalAuthForNewgame = false;
public:
void StartPlayerAuthServer();
diff --git a/NorthstarDedicatedTest/squirrel.h b/NorthstarDedicatedTest/squirrel.h
index 03622f5d..50b4a19e 100644
--- a/NorthstarDedicatedTest/squirrel.h
+++ b/NorthstarDedicatedTest/squirrel.h
@@ -12,6 +12,10 @@ typedef char SQChar;
typedef SQUnsignedInteger SQBool;
typedef SQInteger SQRESULT;
+const SQRESULT SQRESULT_ERROR = -1;
+const SQRESULT SQRESULT_NULL = 0;
+const SQRESULT SQRESULT_NOTNULL = 1;
+
typedef SQInteger(*SQFunction)(void* sqvm);
struct CompileBufferState