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 20:14:39 +02:00
|
|
|
#ifndef CLIENT_DLL
|
2022-05-20 11:52:19 +02:00
|
|
|
#include "engine/server/server.h"
|
2022-05-20 20:14:39 +02:00
|
|
|
#endif // CLIENT_DLL
|
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
|
|
|
#ifndef CLIENT_DLL
|
|
|
|
#include "networksystem/bansystem.h"
|
|
|
|
#endif // !CLIENT_DLL
|
2023-07-18 00:17:49 +02:00
|
|
|
#ifndef SERVER_DLL
|
2022-08-14 15:43:49 +02:00
|
|
|
#include "networksystem/listmanager.h"
|
2023-07-18 00:17:49 +02:00
|
|
|
#endif // !SERVER_DLL
|
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: SDK test and example body
|
|
|
|
//-----------------------------------------------------------------------------
|
2022-03-30 22:54:33 +02:00
|
|
|
SQRESULT SDKNativeTest(HSQUIRRELVM v)
|
2022-01-16 00:35:39 +01:00
|
|
|
{
|
|
|
|
// Function code goes here.
|
|
|
|
return SQ_OK;
|
|
|
|
}
|
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-05-01 01:59:24 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: checks whether the server is active
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
SQRESULT IsServerActive(HSQUIRRELVM v)
|
|
|
|
{
|
|
|
|
bool isActive = false;
|
2022-03-28 12:02:11 +02:00
|
|
|
#ifndef CLIENT_DLL
|
2023-05-01 01:59:24 +02:00
|
|
|
isActive = g_pServer->IsActive();
|
|
|
|
#endif // !CLIENT_DLL
|
|
|
|
|
|
|
|
sq_pushbool(v, isActive);
|
|
|
|
return SQ_OK;
|
|
|
|
}
|
|
|
|
#ifndef CLIENT_DLL
|
|
|
|
|
2022-09-15 23:13:37 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: kicks a player by given name
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
SQRESULT KickPlayerByName(HSQUIRRELVM v)
|
|
|
|
{
|
2023-03-25 17:54:05 +01:00
|
|
|
SQChar* playerName = sq_getstring(v, 1);
|
2023-06-20 08:44:03 +02:00
|
|
|
SQChar* reason = sq_getstring(v, 2);
|
|
|
|
|
|
|
|
// Discard empty strings, this will use the default message instead.
|
|
|
|
if (!VALID_CHARSTAR(reason))
|
|
|
|
reason = nullptr;
|
|
|
|
|
|
|
|
g_pBanSystem->KickPlayerByName(playerName, reason);
|
2022-09-15 23:13:37 +02:00
|
|
|
|
|
|
|
return SQ_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: kicks a player by given handle or id
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
SQRESULT KickPlayerById(HSQUIRRELVM v)
|
|
|
|
{
|
2023-03-25 17:54:05 +01:00
|
|
|
SQChar* playerHandle = sq_getstring(v, 1);
|
2023-06-20 08:44:03 +02:00
|
|
|
SQChar* reason = sq_getstring(v, 2);
|
|
|
|
|
|
|
|
// Discard empty strings, this will use the default message instead.
|
|
|
|
if (!VALID_CHARSTAR(reason))
|
|
|
|
reason = nullptr;
|
|
|
|
|
|
|
|
g_pBanSystem->KickPlayerById(playerHandle, reason);
|
2022-09-15 23:13:37 +02:00
|
|
|
|
|
|
|
return SQ_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: bans a player by given name
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
SQRESULT BanPlayerByName(HSQUIRRELVM v)
|
|
|
|
{
|
2023-03-25 17:54:05 +01:00
|
|
|
SQChar* playerName = sq_getstring(v, 1);
|
2023-06-20 08:44:03 +02:00
|
|
|
SQChar* reason = sq_getstring(v, 2);
|
|
|
|
|
|
|
|
// Discard empty strings, this will use the default message instead.
|
|
|
|
if (!VALID_CHARSTAR(reason))
|
|
|
|
reason = nullptr;
|
|
|
|
|
|
|
|
g_pBanSystem->BanPlayerByName(playerName, reason);
|
2022-09-15 23:13:37 +02:00
|
|
|
|
|
|
|
return SQ_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: bans a player by given handle or id
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
SQRESULT BanPlayerById(HSQUIRRELVM v)
|
|
|
|
{
|
2023-03-25 17:54:05 +01:00
|
|
|
SQChar* playerHandle = sq_getstring(v, 1);
|
2023-06-20 08:44:03 +02:00
|
|
|
SQChar* reason = sq_getstring(v, 2);
|
|
|
|
|
|
|
|
// Discard empty strings, this will use the default message instead.
|
|
|
|
if (!VALID_CHARSTAR(reason))
|
|
|
|
reason = nullptr;
|
|
|
|
|
|
|
|
g_pBanSystem->BanPlayerById(playerHandle, reason);
|
2022-09-16 00:51:35 +02:00
|
|
|
|
|
|
|
return SQ_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: unbans a player by given nucleus id or ip address
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
SQRESULT UnbanPlayer(HSQUIRRELVM v)
|
|
|
|
{
|
|
|
|
SQChar* szCriteria = sq_getstring(v, 1);
|
|
|
|
g_pBanSystem->UnbanPlayer(szCriteria);
|
2022-09-15 23:13:37 +02:00
|
|
|
|
2022-09-16 01:40:17 +02:00
|
|
|
return SQ_OK;
|
|
|
|
}
|
|
|
|
#endif // !CLIENT_DLL
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: shutdown local game (host only)
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
SQRESULT ShutdownHostGame(HSQUIRRELVM v)
|
|
|
|
{
|
|
|
|
if (g_pHostState->m_bActiveGame)
|
|
|
|
g_pHostState->m_iNextState = HostStates_t::HS_GAME_SHUTDOWN;
|
|
|
|
|
|
|
|
return SQ_OK;
|
|
|
|
}
|
2023-07-18 00:17:49 +02:00
|
|
|
|
2023-01-31 22:26:29 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// 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;
|
|
|
|
}
|
2022-09-16 01:40:17 +02:00
|
|
|
}
|
2023-07-18 00:17:49 +02:00
|
|
|
}
|