2013-02-01 14:55:42 -05:00
2012-06-14 09:06:06 -04:00
# include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
2012-09-23 18:09:57 -04:00
# include "PluginManager.h"
# include "Plugin.h"
2013-08-09 09:15:56 -04:00
# include "PluginLua.h"
2013-12-08 06:17:54 -05:00
# include "../WebAdmin.h"
# include "../Item.h"
# include "../Root.h"
# include "../Server.h"
# include "../CommandOutput.h"
2013-12-18 17:05:41 -05:00
# include "../ChatColor.h"
2012-08-16 02:47:09 -04:00
2013-11-27 02:40:59 -05:00
# include "inifile/iniFile.h"
2013-12-08 06:17:54 -05:00
# include "../Entities/Player.h"
2012-06-14 09:06:06 -04:00
2014-06-14 04:51:42 -04:00
# define FIND_HOOK(a_HookName) HookMap::iterator Plugins = m_Hooks.find(a_HookName);
# define VERIFY_HOOK \
if ( Plugins = = m_Hooks . end ( ) ) \
{ \
return false ; \
}
2012-06-14 09:06:06 -04:00
2013-02-01 14:55:42 -05:00
cPluginManager * cPluginManager : : Get ( void )
2012-06-14 09:06:06 -04:00
{
return cRoot : : Get ( ) - > GetPluginManager ( ) ;
}
2013-02-01 14:55:42 -05:00
cPluginManager : : cPluginManager ( void ) :
m_bReloadPlugins ( false )
2012-06-14 09:06:06 -04:00
{
}
cPluginManager : : ~ cPluginManager ( )
{
UnloadPluginsNow ( ) ;
}
2013-02-01 14:55:42 -05:00
void cPluginManager : : ReloadPlugins ( void )
2012-06-14 09:06:06 -04:00
{
m_bReloadPlugins = true ;
}
2013-02-01 14:55:42 -05:00
void cPluginManager : : FindPlugins ( void )
2012-10-13 19:34:47 -04:00
{
2014-02-17 17:36:39 -05:00
AString PluginsPath = GetPluginsPath ( ) + " / " ;
2012-10-13 19:34:47 -04:00
// First get a clean list of only the currently running plugins, we don't want to mess those up
2013-02-01 14:55:42 -05:00
for ( PluginMap : : iterator itr = m_Plugins . begin ( ) ; itr ! = m_Plugins . end ( ) ; )
2012-10-13 19:34:47 -04:00
{
2013-08-21 15:29:30 -04:00
if ( itr - > second = = NULL )
2012-10-13 19:34:47 -04:00
{
PluginMap : : iterator thiz = itr ;
+ + thiz ;
m_Plugins . erase ( itr ) ;
itr = thiz ;
continue ;
}
+ + itr ;
}
2013-11-22 14:11:24 -05:00
AStringVector Files = cFile : : GetFolderContents ( PluginsPath . c_str ( ) ) ;
for ( AStringVector : : const_iterator itr = Files . begin ( ) ; itr ! = Files . end ( ) ; + + itr )
2012-10-13 19:34:47 -04:00
{
2013-10-06 10:58:19 -04:00
if ( ( * itr = = " . " ) | | ( * itr = = " .. " ) | | ( ! cFile : : IsFolder ( PluginsPath + * itr ) ) )
2012-10-13 19:34:47 -04:00
{
2013-10-06 10:58:19 -04:00
// We only want folders, and don't want "." or ".."
2012-10-13 19:34:47 -04:00
continue ;
}
// Add plugin name/directory to the list
2013-09-18 12:43:03 -04:00
if ( m_Plugins . find ( * itr ) = = m_Plugins . end ( ) )
2012-10-13 19:34:47 -04:00
{
2013-09-21 13:45:11 -04:00
m_Plugins [ * itr ] = NULL ;
2012-10-13 19:34:47 -04:00
}
}
}
2013-02-01 14:55:42 -05:00
void cPluginManager : : ReloadPluginsNow ( void )
2013-11-04 16:51:24 -05:00
{
cIniFile a_SettingsIni ;
a_SettingsIni . ReadFile ( " settings.ini " ) ;
ReloadPluginsNow ( a_SettingsIni ) ;
}
void cPluginManager : : ReloadPluginsNow ( cIniFile & a_SettingsIni )
2012-06-14 09:06:06 -04:00
{
2013-09-28 15:36:01 -04:00
LOG ( " -- Loading Plugins -- " ) ;
2012-06-14 09:06:06 -04:00
m_bReloadPlugins = false ;
UnloadPluginsNow ( ) ;
2012-10-13 19:34:47 -04:00
FindPlugins ( ) ;
2013-04-27 10:08:23 -04:00
cServer : : BindBuiltInConsoleCommands ( ) ;
2013-11-16 13:15:12 -05:00
// Check if the Plugins section exists.
int KeyNum = a_SettingsIni . FindKey ( " Plugins " ) ;
// If it does, how many plugins are there?
2013-12-29 06:51:58 -05:00
int NumPlugins = ( ( KeyNum ! = - 1 ) ? ( a_SettingsIni . GetNumValues ( KeyNum ) ) : 0 ) ;
2013-11-16 13:15:12 -05:00
2013-11-04 16:51:24 -05:00
if ( KeyNum = = - 1 )
2012-06-14 09:06:06 -04:00
{
2013-11-05 16:15:39 -05:00
InsertDefaultPlugins ( a_SettingsIni ) ;
2012-06-14 09:06:06 -04:00
}
2013-11-04 16:51:24 -05:00
else if ( NumPlugins > 0 )
2012-06-14 09:06:06 -04:00
{
2013-12-29 06:51:58 -05:00
for ( int i = 0 ; i < NumPlugins ; i + + )
2012-06-14 09:06:06 -04:00
{
2013-11-04 16:51:24 -05:00
AString ValueName = a_SettingsIni . GetValueName ( KeyNum , i ) ;
if ( ValueName . compare ( " Plugin " ) = = 0 )
2012-06-14 09:06:06 -04:00
{
2013-11-04 16:51:24 -05:00
AString PluginFile = a_SettingsIni . GetValue ( KeyNum , i ) ;
2013-02-01 14:55:42 -05:00
if ( ! PluginFile . empty ( ) )
2012-06-14 09:06:06 -04:00
{
2013-02-01 14:55:42 -05:00
if ( m_Plugins . find ( PluginFile ) ! = m_Plugins . end ( ) )
2012-06-14 09:06:06 -04:00
{
2013-12-29 06:51:58 -05:00
LoadPlugin ( PluginFile ) ;
2012-06-14 09:06:06 -04:00
}
}
}
}
}
2014-05-08 14:16:35 -04:00
size_t NumLoadedPlugins = GetNumPlugins ( ) ;
2014-05-10 11:55:39 -04:00
if ( NumLoadedPlugins = = 0 )
2012-06-14 09:06:06 -04:00
{
2013-09-28 15:36:01 -04:00
LOG ( " -- No Plugins Loaded -- " ) ;
}
2014-05-08 14:16:35 -04:00
else if ( NumLoadedPlugins > 1 )
2013-09-28 15:36:01 -04:00
{
2014-05-08 14:16:35 -04:00
LOG ( " -- Loaded %i Plugins -- " , ( int ) NumLoadedPlugins ) ;
2012-06-14 09:06:06 -04:00
}
else
{
2013-09-28 15:36:01 -04:00
LOG ( " -- Loaded 1 Plugin -- " ) ;
2012-06-14 09:06:06 -04:00
}
2013-12-29 06:51:58 -05:00
CallHookPluginsLoaded ( ) ;
2012-06-14 09:06:06 -04:00
}
2013-11-05 16:15:39 -05:00
void cPluginManager : : InsertDefaultPlugins ( cIniFile & a_SettingsIni )
{
a_SettingsIni . AddKeyName ( " Plugins " ) ;
a_SettingsIni . AddKeyComment ( " Plugins " , " Plugin=Debuggers " ) ;
a_SettingsIni . AddKeyComment ( " Plugins " , " Plugin=HookNotify " ) ;
a_SettingsIni . AddKeyComment ( " Plugins " , " Plugin=ChunkWorx " ) ;
a_SettingsIni . AddKeyComment ( " Plugins " , " Plugin=APIDump " ) ;
2014-01-12 09:03:50 -05:00
a_SettingsIni . AddValue ( " Plugins " , " Plugin " , " Core " ) ;
a_SettingsIni . AddValue ( " Plugins " , " Plugin " , " TransAPI " ) ;
a_SettingsIni . AddValue ( " Plugins " , " Plugin " , " ChatLog " ) ;
2013-11-05 16:15:39 -05:00
}
2012-06-14 09:06:06 -04:00
void cPluginManager : : Tick ( float a_Dt )
{
2013-02-01 14:55:42 -05:00
while ( ! m_DisablePluginList . empty ( ) )
2012-10-13 19:34:47 -04:00
{
2013-02-01 14:55:42 -05:00
RemovePlugin ( m_DisablePluginList . front ( ) ) ;
2012-10-13 19:34:47 -04:00
m_DisablePluginList . pop_front ( ) ;
}
2013-02-01 14:55:42 -05:00
if ( m_bReloadPlugins )
2012-06-14 09:06:06 -04:00
{
ReloadPluginsNow ( ) ;
}
2014-06-14 04:51:42 -04:00
FIND_HOOK ( HOOK_TICK ) ;
2013-02-01 14:55:42 -05:00
if ( Plugins ! = m_Hooks . end ( ) )
2012-06-14 09:06:06 -04:00
{
2013-02-01 14:55:42 -05:00
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
2012-06-14 09:06:06 -04:00
{
2013-02-01 14:55:42 -05:00
( * itr ) - > Tick ( a_Dt ) ;
2012-06-14 09:06:06 -04:00
}
}
}
2014-03-16 11:06:03 -04:00
bool cPluginManager : : CallHookBlockSpread ( cWorld * a_World , int a_BlockX , int a_BlockY , int a_BlockZ , eSpreadSource a_Source )
2014-03-16 09:38:41 -04:00
{
2014-06-14 04:51:42 -04:00
FIND_HOOK ( HOOK_BLOCK_SPREAD ) ;
VERIFY_HOOK ;
2014-03-16 09:38:41 -04:00
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
2014-03-16 11:06:03 -04:00
if ( ( * itr ) - > OnBlockSpread ( a_World , a_BlockX , a_BlockY , a_BlockZ , a_Source ) )
2014-03-16 09:38:41 -04:00
{
return true ;
}
}
return false ;
}
2013-01-26 21:00:33 -05:00
bool cPluginManager : : CallHookBlockToPickups (
cWorld * a_World , cEntity * a_Digger ,
2013-11-16 13:15:12 -05:00
int a_BlockX , int a_BlockY , int a_BlockZ , BLOCKTYPE a_BlockType , NIBBLETYPE a_BlockMeta ,
2013-01-26 21:00:33 -05:00
cItems & a_Pickups
2013-01-11 23:46:01 -05:00
)
2012-08-18 05:56:28 -04:00
{
2014-06-14 04:51:42 -04:00
FIND_HOOK ( HOOK_BLOCK_TO_PICKUPS ) ;
VERIFY_HOOK ;
2012-08-18 05:56:28 -04:00
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
2013-01-26 21:00:33 -05:00
if ( ( * itr ) - > OnBlockToPickups ( a_World , a_Digger , a_BlockX , a_BlockY , a_BlockZ , a_BlockType , a_BlockMeta , a_Pickups ) )
2012-08-18 05:56:28 -04:00
{
return true ;
}
}
return false ;
}
2013-06-22 15:08:34 -04:00
bool cPluginManager : : CallHookChat ( cPlayer * a_Player , AString & a_Message )
2012-08-18 06:38:15 -04:00
{
2013-12-18 17:05:41 -05:00
bool WasCommandForbidden = false ;
if ( HandleCommand ( a_Player , a_Message , true , WasCommandForbidden ) ) // We use HandleCommand as opposed to ExecuteCommand to accomodate the need to the WasCommandForbidden bool
2012-08-18 06:38:15 -04:00
{
2013-12-18 17:05:41 -05:00
return true ; // Chat message was handled as command
}
else if ( WasCommandForbidden ) // Couldn't be handled as command, was it because of insufficient permissions?
{
return true ; // Yes - message was sent in HandleCommand, abort
2012-08-18 06:38:15 -04:00
}
2013-01-11 23:46:01 -05:00
// Check if it was a standard command (starts with a slash)
2013-12-18 17:05:41 -05:00
// If it was, we know that it was completely unrecognised (WasCommandForbidden == false)
2013-02-01 14:55:42 -05:00
if ( ! a_Message . empty ( ) & & ( a_Message [ 0 ] = = ' / ' ) )
2012-08-18 06:38:15 -04:00
{
2013-02-01 14:55:42 -05:00
AStringVector Split ( StringSplit ( a_Message , " " ) ) ;
ASSERT ( ! Split . empty ( ) ) ; // This should not happen - we know there's at least one char in the message so the split needs to be at least one item long
2014-03-12 08:11:34 -04:00
a_Player - > SendMessageInfo ( Printf ( " Unknown command: \" %s \" " , a_Message . c_str ( ) ) ) ;
2013-12-18 17:05:41 -05:00
LOGINFO ( " Player %s issued an unknown command: \" %s \" " , a_Player - > GetName ( ) . c_str ( ) , a_Message . c_str ( ) ) ;
return true ; // Cancel sending
2012-08-18 06:38:15 -04:00
}
2014-06-14 04:51:42 -04:00
FIND_HOOK ( HOOK_CHAT ) ;
VERIFY_HOOK ;
2013-11-16 13:15:12 -05:00
2012-08-18 06:38:15 -04:00
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
if ( ( * itr ) - > OnChat ( a_Player , a_Message ) )
{
return true ;
}
}
2013-11-16 13:15:12 -05:00
2012-08-18 06:38:15 -04:00
return false ;
}
2013-02-05 14:57:22 -05:00
bool cPluginManager : : CallHookChunkAvailable ( cWorld * a_World , int a_ChunkX , int a_ChunkZ )
{
2014-06-14 04:51:42 -04:00
FIND_HOOK ( HOOK_CHUNK_AVAILABLE ) ;
VERIFY_HOOK ;
2013-02-05 14:57:22 -05:00
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
if ( ( * itr ) - > OnChunkAvailable ( a_World , a_ChunkX , a_ChunkZ ) )
{
return true ;
}
}
return false ;
}
bool cPluginManager : : CallHookChunkGenerated ( cWorld * a_World , int a_ChunkX , int a_ChunkZ , cChunkDesc * a_ChunkDesc )
2013-01-11 23:46:01 -05:00
{
2014-06-14 04:51:42 -04:00
FIND_HOOK ( HOOK_CHUNK_GENERATED ) ;
VERIFY_HOOK ;
2013-01-11 23:46:01 -05:00
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
2013-02-05 14:57:22 -05:00
if ( ( * itr ) - > OnChunkGenerated ( a_World , a_ChunkX , a_ChunkZ , a_ChunkDesc ) )
2013-01-11 23:46:01 -05:00
{
return true ;
}
}
return false ;
}
2013-02-05 14:57:22 -05:00
bool cPluginManager : : CallHookChunkGenerating ( cWorld * a_World , int a_ChunkX , int a_ChunkZ , cChunkDesc * a_ChunkDesc )
2012-06-14 13:30:37 -04:00
{
2014-06-14 04:51:42 -04:00
FIND_HOOK ( HOOK_CHUNK_GENERATING ) ;
VERIFY_HOOK ;
2012-06-14 13:30:37 -04:00
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
2013-02-05 14:57:22 -05:00
if ( ( * itr ) - > OnChunkGenerating ( a_World , a_ChunkX , a_ChunkZ , a_ChunkDesc ) )
{
return true ;
}
}
return false ;
}
bool cPluginManager : : CallHookChunkUnloaded ( cWorld * a_World , int a_ChunkX , int a_ChunkZ )
{
2014-06-14 04:51:42 -04:00
FIND_HOOK ( HOOK_CHUNK_UNLOADED ) ;
VERIFY_HOOK ;
2013-02-05 14:57:22 -05:00
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
if ( ( * itr ) - > OnChunkUnloaded ( a_World , a_ChunkX , a_ChunkZ ) )
{
return true ;
}
}
return false ;
}
bool cPluginManager : : CallHookChunkUnloading ( cWorld * a_World , int a_ChunkX , int a_ChunkZ )
{
2014-06-14 04:51:42 -04:00
FIND_HOOK ( HOOK_CHUNK_UNLOADING ) ;
VERIFY_HOOK ;
2013-02-05 14:57:22 -05:00
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
if ( ( * itr ) - > OnChunkUnloading ( a_World , a_ChunkX , a_ChunkZ ) )
2012-06-14 13:30:37 -04:00
{
return true ;
}
}
return false ;
}
2013-01-28 11:17:26 -05:00
bool cPluginManager : : CallHookCollectingPickup ( cPlayer * a_Player , cPickup & a_Pickup )
2012-08-24 05:49:00 -04:00
{
2014-06-14 04:51:42 -04:00
FIND_HOOK ( HOOK_COLLECTING_PICKUP ) ;
VERIFY_HOOK ;
2012-08-24 05:49:00 -04:00
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
2013-01-28 11:17:26 -05:00
if ( ( * itr ) - > OnCollectingPickup ( a_Player , & a_Pickup ) )
2012-08-24 05:49:00 -04:00
{
return true ;
}
}
return false ;
}
2012-12-21 06:04:08 -05:00
bool cPluginManager : : CallHookCraftingNoRecipe ( const cPlayer * a_Player , const cCraftingGrid * a_Grid , cCraftingRecipe * a_Recipe )
2012-06-14 09:06:06 -04:00
{
2014-06-14 04:51:42 -04:00
FIND_HOOK ( HOOK_CRAFTING_NO_RECIPE ) ;
VERIFY_HOOK ;
2012-06-14 09:06:06 -04:00
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
2012-12-21 06:04:08 -05:00
if ( ( * itr ) - > OnCraftingNoRecipe ( a_Player , a_Grid , a_Recipe ) )
2012-06-14 09:06:06 -04:00
{
return true ;
}
}
return false ;
}
2014-05-02 05:18:02 -04:00
bool cPluginManager : : CallHookDisconnect ( cClientHandle & a_Client , const AString & a_Reason )
2012-06-14 09:06:06 -04:00
{
2014-06-14 04:51:42 -04:00
FIND_HOOK ( HOOK_DISCONNECT ) ;
VERIFY_HOOK ;
2012-06-14 09:06:06 -04:00
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
2014-05-02 05:18:02 -04:00
if ( ( * itr ) - > OnDisconnect ( a_Client , a_Reason ) )
2012-06-14 09:06:06 -04:00
{
return true ;
}
}
return false ;
}
2014-06-13 06:47:01 -04:00
bool cPluginManager : : CallHookEntityAddEffect ( cEntity & a_Entity , int a_EffectType , int a_EffectDurationTicks , int a_EffectIntensity , cEntity * a_Originator , double a_DistanceModifier )
{
HookMap : : iterator Plugins = m_Hooks . find ( HOOK_ENTITY_ADD_EFFECT ) ;
if ( Plugins = = m_Hooks . end ( ) )
{
return false ;
}
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
if ( ( * itr ) - > OnEntityAddEffect ( a_Entity , a_EffectType , a_EffectDurationTicks , a_EffectIntensity , a_Originator , a_DistanceModifier ) )
{
return true ;
}
}
return false ;
}
2013-02-21 08:47:01 -05:00
bool cPluginManager : : CallHookExecuteCommand ( cPlayer * a_Player , const AStringVector & a_Split )
{
2014-06-14 04:51:42 -04:00
FIND_HOOK ( HOOK_EXECUTE_COMMAND ) ;
VERIFY_HOOK ;
2013-02-21 08:47:01 -05:00
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
if ( ( * itr ) - > OnExecuteCommand ( a_Player , a_Split ) )
{
return true ;
}
}
return false ;
}
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 cPluginManager : : 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 )
{
2014-06-14 04:51:42 -04:00
FIND_HOOK ( HOOK_EXPLODED ) ;
VERIFY_HOOK ;
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
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
if ( ( * itr ) - > OnExploded ( a_World , a_ExplosionSize , a_CanCauseFire , a_X , a_Y , a_Z , a_Source , a_SourceData ) )
{
return true ;
}
}
return false ;
}
bool cPluginManager : : 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-06-14 04:51:42 -04:00
FIND_HOOK ( HOOK_EXPLODING ) ;
VERIFY_HOOK ;
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
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
if ( ( * itr ) - > OnExploding ( a_World , a_ExplosionSize , a_CanCauseFire , a_X , a_Y , a_Z , a_Source , a_SourceData ) )
{
return true ;
}
}
return false ;
}
2013-01-11 23:46:01 -05:00
bool cPluginManager : : CallHookHandshake ( cClientHandle * a_ClientHandle , const AString & a_Username )
2012-08-19 15:42:32 -04:00
{
2014-06-14 04:51:42 -04:00
FIND_HOOK ( HOOK_HANDSHAKE ) ;
VERIFY_HOOK ;
2012-08-19 15:42:32 -04:00
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
2013-01-11 23:46:01 -05:00
if ( ( * itr ) - > OnHandshake ( a_ClientHandle , a_Username ) )
2012-08-19 15:42:32 -04:00
{
return true ;
}
}
return false ;
}
2013-08-11 08:57:07 -04:00
bool cPluginManager : : CallHookHopperPullingItem ( cWorld & a_World , cHopperEntity & a_Hopper , int a_DstSlotNum , cBlockEntityWithItems & a_SrcEntity , int a_SrcSlotNum )
{
2014-06-14 04:51:42 -04:00
FIND_HOOK ( HOOK_HOPPER_PULLING_ITEM ) ;
VERIFY_HOOK ;
2013-08-11 08:57:07 -04:00
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
if ( ( * itr ) - > OnHopperPullingItem ( a_World , a_Hopper , a_DstSlotNum , a_SrcEntity , a_SrcSlotNum ) )
{
return true ;
}
}
return false ;
}
bool cPluginManager : : CallHookHopperPushingItem ( cWorld & a_World , cHopperEntity & a_Hopper , int a_SrcSlotNum , cBlockEntityWithItems & a_DstEntity , int a_DstSlotNum )
{
2014-06-14 04:51:42 -04:00
FIND_HOOK ( HOOK_HOPPER_PUSHING_ITEM ) ;
VERIFY_HOOK ;
2013-08-11 08:57:07 -04:00
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
if ( ( * itr ) - > OnHopperPushingItem ( a_World , a_Hopper , a_SrcSlotNum , a_DstEntity , a_DstSlotNum ) )
{
return true ;
}
}
return false ;
}
2013-07-01 06:39:56 -04:00
bool cPluginManager : : CallHookKilling ( cEntity & a_Victim , cEntity * a_Killer )
2012-06-14 09:06:06 -04:00
{
2014-06-14 04:51:42 -04:00
FIND_HOOK ( HOOK_KILLING ) ;
VERIFY_HOOK ;
2012-06-14 09:06:06 -04:00
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
2013-01-28 11:54:11 -05:00
if ( ( * itr ) - > OnKilling ( a_Victim , a_Killer ) )
2012-12-21 06:04:08 -05:00
{
return true ;
}
}
return false ;
}
2013-01-11 23:46:01 -05:00
bool cPluginManager : : CallHookLogin ( cClientHandle * a_Client , int a_ProtocolVersion , const AString & a_Username )
2012-12-21 06:04:08 -05:00
{
2014-06-14 04:51:42 -04:00
FIND_HOOK ( HOOK_LOGIN ) ;
VERIFY_HOOK ;
2012-12-21 06:04:08 -05:00
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
2013-01-11 23:46:01 -05:00
if ( ( * itr ) - > OnLogin ( a_Client , a_ProtocolVersion , a_Username ) )
2012-06-14 09:06:06 -04:00
{
return true ;
}
}
return false ;
}
2013-12-18 11:11:15 -05:00
bool cPluginManager : : CallHookPlayerAnimation ( cPlayer & a_Player , int a_Animation )
2013-08-11 06:12:20 -04:00
{
2014-06-14 04:51:42 -04:00
FIND_HOOK ( HOOK_PLAYER_ANIMATION ) ;
VERIFY_HOOK ;
2013-08-11 06:12:20 -04:00
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
2013-12-18 11:11:15 -05:00
if ( ( * itr ) - > OnPlayerAnimation ( a_Player , a_Animation ) )
2013-08-11 06:12:20 -04:00
{
return true ;
}
}
return false ;
}
2013-01-11 23:46:01 -05:00
bool cPluginManager : : CallHookPlayerBreakingBlock ( cPlayer & a_Player , int a_BlockX , int a_BlockY , int a_BlockZ , char a_BlockFace , BLOCKTYPE a_BlockType , NIBBLETYPE a_BlockMeta )
{
2014-06-14 04:51:42 -04:00
FIND_HOOK ( HOOK_PLAYER_BREAKING_BLOCK ) ;
VERIFY_HOOK ;
2013-01-11 23:46:01 -05:00
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
if ( ( * itr ) - > OnPlayerBreakingBlock ( a_Player , a_BlockX , a_BlockY , a_BlockZ , a_BlockFace , a_BlockType , a_BlockMeta ) )
{
return true ;
}
}
return false ;
}
bool cPluginManager : : CallHookPlayerBrokenBlock ( cPlayer & a_Player , int a_BlockX , int a_BlockY , int a_BlockZ , char a_BlockFace , BLOCKTYPE a_BlockType , NIBBLETYPE a_BlockMeta )
{
2014-06-14 04:51:42 -04:00
FIND_HOOK ( HOOK_PLAYER_BROKEN_BLOCK ) ;
VERIFY_HOOK ;
2013-01-11 23:46:01 -05:00
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
if ( ( * itr ) - > OnPlayerBrokenBlock ( a_Player , a_BlockX , a_BlockY , a_BlockZ , a_BlockFace , a_BlockType , a_BlockMeta ) )
{
return true ;
}
}
return false ;
}
2014-01-25 05:25:22 -05:00
bool cPluginManager : : CallHookPlayerDestroyed ( cPlayer & a_Player )
{
2014-06-14 04:51:42 -04:00
FIND_HOOK ( HOOK_PLAYER_DESTROYED ) ;
VERIFY_HOOK ;
2014-01-25 05:25:22 -05:00
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
if ( ( * itr ) - > OnPlayerDestroyed ( a_Player ) )
{
return true ;
}
}
return false ;
}
2013-01-11 23:46:01 -05:00
bool cPluginManager : : CallHookPlayerEating ( cPlayer & a_Player )
{
2014-06-14 04:51:42 -04:00
FIND_HOOK ( HOOK_PLAYER_EATING ) ;
VERIFY_HOOK ;
2013-01-11 23:46:01 -05:00
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
if ( ( * itr ) - > OnPlayerEating ( a_Player ) )
{
return true ;
}
}
return false ;
}
2013-12-31 08:53:10 -05:00
bool cPluginManager : : CallHookPlayerFished ( cPlayer & a_Player , const cItems a_Reward )
2013-12-30 16:56:08 -05:00
{
2014-06-14 04:51:42 -04:00
FIND_HOOK ( HOOK_PLAYER_FISHED ) ;
VERIFY_HOOK ;
2013-12-30 16:56:08 -05:00
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
if ( ( * itr ) - > OnPlayerFished ( a_Player , a_Reward ) )
{
return true ;
}
}
return false ;
}
2014-01-01 09:09:53 -05:00
bool cPluginManager : : CallHookPlayerFishing ( cPlayer & a_Player , cItems a_Reward )
2013-12-30 16:56:08 -05:00
{
2014-06-14 04:51:42 -04:00
FIND_HOOK ( HOOK_PLAYER_FISHING ) ;
VERIFY_HOOK ;
2013-12-30 16:56:08 -05:00
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
if ( ( * itr ) - > OnPlayerFishing ( a_Player , a_Reward ) )
{
return true ;
}
}
return false ;
}
2013-01-11 23:46:01 -05:00
bool cPluginManager : : CallHookPlayerJoined ( cPlayer & a_Player )
{
2014-06-14 04:51:42 -04:00
FIND_HOOK ( HOOK_PLAYER_JOINED ) ;
VERIFY_HOOK ;
2013-01-11 23:46:01 -05:00
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
if ( ( * itr ) - > OnPlayerJoined ( a_Player ) )
{
return true ;
}
}
return false ;
}
bool cPluginManager : : CallHookPlayerLeftClick ( cPlayer & a_Player , int a_BlockX , int a_BlockY , int a_BlockZ , char a_BlockFace , char a_Status )
{
2014-06-14 04:51:42 -04:00
FIND_HOOK ( HOOK_PLAYER_LEFT_CLICK ) ;
VERIFY_HOOK ;
2013-01-11 23:46:01 -05:00
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
if ( ( * itr ) - > OnPlayerLeftClick ( a_Player , a_BlockX , a_BlockY , a_BlockZ , a_BlockFace , a_Status ) )
{
return true ;
}
}
return false ;
}
2013-01-26 02:50:06 -05:00
bool cPluginManager : : CallHookPlayerMoving ( cPlayer & a_Player )
2013-01-11 23:46:01 -05:00
{
2014-06-14 04:51:42 -04:00
FIND_HOOK ( HOOK_PLAYER_MOVING ) ;
VERIFY_HOOK ;
2013-01-11 23:46:01 -05:00
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
if ( ( * itr ) - > OnPlayerMoved ( a_Player ) )
{
return true ;
}
}
return false ;
}
bool cPluginManager : : CallHookPlayerPlacedBlock ( 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 )
{
2014-06-14 04:51:42 -04:00
FIND_HOOK ( HOOK_PLAYER_PLACED_BLOCK ) ;
VERIFY_HOOK ;
2013-01-11 23:46:01 -05:00
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
if ( ( * itr ) - > OnPlayerPlacedBlock ( a_Player , a_BlockX , a_BlockY , a_BlockZ , a_BlockFace , a_CursorX , a_CursorY , a_CursorZ , a_BlockType , a_BlockMeta ) )
{
return true ;
}
}
return false ;
}
bool cPluginManager : : CallHookPlayerPlacingBlock ( 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 )
{
2014-06-14 04:51:42 -04:00
FIND_HOOK ( HOOK_PLAYER_PLACING_BLOCK ) ;
VERIFY_HOOK ;
2013-01-11 23:46:01 -05:00
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
if ( ( * itr ) - > OnPlayerPlacingBlock ( a_Player , a_BlockX , a_BlockY , a_BlockZ , a_BlockFace , a_CursorX , a_CursorY , a_CursorZ , a_BlockType , a_BlockMeta ) )
{
return true ;
}
}
return false ;
}
bool cPluginManager : : 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 )
{
2014-06-14 04:51:42 -04:00
FIND_HOOK ( HOOK_PLAYER_RIGHT_CLICK ) ;
VERIFY_HOOK ;
2013-01-11 23:46:01 -05:00
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
if ( ( * itr ) - > OnPlayerRightClick ( a_Player , a_BlockX , a_BlockY , a_BlockZ , a_BlockFace , a_CursorX , a_CursorY , a_CursorZ ) )
{
return true ;
}
}
return false ;
2013-08-02 02:44:06 -04:00
}
bool cPluginManager : : CallHookPlayerRightClickingEntity ( cPlayer & a_Player , cEntity & a_Entity )
{
2014-06-14 04:51:42 -04:00
FIND_HOOK ( HOOK_PLAYER_RIGHT_CLICKING_ENTITY ) ;
VERIFY_HOOK ;
2013-08-02 02:44:06 -04:00
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
if ( ( * itr ) - > OnPlayerRightClickingEntity ( a_Player , a_Entity ) )
{
return true ;
}
}
return false ;
2013-01-11 23:46:01 -05:00
}
bool cPluginManager : : CallHookPlayerShooting ( cPlayer & a_Player )
{
2014-06-14 04:51:42 -04:00
FIND_HOOK ( HOOK_PLAYER_SHOOTING ) ;
VERIFY_HOOK ;
2013-01-11 23:46:01 -05:00
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
if ( ( * itr ) - > OnPlayerShooting ( a_Player ) )
{
return true ;
}
}
return false ;
}
bool cPluginManager : : CallHookPlayerSpawned ( cPlayer & a_Player )
{
2014-06-14 04:51:42 -04:00
FIND_HOOK ( HOOK_PLAYER_SPAWNED ) ;
VERIFY_HOOK ;
2013-01-11 23:46:01 -05:00
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
if ( ( * itr ) - > OnPlayerSpawned ( a_Player ) )
{
return true ;
}
}
return false ;
}
bool cPluginManager : : CallHookPlayerTossingItem ( cPlayer & a_Player )
{
2014-06-14 04:51:42 -04:00
FIND_HOOK ( HOOK_PLAYER_TOSSING_ITEM ) ;
VERIFY_HOOK ;
2013-01-11 23:46:01 -05:00
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
if ( ( * itr ) - > OnPlayerTossingItem ( a_Player ) )
{
return true ;
}
}
return false ;
}
bool cPluginManager : : 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 )
{
2014-06-14 04:51:42 -04:00
FIND_HOOK ( HOOK_PLAYER_USED_BLOCK ) ;
VERIFY_HOOK ;
2013-01-11 23:46:01 -05:00
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
if ( ( * itr ) - > OnPlayerUsedBlock ( a_Player , a_BlockX , a_BlockY , a_BlockZ , a_BlockFace , a_CursorX , a_CursorY , a_CursorZ , a_BlockType , a_BlockMeta ) )
{
return true ;
}
}
return false ;
}
bool cPluginManager : : 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 )
{
2014-06-14 04:51:42 -04:00
FIND_HOOK ( HOOK_PLAYER_USED_ITEM ) ;
VERIFY_HOOK ;
2013-01-11 23:46:01 -05:00
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
if ( ( * itr ) - > OnPlayerUsedItem ( a_Player , a_BlockX , a_BlockY , a_BlockZ , a_BlockFace , a_CursorX , a_CursorY , a_CursorZ ) )
{
return true ;
}
}
return false ;
}
bool cPluginManager : : 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 )
{
2014-06-14 04:51:42 -04:00
FIND_HOOK ( HOOK_PLAYER_USING_BLOCK ) ;
VERIFY_HOOK ;
2013-01-11 23:46:01 -05:00
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
if ( ( * itr ) - > OnPlayerUsingBlock ( a_Player , a_BlockX , a_BlockY , a_BlockZ , a_BlockFace , a_CursorX , a_CursorY , a_CursorZ , a_BlockType , a_BlockMeta ) )
{
return true ;
}
}
return false ;
}
bool cPluginManager : : 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-06-14 04:51:42 -04:00
FIND_HOOK ( HOOK_PLAYER_USING_ITEM ) ;
VERIFY_HOOK ;
2013-01-11 23:46:01 -05:00
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
if ( ( * itr ) - > OnPlayerUsingItem ( a_Player , a_BlockX , a_BlockY , a_BlockZ , a_BlockFace , a_CursorX , a_CursorY , a_CursorZ ) )
{
return true ;
}
}
return false ;
}
2014-01-07 11:47:05 -05:00
bool cPluginManager : : CallHookPluginMessage ( cClientHandle & a_Client , const AString & a_Channel , const AString & a_Message )
{
2014-06-14 04:51:42 -04:00
FIND_HOOK ( HOOK_PLUGIN_MESSAGE ) ;
VERIFY_HOOK ;
2014-01-07 11:47:05 -05:00
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
if ( ( * itr ) - > OnPluginMessage ( a_Client , a_Channel , a_Message ) )
{
return true ;
}
}
return false ;
}
2013-12-29 06:51:58 -05:00
bool cPluginManager : : CallHookPluginsLoaded ( void )
{
2014-06-14 04:51:42 -04:00
FIND_HOOK ( HOOK_PLUGINS_LOADED ) ;
VERIFY_HOOK ;
2013-12-29 06:51:58 -05:00
bool res = false ;
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
res = ! ( * itr ) - > OnPluginsLoaded ( ) | | res ;
}
return res ;
}
2013-01-11 23:46:01 -05:00
bool cPluginManager : : CallHookPostCrafting ( const cPlayer * a_Player , const cCraftingGrid * a_Grid , cCraftingRecipe * a_Recipe )
2012-06-14 09:06:06 -04:00
{
2014-06-14 04:51:42 -04:00
FIND_HOOK ( HOOK_POST_CRAFTING ) ;
VERIFY_HOOK ;
2012-06-14 09:06:06 -04:00
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
2013-01-11 23:46:01 -05:00
if ( ( * itr ) - > OnPostCrafting ( a_Player , a_Grid , a_Recipe ) )
2012-06-14 09:06:06 -04:00
{
return true ;
}
}
return false ;
}
2013-01-11 23:46:01 -05:00
bool cPluginManager : : CallHookPreCrafting ( const cPlayer * a_Player , const cCraftingGrid * a_Grid , cCraftingRecipe * a_Recipe )
2012-06-14 15:20:31 -04:00
{
2014-06-14 04:51:42 -04:00
FIND_HOOK ( HOOK_PRE_CRAFTING ) ;
VERIFY_HOOK ;
2012-06-14 15:20:31 -04:00
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
2013-01-11 23:46:01 -05:00
if ( ( * itr ) - > OnPreCrafting ( a_Player , a_Grid , a_Recipe ) )
{
return true ;
}
}
return false ;
}
2014-06-01 08:06:47 -04:00
bool cPluginManager : : CallHookProjectileHitBlock ( cProjectileEntity & a_Projectile , int a_BlockX , int a_BlockY , int a_BlockZ , eBlockFace a_Face , const Vector3d & a_BlockHitPos )
2014-03-29 11:00:45 -04:00
{
2014-06-14 04:51:42 -04:00
FIND_HOOK ( HOOK_PROJECTILE_HIT_BLOCK ) ;
VERIFY_HOOK ;
2014-03-29 11:00:45 -04:00
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
2014-05-31 08:14:55 -04:00
if ( ( * itr ) - > OnProjectileHitBlock ( a_Projectile , a_BlockX , a_BlockY , a_BlockZ , a_Face , a_BlockHitPos ) )
2014-03-29 11:00:45 -04:00
{
return true ;
}
}
return false ;
}
2014-03-29 10:26:41 -04:00
bool cPluginManager : : CallHookProjectileHitEntity ( cProjectileEntity & a_Projectile , cEntity & a_HitEntity )
{
2014-06-14 04:51:42 -04:00
FIND_HOOK ( HOOK_PROJECTILE_HIT_ENTITY ) ;
VERIFY_HOOK ;
2014-03-29 10:26:41 -04:00
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
if ( ( * itr ) - > OnProjectileHitEntity ( a_Projectile , a_HitEntity ) )
{
return true ;
}
}
return false ;
}
2013-08-08 03:13:13 -04:00
bool cPluginManager : : CallHookSpawnedEntity ( cWorld & a_World , cEntity & a_Entity )
{
2014-06-14 04:51:42 -04:00
FIND_HOOK ( HOOK_SPAWNED_ENTITY ) ;
VERIFY_HOOK ;
2013-08-08 03:13:13 -04:00
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
if ( ( * itr ) - > OnSpawnedEntity ( a_World , a_Entity ) )
{
return true ;
}
}
return false ;
}
bool cPluginManager : : CallHookSpawnedMonster ( cWorld & a_World , cMonster & a_Monster )
{
2014-06-14 04:51:42 -04:00
FIND_HOOK ( HOOK_SPAWNED_MONSTER ) ;
VERIFY_HOOK ;
2013-08-08 03:13:13 -04:00
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
if ( ( * itr ) - > OnSpawnedMonster ( a_World , a_Monster ) )
{
return true ;
}
}
return false ;
}
bool cPluginManager : : CallHookSpawningEntity ( cWorld & a_World , cEntity & a_Entity )
{
2014-06-14 04:51:42 -04:00
FIND_HOOK ( HOOK_SPAWNING_ENTITY ) ;
VERIFY_HOOK ;
2013-08-08 03:13:13 -04:00
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
if ( ( * itr ) - > OnSpawningEntity ( a_World , a_Entity ) )
{
return true ;
}
}
return false ;
}
bool cPluginManager : : CallHookSpawningMonster ( cWorld & a_World , cMonster & a_Monster )
{
2014-06-14 04:51:42 -04:00
FIND_HOOK ( HOOK_SPAWNING_MONSTER ) ;
VERIFY_HOOK ;
2013-08-08 03:13:13 -04:00
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
if ( ( * itr ) - > OnSpawningMonster ( a_World , a_Monster ) )
{
return true ;
}
}
return false ;
}
2013-07-01 06:39:56 -04:00
bool cPluginManager : : CallHookTakeDamage ( cEntity & a_Receiver , TakeDamageInfo & a_TDI )
2013-01-11 23:46:01 -05:00
{
2014-06-14 04:51:42 -04:00
FIND_HOOK ( HOOK_TAKE_DAMAGE ) ;
VERIFY_HOOK ;
2013-01-11 23:46:01 -05:00
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
if ( ( * itr ) - > OnTakeDamage ( a_Receiver , a_TDI ) )
2012-06-14 15:20:31 -04:00
{
return true ;
}
}
return false ;
}
2012-09-01 17:31:20 -04:00
bool cPluginManager : : 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 )
2012-06-16 11:06:14 -04:00
{
2014-06-14 04:51:42 -04:00
FIND_HOOK ( HOOK_UPDATING_SIGN ) ;
VERIFY_HOOK ;
2012-06-16 11:06:14 -04:00
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
2012-09-01 17:31:20 -04:00
if ( ( * itr ) - > OnUpdatingSign ( a_World , a_BlockX , a_BlockY , a_BlockZ , a_Line1 , a_Line2 , a_Line3 , a_Line4 , a_Player ) )
2012-06-16 11:06:14 -04:00
{
return true ;
}
}
return false ;
}
2012-09-01 17:31:20 -04:00
bool cPluginManager : : 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 )
2012-06-16 11:06:14 -04:00
{
2014-06-14 04:51:42 -04:00
FIND_HOOK ( HOOK_UPDATED_SIGN ) ;
VERIFY_HOOK ;
2012-06-16 11:06:14 -04:00
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
2012-09-01 17:31:20 -04:00
if ( ( * itr ) - > OnUpdatedSign ( a_World , a_BlockX , a_BlockY , a_BlockZ , a_Line1 , a_Line2 , a_Line3 , a_Line4 , a_Player ) )
2012-06-16 11:06:14 -04:00
{
return true ;
}
}
return false ;
}
2013-02-13 14:22:08 -05:00
bool cPluginManager : : CallHookWeatherChanged ( cWorld & a_World )
2012-09-05 16:30:27 -04:00
{
2014-06-14 04:51:42 -04:00
FIND_HOOK ( HOOK_WEATHER_CHANGED ) ;
VERIFY_HOOK ;
2012-09-05 16:30:27 -04:00
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
2013-01-11 23:46:01 -05:00
if ( ( * itr ) - > OnWeatherChanged ( a_World ) )
2012-09-05 16:30:27 -04:00
{
return true ;
}
}
return false ;
}
2012-06-16 11:06:14 -04:00
2013-02-13 14:22:08 -05:00
bool cPluginManager : : CallHookWeatherChanging ( cWorld & a_World , eWeather & a_NewWeather )
{
2014-06-14 04:51:42 -04:00
FIND_HOOK ( HOOK_WEATHER_CHANGING ) ;
VERIFY_HOOK ;
2013-02-13 14:22:08 -05:00
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
if ( ( * itr ) - > OnWeatherChanging ( a_World , a_NewWeather ) )
{
return true ;
}
}
return false ;
}
2013-12-11 06:39:13 -05:00
bool cPluginManager : : CallHookWorldStarted ( cWorld & a_World )
{
2014-06-14 04:51:42 -04:00
FIND_HOOK ( HOOK_WORLD_STARTED ) ;
VERIFY_HOOK ;
2013-12-11 06:39:13 -05:00
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
if ( ( * itr ) - > OnWorldStarted ( a_World ) )
{
return true ;
}
}
return false ;
}
2013-11-30 08:22:26 -05:00
bool cPluginManager : : CallHookWorldTick ( cWorld & a_World , float a_Dt , int a_LastTickDurationMSec )
2013-08-19 03:28:22 -04:00
{
2014-06-14 04:51:42 -04:00
FIND_HOOK ( HOOK_WORLD_TICK ) ;
VERIFY_HOOK ;
2013-08-19 03:28:22 -04:00
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
2013-11-30 08:22:26 -05:00
if ( ( * itr ) - > OnWorldTick ( a_World , a_Dt , a_LastTickDurationMSec ) )
2013-08-19 03:28:22 -04:00
{
return true ;
}
}
return false ;
}
2013-12-18 17:05:41 -05:00
bool cPluginManager : : HandleCommand ( cPlayer * a_Player , const AString & a_Command , bool a_ShouldCheckPermissions , bool & a_WasCommandForbidden )
2013-02-01 14:55:42 -05:00
{
ASSERT ( a_Player ! = NULL ) ;
2013-11-16 13:15:12 -05:00
2013-02-01 14:55:42 -05:00
AStringVector Split ( StringSplit ( a_Command , " " ) ) ;
if ( Split . empty ( ) )
{
return false ;
}
2013-11-16 13:15:12 -05:00
2013-02-01 14:55:42 -05:00
CommandMap : : iterator cmd = m_Commands . find ( Split [ 0 ] ) ;
if ( cmd = = m_Commands . end ( ) )
{
// Command not found
return false ;
}
2013-11-16 13:15:12 -05:00
2013-02-21 08:47:01 -05:00
// Ask plugins first if a command is okay to execute the command:
if ( CallHookExecuteCommand ( a_Player , Split ) )
{
2013-12-18 17:05:41 -05:00
LOGINFO ( " Player %s tried executing command \" %s \" that was stopped by the HOOK_EXECUTE_COMMAND hook " , a_Player - > GetName ( ) . c_str ( ) , Split [ 0 ] . c_str ( ) ) ;
2013-02-21 08:47:01 -05:00
return false ;
}
2013-11-16 13:15:12 -05:00
2013-02-01 14:55:42 -05:00
if (
a_ShouldCheckPermissions & &
! cmd - > second . m_Permission . empty ( ) & &
! a_Player - > HasPermission ( cmd - > second . m_Permission )
)
{
2014-02-05 18:24:16 -05:00
a_Player - > SendMessageFailure ( Printf ( " Forbidden command; insufficient privileges: \" %s \" " , Split [ 0 ] . c_str ( ) ) ) ;
2013-12-18 17:05:41 -05:00
LOGINFO ( " Player %s tried to execute forbidden command: \" %s \" " , a_Player - > GetName ( ) . c_str ( ) , Split [ 0 ] . c_str ( ) ) ;
a_WasCommandForbidden = true ;
2013-02-01 14:55:42 -05:00
return false ;
}
ASSERT ( cmd - > second . m_Plugin ! = NULL ) ;
2013-11-16 13:15:12 -05:00
return cmd - > second . m_Plugin - > HandleCommand ( Split , a_Player ) ;
2013-02-01 14:55:42 -05:00
}
cPlugin * cPluginManager : : GetPlugin ( const AString & a_Plugin ) const
2012-06-14 09:06:06 -04:00
{
2012-10-13 19:34:47 -04:00
for ( PluginMap : : const_iterator itr = m_Plugins . begin ( ) ; itr ! = m_Plugins . end ( ) ; + + itr )
2012-06-14 09:06:06 -04:00
{
2012-10-13 19:34:47 -04:00
if ( itr - > second = = NULL ) continue ;
if ( itr - > second - > GetName ( ) . compare ( a_Plugin ) = = 0 )
2012-06-14 09:06:06 -04:00
{
2012-10-13 19:34:47 -04:00
return itr - > second ;
2012-06-14 09:06:06 -04:00
}
}
return 0 ;
}
2012-10-13 19:34:47 -04:00
const cPluginManager : : PluginMap & cPluginManager : : GetAllPlugins ( ) const
2012-06-14 09:06:06 -04:00
{
return m_Plugins ;
}
void cPluginManager : : UnloadPluginsNow ( )
{
m_Hooks . clear ( ) ;
2013-02-01 14:55:42 -05:00
while ( ! m_Plugins . empty ( ) )
2012-10-13 19:34:47 -04:00
{
2013-02-01 14:55:42 -05:00
RemovePlugin ( m_Plugins . begin ( ) - > second ) ;
2012-10-13 19:34:47 -04:00
}
2013-04-27 10:08:23 -04:00
m_Commands . clear ( ) ;
m_ConsoleCommands . clear ( ) ;
2012-10-13 19:34:47 -04:00
}
2013-02-01 14:55:42 -05:00
bool cPluginManager : : DisablePlugin ( const AString & a_PluginName )
2012-10-13 19:34:47 -04:00
{
2013-02-01 14:55:42 -05:00
PluginMap : : iterator itr = m_Plugins . find ( a_PluginName ) ;
if ( itr = = m_Plugins . end ( ) )
2012-06-14 09:06:06 -04:00
{
2013-02-01 14:55:42 -05:00
return false ;
}
2013-11-16 13:15:12 -05:00
2013-02-01 14:55:42 -05:00
if ( itr - > first . compare ( a_PluginName ) = = 0 ) // _X 2013_02_01: wtf? Isn't this supposed to be what find() does?
{
m_DisablePluginList . push_back ( itr - > second ) ;
itr - > second = NULL ; // Get rid of this thing right away
return true ;
2012-06-14 09:06:06 -04:00
}
2012-10-13 19:34:47 -04:00
return false ;
}
2012-06-14 09:06:06 -04:00
2012-10-13 19:34:47 -04:00
2013-02-01 14:55:42 -05:00
bool cPluginManager : : LoadPlugin ( const AString & a_PluginName )
2012-10-13 19:34:47 -04:00
{
2013-08-19 03:39:18 -04:00
return AddPlugin ( new cPluginLua ( a_PluginName . c_str ( ) ) ) ;
2012-06-14 09:06:06 -04:00
}
2013-01-11 23:46:01 -05:00
void cPluginManager : : RemoveHooks ( cPlugin * a_Plugin )
2012-06-14 09:06:06 -04:00
{
2013-01-11 23:46:01 -05:00
for ( HookMap : : iterator itr = m_Hooks . begin ( ) , end = m_Hooks . end ( ) ; itr ! = end ; + + itr )
{
itr - > second . remove ( a_Plugin ) ;
}
2012-06-14 09:06:06 -04:00
}
2013-02-01 14:55:42 -05:00
void cPluginManager : : RemovePlugin ( cPlugin * a_Plugin )
2012-06-14 09:06:06 -04:00
{
2013-02-01 14:55:42 -05:00
for ( PluginMap : : iterator itr = m_Plugins . begin ( ) ; itr ! = m_Plugins . end ( ) ; + + itr )
{
if ( itr - > second = = a_Plugin )
{
m_Plugins . erase ( itr ) ;
break ;
}
}
2013-11-16 13:15:12 -05:00
2013-02-01 14:55:42 -05:00
RemovePluginCommands ( a_Plugin ) ;
2013-02-15 08:00:59 -05:00
RemovePluginConsoleCommands ( a_Plugin ) ;
2013-02-01 14:55:42 -05:00
RemoveHooks ( a_Plugin ) ;
if ( a_Plugin ! = NULL )
2012-06-14 09:06:06 -04:00
{
2013-02-01 14:55:42 -05:00
a_Plugin - > OnDisable ( ) ;
}
delete a_Plugin ;
}
2012-07-09 11:53:17 -04:00
2013-02-01 14:55:42 -05:00
void cPluginManager : : RemovePluginCommands ( cPlugin * a_Plugin )
{
if ( a_Plugin ! = NULL )
{
a_Plugin - > ClearCommands ( ) ;
}
2013-11-16 13:15:12 -05:00
2013-02-01 14:55:42 -05:00
for ( CommandMap : : iterator itr = m_Commands . begin ( ) ; itr ! = m_Commands . end ( ) ; )
{
if ( itr - > second . m_Plugin = = a_Plugin )
2012-10-13 19:34:47 -04:00
{
2013-02-01 15:29:23 -05:00
CommandMap : : iterator EraseMe = itr ; // Stupid GCC doesn't have a std::map::erase() that would return the next iterator
+ + itr ;
m_Commands . erase ( EraseMe ) ;
2012-10-13 19:34:47 -04:00
}
2013-02-01 14:55:42 -05:00
else
2012-06-14 09:06:06 -04:00
{
2013-02-01 14:55:42 -05:00
+ + itr ;
2012-06-14 09:06:06 -04:00
}
2013-02-01 14:55:42 -05:00
} // for itr - m_Commands[]
}
bool cPluginManager : : BindCommand ( const AString & a_Command , cPlugin * a_Plugin , const AString & a_Permission , const AString & a_HelpString )
{
CommandMap : : iterator cmd = m_Commands . find ( a_Command ) ;
if ( cmd ! = m_Commands . end ( ) )
{
LOGWARNING ( " Command \" %s \" is already bound to plugin \" %s \" . " , a_Command . c_str ( ) , cmd - > second . m_Plugin - > GetName ( ) . c_str ( ) ) ;
return false ;
2012-06-14 09:06:06 -04:00
}
2013-11-16 13:15:12 -05:00
2013-02-01 14:55:42 -05:00
m_Commands [ a_Command ] . m_Plugin = a_Plugin ;
m_Commands [ a_Command ] . m_Permission = a_Permission ;
m_Commands [ a_Command ] . m_HelpString = a_HelpString ;
return true ;
2012-06-14 09:06:06 -04:00
}
2013-02-01 14:55:42 -05:00
bool cPluginManager : : ForEachCommand ( cCommandEnumCallback & a_Callback )
2012-06-14 09:06:06 -04:00
{
2013-02-01 14:55:42 -05:00
for ( CommandMap : : iterator itr = m_Commands . begin ( ) , end = m_Commands . end ( ) ; itr ! = end ; + + itr )
2012-06-14 09:06:06 -04:00
{
2013-02-01 14:55:42 -05:00
if ( a_Callback . Command ( itr - > first , itr - > second . m_Plugin , itr - > second . m_Permission , itr - > second . m_HelpString ) )
{
return false ;
}
} // for itr - m_Commands[]
return true ;
}
bool cPluginManager : : IsCommandBound ( const AString & a_Command )
{
return ( m_Commands . find ( a_Command ) ! = m_Commands . end ( ) ) ;
}
AString cPluginManager : : GetCommandPermission ( const AString & a_Command )
{
CommandMap : : iterator cmd = m_Commands . find ( a_Command ) ;
return ( cmd = = m_Commands . end ( ) ) ? " " : cmd - > second . m_Permission ;
}
bool cPluginManager : : ExecuteCommand ( cPlayer * a_Player , const AString & a_Command )
{
return HandleCommand ( a_Player , a_Command , true ) ;
}
bool cPluginManager : : ForceExecuteCommand ( cPlayer * a_Player , const AString & a_Command )
{
return HandleCommand ( a_Player , a_Command , false ) ;
}
2013-02-15 08:00:59 -05:00
void cPluginManager : : RemovePluginConsoleCommands ( cPlugin * a_Plugin )
{
if ( a_Plugin ! = NULL )
{
a_Plugin - > ClearConsoleCommands ( ) ;
}
2013-11-16 13:15:12 -05:00
2013-02-15 08:00:59 -05:00
for ( CommandMap : : iterator itr = m_ConsoleCommands . begin ( ) ; itr ! = m_ConsoleCommands . end ( ) ; )
{
if ( itr - > second . m_Plugin = = a_Plugin )
{
CommandMap : : iterator EraseMe = itr ; // Stupid GCC doesn't have a std::map::erase() that would return the next iterator
+ + itr ;
m_ConsoleCommands . erase ( EraseMe ) ;
}
else
{
+ + itr ;
}
} // for itr - m_Commands[]
}
bool cPluginManager : : BindConsoleCommand ( const AString & a_Command , cPlugin * a_Plugin , const AString & a_HelpString )
{
CommandMap : : iterator cmd = m_ConsoleCommands . find ( a_Command ) ;
if ( cmd ! = m_ConsoleCommands . end ( ) )
{
2013-04-27 10:08:23 -04:00
if ( cmd - > second . m_Plugin = = NULL )
{
2013-11-13 09:50:05 -05:00
LOGWARNING ( " Console command \" %s \" is already bound internally by MCServer, cannot bind in plugin \" %s \" . " , a_Command . c_str ( ) , a_Plugin - > GetName ( ) . c_str ( ) ) ;
2013-04-27 10:08:23 -04:00
}
else
{
2013-11-13 09:50:05 -05:00
LOGWARNING ( " Console command \" %s \" is already bound to plugin \" %s \" , cannot bind in plugin \" %s \" . " , a_Command . c_str ( ) , cmd - > second . m_Plugin - > GetName ( ) . c_str ( ) , a_Plugin - > GetName ( ) . c_str ( ) ) ;
2013-04-27 10:08:23 -04:00
}
2013-02-15 08:00:59 -05:00
return false ;
}
2013-11-16 13:15:12 -05:00
2013-02-15 08:00:59 -05:00
m_ConsoleCommands [ a_Command ] . m_Plugin = a_Plugin ;
m_ConsoleCommands [ a_Command ] . m_Permission = " " ;
m_ConsoleCommands [ a_Command ] . m_HelpString = a_HelpString ;
return true ;
}
bool cPluginManager : : ForEachConsoleCommand ( cCommandEnumCallback & a_Callback )
{
for ( CommandMap : : iterator itr = m_ConsoleCommands . begin ( ) , end = m_ConsoleCommands . end ( ) ; itr ! = end ; + + itr )
{
if ( a_Callback . Command ( itr - > first , itr - > second . m_Plugin , " " , itr - > second . m_HelpString ) )
{
return false ;
}
} // for itr - m_Commands[]
return true ;
}
bool cPluginManager : : IsConsoleCommandBound ( const AString & a_Command )
{
return ( m_ConsoleCommands . find ( a_Command ) ! = m_ConsoleCommands . end ( ) ) ;
}
2013-06-29 11:30:05 -04:00
bool cPluginManager : : ExecuteConsoleCommand ( const AStringVector & a_Split , cCommandOutputCallback & a_Output )
2013-02-15 08:00:59 -05:00
{
if ( a_Split . empty ( ) )
{
return false ;
}
2013-11-16 13:15:12 -05:00
2013-02-15 08:00:59 -05:00
CommandMap : : iterator cmd = m_ConsoleCommands . find ( a_Split [ 0 ] ) ;
if ( cmd = = m_ConsoleCommands . end ( ) )
{
// Command not found
return false ;
}
2013-11-16 13:15:12 -05:00
2013-02-15 08:00:59 -05:00
if ( cmd - > second . m_Plugin = = NULL )
{
// This is a built-in command
return false ;
}
2013-11-16 13:15:12 -05:00
2013-02-21 08:47:01 -05:00
// Ask plugins first if a command is okay to execute the console command:
if ( CallHookExecuteCommand ( NULL , a_Split ) )
{
2013-06-29 11:30:05 -04:00
a_Output . Out ( " Command \" %s \" was stopped by the HOOK_EXECUTE_COMMAND hook " , a_Split [ 0 ] . c_str ( ) ) ;
2013-02-21 08:47:01 -05:00
return false ;
}
2013-11-16 13:15:12 -05:00
return cmd - > second . m_Plugin - > HandleConsoleCommand ( a_Split , a_Output ) ;
2013-02-15 08:00:59 -05:00
}
2013-07-31 05:16:11 -04:00
void cPluginManager : : TabCompleteCommand ( const AString & a_Text , AStringVector & a_Results , cPlayer * a_Player )
{
for ( CommandMap : : iterator itr = m_Commands . begin ( ) , end = m_Commands . end ( ) ; itr ! = end ; + + itr )
{
if ( NoCaseCompare ( itr - > first . substr ( 0 , a_Text . length ( ) ) , a_Text ) ! = 0 )
{
// Command name doesn't match
continue ;
}
if ( ( a_Player ! = NULL ) & & ! a_Player - > HasPermission ( itr - > second . m_Permission ) )
{
// Player doesn't have permission for the command
continue ;
}
a_Results . push_back ( itr - > first ) ;
}
2013-07-30 16:48:59 -04:00
}
2013-08-21 15:29:30 -04:00
bool cPluginManager : : IsValidHookType ( int a_HookType )
{
return ( ( a_HookType > = 0 ) & & ( a_HookType < = HOOK_MAX ) ) ;
}
2014-01-21 16:59:08 -05:00
bool cPluginManager : : DoWithPlugin ( const AString & a_PluginName , cPluginCallback & a_Callback )
{
// TODO: Implement locking for plugins
PluginMap : : iterator itr = m_Plugins . find ( a_PluginName ) ;
2014-01-23 10:14:00 -05:00
if ( ( itr = = m_Plugins . end ( ) ) | | ( itr - > second = = NULL ) )
2014-01-21 16:59:08 -05:00
{
return false ;
}
return a_Callback . Item ( itr - > second ) ;
}
2013-02-01 14:55:42 -05:00
bool cPluginManager : : AddPlugin ( cPlugin * a_Plugin )
{
m_Plugins [ a_Plugin - > GetDirectory ( ) ] = a_Plugin ;
if ( a_Plugin - > Initialize ( ) )
{
// Initialization OK
2012-06-14 09:06:06 -04:00
return true ;
}
2013-02-01 14:55:42 -05:00
// Initialization failed
RemovePlugin ( a_Plugin ) ; // Also undoes any registrations that Initialize() might have made
2012-06-14 09:06:06 -04:00
return false ;
}
2013-08-21 15:29:30 -04:00
void cPluginManager : : AddHook ( cPlugin * a_Plugin , int a_Hook )
2012-06-14 09:06:06 -04:00
{
2013-01-11 23:46:01 -05:00
if ( ! a_Plugin )
2012-06-14 09:06:06 -04:00
{
2013-01-11 23:46:01 -05:00
LOGWARN ( " Called cPluginManager::AddHook() with a_Plugin == NULL " ) ;
2012-06-14 09:06:06 -04:00
return ;
}
2013-01-11 23:46:01 -05:00
PluginList & Plugins = m_Hooks [ a_Hook ] ;
Plugins . remove ( a_Plugin ) ;
Plugins . push_back ( a_Plugin ) ;
2012-06-14 09:06:06 -04:00
}
2014-05-08 14:16:35 -04:00
size_t cPluginManager : : GetNumPlugins ( ) const
2012-06-14 09:06:06 -04:00
{
2013-11-16 13:15:12 -05:00
return m_Plugins . size ( ) ;
2012-06-14 09:06:06 -04:00
}