diff options
author | faketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-01-28 00:47:32 +0100 |
---|---|---|
committer | faketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-01-28 00:47:32 +0100 |
commit | de293999872346271cdfb5dbecbad7f77362b83b (patch) | |
tree | c627283aacda09be1592f85805261fec782b8a6d | |
parent | Added a VC2010 configuration for Debug build with optimized Noise; made it the default in VC2008 (diff) | |
download | cuberite-de293999872346271cdfb5dbecbad7f77362b83b.tar cuberite-de293999872346271cdfb5dbecbad7f77362b83b.tar.gz cuberite-de293999872346271cdfb5dbecbad7f77362b83b.tar.bz2 cuberite-de293999872346271cdfb5dbecbad7f77362b83b.tar.lz cuberite-de293999872346271cdfb5dbecbad7f77362b83b.tar.xz cuberite-de293999872346271cdfb5dbecbad7f77362b83b.tar.zst cuberite-de293999872346271cdfb5dbecbad7f77362b83b.zip |
Diffstat (limited to '')
-rw-r--r-- | Plugins/Core/ban.lua (renamed from Plugins/NewTest/ban.lua) | 0 | ||||
-rw-r--r-- | Plugins/Core/gamemode.lua (renamed from Plugins/NewTest/gamemode.lua) | 0 | ||||
-rw-r--r-- | Plugins/Core/gotoworld.lua (renamed from Plugins/NewTest/gotoworld.lua) | 0 | ||||
-rw-r--r-- | Plugins/Core/help.lua (renamed from Plugins/NewTest/help.lua) | 0 | ||||
-rw-r--r-- | Plugins/Core/item.lua (renamed from Plugins/NewTest/item.lua) | 0 | ||||
-rw-r--r-- | Plugins/Core/kick.lua (renamed from Plugins/NewTest/kick.lua) | 0 | ||||
-rw-r--r-- | Plugins/Core/main.lua (renamed from Plugins/NewTest/main.lua) | 8 | ||||
-rw-r--r-- | Plugins/Core/motd.lua (renamed from Plugins/NewTest/motd.lua) | 0 | ||||
-rw-r--r-- | Plugins/Core/onblockplace.lua (renamed from Plugins/NewTest/onblockplace.lua) | 0 | ||||
-rw-r--r-- | Plugins/Core/onkilled.lua (renamed from Plugins/NewTest/onkilled.lua) | 0 | ||||
-rw-r--r-- | Plugins/Core/onlogin.lua (renamed from Plugins/NewTest/onlogin.lua) | 0 | ||||
-rw-r--r-- | Plugins/Core/onplayerjoin.lua (renamed from Plugins/NewTest/onplayerjoin.lua) | 0 | ||||
-rw-r--r-- | Plugins/Core/playerlist.lua (renamed from Plugins/NewTest/playerlist.lua) | 0 | ||||
-rw-r--r-- | Plugins/Core/pluginlist.lua (renamed from Plugins/NewTest/pluginlist.lua) | 0 | ||||
-rw-r--r-- | Plugins/Core/reload.lua (renamed from Plugins/NewTest/reload.lua) | 0 | ||||
-rw-r--r-- | Plugins/Core/spawn.lua (renamed from Plugins/NewTest/spawn.lua) | 0 | ||||
-rw-r--r-- | Plugins/Core/teleport.lua (renamed from Plugins/NewTest/teleport.lua) | 0 | ||||
-rw-r--r-- | Plugins/Core/time.lua (renamed from Plugins/NewTest/time.lua) | 0 | ||||
-rw-r--r-- | Plugins/Core/top.lua (renamed from Plugins/NewTest/top.lua) | 0 | ||||
-rw-r--r-- | Plugins/Core/unban.lua (renamed from Plugins/NewTest/unban.lua) | 0 | ||||
-rw-r--r-- | Plugins/Core/web_playerlist.lua | 32 | ||||
-rw-r--r-- | Plugins/Core/web_reload.lua | 15 | ||||
-rw-r--r-- | Plugins/Core/web_whitelist.lua | 79 | ||||
-rw-r--r-- | VC2010/MCServer.vcxproj | 2 | ||||
-rw-r--r-- | VC2010/MCServer.vcxproj.filters | 9 | ||||
-rw-r--r-- | makefile | 22 | ||||
-rw-r--r-- | settings.ini | 4 | ||||
-rw-r--r-- | source/AllToLua.pkg | 1 | ||||
-rw-r--r-- | source/Bindings.cpp | 549 | ||||
-rw-r--r-- | source/Bindings.h | 2 | ||||
-rw-r--r-- | source/ManualBindings.cpp | 47 | ||||
-rw-r--r-- | source/cPlugin_NewLua.cpp | 34 | ||||
-rw-r--r-- | source/cPlugin_NewLua.h | 8 | ||||
-rw-r--r-- | source/cWebAdmin.cpp | 50 | ||||
-rw-r--r-- | source/cWebPlugin_Lua.cpp | 149 | ||||
-rw-r--r-- | source/cWebPlugin_Lua.h | 31 |
36 files changed, 936 insertions, 106 deletions
diff --git a/Plugins/NewTest/ban.lua b/Plugins/Core/ban.lua index a6a662c3c..a6a662c3c 100644 --- a/Plugins/NewTest/ban.lua +++ b/Plugins/Core/ban.lua diff --git a/Plugins/NewTest/gamemode.lua b/Plugins/Core/gamemode.lua index 1e73b46fd..1e73b46fd 100644 --- a/Plugins/NewTest/gamemode.lua +++ b/Plugins/Core/gamemode.lua diff --git a/Plugins/NewTest/gotoworld.lua b/Plugins/Core/gotoworld.lua index d5113b667..d5113b667 100644 --- a/Plugins/NewTest/gotoworld.lua +++ b/Plugins/Core/gotoworld.lua diff --git a/Plugins/NewTest/help.lua b/Plugins/Core/help.lua index 02ef25ebd..02ef25ebd 100644 --- a/Plugins/NewTest/help.lua +++ b/Plugins/Core/help.lua diff --git a/Plugins/NewTest/item.lua b/Plugins/Core/item.lua index 942fa8ce6..942fa8ce6 100644 --- a/Plugins/NewTest/item.lua +++ b/Plugins/Core/item.lua diff --git a/Plugins/NewTest/kick.lua b/Plugins/Core/kick.lua index ff4f8a705..ff4f8a705 100644 --- a/Plugins/NewTest/kick.lua +++ b/Plugins/Core/kick.lua diff --git a/Plugins/NewTest/main.lua b/Plugins/Core/main.lua index 3dfa3f2f1..90f86938f 100644 --- a/Plugins/NewTest/main.lua +++ b/Plugins/Core/main.lua @@ -12,7 +12,7 @@ ItemsTable = {} function Initialize( Plugin )
PLUGIN = Plugin
- Plugin:SetName( "NewCore" )
+ Plugin:SetName( "Core" )
Plugin:SetVersion( 8 )
PluginManager = cRoot:Get():GetPluginManager()
@@ -127,6 +127,12 @@ function Initialize( Plugin ) end
end
+ local WebPlugin = Plugin:CreateWebPlugin()
+ WebPlugin:SetName( Plugin:GetName() )
+ WebPlugin:AddTab( "Whitelist", HandleRequest_WhiteList )
+ WebPlugin:AddTab( "Reload", HandleRequest_Reload )
+ WebPlugin:AddTab( "Playerlist", HandleRequest_PlayerList )
+
LOG( "Initialized " .. Plugin:GetName() .. " v." .. Plugin:GetVersion() )
return true
end
\ No newline at end of file diff --git a/Plugins/NewTest/motd.lua b/Plugins/Core/motd.lua index 49cdcecad..49cdcecad 100644 --- a/Plugins/NewTest/motd.lua +++ b/Plugins/Core/motd.lua diff --git a/Plugins/NewTest/onblockplace.lua b/Plugins/Core/onblockplace.lua index ba75bf5c2..ba75bf5c2 100644 --- a/Plugins/NewTest/onblockplace.lua +++ b/Plugins/Core/onblockplace.lua diff --git a/Plugins/NewTest/onkilled.lua b/Plugins/Core/onkilled.lua index a8a92f667..a8a92f667 100644 --- a/Plugins/NewTest/onkilled.lua +++ b/Plugins/Core/onkilled.lua diff --git a/Plugins/NewTest/onlogin.lua b/Plugins/Core/onlogin.lua index a706f8024..a706f8024 100644 --- a/Plugins/NewTest/onlogin.lua +++ b/Plugins/Core/onlogin.lua diff --git a/Plugins/NewTest/onplayerjoin.lua b/Plugins/Core/onplayerjoin.lua index e8263f608..e8263f608 100644 --- a/Plugins/NewTest/onplayerjoin.lua +++ b/Plugins/Core/onplayerjoin.lua diff --git a/Plugins/NewTest/playerlist.lua b/Plugins/Core/playerlist.lua index c120f068f..c120f068f 100644 --- a/Plugins/NewTest/playerlist.lua +++ b/Plugins/Core/playerlist.lua diff --git a/Plugins/NewTest/pluginlist.lua b/Plugins/Core/pluginlist.lua index 6cb767868..6cb767868 100644 --- a/Plugins/NewTest/pluginlist.lua +++ b/Plugins/Core/pluginlist.lua diff --git a/Plugins/NewTest/reload.lua b/Plugins/Core/reload.lua index e2b338ba1..e2b338ba1 100644 --- a/Plugins/NewTest/reload.lua +++ b/Plugins/Core/reload.lua diff --git a/Plugins/NewTest/spawn.lua b/Plugins/Core/spawn.lua index 73034d9cf..73034d9cf 100644 --- a/Plugins/NewTest/spawn.lua +++ b/Plugins/Core/spawn.lua diff --git a/Plugins/NewTest/teleport.lua b/Plugins/Core/teleport.lua index 9fffec9a2..9fffec9a2 100644 --- a/Plugins/NewTest/teleport.lua +++ b/Plugins/Core/teleport.lua diff --git a/Plugins/NewTest/time.lua b/Plugins/Core/time.lua index 425d69e6a..425d69e6a 100644 --- a/Plugins/NewTest/time.lua +++ b/Plugins/Core/time.lua diff --git a/Plugins/NewTest/top.lua b/Plugins/Core/top.lua index 0f7a8f95f..0f7a8f95f 100644 --- a/Plugins/NewTest/top.lua +++ b/Plugins/Core/top.lua diff --git a/Plugins/NewTest/unban.lua b/Plugins/Core/unban.lua index 9defbe323..9defbe323 100644 --- a/Plugins/NewTest/unban.lua +++ b/Plugins/Core/unban.lua diff --git a/Plugins/Core/web_playerlist.lua b/Plugins/Core/web_playerlist.lua new file mode 100644 index 000000000..eeb9369c1 --- /dev/null +++ b/Plugins/Core/web_playerlist.lua @@ -0,0 +1,32 @@ +function HandleRequest_PlayerList( Request )
+ local World = cRoot:Get():GetWorld()
+ local Content = ""
+
+ if( Request.Params:get("playerlist-kick") ~= "" ) then
+ local KickPlayerName = Request.Params:get("playerlist-kick")
+ local Player = World:GetPlayer( KickPlayerName )
+ if( Player == nil ) then
+ Content = Content .. "<p>Could not find player " .. KickPlayerName .. " !</p>"
+ elseif( Player:GetName() == KickPlayerName ) then
+ Player:GetClientHandle():Kick("You were kicked from the game!")
+ Content = Content .. "<p>" .. KickPlayerName .. " has been kicked from the game!</p>"
+ end
+ end
+
+ Content = Content .. "<p>Connected Players: <b>" .. World:GetNumPlayers() .. "</b></p>"
+ Content = Content .. "<table>"
+
+
+ local PlayerList = World:GetAllPlayers()
+ for i, Player in ipairs( PlayerList ) do
+ Content = Content .. "<tr>"
+ Content = Content .. "<td style='width: 10px;'>" .. i .. ".</td>"
+ Content = Content .. "<td>" .. Player:GetName() .. "</td>"
+ Content = Content .. "<td><a href='?playerlist-kick=" .. Player:GetName() .. "'>Kick</a></td>"
+ Content = Content .. "</tr>"
+ end
+
+ Content = Content .. "</table>"
+ Content = Content .. "<br>"
+ return Content
+end
\ No newline at end of file diff --git a/Plugins/Core/web_reload.lua b/Plugins/Core/web_reload.lua new file mode 100644 index 000000000..f78297fcb --- /dev/null +++ b/Plugins/Core/web_reload.lua @@ -0,0 +1,15 @@ +function HandleRequest_Reload( Request )
+ local Content = ""
+
+ if( Request.Params:get("reload") ~= "" ) then
+ Content = Content .. "<head><meta http-equiv=\"refresh\" content=\"2;././\"></head>"
+ Content = Content .. "<p>Reloading plugins... This can take a while depending on the plugins you're using.</p>"
+ cRoot:Get():GetPluginManager():ReloadPlugins()
+ else
+ Content = Content .. "<form method=GET>"
+ Content = Content .. "<p>Click the reload button to reload all plugins!<br>"
+ Content = Content .. "<input type=\"submit\" name=\"reload\" value=\"Reload!\"></p>"
+ Content = Content .. "</form>"
+ end
+ return Content
+end
\ No newline at end of file diff --git a/Plugins/Core/web_whitelist.lua b/Plugins/Core/web_whitelist.lua new file mode 100644 index 000000000..b7a220515 --- /dev/null +++ b/Plugins/Core/web_whitelist.lua @@ -0,0 +1,79 @@ +local function HTMLDeleteButton( name )
+ return "<form method=GET><input type=\"hidden\" name=\"whitelist-delete\" value=\"".. name .."\"><input type=\"submit\" value=\"Remove from whitelist\"></form>"
+end
+
+function HandleRequest_WhiteList( Request )
+ local UpdateMessage = ""
+ if( Request.Params:get("whitelist-add") ~= "" ) then
+ local PlayerName = Request.Params:get("whitelist-add")
+
+ if( WhiteListIni:GetValueB("WhiteList", PlayerName, false) == true ) then
+ UpdateMessage = "<b>".. PlayerName.."</b> is already on the whitelist"
+ else
+ WhiteListIni:SetValueB("WhiteList", PlayerName, true )
+ UpdateMessage = "Added <b>" .. PlayerName .. "</b> to whitelist."
+ WhiteListIni:WriteFile()
+ end
+ elseif( Request.Params:get("whitelist-delete") ~= "" ) then
+ local PlayerName = Request.Params:get("whitelist-delete")
+ WhiteListIni:DeleteValue( "WhiteList", PlayerName )
+ UpdateMessage = "Removed <b>" .. PlayerName .. "</b> from whitelist."
+ WhiteListIni:WriteFile()
+ elseif( Request.Params:get("whitelist-reload") ~= "" ) then
+ WhiteListIni:Erase() -- Empty entire loaded ini first, otherwise weird shit goes down
+ WhiteListIni:ReadFile()
+ UpdateMessage = "Loaded from disk"
+ elseif( Request.Params:get("whitelist-setenable") ~= "" ) then
+ local Enabled = Request.Params:get("whitelist-setenable");
+ local CreateNewValue = false;
+ if( WhiteListIni:FindValue( WhiteListIni:FindKey("WhiteListSettings"), "WhiteListOn" ) == cIniFile.noID ) then -- Find out whether the value is in the ini
+ CreateNewValue = true
+ end
+
+ if( Enabled == "1" ) then
+ WhiteListIni:SetValueB("WhiteListSettings", "WhiteListOn", true, CreateNewValue )
+ else
+ WhiteListIni:SetValueB("WhiteListSettings", "WhiteListOn", false, CreateNewValue )
+ end
+ WhiteListIni:WriteFile()
+ end
+
+
+ local Content = ""
+
+ local WhiteListEnabled = WhiteListIni:GetValueB("WhiteListSettings", "WhiteListOn", false)
+ if( WhiteListEnabled == false ) then
+ Content = Content .. "<p>Whitelist is currently disabled! Click <a href='?whitelist-setenable=1'>here</a> to enable.</p>"
+ end
+
+
+ Content = Content .. "<h4>Whitelisted players</h4>"
+ Content = Content .. "<table>"
+ local KeyNum = WhiteListIni:FindKey("WhiteList")
+ local NumValues = WhiteListIni:GetNumValues(KeyNum)
+ if( NumValues > 0 ) then
+ for Num = 0, NumValues-1 do
+ if( WhiteListIni:GetValue(KeyNum, Num, "0") == "1" ) then
+ local PlayerName = WhiteListIni:GetValueName(KeyNum, Num )
+ Content = Content .. "<tr><td>" .. PlayerName .. "</td><td>" .. HTMLDeleteButton( PlayerName ) .. "</td></tr>"
+ end
+ end
+ else
+ Content = Content .. "<tr><td>None</td></tr>"
+ end
+ Content = Content .. "</table>"
+ Content = Content .. "<br><h4>Add player to whitelist</h4>"
+ Content = Content .. "<form method=\"GET\">"
+ Content = Content .. "<input type=\"text\" name=\"whitelist-add\"><input type=\"submit\" value=\"Add player\">"
+ Content = Content .. "</form>"
+ Content = Content .. "<form method=\"GET\">"
+ Content = Content .. "<input type=\"submit\" name=\"whitelist-reload\" value=\"Reload from disk\">"
+ Content = Content .. "</form>"
+ Content = Content .. "<br>"..UpdateMessage
+
+ if( WhiteListEnabled == true ) then
+ Content = Content .. "<br><br><p>Whitelist is currently enabled, click <a href='?whitelist-setenable=0'>here</a> to disable.</p>"
+ end
+
+ return Content
+end
\ No newline at end of file diff --git a/VC2010/MCServer.vcxproj b/VC2010/MCServer.vcxproj index 561827d31..84449e65d 100644 --- a/VC2010/MCServer.vcxproj +++ b/VC2010/MCServer.vcxproj @@ -374,6 +374,7 @@ <ClCompile Include="..\source\cWaterSimulator.cpp" />
<ClCompile Include="..\Source\cWebAdmin.cpp" />
<ClCompile Include="..\Source\cWebPlugin.cpp" />
+ <ClCompile Include="..\source\cWebPlugin_Lua.cpp" />
<ClCompile Include="..\source\cWindow.cpp" />
<ClCompile Include="..\source\cWolf.cpp" />
<ClCompile Include="..\source\cWorldGenerator.cpp" />
@@ -529,6 +530,7 @@ <ClInclude Include="..\source\cWaterSimulator.h" />
<ClInclude Include="..\Source\cWebAdmin.h" />
<ClInclude Include="..\Source\cWebPlugin.h" />
+ <ClInclude Include="..\source\cWebPlugin_Lua.h" />
<ClInclude Include="..\source\cWindow.h" />
<ClInclude Include="..\source\cWindowOwner.h" />
<ClInclude Include="..\source\cWolf.h" />
diff --git a/VC2010/MCServer.vcxproj.filters b/VC2010/MCServer.vcxproj.filters index 9e1dfae67..98598731a 100644 --- a/VC2010/MCServer.vcxproj.filters +++ b/VC2010/MCServer.vcxproj.filters @@ -454,6 +454,9 @@ <Filter Include="cPlugin\cPlugin_NewLua">
<UniqueIdentifier>{fb282bd3-cf18-44b3-8ccc-9a5a89701a6d}</UniqueIdentifier>
</Filter>
+ <Filter Include="cWebAdmin\cWebPlugin\cWebPlugin">
+ <UniqueIdentifier>{31f2d7f9-9684-456b-9d70-011a10e894fd}</UniqueIdentifier>
+ </Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\source\cServer.cpp">
@@ -901,6 +904,9 @@ <ClCompile Include="..\source\cPlugin_NewLua.cpp">
<Filter>cPlugin\cPlugin_NewLua</Filter>
</ClCompile>
+ <ClCompile Include="..\source\cWebPlugin_Lua.cpp">
+ <Filter>cWebAdmin\cWebPlugin\cWebPlugin</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\source\cServer.h">
@@ -1386,6 +1392,9 @@ <ClInclude Include="..\source\cPlugin_NewLua.h">
<Filter>cPlugin\cPlugin_NewLua</Filter>
</ClInclude>
+ <ClInclude Include="..\source\cWebPlugin_Lua.h">
+ <Filter>cWebAdmin\cWebPlugin\cWebPlugin</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\source\AllToLua.pkg">
@@ -10,10 +10,10 @@ # Macros # -CC = /usr/bin/g++ -msse4 -CC_OPTIONS = -O2 -s -CCE_OPTIONS = -O2 -s -x c -LNK_OPTIONS = -lstdc++ -pthread +CC = /usr/bin/g++ +CC_OPTIONS = -s -O3 +CCE_OPTIONS = -s -x c -O3 +LNK_OPTIONS = -lstdc++ -O3 # @@ -243,7 +243,9 @@ MCServer : \ build/cLavaSimulator.o\ build/cFireSimulator.o\ build/cFileFormatUpdater.o\ - build/cItem.o + build/cItem.o\ + build/cPlugin_NewLua.o\ + build/cWebPlugin_Lua.o $(CC) $(LNK_OPTIONS) \ build/json_reader.o\ build/json_value.o\ @@ -450,6 +452,8 @@ MCServer : \ build/cFireSimulator.o\ build/cFileFormatUpdater.o\ build/cItem.o\ + build/cPlugin_NewLua.o\ + build/cWebPlugin_Lua.o\ -o MCServer clean : @@ -659,6 +663,8 @@ clean : build/cFireSimulator.o\ build/cFileFormatUpdater.o\ build/cItem.o\ + build/cPlugin_NewLua.o\ + build/cWebPlugin_Lua.o\ MCServer install : MCServer @@ -1505,4 +1511,10 @@ build/cFileFormatUpdater.o : source/cFileFormatUpdater.cpp build/cItem.o : source/cItem.cpp $(CC) $(CC_OPTIONS) source/cItem.cpp -c $(INCLUDE) -o build/cItem.o +build/cPlugin_NewLua.o : source/cPlugin_NewLua.cpp + $(CC) $(CC_OPTIONS) source/cPlugin_NewLua.cpp -c $(INCLUDE) -o build/cPlugin_NewLua.o + +build/cWebPlugin_Lua.o : source/cWebPlugin_Lua.cpp + $(CC) $(CC_OPTIONS) source/cWebPlugin_Lua.cpp -c $(INCLUDE) -o build/cWebPlugin_Lua.o + ##### END RUN #### diff --git a/settings.ini b/settings.ini index f3cc8a3f2..866e0498e 100644 --- a/settings.ini +++ b/settings.ini @@ -8,9 +8,9 @@ DefaultWorld=world ;World=world_sexy
[Plugins]
-Plugin=Core
+;Plugin=Core
;Plugin=MagicCarpet
-;NewPlugin=NewTest
+NewPlugin=Core
;Squirrel=SquirrelChatLog
[HelpPlugin]
diff --git a/source/AllToLua.pkg b/source/AllToLua.pkg index 0a10104d0..32293c370 100644 --- a/source/AllToLua.pkg +++ b/source/AllToLua.pkg @@ -26,6 +26,7 @@ $cfile "cInventory.h" $cfile "cItem.h"
$cfile "cWebAdmin.h"
$cfile "cWebPlugin.h"
+$cfile "cWebPlugin_Lua.h"
$cfile "cPickup.h"
$cfile "cRoot.h"
$cfile "cTCPLink.h"
diff --git a/source/Bindings.cpp b/source/Bindings.cpp index b8396c33b..2a97c8af6 100644 --- a/source/Bindings.cpp +++ b/source/Bindings.cpp @@ -1,6 +1,6 @@ /*
** Lua binding: AllToLua
-** Generated automatically by tolua++-1.0.92 on 01/26/12 18:52:03.
+** Generated automatically by tolua++-1.0.92 on 01/27/12 00:53:11.
*/
#ifndef __cplusplus
@@ -38,6 +38,7 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S); #include "cItem.h"
#include "cWebAdmin.h"
#include "cWebPlugin.h"
+#include "cWebPlugin_Lua.h"
#include "cPickup.h"
#include "cRoot.h"
#include "cTCPLink.h"
@@ -167,24 +168,25 @@ static void tolua_reg_types (lua_State* tolua_S) tolua_usertype(tolua_S,"cRoot");
tolua_usertype(tolua_S,"Lua__cPickup");
tolua_usertype(tolua_S,"Lua__cPacket_BlockDig");
+ tolua_usertype(tolua_S,"cWorld");
tolua_usertype(tolua_S,"cPlugin::CommandStruct");
tolua_usertype(tolua_S,"cPickup");
- tolua_usertype(tolua_S,"cWorld");
+ tolua_usertype(tolua_S,"Vector3i");
tolua_usertype(tolua_S,"cPacket_Login");
tolua_usertype(tolua_S,"cClientHandle");
- tolua_usertype(tolua_S,"Vector3i");
- tolua_usertype(tolua_S,"cFurnaceRecipe");
tolua_usertype(tolua_S,"cGroup");
- tolua_usertype(tolua_S,"cChatColor");
+ tolua_usertype(tolua_S,"cFurnaceRecipe");
tolua_usertype(tolua_S,"cTracer");
+ tolua_usertype(tolua_S,"cChatColor");
+ tolua_usertype(tolua_S,"cMCLogger");
tolua_usertype(tolua_S,"cPacket_PickupSpawn");
tolua_usertype(tolua_S,"Lua__cWebPlugin");
tolua_usertype(tolua_S,"Lua__cPawn");
- tolua_usertype(tolua_S,"cMCLogger");
+ tolua_usertype(tolua_S,"cCuboid");
tolua_usertype(tolua_S,"cItem");
tolua_usertype(tolua_S,"Vector3f");
tolua_usertype(tolua_S,"cPlugin_Lua");
- tolua_usertype(tolua_S,"cCuboid");
+ tolua_usertype(tolua_S,"cWebPlugin_Lua");
tolua_usertype(tolua_S,"Lua__cPlayer");
tolua_usertype(tolua_S,"cPacket");
tolua_usertype(tolua_S,"cPacket_BlockDig");
@@ -197,8 +199,8 @@ static void tolua_reg_types (lua_State* tolua_S) tolua_usertype(tolua_S,"cGroupManager");
tolua_usertype(tolua_S,"cPacket_BlockPlace");
tolua_usertype(tolua_S,"cLadder");
- tolua_usertype(tolua_S,"cPluginManager");
tolua_usertype(tolua_S,"Lua__cPlugin_NewLua");
+ tolua_usertype(tolua_S,"cPluginManager");
tolua_usertype(tolua_S,"cIniFile");
tolua_usertype(tolua_S,"Lua__cEntity");
tolua_usertype(tolua_S,"HTTPRequest");
@@ -8043,6 +8045,212 @@ static int tolua_AllToLua_cPlugin_NewLua_Initialize00(lua_State* tolua_S) }
#endif //#ifndef TOLUA_DISABLE
+/* method: Tick of class cPlugin_NewLua */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlugin_NewLua_Tick00
+static int tolua_AllToLua_cPlugin_NewLua_Tick00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"cPlugin_NewLua",0,&tolua_err) ||
+ !tolua_isnumber(tolua_S,2,0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,3,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ cPlugin_NewLua* self = (cPlugin_NewLua*) tolua_tousertype(tolua_S,1,0);
+ float a_Dt = ((float) tolua_tonumber(tolua_S,2,0));
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'Tick'", NULL);
+#endif
+ {
+ self->Tick(a_Dt);
+ }
+ }
+ return 0;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'Tick'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* method: OnPlayerJoin of class cPlugin_NewLua */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlugin_NewLua_OnPlayerJoin00
+static int tolua_AllToLua_cPlugin_NewLua_OnPlayerJoin00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"cPlugin_NewLua",0,&tolua_err) ||
+ !tolua_isusertype(tolua_S,2,"cPlayer",0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,3,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ cPlugin_NewLua* self = (cPlugin_NewLua*) tolua_tousertype(tolua_S,1,0);
+ cPlayer* a_Player = ((cPlayer*) tolua_tousertype(tolua_S,2,0));
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'OnPlayerJoin'", NULL);
+#endif
+ {
+ bool tolua_ret = (bool) self->OnPlayerJoin(a_Player);
+ tolua_pushboolean(tolua_S,(bool)tolua_ret);
+ }
+ }
+ return 1;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'OnPlayerJoin'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* method: OnLogin of class cPlugin_NewLua */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlugin_NewLua_OnLogin00
+static int tolua_AllToLua_cPlugin_NewLua_OnLogin00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"cPlugin_NewLua",0,&tolua_err) ||
+ !tolua_isusertype(tolua_S,2,"cPacket_Login",0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,3,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ cPlugin_NewLua* self = (cPlugin_NewLua*) tolua_tousertype(tolua_S,1,0);
+ cPacket_Login* a_PacketData = ((cPacket_Login*) tolua_tousertype(tolua_S,2,0));
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'OnLogin'", NULL);
+#endif
+ {
+ bool tolua_ret = (bool) self->OnLogin(a_PacketData);
+ tolua_pushboolean(tolua_S,(bool)tolua_ret);
+ }
+ }
+ return 1;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'OnLogin'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* method: OnBlockPlace of class cPlugin_NewLua */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlugin_NewLua_OnBlockPlace00
+static int tolua_AllToLua_cPlugin_NewLua_OnBlockPlace00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"cPlugin_NewLua",0,&tolua_err) ||
+ !tolua_isusertype(tolua_S,2,"cPacket_BlockPlace",0,&tolua_err) ||
+ !tolua_isusertype(tolua_S,3,"cPlayer",0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,4,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ cPlugin_NewLua* self = (cPlugin_NewLua*) tolua_tousertype(tolua_S,1,0);
+ cPacket_BlockPlace* a_PacketData = ((cPacket_BlockPlace*) tolua_tousertype(tolua_S,2,0));
+ cPlayer* a_Player = ((cPlayer*) tolua_tousertype(tolua_S,3,0));
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'OnBlockPlace'", NULL);
+#endif
+ {
+ bool tolua_ret = (bool) self->OnBlockPlace(a_PacketData,a_Player);
+ tolua_pushboolean(tolua_S,(bool)tolua_ret);
+ }
+ }
+ return 1;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'OnBlockPlace'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* method: OnKilled of class cPlugin_NewLua */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlugin_NewLua_OnKilled00
+static int tolua_AllToLua_cPlugin_NewLua_OnKilled00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"cPlugin_NewLua",0,&tolua_err) ||
+ !tolua_isusertype(tolua_S,2,"cPawn",0,&tolua_err) ||
+ !tolua_isusertype(tolua_S,3,"cEntity",0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,4,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ cPlugin_NewLua* self = (cPlugin_NewLua*) tolua_tousertype(tolua_S,1,0);
+ cPawn* a_Killed = ((cPawn*) tolua_tousertype(tolua_S,2,0));
+ cEntity* a_Killer = ((cEntity*) tolua_tousertype(tolua_S,3,0));
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'OnKilled'", NULL);
+#endif
+ {
+ bool tolua_ret = (bool) self->OnKilled(a_Killed,a_Killer);
+ tolua_pushboolean(tolua_S,(bool)tolua_ret);
+ }
+ }
+ return 1;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'OnKilled'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* method: CreateWebPlugin of class cPlugin_NewLua */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlugin_NewLua_CreateWebPlugin00
+static int tolua_AllToLua_cPlugin_NewLua_CreateWebPlugin00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"cPlugin_NewLua",0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,2,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ cPlugin_NewLua* self = (cPlugin_NewLua*) tolua_tousertype(tolua_S,1,0);
+ lua_State* a_LuaState = tolua_S;
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'CreateWebPlugin'", NULL);
+#endif
+ {
+ cWebPlugin_Lua* tolua_ret = (cWebPlugin_Lua*) self->CreateWebPlugin(a_LuaState);
+ tolua_pushusertype(tolua_S,(void*)tolua_ret,"cWebPlugin_Lua");
+ }
+ }
+ return 1;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'CreateWebPlugin'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
class Lua__cPlugin_NewLua : public cPlugin_NewLua, public ToluaBase {
public:
bool Initialize( void ) {
@@ -8055,47 +8263,38 @@ public: return ( bool ) cPlugin_NewLua:: Initialize();
};
};
- void OnDisable( void ) {
- if (push_method("OnDisable", tolua_AllToLua_cPlugin_OnDisable00)) {
- ToluaBase::dbcall(lua_state, 1, 0);
- } else {
- return ( void ) cPlugin_NewLua:: OnDisable();
- };
- };
void Tick( float a_Dt) {
- if (push_method("Tick", tolua_AllToLua_cPlugin_Tick00)) {
+ if (push_method("Tick", tolua_AllToLua_cPlugin_NewLua_Tick00)) {
tolua_pushnumber(lua_state, (lua_Number)a_Dt);
ToluaBase::dbcall(lua_state, 2, 0);
} else {
return ( void ) cPlugin_NewLua:: Tick(a_Dt);
};
};
- bool OnCollectItem( cPickup* a_Pickup, cPlayer* a_Player) {
- if (push_method("OnCollectItem", tolua_AllToLua_cPlugin_OnCollectItem00)) {
- tolua_pushusertype(lua_state, (void*)a_Pickup, "cPickup");
+ bool OnPlayerJoin( cPlayer* a_Player) {
+ if (push_method("OnPlayerJoin", tolua_AllToLua_cPlugin_NewLua_OnPlayerJoin00)) {
tolua_pushusertype(lua_state, (void*)a_Player, "cPlayer");
- ToluaBase::dbcall(lua_state, 3, 1);
+ ToluaBase::dbcall(lua_state, 2, 1);
bool tolua_ret = ( bool )tolua_toboolean(lua_state, -1, 0);
lua_pop(lua_state, 1);
return tolua_ret;
} else {
- return ( bool ) cPlugin_NewLua:: OnCollectItem(a_Pickup,a_Player);
+ return ( bool ) cPlugin_NewLua:: OnPlayerJoin(a_Player);
};
};
- bool OnDisconnect( std::string a_Reason, cPlayer* a_Player) {
- if (push_method("OnDisconnect", tolua_AllToLua_cPlugin_OnDisconnect00)) {
- tolua_pushcppstring(lua_state, (const char*)a_Reason);
- tolua_pushusertype(lua_state, (void*)a_Player, "cPlayer");
- ToluaBase::dbcall(lua_state, 3, 1);
+ bool OnLogin( cPacket_Login* a_PacketData) {
+ if (push_method("OnLogin", tolua_AllToLua_cPlugin_NewLua_OnLogin00)) {
+ tolua_pushusertype(lua_state, (void*)a_PacketData, "cPacket_Login");
+ ToluaBase::dbcall(lua_state, 2, 1);
bool tolua_ret = ( bool )tolua_toboolean(lua_state, -1, 0);
lua_pop(lua_state, 1);
return tolua_ret;
} else {
- return ( bool ) cPlugin_NewLua:: OnDisconnect(a_Reason,a_Player);
+ return ( bool ) cPlugin_NewLua:: OnLogin(a_PacketData);
};
};
bool OnBlockPlace( cPacket_BlockPlace* a_PacketData, cPlayer* a_Player) {
- if (push_method("OnBlockPlace", tolua_AllToLua_cPlugin_OnBlockPlace00)) {
+ if (push_method("OnBlockPlace", tolua_AllToLua_cPlugin_NewLua_OnBlockPlace00)) {
tolua_pushusertype(lua_state, (void*)a_PacketData, "cPacket_BlockPlace");
tolua_pushusertype(lua_state, (void*)a_Player, "cPlayer");
ToluaBase::dbcall(lua_state, 3, 1);
@@ -8106,6 +8305,49 @@ public: return ( bool ) cPlugin_NewLua:: OnBlockPlace(a_PacketData,a_Player);
};
};
+ bool OnKilled( cPawn* a_Killed, cEntity* a_Killer) {
+ if (push_method("OnKilled", tolua_AllToLua_cPlugin_NewLua_OnKilled00)) {
+ tolua_pushusertype(lua_state, (void*)a_Killed, "cPawn");
+ tolua_pushusertype(lua_state, (void*)a_Killer, "cEntity");
+ ToluaBase::dbcall(lua_state, 3, 1);
+ bool tolua_ret = ( bool )tolua_toboolean(lua_state, -1, 0);
+ lua_pop(lua_state, 1);
+ return tolua_ret;
+ } else {
+ return ( bool ) cPlugin_NewLua:: OnKilled(a_Killed,a_Killer);
+ };
+ };
+ void OnDisable( void ) {
+ if (push_method("OnDisable", tolua_AllToLua_cPlugin_OnDisable00)) {
+ ToluaBase::dbcall(lua_state, 1, 0);
+ } else {
+ return ( void ) cPlugin_NewLua:: OnDisable();
+ };
+ };
+ bool OnCollectItem( cPickup* a_Pickup, cPlayer* a_Player) {
+ if (push_method("OnCollectItem", tolua_AllToLua_cPlugin_OnCollectItem00)) {
+ tolua_pushusertype(lua_state, (void*)a_Pickup, "cPickup");
+ tolua_pushusertype(lua_state, (void*)a_Player, "cPlayer");
+ ToluaBase::dbcall(lua_state, 3, 1);
+ bool tolua_ret = ( bool )tolua_toboolean(lua_state, -1, 0);
+ lua_pop(lua_state, 1);
+ return tolua_ret;
+ } else {
+ return ( bool ) cPlugin_NewLua:: OnCollectItem(a_Pickup,a_Player);
+ };
+ };
+ bool OnDisconnect( std::string a_Reason, cPlayer* a_Player) {
+ if (push_method("OnDisconnect", tolua_AllToLua_cPlugin_OnDisconnect00)) {
+ tolua_pushcppstring(lua_state, (const char*)a_Reason);
+ tolua_pushusertype(lua_state, (void*)a_Player, "cPlayer");
+ ToluaBase::dbcall(lua_state, 3, 1);
+ bool tolua_ret = ( bool )tolua_toboolean(lua_state, -1, 0);
+ lua_pop(lua_state, 1);
+ return tolua_ret;
+ } else {
+ return ( bool ) cPlugin_NewLua:: OnDisconnect(a_Reason,a_Player);
+ };
+ };
bool OnBlockDig( cPacket_BlockDig* a_PacketData, cPlayer* a_Player, cItem* a_PickupItem) {
if (push_method("OnBlockDig", tolua_AllToLua_cPlugin_OnBlockDig00)) {
tolua_pushusertype(lua_state, (void*)a_PacketData, "cPacket_BlockDig");
@@ -8131,17 +8373,6 @@ public: return ( bool ) cPlugin_NewLua:: OnChat(a_Chat,a_Player);
};
};
- bool OnLogin( cPacket_Login* a_PacketData) {
- if (push_method("OnLogin", tolua_AllToLua_cPlugin_OnLogin00)) {
- tolua_pushusertype(lua_state, (void*)a_PacketData, "cPacket_Login");
- ToluaBase::dbcall(lua_state, 2, 1);
- bool tolua_ret = ( bool )tolua_toboolean(lua_state, -1, 0);
- lua_pop(lua_state, 1);
- return tolua_ret;
- } else {
- return ( bool ) cPlugin_NewLua:: OnLogin(a_PacketData);
- };
- };
void OnPlayerSpawn( cPlayer* a_Player) {
if (push_method("OnPlayerSpawn", tolua_AllToLua_cPlugin_OnPlayerSpawn00)) {
tolua_pushusertype(lua_state, (void*)a_Player, "cPlayer");
@@ -8150,17 +8381,6 @@ public: return ( void ) cPlugin_NewLua:: OnPlayerSpawn(a_Player);
};
};
- bool OnPlayerJoin( cPlayer* a_Player) {
- if (push_method("OnPlayerJoin", tolua_AllToLua_cPlugin_OnPlayerJoin00)) {
- tolua_pushusertype(lua_state, (void*)a_Player, "cPlayer");
- ToluaBase::dbcall(lua_state, 2, 1);
- bool tolua_ret = ( bool )tolua_toboolean(lua_state, -1, 0);
- lua_pop(lua_state, 1);
- return tolua_ret;
- } else {
- return ( bool ) cPlugin_NewLua:: OnPlayerJoin(a_Player);
- };
- };
void OnPlayerMove( cPlayer* a_Player) {
if (push_method("OnPlayerMove", tolua_AllToLua_cPlugin_OnPlayerMove00)) {
tolua_pushusertype(lua_state, (void*)a_Player, "cPlayer");
@@ -8178,61 +8398,49 @@ public: return ( void ) cPlugin_NewLua:: OnTakeDamage(a_Pawn,a_TakeDamageInfo);
};
};
- bool OnKilled( cPawn* a_Killed, cEntity* a_Killer) {
- if (push_method("OnKilled", tolua_AllToLua_cPlugin_OnKilled00)) {
- tolua_pushusertype(lua_state, (void*)a_Killed, "cPawn");
- tolua_pushusertype(lua_state, (void*)a_Killer, "cEntity");
- ToluaBase::dbcall(lua_state, 3, 1);
- bool tolua_ret = ( bool )tolua_toboolean(lua_state, -1, 0);
- lua_pop(lua_state, 1);
- return tolua_ret;
- } else {
- return ( bool ) cPlugin_NewLua:: OnKilled(a_Killed,a_Killer);
- };
- };
bool cPlugin_NewLua__Initialize( void ) {
return ( bool )cPlugin_NewLua::Initialize();
};
- void cPlugin_NewLua__OnDisable( void ) {
- return ( void )cPlugin_NewLua::OnDisable();
- };
void cPlugin_NewLua__Tick( float a_Dt) {
return ( void )cPlugin_NewLua::Tick(a_Dt);
};
+ bool cPlugin_NewLua__OnPlayerJoin( cPlayer* a_Player) {
+ return ( bool )cPlugin_NewLua::OnPlayerJoin(a_Player);
+ };
+ bool cPlugin_NewLua__OnLogin( cPacket_Login* a_PacketData) {
+ return ( bool )cPlugin_NewLua::OnLogin(a_PacketData);
+ };
+ bool cPlugin_NewLua__OnBlockPlace( cPacket_BlockPlace* a_PacketData, cPlayer* a_Player) {
+ return ( bool )cPlugin_NewLua::OnBlockPlace(a_PacketData,a_Player);
+ };
+ bool cPlugin_NewLua__OnKilled( cPawn* a_Killed, cEntity* a_Killer) {
+ return ( bool )cPlugin_NewLua::OnKilled(a_Killed,a_Killer);
+ };
+ void cPlugin_NewLua__OnDisable( void ) {
+ return ( void )cPlugin_NewLua::OnDisable();
+ };
bool cPlugin_NewLua__OnCollectItem( cPickup* a_Pickup, cPlayer* a_Player) {
return ( bool )cPlugin_NewLua::OnCollectItem(a_Pickup,a_Player);
};
bool cPlugin_NewLua__OnDisconnect( std::string a_Reason, cPlayer* a_Player) {
return ( bool )cPlugin_NewLua::OnDisconnect(a_Reason,a_Player);
};
- bool cPlugin_NewLua__OnBlockPlace( cPacket_BlockPlace* a_PacketData, cPlayer* a_Player) {
- return ( bool )cPlugin_NewLua::OnBlockPlace(a_PacketData,a_Player);
- };
bool cPlugin_NewLua__OnBlockDig( cPacket_BlockDig* a_PacketData, cPlayer* a_Player, cItem* a_PickupItem) {
return ( bool )cPlugin_NewLua::OnBlockDig(a_PacketData,a_Player,a_PickupItem);
};
bool cPlugin_NewLua__OnChat( const char* a_Chat, cPlayer* a_Player) {
return ( bool )cPlugin_NewLua::OnChat(a_Chat,a_Player);
};
- bool cPlugin_NewLua__OnLogin( cPacket_Login* a_PacketData) {
- return ( bool )cPlugin_NewLua::OnLogin(a_PacketData);
- };
void cPlugin_NewLua__OnPlayerSpawn( cPlayer* a_Player) {
return ( void )cPlugin_NewLua::OnPlayerSpawn(a_Player);
};
- bool cPlugin_NewLua__OnPlayerJoin( cPlayer* a_Player) {
- return ( bool )cPlugin_NewLua::OnPlayerJoin(a_Player);
- };
void cPlugin_NewLua__OnPlayerMove( cPlayer* a_Player) {
return ( void )cPlugin_NewLua::OnPlayerMove(a_Player);
};
void cPlugin_NewLua__OnTakeDamage( cPawn* a_Pawn, TakeDamageInfo* a_TakeDamageInfo) {
return ( void )cPlugin_NewLua::OnTakeDamage(a_Pawn,a_TakeDamageInfo);
};
- bool cPlugin_NewLua__OnKilled( cPawn* a_Killed, cEntity* a_Killer) {
- return ( bool )cPlugin_NewLua::OnKilled(a_Killed,a_Killer);
- };
};
/* method: tolua__set_instance of class Lua__cPlugin_NewLua */
@@ -8300,6 +8508,179 @@ static int tolua_AllToLua_Lua__cPlugin_NewLua_cPlugin_NewLua__Initialize00(lua_S }
#endif //#ifndef TOLUA_DISABLE
+/* method: cPlugin_NewLua__Tick of class Lua__cPlugin_NewLua */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_Lua__cPlugin_NewLua_cPlugin_NewLua__Tick00
+static int tolua_AllToLua_Lua__cPlugin_NewLua_cPlugin_NewLua__Tick00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"Lua__cPlugin_NewLua",0,&tolua_err) ||
+ !tolua_isnumber(tolua_S,2,0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,3,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ Lua__cPlugin_NewLua* self = (Lua__cPlugin_NewLua*) tolua_tousertype(tolua_S,1,0);
+ float a_Dt = ((float) tolua_tonumber(tolua_S,2,0));
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'cPlugin_NewLua__Tick'", NULL);
+#endif
+ {
+ self->cPlugin_NewLua__Tick(a_Dt);
+ }
+ }
+ return 0;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'cPlugin_NewLua__Tick'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* method: cPlugin_NewLua__OnPlayerJoin of class Lua__cPlugin_NewLua */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_Lua__cPlugin_NewLua_cPlugin_NewLua__OnPlayerJoin00
+static int tolua_AllToLua_Lua__cPlugin_NewLua_cPlugin_NewLua__OnPlayerJoin00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"Lua__cPlugin_NewLua",0,&tolua_err) ||
+ !tolua_isusertype(tolua_S,2,"cPlayer",0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,3,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ Lua__cPlugin_NewLua* self = (Lua__cPlugin_NewLua*) tolua_tousertype(tolua_S,1,0);
+ cPlayer* a_Player = ((cPlayer*) tolua_tousertype(tolua_S,2,0));
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'cPlugin_NewLua__OnPlayerJoin'", NULL);
+#endif
+ {
+ bool tolua_ret = (bool) self->cPlugin_NewLua__OnPlayerJoin(a_Player);
+ tolua_pushboolean(tolua_S,(bool)tolua_ret);
+ }
+ }
+ return 1;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'cPlugin_NewLua__OnPlayerJoin'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* method: cPlugin_NewLua__OnLogin of class Lua__cPlugin_NewLua */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_Lua__cPlugin_NewLua_cPlugin_NewLua__OnLogin00
+static int tolua_AllToLua_Lua__cPlugin_NewLua_cPlugin_NewLua__OnLogin00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"Lua__cPlugin_NewLua",0,&tolua_err) ||
+ !tolua_isusertype(tolua_S,2,"cPacket_Login",0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,3,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ Lua__cPlugin_NewLua* self = (Lua__cPlugin_NewLua*) tolua_tousertype(tolua_S,1,0);
+ cPacket_Login* a_PacketData = ((cPacket_Login*) tolua_tousertype(tolua_S,2,0));
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'cPlugin_NewLua__OnLogin'", NULL);
+#endif
+ {
+ bool tolua_ret = (bool) self->cPlugin_NewLua__OnLogin(a_PacketData);
+ tolua_pushboolean(tolua_S,(bool)tolua_ret);
+ }
+ }
+ return 1;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'cPlugin_NewLua__OnLogin'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* method: cPlugin_NewLua__OnBlockPlace of class Lua__cPlugin_NewLua */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_Lua__cPlugin_NewLua_cPlugin_NewLua__OnBlockPlace00
+static int tolua_AllToLua_Lua__cPlugin_NewLua_cPlugin_NewLua__OnBlockPlace00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"Lua__cPlugin_NewLua",0,&tolua_err) ||
+ !tolua_isusertype(tolua_S,2,"cPacket_BlockPlace",0,&tolua_err) ||
+ !tolua_isusertype(tolua_S,3,"cPlayer",0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,4,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ Lua__cPlugin_NewLua* self = (Lua__cPlugin_NewLua*) tolua_tousertype(tolua_S,1,0);
+ cPacket_BlockPlace* a_PacketData = ((cPacket_BlockPlace*) tolua_tousertype(tolua_S,2,0));
+ cPlayer* a_Player = ((cPlayer*) tolua_tousertype(tolua_S,3,0));
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'cPlugin_NewLua__OnBlockPlace'", NULL);
+#endif
+ {
+ bool tolua_ret = (bool) self->cPlugin_NewLua__OnBlockPlace(a_PacketData,a_Player);
+ tolua_pushboolean(tolua_S,(bool)tolua_ret);
+ }
+ }
+ return 1;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'cPlugin_NewLua__OnBlockPlace'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* method: cPlugin_NewLua__OnKilled of class Lua__cPlugin_NewLua */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_Lua__cPlugin_NewLua_cPlugin_NewLua__OnKilled00
+static int tolua_AllToLua_Lua__cPlugin_NewLua_cPlugin_NewLua__OnKilled00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"Lua__cPlugin_NewLua",0,&tolua_err) ||
+ !tolua_isusertype(tolua_S,2,"cPawn",0,&tolua_err) ||
+ !tolua_isusertype(tolua_S,3,"cEntity",0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,4,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ Lua__cPlugin_NewLua* self = (Lua__cPlugin_NewLua*) tolua_tousertype(tolua_S,1,0);
+ cPawn* a_Killed = ((cPawn*) tolua_tousertype(tolua_S,2,0));
+ cEntity* a_Killer = ((cEntity*) tolua_tousertype(tolua_S,3,0));
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'cPlugin_NewLua__OnKilled'", NULL);
+#endif
+ {
+ bool tolua_ret = (bool) self->cPlugin_NewLua__OnKilled(a_Killed,a_Killer);
+ tolua_pushboolean(tolua_S,(bool)tolua_ret);
+ }
+ }
+ return 1;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'cPlugin_NewLua__OnKilled'.",&tolua_err);
+ return 0;
+#endif
+}
+#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)
@@ -16496,11 +16877,22 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S) tolua_cclass(tolua_S,"cPlugin_NewLua","cPlugin_NewLua","cPlugin",NULL);
tolua_beginmodule(tolua_S,"cPlugin_NewLua");
tolua_function(tolua_S,"Initialize",tolua_AllToLua_cPlugin_NewLua_Initialize00);
+ tolua_function(tolua_S,"Tick",tolua_AllToLua_cPlugin_NewLua_Tick00);
+ tolua_function(tolua_S,"OnPlayerJoin",tolua_AllToLua_cPlugin_NewLua_OnPlayerJoin00);
+ tolua_function(tolua_S,"OnLogin",tolua_AllToLua_cPlugin_NewLua_OnLogin00);
+ tolua_function(tolua_S,"OnBlockPlace",tolua_AllToLua_cPlugin_NewLua_OnBlockPlace00);
+ tolua_function(tolua_S,"OnKilled",tolua_AllToLua_cPlugin_NewLua_OnKilled00);
+ tolua_function(tolua_S,"CreateWebPlugin",tolua_AllToLua_cPlugin_NewLua_CreateWebPlugin00);
tolua_endmodule(tolua_S);
tolua_cclass(tolua_S,"Lua__cPlugin_NewLua","Lua__cPlugin_NewLua","cPlugin_NewLua",NULL);
tolua_beginmodule(tolua_S,"Lua__cPlugin_NewLua");
tolua_function(tolua_S,"tolua__set_instance",tolua_AllToLua_Lua__cPlugin_NewLua_tolua__set_instance00);
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__OnPlayerJoin",tolua_AllToLua_Lua__cPlugin_NewLua_cPlugin_NewLua__OnPlayerJoin00);
+ tolua_function(tolua_S,"cPlugin_NewLua__OnLogin",tolua_AllToLua_Lua__cPlugin_NewLua_cPlugin_NewLua__OnLogin00);
+ tolua_function(tolua_S,"cPlugin_NewLua__OnBlockPlace",tolua_AllToLua_Lua__cPlugin_NewLua_cPlugin_NewLua__OnBlockPlace00);
+ tolua_function(tolua_S,"cPlugin_NewLua__OnKilled",tolua_AllToLua_Lua__cPlugin_NewLua_cPlugin_NewLua__OnKilled00);
tolua_endmodule(tolua_S);
tolua_cclass(tolua_S,"cPlugin_Lua","cPlugin_Lua","",NULL);
tolua_beginmodule(tolua_S,"cPlugin_Lua");
@@ -16602,6 +16994,9 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S) tolua_function(tolua_S,".call",tolua_AllToLua_Lua__cWebPlugin_new00_local);
tolua_function(tolua_S,"delete",tolua_AllToLua_Lua__cWebPlugin_delete00);
tolua_endmodule(tolua_S);
+ tolua_cclass(tolua_S,"cWebPlugin_Lua","cWebPlugin_Lua","cWebPlugin",NULL);
+ tolua_beginmodule(tolua_S,"cWebPlugin_Lua");
+ tolua_endmodule(tolua_S);
#ifdef __cplusplus
tolua_cclass(tolua_S,"cPickup","cPickup","cEntity",tolua_collect_cPickup);
#else
diff --git a/source/Bindings.h b/source/Bindings.h index 6e7719b93..fc3d0cb62 100644 --- a/source/Bindings.h +++ b/source/Bindings.h @@ -1,6 +1,6 @@ /*
** Lua binding: AllToLua
-** Generated automatically by tolua++-1.0.92 on 01/26/12 18:52:03.
+** Generated automatically by tolua++-1.0.92 on 01/27/12 00:53:12.
*/
/* Exported function */
diff --git a/source/ManualBindings.cpp b/source/ManualBindings.cpp index 728320f11..a40bcb9d6 100644 --- a/source/ManualBindings.cpp +++ b/source/ManualBindings.cpp @@ -6,6 +6,7 @@ #include "cWorld.h"
#include "cPlugin.h"
#include "cPluginManager.h"
+#include "cWebPlugin_Lua.h"
#include "cLuaCommandBinder.h"
#include "cPlayer.h"
#include "md5/md5.h"
@@ -191,6 +192,49 @@ static int tolua_cPlugin_BindCommand(lua_State* tolua_S) return 0;
}
+static int tolua_cWebPlugin_Lua_AddTab(lua_State* tolua_S)
+{
+ cWebPlugin_Lua* self = (cWebPlugin_Lua*) tolua_tousertype(tolua_S,1,0);
+
+ tolua_Error tolua_err;
+ tolua_err.array = 0;
+ tolua_err.index = 0;
+ tolua_err.type = 0;
+
+ std::string Title = "";
+ int Reference = LUA_REFNIL;
+
+ if( tolua_isstring( tolua_S, 2, 0, &tolua_err ) &&
+ lua_isfunction( tolua_S, 3 ) )
+ {
+ Reference = luaL_ref(tolua_S, LUA_REGISTRYINDEX);
+ Title = ((std::string) tolua_tocppstring(tolua_S,2,0));
+ }
+ else
+ {
+ if( tolua_err.type == 0 )
+ {
+ tolua_err.type = "function";
+ }
+ tolua_error(tolua_S,"#ferror in function 'AddTab'.",&tolua_err);
+ return 0;
+ }
+
+ if( Reference != LUA_REFNIL )
+ {
+ if( !self->AddTab( Title.c_str(), tolua_S, Reference ) )
+ {
+ luaL_unref( tolua_S, LUA_REGISTRYINDEX, Reference );
+ }
+ }
+ else
+ {
+ LOGERROR("ERROR: cWebPlugin_Lua:AddTab invalid function reference in 2nd argument (Title: \"%s\")", Title.c_str() );
+ }
+
+ return 0;
+}
+
static int tolua_md5(lua_State* tolua_S)
{
std::string SourceString = tolua_tostring(tolua_S, 1, 0);
@@ -222,6 +266,9 @@ void ManualBindings::Bind( lua_State* tolua_S ) tolua_beginmodule(tolua_S,"cPlayer");
tolua_function(tolua_S,"GetGroups",tolua_cPlayer_GetGroups);
tolua_endmodule(tolua_S);
+ tolua_beginmodule(tolua_S,"cWebPlugin_Lua");
+ tolua_function(tolua_S,"AddTab",tolua_cWebPlugin_Lua_AddTab);
+ tolua_endmodule(tolua_S);
tolua_function(tolua_S,"md5",tolua_md5);
diff --git a/source/cPlugin_NewLua.cpp b/source/cPlugin_NewLua.cpp index 81e629ce4..fd5a23772 100644 --- a/source/cPlugin_NewLua.cpp +++ b/source/cPlugin_NewLua.cpp @@ -1,6 +1,7 @@ #define LUA_USE_POSIX
#include "cPlugin_NewLua.h"
#include "cMCLogger.h"
+#include "cWebPlugin_Lua.h"
extern "C"
{
@@ -11,10 +12,10 @@ extern "C" #include "Bindings.h"
#include "ManualBindings.h"
-#ifdef _WIN32 -#include "wdirent.h" -#else -#include <dirent.h> +#ifdef _WIN32
+#include "wdirent.h"
+#else
+#include <dirent.h>
#endif
extern bool report_errors(lua_State* lua, int status);
@@ -27,6 +28,12 @@ cPlugin_NewLua::cPlugin_NewLua( const char* a_PluginName ) cPlugin_NewLua::~cPlugin_NewLua()
{
+ for( WebPluginList::iterator itr = m_WebPlugins.begin(); itr != m_WebPlugins.end(); ++itr )
+ {
+ delete *itr;
+ }
+ m_WebPlugins.clear();
+
if( m_LuaState )
{
lua_close( m_LuaState );
@@ -49,9 +56,9 @@ bool cPlugin_NewLua::Initialize() // Load all files for this plugin, and execute them
DIR* dp;
struct dirent *entry;
- if(dp = opendir( PluginPath.c_str() )) - { - while(entry = readdir(dp)) + if(dp = opendir( PluginPath.c_str() ))
+ {
+ while(entry = readdir(dp))
{
std::string FileName = entry->d_name;
if( FileName.find(".lua") != std::string::npos )
@@ -76,6 +83,7 @@ bool cPlugin_NewLua::Initialize() }
}
}
+ closedir( dp );
}
@@ -177,7 +185,19 @@ bool cPlugin_NewLua::OnKilled( cPawn* a_Killed, cEntity* a_Killer ) return bRetVal;
}
+cWebPlugin_Lua* cPlugin_NewLua::CreateWebPlugin(lua_State* a_LuaState)
+{
+ if( a_LuaState != m_LuaState )
+ {
+ LOGERROR("Not allowed to create a WebPlugin from another plugin but your own!");
+ return 0;
+ }
+ cWebPlugin_Lua* WebPlugin = new cWebPlugin_Lua( this );
+ m_WebPlugins.push_back( WebPlugin );
+
+ return WebPlugin;
+}
// Helper functions
diff --git a/source/cPlugin_NewLua.h b/source/cPlugin_NewLua.h index bdd7f1f7e..1aa4242ea 100644 --- a/source/cPlugin_NewLua.h +++ b/source/cPlugin_NewLua.h @@ -2,8 +2,10 @@ #include "cPlugin.h"
#include <string>
+#include <list>
typedef struct lua_State lua_State;
+class cWebPlugin_Lua;
class cPlugin_NewLua : public cPlugin //tolua_export
{ //tolua_export
@@ -18,10 +20,16 @@ public: //tolua_export virtual bool OnBlockPlace( cPacket_BlockPlace* a_PacketData, cPlayer* a_Player ); // tolua_export
virtual bool OnKilled( cPawn* a_Killed, cEntity* a_Killer ); //tolua_export
+ lua_State* GetLuaState() { return m_LuaState; }
+
+ cWebPlugin_Lua* CreateWebPlugin(lua_State* a_LuaState); //tolua_export
private:
bool PushFunction( const char* a_FunctionName );
bool CallFunction( int a_NumArgs, int a_NumResults, const char* a_FunctionName ); // a_FunctionName is only used for error messages, nothing else
+ typedef std::list< cWebPlugin_Lua* > WebPluginList;
+ WebPluginList m_WebPlugins;
+
std::string m_Directory;
lua_State* m_LuaState;
};//tolua_export
\ No newline at end of file diff --git a/source/cWebAdmin.cpp b/source/cWebAdmin.cpp index 86dbf5990..ec4894aef 100644 --- a/source/cWebAdmin.cpp +++ b/source/cWebAdmin.cpp @@ -3,6 +3,7 @@ #include "cStringMap.h"
#include "cWebPlugin.h"
+#include "cWebPlugin_Lua.h"
#include "cPluginManager.h"
#include "cPlugin.h"
@@ -96,6 +97,16 @@ void cWebAdmin::Request_Handler(webserver::http_request* r) std::string UserPassword = WebAdmin->m_IniFile->GetValue( "User:"+r->username_, "Password", "");
if (UserPassword != "" && r->password_ == UserPassword)
{
+ std::string BaseURL = "./";
+ if( Split.size() > 1 )
+ {
+ for( unsigned int i = 0; i < Split.size(); i++)
+ {
+ BaseURL += "../";
+ }
+ BaseURL += "webadmin/";
+ }
+
std::string Menu;
std::string Content;
std::string Template = WebAdmin->GetTemplate();
@@ -103,7 +114,20 @@ void cWebAdmin::Request_Handler(webserver::http_request* r) for( PluginList::iterator itr = WebAdmin->m_Plugins.begin(); itr != WebAdmin->m_Plugins.end(); ++itr )
{
- Menu += "<li><a href='" + (*itr)->GetName() + "'>" + (*itr)->GetName() + "</a></li>";
+ cWebPlugin* WebPlugin = *itr;
+ cWebPlugin_Lua* LuaPlugin = dynamic_cast< cWebPlugin_Lua* >( WebPlugin );
+ if( LuaPlugin )
+ {
+ std::list< std::string > NameList = LuaPlugin->GetTabNames();
+ for( std::list< std::string >::iterator Name = NameList.begin(); Name != NameList.end(); ++Name )
+ {
+ Menu += "<li><a href='" + BaseURL + WebPlugin->GetName() + "/" + (*Name) + "'>" + (*Name) + "</a></li>";
+ }
+ }
+ else
+ {
+ Menu += "<li><a href='" + BaseURL + WebPlugin->GetName() + "'>" + WebPlugin->GetName() + "</a></li>";
+ }
}
HTTPRequest Request;
@@ -112,17 +136,20 @@ void cWebAdmin::Request_Handler(webserver::http_request* r) Request.Params = new cStringMap(r->params_);
Request.Path = r->path_;
-
-
if( Split.size() > 1 )
{
-
for( PluginList::iterator itr = WebAdmin->m_Plugins.begin(); itr != WebAdmin->m_Plugins.end(); ++itr )
{
if( (*itr)->GetName() == Split[1] )
{
Content = (*itr)->HandleRequest( &Request );
- FoundPlugin = (*itr)->GetName();
+ cWebPlugin* WebPlugin = *itr;
+ FoundPlugin = WebPlugin->GetName();
+ cWebPlugin_Lua* LuaPlugin = dynamic_cast< cWebPlugin_Lua* >( WebPlugin );
+ if( LuaPlugin )
+ {
+ FoundPlugin += " - " + LuaPlugin->GetTabNameForRequest( &Request );
+ }
break;
}
}
@@ -144,7 +171,10 @@ void cWebAdmin::Request_Handler(webserver::http_request* r) const cPluginManager::PluginList & List = PM->GetAllPlugins();
for( cPluginManager::PluginList::const_iterator itr = List.begin(); itr != List.end(); ++itr )
{
- Content += std::string("<li>") + std::string( (*itr)->GetName() ) + "</li>";
+ char c_VersionNum[32]; // 32 digits should be enough? XD
+ sprintf_s( c_VersionNum, 32, "%i", (*itr)->GetVersion() );
+ Content += std::string("<li>") + std::string( (*itr)->GetName() ) + " V. " + std::string( c_VersionNum ) + "</li>";
+
}
}
Content += "</ul>";
@@ -163,13 +193,7 @@ void cWebAdmin::Request_Handler(webserver::http_request* r) if( Split.size() > 1 )
{
- Content += "\n<p><a href='";
- for( unsigned int i = 0; i < Split.size(); i++)
- {
- Content += "../";
- }
- Content += "webadmin/";
- Content += "'>Go back</a></p>";
+ Content += "\n<p><a href='" + BaseURL + "'>Go back</a></p>";
}
// mem usage
diff --git a/source/cWebPlugin_Lua.cpp b/source/cWebPlugin_Lua.cpp new file mode 100644 index 000000000..c9aaef5a7 --- /dev/null +++ b/source/cWebPlugin_Lua.cpp @@ -0,0 +1,149 @@ +#include "cMCLogger.h"
+#include "cWebPlugin_Lua.h"
+#include "cPlugin_NewLua.h"
+
+#include <string>
+#include "tolua++.h"
+#include "cWebAdmin.h"
+
+extern bool report_errors(lua_State* lua, int status);
+extern std::vector<std::string> StringSplit(std::string str, std::string delim);
+
+struct cWebPlugin_Lua::sWebPluginTab
+{
+ std::string Title;
+ std::string SafeTitle;
+
+ int Reference;
+};
+
+cWebPlugin_Lua::cWebPlugin_Lua( cPlugin_NewLua* a_Plugin )
+ : cWebPlugin( a_Plugin->GetLuaState() )
+ , m_Plugin( a_Plugin )
+{
+
+}
+
+cWebPlugin_Lua::~cWebPlugin_Lua()
+{
+ for( TabList::iterator itr = m_Tabs.begin(); itr != m_Tabs.end(); ++itr )
+ {
+ delete *itr;
+ }
+ m_Tabs.clear();
+}
+
+bool cWebPlugin_Lua::AddTab( const char* a_Title, lua_State * a_LuaState, int a_FunctionReference )
+{
+ if( a_LuaState != m_Plugin->GetLuaState() )
+ {
+ LOGERROR("Only allowed to add a tab to a WebPlugin of your own Plugin!");
+ return false;
+ }
+ sWebPluginTab* Tab = new sWebPluginTab();
+ Tab->Title = a_Title;
+ Tab->SafeTitle = a_Title; // TODO - Convert all non alphabet/digit letters to underscores
+
+ Tab->Reference = a_FunctionReference;
+
+ m_Tabs.push_back( Tab );
+ return true;
+}
+
+std::string cWebPlugin_Lua::HandleRequest( HTTPRequest* a_Request )
+{
+ lua_State* LuaState = m_Plugin->GetLuaState();
+ std::string RetVal = "";
+
+ std::string TabName = GetTabNameForRequest(a_Request);
+ if( TabName.empty() )
+ return "";
+
+ sWebPluginTab* Tab = 0;
+ for( TabList::iterator itr = m_Tabs.begin(); itr != m_Tabs.end(); ++itr )
+ {
+ if( (*itr)->Title.compare( TabName ) == 0 ) // This is the one! Rawr
+ {
+ Tab = *itr;
+ break;
+ }
+ }
+
+ if( Tab )
+ {
+ LOGINFO("1. Stack size: %i", lua_gettop(LuaState) );
+ lua_rawgeti( LuaState, LUA_REGISTRYINDEX, Tab->Reference); // same as lua_getref()
+
+ LOGINFO("2. Stack size: %i", lua_gettop(LuaState) );
+ // Push HTTPRequest
+ tolua_pushusertype( LuaState, a_Request, "HTTPRequest" );
+ LOGINFO("Calling bound function! :D");
+ int s = lua_pcall( LuaState, 1, 1, 0);
+ if( report_errors( LuaState, s ) )
+ {
+ LOGINFO("error. Stack size: %i", lua_gettop(LuaState) );
+ return false;
+ }
+
+
+ if( !lua_isstring( LuaState, -1 ) )
+ {
+ LOGWARN("WARNING: WebPlugin tab '%s' did not return a string!", Tab->Title.c_str() );
+ lua_pop(LuaState, 1); // Pop return value
+ return "";
+ }
+
+ RetVal += tolua_tostring(LuaState, -1, 0);
+ lua_pop(LuaState, 1); // Pop return value
+ LOGINFO("ok. Stack size: %i", lua_gettop(LuaState) );
+ }
+
+ return RetVal;
+}
+
+void cWebPlugin_Lua::Initialize()
+{
+}
+
+std::string cWebPlugin_Lua::GetTabNameForRequest( HTTPRequest* a_Request )
+{
+ std::vector<std::string> Split = StringSplit( a_Request->Path, "/" );
+
+ if( Split.size() > 1 )
+ {
+ sWebPluginTab* Tab = 0;
+ if( Split.size() > 2 ) // If we got the tab name, show that page
+ {
+ for( TabList::iterator itr = m_Tabs.begin(); itr != m_Tabs.end(); ++itr )
+ {
+ if( (*itr)->SafeTitle.compare( Split[2] ) == 0 ) // This is the one! Rawr
+ {
+ Tab = *itr;
+ break;
+ }
+ }
+ }
+ else // Otherwise show the first tab
+ {
+ if( m_Tabs.size() > 0 )
+ Tab = *m_Tabs.begin();
+ }
+
+ if( Tab )
+ {
+ return Tab->Title;
+ }
+ }
+
+ return "";
+}
+
+std::list< std::string > cWebPlugin_Lua::GetTabNames()
+{
+ std::list< std::string > NameList;
+ for( TabList::iterator itr = m_Tabs.begin(); itr != m_Tabs.end(); ++itr )
+ {
+ NameList.push_back( (*itr)->Title );
+ }
+ return NameList;
+}
\ No newline at end of file diff --git a/source/cWebPlugin_Lua.h b/source/cWebPlugin_Lua.h new file mode 100644 index 000000000..deec9333e --- /dev/null +++ b/source/cWebPlugin_Lua.h @@ -0,0 +1,31 @@ +#pragma once
+
+#include "cWebPlugin.h"
+
+#include <list>
+#include <string>
+class cPlugin_NewLua;
+typedef struct lua_State lua_State;
+
+// a WebPlugin class more specialized for Lua
+class cWebPlugin_Lua : public cWebPlugin //tolua_export
+{ //tolua_export
+public: //tolua_export
+ cWebPlugin_Lua( cPlugin_NewLua* a_Plugin );
+ virtual ~cWebPlugin_Lua();
+
+ bool AddTab( const char* a_Title, lua_State * a_LuaState, int a_FunctionReference ); // >> EXPORTED IN MANUALBINDINGS <<
+
+ virtual std::string HandleRequest( HTTPRequest* a_Request );
+ virtual void Initialize();
+
+ std::string GetTabNameForRequest( HTTPRequest* a_Request );
+
+ std::list< std::string > GetTabNames();
+private:
+ cPlugin_NewLua* m_Plugin;
+
+ struct sWebPluginTab;
+ typedef std::list< sWebPluginTab* > TabList;
+ TabList m_Tabs;
+}; //tolua_export
\ No newline at end of file |