2021-12-25 22:36:38 +01:00
//=============================================================================//
//
2022-01-16 00:35:39 +01:00
// Purpose: Expose native code to VScript API
//
//-----------------------------------------------------------------------------
//
// Create functions here under the target VM namespace. If the function has to
// be registered for 2 or more VM's, put them under the 'SHARED' namespace.
2023-07-18 00:17:49 +02:00
// Ifdef them out for 'SERVER_DLL' / 'CLIENT_DLL' if the target VM's do not
2022-03-28 12:02:11 +02:00
// include 'SERVER' / 'CLIENT'.
2021-12-25 22:36:38 +01:00
//
//=============================================================================//
# include "core/stdafx.h"
2022-05-29 02:08:07 +02:00
# include "vpc/keyvalues.h"
2022-05-20 11:52:19 +02:00
# include "engine/server/server.h"
2022-05-27 02:08:51 +02:00
# include "engine/cmodel_bsp.h"
2022-05-28 17:27:52 +02:00
# include "engine/host_state.h"
2022-07-01 10:29:27 +02:00
# include "networksystem/pylon.h"
2022-09-15 23:13:37 +02:00
# include "networksystem/bansystem.h"
2022-08-14 15:43:49 +02:00
# include "networksystem/listmanager.h"
2023-05-06 16:23:56 +02:00
# include "vscript_shared.h"
# include "vscript/languages/squirrel_re/include/sqvm.h"
2022-01-16 00:35:39 +01:00
2023-05-06 16:23:56 +02:00
namespace VScriptCode
2022-01-16 00:35:39 +01:00
{
2023-07-18 21:05:29 +02:00
namespace Shared
2022-01-16 00:35:39 +01:00
{
2022-03-28 19:34:51 +02:00
//-----------------------------------------------------------------------------
// Purpose: expose SDK version to the VScript API
//-----------------------------------------------------------------------------
2022-03-30 22:54:33 +02:00
SQRESULT GetSDKVersion ( HSQUIRRELVM v )
2022-03-28 19:34:51 +02:00
{
2022-07-01 02:20:47 +02:00
sq_pushstring ( v , SDK_VERSION , - 1 ) ;
2022-03-28 19:34:51 +02:00
return SQ_OK ;
}
2022-05-27 02:08:51 +02:00
//-----------------------------------------------------------------------------
// Purpose: return all available maps
//-----------------------------------------------------------------------------
SQRESULT GetAvailableMaps ( HSQUIRRELVM v )
{
2023-03-31 00:35:01 +02:00
std : : lock_guard < std : : mutex > l ( g_InstalledMapsMutex ) ;
2022-08-29 11:55:58 +02:00
2023-03-31 00:35:01 +02:00
if ( g_InstalledMaps . empty ( ) )
2022-05-27 02:08:51 +02:00
return SQ_OK ;
sq_newarray ( v , 0 ) ;
2023-03-31 00:35:01 +02:00
for ( const string & it : g_InstalledMaps )
2022-05-27 02:08:51 +02:00
{
sq_pushstring ( v , it . c_str ( ) , - 1 ) ;
sq_arrayappend ( v , - 2 ) ;
}
return SQ_OK ;
}
//-----------------------------------------------------------------------------
// Purpose: return all available playlists
//-----------------------------------------------------------------------------
SQRESULT GetAvailablePlaylists ( HSQUIRRELVM v )
{
2022-08-29 11:55:58 +02:00
std : : lock_guard < std : : mutex > l ( g_PlaylistsVecMutex ) ;
2022-05-27 02:08:51 +02:00
if ( g_vAllPlaylists . empty ( ) )
return SQ_OK ;
sq_newarray ( v , 0 ) ;
2022-07-01 23:33:47 +02:00
for ( const string & it : g_vAllPlaylists )
2022-05-27 02:08:51 +02:00
{
sq_pushstring ( v , it . c_str ( ) , - 1 ) ;
sq_arrayappend ( v , - 2 ) ;
}
return SQ_OK ;
}
2023-07-19 02:12:56 +02:00
}
}
2022-09-16 01:40:17 +02:00
2023-07-19 02:12:56 +02:00
//---------------------------------------------------------------------------------
// Purpose: common script abstractions
// Input : *s -
//---------------------------------------------------------------------------------
void Script_RegisterCommonAbstractions ( CSquirrelVM * s )
{
s - > RegisterFunction ( " GetSDKVersion " , " Script_GetSDKVersion " , " Gets the SDK version as a string " , " string " , " " , & VScriptCode : : Shared : : GetSDKVersion ) ;
2023-07-18 00:17:49 +02:00
2023-07-19 02:12:56 +02:00
s - > RegisterFunction ( " GetAvailableMaps " , " Script_GetAvailableMaps " , " Gets an array of all available maps " , " array< string > " , " " , & VScriptCode : : Shared : : GetAvailableMaps ) ;
s - > RegisterFunction ( " GetAvailablePlaylists " , " Script_GetAvailablePlaylists " , " Gets an array of all available playlists " , " array< string > " , " " , & VScriptCode : : Shared : : GetAvailablePlaylists ) ;
2023-07-18 00:17:49 +02:00
}