2016-05-22 05:20:38 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-09-30 02:56:11 +02:00
|
|
|
#include "Logger.hpp"
|
|
|
|
#include "Core.hpp"
|
2016-02-27 10:57:10 +01:00
|
|
|
#include "SqMod.h"
|
2015-09-30 02:56:11 +02:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-05-22 05:20:38 +02:00
|
|
|
#include <cstdio>
|
2015-10-30 03:17:18 +01:00
|
|
|
|
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
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-23 16:48:30 +01:00
|
|
|
extern void InitExports();
|
2016-05-23 02:54:50 +02:00
|
|
|
extern void ProcessRoutines();
|
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
|
2016-05-24 05:51:40 +02:00
|
|
|
const ReloadGuard rg;
|
|
|
|
// 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) /*
|
|
|
|
*/ catch (const Sqrat::Exception & e) /*
|
|
|
|
*/ { /*
|
2016-05-22 05:20:38 +02:00
|
|
|
*/ LogErr("Squirrel exception caught (" #ev ") event"); /*
|
2016-07-09 13:18:09 +02:00
|
|
|
*/ LogInf("Message: %s", e.what()); /*
|
2016-03-12 07:47:50 +01:00
|
|
|
*/ } /*
|
|
|
|
*/ catch (const std::exception & e) /*
|
|
|
|
*/ { /*
|
2016-05-22 05:20:38 +02:00
|
|
|
*/ LogErr("Program exception caught (" #ev ") event"); /*
|
2016-03-12 07:47:50 +01:00
|
|
|
*/ LogInf("Message: %s", e.what()); /*
|
|
|
|
*/ } /*
|
|
|
|
*/ catch (...) /*
|
|
|
|
*/ { /*
|
2016-05-22 05:20:38 +02:00
|
|
|
*/ LogErr("Unknown exception caught (" #ev ") event"); /*
|
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
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
static uint8_t OnServerInitialise(void)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-03-12 07:47:50 +01:00
|
|
|
// Mark the initialization as successful by default
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().SetState(SQMOD_SUCCESS);
|
2016-03-12 07:47:50 +01:00
|
|
|
// Attempt to forward the event
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// Signal outside plug-ins to do fetch our proxies
|
2016-07-17 02:56:52 +02:00
|
|
|
_Func->SendPluginCommand(SQMOD_INITIALIZE_CMD, "%d", SQMOD_API_VER);
|
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();
|
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
|
|
|
|
{
|
2016-08-25 11:00:48 +02:00
|
|
|
OutputError("Unable to load the plug-in resources properly");
|
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
|
2016-06-03 20:26:19 +02:00
|
|
|
return ConvTo< Uint8 >::From(Core::Get().GetState());
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-05-22 05:20:38 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
static void OnServerShutdown(void)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-03-12 07:47:50 +01:00
|
|
|
// Attempt to forward the event
|
|
|
|
try
|
|
|
|
{
|
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);
|
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)
|
2016-05-22 05:20:38 +02:00
|
|
|
// The server still triggers callbacks and we deallocated everything!
|
2016-07-16 20:51:01 +02:00
|
|
|
_Clbk->OnServerInitialise = nullptr;
|
|
|
|
_Clbk->OnServerShutdown = nullptr;
|
|
|
|
_Clbk->OnServerFrame = nullptr;
|
|
|
|
_Clbk->OnPluginCommand = nullptr;
|
|
|
|
_Clbk->OnIncomingConnection = nullptr;
|
|
|
|
_Clbk->OnClientScriptData = nullptr;
|
|
|
|
_Clbk->OnPlayerConnect = nullptr;
|
|
|
|
_Clbk->OnPlayerDisconnect = nullptr;
|
|
|
|
_Clbk->OnPlayerRequestClass = nullptr;
|
|
|
|
_Clbk->OnPlayerRequestSpawn = nullptr;
|
|
|
|
_Clbk->OnPlayerSpawn = nullptr;
|
|
|
|
_Clbk->OnPlayerDeath = nullptr;
|
|
|
|
_Clbk->OnPlayerUpdate = nullptr;
|
|
|
|
_Clbk->OnPlayerRequestEnterVehicle = nullptr;
|
|
|
|
_Clbk->OnPlayerEnterVehicle = nullptr;
|
|
|
|
_Clbk->OnPlayerExitVehicle = nullptr;
|
|
|
|
_Clbk->OnPlayerNameChange = nullptr;
|
|
|
|
_Clbk->OnPlayerStateChange = nullptr;
|
|
|
|
_Clbk->OnPlayerActionChange = nullptr;
|
|
|
|
_Clbk->OnPlayerOnFireChange = nullptr;
|
|
|
|
_Clbk->OnPlayerCrouchChange = nullptr;
|
|
|
|
_Clbk->OnPlayerGameKeysChange = nullptr;
|
|
|
|
_Clbk->OnPlayerBeginTyping = nullptr;
|
|
|
|
_Clbk->OnPlayerEndTyping = nullptr;
|
|
|
|
_Clbk->OnPlayerAwayChange = nullptr;
|
|
|
|
_Clbk->OnPlayerMessage = nullptr;
|
|
|
|
_Clbk->OnPlayerCommand = nullptr;
|
|
|
|
_Clbk->OnPlayerPrivateMessage = nullptr;
|
|
|
|
_Clbk->OnPlayerKeyBindDown = nullptr;
|
|
|
|
_Clbk->OnPlayerKeyBindUp = nullptr;
|
|
|
|
_Clbk->OnPlayerSpectate = nullptr;
|
|
|
|
_Clbk->OnPlayerCrashReport = nullptr;
|
|
|
|
_Clbk->OnVehicleUpdate = nullptr;
|
|
|
|
_Clbk->OnVehicleExplode = nullptr;
|
|
|
|
_Clbk->OnVehicleRespawn = nullptr;
|
|
|
|
_Clbk->OnObjectShot = nullptr;
|
|
|
|
_Clbk->OnObjectTouched = nullptr;
|
|
|
|
_Clbk->OnPickupPickAttempt = nullptr;
|
|
|
|
_Clbk->OnPickupPicked = nullptr;
|
|
|
|
_Clbk->OnPickupRespawn = nullptr;
|
|
|
|
_Clbk->OnCheckpointEntered = nullptr;
|
|
|
|
_Clbk->OnCheckpointExited = nullptr;
|
|
|
|
_Clbk->OnEntityPoolChange = nullptr;
|
|
|
|
_Clbk->OnServerPerformanceReport = nullptr;
|
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
|
|
|
|
{
|
2016-05-23 02:54:50 +02:00
|
|
|
// Now forward the event
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitServerFrame(elapsed_time);
|
2016-03-12 07:47:50 +01:00
|
|
|
}
|
2016-05-22 05:20:38 +02:00
|
|
|
SQMOD_CATCH_EVENT_EXCEPTION(OnServerFrame)
|
2016-05-23 02:54:50 +02:00
|
|
|
// Process routines, if any
|
|
|
|
ProcessRoutines();
|
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 OnPluginCommand(uint32_t command_identifier, CCStr message)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-05-22 05:20:38 +02:00
|
|
|
// Mark the initialization as successful by default
|
|
|
|
Core::Get().SetState(SQMOD_SUCCESS);
|
2016-03-12 07:47:50 +01:00
|
|
|
// Attempt to forward the event
|
|
|
|
try
|
|
|
|
{
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitPluginCommand(command_identifier, message);
|
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
|
2016-06-03 20:26:19 +02:00
|
|
|
return ConvTo< Uint8 >::From(Core::Get().GetState());
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-05-22 05:20:38 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
static uint8_t OnIncomingConnection(CStr player_name, size_t name_buffer_size,
|
|
|
|
CCStr user_password, CCStr 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
|
|
|
|
Core::Get().SetState(SQMOD_SUCCESS);
|
2016-03-12 07:47:50 +01:00
|
|
|
// Attempt to forward the event
|
|
|
|
try
|
|
|
|
{
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitIncomingConnection(player_name, name_buffer_size, user_password, ip_address);
|
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
|
2016-06-03 20:26:19 +02:00
|
|
|
return ConvTo< Uint8 >::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
|
|
|
|
{
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitClientScriptData(player_id, data, size);
|
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
|
|
|
|
{
|
|
|
|
Core::Get().ConnectPlayer(player_id, SQMOD_CREATE_AUTOMATIC, NullObject());
|
|
|
|
}
|
|
|
|
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
|
|
|
|
{
|
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
|
|
|
|
{
|
|
|
|
Core::Get().DisconnectPlayer(player_id, reason, NullObject());
|
|
|
|
}
|
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
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().SetState(SQMOD_SUCCESS);
|
2016-03-12 07:47:50 +01:00
|
|
|
// Attempt to forward the event
|
|
|
|
try
|
|
|
|
{
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitPlayerRequestClass(player_id, offset);
|
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
|
2016-06-03 20:26:19 +02:00
|
|
|
return ConvTo< Uint8 >::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
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().SetState(SQMOD_SUCCESS);
|
2016-03-12 07:47:50 +01:00
|
|
|
// Attempt to forward the event
|
|
|
|
try
|
|
|
|
{
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitPlayerRequestSpawn(player_id);
|
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
|
2016-06-03 20:26:19 +02:00
|
|
|
return ConvTo< Uint8 >::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
|
|
|
|
{
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitPlayerSpawn(player_id);
|
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
|
|
|
|
{
|
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
|
|
|
|
{
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitPlayerWasted(player_id, reason);
|
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
|
|
|
|
{
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitPlayerUpdate(player_id, update_type);
|
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
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().SetState(SQMOD_SUCCESS);
|
2016-03-12 07:47:50 +01:00
|
|
|
// Attempt to forward the event
|
|
|
|
try
|
|
|
|
{
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitPlayerEmbarking(player_id, vehicle_id, slot_index);
|
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
|
2016-06-03 20:26:19 +02:00
|
|
|
return ConvTo< Uint8 >::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
|
|
|
|
{
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitPlayerEmbarked(player_id, vehicle_id, slot_index);
|
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
|
|
|
|
{
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitPlayerDisembark(player_id, vehicle_id);
|
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
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
static void OnPlayerNameChange(int32_t player_id, CCStr old_name, CCStr new_name)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-03-12 07:47:50 +01:00
|
|
|
// Attempt to forward the event
|
|
|
|
try
|
|
|
|
{
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitPlayerRename(player_id, old_name, new_name);
|
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
|
|
|
{
|
2016-03-12 07:47:50 +01:00
|
|
|
// Attempt to forward the event
|
|
|
|
try
|
|
|
|
{
|
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;
|
|
|
|
default: LogErr("Unknown player state change: %d", static_cast< Int32 >(new_state));
|
|
|
|
}
|
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
|
|
|
{
|
2016-03-12 07:47:50 +01:00
|
|
|
// Attempt to forward the event
|
|
|
|
try
|
|
|
|
{
|
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;
|
|
|
|
}
|
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
|
|
|
|
{
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitPlayerBurning(player_id, is_on_fire);
|
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
|
|
|
|
{
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitPlayerCrouching(player_id, is_crouching);
|
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
|
|
|
|
{
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitPlayerGameKeys(player_id, old_keys, new_keys);
|
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
|
|
|
|
{
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitPlayerStartTyping(player_id);
|
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
|
|
|
|
{
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitPlayerStopTyping(player_id);
|
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
|
|
|
|
{
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitPlayerAway(player_id, is_away);
|
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
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
static uint8_t OnPlayerMessage(int32_t player_id, CCStr message)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-03-12 07:47:50 +01:00
|
|
|
// Mark the initialization as successful by default
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().SetState(SQMOD_SUCCESS);
|
2016-03-12 07:47:50 +01:00
|
|
|
// Attempt to forward the event
|
|
|
|
try
|
|
|
|
{
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitPlayerMessage(player_id, message);
|
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
|
2016-06-03 20:26:19 +02:00
|
|
|
return ConvTo< Uint8 >::From(Core::Get().GetState());
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-05-22 05:20:38 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
static uint8_t OnPlayerCommand(int32_t player_id, CCStr message)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-03-12 07:47:50 +01:00
|
|
|
// Mark the initialization as successful by default
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().SetState(SQMOD_SUCCESS);
|
2016-03-12 07:47:50 +01:00
|
|
|
// Attempt to forward the event
|
|
|
|
try
|
|
|
|
{
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitPlayerCommand(player_id, message);
|
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
|
2016-06-03 20:26:19 +02:00
|
|
|
return ConvTo< Uint8 >::From(Core::Get().GetState());
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-05-22 05:20:38 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
static uint8_t OnPlayerPrivateMessage(int32_t player_id, int32_t target_player_id, CCStr message)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-03-12 07:47:50 +01:00
|
|
|
// Mark the initialization as successful by default
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().SetState(SQMOD_SUCCESS);
|
2016-03-12 07:47:50 +01:00
|
|
|
// Attempt to forward the event
|
|
|
|
try
|
|
|
|
{
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitPlayerPrivateMessage(player_id, target_player_id, message);
|
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
|
2016-06-03 20:26:19 +02:00
|
|
|
return ConvTo< Uint8 >::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
|
|
|
|
{
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitPlayerKeyPress(player_id, bind_id);
|
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
|
|
|
|
{
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitPlayerKeyRelease(player_id, bind_id);
|
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
|
|
|
|
{
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitPlayerSpectate(player_id, target_player_id);
|
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
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
static void OnPlayerCrashReport(int32_t player_id, CCStr report)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-03-12 07:47:50 +01:00
|
|
|
// Attempt to forward the event
|
|
|
|
try
|
|
|
|
{
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitPlayerCrashreport(player_id, report);
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
|
{
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitVehicleUpdate(vehicle_id, update_type);
|
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
|
|
|
|
{
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitVehicleExplode(vehicle_id);
|
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
|
|
|
|
{
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitVehicleRespawn(vehicle_id);
|
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
|
|
|
|
{
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitObjectShot(object_id, player_id, weapon_id);
|
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
|
|
|
|
{
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitObjectTouched(object_id, player_id);
|
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
|
|
|
|
Core::Get().SetState(SQMOD_SUCCESS);
|
2016-03-12 07:47:50 +01:00
|
|
|
// Attempt to forward the event
|
|
|
|
try
|
|
|
|
{
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitPickupClaimed(pickup_id, player_id);
|
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
|
2016-06-03 20:26:19 +02:00
|
|
|
return ConvTo< Uint8 >::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
|
|
|
|
{
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitPickupCollected(pickup_id, player_id);
|
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
|
|
|
|
{
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitPickupRespawn(pickup_id);
|
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
|
|
|
|
{
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitCheckpointEntered(checkpoint_id, player_id);
|
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
|
|
|
|
{
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitCheckpointExited(checkpoint_id, player_id);
|
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
|
|
|
|
{
|
2016-05-22 05:20:38 +02:00
|
|
|
Core::Get().EmitEntityPool(entity_type, entity_id, is_deleted);
|
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
|
|
|
}
|
|
|
|
|
2016-05-22 05:20:38 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
static void OnServerPerformanceReport(size_t /*entry_count*/, CCStr * /*descriptions*/, uint64_t * /*times*/)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-05-22 05:20:38 +02:00
|
|
|
// Ignored for now...
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-16 20:51:01 +02:00
|
|
|
} // Namespace:: SqMod
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
|
|
* Plugiun initialization procedure.
|
|
|
|
*/
|
|
|
|
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);
|
|
|
|
// Attempt to initialize the logger before anything else
|
|
|
|
Logger::Get().Initialize(nullptr);
|
|
|
|
// Attempt to initialize the plug-in core
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
// 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;
|
2016-06-03 20:26:19 +02:00
|
|
|
// Attempt to initialize the plug-in exports
|
2016-05-22 05:20:38 +02:00
|
|
|
InitExports();
|
|
|
|
// Dummy spacing
|
|
|
|
puts("");
|
|
|
|
// Initialization was successful
|
|
|
|
return SQMOD_SUCCESS;
|
2015-11-08 21:31:03 +01:00
|
|
|
}
|