From 419bf12e068bdc52e4111206a5db9dad9b4048f9 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Tue, 31 Jan 2023 22:26:29 +0100 Subject: [PATCH] Add abstracted functions to determine build type Allow scripters to determine whether or not this is a dedicated server or client only build. Note that these should not be abused in scripts! Since the client dll doesn't support running games locally, loading up the lobby isn't going to work when you leave a match (which is the current implementation in the scripts). with this, the scripter could do other things such as loading the title screen, or connecting to a remote lobby server if this happens to be a client only build. --- r5dev/squirrel/sqinit.cpp | 24 ++++++++++++++++++++++++ r5dev/squirrel/sqinit.h | 4 ++++ r5dev/squirrel/sqscript.cpp | 3 +++ 3 files changed, 31 insertions(+) diff --git a/r5dev/squirrel/sqinit.cpp b/r5dev/squirrel/sqinit.cpp index 4ef04926..d8014806 100644 --- a/r5dev/squirrel/sqinit.cpp +++ b/r5dev/squirrel/sqinit.cpp @@ -156,6 +156,21 @@ namespace VSquirrel return SQ_OK; } +#ifndef DEDICATED + //----------------------------------------------------------------------------- + // Purpose: checks whether this SDK build is a client dll + //----------------------------------------------------------------------------- + SQRESULT IsClientDLL(HSQUIRRELVM v) + { +#ifdef CLIENT_DLL + constexpr SQBool bClientOnly = true; +#else + constexpr SQBool bClientOnly = false; +#endif + sq_pushbool(v, bClientOnly); + return SQ_OK; + } +#endif // !DEDICATED } #ifndef CLIENT_DLL namespace SERVER @@ -177,6 +192,15 @@ namespace VSquirrel sq_pushinteger(v, g_pServer->GetNumFakeClients()); return SQ_OK; } + + //----------------------------------------------------------------------------- + // Purpose: checks whether this SDK build is a dedicated server + //----------------------------------------------------------------------------- + SQRESULT IsDedicated(HSQUIRRELVM v) + { + sq_pushbool(v, *s_bDedicated); + return SQ_OK; + } } #endif // !CLIENT_DLL #ifndef DEDICATED diff --git a/r5dev/squirrel/sqinit.h b/r5dev/squirrel/sqinit.h index 4577cca5..4e2cff07 100644 --- a/r5dev/squirrel/sqinit.h +++ b/r5dev/squirrel/sqinit.h @@ -23,6 +23,9 @@ namespace VSquirrel SQRESULT GetAvailableMaps(HSQUIRRELVM v); SQRESULT GetAvailablePlaylists(HSQUIRRELVM v); SQRESULT ShutdownHostGame(HSQUIRRELVM v); +#ifndef DEDICATED + SQRESULT IsClientDLL(HSQUIRRELVM v); +#endif // !DEDICATED #ifndef CLIENT_DLL SQRESULT KickPlayerByName(HSQUIRRELVM v); SQRESULT KickPlayerById(HSQUIRRELVM v); @@ -36,6 +39,7 @@ namespace VSquirrel { SQRESULT GetNumHumanPlayers(HSQUIRRELVM v); SQRESULT GetNumFakeClients(HSQUIRRELVM v); + SQRESULT IsDedicated(HSQUIRRELVM v); } #endif // !CLIENT_DLL #ifndef DEDICATED diff --git a/r5dev/squirrel/sqscript.cpp b/r5dev/squirrel/sqscript.cpp index 86f66bed..9321f702 100644 --- a/r5dev/squirrel/sqscript.cpp +++ b/r5dev/squirrel/sqscript.cpp @@ -76,6 +76,8 @@ void Script_RegisterServerFunctions(CSquirrelVM* s) Script_RegisterFunction(s, "UnbanPlayer", "Script_UnbanPlayer", "Unbans a player from the server by nucleus id or ip address", "void", "string", &VSquirrel::SHARED::UnbanPlayer); Script_RegisterFunction(s, "ShutdownHostGame", "Script_ShutdownHostGame", "Shuts the local host game down", "void", "", &VSquirrel::SHARED::ShutdownHostGame); + + Script_RegisterFunction(s, "IsDedicated", "Script_IsDedicated", "Returns whether this is a dedicated server", "bool", "", &VSquirrel::SERVER::IsDedicated); } #endif // !CLIENT_DLL @@ -137,6 +139,7 @@ void Script_RegisterUIFunctions(CSquirrelVM* s) Script_RegisterFunction(s, "UnbanPlayer", "Script_UnbanPlayer", "Unbans a player from the server by nucleus id or ip address", "void", "string", &VSquirrel::SHARED::UnbanPlayer); #endif // !CLIENT_DLL Script_RegisterFunction(s, "ShutdownHostGame", "Script_ShutdownHostGame", "Shuts the local host game down", "void", "", &VSquirrel::SHARED::ShutdownHostGame); + Script_RegisterFunction(s, "IsClientDLL", "Script_IsClientDLL", "Returns whether this build is client only", "bool", "", &VSquirrel::SHARED::IsClientDLL); } //---------------------------------------------------------------------------------