1
0

Completely removed support for old style Lua plugins (can use both Plugin and NewPlugin in settings.ini for now)

Removed cPlugin_Lua, obviously
cPluginManager stores plugins by their (folder)name
cPluginManager now scans the Plugins folder for potential plugins and adds them as non-loaded plugins
Added a DisablePlugin and LoadPlugin to disable and load plugins on a per-plugin basis instead of all at once
cPluginManager::FindPlugins refreshes the plugin list by removing non-existing plugins and adding new plugins
Made it incredibly easy to use new plugins from the WebAdmin
Exposed some food/hunger related functions in cPlayer to Lua

git-svn-id: http://mc-server.googlecode.com/svn/trunk@959 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
faketruth 2012-10-13 23:34:47 +00:00
parent b4ca06b9d9
commit 41ba1a7642
19 changed files with 638 additions and 570 deletions

View File

@ -2,31 +2,93 @@ local function Button_RemovePlugin( Name, Index )
return "<form method='POST'><input type='hidden' name='PluginName' value='"..Name.."'><input type='hidden' name='PluginIndex' value='"..Index.."'><input type='submit' name='RemovePlugin' value='Remove'></form>" return "<form method='POST'><input type='hidden' name='PluginName' value='"..Name.."'><input type='hidden' name='PluginIndex' value='"..Index.."'><input type='submit' name='RemovePlugin' value='Remove'></form>"
end end
local function Button_EnablePlugin( Name )
return [[<form method="POST"><input type="hidden" name="PluginName", value="]].. Name ..[["><input type="submit" name="EnablePlugin" value="Enable"></form>]]
end
local function Button_DisablePlugin( Name )
return [[<form method="POST"><input type="hidden" name="PluginName", value="]].. Name ..[["><input type="submit" name="DisablePlugin" value="Disable"></form>]]
end
local function FindPluginID( SettingsIni, PluginName )
local KeyIdx = SettingsIni:FindKey("Plugins")
local NumValues = SettingsIni:GetNumValues( KeyIdx )
for i = 0, NumValues-1 do
LOGINFO( SettingsIni:GetValue(KeyIdx, i) )
if( SettingsIni:GetValue(KeyIdx, i) == PluginName ) then
return i
end
end
return nil
end
local function RemovePluginFromIni( SettingsIni, PluginName )
local KeyIdx = SettingsIni:FindKey("Plugins")
local PluginIdx = FindPluginID( SettingsIni, PluginName )
if( PluginIdx == nil ) then
LOGINFO("Got nil! NOOOO")
return false
end
local Name = SettingsIni:GetValue( KeyIdx, PluginIdx )
if( Name ~= PluginName ) then
LOGINFO("not the same name T_T '" .. Name .. "' '" .. PluginName .. "'")
end
if( (Name == PluginName) and (SettingsIni:DeleteValueByID( KeyIdx, PluginIdx ) == true) ) then
return SettingsIni:WriteFile()
end
return false
end
local function AddPluginToIni( SettingsIni, PluginName )
RemovePluginFromIni( SettingsIni, PluginName ) -- Make sure there are no duplicates
if( SettingsIni:SetValue("Plugins", "Plugin", PluginName, true ) == true ) then
return SettingsIni:WriteFile()
end
return false
end
local function HandlePluginListChanges( Request, SettingsIni ) local function HandlePluginListChanges( Request, SettingsIni )
local Content = "" local Content = ""
if( Request.PostParams["RemovePlugin"] ~= nil
and Request.PostParams["PluginName"] ~= nil if( Request.PostParams["EnablePlugin"] ~= nil
and Request.PostParams["PluginIndex"] ~= nil ) then -- Removing a plugin and Request.PostParams["PluginName"] ~= nil ) then
local KeyIdx = SettingsIni:FindKey("Plugins") local PluginName = Request.PostParams["PluginName"]
local PluginIdx = Request.PostParams["PluginIndex"]
local PM = cRoot:Get():GetPluginManager()
local PluginName = SettingsIni:GetValue( KeyIdx, PluginIdx ) if( PM:LoadPlugin( PluginName ) == false ) then
if( (PluginName == Request.PostParams["PluginName"]) and (SettingsIni:DeleteValueByID( KeyIdx, PluginIdx ) == true) ) then Content = "Could not enable '".. PluginName .."'!"
SettingsIni:WriteFile() end
Content = "Removed plugin '" .. PluginName .. "'"
if( AddPluginToIni( SettingsIni, PluginName ) == true ) then
Content = "Enabled plugin '".. PluginName .."'"
else else
Content = "Whoops! Something went wrong!" Content = "Enabled plugin '".. PluginName .."' but could not add it to settings.ini"
end
elseif( Request.PostParams["DisablePlugin"] ~= nil
and Request.PostParams["PluginName"] ~= nil ) then
local PluginName = Request.PostParams["PluginName"]
local PM = cRoot:Get():GetPluginManager()
PM:DisablePlugin( PluginName )
if( RemovePluginFromIni( SettingsIni, PluginName ) == true ) then
Content = "Disabled plugin '".. PluginName .."'"
else
Content = "Disabled plugin '".. PluginName .."' but could not remove it from settings.ini"
end end
elseif( Request.PostParams["AddPlugin"] ~= nil
and Request.PostParams["PluginName"] ~= nil ) then -- Add a plugin
SettingsIni:SetValue("Plugins", "NewPlugin", Request.PostParams["PluginName"], true )
SettingsIni:WriteFile()
Content = "Added plugin '".. Request.PostParams["PluginName"] .."'"
end end
@ -47,45 +109,33 @@ function HandleRequest_ManagePlugins( Request )
return Content return Content
end end
local SettingsIni = cIniFile("settings.ini")
if( SettingsIni:ReadFile() == true ) then
Content = Content .. HandlePluginListChanges( Request, SettingsIni )
else
Content = Content .. "Cannot find/modify settings.ini"
end
local PluginManager = cRoot:Get():GetPluginManager() local PluginManager = cRoot:Get():GetPluginManager()
PluginManager:FindPlugins() -- Refreshes the plugin list
local PluginList = PluginManager:GetAllPlugins() local PluginList = PluginManager:GetAllPlugins()
Content = Content .. "<h4>Currently active plugins</h4>" Content = Content .. "<h4>Currently installed plugins</h4>"
Content = Content .. "<table>" Content = Content .. "<table>"
for k, Plugin in pairs(PluginList) do for k, Plugin in pairs(PluginList) do
Content = Content .. "<tr><td>" .. Plugin:GetName() .. " V. " .. Plugin:GetVersion() .. "</td></tr>" Content = Content .. "<tr><td>".. k .."</td>"
if( Plugin ) then
Content = Content .. "<td>" .. Plugin:GetName() .. " V. " .. Plugin:GetVersion() .. "</td><td>" .. Button_DisablePlugin(k) .. "</td>"
else
Content = Content .. "<td></td><td>" .. Button_EnablePlugin(k) .. "</td>"
end
Content = Content .. "</tr>"
end end
Content = Content .. "</table>" Content = Content .. "</table>"
local SettingsIni = cIniFile("settings.ini")
if( SettingsIni:ReadFile() == true ) then
Content = Content .. "<h4>Plugins according to settings.ini</h4>"
Content = Content .. HandlePluginListChanges( Request, SettingsIni )
Content = Content .. "<table>"
local KeyIdx = SettingsIni:FindKey("Plugins")
local NumValues = SettingsIni:GetNumValues( KeyIdx )
for i = 0, NumValues-1 do
local ValueName = SettingsIni:GetValueName(KeyIdx, i )
local PluginName = SettingsIni:GetValue(KeyIdx, i)
Content = Content .. "<tr>"
Content = Content .. "<td>" .. ValueName .. ": " .. PluginName .. "</td>"
Content = Content .. "<td>" .. Button_RemovePlugin( PluginName, i ) .. "</td>"
Content = Content .. "</tr>"
end
Content = Content .. "</table>"
end
Content = Content .. "<h4>Add plugin to settings.ini</h4>"
Content = Content .. "<form method='POST'>"
Content = Content .. "<input type='text' name='PluginName'><input type='submit' name='AddPlugin' value='Add Plugin'>"
Content = Content .. "</form>"
Content = Content .. "<h4>Reload</h4>" Content = Content .. "<h4>Reload</h4>"
Content = Content .. "<form method='POST'>" Content = Content .. "<form method='POST'>"
Content = Content .. "<p>Click the reload button to reload all plugins!<br>" Content = Content .. "<p>Click the reload button to reload all plugins according to <strong>settings.ini</strong>!"
Content = Content .. "<input type='submit' name='reload' value='Reload!'></p>" Content = Content .. "<input type='submit' name='reload' value='Reload!'></p>"
Content = Content .. "</form>" Content = Content .. "</form>"

View File

@ -11,10 +11,10 @@ Description=MCServer - in C++
DefaultWorld=world DefaultWorld=world
[Plugins] [Plugins]
; NewPlugin=sTick ; Plugin=sTick
; NewPlugin=DiamondMover ; Plugin=DiamondMover
NewPlugin=Core Plugin=Core
NewPlugin=ChunkWorx Plugin=ChunkWorx
[HelpPlugin] [HelpPlugin]
ShowPluginNames=1 ShowPluginNames=1

View File

@ -1431,14 +1431,6 @@
RelativePath="..\source\Plugin.h" RelativePath="..\source\Plugin.h"
> >
</File> </File>
<File
RelativePath="..\source\Plugin_Lua.cpp"
>
</File>
<File
RelativePath="..\source\Plugin_Lua.h"
>
</File>
<File <File
RelativePath="..\source\Plugin_NewLua.cpp" RelativePath="..\source\Plugin_NewLua.cpp"
> >

View File

@ -24,7 +24,6 @@ $cfile "Player.h"
$cfile "PluginManager.h" $cfile "PluginManager.h"
$cfile "Plugin.h" $cfile "Plugin.h"
$cfile "Plugin_NewLua.h" $cfile "Plugin_NewLua.h"
$cfile "Plugin_Lua.h"
$cfile "Server.h" $cfile "Server.h"
$cfile "World.h" $cfile "World.h"
$cfile "Inventory.h" $cfile "Inventory.h"

View File

