Add callback for registering script constants, and added 'LISTEN_SERVER'

All listen server code should be compiled out of the scripts using 'LISTEN_SERVER'. The constant must have a non-null value.
This commit is contained in:
Kawe Mazidjatari 2023-07-19 18:52:00 +02:00
parent 80fecd2cb0
commit a0f0b79266
5 changed files with 51 additions and 20 deletions

View File

@ -149,6 +149,31 @@
//
/////////////////////////////////////////////////////////////////////////////////////////////////
#ifdef DEDICATED
// These command line parameters disable a bunch of things in the engine that
// the dedicated server does not need, therefore, reducing a lot of overhead.
void InitCommandLineParameters()
{
CommandLine()->AppendParm("-collate", "");
CommandLine()->AppendParm("-multiple", "");
CommandLine()->AppendParm("-noorigin", "");
CommandLine()->AppendParm("-nodiscord", "");
CommandLine()->AppendParm("-noshaderapi", "");
CommandLine()->AppendParm("-nobakedparticles", "");
CommandLine()->AppendParm("-novid", "");
CommandLine()->AppendParm("-nomenuvid", "");
CommandLine()->AppendParm("-nosound", "");
CommandLine()->AppendParm("-nomouse", "");
CommandLine()->AppendParm("-nojoy", "");
CommandLine()->AppendParm("-nosendtable", "");
}
#endif // DEDICATED
void ScriptConstantRegistrationCallback(CSquirrelVM* s)
{
Script_RegisterListenServerConstants(s);
}
void Systems_Init()
{
DevMsg(eDLL_T::NONE, "+-------------------------------------------------------------+\n");
@ -197,23 +222,12 @@ void Systems_Init()
ConVar_StaticInit();
#ifdef DEDICATED
// These command line parameters disable a bunch of things in the engine that
// the dedicated server does not need, therefore, reducing a lot of overhead.
CommandLine()->AppendParm("-collate", "");
CommandLine()->AppendParm("-multiple", "");
CommandLine()->AppendParm("-noorigin", "");
CommandLine()->AppendParm("-nodiscord", "");
CommandLine()->AppendParm("-noshaderapi", "");
CommandLine()->AppendParm("-nobakedparticles", "");
CommandLine()->AppendParm("-novid", "");
CommandLine()->AppendParm("-nomenuvid", "");
CommandLine()->AppendParm("-nosound", "");
CommandLine()->AppendParm("-nomouse", "");
CommandLine()->AppendParm("-nojoy", "");
CommandLine()->AppendParm("-nosendtable", "");
InitCommandLineParameters();
#endif // DEDICATED
// Script context registration callbacks.
ScriptConstantRegister_Callback = ScriptConstantRegistrationCallback;
#ifndef CLIENT_DLL
ServerScriptRegister_Callback = Script_RegisterServerFunctions;
CoreServerScriptRegister_Callback = Script_RegisterCoreServerFunctions;

View File

@ -13,14 +13,10 @@
#include "core/stdafx.h"
#include "vpc/keyvalues.h"
#include "engine/server/server.h"
#include "engine/client/cl_main.h"
#include "engine/cmodel_bsp.h"
#include "engine/host_state.h"
#include "networksystem/pylon.h"
#include "networksystem/bansystem.h"
#include "networksystem/listmanager.h"
#include "vscript_shared.h"
#include "vscript/languages/squirrel_re/include/sqvm.h"
#include "vscript_shared.h"
namespace VScriptCode
{
@ -88,3 +84,13 @@ void Script_RegisterCommonAbstractions(CSquirrelVM* s)
DEFINE_SHARED_SCRIPTFUNC_NAMED(s, GetAvailableMaps, "Gets an array of all available maps", "array< string >", "");
DEFINE_SHARED_SCRIPTFUNC_NAMED(s, GetAvailablePlaylists, "Gets an array of all available playlists", "array< string >", "");
}
//---------------------------------------------------------------------------------
// Purpose: listen server constants (!!! only call on builds containing a listen server !!!)
// Input : *s -
//---------------------------------------------------------------------------------
void Script_RegisterListenServerConstants(CSquirrelVM* s)
{
const SQBool hasListenServer = !IsClientDLL();
s->RegisterConstant("LISTEN_SERVER", hasListenServer);
}

View File

@ -23,6 +23,7 @@ namespace VScriptCode
}
void Script_RegisterCommonAbstractions(CSquirrelVM* s);
void Script_RegisterListenServerConstants(CSquirrelVM* s);
#define DEFINE_SHARED_SCRIPTFUNC_NAMED(s, functionName, helpString, \
returnType, parameters) \

View File

@ -17,6 +17,9 @@ void(*UiScriptRegister_Callback)(CSquirrelVM* s) = nullptr;
void(*CoreServerScriptRegister_Callback)(CSquirrelVM* s) = nullptr;
void(*AdminPanelScriptRegister_Callback)(CSquirrelVM* s) = nullptr;
// Registering constants in scripts.
void(*ScriptConstantRegister_Callback)(CSquirrelVM* s) = nullptr;
//---------------------------------------------------------------------------------
// Purpose: Initialises a Squirrel VM instance
// Output : True on success, false on failure
@ -75,6 +78,11 @@ SQBool CSquirrelVM::DestroySignalEntryListHead(CSquirrelVM* s, HSQUIRRELVM v, SQ
{
SQBool result = v_CSquirrelVM_DestroySignalEntryListHead(s, v, f);
s->RegisterConstant("DEVELOPER", developer->GetInt());
// Must have one.
Assert(ScriptConstantRegister_Callback);
ScriptConstantRegister_Callback(s);
return result;
}

View File

@ -50,6 +50,8 @@ extern void(*UiScriptRegister_Callback)(CSquirrelVM* s);
extern void(*CoreServerScriptRegister_Callback)(CSquirrelVM* s);
extern void(*AdminPanelScriptRegister_Callback)(CSquirrelVM* s);
extern void(*ScriptConstantRegister_Callback)(CSquirrelVM* s);
inline CMemory p_CSquirrelVM_Init;
inline bool(*v_CSquirrelVM_Init)(CSquirrelVM* s, SQCONTEXT context, SQFloat curtime);