2017-09-02 03:45:06 -04:00
2012-06-14 09:06:06 -04:00
# pragma once
2013-05-26 16:18:56 -04:00
2020-04-03 02:57:01 -04:00
# include "../BlockType.h"
2018-08-28 20:51:25 -04:00
# include "../Defines.h"
# include "../FunctionRef.h"
2013-05-26 16:18:56 -04:00
2012-06-14 09:06:06 -04:00
2012-06-14 13:30:37 -04:00
2015-04-19 04:57:41 -04:00
// fwd:
class cBlockEntityWithItems ;
2015-09-24 04:48:33 -04:00
class cBrewingstandEntity ;
2013-01-25 05:12:29 -05:00
class cChunkDesc ;
2015-04-19 04:57:41 -04:00
class cClientHandle ;
class cCommandOutputCallback ;
2012-06-14 09:06:06 -04:00
class cCraftingGrid ;
class cCraftingRecipe ;
2015-04-19 04:57:41 -04:00
class cEntity ;
class cHopperEntity ;
class cItems ;
class cMonster ;
2012-08-24 05:49:00 -04:00
class cPickup ;
2015-04-19 04:57:41 -04:00
class cPlayer ;
class cPlugin ;
class cProjectileEntity ;
2017-08-17 10:27:43 -04:00
class cWindow ;
2015-04-19 04:57:41 -04:00
class cWorld ;
2015-05-14 10:47:51 -04:00
class cSettingsRepositoryInterface ;
2017-01-17 16:38:04 -05:00
class cDeadlockDetect ;
2012-12-21 06:04:08 -05:00
struct TakeDamageInfo ;
2017-07-20 07:19:18 -04:00
typedef std : : shared_ptr < cPlugin > cPluginPtr ;
2015-04-19 04:57:41 -04:00
typedef std : : vector < cPluginPtr > cPluginPtrs ;
2013-06-29 11:30:05 -04:00
2013-08-11 08:57:07 -04:00
2014-09-26 11:26:03 -04:00
2012-06-14 09:06:06 -04:00
2014-07-17 16:50:58 -04:00
// tolua_begin
class cPluginManager
{
public :
2015-04-19 04:57:41 -04:00
2014-06-17 08:55:15 -04:00
enum CommandResult
{
crExecuted ,
crUnknownCommand ,
crError ,
2014-06-17 10:19:31 -04:00
crBlocked ,
crNoPermission ,
2014-06-17 08:55:15 -04:00
} ;
2015-04-19 04:57:41 -04:00
/** Defines the status of a single plugin - whether it is loaded, disabled or errored. */
enum ePluginStatus
{
/** The plugin has been loaded successfully. */
psLoaded ,
/** The plugin is disabled in settings.ini. */
psDisabled ,
/** The plugin is enabled in settings.ini but has been unloaded (by a command). */
psUnloaded ,
/** The plugin is enabled in settings.ini but has failed to load.
m_LoadError is the description of the error . */
psError ,
/** The plugin has been loaded before, but after a folder refresh it is no longer present.
The plugin will be unloaded in the next call to ReloadPlugins ( ) . */
psNotFound ,
} ;
2012-06-14 09:06:06 -04:00
enum PluginHook
{
2014-03-16 09:38:41 -04:00
HOOK_BLOCK_SPREAD ,
2013-01-26 21:00:33 -05:00
HOOK_BLOCK_TO_PICKUPS ,
2015-09-24 04:48:33 -04:00
HOOK_BREWING_COMPLETING ,
HOOK_BREWING_COMPLETED ,
2012-06-14 09:06:06 -04:00
HOOK_CHAT ,
2013-02-05 14:57:22 -05:00
HOOK_CHUNK_AVAILABLE ,
2013-01-11 23:46:01 -05:00
HOOK_CHUNK_GENERATED ,
HOOK_CHUNK_GENERATING ,
2013-02-05 14:57:22 -05:00
HOOK_CHUNK_UNLOADED ,
HOOK_CHUNK_UNLOADING ,
2013-01-28 11:17:26 -05:00
HOOK_COLLECTING_PICKUP ,
2013-01-11 23:46:01 -05:00
HOOK_CRAFTING_NO_RECIPE ,
2012-06-14 09:06:06 -04:00
HOOK_DISCONNECT ,
2013-12-18 11:11:15 -05:00
HOOK_PLAYER_ANIMATION ,
2014-06-13 06:47:01 -04:00
HOOK_ENTITY_ADD_EFFECT ,
2015-05-21 06:27:54 -04:00
HOOK_ENTITY_CHANGING_WORLD ,
2015-05-18 16:29:39 -04:00
HOOK_ENTITY_CHANGED_WORLD ,
2013-02-21 08:47:01 -05:00
HOOK_EXECUTE_COMMAND ,
Added OnExploding() and OnExploded() hooks.
As requested in FS 413, with extra parameters:
World, BlockX, BlockY, BlockZ, Size, CanCauseFire, Source, SourceData
OnExploding() can return 3 values:
StopHook, CanCauseFire, ExplosionSize
2013-08-09 08:58:43 -04:00
HOOK_EXPLODED ,
HOOK_EXPLODING ,
2012-06-14 09:06:06 -04:00
HOOK_HANDSHAKE ,
2013-08-11 08:57:07 -04:00
HOOK_HOPPER_PULLING_ITEM ,
HOOK_HOPPER_PUSHING_ITEM ,
2015-06-02 11:06:18 -04:00
HOOK_KILLED ,
2013-01-28 11:54:11 -05:00
HOOK_KILLING ,
2013-01-11 23:46:01 -05:00
HOOK_LOGIN ,
2017-08-27 17:10:20 -04:00
HOOK_LOGIN_FORGE ,
2013-01-11 23:46:01 -05:00
HOOK_PLAYER_BREAKING_BLOCK ,
HOOK_PLAYER_BROKEN_BLOCK ,
2014-01-25 05:25:22 -05:00
HOOK_PLAYER_DESTROYED ,
2013-01-11 23:46:01 -05:00
HOOK_PLAYER_EATING ,
2013-12-30 16:56:08 -05:00
HOOK_PLAYER_FISHED ,
HOOK_PLAYER_FISHING ,
2014-06-30 09:12:56 -04:00
HOOK_PLAYER_FOOD_LEVEL_CHANGE ,
2013-01-11 23:46:01 -05:00
HOOK_PLAYER_JOINED ,
HOOK_PLAYER_LEFT_CLICK ,
2013-01-26 02:50:06 -05:00
HOOK_PLAYER_MOVING ,
2017-08-17 10:27:43 -04:00
HOOK_PLAYER_OPENING_WINDOW ,
2013-01-11 23:46:01 -05:00
HOOK_PLAYER_PLACED_BLOCK ,
HOOK_PLAYER_PLACING_BLOCK ,
2020-03-23 08:18:12 -04:00
HOOK_PLAYER_CROUCHED ,
2013-01-18 13:28:27 -05:00
HOOK_PLAYER_RIGHT_CLICK ,
2013-08-02 02:44:06 -04:00
HOOK_PLAYER_RIGHT_CLICKING_ENTITY ,
2013-01-11 23:46:01 -05:00
HOOK_PLAYER_SHOOTING ,
HOOK_PLAYER_SPAWNED ,
2015-03-05 05:52:42 -05:00
HOOK_ENTITY_TELEPORT ,
2013-01-11 23:46:01 -05:00
HOOK_PLAYER_TOSSING_ITEM ,
HOOK_PLAYER_USED_BLOCK ,
HOOK_PLAYER_USED_ITEM ,
HOOK_PLAYER_USING_BLOCK ,
HOOK_PLAYER_USING_ITEM ,
2014-01-07 11:47:05 -05:00
HOOK_PLUGIN_MESSAGE ,
2013-12-29 06:51:58 -05:00
HOOK_PLUGINS_LOADED ,
2013-01-11 23:46:01 -05:00
HOOK_POST_CRAFTING ,
HOOK_PRE_CRAFTING ,
2014-03-29 11:00:45 -04:00
HOOK_PROJECTILE_HIT_BLOCK ,
2014-03-29 10:26:41 -04:00
HOOK_PROJECTILE_HIT_ENTITY ,
2014-08-16 12:02:16 -04:00
HOOK_SERVER_PING ,
2013-08-08 03:13:13 -04:00
HOOK_SPAWNED_ENTITY ,
HOOK_SPAWNED_MONSTER ,
HOOK_SPAWNING_ENTITY ,
HOOK_SPAWNING_MONSTER ,
2013-01-11 23:46:01 -05:00
HOOK_TAKE_DAMAGE ,
HOOK_TICK ,
HOOK_UPDATED_SIGN ,
HOOK_UPDATING_SIGN ,
HOOK_WEATHER_CHANGED ,
2013-02-13 14:22:08 -05:00
HOOK_WEATHER_CHANGING ,
2013-12-11 06:39:13 -05:00
HOOK_WORLD_STARTED ,
2013-08-19 03:28:22 -04:00
HOOK_WORLD_TICK ,
2015-04-13 06:33:25 -04:00
// tolua_end
2016-02-05 16:45:45 -05:00
2013-02-13 14:22:08 -05:00
// Note that if a hook type is added, it may need processing in cPlugin::CanAddHook() descendants,
2013-08-19 03:39:18 -04:00
// and it definitely needs adding in cPluginLua::GetHookFnName() !
2016-02-05 16:45:45 -05:00
2013-08-21 15:29:30 -04:00
// Keep these two as the last items, they are used for validity checking and get their values automagically
HOOK_NUM_HOOKS ,
HOOK_MAX = HOOK_NUM_HOOKS - 1 ,
2015-04-13 06:33:25 -04:00
} ; // tolua_export
2012-06-14 09:06:06 -04:00
2016-06-12 12:11:40 -04:00
2014-01-21 16:59:08 -05:00
/** Used as a callback for enumerating bound commands */
2013-02-01 14:55:42 -05:00
class cCommandEnumCallback
{
public :
2014-03-28 16:35:45 -04:00
virtual ~ cCommandEnumCallback ( ) { }
2016-02-05 16:45:45 -05:00
2013-02-15 08:00:59 -05:00
/** Called for each command; return true to abort enumeration
For console commands , a_Permission is not used ( set to empty string )
*/
2013-02-01 14:55:42 -05:00
virtual bool Command ( const AString & a_Command , const cPlugin * a_Plugin , const AString & a_Permission , const AString & a_HelpString ) = 0 ;
} ;
2016-02-05 16:45:45 -05:00
2016-06-12 12:11:40 -04:00
/** Interface that must be provided by any class that implements a command handler, either in-game or console command. */
class cCommandHandler
{
public :
// Force a virtual destructor in descendants
virtual ~ cCommandHandler ( ) { }
/** Executes the specified in-game command.
a_Split is the command string , split at the spaces .
a_Player is the player executing the command , nullptr in case of the console .
a_Command is the entire command string .
a_Output is the sink into which the additional text returned by the command handler should be sent ; only used for console commands . */
virtual bool ExecuteCommand (
const AStringVector & a_Split ,
cPlayer * a_Player ,
const AString & a_Command ,
cCommandOutputCallback * a_Output = nullptr
) = 0 ;
} ;
2017-07-20 07:19:18 -04:00
typedef std : : shared_ptr < cCommandHandler > cCommandHandlerPtr ;
2016-06-12 12:11:40 -04:00
2014-01-21 16:59:08 -05:00
/** The interface used for enumerating and extern-calling plugins */
2017-09-11 17:20:49 -04:00
using cPluginCallback = cFunctionRef < bool ( cPlugin & ) > ;
2016-02-05 16:45:45 -05:00
2015-04-19 04:57:41 -04:00
typedef std : : list < cPlugin * > PluginList ;
/** Called each tick, calls the plugins' OnTick hook, as well as processes plugin events (addition, removal) */
void Tick ( float a_Dt ) ;
2016-02-05 16:45:45 -05:00
2014-01-21 16:59:08 -05:00
/** Returns the instance of the Plugin Manager (there is only ever one) */
2014-07-17 16:50:58 -04:00
static cPluginManager * Get ( void ) ; // tolua_export
2012-06-14 09:06:06 -04:00
2015-04-19 04:57:41 -04:00
/** Refreshes the m_Plugins list based on the current contents of the Plugins folder.
If an active plugin ' s folder is not found anymore , the plugin is set as psNotFound , but not yet unloaded . */
void RefreshPluginList ( ) ; // tolua_export
2012-06-14 09:06:06 -04:00
2015-04-19 04:57:41 -04:00
/** Schedules a reload of the plugins to happen within the next call to Tick(). */
void ReloadPlugins ( ) ; // tolua_export
2016-02-05 16:45:45 -05:00
2015-04-19 04:57:41 -04:00
/** Adds the plugin to the list of plugins called for the specified hook type.
If a plugin adds multiple handlers for a single hook , it is added only once ( ignore - duplicates ) . */
2013-08-21 15:29:30 -04:00
void AddHook ( cPlugin * a_Plugin , int a_HookType ) ;
2013-01-11 23:46:01 -05:00
2015-04-19 04:57:41 -04:00
/** Returns the number of all plugins in m_Plugins (includes disabled, unloaded and errored plugins). */
2014-05-08 14:16:35 -04:00
size_t GetNumPlugins ( ) const ; // tolua_export
2015-04-19 04:57:41 -04:00
/** Returns the number of plugins that are psLoaded. */
size_t GetNumLoadedPlugins ( void ) const ; // tolua_export
2016-02-05 16:45:45 -05:00
2013-08-08 03:13:13 -04:00
// Calls for individual hooks. Each returns false if the action is to continue or true if the plugin wants to abort
2014-10-15 13:01:55 -04:00
bool CallHookBlockSpread ( cWorld & a_World , int a_BlockX , int a_BlockY , int a_BlockZ , eSpreadSource a_Source ) ;
2019-10-16 04:06:34 -04:00
bool CallHookBlockToPickups ( cWorld & a_World , Vector3i a_BlockPos , BLOCKTYPE a_BlockType , NIBBLETYPE a_BlockMeta , const cBlockEntity * a_BlockEntity , const cEntity * a_Digger , const cItem * a_Tool , cItems & a_Pickups ) ;
2015-09-24 04:48:33 -04:00
bool CallHookBrewingCompleting ( cWorld & a_World , cBrewingstandEntity & a_Brewingstand ) ;
bool CallHookBrewingCompleted ( cWorld & a_World , cBrewingstandEntity & a_Brewingstand ) ;
2014-10-15 13:01:55 -04:00
bool CallHookChat ( cPlayer & a_Player , AString & a_Message ) ;
bool CallHookChunkAvailable ( cWorld & a_World , int a_ChunkX , int a_ChunkZ ) ;
bool CallHookChunkGenerated ( cWorld & a_World , int a_ChunkX , int a_ChunkZ , cChunkDesc * a_ChunkDesc ) ;
bool CallHookChunkGenerating ( cWorld & a_World , int a_ChunkX , int a_ChunkZ , cChunkDesc * a_ChunkDesc ) ;
bool CallHookChunkUnloaded ( cWorld & a_World , int a_ChunkX , int a_ChunkZ ) ;
bool CallHookChunkUnloading ( cWorld & a_World , int a_ChunkX , int a_ChunkZ ) ;
bool CallHookCollectingPickup ( cPlayer & a_Player , cPickup & a_Pickup ) ;
2014-12-04 03:21:57 -05:00
bool CallHookCraftingNoRecipe ( cPlayer & a_Player , cCraftingGrid & a_Grid , cCraftingRecipe & a_Recipe ) ;
2014-05-02 05:18:02 -04:00
bool CallHookDisconnect ( cClientHandle & a_Client , const AString & a_Reason ) ;
2014-07-11 20:27:29 -04:00
bool CallHookEntityAddEffect ( cEntity & a_Entity , int a_EffectType , int a_EffectDurationTicks , int a_EffectIntensity , double a_DistanceModifier ) ;
2015-03-05 05:52:42 -05:00
bool CallHookEntityTeleport ( cEntity & a_Entity , const Vector3d & a_OldPosition , const Vector3d & a_NewPosition ) ;
2015-05-21 06:27:54 -04:00
bool CallHookEntityChangingWorld ( cEntity & a_Entity , cWorld & a_World ) ;
2015-05-18 16:29:39 -04:00
bool CallHookEntityChangedWorld ( cEntity & a_Entity , cWorld & a_World ) ;
2015-05-10 17:11:30 -04:00
bool CallHookExecuteCommand ( cPlayer * a_Player , const AStringVector & a_Split , const AString & a_EntireCommand , CommandResult & a_Result ) ; // If a_Player == nullptr, it is a console cmd
Added OnExploding() and OnExploded() hooks.
As requested in FS 413, with extra parameters:
World, BlockX, BlockY, BlockZ, Size, CanCauseFire, Source, SourceData
OnExploding() can return 3 values:
StopHook, CanCauseFire, ExplosionSize
2013-08-09 08:58:43 -04:00
bool CallHookExploded ( cWorld & a_World , double a_ExplosionSize , bool a_CanCauseFire , double a_X , double a_Y , double a_Z , eExplosionSource a_Source , void * a_SourceData ) ;
bool CallHookExploding ( cWorld & a_World , double & a_ExplosionSize , bool & a_CanCauseFire , double a_X , double a_Y , double a_Z , eExplosionSource a_Source , void * a_SourceData ) ;
2014-10-15 13:01:55 -04:00
bool CallHookHandshake ( cClientHandle & a_ClientHandle , const AString & a_Username ) ;
2013-08-11 08:57:07 -04:00
bool CallHookHopperPullingItem ( cWorld & a_World , cHopperEntity & a_Hopper , int a_DstSlotNum , cBlockEntityWithItems & a_SrcEntity , int a_SrcSlotNum ) ;
bool CallHookHopperPushingItem ( cWorld & a_World , cHopperEntity & a_Hopper , int a_SrcSlotNum , cBlockEntityWithItems & a_DstEntity , int a_DstSlotNum ) ;
2015-06-02 11:06:18 -04:00
bool CallHookKilled ( cEntity & a_Victim , TakeDamageInfo & a_TDI , AString & a_DeathMessage ) ;
2014-07-16 06:38:52 -04:00
bool CallHookKilling ( cEntity & a_Victim , cEntity * a_Killer , TakeDamageInfo & a_TDI ) ;
2015-07-29 11:04:03 -04:00
bool CallHookLogin ( cClientHandle & a_Client , UInt32 a_ProtocolVersion , const AString & a_Username ) ;
2017-08-27 17:10:20 -04:00
bool CallHookLoginForge ( cClientHandle & a_Client , AStringMap & a_Mods ) ;
2013-12-18 11:11:15 -05:00
bool CallHookPlayerAnimation ( cPlayer & a_Player , int a_Animation ) ;
2013-08-02 02:44:06 -04:00
bool CallHookPlayerBreakingBlock ( cPlayer & a_Player , int a_BlockX , int a_BlockY , int a_BlockZ , char a_BlockFace , BLOCKTYPE a_BlockType , NIBBLETYPE a_BlockMeta ) ;
bool CallHookPlayerBrokenBlock ( cPlayer & a_Player , int a_BlockX , int a_BlockY , int a_BlockZ , char a_BlockFace , BLOCKTYPE a_BlockType , NIBBLETYPE a_BlockMeta ) ;
2014-01-25 05:25:22 -05:00
bool CallHookPlayerDestroyed ( cPlayer & a_Player ) ;
2013-08-02 02:44:06 -04:00
bool CallHookPlayerEating ( cPlayer & a_Player ) ;
2015-01-16 10:42:19 -05:00
bool CallHookPlayerFished ( cPlayer & a_Player , const cItems & a_Reward ) ;
2014-01-01 09:09:53 -05:00
bool CallHookPlayerFishing ( cPlayer & a_Player , cItems a_Reward ) ;
2014-07-02 08:46:00 -04:00
bool CallHookPlayerFoodLevelChange ( cPlayer & a_Player , int a_NewFoodLevel ) ;
2013-08-02 02:44:06 -04:00
bool CallHookPlayerJoined ( cPlayer & a_Player ) ;
bool CallHookPlayerLeftClick ( cPlayer & a_Player , int a_BlockX , int a_BlockY , int a_BlockZ , char a_BlockFace , char a_Status ) ;
2020-03-23 08:18:12 -04:00
bool CallHookPlayerMoving ( cPlayer & a_Player , const Vector3d & a_OldPosition , const Vector3d & a_NewPosition , bool a_PreviousIsOnGround ) ;
2017-08-17 10:27:43 -04:00
bool CallHookPlayerOpeningWindow ( cPlayer & a_Player , cWindow & a_Window ) ;
2014-12-24 01:20:17 -05:00
bool CallHookPlayerPlacedBlock ( cPlayer & a_Player , const sSetBlock & a_BlockChange ) ;
bool CallHookPlayerPlacingBlock ( cPlayer & a_Player , const sSetBlock & a_BlockChange ) ;
2020-03-23 08:18:12 -04:00
bool CallHookPlayerCrouched ( cPlayer & a_Player ) ;
2013-08-02 02:44:06 -04:00
bool CallHookPlayerRightClick ( cPlayer & a_Player , int a_BlockX , int a_BlockY , int a_BlockZ , char a_BlockFace , int a_CursorX , int a_CursorY , int a_CursorZ ) ;
bool CallHookPlayerRightClickingEntity ( cPlayer & a_Player , cEntity & a_Entity ) ;
bool CallHookPlayerShooting ( cPlayer & a_Player ) ;
bool CallHookPlayerSpawned ( cPlayer & a_Player ) ;
bool CallHookPlayerTossingItem ( cPlayer & a_Player ) ;
bool CallHookPlayerUsedBlock ( cPlayer & a_Player , int a_BlockX , int a_BlockY , int a_BlockZ , char a_BlockFace , int a_CursorX , int a_CursorY , int a_CursorZ , BLOCKTYPE a_BlockType , NIBBLETYPE a_BlockMeta ) ;
bool CallHookPlayerUsedItem ( cPlayer & a_Player , int a_BlockX , int a_BlockY , int a_BlockZ , char a_BlockFace , int a_CursorX , int a_CursorY , int a_CursorZ ) ;
bool CallHookPlayerUsingBlock ( cPlayer & a_Player , int a_BlockX , int a_BlockY , int a_BlockZ , char a_BlockFace , int a_CursorX , int a_CursorY , int a_CursorZ , BLOCKTYPE a_BlockType , NIBBLETYPE a_BlockMeta ) ;
bool CallHookPlayerUsingItem ( cPlayer & a_Player , int a_BlockX , int a_BlockY , int a_BlockZ , char a_BlockFace , int a_CursorX , int a_CursorY , int a_CursorZ ) ;
2014-01-07 11:47:05 -05:00
bool CallHookPluginMessage ( cClientHandle & a_Client , const AString & a_Channel , const AString & a_Message ) ;
2013-12-29 06:51:58 -05:00
bool CallHookPluginsLoaded ( void ) ;
2014-10-15 13:01:55 -04:00
bool CallHookPostCrafting ( cPlayer & a_Player , cCraftingGrid & a_Grid , cCraftingRecipe & a_Recipe ) ;
bool CallHookPreCrafting ( cPlayer & a_Player , cCraftingGrid & a_Grid , cCraftingRecipe & a_Recipe ) ;
2014-06-01 08:06:47 -04:00
bool CallHookProjectileHitBlock ( cProjectileEntity & a_Projectile , int a_BlockX , int a_BlockY , int a_BlockZ , eBlockFace a_Face , const Vector3d & a_BlockHitPos ) ;
2014-03-29 10:26:41 -04:00
bool CallHookProjectileHitEntity ( cProjectileEntity & a_Projectile , cEntity & a_HitEntity ) ;
2014-08-20 16:22:38 -04:00
bool CallHookServerPing ( cClientHandle & a_ClientHandle , AString & a_ServerDescription , int & a_OnlinePlayersCount , int & a_MaxPlayersCount , AString & a_Favicon ) ;
2013-08-08 03:13:13 -04:00
bool CallHookSpawnedEntity ( cWorld & a_World , cEntity & a_Entity ) ;
bool CallHookSpawnedMonster ( cWorld & a_World , cMonster & a_Monster ) ;
bool CallHookSpawningEntity ( cWorld & a_World , cEntity & a_Entity ) ;
bool CallHookSpawningMonster ( cWorld & a_World , cMonster & a_Monster ) ;
2013-08-02 02:44:06 -04:00
bool CallHookTakeDamage ( cEntity & a_Receiver , TakeDamageInfo & a_TDI ) ;
2014-10-15 13:01:55 -04:00
bool CallHookUpdatedSign ( cWorld & a_World , int a_BlockX , int a_BlockY , int a_BlockZ , const AString & a_Line1 , const AString & a_Line2 , const AString & a_Line3 , const AString & a_Line4 , cPlayer * a_Player ) ;
bool CallHookUpdatingSign ( cWorld & a_World , int a_BlockX , int a_BlockY , int a_BlockZ , AString & a_Line1 , AString & a_Line2 , AString & a_Line3 , AString & a_Line4 , cPlayer * a_Player ) ;
2013-08-02 02:44:06 -04:00
bool CallHookWeatherChanged ( cWorld & a_World ) ;
bool CallHookWeatherChanging ( cWorld & a_World , eWeather & a_NewWeather ) ;
2013-12-11 06:39:13 -05:00
bool CallHookWorldStarted ( cWorld & a_World ) ;
2015-01-11 16:12:26 -05:00
bool CallHookWorldTick ( cWorld & a_World , std : : chrono : : milliseconds a_Dt , std : : chrono : : milliseconds a_LastTickDurationMSec ) ;
2016-02-05 16:45:45 -05:00
2015-04-19 04:57:41 -04:00
/** Queues the specified plugin to be unloaded in the next call to Tick().
Note that this function returns before the plugin is unloaded , to avoid deadlocks . */
void UnloadPlugin ( const AString & a_PluginFolder ) ; // tolua_export
/** Loads the plugin from the specified plugin folder.
Returns true if the plugin was loaded successfully or was already loaded before , false otherwise . */
bool LoadPlugin ( const AString & a_PluginFolder ) ; // tolua_export
2013-01-11 23:46:01 -05:00
2014-01-21 16:59:08 -05:00
/** Removes all hooks the specified plugin has registered */
2013-02-01 14:55:42 -05:00
void RemoveHooks ( cPlugin * a_Plugin ) ;
2016-02-05 16:45:45 -05:00
2015-04-19 04:57:41 -04:00
/** Removes the plugin of the specified name from the internal structures and deletes its object. */
void RemovePlugin ( const AString & a_PluginName ) ;
2016-02-05 16:45:45 -05:00
2014-01-21 16:59:08 -05:00
/** Removes all command bindings that the specified plugin has made */
2013-02-01 14:55:42 -05:00
void RemovePluginCommands ( cPlugin * a_Plugin ) ;
2015-04-19 11:20:15 -04:00
/** Returns true if the specified plugin is loaded. */
bool IsPluginLoaded ( const AString & a_PluginName ) ; // tolua_export
2016-06-12 12:11:40 -04:00
/** Binds a command to the specified handler.
Returns true if successful , false if command already bound .
Exported in ManualBindings . cpp . */
bool BindCommand (
const AString & a_Command ,
cPlugin * a_Plugin ,
cCommandHandlerPtr a_Handler ,
const AString & a_Permission ,
const AString & a_HelpString
) ;
2016-02-05 16:45:45 -05:00
2014-01-21 16:59:08 -05:00
/** Calls a_Callback for each bound command, returns true if all commands were enumerated */
2013-02-01 14:55:42 -05:00
bool ForEachCommand ( cCommandEnumCallback & a_Callback ) ; // Exported in ManualBindings.cpp
2016-02-05 16:45:45 -05:00
2014-01-21 16:59:08 -05:00
/** Returns true if the command is in the command map */
2013-02-01 14:55:42 -05:00
bool IsCommandBound ( const AString & a_Command ) ; // tolua_export
2016-02-05 16:45:45 -05:00
2014-01-21 16:59:08 -05:00
/** Returns the permission needed for the specified command; empty string if command not found */
2013-02-01 14:55:42 -05:00
AString GetCommandPermission ( const AString & a_Command ) ; // tolua_export
2016-02-05 16:45:45 -05:00
2014-06-28 15:55:21 -04:00
/** Executes the command, as if it was requested by a_Player. Checks permissions first. Returns crExecuted if executed. */
2014-10-15 13:01:55 -04:00
CommandResult ExecuteCommand ( cPlayer & a_Player , const AString & a_Command ) ; // tolua_export
2016-02-05 16:45:45 -05:00
2014-06-28 15:55:21 -04:00
/** Executes the command, as if it was requested by a_Player. Permisssions are not checked. Returns crExecuted if executed. */
2014-10-15 13:01:55 -04:00
CommandResult ForceExecuteCommand ( cPlayer & a_Player , const AString & a_Command ) ; // tolua_export
2016-02-05 16:45:45 -05:00
2014-01-21 16:59:08 -05:00
/** Removes all console command bindings that the specified plugin has made */
2013-02-15 08:00:59 -05:00
void RemovePluginConsoleCommands ( cPlugin * a_Plugin ) ;
2016-02-05 16:45:45 -05:00
2016-06-12 12:11:40 -04:00
/** Binds a console command to the specified handler.
Returns true if successful , false if command already bound .
Exported in ManualBindings . cpp . */
bool BindConsoleCommand (
const AString & a_Command ,
cPlugin * a_Plugin ,
cCommandHandlerPtr a_Handler ,
const AString & a_HelpString
) ;
2016-02-05 16:45:45 -05:00
2014-01-21 16:59:08 -05:00
/** Calls a_Callback for each bound console command, returns true if all commands were enumerated */
2013-02-15 08:00:59 -05:00
bool ForEachConsoleCommand ( cCommandEnumCallback & a_Callback ) ; // Exported in ManualBindings.cpp
2016-02-05 16:45:45 -05:00
2014-01-21 16:59:08 -05:00
/** Returns true if the console command is in the command map */
2013-02-15 08:00:59 -05:00
bool IsConsoleCommandBound ( const AString & a_Command ) ; // tolua_export
2016-02-05 16:45:45 -05:00
2015-05-10 16:51:16 -04:00
/** Executes the command split into a_Split, as if it was given on the console.
Returns true if executed . Output is sent to the a_Output callback
Exported in ManualBindings . cpp with a different signature . */
2015-03-10 23:14:17 -04:00
bool ExecuteConsoleCommand ( const AStringVector & a_Split , cCommandOutputCallback & a_Output , const AString & a_Command ) ;
2016-02-05 16:45:45 -05:00
2013-07-31 05:16:11 -04:00
/** Appends all commands beginning with a_Text (case-insensitive) into a_Results.
2014-10-20 16:55:07 -04:00
If a_Player is not nullptr , only commands for which the player has permissions are added .
2013-07-31 05:16:11 -04:00
*/
void TabCompleteCommand ( const AString & a_Text , AStringVector & a_Results , cPlayer * a_Player ) ;
2016-02-05 16:45:45 -05:00
2014-01-21 16:59:08 -05:00
/** Returns true if the specified hook type is within the allowed range */
2013-08-21 15:29:30 -04:00
static bool IsValidHookType ( int a_HookType ) ;
2016-02-05 16:45:45 -05:00
2014-01-21 16:59:08 -05:00
/** Calls the specified callback with the plugin object of the specified plugin.
2015-04-19 04:57:41 -04:00
Returns false if plugin not found , otherwise returns the value that the callback has returned . */
2017-09-11 17:20:49 -04:00
bool DoWithPlugin ( const AString & a_PluginName , cPluginCallback a_Callback ) ;
2015-04-19 04:57:41 -04:00
/** Calls the specified callback for each plugin in m_Plugins.
Returns true if all plugins have been reported , false if the callback has aborted the enumeration by returning true . */
2017-09-11 17:20:49 -04:00
bool ForEachPlugin ( cPluginCallback a_Callback ) ;
2016-02-05 16:45:45 -05:00
2016-03-02 04:05:10 -05:00
/** Returns the name of the folder (cPlugin::GetFolderName()) from which the specified plugin was loaded. */
AString GetPluginFolderName ( const AString & a_PluginName ) ; // tolua_export
2014-02-17 17:36:39 -05:00
/** Returns the path where individual plugins' folders are expected.
The path doesn ' t end in a slash . */
2020-05-07 15:14:00 -04:00
static AString GetPluginsPath ( void ) { return " Plugins " ; } // tolua_export
2016-02-05 16:45:45 -05:00
2013-02-01 14:55:42 -05:00
private :
2012-06-14 09:06:06 -04:00
friend class cRoot ;
2016-02-05 16:45:45 -05:00
2013-02-01 14:55:42 -05:00
class cCommandReg
{
public :
cPlugin * m_Plugin ;
2013-02-15 08:00:59 -05:00
AString m_Permission ; // Not used for console commands
2013-02-01 14:55:42 -05:00
AString m_HelpString ;
2016-06-12 12:11:40 -04:00
cCommandHandlerPtr m_Handler ;
2013-02-01 14:55:42 -05:00
} ;
2016-02-05 16:45:45 -05:00
2013-08-21 15:29:30 -04:00
typedef std : : map < int , cPluginManager : : PluginList > HookMap ;
2013-02-01 14:55:42 -05:00
typedef std : : map < AString , cCommandReg > CommandMap ;
2012-06-14 09:06:06 -04:00
2015-04-19 04:57:41 -04:00
/** FolderNames of plugins that should be unloaded.
The plugins will be unloaded within the next call to Tick ( ) , to avoid multithreading issues .
Protected against multithreaded access by m_CSPluginsToUnload . */
AStringVector m_PluginsToUnload ;
/** Protects m_PluginsToUnload against multithreaded access. */
mutable cCriticalSection m_CSPluginsToUnload ;
/** All plugins that have been found in the Plugins folder. */
cPluginPtrs m_Plugins ;
2013-02-01 14:55:42 -05:00
HookMap m_Hooks ;
CommandMap m_Commands ;
2013-02-15 08:00:59 -05:00
CommandMap m_ConsoleCommands ;
2013-02-01 14:55:42 -05:00
2015-04-19 04:57:41 -04:00
/** If set to true, all the plugins will be reloaded within the next call to Tick(). */
2013-02-01 14:55:42 -05:00
bool m_bReloadPlugins ;
2012-10-13 19:34:47 -04:00
2017-01-17 16:38:04 -05:00
/** The deadlock detect in which all plugins should track their CSs. */
cDeadlockDetect & m_DeadlockDetect ;
2015-04-19 04:57:41 -04:00
2017-01-17 16:38:04 -05:00
cPluginManager ( cDeadlockDetect & a_DeadlockDetect ) ;
2013-12-21 10:38:37 -05:00
virtual ~ cPluginManager ( ) ;
2012-06-14 09:06:06 -04:00
2014-01-21 16:59:08 -05:00
/** Reloads all plugins, defaulting to settings.ini for settings location */
2013-02-01 14:55:42 -05:00
void ReloadPluginsNow ( void ) ;
2013-11-04 16:51:24 -05:00
2015-05-14 10:47:51 -04:00
/** Reloads all plugins with a settings repo expected to be initialised to settings.ini */
void ReloadPluginsNow ( cSettingsRepositoryInterface & a_Settings ) ;
2013-11-04 16:51:24 -05:00
2014-01-21 16:59:08 -05:00
/** Unloads all plugins */
2013-02-01 14:55:42 -05:00
void UnloadPluginsNow ( void ) ;
2012-06-14 09:06:06 -04:00
2015-05-14 10:47:51 -04:00
/** Handles writing default plugins if 'Plugins' key not found using a settings repo expected to be intialised to settings.ini */
void InsertDefaultPlugins ( cSettingsRepositoryInterface & a_Settings ) ;
2013-11-05 16:15:39 -05:00
2014-06-28 15:55:21 -04:00
/** Tries to match a_Command to the internal table of commands, if a match is found, the corresponding plugin is called. Returns crExecuted if the command is executed. */
2014-10-15 13:01:55 -04:00
CommandResult HandleCommand ( cPlayer & a_Player , const AString & a_Command , bool a_ShouldCheckPermissions ) ;
2015-04-19 04:57:41 -04:00
/** Returns the folders that are specified in the settings ini to load plugins from. */
2015-05-14 10:47:51 -04:00
AStringVector GetFoldersToLoad ( cSettingsRepositoryInterface & a_Settings ) ;
2018-03-02 05:40:48 -05:00
/** Calls a_HookFunction on each plugin registered to the hook HookName.
Returns false if the action is to continue or true if the plugin wants to abort .
Accessible only from within PluginManager . cpp */
template < typename HookFunction >
bool GenericCallHook ( PluginHook a_HookName , HookFunction a_HookFunction ) ;
2014-07-17 16:15:34 -04:00
} ; // tolua_export
2012-11-08 14:09:35 -05:00