@ -1,6 +1,6 @@
/* /*
** Lua binding: AllToLua ** Lua binding: AllToLua
** Generated automatically by tolua++-1.0.92 on 10/13/12 10:55:10. ** Generated automatically by tolua++-1.0.92 on 10/14/12 01:26:59.
*/ */
#ifndef __cplusplus #ifndef __cplusplus
@ -33,7 +33,6 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S);
#include "PluginManager.h" #include "PluginManager.h"
#include "Plugin.h" #include "Plugin.h"
#include "Plugin_NewLua.h" #include "Plugin_NewLua.h"
#include "Plugin_Lua.h"
#include "Server.h" #include "Server.h"
#include "World.h" #include "World.h"
#include "Inventory.h" #include "Inventory.h"
@ -169,29 +168,28 @@ static void tolua_reg_types (lua_State* tolua_S)
tolua_usertype(tolua_S,"cStringMap"); tolua_usertype(tolua_S,"cStringMap");
tolua_usertype(tolua_S,"cBlockArea"); tolua_usertype(tolua_S,"cBlockArea");
tolua_usertype(tolua_S,"cLuaItems"); tolua_usertype(tolua_S,"cLuaItems");
tolua_usertype(tolua_S,"cCraftingGrid");
tolua_usertype(tolua_S,"cServer"); tolua_usertype(tolua_S,"cServer");
tolua_usertype(tolua_S,"cRoot"); tolua_usertype(tolua_S,"cRoot");
tolua_usertype(tolua_S,"cTCPLink"); tolua_usertype(tolua_S,"cCraftingGrid");
tolua_usertype(tolua_S,"cStairs");
tolua_usertype(tolua_S,"cGroup"); tolua_usertype(tolua_S,"cGroup");
tolua_usertype(tolua_S,"cTracer");
tolua_usertype(tolua_S,"cPlugin::CommandStruct"); tolua_usertype(tolua_S,"cPlugin::CommandStruct");
tolua_usertype(tolua_S,"cPickup"); tolua_usertype(tolua_S,"cPickup");
tolua_usertype(tolua_S,"cItems"); tolua_usertype(tolua_S,"cItems");
tolua_usertype(tolua_S,"cMCLogger"); tolua_usertype(tolua_S,"cTracer");
tolua_usertype(tolua_S,"cClientHandle"); tolua_usertype(tolua_S,"cClientHandle");
tolua_usertype(tolua_S,"cCuboid"); tolua_usertype(tolua_S,"cMCLogger");
tolua_usertype(tolua_S,"cFurnaceRecipe"); tolua_usertype(tolua_S,"cFurnaceRecipe");
tolua_usertype(tolua_S,"Vector3i"); tolua_usertype(tolua_S,"cCuboid");
tolua_usertype(tolua_S,"cChatColor"); tolua_usertype(tolua_S,"cChatColor");
tolua_usertype(tolua_S,"cStairs"); tolua_usertype(tolua_S,"Vector3i");
tolua_usertype(tolua_S,"cLuaChunk"); tolua_usertype(tolua_S,"cLuaChunk");
tolua_usertype(tolua_S,"Lua__cWebPlugin"); tolua_usertype(tolua_S,"Lua__cWebPlugin");
tolua_usertype(tolua_S,"Lua__cPawn"); tolua_usertype(tolua_S,"Lua__cPawn");
tolua_usertype(tolua_S,"Lua__cTCPLink"); tolua_usertype(tolua_S,"cTCPLink");
tolua_usertype(tolua_S,"cItem"); tolua_usertype(tolua_S,"cItem");
tolua_usertype(tolua_S,"Vector3f"); tolua_usertype(tolua_S,"Vector3f");
tolua_usertype(tolua_S,"cPlugin_Lua"); tolua_usertype(tolua_S,"Lua__cTCPLink");
tolua_usertype(tolua_S,"cCraftingRecipes"); tolua_usertype(tolua_S,"cCraftingRecipes");
tolua_usertype(tolua_S,"Lua__cPlugin_NewLua"); tolua_usertype(tolua_S,"Lua__cPlugin_NewLua");
tolua_usertype(tolua_S,"cGroupManager"); tolua_usertype(tolua_S,"cGroupManager");
@ -202,8 +200,8 @@ static void tolua_reg_types (lua_State* tolua_S)
tolua_usertype(tolua_S,"cWebPlugin"); tolua_usertype(tolua_S,"cWebPlugin");
tolua_usertype(tolua_S,"cEntity"); tolua_usertype(tolua_S,"cEntity");
tolua_usertype(tolua_S,"Lua__cPlugin"); tolua_usertype(tolua_S,"Lua__cPlugin");
tolua_usertype(tolua_S,"HTTPFormData");
tolua_usertype(tolua_S,"cPluginManager"); tolua_usertype(tolua_S,"cPluginManager");
tolua_usertype(tolua_S,"HTTPFormData");
tolua_usertype(tolua_S,"cLadder"); tolua_usertype(tolua_S,"cLadder");
tolua_usertype(tolua_S,"cWorld"); tolua_usertype(tolua_S,"cWorld");
tolua_usertype(tolua_S,"Lua__cPlayer"); tolua_usertype(tolua_S,"Lua__cPlayer");
@ -6825,6 +6823,203 @@ static int tolua_AllToLua_cPlayer_Heal00(lua_State* tolua_S)
} }
#endif //#ifndef TOLUA_DISABLE #endif //#ifndef TOLUA_DISABLE
/* method: Feed of class cPlayer */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlayer_Feed00
static int tolua_AllToLua_cPlayer_Feed00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"cPlayer",0,&tolua_err) ||
!tolua_isnumber(tolua_S,2,0,&tolua_err) ||
!tolua_isnumber(tolua_S,3,0,&tolua_err) ||
!tolua_isnoobj(tolua_S,4,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
cPlayer* self = (cPlayer*) tolua_tousertype(tolua_S,1,0);
short a_Food = ((short) tolua_tonumber(tolua_S,2,0));
float a_Saturation = ((float) tolua_tonumber(tolua_S,3,0));
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'Feed'", NULL);
#endif
{
bool tolua_ret = (bool) self->Feed(a_Food,a_Saturation);
tolua_pushboolean(tolua_S,(bool)tolua_ret);
}
}
return 1;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'Feed'.",&tolua_err);
return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE
/* method: GetMaxFoodLevel of class cPlayer */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlayer_GetMaxFoodLevel00
static int tolua_AllToLua_cPlayer_GetMaxFoodLevel00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"cPlayer",0,&tolua_err) ||
!tolua_isnoobj(tolua_S,2,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
cPlayer* self = (cPlayer*) tolua_tousertype(tolua_S,1,0);
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetMaxFoodLevel'", NULL);
#endif
{
short tolua_ret = (short) self->GetMaxFoodLevel();
tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
}
}
return 1;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'GetMaxFoodLevel'.",&tolua_err);
return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE
/* method: GetFoodLevel of class cPlayer */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlayer_GetFoodLevel00
static int tolua_AllToLua_cPlayer_GetFoodLevel00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"cPlayer",0,&tolua_err) ||
!tolua_isnoobj(tolua_S,2,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
cPlayer* self = (cPlayer*) tolua_tousertype(tolua_S,1,0);
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetFoodLevel'", NULL);
#endif
{
short tolua_ret = (short) self->GetFoodLevel();
tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
}
}
return 1;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'GetFoodLevel'.",&tolua_err);
return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE
/* method: GetMaxFoodSaturationLevel of class cPlayer */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlayer_GetMaxFoodSaturationLevel00
static int tolua_AllToLua_cPlayer_GetMaxFoodSaturationLevel00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"cPlayer",0,&tolua_err) ||
!tolua_isnoobj(tolua_S,2,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
cPlayer* self = (cPlayer*) tolua_tousertype(tolua_S,1,0);
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetMaxFoodSaturationLevel'", NULL);
#endif
{
float tolua_ret = (float) self->GetMaxFoodSaturationLevel();
tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
}
}
return 1;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'GetMaxFoodSaturationLevel'.",&tolua_err);
return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE
/* method: GetFoodSaturationLevel of class cPlayer */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlayer_GetFoodSaturationLevel00
static int tolua_AllToLua_cPlayer_GetFoodSaturationLevel00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"cPlayer",0,&tolua_err) ||
!tolua_isnoobj(tolua_S,2,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
cPlayer* self = (cPlayer*) tolua_tousertype(tolua_S,1,0);
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetFoodSaturationLevel'", NULL);
#endif
{
float tolua_ret = (float) self->GetFoodSaturationLevel();
tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
}
}
return 1;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'GetFoodSaturationLevel'.",&tolua_err);
return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE
/* method: AddFoodExhaustion of class cPlayer */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlayer_AddFoodExhaustion00
static int tolua_AllToLua_cPlayer_AddFoodExhaustion00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"cPlayer",0,&tolua_err) ||
!tolua_isnumber(tolua_S,2,0,&tolua_err) ||
!tolua_isnoobj(tolua_S,3,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
cPlayer* self = (cPlayer*) tolua_tousertype(tolua_S,1,0);
float a_Exhaustion = ((float) tolua_tonumber(tolua_S,2,0));
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'AddFoodExhaustion'", NULL);
#endif
{
self->AddFoodExhaustion(a_Exhaustion);
}
}
return 0;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'AddFoodExhaustion'.",&tolua_err);
return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE
/* method: TakeDamage of class cPlayer */ /* method: TakeDamage of class cPlayer */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlayer_TakeDamage00 #ifndef TOLUA_DISABLE_tolua_AllToLua_cPlayer_TakeDamage00
static int tolua_AllToLua_cPlayer_TakeDamage00(lua_State* tolua_S) static int tolua_AllToLua_cPlayer_TakeDamage00(lua_State* tolua_S)
@ -7395,6 +7590,37 @@ static int tolua_AllToLua_cPluginManager_GetPlugin00(lua_State* tolua_S)
} }
#endif //#ifndef TOLUA_DISABLE #endif //#ifndef TOLUA_DISABLE
/* method: FindPlugins of class cPluginManager */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cPluginManager_FindPlugins00
static int tolua_AllToLua_cPluginManager_FindPlugins00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"cPluginManager",0,&tolua_err) ||
!tolua_isnoobj(tolua_S,2,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
cPluginManager* self = (cPluginManager*) tolua_tousertype(tolua_S,1,0);
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'FindPlugins'", NULL);
#endif
{
self->FindPlugins();
}
}
return 0;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'FindPlugins'.",&tolua_err);
return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE
/* method: ReloadPlugins of class cPluginManager */ /* method: ReloadPlugins of class cPluginManager */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cPluginManager_ReloadPlugins00 #ifndef TOLUA_DISABLE_tolua_AllToLua_cPluginManager_ReloadPlugins00
static int tolua_AllToLua_cPluginManager_ReloadPlugins00(lua_State* tolua_S) static int tolua_AllToLua_cPluginManager_ReloadPlugins00(lua_State* tolua_S)
@ -7426,41 +7652,6 @@ static int tolua_AllToLua_cPluginManager_ReloadPlugins00(lua_State* tolua_S)
} }
#endif //#ifndef TOLUA_DISABLE #endif //#ifndef TOLUA_DISABLE
/* method: AddPlugin of class cPluginManager */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cPluginManager_AddPlugin00
static int tolua_AllToLua_cPluginManager_AddPlugin00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"cPluginManager",0,&tolua_err) ||
!tolua_isusertype(tolua_S,2,"cPlugin",0,&tolua_err) ||
!tolua_isnoobj(tolua_S,3,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
cPluginManager* self = (cPluginManager*) tolua_tousertype(tolua_S,1,0);
lua_State* a_LuaState = tolua_S;
cPlugin* a_Plugin = ((cPlugin*) tolua_tousertype(tolua_S,2,0));
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'AddPlugin'", NULL);
#endif
{
bool tolua_ret = (bool) self->AddPlugin(a_LuaState,a_Plugin);
tolua_pushboolean(tolua_S,(bool)tolua_ret);
}
}
return 1;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'AddPlugin'.",&tolua_err);
return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE
/* method: AddHook of class cPluginManager */ /* method: AddHook of class cPluginManager */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cPluginManager_AddHook00 #ifndef TOLUA_DISABLE_tolua_AllToLua_cPluginManager_AddHook00
static int tolua_AllToLua_cPluginManager_AddHook00(lua_State* tolua_S) static int tolua_AllToLua_cPluginManager_AddHook00(lua_State* tolua_S)
@ -7528,44 +7719,9 @@ static int tolua_AllToLua_cPluginManager_GetNumPlugins00(lua_State* tolua_S)
} }
#endif //#ifndef TOLUA_DISABLE #endif //#ifndef TOLUA_DISABLE
/* method: RemovePlugin of class cPluginManager */ /* method: DisablePlugin of class cPluginManager */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cPluginManager_RemovePlugin00 #ifndef TOLUA_DISABLE_tolua_AllToLua_cPluginManager_DisablePlugin00
static int tolua_AllToLua_cPluginManager_RemovePlugin00(lua_State* tolua_S) static int tolua_AllToLua_cPluginManager_DisablePlugin00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"cPluginManager",0,&tolua_err) ||
!tolua_isusertype(tolua_S,2,"cPlugin",0,&tolua_err) ||
!tolua_isboolean(tolua_S,3,1,&tolua_err) ||
!tolua_isnoobj(tolua_S,4,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
cPluginManager* self = (cPluginManager*) tolua_tousertype(tolua_S,1,0);
cPlugin* a_Plugin = ((cPlugin*) tolua_tousertype(tolua_S,2,0));
bool a_bDelete = ((bool) tolua_toboolean(tolua_S,3,false));
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'RemovePlugin'", NULL);
#endif
{
self->RemovePlugin(a_Plugin,a_bDelete);
}
}
return 0;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'RemovePlugin'.",&tolua_err);
return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE
/* method: RemoveLuaPlugin of class cPluginManager */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cPluginManager_RemoveLuaPlugin00
static int tolua_AllToLua_cPluginManager_RemoveLuaPlugin00(lua_State* tolua_S)
{ {
#ifndef TOLUA_RELEASE #ifndef TOLUA_RELEASE
tolua_Error tolua_err; tolua_Error tolua_err;
@ -7579,51 +7735,55 @@ static int tolua_AllToLua_cPluginManager_RemoveLuaPlugin00(lua_State* tolua_S)
#endif #endif
{ {
cPluginManager* self = (cPluginManager*) tolua_tousertype(tolua_S,1,0); cPluginManager* self = (cPluginManager*) tolua_tousertype(tolua_S,1,0);
std::string a_FileName = ((std::string) tolua_tocppstring(tolua_S,2,0)); AString a_PluginName = ((AString) tolua_tocppstring(tolua_S,2,0));
#ifndef TOLUA_RELEASE #ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'RemoveLuaPlugin'", NULL); if (!self) tolua_error(tolua_S,"invalid 'self' in function 'DisablePlugin'", NULL);
#endif #endif
{ {
self->RemoveLuaPlugin(a_FileName); bool tolua_ret = (bool) self->DisablePlugin(a_PluginName);
tolua_pushboolean(tolua_S,(bool)tolua_ret);
tolua_pushcppstring(tolua_S,(const char*)a_PluginName);
} }
} }
return 0; return 2;
#ifndef TOLUA_RELEASE #ifndef TOLUA_RELEASE
tolua_lerror: tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'RemoveLuaPlugin'.",&tolua_err); tolua_error(tolua_S,"#ferror in function 'DisablePlugin'.",&tolua_err);
return 0; return 0;
#endif #endif
} }
#endif //#ifndef TOLUA_DISABLE #endif //#ifndef TOLUA_DISABLE
/* method: GetLuaPlugin of class cPluginManager */ /* method: LoadPlugin of class cPluginManager */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cPluginManager_GetLuaPlugin00 #ifndef TOLUA_DISABLE_tolua_AllToLua_cPluginManager_LoadPlugin00
static int tolua_AllToLua_cPluginManager_GetLuaPlugin00(lua_State* tolua_S) static int tolua_AllToLua_cPluginManager_LoadPlugin00(lua_State* tolua_S)
{ {
#ifndef TOLUA_RELEASE #ifndef TOLUA_RELEASE
tolua_Error tolua_err; tolua_Error tolua_err;
if ( if (
!tolua_isusertype(tolua_S,1,"cPluginManager",0,&tolua_err) || !tolua_isusertype(tolua_S,1,"cPluginManager",0,&tolua_err) ||
!tolua_isnoobj(tolua_S,2,&tolua_err) !tolua_iscppstring(tolua_S,2,0,&tolua_err) ||
!tolua_isnoobj(tolua_S,3,&tolua_err)
) )
goto tolua_lerror; goto tolua_lerror;
else else
#endif #endif
{ {
cPluginManager* self = (cPluginManager*) tolua_tousertype(tolua_S,1,0); cPluginManager* self = (cPluginManager*) tolua_tousertype(tolua_S,1,0);
lua_State* a_State = tolua_S; AString a_PluginName = ((AString) tolua_tocppstring(tolua_S,2,0));
#ifndef TOLUA_RELEASE #ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetLuaPlugin'", NULL); if (!self) tolua_error(tolua_S,"invalid 'self' in function 'LoadPlugin'", NULL);
#endif #endif
{ {
cPlugin_Lua* tolua_ret = (cPlugin_Lua*) self->GetLuaPlugin(a_State); bool tolua_ret = (bool) self->LoadPlugin(a_PluginName);
tolua_pushusertype(tolua_S,(void*)tolua_ret,"cPlugin_Lua"); tolua_pushboolean(tolua_S,(bool)tolua_ret);
tolua_pushcppstring(tolua_S,(const char*)a_PluginName);
} }
} }
return 1; return 2;
#ifndef TOLUA_RELEASE #ifndef TOLUA_RELEASE
tolua_lerror: tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'GetLuaPlugin'.",&tolua_err); tolua_error(tolua_S,"#ferror in function 'LoadPlugin'.",&tolua_err);
return 0; return 0;
#endif #endif
} }
@ -8709,6 +8869,70 @@ static int tolua_AllToLua_cPlugin_SetVersion00(lua_State* tolua_S)
} }
#endif //#ifndef TOLUA_DISABLE #endif //#ifndef TOLUA_DISABLE
/* method: GetDirectory of class cPlugin */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlugin_GetDirectory00
static int tolua_AllToLua_cPlugin_GetDirectory00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"const cPlugin",0,&tolua_err) ||
!tolua_isnoobj(tolua_S,2,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
const cPlugin* self = (const cPlugin*) tolua_tousertype(tolua_S,1,0);
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetDirectory'", NULL);
#endif
{
const AString tolua_ret = (const AString) self->GetDirectory();
tolua_pushcppstring(tolua_S,(const char*)tolua_ret);
}
}
return 1;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'GetDirectory'.",&tolua_err);
return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE
/* method: GetLocalDirectory of class cPlugin */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlugin_GetLocalDirectory00
static int tolua_AllToLua_cPlugin_GetLocalDirectory00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"const cPlugin",0,&tolua_err) ||
!tolua_isnoobj(tolua_S,2,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
const cPlugin* self = (const cPlugin*) tolua_tousertype(tolua_S,1,0);
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetLocalDirectory'", NULL);
#endif
{
AString tolua_ret = (AString) self->GetLocalDirectory();
tolua_pushcppstring(tolua_S,(const char*)tolua_ret);
}
}
return 1;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'GetLocalDirectory'.",&tolua_err);
return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE
/* get function: Command of class CommandStruct */ /* get function: Command of class CommandStruct */
#ifndef TOLUA_DISABLE_tolua_get_cPlugin__CommandStruct_Command #ifndef TOLUA_DISABLE_tolua_get_cPlugin__CommandStruct_Command
static int tolua_get_cPlugin__CommandStruct_Command(lua_State* tolua_S) static int tolua_get_cPlugin__CommandStruct_Command(lua_State* tolua_S)
@ -8733,7 +8957,7 @@ static int tolua_set_cPlugin__CommandStruct_Command(lua_State* tolua_S)
if (!tolua_iscppstring(tolua_S,2,0,&tolua_err)) if (!tolua_iscppstring(tolua_S,2,0,&tolua_err))
tolua_error(tolua_S,"#vinvalid type in variable assignment.",&tolua_err); tolua_error(tolua_S,"#vinvalid type in variable assignment.",&tolua_err);
#endif #endif
self->Command = ((std::string) tolua_tocppstring(tolua_S,2,0)) self->Command = ((AString) tolua_tocppstring(tolua_S,2,0))
; ;
return 0; return 0;
} }
@ -8763,7 +8987,7 @@ static int tolua_set_cPlugin__CommandStruct_Description(lua_State* tolua_S)
if (!tolua_iscppstring(tolua_S,2,0,&tolua_err)) if (!tolua_iscppstring(tolua_S,2,0,&tolua_err))
tolua_error(tolua_S,"#vinvalid type in variable assignment.",&tolua_err); tolua_error(tolua_S,"#vinvalid type in variable assignment.",&tolua_err);
#endif #endif
self->Description = ((std::string) tolua_tocppstring(tolua_S,2,0)) self->Description = ((AString) tolua_tocppstring(tolua_S,2,0))
; ;
return 0; return 0;
} }
@ -8793,7 +9017,7 @@ static int tolua_set_cPlugin__CommandStruct_Permission(lua_State* tolua_S)
if (!tolua_iscppstring(tolua_S,2,0,&tolua_err)) if (!tolua_iscppstring(tolua_S,2,0,&tolua_err))
tolua_error(tolua_S,"#vinvalid type in variable assignment.",&tolua_err); tolua_error(tolua_S,"#vinvalid type in variable assignment.",&tolua_err);
#endif #endif
self->Permission = ((std::string) tolua_tocppstring(tolua_S,2,0)) self->Permission = ((AString) tolua_tocppstring(tolua_S,2,0))
; ;
return 0; return 0;
} }
@ -9223,7 +9447,7 @@ public:
void cPlugin__SetName( const AString& a_Name) { void cPlugin__SetName( const AString& a_Name) {
return ( void )cPlugin::SetName(a_Name); return ( void )cPlugin::SetName(a_Name);
}; };
Lua__cPlugin( void ): cPlugin(){}; Lua__cPlugin( const AString& a_PluginDirectory): cPlugin(a_PluginDirectory){};
}; };
/* method: tolua__set_instance of class Lua__cPlugin */ /* method: tolua__set_instance of class Lua__cPlugin */
@ -10189,18 +10413,21 @@ static int tolua_AllToLua_Lua__cPlugin_new00(lua_State* tolua_S)
tolua_Error tolua_err; tolua_Error tolua_err;
if ( if (
!tolua_isusertable(tolua_S,1,"Lua__cPlugin",0,&tolua_err) || !tolua_isusertable(tolua_S,1,"Lua__cPlugin",0,&tolua_err) ||
!tolua_isnoobj(tolua_S,2,&tolua_err) !tolua_iscppstring(tolua_S,2,0,&tolua_err) ||
!tolua_isnoobj(tolua_S,3,&tolua_err)
) )
goto tolua_lerror; goto tolua_lerror;
else else
#endif #endif
{ {
const AString a_PluginDirectory = ((const AString) tolua_tocppstring(tolua_S,2,0));
{ {
Lua__cPlugin* tolua_ret = (Lua__cPlugin*) Mtolua_new((Lua__cPlugin)()); Lua__cPlugin* tolua_ret = (Lua__cPlugin*) Mtolua_new((Lua__cPlugin)(a_PluginDirectory));
tolua_pushusertype(tolua_S,(void*)tolua_ret,"Lua__cPlugin"); tolua_pushusertype(tolua_S,(void*)tolua_ret,"Lua__cPlugin");
tolua_pushcppstring(tolua_S,(const char*)a_PluginDirectory);
} }
} }
return 1; return 2;
#ifndef TOLUA_RELEASE #ifndef TOLUA_RELEASE
tolua_lerror: tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'new'.",&tolua_err); tolua_error(tolua_S,"#ferror in function 'new'.",&tolua_err);
@ -10217,19 +10444,22 @@ static int tolua_AllToLua_Lua__cPlugin_new00_local(lua_State* tolua_S)
tolua_Error tolua_err; tolua_Error tolua_err;
if ( if (
!tolua_isusertable(tolua_S,1,"Lua__cPlugin",0,&tolua_err) || !tolua_isusertable(tolua_S,1,"Lua__cPlugin",0,&tolua_err) ||
!tolua_isnoobj(tolua_S,2,&tolua_err) !tolua_iscppstring(tolua_S,2,0,&tolua_err) ||
!tolua_isnoobj(tolua_S,3,&tolua_err)
) )
goto tolua_lerror; goto tolua_lerror;
else else
#endif #endif
{ {
const AString a_PluginDirectory = ((const AString) tolua_tocppstring(tolua_S,2,0));
{ {
Lua__cPlugin* tolua_ret = (Lua__cPlugin*) Mtolua_new((Lua__cPlugin)()); Lua__cPlugin* tolua_ret = (Lua__cPlugin*) Mtolua_new((Lua__cPlugin)(a_PluginDirectory));
tolua_pushusertype(tolua_S,(void*)tolua_ret,"Lua__cPlugin"); tolua_pushusertype(tolua_S,(void*)tolua_ret,"Lua__cPlugin");
tolua_register_gc(tolua_S,lua_gettop(tolua_S)); tolua_register_gc(tolua_S,lua_gettop(tolua_S));
tolua_pushcppstring(tolua_S,(const char*)a_PluginDirectory);
} }
} }
return 1; return 2;
#ifndef TOLUA_RELEASE #ifndef TOLUA_RELEASE
tolua_lerror: tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'new'.",&tolua_err); tolua_error(tolua_S,"#ferror in function 'new'.",&tolua_err);
@ -10375,38 +10605,6 @@ static int tolua_AllToLua_cPlugin_NewLua_Tick00(lua_State* tolua_S)
} }
#endif //#ifndef TOLUA_DISABLE #endif //#ifndef TOLUA_DISABLE
/* method: GetLocalDirectory of class cPlugin_NewLua */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlugin_NewLua_GetLocalDirectory00
static int tolua_AllToLua_cPlugin_NewLua_GetLocalDirectory00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"const cPlugin_NewLua",0,&tolua_err) ||
!tolua_isnoobj(tolua_S,2,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
const cPlugin_NewLua* self = (const cPlugin_NewLua*) tolua_tousertype(tolua_S,1,0);
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetLocalDirectory'", NULL);
#endif
{
AString tolua_ret = (AString) self->GetLocalDirectory();
tolua_pushcppstring(tolua_S,(const char*)tolua_ret);
}
}
return 1;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'GetLocalDirectory'.",&tolua_err);
return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE
/* method: CreateWebPlugin of class cPlugin_NewLua */ /* method: CreateWebPlugin of class cPlugin_NewLua */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlugin_NewLua_CreateWebPlugin00 #ifndef TOLUA_DISABLE_tolua_AllToLua_cPlugin_NewLua_CreateWebPlugin00
static int tolua_AllToLua_cPlugin_NewLua_CreateWebPlugin00(lua_State* tolua_S) static int tolua_AllToLua_cPlugin_NewLua_CreateWebPlugin00(lua_State* tolua_S)
@ -10969,38 +11167,6 @@ static int tolua_AllToLua_Lua__cPlugin_NewLua_cPlugin_NewLua__Tick00(lua_State*
} }
#endif //#ifndef TOLUA_DISABLE #endif //#ifndef TOLUA_DISABLE
/* method: GetFileName of class cPlugin_Lua */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlugin_Lua_GetFileName00
static int tolua_AllToLua_cPlugin_Lua_GetFileName00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"cPlugin_Lua",0,&tolua_err) ||
!tolua_isnoobj(tolua_S,2,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
cPlugin_Lua* self = (cPlugin_Lua*) tolua_tousertype(tolua_S,1,0);
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetFileName'", NULL);
#endif
{
std::string tolua_ret = (std::string) self->GetFileName();
tolua_pushcppstring(tolua_S,(const char*)tolua_ret);
}
}
return 1;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'GetFileName'.",&tolua_err);
return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE
/* method: GetServer of class cServer */ /* method: GetServer of class cServer */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cServer_GetServer00 #ifndef TOLUA_DISABLE_tolua_AllToLua_cServer_GetServer00
static int tolua_AllToLua_cServer_GetServer00(lua_State* tolua_S) static int tolua_AllToLua_cServer_GetServer00(lua_State* tolua_S)
@ -22298,6 +22464,12 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_function(tolua_S,"GetColor",tolua_AllToLua_cPlayer_GetColor00); tolua_function(tolua_S,"GetColor",tolua_AllToLua_cPlayer_GetColor00);
tolua_function(tolua_S,"TossItem",tolua_AllToLua_cPlayer_TossItem00); tolua_function(tolua_S,"TossItem",tolua_AllToLua_cPlayer_TossItem00);
tolua_function(tolua_S,"Heal",tolua_AllToLua_cPlayer_Heal00); tolua_function(tolua_S,"Heal",tolua_AllToLua_cPlayer_Heal00);
tolua_function(tolua_S,"Feed",tolua_AllToLua_cPlayer_Feed00);
tolua_function(tolua_S,"GetMaxFoodLevel",tolua_AllToLua_cPlayer_GetMaxFoodLevel00);
tolua_function(tolua_S,"GetFoodLevel",tolua_AllToLua_cPlayer_GetFoodLevel00);
tolua_function(tolua_S,"GetMaxFoodSaturationLevel",tolua_AllToLua_cPlayer_GetMaxFoodSaturationLevel00);
tolua_function(tolua_S,"GetFoodSaturationLevel",tolua_AllToLua_cPlayer_GetFoodSaturationLevel00);
tolua_function(tolua_S,"AddFoodExhaustion",tolua_AllToLua_cPlayer_AddFoodExhaustion00);
tolua_function(tolua_S,"TakeDamage",tolua_AllToLua_cPlayer_TakeDamage00); tolua_function(tolua_S,"TakeDamage",tolua_AllToLua_cPlayer_TakeDamage00);
tolua_function(tolua_S,"KilledBy",tolua_AllToLua_cPlayer_KilledBy00); tolua_function(tolua_S,"KilledBy",tolua_AllToLua_cPlayer_KilledBy00);
tolua_function(tolua_S,"Respawn",tolua_AllToLua_cPlayer_Respawn00); tolua_function(tolua_S,"Respawn",tolua_AllToLua_cPlayer_Respawn00);
@ -22357,13 +22529,12 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_constant(tolua_S,"E_PLUGIN_BLOCK_TO_DROPS",cPluginManager::E_PLUGIN_BLOCK_TO_DROPS); tolua_constant(tolua_S,"E_PLUGIN_BLOCK_TO_DROPS",cPluginManager::E_PLUGIN_BLOCK_TO_DROPS);
tolua_function(tolua_S,"GetPluginManager",tolua_AllToLua_cPluginManager_GetPluginManager00); tolua_function(tolua_S,"GetPluginManager",tolua_AllToLua_cPluginManager_GetPluginManager00);
tolua_function(tolua_S,"GetPlugin",tolua_AllToLua_cPluginManager_GetPlugin00); tolua_function(tolua_S,"GetPlugin",tolua_AllToLua_cPluginManager_GetPlugin00);
tolua_function(tolua_S,"FindPlugins",tolua_AllToLua_cPluginManager_FindPlugins00);
tolua_function(tolua_S,"ReloadPlugins",tolua_AllToLua_cPluginManager_ReloadPlugins00); tolua_function(tolua_S,"ReloadPlugins",tolua_AllToLua_cPluginManager_ReloadPlugins00);
tolua_function(tolua_S,"AddPlugin",tolua_AllToLua_cPluginManager_AddPlugin00);
tolua_function(tolua_S,"AddHook",tolua_AllToLua_cPluginManager_AddHook00); tolua_function(tolua_S,"AddHook",tolua_AllToLua_cPluginManager_AddHook00);
tolua_function(tolua_S,"GetNumPlugins",tolua_AllToLua_cPluginManager_GetNumPlugins00); tolua_function(tolua_S,"GetNumPlugins",tolua_AllToLua_cPluginManager_GetNumPlugins00);
tolua_function(tolua_S,"RemovePlugin",tolua_AllToLua_cPluginManager_RemovePlugin00); tolua_function(tolua_S,"DisablePlugin",tolua_AllToLua_cPluginManager_DisablePlugin00);
tolua_function(tolua_S,"RemoveLuaPlugin",tolua_AllToLua_cPluginManager_RemoveLuaPlugin00); tolua_function(tolua_S,"LoadPlugin",tolua_AllToLua_cPluginManager_LoadPlugin00);
tolua_function(tolua_S,"GetLuaPlugin",tolua_AllToLua_cPluginManager_GetLuaPlugin00);
tolua_endmodule(tolua_S); tolua_endmodule(tolua_S);
#ifdef __cplusplus #ifdef __cplusplus
tolua_cclass(tolua_S,"cPlugin","cPlugin","",tolua_collect_cPlugin); tolua_cclass(tolua_S,"cPlugin","cPlugin","",tolua_collect_cPlugin);
@ -22400,6 +22571,8 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_function(tolua_S,"SetName",tolua_AllToLua_cPlugin_SetName00); tolua_function(tolua_S,"SetName",tolua_AllToLua_cPlugin_SetName00);
tolua_function(tolua_S,"GetVersion",tolua_AllToLua_cPlugin_GetVersion00); tolua_function(tolua_S,"GetVersion",tolua_AllToLua_cPlugin_GetVersion00);
tolua_function(tolua_S,"SetVersion",tolua_AllToLua_cPlugin_SetVersion00); tolua_function(tolua_S,"SetVersion",tolua_AllToLua_cPlugin_SetVersion00);
tolua_function(tolua_S,"GetDirectory",tolua_AllToLua_cPlugin_GetDirectory00);
tolua_function(tolua_S,"GetLocalDirectory",tolua_AllToLua_cPlugin_GetLocalDirectory00);
tolua_cclass(tolua_S,"CommandStruct","cPlugin::CommandStruct","",NULL); tolua_cclass(tolua_S,"CommandStruct","cPlugin::CommandStruct","",NULL);
tolua_beginmodule(tolua_S,"CommandStruct"); tolua_beginmodule(tolua_S,"CommandStruct");
tolua_variable(tolua_S,"Command",tolua_get_cPlugin__CommandStruct_Command,tolua_set_cPlugin__CommandStruct_Command); tolua_variable(tolua_S,"Command",tolua_get_cPlugin__CommandStruct_Command,tolua_set_cPlugin__CommandStruct_Command);
@ -22449,7 +22622,6 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_function(tolua_S,"OnDisable",tolua_AllToLua_cPlugin_NewLua_OnDisable00); tolua_function(tolua_S,"OnDisable",tolua_AllToLua_cPlugin_NewLua_OnDisable00);
tolua_function(tolua_S,"Initialize",tolua_AllToLua_cPlugin_NewLua_Initialize00); tolua_function(tolua_S,"Initialize",tolua_AllToLua_cPlugin_NewLua_Initialize00);
tolua_function(tolua_S,"Tick",tolua_AllToLua_cPlugin_NewLua_Tick00); tolua_function(tolua_S,"Tick",tolua_AllToLua_cPlugin_NewLua_Tick00);
tolua_function(tolua_S,"GetLocalDirectory",tolua_AllToLua_cPlugin_NewLua_GetLocalDirectory00);
tolua_function(tolua_S,"CreateWebPlugin",tolua_AllToLua_cPlugin_NewLua_CreateWebPlugin00); tolua_function(tolua_S,"CreateWebPlugin",tolua_AllToLua_cPlugin_NewLua_CreateWebPlugin00);
tolua_variable(tolua_S,"__cWebPlugin__",tolua_get_cPlugin_NewLua___cWebPlugin__,NULL); tolua_variable(tolua_S,"__cWebPlugin__",tolua_get_cPlugin_NewLua___cWebPlugin__,NULL);
tolua_endmodule(tolua_S); tolua_endmodule(tolua_S);
@ -22460,10 +22632,6 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_function(tolua_S,"cPlugin_NewLua__Initialize",tolua_AllToLua_Lua__cPlugin_NewLua_cPlugin_NewLua__Initialize00); tolua_function(tolua_S,"cPlugin_NewLua__Initialize",tolua_AllToLua_Lua__cPlugin_NewLua_cPlugin_NewLua__Initialize00);
tolua_function(tolua_S,"cPlugin_NewLua__Tick",tolua_AllToLua_Lua__cPlugin_NewLua_cPlugin_NewLua__Tick00); tolua_function(tolua_S,"cPlugin_NewLua__Tick",tolua_AllToLua_Lua__cPlugin_NewLua_cPlugin_NewLua__Tick00);
tolua_endmodule(tolua_S); tolua_endmodule(tolua_S);
tolua_cclass(tolua_S,"cPlugin_Lua","cPlugin_Lua","",NULL);
tolua_beginmodule(tolua_S,"cPlugin_Lua");
tolua_function(tolua_S,"GetFileName",tolua_AllToLua_cPlugin_Lua_GetFileName00);
tolua_endmodule(tolua_S);
tolua_cclass(tolua_S,"cServer","cServer","",NULL); tolua_cclass(tolua_S,"cServer","cServer","",NULL);
tolua_beginmodule(tolua_S,"cServer"); tolua_beginmodule(tolua_S,"cServer");
tolua_function(tolua_S,"GetServer",tolua_AllToLua_cServer_GetServer00); tolua_function(tolua_S,"GetServer",tolua_AllToLua_cServer_GetServer00);

