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"
2012-09-23 18:09:57 -04:00
# include "WebAdmin.h"
# include "Item.h"
# include "Root.h"
2013-02-15 08:00:59 -05:00
# include "Server.h"
2013-06-29 11:30:05 -04:00
# include "CommandOutput.h"
2012-08-16 02:47:09 -04:00
2012-06-14 09:06:06 -04:00
# include "../iniFile/iniFile.h"
# include "tolua++.h"
2013-08-19 05:39:13 -04:00
# include "Entities/Player.h"
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
{
AString PluginsPath = FILE_IO_PREFIX + AString ( " Plugins/ " ) ;
// 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 ;
}
AStringList Files = GetDirectoryContents ( PluginsPath . c_str ( ) ) ;
for ( AStringList : : const_iterator itr = Files . begin ( ) ; itr ! = Files . end ( ) ; + + itr )
{
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-04 16:51:24 -05:00
unsigned int KeyNum = a_SettingsIni . FindKey ( " Plugins " ) ;
unsigned int NumPlugins = ( ( KeyNum ! = - 1 ) ? ( a_SettingsIni . GetNumValues ( KeyNum ) ) : 0 ) ;
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
{
for ( unsigned int i = 0 ; i < NumPlugins ; i + + )
{
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
{
2012-10-13 19:34:47 -04:00
LoadPlugin ( PluginFile ) ;
2012-06-14 09:06:06 -04:00
}
}
}
}
}
2013-02-01 14:55:42 -05:00
if ( GetNumPlugins ( ) = = 0 )
2012-06-14 09:06:06 -04:00
{
2013-09-28 15:36:01 -04:00
LOG ( " -- No Plugins Loaded -- " ) ;
}
2013-11-04 16:51:24 -05:00
else if ( GetNumPlugins ( ) > 1 )
2013-09-28 15:36:01 -04:00
{
LOG ( " -- Loaded %i Plugins -- " , GetNumPlugins ( ) ) ;
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-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 " ) ;
a_SettingsIni . SetValue ( " Plugins " , " Plugin " , " Core " ) ;
a_SettingsIni . SetValue ( " Plugins " , " Plugin " , " TransAPI " ) ;
a_SettingsIni . SetValue ( " Plugins " , " Plugin " , " ChatLog " ) ;
}
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 ( ) ;
}
2013-01-11 23:46:01 -05:00
HookMap : : iterator Plugins = m_Hooks . find ( 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
}
}
}
2013-01-26 21:00:33 -05:00
bool cPluginManager : : CallHookBlockToPickups (
cWorld * a_World , cEntity * a_Digger ,
int a_BlockX , int a_BlockY , int a_BlockZ , BLOCKTYPE a_BlockType , NIBBLETYPE a_BlockMeta ,
cItems & a_Pickups
2013-01-11 23:46:01 -05:00
)
2012-08-18 05:56:28 -04:00
{
2013-01-26 21:00:33 -05:00
HookMap : : iterator Plugins = m_Hooks . find ( HOOK_BLOCK_TO_PICKUPS ) ;
2012-08-18 05:56:28 -04:00
if ( Plugins = = m_Hooks . end ( ) )
{
return false ;
}
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-02-01 14:55:42 -05:00
if ( ExecuteCommand ( a_Player , a_Message ) )
2012-08-18 06:38:15 -04:00
{
return true ;
}
2013-01-11 23:46:01 -05:00
// Check if it was a standard command (starts with a slash)
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
a_Player - > SendMessage ( Printf ( " Unknown Command: \" %s \" " , Split [ 0 ] . c_str ( ) ) ) ;
2012-08-18 06:38:15 -04:00
LOGINFO ( " Player \" %s \" issued an unknown command: \" %s \" " , a_Player - > GetName ( ) . c_str ( ) , a_Message . c_str ( ) ) ;
return true ; // Cancel sending
}
HookMap : : iterator Plugins = m_Hooks . find ( HOOK_CHAT ) ;
if ( Plugins = = m_Hooks . end ( ) )
{
return false ;
}
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
if ( ( * itr ) - > OnChat ( a_Player , a_Message ) )
{
return true ;
}
}
return false ;
}
2013-02-05 14:57:22 -05:00
bool cPluginManager : : CallHookChunkAvailable ( cWorld * a_World , int a_ChunkX , int a_ChunkZ )
{
HookMap : : iterator Plugins = m_Hooks . find ( HOOK_CHUNK_AVAILABLE ) ;
if ( Plugins = = m_Hooks . end ( ) )
{
return false ;
}
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
{
HookMap : : iterator Plugins = m_Hooks . find ( HOOK_CHUNK_GENERATED ) ;
if ( Plugins = = m_Hooks . end ( ) )
{
return false ;
}
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
{
HookMap : : iterator Plugins = m_Hooks . find ( HOOK_CHUNK_GENERATING ) ;
if ( Plugins = = m_Hooks . end ( ) )
{
return false ;
}
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 )
{
HookMap : : iterator Plugins = m_Hooks . find ( HOOK_CHUNK_UNLOADED ) ;
if ( Plugins = = m_Hooks . end ( ) )
{
return false ;
}
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 )
{
HookMap : : iterator Plugins = m_Hooks . find ( HOOK_CHUNK_UNLOADING ) ;
if ( Plugins = = m_Hooks . end ( ) )
{
return false ;
}
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
{
2013-01-28 11:17:26 -05:00
HookMap : : iterator Plugins = m_Hooks . find ( HOOK_COLLECTING_PICKUP ) ;
2012-08-24 05:49:00 -04:00
if ( Plugins = = m_Hooks . end ( ) )
{
return false ;
}
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
{
2012-12-21 06:04:08 -05:00
HookMap : : iterator Plugins = m_Hooks . find ( HOOK_CRAFTING_NO_RECIPE ) ;
2012-06-14 09:06:06 -04:00
if ( Plugins = = m_Hooks . end ( ) )
{
return false ;
}
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 ;
}
2012-12-21 06:04:08 -05:00
bool cPluginManager : : CallHookDisconnect ( cPlayer * a_Player , const AString & a_Reason )
2012-06-14 09:06:06 -04:00
{
2012-12-21 06:04:08 -05:00
HookMap : : iterator Plugins = m_Hooks . find ( HOOK_DISCONNECT ) ;
2012-06-14 09:06:06 -04:00
if ( Plugins = = m_Hooks . end ( ) )
{
return false ;
}
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
2012-12-21 06:04:08 -05:00
if ( ( * itr ) - > OnDisconnect ( a_Player , a_Reason ) )
2012-06-14 09:06:06 -04:00
{
return true ;
}
}
return false ;
}
2013-02-21 08:47:01 -05:00
bool cPluginManager : : CallHookExecuteCommand ( cPlayer * a_Player , const AStringVector & a_Split )
{
HookMap : : iterator Plugins = m_Hooks . find ( HOOK_EXECUTE_COMMAND ) ;
if ( Plugins = = m_Hooks . end ( ) )
{
return false ;
}
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 )
{
HookMap : : iterator Plugins = m_Hooks . find ( HOOK_EXPLODED ) ;
if ( Plugins = = m_Hooks . end ( ) )
{
return false ;
}
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 )
{
HookMap : : iterator Plugins = m_Hooks . find ( HOOK_EXPLODING ) ;
if ( Plugins = = m_Hooks . end ( ) )
{
return false ;
}
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
{
2013-01-11 23:46:01 -05:00
HookMap : : iterator Plugins = m_Hooks . find ( HOOK_HANDSHAKE ) ;
2012-08-19 15:42:32 -04:00
if ( Plugins = = m_Hooks . end ( ) )
{
return false ;
}
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 )
{
HookMap : : iterator Plugins = m_Hooks . find ( HOOK_HOPPER_PULLING_ITEM ) ;
if ( Plugins = = m_Hooks . end ( ) )
{
return false ;
}
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 )
{
HookMap : : iterator Plugins = m_Hooks . find ( HOOK_HOPPER_PUSHING_ITEM ) ;
if ( Plugins = = m_Hooks . end ( ) )
{
return false ;
}
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
{
2013-01-28 11:54:11 -05:00
HookMap : : iterator Plugins = m_Hooks . find ( HOOK_KILLING ) ;
2012-06-14 09:06:06 -04:00
if ( Plugins = = m_Hooks . end ( ) )
{
return false ;
}
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
{
2013-01-11 23:46:01 -05:00
HookMap : : iterator Plugins = m_Hooks . find ( HOOK_LOGIN ) ;
2012-12-21 06:04:08 -05:00
if ( Plugins = = m_Hooks . end ( ) )
{
return false ;
}
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-08-11 06:12:20 -04:00
bool cPluginManager : : CallHookPlayerAnimation ( cPlayer & a_Player , int a_Animation )
{
HookMap : : iterator Plugins = m_Hooks . find ( HOOK_PLAYER_ANIMATION ) ;
if ( Plugins = = m_Hooks . end ( ) )
{
return false ;
}
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
if ( ( * itr ) - > OnPlayerAnimation ( a_Player , a_Animation ) )
{
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 )
{
HookMap : : iterator Plugins = m_Hooks . find ( HOOK_PLAYER_BREAKING_BLOCK ) ;
if ( Plugins = = m_Hooks . end ( ) )
{
return false ;
}
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 )
{
HookMap : : iterator Plugins = m_Hooks . find ( HOOK_PLAYER_BROKEN_BLOCK ) ;
if ( Plugins = = m_Hooks . end ( ) )
{
return false ;
}
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 ;
}
bool cPluginManager : : CallHookPlayerEating ( cPlayer & a_Player )
{
HookMap : : iterator Plugins = m_Hooks . find ( HOOK_PLAYER_EATING ) ;
if ( Plugins = = m_Hooks . end ( ) )
{
return false ;
}
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
if ( ( * itr ) - > OnPlayerEating ( a_Player ) )
{
return true ;
}
}
return false ;
}
bool cPluginManager : : CallHookPlayerJoined ( cPlayer & a_Player )
{
HookMap : : iterator Plugins = m_Hooks . find ( HOOK_PLAYER_JOINED ) ;
if ( Plugins = = m_Hooks . end ( ) )
{
return false ;
}
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 )
{
HookMap : : iterator Plugins = m_Hooks . find ( HOOK_PLAYER_LEFT_CLICK ) ;
if ( Plugins = = m_Hooks . end ( ) )
{
return false ;
}
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
{
2013-01-26 02:50:06 -05:00
HookMap : : iterator Plugins = m_Hooks . find ( HOOK_PLAYER_MOVING ) ;
2013-01-11 23:46:01 -05:00
if ( Plugins = = m_Hooks . end ( ) )
{
return false ;
}
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 )
{
HookMap : : iterator Plugins = m_Hooks . find ( HOOK_PLAYER_PLACED_BLOCK ) ;
if ( Plugins = = m_Hooks . end ( ) )
{
return false ;
}
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 )
{
HookMap : : iterator Plugins = m_Hooks . find ( HOOK_PLAYER_PLACING_BLOCK ) ;
if ( Plugins = = m_Hooks . end ( ) )
{
return false ;
}
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 )
{
2013-01-18 13:28:27 -05:00
HookMap : : iterator Plugins = m_Hooks . find ( HOOK_PLAYER_RIGHT_CLICK ) ;
2013-01-11 23:46:01 -05:00
if ( Plugins = = m_Hooks . end ( ) )
{
return false ;
}
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 )
{
HookMap : : iterator Plugins = m_Hooks . find ( HOOK_PLAYER_RIGHT_CLICKING_ENTITY ) ;
if ( Plugins = = m_Hooks . end ( ) )
{
return false ;
}
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 )
{
HookMap : : iterator Plugins = m_Hooks . find ( HOOK_PLAYER_SHOOTING ) ;
if ( Plugins = = m_Hooks . end ( ) )
{
return false ;
}
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 )
{
HookMap : : iterator Plugins = m_Hooks . find ( HOOK_PLAYER_SPAWNED ) ;
if ( Plugins = = m_Hooks . end ( ) )
{
return false ;
}
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 )
{
HookMap : : iterator Plugins = m_Hooks . find ( HOOK_PLAYER_TOSSING_ITEM ) ;
if ( Plugins = = m_Hooks . end ( ) )
{
return false ;
}
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 )
{
HookMap : : iterator Plugins = m_Hooks . find ( HOOK_PLAYER_USED_BLOCK ) ;
if ( Plugins = = m_Hooks . end ( ) )
{
return false ;
}
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 )
{
HookMap : : iterator Plugins = m_Hooks . find ( HOOK_PLAYER_USED_ITEM ) ;
if ( Plugins = = m_Hooks . end ( ) )
{
return false ;
}
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 )
{
HookMap : : iterator Plugins = m_Hooks . find ( HOOK_PLAYER_USING_BLOCK ) ;
if ( Plugins = = m_Hooks . end ( ) )
{
return false ;
}
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 )
{
HookMap : : iterator Plugins = m_Hooks . find ( HOOK_PLAYER_USING_ITEM ) ;
if ( Plugins = = m_Hooks . end ( ) )
{
return false ;
}
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 ;
}
bool cPluginManager : : CallHookPostCrafting ( const cPlayer * a_Player , const cCraftingGrid * a_Grid , cCraftingRecipe * a_Recipe )
2012-06-14 09:06:06 -04:00
{
HookMap : : iterator Plugins = m_Hooks . find ( HOOK_POST_CRAFTING ) ;
if ( Plugins = = m_Hooks . end ( ) )
{
return false ;
}
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
{
2013-01-11 23:46:01 -05:00
HookMap : : iterator Plugins = m_Hooks . find ( HOOK_PRE_CRAFTING ) ;
2012-06-14 15:20:31 -04:00
if ( Plugins = = m_Hooks . end ( ) )
{
return false ;
}
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 ;
}
2013-08-08 03:13:13 -04:00
bool cPluginManager : : CallHookSpawnedEntity ( cWorld & a_World , cEntity & a_Entity )
{
HookMap : : iterator Plugins = m_Hooks . find ( HOOK_SPAWNED_ENTITY ) ;
if ( Plugins = = m_Hooks . end ( ) )
{
return false ;
}
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 )
{
HookMap : : iterator Plugins = m_Hooks . find ( HOOK_SPAWNED_MONSTER ) ;
if ( Plugins = = m_Hooks . end ( ) )
{
return false ;
}
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 )
{
HookMap : : iterator Plugins = m_Hooks . find ( HOOK_SPAWNING_ENTITY ) ;
if ( Plugins = = m_Hooks . end ( ) )
{
return false ;
}
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 )
{
HookMap : : iterator Plugins = m_Hooks . find ( HOOK_SPAWNING_MONSTER ) ;
if ( Plugins = = m_Hooks . end ( ) )
{
return false ;
}
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
{
HookMap : : iterator Plugins = m_Hooks . find ( HOOK_TAKE_DAMAGE ) ;
if ( Plugins = = m_Hooks . end ( ) )
{
return false ;
}
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
{
HookMap : : iterator Plugins = m_Hooks . find ( HOOK_UPDATING_SIGN ) ;
if ( Plugins = = m_Hooks . end ( ) )
{
return false ;
}
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
{
HookMap : : iterator Plugins = m_Hooks . find ( HOOK_UPDATED_SIGN ) ;
if ( Plugins = = m_Hooks . end ( ) )
{
return false ;
}
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
{
2013-01-11 23:46:01 -05:00
HookMap : : iterator Plugins = m_Hooks . find ( HOOK_WEATHER_CHANGED ) ;
2012-09-05 16:30:27 -04:00
if ( Plugins = = m_Hooks . end ( ) )
{
return false ;
}
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 )
{
HookMap : : iterator Plugins = m_Hooks . find ( HOOK_WEATHER_CHANGING ) ;
if ( Plugins = = m_Hooks . end ( ) )
{
return false ;
}
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
if ( ( * itr ) - > OnWeatherChanging ( a_World , a_NewWeather ) )
{
return true ;
}
}
return false ;
}
2013-08-19 03:28:22 -04:00
bool cPluginManager : : CallHookWorldTick ( cWorld & a_World , float a_Dt )
{
HookMap : : iterator Plugins = m_Hooks . find ( HOOK_WORLD_TICK ) ;
if ( Plugins = = m_Hooks . end ( ) )
{
return false ;
}
for ( PluginList : : iterator itr = Plugins - > second . begin ( ) ; itr ! = Plugins - > second . end ( ) ; + + itr )
{
if ( ( * itr ) - > OnWorldTick ( a_World , a_Dt ) )
{
return true ;
}
}
return false ;
}
2013-02-01 14:55:42 -05:00
bool cPluginManager : : HandleCommand ( cPlayer * a_Player , const AString & a_Command , bool a_ShouldCheckPermissions )
{
ASSERT ( a_Player ! = NULL ) ;
AStringVector Split ( StringSplit ( a_Command , " " ) ) ;
if ( Split . empty ( ) )
{
return false ;
}
CommandMap : : iterator cmd = m_Commands . find ( Split [ 0 ] ) ;
if ( cmd = = m_Commands . end ( ) )
{
// Command not found
return false ;
}
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 ) )
{
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 ( ) ) ;
return false ;
}
2013-02-01 14:55:42 -05:00
if (
a_ShouldCheckPermissions & &
! cmd - > second . m_Permission . empty ( ) & &
! a_Player - > HasPermission ( cmd - > second . m_Permission )
)
{
LOGINFO ( " Player \" %s \" tried to execute forbidden command \" %s \" . " , a_Player - > GetName ( ) . c_str ( ) , Split [ 0 ] . c_str ( ) ) ;
return false ;
}
ASSERT ( cmd - > second . m_Plugin ! = NULL ) ;
return cmd - > second . m_Plugin - > HandleCommand ( Split , a_Player ) ;
}
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 ;
}
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 ;
}
}
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 ( ) ;
}
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-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 ( ) ;
}
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 ;
}
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 ;
}
CommandMap : : iterator cmd = m_ConsoleCommands . find ( a_Split [ 0 ] ) ;
if ( cmd = = m_ConsoleCommands . end ( ) )
{
// Command not found
return false ;
}
if ( cmd - > second . m_Plugin = = NULL )
{
// This is a built-in command
return false ;
}
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-06-29 11:30:05 -04: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 ) ) ;
}
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
}
unsigned int cPluginManager : : GetNumPlugins ( ) const
{
return m_Plugins . size ( ) ;
}