diff --git a/Plugins/NewTest/ban.lua b/Plugins/Core/ban.lua similarity index 100% rename from Plugins/NewTest/ban.lua rename to Plugins/Core/ban.lua diff --git a/Plugins/NewTest/gamemode.lua b/Plugins/Core/gamemode.lua similarity index 100% rename from Plugins/NewTest/gamemode.lua rename to Plugins/Core/gamemode.lua diff --git a/Plugins/NewTest/gotoworld.lua b/Plugins/Core/gotoworld.lua similarity index 100% rename from Plugins/NewTest/gotoworld.lua rename to Plugins/Core/gotoworld.lua diff --git a/Plugins/NewTest/help.lua b/Plugins/Core/help.lua similarity index 100% rename from Plugins/NewTest/help.lua rename to Plugins/Core/help.lua diff --git a/Plugins/NewTest/item.lua b/Plugins/Core/item.lua similarity index 100% rename from Plugins/NewTest/item.lua rename to Plugins/Core/item.lua diff --git a/Plugins/NewTest/kick.lua b/Plugins/Core/kick.lua similarity index 100% rename from Plugins/NewTest/kick.lua rename to Plugins/Core/kick.lua diff --git a/Plugins/NewTest/main.lua b/Plugins/Core/main.lua similarity index 93% rename from Plugins/NewTest/main.lua rename to 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 similarity index 100% rename from Plugins/NewTest/motd.lua rename to Plugins/Core/motd.lua diff --git a/Plugins/NewTest/onblockplace.lua b/Plugins/Core/onblockplace.lua similarity index 100% rename from Plugins/NewTest/onblockplace.lua rename to Plugins/Core/onblockplace.lua diff --git a/Plugins/NewTest/onkilled.lua b/Plugins/Core/onkilled.lua similarity index 100% rename from Plugins/NewTest/onkilled.lua rename to Plugins/Core/onkilled.lua diff --git a/Plugins/NewTest/onlogin.lua b/Plugins/Core/onlogin.lua similarity index 100% rename from Plugins/NewTest/onlogin.lua rename to Plugins/Core/onlogin.lua diff --git a/Plugins/NewTest/onplayerjoin.lua b/Plugins/Core/onplayerjoin.lua similarity index 100% rename from Plugins/NewTest/onplayerjoin.lua rename to Plugins/Core/onplayerjoin.lua diff --git a/Plugins/NewTest/playerlist.lua b/Plugins/Core/playerlist.lua similarity index 100% rename from Plugins/NewTest/playerlist.lua rename to Plugins/Core/playerlist.lua diff --git a/Plugins/NewTest/pluginlist.lua b/Plugins/Core/pluginlist.lua similarity index 100% rename from Plugins/NewTest/pluginlist.lua rename to Plugins/Core/pluginlist.lua diff --git a/Plugins/NewTest/reload.lua b/Plugins/Core/reload.lua similarity index 100% rename from Plugins/NewTest/reload.lua rename to Plugins/Core/reload.lua diff --git a/Plugins/NewTest/spawn.lua b/Plugins/Core/spawn.lua similarity index 100% rename from Plugins/NewTest/spawn.lua rename to Plugins/Core/spawn.lua diff --git a/Plugins/NewTest/teleport.lua b/Plugins/Core/teleport.lua similarity index 100% rename from Plugins/NewTest/teleport.lua rename to Plugins/Core/teleport.lua diff --git a/Plugins/NewTest/time.lua b/Plugins/Core/time.lua similarity index 100% rename from Plugins/NewTest/time.lua rename to Plugins/Core/time.lua diff --git a/Plugins/NewTest/top.lua b/Plugins/Core/top.lua similarity index 100% rename from Plugins/NewTest/top.lua rename to Plugins/Core/top.lua diff --git a/Plugins/NewTest/unban.lua b/Plugins/Core/unban.lua similarity index 100% rename from Plugins/NewTest/unban.lua rename to 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 .. "

Could not find player " .. KickPlayerName .. " !

" + elseif( Player:GetName() == KickPlayerName ) then + Player:GetClientHandle():Kick("You were kicked from the game!") + Content = Content .. "

" .. KickPlayerName .. " has been kicked from the game!

" + end + end + + Content = Content .. "

Connected Players: " .. World:GetNumPlayers() .. "

" + Content = Content .. "" + + + local PlayerList = World:GetAllPlayers() + for i, Player in ipairs( PlayerList ) do + Content = Content .. "" + Content = Content .. "" + Content = Content .. "" + Content = Content .. "" + Content = Content .. "" + end + + Content = Content .. "
" .. i .. "." .. Player:GetName() .. "Kick
" + Content = Content .. "
" + 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 .. "" + Content = Content .. "

Reloading plugins... This can take a while depending on the plugins you're using.

" + cRoot:Get():GetPluginManager():ReloadPlugins() + else + Content = Content .. "
" + Content = Content .. "