View File

@ -1,6 +1,6 @@
/* /*
** Lua binding: AllToLua ** Lua binding: AllToLua
** Generated automatically by tolua++-1.0.92 on 10/13/12 10:55:10. ** Generated automatically by tolua++-1.0.92 on 10/14/12 01:27:00.
*/ */
/* Exported function */ /* Exported function */

View File

@ -4,7 +4,6 @@
#include "LuaCommandBinder.h" #include "LuaCommandBinder.h"
#include "Player.h" #include "Player.h"
#include "Plugin.h" #include "Plugin.h"
#include "Plugin_Lua.h"
#include "tolua++.h" #include "tolua++.h"
@ -12,7 +11,18 @@
extern bool report_errors(lua_State* lua, int status); bool report_errors(lua_State* lua, int status)
{
if ( status!=0 )
{
std::string s = lua_tostring(lua, -1);
LOGERROR("-- %s", s.c_str() );
lua_pop(lua, 1);
return true;
}
return false;
}
cLuaCommandBinder::cLuaCommandBinder() cLuaCommandBinder::cLuaCommandBinder()
{ {

View File

@ -521,17 +521,27 @@ static int tolua_cPluginManager_GetAllPlugins(lua_State* tolua_S)
{ {
cPluginManager* self = (cPluginManager*) tolua_tousertype(tolua_S,1,0); cPluginManager* self = (cPluginManager*) tolua_tousertype(tolua_S,1,0);
const cPluginManager::PluginList & AllPlugins = self->GetAllPlugins(); const cPluginManager::PluginMap & AllPlugins = self->GetAllPlugins();
lua_createtable(tolua_S, AllPlugins.size(), 0); lua_newtable(tolua_S);
//lua_createtable(tolua_S, AllPlugins.size(), 0);
int newTable = lua_gettop(tolua_S); int newTable = lua_gettop(tolua_S);
int index = 1; int index = 1;
cPluginManager::PluginList::const_iterator iter = AllPlugins.begin(); cPluginManager::PluginMap::const_iterator iter = AllPlugins.begin();
while(iter != AllPlugins.end()) while(iter != AllPlugins.end())
{ {
const cPlugin* Plugin = *iter; const cPlugin* Plugin = iter->second;
tolua_pushusertype( tolua_S, (void*)Plugin, "const cPlugin" ); tolua_pushstring( tolua_S, iter->first.c_str() );
lua_rawseti(tolua_S, newTable, index); if( Plugin != NULL )
{
tolua_pushusertype( tolua_S, (void*)Plugin, "const cPlugin" );
}
else
{
tolua_pushboolean(tolua_S, 0);
}
//lua_rawseti(tolua_S, newTable, index);
lua_rawset(tolua_S, -3);
++iter; ++iter;
++index; ++index;
} }

View File

@ -88,15 +88,15 @@ public:
void Heal( int a_Health ); //tolua_export void Heal( int a_Health ); //tolua_export
/// Returns true if any food has been consumed, false if player "full" /// Returns true if any food has been consumed, false if player "full"
bool Feed(short a_Food, float a_Saturation); bool Feed(short a_Food, float a_Saturation); //tolua_export
short GetMaxFoodLevel() { return m_MaxFoodLevel; } short GetMaxFoodLevel() { return m_MaxFoodLevel; } //tolua_export
short GetFoodLevel() { return m_FoodLevel; } short GetFoodLevel() { return m_FoodLevel; } //tolua_export
float GetMaxFoodSaturationLevel() { return m_MaxFoodSaturationLevel; } float GetMaxFoodSaturationLevel() { return m_MaxFoodSaturationLevel; } //tolua_export
float GetFoodSaturationLevel() { return m_FoodSaturationLevel; } float GetFoodSaturationLevel() { return m_FoodSaturationLevel; } //tolua_export
void AddFoodExhaustion(float a_Exhaustion) { m_FoodExhaustionLevel += a_Exhaustion; } void AddFoodExhaustion(float a_Exhaustion) { m_FoodExhaustionLevel += a_Exhaustion; } //tolua_export
void TakeDamage( int a_Damage, cEntity* a_Instigator ); //tolua_export void TakeDamage( int a_Damage, cEntity* a_Instigator ); //tolua_export
void KilledBy( cEntity* a_Killer ); //tolua_export void KilledBy( cEntity* a_Killer ); //tolua_export

View File

@ -7,10 +7,11 @@
cPlugin::cPlugin() cPlugin::cPlugin( const AString & a_PluginDirectory )
: m_Version( 0 ) : m_Version( 0 )
, m_Language( E_CPP ) , m_Language( E_CPP )
, m_bCanBindCommands( false ) , m_bCanBindCommands( false )
, m_Directory( a_PluginDirectory )
{ {
} }
@ -306,3 +307,8 @@ void cPlugin::AddCommand(const AString & a_Command, const AString & a_Descriptio
AString cPlugin::GetLocalDirectory(void) const
{
return std::string("Plugins/") + m_Directory;
}

View File

@ -28,7 +28,7 @@ class cCraftingRecipe;
class cPlugin class cPlugin
{ {
public: public:
cPlugin(); cPlugin( const AString & a_PluginDirectory );
virtual ~cPlugin(); virtual ~cPlugin();
virtual void OnDisable() {} virtual void OnDisable() {}
@ -70,18 +70,21 @@ public:
int GetVersion() const { return m_Version; } int GetVersion() const { return m_Version; }
void SetVersion( int a_Version ) { m_Version = a_Version; } void SetVersion( int a_Version ) { m_Version = a_Version; }
const AString & GetDirectory(void) const {return m_Directory; }
AString GetLocalDirectory(void) const; //tolua_export
struct CommandStruct struct CommandStruct
{ {
std::string Command; AString Command;
std::string Description; AString Description;
std::string Permission; AString Permission;
}; };
void AddCommand(const AString & a_Command, const AString & a_Description, const AString & a_Permission); void AddCommand(const AString & a_Command, const AString & a_Description, const AString & a_Permission);
// tolua_end // tolua_end
typedef bool (FuncCommandHandler)( std::string & a_Command, std::vector< std::string > & a_Split ); typedef bool (FuncCommandHandler)( AString & a_Command, std::vector< std::string > & a_Split );
void BindCommand( FuncCommandHandler* a_Function, std::string & a_Command ); // >> EXPORTED IN MANUALBINDINGS << void BindCommand( FuncCommandHandler* a_Function, AString & a_Command ); // >> EXPORTED IN MANUALBINDINGS <<
const std::vector< CommandStruct > & GetCommands() const { return m_Commands; } // >> EXPORTED IN MANUALBINDINGS << const std::vector< CommandStruct > & GetCommands() const { return m_Commands; } // >> EXPORTED IN MANUALBINDINGS <<
@ -102,8 +105,10 @@ private:
PluginLanguage m_Language; PluginLanguage m_Language;
std::vector< CommandStruct > m_Commands; std::vector< CommandStruct > m_Commands;
std::string m_Name; AString m_Name;
int m_Version; int m_Version;
AString m_Directory;
}; //tolua_export }; //tolua_export

View File

@ -2,7 +2,6 @@
#include "PluginManager.h" #include "PluginManager.h"
#include "Plugin.h" #include "Plugin.h"
#include "Plugin_Lua.h"
#include "Plugin_NewLua.h" #include "Plugin_NewLua.h"
#include "WebAdmin.h" #include "WebAdmin.h"
#include "Item.h" #include "Item.h"
@ -76,6 +75,45 @@ void cPluginManager::ReloadPlugins()
void cPluginManager::FindPlugins()
{
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
for( PluginMap::iterator itr = m_Plugins.begin(); itr != m_Plugins.end(); )
{
if( itr->second == NULL )
{
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)
{
if (itr->rfind(".") != AString::npos)
{
// Ignore files, we only want directories
continue;
}
// Add plugin name/directory to the list
if( m_Plugins.find( *itr ) == m_Plugins.end() )
{
m_Plugins[ *itr ] = NULL;
}
}
}
void cPluginManager::ReloadPluginsNow() void cPluginManager::ReloadPluginsNow()
{ {
LOG("Loading plugins"); LOG("Loading plugins");
@ -87,6 +125,8 @@ void cPluginManager::ReloadPluginsNow()
OpenSquirrelVM(); OpenSquirrelVM();
#endif // USE_SQUIRREL #endif // USE_SQUIRREL
FindPlugins();
cIniFile IniFile("settings.ini"); cIniFile IniFile("settings.ini");
if (!IniFile.ReadFile() ) if (!IniFile.ReadFile() )
{ {
@ -100,34 +140,14 @@ void cPluginManager::ReloadPluginsNow()
for(unsigned int i = 0; i < NumPlugins; i++) for(unsigned int i = 0; i < NumPlugins; i++)
{ {
AString ValueName = IniFile.GetValueName(KeyNum, i ); AString ValueName = IniFile.GetValueName(KeyNum, i );
if( ValueName.compare("Plugin") == 0 ) // It's a Lua plugin if( (ValueName.compare("NewPlugin") == 0) || (ValueName.compare("Plugin") == 0) ) // New plugin style
{
AString PluginFile = IniFile.GetValue(KeyNum, i );
if( !PluginFile.empty() )
{
// allow for comma separated plugin list
// degrades and works fine for the plugin
// per line
AStringVector split = StringSplit( PluginFile, "," );
for (unsigned int j = 0; j < split.size(); j++)
{
cPlugin_Lua* Plugin = new cPlugin_Lua( (split[j] + AString(".lua") ).c_str() );
if( !AddLuaPlugin( Plugin ) )
{
delete Plugin;
}
}
}
}
else if( ValueName.compare("NewPlugin") == 0 ) // New plugin style
{ {
AString PluginFile = IniFile.GetValue(KeyNum, i ); AString PluginFile = IniFile.GetValue(KeyNum, i );
if( !PluginFile.empty() ) if( !PluginFile.empty() )
{ {
cPlugin_NewLua* Plugin = new cPlugin_NewLua( PluginFile.c_str() ); if( m_Plugins.find( PluginFile ) != m_Plugins.end() )
if( !AddPlugin( Plugin ) )
{ {
delete Plugin; LoadPlugin( PluginFile );
} }
} }
} }
@ -168,6 +188,12 @@ void cPluginManager::ReloadPluginsNow()
void cPluginManager::Tick(float a_Dt) void cPluginManager::Tick(float a_Dt)
{ {
while( m_DisablePluginList.size() > 0 )
{
RemovePlugin( m_DisablePluginList.front(), true );
m_DisablePluginList.pop_front();
}
if( m_bReloadPlugins ) if( m_bReloadPlugins )
{ {
ReloadPluginsNow(); ReloadPluginsNow();
@ -650,11 +676,12 @@ bool cPluginManager::CallHookHandshake(cClientHandle * a_ClientHandle, const ASt
cPlugin* cPluginManager::GetPlugin( const AString & a_Plugin ) const cPlugin* cPluginManager::GetPlugin( const AString & a_Plugin ) const
{ {
for( PluginList::const_iterator itr = m_Plugins.begin(); itr != m_Plugins.end(); ++itr ) for( PluginMap::const_iterator itr = m_Plugins.begin(); itr != m_Plugins.end(); ++itr )
{ {
if ((*itr)->GetName().compare(a_Plugin) == 0) if (itr->second == NULL ) continue;
if (itr->second->GetName().compare(a_Plugin) == 0)
{ {
return *itr; return itr->second;
} }
} }
return 0; return 0;
@ -664,7 +691,7 @@ cPlugin* cPluginManager::GetPlugin( const AString & a_Plugin ) const
const cPluginManager::PluginList & cPluginManager::GetAllPlugins() const const cPluginManager::PluginMap & cPluginManager::GetAllPlugins() const
{ {
return m_Plugins; return m_Plugins;
} }
@ -677,19 +704,9 @@ void cPluginManager::UnloadPluginsNow()
{ {
m_Hooks.clear(); m_Hooks.clear();
while( m_LuaPlugins.size() > 0 )
{
cPlugin_Lua* LuaPlugin = *m_LuaPlugins.begin();
if( LuaPlugin )
{
delete LuaPlugin;
}
m_LuaPlugins.remove( LuaPlugin );
}
while( m_Plugins.size() > 0 ) while( m_Plugins.size() > 0 )
{ {
RemovePlugin( *m_Plugins.begin(), true ); RemovePlugin( m_Plugins.begin()->second, true );
} }
//SquirrelVM::Shutdown(); // This breaks shit //SquirrelVM::Shutdown(); // This breaks shit
@ -699,6 +716,40 @@ void cPluginManager::UnloadPluginsNow()
bool cPluginManager::DisablePlugin( AString & a_PluginName )
{
PluginMap::iterator itr = m_Plugins.find( a_PluginName );
if (itr != m_Plugins.end())
{
if (itr->first.compare( a_PluginName ) == 0)
{
m_DisablePluginList.push_back( itr->second );
itr->second = NULL; // Get rid of this thing right away
return true;
}
}
return false;
}
bool cPluginManager::LoadPlugin( AString & a_PluginName )
{
cPlugin_NewLua* Plugin = new cPlugin_NewLua( a_PluginName.c_str() );
if( !AddPlugin( Plugin ) )
{
delete Plugin;
return false;
}
return true;
}
void cPluginManager::RemoveHooks( cPlugin* a_Plugin ) void cPluginManager::RemoveHooks( cPlugin* a_Plugin )
{ {
m_Hooks[ E_PLUGIN_TICK].remove ( a_Plugin ); m_Hooks[ E_PLUGIN_TICK].remove ( a_Plugin );
@ -723,7 +774,7 @@ void cPluginManager::RemoveHooks( cPlugin* a_Plugin )
void cPluginManager::RemovePlugin( cPlugin* a_Plugin, bool a_bDelete /* = false */ ) void cPluginManager::RemovePlugin( cPlugin * a_Plugin, bool a_bDelete /* = false */ )
{ {
if( a_bDelete ) if( a_bDelete )
{ {
@ -731,17 +782,20 @@ void cPluginManager::RemovePlugin( cPlugin* a_Plugin, bool a_bDelete /* = false
#ifdef USE_SQUIRREL #ifdef USE_SQUIRREL
m_SquirrelCommandBinder->RemoveBindingsForPlugin( a_Plugin ); m_SquirrelCommandBinder->RemoveBindingsForPlugin( a_Plugin );
#endif #endif
m_Plugins.remove( a_Plugin );
RemoveHooks( a_Plugin );
a_Plugin->OnDisable();
delete a_Plugin; for( PluginMap::iterator itr = m_Plugins.begin(); itr != m_Plugins.end(); ++itr )
}
else
{
for( LuaPluginList::iterator itr = m_LuaPlugins.begin(); itr != m_LuaPlugins.end(); ++itr )
{ {
(*itr)->RemovePlugin( a_Plugin ); if( itr->second == a_Plugin )
{
m_Plugins.erase( itr );
break;
}
}
if( a_Plugin != NULL )
{
RemoveHooks( a_Plugin );
a_Plugin->OnDisable();
delete a_Plugin;
} }
} }
} }
@ -755,8 +809,7 @@ bool cPluginManager::AddPlugin( cPlugin* a_Plugin )
a_Plugin->m_bCanBindCommands = true; a_Plugin->m_bCanBindCommands = true;
if( a_Plugin->Initialize() ) if( a_Plugin->Initialize() )
{ {
m_Plugins.remove( a_Plugin ); m_Plugins[ a_Plugin->GetDirectory() ] = a_Plugin;
m_Plugins.push_back( a_Plugin );
return true; return true;
} }
@ -769,84 +822,6 @@ bool cPluginManager::AddPlugin( cPlugin* a_Plugin )
bool cPluginManager::AddPlugin( lua_State* a_LuaState, cPlugin* a_Plugin )
{
a_Plugin->SetLanguage( cPlugin::E_LUA );
cPlugin_Lua* LuaPlugin = GetLuaPlugin( a_LuaState );
if( LuaPlugin == NULL )
{
lua_Debug ar;
lua_getstack(a_LuaState, 1, &ar);
lua_getinfo(a_LuaState, "nSl", &ar);
LOGERROR("ERROR: Trying to add an 'old style' plugin from within a 'new style' plugin.\nIn file: %s at line: %i", ar.source, ar.currentline);
}
a_Plugin->m_bCanBindCommands = true;
if( LuaPlugin && a_Plugin->Initialize() )
{
m_Plugins.remove( a_Plugin );
m_Plugins.push_back( a_Plugin );
LuaPlugin->AddPlugin( a_Plugin );
return true;
}
a_Plugin->m_bCanBindCommands = false;
return false;
}
bool cPluginManager::AddLuaPlugin( cPlugin_Lua* a_Plugin )
{
m_LuaPlugins.push_back( a_Plugin ); // It HAS to be in here before calling Initialize, so it can be found by AddPlugin()
if(a_Plugin->Initialize() )
{
return true;
}
LOG(">>>>>>> Could not initialize a plugin! ");
m_LuaPlugins.remove( a_Plugin );
return false;
}
void cPluginManager::RemoveLuaPlugin( std::string a_FileName )
{
for( LuaPluginList::iterator itr = m_LuaPlugins.begin(); itr != m_LuaPlugins.end(); ++itr )
{
if( (*itr)->GetFileName() == a_FileName )
{
cPlugin_Lua* Plugin = *itr;
m_LuaPlugins.remove( Plugin );
delete Plugin;
return;
}
}
}
cPlugin_Lua* cPluginManager::GetLuaPlugin( lua_State* a_State )
{
for( LuaPluginList::iterator itr = m_LuaPlugins.begin(); itr != m_LuaPlugins.end(); ++itr )
{
if( (*itr)->GetLuaState() == a_State )
{
return *itr;
}
}
return NULL;
}
void cPluginManager::AddHook( cPlugin* a_Plugin, PluginHook a_Hook ) void cPluginManager::AddHook( cPlugin* a_Plugin, PluginHook a_Hook )
{ {
if( !a_Plugin ) if( !a_Plugin )
@ -874,9 +849,9 @@ unsigned int cPluginManager::GetNumPlugins() const
bool cPluginManager::HasPlugin( cPlugin* a_Plugin ) const bool cPluginManager::HasPlugin( cPlugin* a_Plugin ) const
{ {
for( PluginList::const_iterator itr = m_Plugins.begin(); itr != m_Plugins.end(); ++itr ) for( PluginMap::const_iterator itr = m_Plugins.begin(); itr != m_Plugins.end(); ++itr )
{ {
if( *itr == a_Plugin ) if( itr->second == a_Plugin )
return true; return true;
} }
return false; return false;

View File

@ -7,7 +7,6 @@ struct lua_State;
class cLuaCommandBinder; class cLuaCommandBinder;
class cSquirrelCommandBinder; class cSquirrelCommandBinder;
class cPlugin; class cPlugin;
class cPlugin_Lua;
// fwd: cWorld.h // fwd: cWorld.h
class cWorld; class cWorld;
@ -86,14 +85,14 @@ public: //tolua_export
static cPluginManager * GetPluginManager(); //tolua_export static cPluginManager * GetPluginManager(); //tolua_export
typedef std::map< AString, cPlugin * > PluginMap;
typedef std::list< cPlugin * > PluginList; typedef std::list< cPlugin * > PluginList;
cPlugin * GetPlugin( const AString & a_Plugin ) const; //tolua_export cPlugin * GetPlugin( const AString & a_Plugin ) const; //tolua_export
const PluginList & GetAllPlugins() const; // >> EXPORTED IN MANUALBINDINGS << const PluginMap & GetAllPlugins() const; // >> EXPORTED IN MANUALBINDINGS <<
void FindPlugins(); //tolua_export
void ReloadPlugins(); //tolua_export void ReloadPlugins(); //tolua_export
bool AddPlugin( cPlugin* a_Plugin ); bool AddPlugin( cPlugin* a_Plugin );
bool AddPlugin( lua_State* a_LuaState, cPlugin* a_Plugin ); //tolua_export
bool AddLuaPlugin( cPlugin_Lua* a_Plugin );
void AddHook( cPlugin* a_Plugin, PluginHook a_Hook ); //tolua_export void AddHook( cPlugin* a_Plugin, PluginHook a_Hook ); //tolua_export
unsigned int GetNumPlugins() const; //tolua_export unsigned int GetNumPlugins() const; //tolua_export
@ -117,10 +116,11 @@ public: //tolua_export
bool CallHookWeatherChanged (cWorld * a_World); bool CallHookWeatherChanged (cWorld * a_World);
bool CallHookHandshake (cClientHandle * a_ClientHandle, const AString & a_Username); bool CallHookHandshake (cClientHandle * a_ClientHandle, const AString & a_Username);
void RemoveHooks( cPlugin* a_Plugin ); bool DisablePlugin( AString & a_PluginName ); //tolua_export
void RemovePlugin( cPlugin* a_Plugin, bool a_bDelete = false ); //tolua_export bool LoadPlugin( AString & a_PluginName ); //tolua_export
void RemoveLuaPlugin( std::string a_FileName ); //tolua_export
cPlugin_Lua* GetLuaPlugin( lua_State* a_State ); //tolua_export void RemoveHooks( cPlugin * a_Plugin );
void RemovePlugin( cPlugin * a_Plugin, bool a_bDelete = false );
cLuaCommandBinder* GetLuaCommandBinder() const { return m_LuaCommandBinder; } cLuaCommandBinder* GetLuaCommandBinder() const { return m_LuaCommandBinder; }
@ -132,11 +132,11 @@ private:
cPluginManager(); cPluginManager();
~cPluginManager(); ~cPluginManager();
typedef std::list< cPlugin_Lua* > LuaPluginList;
typedef std::map< cPluginManager::PluginHook, cPluginManager::PluginList > HookMap; typedef std::map< cPluginManager::PluginHook, cPluginManager::PluginList > HookMap;
LuaPluginList m_LuaPlugins; PluginList m_DisablePluginList;
PluginList m_Plugins;
PluginMap m_Plugins;
HookMap m_Hooks; HookMap m_Hooks;
void ReloadPluginsNow(); void ReloadPluginsNow();

View File

@ -1,98 +0,0 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#define LUA_USE_POSIX
#include "Plugin_Lua.h"
#include "PluginManager.h"
#include "Root.h"
extern "C"
{
#include "lualib.h"
}
#include "tolua++.h"
#include "Bindings.h"
#include "ManualBindings.h"
bool report_errors(lua_State* lua, int status)
{
if ( status!=0 )
{
std::string s = lua_tostring(lua, -1);
LOGERROR("-- %s", s.c_str() );
lua_pop(lua, 1);
return true;
}
return false;
}
cPlugin_Lua::~cPlugin_Lua()
{
UnloadPlugins();
if( m_LuaState )
{
lua_close( m_LuaState );
m_LuaState = 0;
}
}
cPlugin_Lua::cPlugin_Lua(const char* a_Plugin)
: m_LuaState( 0 )
{
m_FileName.assign( a_Plugin );
}
bool cPlugin_Lua::Initialize()
{
if( !m_LuaState )
{
m_LuaState = lua_open();
luaL_openlibs( m_LuaState );
tolua_AllToLua_open(m_LuaState);
ManualBindings::Bind( m_LuaState );
}
int s = luaL_loadfile(m_LuaState, (std::string("Plugins/") + m_FileName ).c_str() );
if( report_errors( m_LuaState, s ) )
{
LOGERROR("Can't load plugin %s", m_FileName.c_str() );
lua_close( m_LuaState );
m_LuaState = 0;
return false;
}
s = lua_pcall(m_LuaState, 0, LUA_MULTRET, 0);
if( report_errors( m_LuaState, s ) )
{
LOGERROR("Error in plugin %s", m_FileName.c_str() );
lua_close( m_LuaState );
m_LuaState = 0;
return false;
}
return true;
}
void cPlugin_Lua::AddPlugin( cPlugin* a_Plugin )
{
m_Plugins.push_back( a_Plugin );
}
void cPlugin_Lua::RemovePlugin( cPlugin* a_Plugin )
{
m_Plugins.remove( a_Plugin );
cRoot::Get()->GetPluginManager()->RemovePlugin( a_Plugin, true );
}
void cPlugin_Lua::UnloadPlugins()
{
while( m_Plugins.begin() != m_Plugins.end() )
{
RemovePlugin( *m_Plugins.begin() );
}
}
lua_State* cPlugin_Lua::GetLuaState()
{
return m_LuaState;
}

View File

@ -1,38 +0,0 @@
#pragma once
class cPickup;
class cPlayer;
class cPlugin;
class cPlugin_Lua //tolua_export
{ //tolua_export
public:
cPlugin_Lua(const char* a_Plugin);
~cPlugin_Lua();
virtual bool Initialize();
std::string GetFileName() { return m_FileName; } //tolua_export
typedef struct lua_State lua_State;
lua_State* GetLuaState();
void AddPlugin( cPlugin* a_Plugin );
void RemovePlugin( cPlugin* a_Plugin );
private:
void UnloadPlugins();
std::string m_FileName;
lua_State* m_LuaState;
typedef std::list< cPlugin* > PluginList;
PluginList m_Plugins;
}; //tolua_export

View File

@ -31,11 +31,11 @@ extern bool report_errors(lua_State* lua, int status);
cPlugin_NewLua::cPlugin_NewLua( const char* a_PluginName ) cPlugin_NewLua::cPlugin_NewLua( const AString & a_PluginDirectory )
: m_LuaState( 0 ) : m_LuaState( 0 )
, cWebPlugin() , cWebPlugin()
, cPlugin( a_PluginDirectory )
{ {
m_Directory = a_PluginName;
} }
@ -82,7 +82,7 @@ bool cPlugin_NewLua::Initialize()
int s = luaL_loadfile(m_LuaState, Path.c_str() ); int s = luaL_loadfile(m_LuaState, Path.c_str() );
if( report_errors( m_LuaState, s ) ) if( report_errors( m_LuaState, s ) )
{ {
LOGERROR("Can't load plugin %s because of an error in file %s", m_Directory.c_str(), Path.c_str() ); LOGERROR("Can't load plugin %s because of an error in file %s", GetLocalDirectory().c_str(), Path.c_str() );
lua_close( m_LuaState ); lua_close( m_LuaState );
m_LuaState = 0; m_LuaState = 0;
return false; return false;
@ -91,7 +91,7 @@ bool cPlugin_NewLua::Initialize()
s = lua_pcall(m_LuaState, 0, LUA_MULTRET, 0); s = lua_pcall(m_LuaState, 0, LUA_MULTRET, 0);
if( report_errors( m_LuaState, s ) ) if( report_errors( m_LuaState, s ) )
{ {
LOGERROR("Error in plugin %s in file %s", m_Directory.c_str(), Path.c_str() ); LOGERROR("Error in plugin %s in file %s", GetLocalDirectory().c_str(), Path.c_str() );
lua_close( m_LuaState ); lua_close( m_LuaState );
m_LuaState = 0; m_LuaState = 0;
return false; return false;
@ -117,7 +117,7 @@ bool cPlugin_NewLua::Initialize()
if( !lua_isboolean( m_LuaState, -1 ) ) if( !lua_isboolean( m_LuaState, -1 ) )
{ {
LOGWARN("Error in plugin %s Initialize() must return a boolean value!", m_Directory.c_str() ); LOGWARN("Error in plugin %s Initialize() must return a boolean value!", GetLocalDirectory().c_str() );
lua_close( m_LuaState ); lua_close( m_LuaState );
m_LuaState = 0; m_LuaState = 0;
return false; return false;
@ -131,15 +131,6 @@ bool cPlugin_NewLua::Initialize()
AString cPlugin_NewLua::GetLocalDirectory(void) const
{
return std::string("Plugins/") + m_Directory;
}
void cPlugin_NewLua::OnDisable() void cPlugin_NewLua::OnDisable()
{ {
cCSLock Lock( m_CriticalSection ); cCSLock Lock( m_CriticalSection );
@ -699,7 +690,7 @@ bool cPlugin_NewLua::OnHandshake(cClientHandle * a_Client, const AString & a_Use
cPlugin_NewLua * cPlugin_NewLua::CreateWebPlugin(lua_State * a_LuaState) cPlugin_NewLua * cPlugin_NewLua::CreateWebPlugin(lua_State * a_LuaState)
{ {
LOGWARN("WARNING: Using deprecated function CreateWebPlugin()! A Lua plugin is a WebPlugin by itself now. (plugin \"%s\" in folder \"%s\")", LOGWARN("WARNING: Using deprecated function CreateWebPlugin()! A Lua plugin is a WebPlugin by itself now. (plugin \"%s\" in folder \"%s\")",
cPlugin::GetName().c_str(), m_Directory.c_str() cPlugin::GetName().c_str(), GetLocalDirectory().c_str()
); );
return this; return this;
} }
@ -797,7 +788,7 @@ bool cPlugin_NewLua::PushFunction( const char* a_FunctionName, bool a_bLogError
{ {
if( a_bLogError ) if( a_bLogError )
{ {
LOGWARN("Error in plugin %s: Could not find function %s()", m_Directory.c_str(), a_FunctionName ); LOGWARN("Error in plugin %s: Could not find function %s()", GetLocalDirectory().c_str(), a_FunctionName );
} }
lua_pop(m_LuaState,1); lua_pop(m_LuaState,1);
return false; return false;
@ -810,7 +801,7 @@ bool cPlugin_NewLua::CallFunction( int a_NumArgs, int a_NumResults, const char*
int s = lua_pcall(m_LuaState, a_NumArgs, a_NumResults, 0); int s = lua_pcall(m_LuaState, a_NumArgs, a_NumResults, 0);
if( report_errors( m_LuaState, s ) ) if( report_errors( m_LuaState, s ) )
{ {
LOGWARN("Error in plugin %s calling function %s()", m_Directory.c_str(), a_FunctionName ); LOGWARN("Error in plugin %s calling function %s()", GetLocalDirectory().c_str(), a_FunctionName );
return false; return false;
} }
return true; return true;

View File

@ -17,7 +17,7 @@ typedef struct lua_State lua_State;
class cPlugin_NewLua : public cPlugin, public cWebPlugin //tolua_export class cPlugin_NewLua : public cPlugin, public cWebPlugin //tolua_export
{ //tolua_export { //tolua_export
public: //tolua_export public: //tolua_export
cPlugin_NewLua( const char* a_PluginName ); cPlugin_NewLua( const AString & a_PluginDirectory );
~cPlugin_NewLua(); ~cPlugin_NewLua();
virtual void OnDisable(); //tolua_export virtual void OnDisable(); //tolua_export
@ -46,9 +46,6 @@ public: //tolua_export
virtual bool OnUpdatingSign (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) override; virtual bool OnUpdatingSign (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) override;
virtual bool OnWeatherChanged (cWorld * a_World) override; virtual bool OnWeatherChanged (cWorld * a_World) override;
virtual bool OnHandshake (cClientHandle * a_Client, const AString & a_Username) override; virtual bool OnHandshake (cClientHandle * a_Client, const AString & a_Username) override;
const AString & GetDirectory(void) const {return m_Directory; }
AString GetLocalDirectory(void) const; //tolua_export
virtual void SetName( const AString & a_Name ) override { cPlugin::SetName(a_Name); } virtual void SetName( const AString & a_Name ) override { cPlugin::SetName(a_Name); }
@ -71,6 +68,5 @@ private:
cCriticalSection m_CriticalSection; cCriticalSection m_CriticalSection;
std::string m_Directory;
lua_State * m_LuaState; lua_State * m_LuaState;
};//tolua_export };//tolua_export

View File

@ -6,6 +6,7 @@
cPlugin_Squirrel::cPlugin_Squirrel( const char* a_PluginName ) cPlugin_Squirrel::cPlugin_Squirrel( const char* a_PluginName )
: cPlugin( a_PluginName )
{ {
SetLanguage( cPlugin::E_SQUIRREL ); SetLanguage( cPlugin::E_SQUIRREL );
m_PluginName = a_PluginName; m_PluginName = a_PluginName;

View File

@ -216,11 +216,12 @@ void cWebAdmin::Request_Handler(webserver::http_request* r)
cPluginManager* PM = cRoot::Get()->GetPluginManager(); cPluginManager* PM = cRoot::Get()->GetPluginManager();
if( PM ) if( PM )
{ {
const cPluginManager::PluginList & List = PM->GetAllPlugins(); const cPluginManager::PluginMap & List = PM->GetAllPlugins();
for( cPluginManager::PluginList::const_iterator itr = List.begin(); itr != List.end(); ++itr ) for( cPluginManager::PluginMap::const_iterator itr = List.begin(); itr != List.end(); ++itr )
{ {
if( itr->second == NULL ) continue;
AString VersionNum; AString VersionNum;
AppendPrintf(Content, "<li>%s V.%i</li>", (*itr)->GetName().c_str(), (*itr)->GetVersion()); AppendPrintf(Content, "<li>%s V.%i</li>", itr->second->GetName().c_str(), itr->second->GetVersion());
} }
} }
Content += "</ul>"; Content += "</ul>";