2016-05-22 05:20:38 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-09-30 02:56:11 +02:00
|
|
|
#include "Logger.hpp"
|
|
|
|
#include "Core.hpp"
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-05-22 05:20:38 +02:00
|
|
|
#include <cstdio>
|
2015-10-30 03:17:18 +01:00
|
|
|
|
2019-02-17 16:23:59 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
#ifdef SQMOD_OS_WINDOWS
|
2021-01-30 07:51:39 +01:00
|
|
|
#include <winsock2.h>
|
2019-02-17 16:23:59 +01:00
|
|
|
#endif // SQMOD_OS_WINDOWS
|
|
|
|
|
2023-08-05 20:31:33 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
#include <curl/curl.h>
|
|
|
|
#include <civetweb.h>
|
|
|
|
|
2016-02-23 16:48:30 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
namespace SqMod {
|
2016-03-24 08:32:44 +01:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-05-24 18:26:43 +02:00
|
|
|
static bool g_Reload = false;
|
2016-03-24 08:32:44 +01:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2023-03-05 14:38:59 +01:00
|
|
|
extern void InitExports();
|
2021-09-07 19:55:05 +02:00
|
|
|
extern void InitializeNet();
|
2021-01-30 23:16:10 +01:00
|
|
|
extern void InitializePocoDataConnectors();
|
2016-05-23 02:54:50 +02:00
|
|
|
extern void ProcessRoutines();
|
2021-03-27 23:19:09 +01:00
|
|
|
extern void ProcessTasks();
|
|
|
|
extern void ProcessThreads();
|
2021-09-07 19:55:05 +02:00
|
|
|
extern void ProcessNet();
|
2023-08-05 20:31:33 +02:00
|
|
|
#ifdef SQMOD_DISCORD
|
|
|
|
extern void ProcessDiscord();
|
|
|
|
#endif
|
2016-03-24 08:32:44 +01:00
|
|
|
|
2016-05-22 05:20:38 +02:00
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
|
|
* Will the scripts be reloaded at the end of the current event?
|
|
|
|
*/
|
2016-05-24 18:26:43 +02:00
|
|
|
bool GetReloadStatus()
|
2016-03-24 08:32:44 +01:00
|
|
|
{
|
|
|
|
return g_Reload;
|
|
|
|
}
|
|
|
|
|
2016-05-22 05:20:38 +02:00
|
|
|
/* ------------------------------------------------------------------------------------------------
|
2016-05-24 18:26:43 +02:00
|
|
|
* Toggles the reload status.
|
2016-05-22 05:20:38 +02:00
|
|
|
*/
|
2016-05-24 18:26:43 +02:00
|
|
|
void SetReloadStatus(bool toggle)
|
2016-05-22 05:20:38 +02:00
|
|
|
{
|
2016-05-24 18:26:43 +02:00
|
|
|
g_Reload = toggle;
|
2016-05-22 05:20:38 +02:00
|
|
|
}
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
|
|
* Helper class to make sure that the reload is disabled and the payload is released.
|
|
|
|
*/
|
|
|
|
struct ReloadGuard
|
|
|
|
{
|
|
|
|
~ReloadGuard()
|
|
|
|
{
|
2016-05-24 18:26:43 +02:00
|
|
|
g_Reload = false;
|
2016-05-22 05:20:38 +02:00
|
|
|
}
|
|
|
|
};
|
2015-09-30 02:56:11 +02:00
|
|
|
|
2016-05-22 05:20:38 +02:00
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
|
|
* Perform the actual reload.
|
|
|
|
*/
|
2016-03-24 08:32:44 +01:00
|
|
|
void DoReload()
|
|
|
|
{
|
2016-05-24 05:51:40 +02:00
|
|
|
// Are we already trying to reload?
|
|
|
|
if (Core::Get().GetCircularLock() & CCL_RELOAD_SCRIPTS)
|
2016-03-24 08:32:44 +01:00
|
|
|
{
|
2016-05-24 05:51:40 +02:00
|
|
|
return; // Don't even bother!
|
2016-03-24 08:32:44 +01:00
|
|
|
}
|
2016-05-24 18:26:43 +02:00
|
|
|
// Make sure reloading is disabled at the end of this function
|
2021-01-30 07:51:39 +01:00
|
|
|
const ReloadGuard rg;
|
2016-05-24 05:51:40 +02:00
|
|
|
// Tell the central core to attempt to reload
|
2016-05-24 18:26:43 +02:00
|
|
|
if (!Core::Get().Reload())
|
2016-03-24 08:32:44 +01:00
|
|
|
{
|
2016-05-24 05:51:40 +02:00
|
|
|
LogFtl("Unable to reload scripts");
|
2016-03-24 08:32:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
2016-03-12 07:47:50 +01:00
|
|
|
#define SQMOD_CATCH_EVENT_EXCEPTION(ev) /*
|
2021-02-20 20:22:12 +01:00
|
|
|
*/ catch (const Poco::Exception & e) /*
|
|
|
|
*/ { /*
|
|
|
|
*/ LogErr("Squirrel exception caught (" #ev ") event"); /*
|
|
|
|
*/ LogSInf("Message: %s", e.displayText().c_str()); /*
|
|
|
|
*/ } /*
|
2021-01-30 07:51:39 +01:00
|
|
|
*/ catch (const std::exception & e) /*
|
2016-03-12 07:47:50 +01:00
|
|
|
*/ { /*
|
2016-05-22 05:20:38 +02:00
|
|
|
*/ LogErr("Squirrel exception caught (" #ev ") event"); /*
|
2018-07-27 21:43:19 +02:00
|
|
|
*/ LogSInf("Message: %s", e.what()); /*
|
2016-03-12 07:47:50 +01:00
|
|
|
*/ } /*
|
|
|
|
*/
|
|
|
|
|
2016-03-24 08:32:44 +01:00
|
|
|
// --------------------------------------------------------------------------------------------
|
2016-05-24 05:51:40 +02:00
|
|
|
#define SQMOD_RELOAD_CHECK(exp) if (exp) DoReload();
|
2016-03-24 08:32:44 +01:00
|
|
|
|
2016-05-22 05:20:38 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-03-22 09:31:43 +01:00
|
|
|
static uint8_t OnServerInitialise()
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-03-12 07:47:50 +01:00
|
|
|
// Mark the initialization as successful by default
|
2017-06-19 15:10:31 +02:00
|
|
|
const CoreState cs(SQMOD_SUCCESS);
|
2016-03-12 07:47:50 +01:00
|
|
|
// Attempt to forward the event
|
|
|
|
try
|
|
|
|
{
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE<] OnServerInitialise")
|
2016-03-12 07:47:50 +01:00
|
|
|
// Signal outside plug-ins to do fetch our proxies
|
2023-03-05 16:11:38 +01:00
|
|
|
_Func->SendPluginCommand(SQMOD_INITIALIZE_CMD, "%d", 1);
|
2016-03-12 07:47:50 +01:00
|
|
|
// Attempt to load the module core
|
2016-05-22 05:20:38 +02:00
|
|
|
if (Core::Get().Execute())
|
2016-03-12 07:47:50 +01:00
|
|
|
{
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitServerStartup();
|
2019-06-02 17:19:39 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE>] OnServerInitialise")
|
2016-08-23 23:27:22 +02:00
|
|
|
// Add a notification to let the user know the plug-in was loaded
|
2016-08-25 11:00:48 +02:00
|
|
|
OutputMessage("The Squirrel plug-in was loaded successfully");
|
2016-03-12 07:47:50 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-06-02 17:19:39 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE>] OnServerInitialise")
|
2016-08-25 11:00:48 +02:00
|
|
|
OutputError("Unable to load the plug-in resources properly");
|
2021-03-28 00:07:46 +01:00
|
|
|
// The server may not invoke the shutdown callback
|
|
|
|
Core::Get().Terminate(true);
|
2016-05-22 05:20:38 +02:00
|
|
|
// Failed to initialize
|
|
|
|
return SQMOD_FAILURE;
|
2016-03-12 07:47:50 +01:00
|
|
|
}
|
|
|
|
}
|
2016-05-22 05:20:38 +02:00
|
|
|
SQMOD_CATCH_EVENT_EXCEPTION(OnServerInitialise)
|
2016-03-24 08:32:44 +01:00
|
|
|
// See if a reload was requested
|
2016-05-22 05:20:38 +02:00
|
|
|
SQMOD_RELOAD_CHECK(false)
|
2016-03-12 07:47:50 +01:00
|
|
|
// Return the last known plug-in state
|
2021-01-30 07:51:39 +01:00
|
|
|
return ConvTo< uint8_t >::From(Core::Get().GetState());
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2017-02-21 20:42:40 +01:00
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
|
|
* RAII approach to unbinding the server callbacks.
|
|
|
|
*/
|
|
|
|
struct CallbackUnbinder
|
|
|
|
{
|
|
|
|
~CallbackUnbinder()
|
|
|
|
{
|
2019-06-02 18:00:02 +02:00
|
|
|
memset(_Clbk, 0, sizeof(PluginCallbacks));
|
2017-02-21 20:42:40 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-05-22 05:20:38 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-03-22 09:31:43 +01:00
|
|
|
static void OnServerShutdown()
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2017-02-21 20:42:40 +01:00
|
|
|
// The server still triggers callbacks and we deallocated everything!
|
2021-01-30 07:51:39 +01:00
|
|
|
const CallbackUnbinder cu;
|
2016-03-12 07:47:50 +01:00
|
|
|
// Attempt to forward the event
|
|
|
|
try
|
|
|
|
{
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE<] OnServerShutdown")
|
2016-05-22 05:20:38 +02:00
|
|
|
// Tell the script that the server is shutting down
|
|
|
|
Core::Get().EmitServerShutdown();
|
2016-03-12 07:47:50 +01:00
|
|
|
// Deallocate and release everything obtained at startup
|
2016-07-16 16:52:55 +02:00
|
|
|
Core::Get().Terminate(true);
|
2023-08-05 20:31:33 +02:00
|
|
|
curl_global_cleanup();
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE>] OnServerShutdown")
|
2016-03-12 07:47:50 +01:00
|
|
|
}
|
2016-05-22 05:20:38 +02:00
|
|
|
SQMOD_CATCH_EVENT_EXCEPTION(OnServerShutdown)
|
2016-03-24 08:32:44 +01:00
|
|
|
// See if a reload was requested (quite useless here but why not)
|
2016-05-24 05:51:40 +02:00
|
|
|
SQMOD_RELOAD_CHECK(g_Reload)
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-05-22 05:20:38 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
static void OnServerFrame(float elapsed_time)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-03-12 07:47:50 +01:00
|
|
|
// Attempt to forward the event
|
|
|
|
try
|
|
|
|
{
|
2019-06-02 17:02:17 +02:00
|
|
|
//SQMOD_SV_EV_TRACEBACK("[TRACE<] OnServerFrame")
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitServerFrame(elapsed_time);
|
2019-06-02 17:02:17 +02:00
|
|
|
//SQMOD_SV_EV_TRACEBACK("[TRACE>] OnServerFrame")
|
2016-03-12 07:47:50 +01:00
|
|
|
}
|
2016-05-22 05:20:38 +02:00
|
|
|
SQMOD_CATCH_EVENT_EXCEPTION(OnServerFrame)
|
2016-11-16 23:23:59 +01:00
|
|
|
// Process routines and tasks, if any
|
2016-05-23 02:54:50 +02:00
|
|
|
ProcessRoutines();
|
2016-11-16 23:23:59 +01:00
|
|
|
ProcessTasks();
|
2021-03-27 23:19:09 +01:00
|
|
|
// Process threads
|
|
|
|
ProcessThreads();
|
2021-09-07 19:55:05 +02:00
|
|
|
// Process network
|
|
|
|
ProcessNet();
|
2023-08-05 20:31:33 +02:00
|
|
|
// Process Discord
|
|
|
|
#ifdef SQMOD_DISCORD
|
|
|
|
ProcessDiscord();
|
|
|
|
#endif
|
2020-09-08 21:44:04 +02:00
|
|
|
// Process log messages from other threads
|
|
|
|
Logger::Get().ProcessQueue();
|
2016-03-24 08:32:44 +01:00
|
|
|
// See if a reload was requested
|
2016-05-24 05:51:40 +02:00
|
|
|
SQMOD_RELOAD_CHECK(g_Reload)
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-05-22 05:20:38 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
static uint8_t OnPluginCommand(uint32_t command_identifier, const char * message)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-05-22 05:20:38 +02:00
|
|
|
// Mark the initialization as successful by default
|
2017-06-19 15:10:31 +02:00
|
|
|
const CoreState cs(SQMOD_SUCCESS);
|
2016-03-12 07:47:50 +01:00
|
|
|
// Attempt to forward the event
|
|
|
|
try
|
|
|
|
{
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE<] OnPluginCommand")
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitPluginCommand(command_identifier, message);
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE>] OnPluginCommand")
|
2016-03-12 07:47:50 +01:00
|
|
|
}
|
2016-05-22 05:20:38 +02:00
|
|
|
SQMOD_CATCH_EVENT_EXCEPTION(OnPluginCommand)
|
2016-03-24 08:32:44 +01:00
|
|
|
// See if a reload was requested
|
2016-05-24 05:51:40 +02:00
|
|
|
SQMOD_RELOAD_CHECK(g_Reload)
|
2016-05-22 05:20:38 +02:00
|
|
|
// Return the last known plug-in state
|
2021-01-30 07:51:39 +01:00
|
|
|
return ConvTo< uint8_t >::From(Core::Get().GetState());
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-05-22 05:20:38 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
static uint8_t OnIncomingConnection(char * player_name, size_t name_buffer_size,
|
|
|
|
const char * user_password, const char * ip_address)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-05-22 05:20:38 +02:00
|
|
|
// Mark the initialization as successful by default
|
2017-06-19 15:10:31 +02:00
|
|
|
const CoreState cs(SQMOD_SUCCESS);
|
2016-03-12 07:47:50 +01:00
|
|
|
// Attempt to forward the event
|
|
|
|
try
|
|
|
|
{
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE<] OnIncomingConnection")
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitIncomingConnection(player_name, name_buffer_size, user_password, ip_address);
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE>] OnIncomingConnection")
|
2016-03-12 07:47:50 +01:00
|
|
|
}
|
2016-05-22 05:20:38 +02:00
|
|
|
SQMOD_CATCH_EVENT_EXCEPTION(OnIncomingConnection)
|
2016-03-24 08:32:44 +01:00
|
|
|
// See if a reload was requested
|
2016-05-24 05:51:40 +02:00
|
|
|
SQMOD_RELOAD_CHECK(g_Reload)
|
2016-05-22 05:20:38 +02:00
|
|
|
// Return the last known plug-in state
|
2021-01-30 07:51:39 +01:00
|
|
|
return ConvTo< uint8_t >::From(Core::Get().GetState());
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-05-22 05:20:38 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
static void OnClientScriptData(int32_t player_id, const uint8_t * data, size_t size)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-03-12 07:47:50 +01:00
|
|
|
// Attempt to forward the event
|
|
|
|
try
|
|
|
|
{
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE<] OnClientScriptData")
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitClientScriptData(player_id, data, size);
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE>] OnClientScriptData")
|
2016-03-12 07:47:50 +01:00
|
|
|
}
|
2016-05-22 05:20:38 +02:00
|
|
|
SQMOD_CATCH_EVENT_EXCEPTION(OnClientScriptData)
|
|
|
|
// See if a reload was requested
|
2016-05-24 05:51:40 +02:00
|
|
|
SQMOD_RELOAD_CHECK(g_Reload)
|
2016-05-22 05:20:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
static void OnPlayerConnect(int32_t player_id)
|
|
|
|
{
|
|
|
|
// Attempt to forward the event
|
|
|
|
try
|
|
|
|
{
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE<] OnPlayerConnect")
|
2017-02-21 20:24:59 +01:00
|
|
|
Core::Get().ConnectPlayer(player_id, SQMOD_CREATE_AUTOMATIC, NullLightObj());
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE>] OnPlayerConnect")
|
2016-05-22 05:20:38 +02:00
|
|
|
}
|
|
|
|
SQMOD_CATCH_EVENT_EXCEPTION(OnPlayerConnect)
|
2016-03-24 08:32:44 +01:00
|
|
|
// See if a reload was requested
|
2016-05-24 05:51:40 +02:00
|
|
|
SQMOD_RELOAD_CHECK(g_Reload)
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-05-22 05:20:38 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
static void OnPlayerDisconnect(int32_t player_id, vcmpDisconnectReason reason)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-03-12 07:47:50 +01:00
|
|
|
// Attempt to forward the event
|
|
|
|
try
|
|
|
|
{
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE<] OnPlayerDisconnect")
|
2016-08-17 12:48:29 +02:00
|
|
|
if (reason == vcmpDisconnectReasonKick)
|
|
|
|
{
|
|
|
|
Core::Get().DisconnectPlayer(player_id, Core::Get().GetPlayer(player_id).mKickBanHeader,
|
|
|
|
Core::Get().GetPlayer(player_id).mKickBanPayload);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-02-21 20:24:59 +01:00
|
|
|
Core::Get().DisconnectPlayer(player_id, reason, NullLightObj());
|
2016-08-17 12:48:29 +02:00
|
|
|
}
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE>] OnPlayerDisconnect")
|
2016-03-12 07:47:50 +01:00
|
|
|
}
|
2016-05-22 05:20:38 +02:00
|
|
|
SQMOD_CATCH_EVENT_EXCEPTION(OnPlayerDisconnect)
|
2016-03-24 08:32:44 +01:00
|
|
|
// See if a reload was requested
|
2016-05-24 05:51:40 +02:00
|
|
|
SQMOD_RELOAD_CHECK(g_Reload)
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-05-22 05:20:38 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
static uint8_t OnPlayerRequestClass(int32_t player_id, int32_t offset)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-03-12 07:47:50 +01:00
|
|
|
// Mark the initialization as successful by default
|
2017-06-19 15:10:31 +02:00
|
|
|
const CoreState cs(SQMOD_SUCCESS);
|
2016-03-12 07:47:50 +01:00
|
|
|
// Attempt to forward the event
|
|
|
|
try
|
|
|
|
{
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE<] OnPlayerRequestClass")
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitPlayerRequestClass(player_id, offset);
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE>] OnPlayerRequestClass")
|
2016-03-12 07:47:50 +01:00
|
|
|
}
|
2016-05-22 05:20:38 +02:00
|
|
|
SQMOD_CATCH_EVENT_EXCEPTION(OnPlayerRequestClass)
|
2016-03-24 08:32:44 +01:00
|
|
|
// See if a reload was requested
|
2016-05-24 05:51:40 +02:00
|
|
|
SQMOD_RELOAD_CHECK(g_Reload)
|
2016-03-12 07:47:50 +01:00
|
|
|
// Return the last known plug-in state
|
2021-01-30 07:51:39 +01:00
|
|
|
return ConvTo< uint8_t >::From(Core::Get().GetState());
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-05-22 05:20:38 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
static uint8_t OnPlayerRequestSpawn(int32_t player_id)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-03-12 07:47:50 +01:00
|
|
|
// Mark the initialization as successful by default
|
2017-06-19 15:10:31 +02:00
|
|
|
const CoreState cs(SQMOD_SUCCESS);
|
2016-03-12 07:47:50 +01:00
|
|
|
// Attempt to forward the event
|
|
|
|
try
|
|
|
|
{
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE<] OnPlayerRequestSpawn")
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitPlayerRequestSpawn(player_id);
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE>] OnPlayerRequestSpawn")
|
2016-03-12 07:47:50 +01:00
|
|
|
}
|
2016-05-22 05:20:38 +02:00
|
|
|
SQMOD_CATCH_EVENT_EXCEPTION(OnPlayerRequestSpawn)
|
2016-03-24 08:32:44 +01:00
|
|
|
// See if a reload was requested
|
2016-05-24 05:51:40 +02:00
|
|
|
SQMOD_RELOAD_CHECK(g_Reload)
|
2016-03-12 07:47:50 +01:00
|
|
|
// Return the last known plug-in state
|
2021-01-30 07:51:39 +01:00
|
|
|
return ConvTo< uint8_t >::From(Core::Get().GetState());
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-05-22 05:20:38 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
static void OnPlayerSpawn(int32_t player_id)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-03-12 07:47:50 +01:00
|
|
|
// Attempt to forward the event
|
|
|
|
try
|
|
|
|
{
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE<] OnPlayerSpawn")
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitPlayerSpawn(player_id);
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE>] OnPlayerSpawn")
|
2016-03-12 07:47:50 +01:00
|
|
|
}
|
2016-05-22 05:20:38 +02:00
|
|
|
SQMOD_CATCH_EVENT_EXCEPTION(OnPlayerSpawn)
|
2016-03-24 08:32:44 +01:00
|
|
|
// See if a reload was requested
|
2016-05-24 05:51:40 +02:00
|
|
|
SQMOD_RELOAD_CHECK(g_Reload)
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-05-22 05:20:38 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
static void OnPlayerDeath(int32_t player_id, int32_t killer_id, int32_t reason, vcmpBodyPart body_part)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-03-12 07:47:50 +01:00
|
|
|
// Attempt to forward the event
|
|
|
|
try
|
|
|
|
{
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE<] OnPlayerDeath")
|
2016-05-22 05:20:38 +02:00
|
|
|
if (_Func->IsPlayerConnected(killer_id))
|
2016-03-12 07:47:50 +01:00
|
|
|
{
|
2016-05-22 05:20:38 +02:00
|
|
|
const int32_t pt = _Func->GetPlayerTeam(player_id), kt = _Func->GetPlayerTeam(killer_id);
|
|
|
|
Core::Get().EmitPlayerKilled(player_id, killer_id, reason, body_part,
|
|
|
|
(pt == kt && pt >= 0 && kt >= 0));
|
2016-03-12 07:47:50 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-15 06:02:48 +01:00
|
|
|
Core::Get().EmitPlayerWasted(player_id, reason, body_part);
|
2016-03-12 07:47:50 +01:00
|
|
|
}
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE>] OnPlayerDeath")
|
2016-03-12 07:47:50 +01:00
|
|
|
}
|
2016-05-22 05:20:38 +02:00
|
|
|
SQMOD_CATCH_EVENT_EXCEPTION(OnPlayerDeath)
|
2016-03-24 08:32:44 +01:00
|
|
|
// See if a reload was requested
|
2016-05-24 05:51:40 +02:00
|
|
|
SQMOD_RELOAD_CHECK(g_Reload)
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-05-22 05:20:38 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
static void OnPlayerUpdate(int32_t player_id, vcmpPlayerUpdate update_type)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-03-12 07:47:50 +01:00
|
|
|
// Attempt to forward the event
|
|
|
|
try
|
|
|
|
{
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE<] OnPlayerUpdate")
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitPlayerUpdate(player_id, update_type);
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE>] OnPlayerUpdate")
|
2016-03-12 07:47:50 +01:00
|
|
|
}
|
2016-05-22 05:20:38 +02:00
|
|
|
SQMOD_CATCH_EVENT_EXCEPTION(OnPlayerUpdate)
|
2016-03-24 08:32:44 +01:00
|
|
|
// See if a reload was requested
|
2016-05-24 05:51:40 +02:00
|
|
|
SQMOD_RELOAD_CHECK(g_Reload)
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-05-22 05:20:38 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
static uint8_t OnPlayerRequestEnterVehicle(int32_t player_id, int32_t vehicle_id, int32_t slot_index)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-03-12 07:47:50 +01:00
|
|
|
// Mark the initialization as successful by default
|
2017-06-19 15:10:31 +02:00
|
|
|
const CoreState cs(SQMOD_SUCCESS);
|
2016-03-12 07:47:50 +01:00
|
|
|
// Attempt to forward the event
|
|
|
|
try
|
|
|
|
{
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE<] OnPlayerRequestEnterVehicle")
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitPlayerEmbarking(player_id, vehicle_id, slot_index);
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE>] OnPlayerRequestEnterVehicle")
|
2016-03-12 07:47:50 +01:00
|
|
|
}
|
2016-05-22 05:20:38 +02:00
|
|
|
SQMOD_CATCH_EVENT_EXCEPTION(OnPlayerRequestEnterVehicle)
|
2016-03-24 08:32:44 +01:00
|
|
|
// See if a reload was requested
|
2016-05-24 05:51:40 +02:00
|
|
|
SQMOD_RELOAD_CHECK(g_Reload)
|
2016-03-12 07:47:50 +01:00
|
|
|
// Return the last known plug-in state
|
2021-01-30 07:51:39 +01:00
|
|
|
return ConvTo< uint8_t >::From(Core::Get().GetState());
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-05-22 05:20:38 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
static void OnPlayerEnterVehicle(int32_t player_id, int32_t vehicle_id, int32_t slot_index)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-03-12 07:47:50 +01:00
|
|
|
// Attempt to forward the event
|
|
|
|
try
|
|
|
|
{
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE<] OnPlayerEnterVehicle")
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitPlayerEmbarked(player_id, vehicle_id, slot_index);
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE>] OnPlayerEnterVehicle")
|
2016-03-12 07:47:50 +01:00
|
|
|
}
|
2016-05-22 05:20:38 +02:00
|
|
|
SQMOD_CATCH_EVENT_EXCEPTION(OnPlayerEnterVehicle)
|
2016-03-24 08:32:44 +01:00
|
|
|
// See if a reload was requested
|
2016-05-24 05:51:40 +02:00
|
|
|
SQMOD_RELOAD_CHECK(g_Reload)
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-05-22 05:20:38 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
static void OnPlayerExitVehicle(int32_t player_id, int32_t vehicle_id)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-03-12 07:47:50 +01:00
|
|
|
// Attempt to forward the event
|
|
|
|
try
|
|
|
|
{
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE<] OnPlayerExitVehicle")
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitPlayerDisembark(player_id, vehicle_id);
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE>] OnPlayerExitVehicle")
|
2016-03-12 07:47:50 +01:00
|
|
|
}
|
2016-05-22 05:20:38 +02:00
|
|
|
SQMOD_CATCH_EVENT_EXCEPTION(OnPlayerExitVehicle)
|
2016-03-24 08:32:44 +01:00
|
|
|
// See if a reload was requested
|
2016-05-24 05:51:40 +02:00
|
|
|
SQMOD_RELOAD_CHECK(g_Reload)
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-05-22 05:20:38 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
static void OnPlayerNameChange(int32_t player_id, const char * old_name, const char * new_name)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-03-12 07:47:50 +01:00
|
|
|
// Attempt to forward the event
|
|
|
|
try
|
|
|
|
{
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE<] OnPlayerNameChange")
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitPlayerRename(player_id, old_name, new_name);
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE>] OnPlayerNameChange")
|
2016-03-12 07:47:50 +01:00
|
|
|
}
|
2016-05-22 05:20:38 +02:00
|
|
|
SQMOD_CATCH_EVENT_EXCEPTION(OnPlayerNameChange)
|
2016-03-24 08:32:44 +01:00
|
|
|
// See if a reload was requested
|
2016-05-24 05:51:40 +02:00
|
|
|
SQMOD_RELOAD_CHECK(g_Reload)
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-05-22 05:20:38 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
static void OnPlayerStateChange(int32_t player_id, vcmpPlayerState old_state, vcmpPlayerState new_state)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2021-04-17 19:39:15 +02:00
|
|
|
// Look for changes
|
|
|
|
if (old_state == new_state)
|
|
|
|
{
|
|
|
|
return; // Nothing changed!
|
|
|
|
}
|
2016-03-12 07:47:50 +01:00
|
|
|
// Attempt to forward the event
|
|
|
|
try
|
|
|
|
{
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE<] OnPlayerStateChange")
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitPlayerState(player_id, old_state, new_state);
|
|
|
|
// Identify the current state and trigger the listeners specific to that
|
|
|
|
switch (new_state)
|
|
|
|
{
|
|
|
|
case vcmpPlayerStateNone:
|
|
|
|
Core::Get().EmitStateNone(player_id, old_state);
|
|
|
|
break;
|
|
|
|
case vcmpPlayerStateNormal:
|
|
|
|
Core::Get().EmitStateNormal(player_id, old_state);
|
|
|
|
break;
|
|
|
|
case vcmpPlayerStateAim:
|
|
|
|
Core::Get().EmitStateAim(player_id, old_state);
|
|
|
|
break;
|
|
|
|
case vcmpPlayerStateDriver:
|
|
|
|
Core::Get().EmitStateDriver(player_id, old_state);
|
|
|
|
break;
|
|
|
|
case vcmpPlayerStatePassenger:
|
|
|
|
Core::Get().EmitStatePassenger(player_id, old_state);
|
|
|
|
break;
|
|
|
|
case vcmpPlayerStateEnterDriver:
|
|
|
|
Core::Get().EmitStateEnterDriver(player_id, old_state);
|
|
|
|
break;
|
|
|
|
case vcmpPlayerStateEnterPassenger:
|
|
|
|
Core::Get().EmitStateEnterPassenger(player_id, old_state);
|
|
|
|
break;
|
|
|
|
case vcmpPlayerStateExit:
|
|
|
|
Core::Get().EmitStateExit(player_id, old_state);
|
|
|
|
break;
|
|
|
|
case vcmpPlayerStateUnspawned:
|
|
|
|
Core::Get().EmitStateUnspawned(player_id, old_state);
|
|
|
|
break;
|
2021-01-30 07:51:39 +01:00
|
|
|
default: LogErr("Unknown player state change: %d", static_cast< int32_t >(new_state));
|
2016-05-22 05:20:38 +02:00
|
|
|
}
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE>] OnPlayerStateChange")
|
2016-03-12 07:47:50 +01:00
|
|
|
}
|
2016-05-22 05:20:38 +02:00
|
|
|
SQMOD_CATCH_EVENT_EXCEPTION(OnPlayerStateChange)
|
2016-03-24 08:32:44 +01:00
|
|
|
// See if a reload was requested
|
2016-05-24 05:51:40 +02:00
|
|
|
SQMOD_RELOAD_CHECK(g_Reload)
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-05-22 05:20:38 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
static void OnPlayerActionChange(int32_t player_id, int32_t old_action, int32_t new_action)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2021-04-17 19:39:15 +02:00
|
|
|
// Look for changes
|
|
|
|
if (old_action == new_action)
|
|
|
|
{
|
|
|
|
return; // Nothing changed!
|
|
|
|
}
|
2016-03-12 07:47:50 +01:00
|
|
|
// Attempt to forward the event
|
|
|
|
try
|
|
|
|
{
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE<] OnPlayerActionChange")
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitPlayerAction(player_id, old_action, new_action);
|
|
|
|
// Identify the current action and trigger the listeners specific to that
|
|
|
|
switch (new_action)
|
|
|
|
{
|
|
|
|
case SQMOD_PLAYER_ACTION_NONE:
|
|
|
|
Core::Get().EmitActionNone(player_id, old_action);
|
|
|
|
break;
|
|
|
|
case SQMOD_PLAYER_ACTION_NORMAL:
|
|
|
|
Core::Get().EmitActionNormal(player_id, old_action);
|
|
|
|
break;
|
|
|
|
case SQMOD_PLAYER_ACTION_AIMING:
|
|
|
|
Core::Get().EmitActionAiming(player_id, old_action);
|
|
|
|
break;
|
|
|
|
case SQMOD_PLAYER_ACTION_SHOOTING:
|
|
|
|
Core::Get().EmitActionShooting(player_id, old_action);
|
|
|
|
break;
|
|
|
|
case SQMOD_PLAYER_ACTION_JUMPING:
|
|
|
|
Core::Get().EmitActionJumping(player_id, old_action);
|
|
|
|
break;
|
|
|
|
case SQMOD_PLAYER_ACTION_LYING_ON_GROUND:
|
|
|
|
Core::Get().EmitActionLieDown(player_id, old_action);
|
|
|
|
break;
|
|
|
|
case SQMOD_PLAYER_ACTION_GETTING_UP:
|
|
|
|
Core::Get().EmitActionGettingUp(player_id, old_action);
|
|
|
|
break;
|
|
|
|
case SQMOD_PLAYER_ACTION_JUMPING_FROM_VEHICLE:
|
|
|
|
Core::Get().EmitActionJumpVehicle(player_id, old_action);
|
|
|
|
break;
|
|
|
|
case SQMOD_PLAYER_ACTION_DRIVING:
|
|
|
|
Core::Get().EmitActionDriving(player_id, old_action);
|
|
|
|
break;
|
|
|
|
case SQMOD_PLAYER_ACTION_DYING:
|
|
|
|
Core::Get().EmitActionDying(player_id, old_action);
|
|
|
|
break;
|
|
|
|
case SQMOD_PLAYER_ACTION_WASTED:
|
|
|
|
Core::Get().EmitActionWasted(player_id, old_action);
|
|
|
|
break;
|
|
|
|
case SQMOD_PLAYER_ACTION_ENTERING_VEHICLE:
|
|
|
|
Core::Get().EmitActionEmbarking(player_id, old_action);
|
|
|
|
break;
|
|
|
|
case SQMOD_PLAYER_ACTION_EXITING_VEHICLE:
|
|
|
|
Core::Get().EmitActionDisembarking(player_id, old_action);
|
|
|
|
break;
|
2020-03-22 09:31:43 +01:00
|
|
|
default: break;
|
2016-05-22 05:20:38 +02:00
|
|
|
}
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE>] OnPlayerActionChange")
|
2016-03-12 07:47:50 +01:00
|
|
|
}
|
2016-05-22 05:20:38 +02:00
|
|
|
SQMOD_CATCH_EVENT_EXCEPTION(OnPlayerActionChange)
|
2016-03-24 08:32:44 +01:00
|
|
|
// See if a reload was requested
|
2016-05-24 05:51:40 +02:00
|
|
|
SQMOD_RELOAD_CHECK(g_Reload)
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-05-22 05:20:38 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
static void OnPlayerOnFireChange(int32_t player_id, uint8_t is_on_fire)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-03-12 07:47:50 +01:00
|
|
|
// Attempt to forward the event
|
|
|
|
try
|
|
|
|
{
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE<] OnPlayerOnFireChange")
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitPlayerBurning(player_id, is_on_fire);
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE>] OnPlayerOnFireChange")
|
2016-03-12 07:47:50 +01:00
|
|
|
}
|
2016-05-22 05:20:38 +02:00
|
|
|
SQMOD_CATCH_EVENT_EXCEPTION(OnPlayerOnFireChange)
|
2016-03-24 08:32:44 +01:00
|
|
|
// See if a reload was requested
|
2016-05-24 05:51:40 +02:00
|
|
|
SQMOD_RELOAD_CHECK(g_Reload)
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-05-22 05:20:38 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
static void OnPlayerCrouchChange(int32_t player_id, uint8_t is_crouching)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-03-12 07:47:50 +01:00
|
|
|
// Attempt to forward the event
|
|
|
|
try
|
|
|
|
{
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE<] OnPlayerCrouchChange")
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitPlayerCrouching(player_id, is_crouching);
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE>] OnPlayerCrouchChange")
|
2016-03-12 07:47:50 +01:00
|
|
|
}
|
2016-05-22 05:20:38 +02:00
|
|
|
SQMOD_CATCH_EVENT_EXCEPTION(OnPlayerCrouchChange)
|
2016-03-24 08:32:44 +01:00
|
|
|
// See if a reload was requested
|
2016-05-24 05:51:40 +02:00
|
|
|
SQMOD_RELOAD_CHECK(g_Reload)
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-05-22 05:20:38 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
static void OnPlayerGameKeysChange(int32_t player_id, uint32_t old_keys, uint32_t new_keys)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-03-12 07:47:50 +01:00
|
|
|
// Attempt to forward the event
|
|
|
|
try
|
|
|
|
{
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE<] OnPlayerGameKeysChange")
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitPlayerGameKeys(player_id, old_keys, new_keys);
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE>] OnPlayerGameKeysChange")
|
2016-03-12 07:47:50 +01:00
|
|
|
}
|
2016-05-22 05:20:38 +02:00
|
|
|
SQMOD_CATCH_EVENT_EXCEPTION(OnPlayerGameKeysChange)
|
2016-03-24 08:32:44 +01:00
|
|
|
// See if a reload was requested
|
2016-05-24 05:51:40 +02:00
|
|
|
SQMOD_RELOAD_CHECK(g_Reload)
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-05-22 05:20:38 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
static void OnPlayerBeginTyping(int32_t player_id)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-03-12 07:47:50 +01:00
|
|
|
// Attempt to forward the event
|
|
|
|
try
|
|
|
|
{
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE<] OnPlayerBeginTyping")
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitPlayerStartTyping(player_id);
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE>] OnPlayerBeginTyping")
|
2016-03-12 07:47:50 +01:00
|
|
|
}
|
2016-05-22 05:20:38 +02:00
|
|
|
SQMOD_CATCH_EVENT_EXCEPTION(PlayerBeginTyping)
|
2016-03-24 08:32:44 +01:00
|
|
|
// See if a reload was requested
|
2016-05-24 05:51:40 +02:00
|
|
|
SQMOD_RELOAD_CHECK(g_Reload)
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-05-22 05:20:38 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
static void OnPlayerEndTyping(int32_t player_id)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-03-12 07:47:50 +01:00
|
|
|
// Attempt to forward the event
|
|
|
|
try
|
|
|
|
{
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE<] OnPlayerEndTyping")
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitPlayerStopTyping(player_id);
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE>] OnPlayerEndTyping")
|
2016-03-12 07:47:50 +01:00
|
|
|
}
|
2016-05-22 05:20:38 +02:00
|
|
|
SQMOD_CATCH_EVENT_EXCEPTION(PlayerEndTyping)
|
2016-03-24 08:32:44 +01:00
|
|
|
// See if a reload was requested
|
2016-05-24 05:51:40 +02:00
|
|
|
SQMOD_RELOAD_CHECK(g_Reload)
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-05-22 05:20:38 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
static void OnPlayerAwayChange(int32_t player_id, uint8_t is_away)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-03-12 07:47:50 +01:00
|
|
|
// Attempt to forward the event
|
|
|
|
try
|
|
|
|
{
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE<] OnPlayerAwayChange")
|
2021-03-15 06:02:48 +01:00
|
|
|
Core::Get().EmitPlayerAway(player_id, is_away >= 1);
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE>] OnPlayerAwayChange")
|
2016-03-12 07:47:50 +01:00
|
|
|
}
|
2016-05-22 05:20:38 +02:00
|
|
|
SQMOD_CATCH_EVENT_EXCEPTION(OnPlayerAwayChange)
|
2016-03-24 08:32:44 +01:00
|
|
|
// See if a reload was requested
|
2016-05-24 05:51:40 +02:00
|
|
|
SQMOD_RELOAD_CHECK(g_Reload)
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-05-22 05:20:38 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
static uint8_t OnPlayerMessage(int32_t player_id, const char * message)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-03-12 07:47:50 +01:00
|
|
|
// Mark the initialization as successful by default
|
2017-06-19 15:10:31 +02:00
|
|
|
const CoreState cs(SQMOD_SUCCESS);
|
2016-03-12 07:47:50 +01:00
|
|
|
// Attempt to forward the event
|
|
|
|
try
|
|
|
|
{
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE<] OnPlayerMessage")
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitPlayerMessage(player_id, message);
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE>] OnPlayerMessage")
|
2016-03-12 07:47:50 +01:00
|
|
|
}
|
2016-05-22 05:20:38 +02:00
|
|
|
SQMOD_CATCH_EVENT_EXCEPTION(OnPlayerMessage)
|
2016-03-24 08:32:44 +01:00
|
|
|
// See if a reload was requested
|
2016-05-24 05:51:40 +02:00
|
|
|
SQMOD_RELOAD_CHECK(g_Reload)
|
2016-03-12 07:47:50 +01:00
|
|
|
// Return the last known plug-in state
|
2021-01-30 07:51:39 +01:00
|
|
|
return ConvTo< uint8_t >::From(Core::Get().GetState());
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-05-22 05:20:38 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
static uint8_t OnPlayerCommand(int32_t player_id, const char * message)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-03-12 07:47:50 +01:00
|
|
|
// Mark the initialization as successful by default
|
2017-06-19 15:10:31 +02:00
|
|
|
const CoreState cs(SQMOD_SUCCESS);
|
2016-03-12 07:47:50 +01:00
|
|
|
// Attempt to forward the event
|
|
|
|
try
|
|
|
|
{
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE<] OnPlayerCommand")
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitPlayerCommand(player_id, message);
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE>] OnPlayerCommand")
|
2016-03-12 07:47:50 +01:00
|
|
|
}
|
2016-05-22 05:20:38 +02:00
|
|
|
SQMOD_CATCH_EVENT_EXCEPTION(OnPlayerCommand)
|
2016-03-24 08:32:44 +01:00
|
|
|
// See if a reload was requested
|
2016-05-24 05:51:40 +02:00
|
|
|
SQMOD_RELOAD_CHECK(g_Reload)
|
2016-03-12 07:47:50 +01:00
|
|
|
// Return the last known plug-in state
|
2021-01-30 07:51:39 +01:00
|
|
|
return ConvTo< uint8_t >::From(Core::Get().GetState());
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-05-22 05:20:38 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
static uint8_t OnPlayerPrivateMessage(int32_t player_id, int32_t target_player_id, const char * message)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-03-12 07:47:50 +01:00
|
|
|
// Mark the initialization as successful by default
|
2017-06-19 15:10:31 +02:00
|
|
|
const CoreState cs(SQMOD_SUCCESS);
|
2016-03-12 07:47:50 +01:00
|
|
|
// Attempt to forward the event
|
|
|
|
try
|
|
|
|
{
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE<] OnPlayerPrivateMessage")
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitPlayerPrivateMessage(player_id, target_player_id, message);
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE>] OnPlayerPrivateMessage")
|
2016-03-12 07:47:50 +01:00
|
|
|
}
|
2016-05-22 05:20:38 +02:00
|
|
|
SQMOD_CATCH_EVENT_EXCEPTION(OnPlayerPrivateMessage)
|
2016-03-24 08:32:44 +01:00
|
|
|
// See if a reload was requested
|
2016-05-24 05:51:40 +02:00
|
|
|
SQMOD_RELOAD_CHECK(g_Reload)
|
2016-03-12 07:47:50 +01:00
|
|
|
// Return the last known plug-in state
|
2021-01-30 07:51:39 +01:00
|
|
|
return ConvTo< uint8_t >::From(Core::Get().GetState());
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-05-22 05:20:38 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
static void OnPlayerKeyBindDown(int32_t player_id, int32_t bind_id)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-03-12 07:47:50 +01:00
|
|
|
// Attempt to forward the event
|
|
|
|
try
|
|
|
|
{
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE<] OnPlayerKeyBindDown")
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitPlayerKeyPress(player_id, bind_id);
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE>] OnPlayerKeyBindDown")
|
2016-03-12 07:47:50 +01:00
|
|
|
}
|
2016-05-22 05:20:38 +02:00
|
|
|
SQMOD_CATCH_EVENT_EXCEPTION(OnPlayerKeyBindDown)
|
2016-03-24 08:32:44 +01:00
|
|
|
// See if a reload was requested
|
2016-05-24 05:51:40 +02:00
|
|
|
SQMOD_RELOAD_CHECK(g_Reload)
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-05-22 05:20:38 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
static void OnPlayerKeyBindUp(int32_t player_id, int32_t bind_id)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-03-12 07:47:50 +01:00
|
|
|
// Attempt to forward the event
|
|
|
|
try
|
|
|
|
{
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE<] OnPlayerKeyBindUp")
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitPlayerKeyRelease(player_id, bind_id);
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE>] OnPlayerKeyBindUp")
|
2016-03-12 07:47:50 +01:00
|
|
|
}
|
2016-05-22 05:20:38 +02:00
|
|
|
SQMOD_CATCH_EVENT_EXCEPTION(OnPlayerKeyBindUp)
|
2016-03-24 08:32:44 +01:00
|
|
|
// See if a reload was requested
|
2016-05-24 05:51:40 +02:00
|
|
|
SQMOD_RELOAD_CHECK(g_Reload)
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-05-22 05:20:38 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
static void OnPlayerSpectate(int32_t player_id, int32_t target_player_id)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-03-12 07:47:50 +01:00
|
|
|
// Attempt to forward the event
|
|
|
|
try
|
|
|
|
{
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE<] OnPlayerSpectate")
|
2017-08-06 17:14:58 +02:00
|
|
|
if (target_player_id < 0)
|
|
|
|
{
|
|
|
|
Core::Get().EmitPlayerUnspectate(player_id);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Core::Get().EmitPlayerSpectate(player_id, target_player_id);
|
|
|
|
}
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE>] OnPlayerSpectate")
|
2016-03-12 07:47:50 +01:00
|
|
|
}
|
2016-05-22 05:20:38 +02:00
|
|
|
SQMOD_CATCH_EVENT_EXCEPTION(OnPlayerSpectate)
|
2016-03-24 08:32:44 +01:00
|
|
|
// See if a reload was requested
|
2016-05-22 05:20:38 +02:00
|
|
|
SQMOD_RELOAD_CHECK(false)
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-05-22 05:20:38 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
static void OnPlayerCrashReport(int32_t player_id, const char * report)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-03-12 07:47:50 +01:00
|
|
|
// Attempt to forward the event
|
|
|
|
try
|
|
|
|
{
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE<] OnPlayerCrashReport")
|
2021-01-30 07:51:39 +01:00
|
|
|
Core::Get().EmitPlayerCrashReport(player_id, report);
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE>] OnPlayerCrashReport")
|
2016-03-12 07:47:50 +01:00
|
|
|
}
|
2016-05-22 05:20:38 +02:00
|
|
|
SQMOD_CATCH_EVENT_EXCEPTION(OnPlayerCrashReport)
|
2016-03-24 08:32:44 +01:00
|
|
|
// See if a reload was requested
|
2016-05-22 05:20:38 +02:00
|
|
|
SQMOD_RELOAD_CHECK(false)
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2018-06-28 20:41:31 +02:00
|
|
|
static void OnPlayerModuleList(int32_t player_id, const char * list)
|
|
|
|
{
|
|
|
|
// Attempt to forward the event
|
|
|
|
try
|
|
|
|
{
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE<] OnPlayerModuleList")
|
2018-06-28 20:41:31 +02:00
|
|
|
Core::Get().EmitPlayerModuleList(player_id, list);
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE>] OnPlayerModuleList")
|
2018-06-28 20:41:31 +02:00
|
|
|
}
|
|
|
|
SQMOD_CATCH_EVENT_EXCEPTION(OnPlayerModuleList)
|
|
|
|
// See if a reload was requested
|
|
|
|
SQMOD_RELOAD_CHECK(false)
|
|
|
|
}
|
|
|
|
|
2016-05-22 05:20:38 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
static void OnVehicleUpdate(int32_t vehicle_id, vcmpVehicleUpdate update_type)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-03-12 07:47:50 +01:00
|
|
|
// Attempt to forward the event
|
|
|
|
try
|
|
|
|
{
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE<] OnVehicleUpdate")
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitVehicleUpdate(vehicle_id, update_type);
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE>] OnVehicleUpdate")
|
2016-03-12 07:47:50 +01:00
|
|
|
}
|
2016-05-22 05:20:38 +02:00
|
|
|
SQMOD_CATCH_EVENT_EXCEPTION(OnVehicleUpdate)
|
2016-03-24 08:32:44 +01:00
|
|
|
// See if a reload was requested
|
2016-05-22 05:20:38 +02:00
|
|
|
SQMOD_RELOAD_CHECK(false)
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-05-22 05:20:38 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
static void OnVehicleExplode(int32_t vehicle_id)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-03-12 07:47:50 +01:00
|
|
|
// Attempt to forward the event
|
|
|
|
try
|
|
|
|
{
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE<] OnVehicleExplode")
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitVehicleExplode(vehicle_id);
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE>] OnVehicleExplode")
|
2016-03-12 07:47:50 +01:00
|
|
|
}
|
2016-05-22 05:20:38 +02:00
|
|
|
SQMOD_CATCH_EVENT_EXCEPTION(OnVehicleExplode)
|
2016-03-24 08:32:44 +01:00
|
|
|
// See if a reload was requested
|
2016-05-22 05:20:38 +02:00
|
|
|
SQMOD_RELOAD_CHECK(false)
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-05-22 05:20:38 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
static void OnVehicleRespawn(int32_t vehicle_id)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-03-12 07:47:50 +01:00
|
|
|
// Attempt to forward the event
|
|
|
|
try
|
|
|
|
{
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE<] OnVehicleRespawn")
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitVehicleRespawn(vehicle_id);
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE>] OnVehicleRespawn")
|
2016-03-12 07:47:50 +01:00
|
|
|
}
|
2016-05-22 05:20:38 +02:00
|
|
|
SQMOD_CATCH_EVENT_EXCEPTION(OnVehicleRespawn)
|
2016-03-24 08:32:44 +01:00
|
|
|
// See if a reload was requested
|
2016-05-22 05:20:38 +02:00
|
|
|
SQMOD_RELOAD_CHECK(false)
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-05-22 05:20:38 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
static void OnObjectShot(int32_t object_id, int32_t player_id, int32_t weapon_id)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-03-12 07:47:50 +01:00
|
|
|
// Attempt to forward the event
|
|
|
|
try
|
|
|
|
{
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE<] OnObjectShot")
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitObjectShot(object_id, player_id, weapon_id);
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE>] OnObjectShot")
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
2016-05-22 05:20:38 +02:00
|
|
|
SQMOD_CATCH_EVENT_EXCEPTION(OnObjectShot)
|
2016-03-24 08:32:44 +01:00
|
|
|
// See if a reload was requested
|
2016-05-22 05:20:38 +02:00
|
|
|
SQMOD_RELOAD_CHECK(false)
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-05-22 05:20:38 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
static void OnObjectTouched(int32_t object_id, int32_t player_id)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-03-12 07:47:50 +01:00
|
|
|
// Attempt to forward the event
|
|
|
|
try
|
|
|
|
{
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE<] OnObjectTouched")
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitObjectTouched(object_id, player_id);
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE>] OnObjectTouched")
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
2016-05-22 05:20:38 +02:00
|
|
|
SQMOD_CATCH_EVENT_EXCEPTION(OnObjectTouched)
|
2016-03-24 08:32:44 +01:00
|
|
|
// See if a reload was requested
|
2016-05-22 05:20:38 +02:00
|
|
|
SQMOD_RELOAD_CHECK(false)
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-05-22 05:20:38 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
static uint8_t OnPickupPickAttempt(int32_t pickup_id, int32_t player_id)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-05-22 05:20:38 +02:00
|
|
|
// Mark the initialization as successful by default
|
2017-06-19 15:10:31 +02:00
|
|
|
const CoreState cs(SQMOD_SUCCESS);
|
2016-03-12 07:47:50 +01:00
|
|
|
// Attempt to forward the event
|
|
|
|
try
|
|
|
|
{
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE<] OnPickupPickAttempt")
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitPickupClaimed(pickup_id, player_id);
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE>] OnPickupPickAttempt")
|
2016-03-12 07:47:50 +01:00
|
|
|
}
|
2016-05-22 05:20:38 +02:00
|
|
|
SQMOD_CATCH_EVENT_EXCEPTION(OnPickupPickAttempt)
|
2016-03-24 08:32:44 +01:00
|
|
|
// See if a reload was requested
|
2016-05-22 05:20:38 +02:00
|
|
|
SQMOD_RELOAD_CHECK(false)
|
|
|
|
// Return the last known plug-in state
|
2021-01-30 07:51:39 +01:00
|
|
|
return ConvTo< uint8_t >::From(Core::Get().GetState());
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-05-22 05:20:38 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
static void OnPickupPicked(int32_t pickup_id, int32_t player_id)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-03-12 07:47:50 +01:00
|
|
|
// Attempt to forward the event
|
|
|
|
try
|
|
|
|
{
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE<] OnPickupPicked")
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitPickupCollected(pickup_id, player_id);
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE>] OnPickupPicked")
|
2016-03-12 07:47:50 +01:00
|
|
|
}
|
2016-05-22 05:20:38 +02:00
|
|
|
SQMOD_CATCH_EVENT_EXCEPTION(OnPickupPicked)
|
2016-03-24 08:32:44 +01:00
|
|
|
// See if a reload was requested
|
2016-05-22 05:20:38 +02:00
|
|
|
SQMOD_RELOAD_CHECK(false)
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-05-22 05:20:38 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
static void OnPickupRespawn(int32_t pickup_id)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-03-12 07:47:50 +01:00
|
|
|
// Attempt to forward the event
|
|
|
|
try
|
|
|
|
{
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE<] OnPickupRespawn")
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitPickupRespawn(pickup_id);
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE>] OnPickupRespawn")
|
2016-03-12 07:47:50 +01:00
|
|
|
}
|
2016-05-22 05:20:38 +02:00
|
|
|
SQMOD_CATCH_EVENT_EXCEPTION(OnPickupRespawn)
|
2016-03-24 08:32:44 +01:00
|
|
|
// See if a reload was requested
|
2016-05-22 05:20:38 +02:00
|
|
|
SQMOD_RELOAD_CHECK(false)
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-05-22 05:20:38 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
static void OnCheckpointEntered(int32_t checkpoint_id, int32_t player_id)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-03-12 07:47:50 +01:00
|
|
|
// Attempt to forward the event
|
|
|
|
try
|
|
|
|
{
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE<] OnCheckpointEntered")
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitCheckpointEntered(checkpoint_id, player_id);
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE>] OnCheckpointEntered")
|
2016-03-12 07:47:50 +01:00
|
|
|
}
|
2016-05-22 05:20:38 +02:00
|
|
|
SQMOD_CATCH_EVENT_EXCEPTION(OnCheckpointEntered)
|
2016-03-24 08:32:44 +01:00
|
|
|
// See if a reload was requested
|
2016-05-22 05:20:38 +02:00
|
|
|
SQMOD_RELOAD_CHECK(false)
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-05-22 05:20:38 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
static void OnCheckpointExited(int32_t checkpoint_id, int32_t player_id)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-03-12 07:47:50 +01:00
|
|
|
// Attempt to forward the event
|
|
|
|
try
|
|
|
|
{
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE<] OnCheckpointExited")
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitCheckpointExited(checkpoint_id, player_id);
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE>] OnCheckpointExited")
|
2016-03-12 07:47:50 +01:00
|
|
|
}
|
2016-05-22 05:20:38 +02:00
|
|
|
SQMOD_CATCH_EVENT_EXCEPTION(OnCheckpointExited)
|
2016-03-24 08:32:44 +01:00
|
|
|
// See if a reload was requested
|
2016-05-22 05:20:38 +02:00
|
|
|
SQMOD_RELOAD_CHECK(false)
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-05-22 05:20:38 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
static void OnEntityPoolChange(vcmpEntityPool entity_type, int32_t entity_id, uint8_t is_deleted)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-03-12 07:47:50 +01:00
|
|
|
// Attempt to forward the event
|
|
|
|
try
|
|
|
|
{
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE<] OnEntityPoolChange")
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitEntityPool(entity_type, entity_id, is_deleted);
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE>] OnEntityPoolChange")
|
2016-03-12 07:47:50 +01:00
|
|
|
}
|
2016-05-22 05:20:38 +02:00
|
|
|
SQMOD_CATCH_EVENT_EXCEPTION(OnEntityPoolChange)
|
2016-03-24 08:32:44 +01:00
|
|
|
// See if a reload was requested
|
2016-05-22 05:20:38 +02:00
|
|
|
SQMOD_RELOAD_CHECK(false)
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2019-06-01 23:39:06 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-03-20 19:37:17 +01:00
|
|
|
#if SQMOD_SDK_LEAST(2, 1)
|
2019-06-01 23:39:06 +02:00
|
|
|
static void OnEntityStreamingChange(int32_t player_id, int32_t entity_id, vcmpEntityPool entity_type, uint8_t is_deleted)
|
|
|
|
{
|
|
|
|
// Attempt to forward the event
|
|
|
|
try
|
|
|
|
{
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE<] OnEntityStreamingChange")
|
2019-06-01 23:39:06 +02:00
|
|
|
Core::Get().EmitEntityStreaming(player_id, entity_id, entity_type, is_deleted);
|
2019-06-02 14:11:48 +02:00
|
|
|
SQMOD_SV_EV_TRACEBACK("[TRACE>] OnEntityStreamingChange")
|
2019-06-01 23:39:06 +02:00
|
|
|
}
|
|
|
|
SQMOD_CATCH_EVENT_EXCEPTION(OnEntityStreamingChange)
|
|
|
|
// See if a reload was requested
|
|
|
|
SQMOD_RELOAD_CHECK(false)
|
|
|
|
}
|
2020-03-20 19:37:17 +01:00
|
|
|
#endif
|
2016-05-22 05:20:38 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
static void OnServerPerformanceReport(size_t /*entry_count*/, const char * * /*descriptions*/, uint64_t * /*times*/)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2019-06-02 17:13:04 +02:00
|
|
|
//SQMOD_SV_EV_TRACEBACK("[TRACE<] OnServerPerformanceReport")
|
2016-05-22 05:20:38 +02:00
|
|
|
// Ignored for now...
|
2019-06-02 17:13:04 +02:00
|
|
|
//SQMOD_SV_EV_TRACEBACK("[TRACE>] OnServerPerformanceReport")
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-16 20:51:01 +02:00
|
|
|
} // Namespace:: SqMod
|
|
|
|
|
2022-06-24 21:51:20 +02:00
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
|
|
* Automatically terminate the third-party allocator.
|
|
|
|
*/
|
|
|
|
static std::unique_ptr< SqMod::RPMallocInit > gsRPMallocInit;
|
|
|
|
|
2016-07-16 20:51:01 +02:00
|
|
|
/* ------------------------------------------------------------------------------------------------
|
2020-09-06 19:11:53 +02:00
|
|
|
* Plug-in initialization procedure.
|
2016-07-16 20:51:01 +02:00
|
|
|
*/
|
|
|
|
SQMOD_API_EXPORT unsigned int VcmpPluginInit(PluginFuncs * funcs, PluginCallbacks * calls, PluginInfo * info)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-07-16 20:51:01 +02:00
|
|
|
using namespace SqMod;
|
|
|
|
// Output plug-in header
|
|
|
|
puts("");
|
|
|
|
OutputMessage("--------------------------------------------------------------------");
|
|
|
|
OutputMessage("Plug-in: %s", SQMOD_NAME);
|
|
|
|
OutputMessage("Author: %s", SQMOD_AUTHOR);
|
|
|
|
OutputMessage("Legal: %s", SQMOD_COPYRIGHT);
|
|
|
|
OutputMessage("--------------------------------------------------------------------");
|
|
|
|
puts("");
|
|
|
|
// Store server proxies
|
|
|
|
_Func = funcs;
|
|
|
|
_Clbk = calls;
|
|
|
|
_Info = info;
|
|
|
|
// Assign plug-in version
|
|
|
|
_Info->pluginVersion = SQMOD_VERSION;
|
|
|
|
_Info->apiMajorVersion = PLUGIN_API_MAJOR;
|
|
|
|
_Info->apiMinorVersion = PLUGIN_API_MINOR;
|
|
|
|
// Assign the plug-in name
|
|
|
|
std::snprintf(_Info->name, sizeof(_Info->name), "%s", SQMOD_HOST_NAME);
|
2023-08-05 20:31:33 +02:00
|
|
|
// Initialize CURL
|
|
|
|
curl_global_init(CURL_GLOBAL_DEFAULT);
|
2022-06-24 21:51:20 +02:00
|
|
|
// Initialize third-party allocator
|
|
|
|
gsRPMallocInit = std::make_unique< RPMallocInit >();
|
2016-07-16 20:51:01 +02:00
|
|
|
// Attempt to initialize the logger before anything else
|
|
|
|
Logger::Get().Initialize(nullptr);
|
|
|
|
// Attempt to initialize the plug-in core
|
2018-07-27 21:43:19 +02:00
|
|
|
try
|
2016-07-16 20:51:01 +02:00
|
|
|
{
|
2021-01-30 23:16:10 +01:00
|
|
|
// External plugs that need to happen (once) before initialization
|
2021-09-07 19:55:05 +02:00
|
|
|
InitializeNet();
|
2021-01-30 23:16:10 +01:00
|
|
|
InitializePocoDataConnectors();
|
|
|
|
// Proceed with plug-in initialization
|
2018-07-27 21:43:19 +02:00
|
|
|
if (!Core::Get().Initialize())
|
|
|
|
{
|
|
|
|
LogFtl("Unable to initialize the plug-in central core");
|
|
|
|
// Attempt to terminate
|
|
|
|
Core::Get().Terminate(false);
|
|
|
|
// Stop here!
|
|
|
|
return SQMOD_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
2021-02-20 20:22:12 +01:00
|
|
|
catch (const Poco::Exception & e)
|
|
|
|
{
|
|
|
|
LogErr("Program exception caught during initialization");
|
|
|
|
LogSInf("Message: %s", e.displayText().c_str());
|
|
|
|
}
|
2018-07-27 21:43:19 +02:00
|
|
|
catch (const Sqrat::Exception & e)
|
|
|
|
{
|
|
|
|
LogErr("Squirrel exception caught during initialization");
|
|
|
|
LogSInf("Message: %s", e.what());
|
|
|
|
}
|
|
|
|
catch (const std::exception & e)
|
|
|
|
{
|
|
|
|
LogErr("System exception caught during initialization");
|
|
|
|
LogSInf("Message: %s", e.what());
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
LogErr("Unknown exception caught during initialization");
|
2016-07-16 20:51:01 +02:00
|
|
|
}
|
|
|
|
// Bind to the server callbacks
|
2016-05-22 05:20:38 +02:00
|
|
|
_Clbk->OnServerInitialise = OnServerInitialise;
|
|
|
|
_Clbk->OnServerShutdown = OnServerShutdown;
|
|
|
|
_Clbk->OnServerFrame = OnServerFrame;
|
|
|
|
_Clbk->OnPluginCommand = OnPluginCommand;
|
|
|
|
_Clbk->OnIncomingConnection = OnIncomingConnection;
|
|
|
|
_Clbk->OnClientScriptData = OnClientScriptData;
|
|
|
|
_Clbk->OnPlayerConnect = OnPlayerConnect;
|
|
|
|
_Clbk->OnPlayerDisconnect = OnPlayerDisconnect;
|
|
|
|
_Clbk->OnPlayerRequestClass = OnPlayerRequestClass;
|
|
|
|
_Clbk->OnPlayerRequestSpawn = OnPlayerRequestSpawn;
|
|
|
|
_Clbk->OnPlayerSpawn = OnPlayerSpawn;
|
|
|
|
_Clbk->OnPlayerDeath = OnPlayerDeath;
|
|
|
|
_Clbk->OnPlayerUpdate = OnPlayerUpdate;
|
|
|
|
_Clbk->OnPlayerRequestEnterVehicle = OnPlayerRequestEnterVehicle;
|
|
|
|
_Clbk->OnPlayerEnterVehicle = OnPlayerEnterVehicle;
|
|
|
|
_Clbk->OnPlayerExitVehicle = OnPlayerExitVehicle;
|
|
|
|
_Clbk->OnPlayerNameChange = OnPlayerNameChange;
|
|
|
|
_Clbk->OnPlayerStateChange = OnPlayerStateChange;
|
|
|
|
_Clbk->OnPlayerActionChange = OnPlayerActionChange;
|
|
|
|
_Clbk->OnPlayerOnFireChange = OnPlayerOnFireChange;
|
|
|
|
_Clbk->OnPlayerCrouchChange = OnPlayerCrouchChange;
|
|
|
|
_Clbk->OnPlayerGameKeysChange = OnPlayerGameKeysChange;
|
|
|
|
_Clbk->OnPlayerBeginTyping = OnPlayerBeginTyping;
|
|
|
|
_Clbk->OnPlayerEndTyping = OnPlayerEndTyping;
|
|
|
|
_Clbk->OnPlayerAwayChange = OnPlayerAwayChange;
|
|
|
|
_Clbk->OnPlayerMessage = OnPlayerMessage;
|
|
|
|
_Clbk->OnPlayerCommand = OnPlayerCommand;
|
|
|
|
_Clbk->OnPlayerPrivateMessage = OnPlayerPrivateMessage;
|
|
|
|
_Clbk->OnPlayerKeyBindDown = OnPlayerKeyBindDown;
|
|
|
|
_Clbk->OnPlayerKeyBindUp = OnPlayerKeyBindUp;
|
|
|
|
_Clbk->OnPlayerSpectate = OnPlayerSpectate;
|
|
|
|
_Clbk->OnPlayerCrashReport = OnPlayerCrashReport;
|
|
|
|
_Clbk->OnVehicleUpdate = OnVehicleUpdate;
|
|
|
|
_Clbk->OnVehicleExplode = OnVehicleExplode;
|
|
|
|
_Clbk->OnVehicleRespawn = OnVehicleRespawn;
|
|
|
|
_Clbk->OnObjectShot = OnObjectShot;
|
|
|
|
_Clbk->OnObjectTouched = OnObjectTouched;
|
|
|
|
_Clbk->OnPickupPickAttempt = OnPickupPickAttempt;
|
|
|
|
_Clbk->OnPickupPicked = OnPickupPicked;
|
|
|
|
_Clbk->OnPickupRespawn = OnPickupRespawn;
|
|
|
|
_Clbk->OnCheckpointEntered = OnCheckpointEntered;
|
|
|
|
_Clbk->OnCheckpointExited = OnCheckpointExited;
|
|
|
|
_Clbk->OnEntityPoolChange = OnEntityPoolChange;
|
|
|
|
_Clbk->OnServerPerformanceReport = OnServerPerformanceReport;
|
2018-06-28 20:41:31 +02:00
|
|
|
_Clbk->OnPlayerModuleList = OnPlayerModuleList;
|
2020-03-20 19:37:17 +01:00
|
|
|
#if SQMOD_SDK_LEAST(2, 1)
|
2019-06-01 23:39:06 +02:00
|
|
|
_Clbk->OnEntityStreamingChange = OnEntityStreamingChange;
|
2020-03-20 19:37:17 +01:00
|
|
|
#endif
|
2016-06-03 20:26:19 +02:00
|
|
|
// Attempt to initialize the plug-in exports
|
2023-03-05 14:38:59 +01:00
|
|
|
InitExports();
|
2016-05-22 05:20:38 +02:00
|
|
|
// Dummy spacing
|
|
|
|
puts("");
|
|
|
|
// Initialization was successful
|
|
|
|
return SQMOD_SUCCESS;
|
2015-11-08 21:31:03 +01:00
|
|
|
}
|