Click the reload button to reload all plugins!
" + Content = Content .. "

" + Content = Content .. "
" + 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 "
" +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 = "".. PlayerName.." is already on the whitelist" + else + WhiteListIni:SetValueB("WhiteList", PlayerName, true ) + UpdateMessage = "Added " .. PlayerName .. " 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 " .. PlayerName .. " 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 .. "

Whitelist is currently disabled! Click here to enable.

" + end + + + Content = Content .. "

Whitelisted players

" + Content = Content .. "" + 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 .. "" + end + end + else + Content = Content .. "" + end + Content = Content .. "
" .. PlayerName .. "" .. HTMLDeleteButton( PlayerName ) .. "
None
" + Content = Content .. "

Add player to whitelist

" + Content = Content .. "
" + Content = Content .. "" + Content = Content .. "
" + Content = Content .. "
" + Content = Content .. "" + Content = Content .. "
" + Content = Content .. "
"..UpdateMessage + + if( WhiteListEnabled == true ) then + Content = Content .. "

Whitelist is currently enabled, click here to disable.

" + 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 @@ + @@ -529,6 +530,7 @@ + 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 @@ {fb282bd3-cf18-44b3-8ccc-9a5a89701a6d} + + {31f2d7f9-9684-456b-9d70-011a10e894fd} + @@ -901,6 +904,9 @@ cPlugin\cPlugin_NewLua + + cWebAdmin\cWebPlugin\cWebPlugin + @@ -1386,6 +1392,9 @@ cPlugin\cPlugin_NewLua + + cWebAdmin\cWebPlugin\cWebPlugin + diff --git a/makefile b/makefile index 7f922f4a0..378847ffe 100644 --- a/makefile +++ b/makefile @@ -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"); @@ -8041,6 +8043,212 @@ static int tolua_AllToLua_cPlugin_NewLua_Initialize00(lua_State* tolua_S) return 0; #endif } +#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 { @@ -8054,6 +8262,60 @@ public: } else { return ( bool ) cPlugin_NewLua:: Initialize(); }; + }; + void Tick( float a_Dt) { + 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 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, 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); + }; + }; + 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:: OnLogin(a_PacketData); + }; + }; + bool OnBlockPlace( cPacket_BlockPlace* a_PacketData, cPlayer* a_Player) { + 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); + bool tolua_ret = ( bool )tolua_toboolean(lua_state, -1, 0); + lua_pop(lua_state, 1); + return tolua_ret; + } else { + 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)) { @@ -8061,14 +8323,6 @@ public: } else { return ( void ) cPlugin_NewLua:: OnDisable(); }; - }; - void Tick( float a_Dt) { - if (push_method("Tick", tolua_AllToLua_cPlugin_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)) { @@ -8093,18 +8347,6 @@ public: } else { return ( bool ) cPlugin_NewLua:: OnDisconnect(a_Reason,a_Player); }; - }; - bool OnBlockPlace( cPacket_BlockPlace* a_PacketData, cPlayer* a_Player) { - if (push_method("OnBlockPlace", tolua_AllToLua_cPlugin_OnBlockPlace00)) { - tolua_pushusertype(lua_state, (void*)a_PacketData, "cPacket_BlockPlace"); - 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:: OnBlockPlace(a_PacketData,a_Player); - }; }; bool OnBlockDig( cPacket_BlockDig* a_PacketData, cPlayer* a_Player, cItem* a_PickupItem) { if (push_method("OnBlockDig", tolua_AllToLua_cPlugin_OnBlockDig00)) { @@ -8130,17 +8372,6 @@ public: } else { 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)) { @@ -8149,17 +8380,6 @@ public: } else { 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)) { @@ -8178,51 +8398,42 @@ 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); @@ -8230,9 +8441,6 @@ public: 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 +#ifdef _WIN32 +#include "wdirent.h" +#else +#include #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 +#include 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 += "
  • " + (*itr)->GetName() + "
  • "; + 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 += "
  • " + (*Name) + "
  • "; + } + } + else + { + Menu += "
  • " + WebPlugin->GetName() + "
  • "; + } } 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("
  • ") + std::string( (*itr)->GetName() ) + "
  • "; + char c_VersionNum[32]; // 32 digits should be enough? XD + sprintf_s( c_VersionNum, 32, "%i", (*itr)->GetVersion() ); + Content += std::string("
  • ") + std::string( (*itr)->GetName() ) + " V. " + std::string( c_VersionNum ) + "
  • "; + } } Content += ""; @@ -163,13 +193,7 @@ void cWebAdmin::Request_Handler(webserver::http_request* r) if( Split.size() > 1 ) { - Content += "\n

    Go back

    "; + Content += "\n

    Go back

    "; } // 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 +#include "tolua++.h" +#include "cWebAdmin.h" + +extern bool report_errors(lua_State* lua, int status); +extern std::vector 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 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 +#include +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