From de293999872346271cdfb5dbecbad7f77362b83b Mon Sep 17 00:00:00 2001 From: faketruth Date: Fri, 27 Jan 2012 23:47:32 +0000 Subject: Converted entire Core plugin including WebAdmin interface to new plugin method/system/thingy and sexyfied it. Made some changes to WebAdmin to make the new plugins work Old plugins still work like they're supposed to Not all hooks have been programmed for the new plugins yet, this still needs to be done git-svn-id: http://mc-server.googlecode.com/svn/trunk@182 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- Plugins/Core/ban.lua | 30 +++ Plugins/Core/gamemode.lua | 10 + Plugins/Core/gotoworld.lua | 15 ++ Plugins/Core/help.lua | 54 ++++ Plugins/Core/item.lua | 65 +++++ Plugins/Core/kick.lua | 27 ++ Plugins/Core/main.lua | 138 ++++++++++ Plugins/Core/motd.lua | 10 + Plugins/Core/onblockplace.lua | 60 +++++ Plugins/Core/onkilled.lua | 24 ++ Plugins/Core/onlogin.lua | 20 ++ Plugins/Core/onplayerjoin.lua | 4 + Plugins/Core/playerlist.lua | 16 ++ Plugins/Core/pluginlist.lua | 13 + Plugins/Core/reload.lua | 6 + Plugins/Core/spawn.lua | 6 + Plugins/Core/teleport.lua | 18 ++ Plugins/Core/time.lua | 18 ++ Plugins/Core/top.lua | 11 + Plugins/Core/unban.lua | 20 ++ Plugins/Core/web_playerlist.lua | 32 +++ Plugins/Core/web_reload.lua | 15 ++ Plugins/Core/web_whitelist.lua | 79 ++++++ Plugins/NewTest/ban.lua | 30 --- Plugins/NewTest/gamemode.lua | 10 - Plugins/NewTest/gotoworld.lua | 15 -- Plugins/NewTest/help.lua | 54 ---- Plugins/NewTest/item.lua | 65 ----- Plugins/NewTest/kick.lua | 27 -- Plugins/NewTest/main.lua | 132 ---------- Plugins/NewTest/motd.lua | 10 - Plugins/NewTest/onblockplace.lua | 60 ----- Plugins/NewTest/onkilled.lua | 24 -- Plugins/NewTest/onlogin.lua | 20 -- Plugins/NewTest/onplayerjoin.lua | 4 - Plugins/NewTest/playerlist.lua | 16 -- Plugins/NewTest/pluginlist.lua | 13 - Plugins/NewTest/reload.lua | 6 - Plugins/NewTest/spawn.lua | 6 - Plugins/NewTest/teleport.lua | 18 -- Plugins/NewTest/time.lua | 18 -- Plugins/NewTest/top.lua | 11 - Plugins/NewTest/unban.lua | 20 -- VC2010/MCServer.vcxproj | 2 + VC2010/MCServer.vcxproj.filters | 9 + makefile | 22 +- settings.ini | 4 +- source/AllToLua.pkg | 1 + source/Bindings.cpp | 549 +++++++++++++++++++++++++++++++++------ source/Bindings.h | 2 +- source/ManualBindings.cpp | 47 ++++ source/cPlugin_NewLua.cpp | 34 ++- source/cPlugin_NewLua.h | 8 + source/cWebAdmin.cpp | 50 +++- source/cWebPlugin_Lua.cpp | 149 +++++++++++ source/cWebPlugin_Lua.h | 31 +++ 56 files changed, 1494 insertions(+), 664 deletions(-) create mode 100644 Plugins/Core/ban.lua create mode 100644 Plugins/Core/gamemode.lua create mode 100644 Plugins/Core/gotoworld.lua create mode 100644 Plugins/Core/help.lua create mode 100644 Plugins/Core/item.lua create mode 100644 Plugins/Core/kick.lua create mode 100644 Plugins/Core/main.lua create mode 100644 Plugins/Core/motd.lua create mode 100644 Plugins/Core/onblockplace.lua create mode 100644 Plugins/Core/onkilled.lua create mode 100644 Plugins/Core/onlogin.lua create mode 100644 Plugins/Core/onplayerjoin.lua create mode 100644 Plugins/Core/playerlist.lua create mode 100644 Plugins/Core/pluginlist.lua create mode 100644 Plugins/Core/reload.lua create mode 100644 Plugins/Core/spawn.lua create mode 100644 Plugins/Core/teleport.lua create mode 100644 Plugins/Core/time.lua create mode 100644 Plugins/Core/top.lua create mode 100644 Plugins/Core/unban.lua create mode 100644 Plugins/Core/web_playerlist.lua create mode 100644 Plugins/Core/web_reload.lua create mode 100644 Plugins/Core/web_whitelist.lua delete mode 100644 Plugins/NewTest/ban.lua delete mode 100644 Plugins/NewTest/gamemode.lua delete mode 100644 Plugins/NewTest/gotoworld.lua delete mode 100644 Plugins/NewTest/help.lua delete mode 100644 Plugins/NewTest/item.lua delete mode 100644 Plugins/NewTest/kick.lua delete mode 100644 Plugins/NewTest/main.lua delete mode 100644 Plugins/NewTest/motd.lua delete mode 100644 Plugins/NewTest/onblockplace.lua delete mode 100644 Plugins/NewTest/onkilled.lua delete mode 100644 Plugins/NewTest/onlogin.lua delete mode 100644 Plugins/NewTest/onplayerjoin.lua delete mode 100644 Plugins/NewTest/playerlist.lua delete mode 100644 Plugins/NewTest/pluginlist.lua delete mode 100644 Plugins/NewTest/reload.lua delete mode 100644 Plugins/NewTest/spawn.lua delete mode 100644 Plugins/NewTest/teleport.lua delete mode 100644 Plugins/NewTest/time.lua delete mode 100644 Plugins/NewTest/top.lua delete mode 100644 Plugins/NewTest/unban.lua create mode 100644 source/cWebPlugin_Lua.cpp create mode 100644 source/cWebPlugin_Lua.h diff --git a/Plugins/Core/ban.lua b/Plugins/Core/ban.lua new file mode 100644 index 000000000..a6a662c3c --- /dev/null +++ b/Plugins/Core/ban.lua @@ -0,0 +1,30 @@ +function HandleBanCommand( Split, Player ) + if( #Split < 2 ) then + Player:SendMessage( cChatColor.Green .. "Usage: /ban [Player] " ) + return true + end + + local World = Player:GetWorld() + local OtherPlayer = World:GetPlayer( Split[2] ) + if( OtherPlayer == nil ) then + Player:SendMessage( cChatColor.Green .. "Could not find player " .. Split[2] ) + return true + end + + local Reason = "You have been banned" + if( #Split > 2 ) then + Reason = table.concat(Split, " ", 3) + end + + local Server = cRoot:Get():GetServer() + LOGINFO( Player:GetName() .. " is banning " .. OtherPlayer:GetName() .. " ( "..Reason..") " ) + Server:SendMessage( "Banning " .. OtherPlayer:GetName() ) + + local ClientHandle = OtherPlayer:GetClientHandle() + ClientHandle:Kick( Reason ) + + BannedPlayersIni:SetValueB("Banned", OtherPlayer:GetName(), true) + BannedPlayersIni:WriteFile() + + return true +end \ No newline at end of file diff --git a/Plugins/Core/gamemode.lua b/Plugins/Core/gamemode.lua new file mode 100644 index 000000000..1e73b46fd --- /dev/null +++ b/Plugins/Core/gamemode.lua @@ -0,0 +1,10 @@ +function HandleChangeGMCommand( Split, Player ) + if( #Split ~= 2 ) then + Player:SendMessage( cChatColor.Green .. "Usage: /gm [GameMode (0|1)]" ) + return true + end + + Player:SetGameMode(Split[2]) + + return true +end \ No newline at end of file diff --git a/Plugins/Core/gotoworld.lua b/Plugins/Core/gotoworld.lua new file mode 100644 index 000000000..d5113b667 --- /dev/null +++ b/Plugins/Core/gotoworld.lua @@ -0,0 +1,15 @@ +function HandleGotoWorldCommand( Split, Player ) + if( #Split ~= 2 ) then + Player:SendMessage( cChatColor.Green .. "Usage: /gotoworld [WorldName]" ) + return true + end + + if( Player:MoveToWorld(Split[2]) == false ) then + Player:SendMessage( cChatColor.Green .. "Could not move to world '" .. Split[2] .. "'!" ) + return true + end + + + Player:SendMessage( cChatColor.Green .. "Moved successfully to '" .. Split[2] .. "'! :D" ) + return true +end \ No newline at end of file diff --git a/Plugins/Core/help.lua b/Plugins/Core/help.lua new file mode 100644 index 000000000..02ef25ebd --- /dev/null +++ b/Plugins/Core/help.lua @@ -0,0 +1,54 @@ +function HandleHelpCommand( Split, Player ) + local PluginManager = cRoot:Get():GetPluginManager() + + local LinesPerPage = 9 + local CurrentPage = 1 + local CurrentLine = 0 + + if( #Split == 2 ) then + CurrentPage = tonumber(Split[2]) + end + + local Pages = {} + + local PluginList = PluginManager:GetAllPlugins() + for i, Plugin in ipairs( PluginList ) do + local Commands = Plugin:GetCommands() + for i, v in ipairs( Commands ) do + if( Player:HasPermission( v.Permission ) ) then + local PageNum = math.floor( CurrentLine/LinesPerPage )+1 + if( Pages[ PageNum ] == nil ) then Pages[ PageNum ] = {} end -- Create page + + if( Pages[ PageNum ].ShownName ~= Plugin:GetName() and SHOW_PLUGIN_NAMES == true ) then + if( CurrentLine == LinesPerPage * PageNum -1 ) then -- Don't add if it's the last line of the page, it looks silly + -- Add it to the next page instead + CurrentLine = CurrentLine+1 + PageNum = math.floor( CurrentLine/LinesPerPage )+1 + + if( Pages[ PageNum ] == nil ) then Pages[ PageNum ] = {} end -- Create page + table.insert( Pages[ PageNum ], cChatColor.Gold .. Plugin:GetName() ) + else + Pages[ PageNum ].ShownName = Plugin:GetName() + table.insert( Pages[ PageNum ], cChatColor.Gold .. Plugin:GetName() ) + end + CurrentLine = CurrentLine+1 + PageNum = math.floor( CurrentLine/LinesPerPage )+1 + if( Pages[ PageNum ] == nil ) then Pages[ PageNum ] = {} end -- Create page + end + local Message = cChatColor.Blue .. v.Command .. v.Description; + table.insert( Pages[ PageNum ], Message ) + CurrentLine = CurrentLine+1 + end + end + end + + Player:SendMessage( cChatColor.Purple .. "- All commands - " .. cChatColor.Gold .. "[Page " .. (CurrentPage) .."/"..#Pages.."]" ) + + if( Pages[CurrentPage] ~= nil ) then + for i, v in ipairs(Pages[CurrentPage]) do + Player:SendMessage( v ) + end + end + + return true +end \ No newline at end of file diff --git a/Plugins/Core/item.lua b/Plugins/Core/item.lua new file mode 100644 index 000000000..942fa8ce6 --- /dev/null +++ b/Plugins/Core/item.lua @@ -0,0 +1,65 @@ +function HandleItemCommand( Split, Player ) + if( #Split ~= 2 and #Split ~=3 ) then + Player:SendMessage( cChatColor.Green .. "Usage: /item [ItemID/Name:Dmg] " ) + return true + end + + local FoundItem = false + + local ItemSyntax = Split[2] -- Contains item string with optional metadata + local ItemData = StringSplit( Split[2], ":" ) + + -- Default item values + local ItemID = 0 + local ItemMeta = 0 + local ItemAmount = 1 + + if( #ItemData > 0 ) then + ItemID = ItemData[1] + end + + if( tonumber(ItemID) ~= nil ) then -- Definitely a number + ItemID = tonumber(ItemID) + if( IsValidItem( ItemID ) ) then + FoundItem = true + end + end + + if( FoundItem == false ) then + if ( HAVE_ITEM_NAMES == true ) then + local Item = ItemsTable[ ItemID ] + if( Item ~= nil ) then + ItemID = Item.m_ItemID + ItemMeta = Item.m_ItemHealth + FoundItem = true + end + end + end + + -- Override metadata from item in list, if metadata was given + if( #ItemData > 1 and tonumber( ItemData[2] ) ~= nil ) then -- Metadata is given, and is a number + ItemMeta = tonumber( ItemData[2] ) + end + + if( FoundItem == false ) then + Player:SendMessage( cChatColor.Green .. "Invalid Item ID / Name !" ) + return true + end + + if( #Split == 3 ) then + ItemAmount = tonumber( Split[3] ) + if( ItemAmount == nil or ItemAmount < 1 or ItemAmount > 512 ) then + Player:SendMessage( cChatColor.Green .. "Invalid Amount !" ) + return true + end + end + + local NewItem = cItem( ItemID, ItemAmount, ItemMeta ) + if( Player:GetInventory():AddItem( NewItem ) == true ) then + Player:SendMessage( cChatColor.Green .. "There you go !" ) + LOG("Gave " .. Player:GetName() .. " " .. ItemAmount .. " times " .. ItemID .. ":" .. ItemMeta) + else + Player:SendMessage( cChatColor.Green .. "Not enough space in inventory !" ) + end + return true +end \ No newline at end of file diff --git a/Plugins/Core/kick.lua b/Plugins/Core/kick.lua new file mode 100644 index 000000000..ff4f8a705 --- /dev/null +++ b/Plugins/Core/kick.lua @@ -0,0 +1,27 @@ +function HandleKickCommand( Split, Player ) + if( #Split < 2 ) then + Player:SendMessage( cChatColor.Green .. "Usage: /kick [Player] " ) + return true + end + + local World = Player:GetWorld() + local OtherPlayer = World:GetPlayer( Split[2] ) + if( OtherPlayer == nil ) then + Player:SendMessage( cChatColor.Green .. "Could not find player " .. Split[2] ) + return true + end + + local Reason = "You have been kicked" + if( #Split > 2 ) then + Reason = table.concat(Split, " ", 3) + end + + local Server = cRoot:Get():GetServer() + LOGINFO( Player:GetName() .. " is kicking " .. OtherPlayer:GetName() .. " ( "..Reason..") " ) + Server:SendMessage( "Kicking " .. OtherPlayer:GetName() ) + + local ClientHandle = OtherPlayer:GetClientHandle() + ClientHandle:Kick( Reason ) + + return true +end \ No newline at end of file diff --git a/Plugins/Core/main.lua b/Plugins/Core/main.lua new file mode 100644 index 000000000..90f86938f --- /dev/null +++ b/Plugins/Core/main.lua @@ -0,0 +1,138 @@ +---- Some settings ----- +SHOW_PLUGIN_NAMES = true -- If true, plugin name will be shown before commands + -- This is overwritten in the Initialize() function +------------------------ + +-- Global variables +PLUGIN = {} -- Reference to own plugin object +BannedPlayersIni = {} +WhiteListIni = {} +ItemsTable = {} + +function Initialize( Plugin ) + PLUGIN = Plugin + + Plugin:SetName( "Core" ) + Plugin:SetVersion( 8 ) + + PluginManager = cRoot:Get():GetPluginManager() + PluginManager:AddHook( Plugin, cPluginManager.E_PLUGIN_PLAYER_JOIN ) + PluginManager:AddHook( Plugin, cPluginManager.E_PLUGIN_LOGIN ) + PluginManager:AddHook( Plugin, cPluginManager.E_PLUGIN_BLOCK_PLACE ) + PluginManager:AddHook( Plugin, cPluginManager.E_PLUGIN_KILLED ) + + Plugin:AddCommand("/help", " - [Page] Show this message", "core.help") + Plugin:AddCommand("/pluginlist", " - Show list of plugins", "core.pluginlist") + Plugin:AddCommand("/tp", " - [Player] - Teleport yourself to a player", "core.teleport") + Plugin:AddCommand("/item", " - [ItemID/Name] - Spawn an item for yourself", "core.item") + Plugin:AddCommand("/list", " - Shows list of connected players", "core.playerlist") + Plugin:AddCommand("/motd", " - Show message of the day", "core.motd") + Plugin:AddCommand("/reload", " - Reload all plugins", "core.reload") + Plugin:AddCommand("/time", " - [Day/Night] - Sets the time of day", "core.time") + Plugin:AddCommand("/spawn", " - Return to the spawn", "core.spawn") + Plugin:AddCommand("/kick", " - [Player] - Kick a player", "core.kick") + Plugin:AddCommand("/ban", " - [Player] - Ban a player", "core.ban") + Plugin:AddCommand("/unban", " - [Player] - Unban a player", "core.unban") + Plugin:AddCommand("/top", " - Teleport yourself to the top most block", "core.top") + Plugin:AddCommand("/gm", " - [Gamemode (0|1)] - Change your gamemode", "core.changegm") + Plugin:AddCommand("/gotoworld", " - Move to a different world!", "core.gotoworld") + + Plugin:BindCommand( "/help", "core.help", HandleHelpCommand ) + Plugin:BindCommand( "/pluginlist", "core.pluginlist", HandlePluginListCommand ) + Plugin:BindCommand( "/tp", "core.teleport", HandleTPCommand ) + Plugin:BindCommand( "/item", "core.item", HandleItemCommand ) + Plugin:BindCommand( "/i", "core.item", HandleItemCommand ) + Plugin:BindCommand( "/list", "core.playerlist", HandlePlayerListCommand ) + Plugin:BindCommand( "/who", "core.playerlist", HandlePlayerListCommand ) + Plugin:BindCommand( "/playerlist", "core.playerlist", HandlePlayerListCommand ) + Plugin:BindCommand( "/motd", "core.motd", HandleMOTDCommand ) + Plugin:BindCommand( "/reload", "core.reload", HandleReloadCommand ) + Plugin:BindCommand( "/time", "core.time", HandleTimeCommand ) + Plugin:BindCommand( "/spawn", "core.spawn", HandleSpawnCommand ) + Plugin:BindCommand( "/home", "core.spawn", HandleSpawnCommand ) + Plugin:BindCommand( "/kick", "core.kick", HandleKickCommand ) + Plugin:BindCommand( "/ban", "core.ban", HandleBanCommand ) + Plugin:BindCommand( "/unban", "core.unban", HandleUnbanCommand ) + Plugin:BindCommand( "/top", "core.top", HandleTopCommand ) + Plugin:BindCommand( "/gm", "core.changegm", HandleChangeGMCommand ) + Plugin:BindCommand( "/gotoworld", "core.gotoworld", HandleGotoWorldCommand ) + + + local IniFile = cIniFile("settings.ini") + if ( IniFile:ReadFile() == true ) then + SHOW_PLUGIN_NAMES = IniFile:GetValueB("HelpPlugin", "ShowPluginNames", true ) + end + + local itemsINI = cIniFile("items.ini") + if ( itemsINI:ReadFile() == true ) then + local KeyID = itemsINI:FindKey('Items') + + LOGINFO("Core: loaded " .. itemsINI:GetNumValues( KeyID ) .. " item names.") + + for i = 0, itemsINI:GetNumValues('Items') do + local ItemName = itemsINI:GetValueName( KeyID, i ) + local ItemSyntax = itemsINI:GetValue(KeyID, i, "0") + + local ItemData = StringSplit(ItemSyntax, ":") -- [1] = ID, [2] = perhaps meta/dmg + --LOGINFO( "#ItemData: " .. #ItemData ) + if( #ItemData > 0 ) then + --LOGINFO("ItemData[0]: "..ItemData[1]) + local ItemID = tonumber( ItemData[1] ) + if( ItemID > 0 ) then + local ItemMeta = 0 + if( #ItemData > 1 ) then + ItemMeta = tonumber( ItemData[2] ) + end + ItemsTable[ ItemName ] = cItem( ItemID, 1, ItemMeta ) + LOGINFO("Got item: " .. ItemName .. "-> " .. ItemsTable[ ItemName ].m_ItemID ..":" .. ItemsTable[ ItemName ].m_ItemHealth ) + end + end + end + + HAVE_ITEM_NAMES = true + end + + -- Load whitelist, and add default values and stuff + WhiteListIni = cIniFile("whitelist.ini") + if ( WhiteListIni:ReadFile() == true ) then + if( WhiteListIni:GetValueB("WhiteListSettings", "WhiteListOn", false) == true ) then + if( WhiteListIni:GetNumValues("WhiteList") > 0 ) then + LOGINFO("Core: loaded " .. WhiteListIni:GetNumValues('WhiteList') .. " whitelisted players.") + else + LOGWARN("WARNING: WhiteList is on, but there are no people in the whitelist!") + end + end + else + WhiteListIni:SetValueB("WhiteListSettings", "WhiteListOn", false ) + WhiteListIni:SetValue("WhiteList", "", "") -- So it adds an empty header + WhiteListIni:DeleteValue("WhiteList", "") -- And remove the value + WhiteListIni:KeyComment("WhiteList", "PlayerName=1") + if( WhiteListIni:WriteFile() == false ) then + LOGWARN("WARNING: Could not write to whitelist.ini") + end + end + + -- Load banned players, and add default values and stuff + BannedPlayersIni = cIniFile("banned.ini") + if ( BannedPlayersIni:ReadFile() == true ) then + if( BannedPlayersIni:GetNumValues("Banned") > 0 ) then + LOGINFO("Core: loaded " .. BannedPlayersIni:GetNumValues("Banned") .. " banned players.") + end + else + BannedPlayersIni:SetValue("Banned", "", "") -- So it adds an empty header + BannedPlayersIni:DeleteValue("Banned", "") -- And remove the value + BannedPlayersIni:KeyComment("Banned", "PlayerName=1") + if( BannedPlayersIni:WriteFile() == false ) then + LOGWARN("WARNING: Could not write to banned.ini") + 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/Core/motd.lua b/Plugins/Core/motd.lua new file mode 100644 index 000000000..49cdcecad --- /dev/null +++ b/Plugins/Core/motd.lua @@ -0,0 +1,10 @@ +function HandleMOTDCommand( Split, Player ) + ShowMOTDTo( Player ) + return true +end + +function ShowMOTDTo( Player ) + Player:SendMessage( cChatColor.Gold .. "Welcome to the MCServer test server!" ); + Player:SendMessage( cChatColor.Gold .. "http://mcserver.ae-c.net/" ); + Player:SendMessage( cChatColor.Gold .. "Type /help for all commands" ); +end \ No newline at end of file diff --git a/Plugins/Core/onblockplace.lua b/Plugins/Core/onblockplace.lua new file mode 100644 index 000000000..ba75bf5c2 --- /dev/null +++ b/Plugins/Core/onblockplace.lua @@ -0,0 +1,60 @@ +function OnBlockPlace( Block, Player ) + + -- dont check if the direction is in the air + if Block.m_Direction ~= -1 then + + local X = Block.m_PosX + local Y = Block.m_PosY + local Z = Block.m_PosZ + X, Y, Z = AddDirection( X, Y, Z, Block.m_Direction ) + if( Y >= 128 or Y < 0 ) then + return true + end + + local collision = false + local World = Player:GetWorld() + local PlayerList = World:GetAllPlayers() + + -- check if a player occupies the placement location + for i, Player in ipairs( PlayerList ) do + + -- drop the decimals, we only care about the full block X,Y,Z + local PlayerX = math.floor(Player:GetPosX(), 0) + local PlayerY = math.floor(Player:GetPosY(), 0) + local PlayerZ = math.floor(Player:GetPosZ(), 0) + + local BlockX = Block.m_PosX + local BlockY = Block.m_PosY + local BlockZ = Block.m_PosZ + + -- player height is 2 blocks, so we check the position and then offset it up one + -- so they can't place a block on there face + + if Block.m_Direction == 0 then if PlayerY == BlockY-2 and PlayerX == BlockX and PlayerZ == BlockZ then collision = true end end + if Block.m_Direction == 1 then if PlayerY == BlockY+1 and PlayerX == BlockX and PlayerZ == BlockZ then collision = true end end + + if Block.m_Direction == 2 then if PlayerY == BlockY and PlayerX == BlockX and PlayerZ == BlockZ-1 then collision = true end end + if Block.m_Direction == 2 then if PlayerY+1 == BlockY and PlayerX == BlockX and PlayerZ == BlockZ-1 then collision = true end end + + if Block.m_Direction == 3 then if PlayerY == BlockY and PlayerX == BlockX and PlayerZ == BlockZ+1 then collision = true end end + if Block.m_Direction == 3 then if PlayerY+1 == BlockY and PlayerX == BlockX and PlayerZ == BlockZ+1 then collision = true end end + + if Block.m_Direction == 4 then if PlayerY == BlockY and PlayerX == BlockX-1 and PlayerZ == BlockZ then collision = true end end + if Block.m_Direction == 4 then if PlayerY+1 == BlockY and PlayerX == BlockX-1 and PlayerZ == BlockZ then collision = true end end + + if Block.m_Direction == 5 then if PlayerY == BlockY and PlayerX == BlockX+1 and PlayerZ == BlockZ then collision = true end end + if Block.m_Direction == 5 then if PlayerY+1 == BlockY and PlayerX == BlockX+1 and PlayerZ == BlockZ then collision = true end end + + end + + if collision then + return true + else + return false + end + + end + + return false + +end \ No newline at end of file diff --git a/Plugins/Core/onkilled.lua b/Plugins/Core/onkilled.lua new file mode 100644 index 000000000..a8a92f667 --- /dev/null +++ b/Plugins/Core/onkilled.lua @@ -0,0 +1,24 @@ +function OnKilled( Killed, Killer ) + if( Killer == nil ) then + local KilledPlayer = tolua.cast( Killed, "cPlayer") + if( not KilledPlayer:IsA("cPlayer") or KilledPlayer == nil ) then + return false + end + + local Server = cRoot:Get():GetServer() + Server:SendMessage( cChatColor.Red .. KilledPlayer:GetName() .. " died" ) + else + local KilledPlayer = tolua.cast( Killed, "cPlayer") + if( not KilledPlayer:IsA("cPlayer") or KilledPlayer == nil ) then + return false + end + local KillerPlayer = tolua.cast( Killer, "cPlayer") + if( not KillerPlayer:IsA("cPlayer") or KillerPlayer == nil ) then + return false + end + + local Server = cRoot:Get():GetServer() + Server:SendMessage( cChatColor.Red .. KilledPlayer:GetName() .. " was killed by " .. KillerPlayer:GetName() .. "!" ) + end + return false +end \ No newline at end of file diff --git a/Plugins/Core/onlogin.lua b/Plugins/Core/onlogin.lua new file mode 100644 index 000000000..a706f8024 --- /dev/null +++ b/Plugins/Core/onlogin.lua @@ -0,0 +1,20 @@ +function OnLogin( PacketData ) + if( PacketData.m_Username ~= "" ) then + if( BannedPlayersIni:GetValueB("Banned", PacketData.m_Username, false) == true ) then + local Server = cRoot:Get():GetServer() + Server:SendMessage( PacketData.m_Username .. " tried to join, but is banned!" ) + LOGINFO( PacketData.m_Username .. " tried to join, but is banned!") + return true -- Player is banned, return true to deny access + end + if( WhiteListIni:GetValueB("WhiteListSettings", "WhiteListOn", false ) == true ) then + if( WhiteListIni:GetValueB("WhiteList", PacketData.m_Username, false ) == false ) then -- not on whitelist + local Server = cRoot:Get():GetServer() + Server:SendMessage( PacketData.m_Username .. " tried to join, but is not on the whitelist." ) + LOGINFO( PacketData.m_Username .. " tried to join, but is not on the whitelist." ) + return true -- Deny access to the server + end + end + end + + return false +end \ No newline at end of file diff --git a/Plugins/Core/onplayerjoin.lua b/Plugins/Core/onplayerjoin.lua new file mode 100644 index 000000000..e8263f608 --- /dev/null +++ b/Plugins/Core/onplayerjoin.lua @@ -0,0 +1,4 @@ +function OnPlayerJoin( Player ) + ShowMOTDTo( Player ) + return false +end \ No newline at end of file diff --git a/Plugins/Core/playerlist.lua b/Plugins/Core/playerlist.lua new file mode 100644 index 000000000..c120f068f --- /dev/null +++ b/Plugins/Core/playerlist.lua @@ -0,0 +1,16 @@ +function HandlePlayerListCommand( Split, Player ) + local World = Player:GetWorld() + local PlayerList = World:GetAllPlayers() + + local Message = cChatColor.Green .. "Connected players: (".. cChatColor.White.. #PlayerList .. cChatColor.Green .. ")" + Player:SendMessage( Message ) + + local PlayerTable = {} + for i, TempPlayer in ipairs( PlayerList ) do + local PlayerName = TempPlayer:GetName() + table.insert(PlayerTable, PlayerName ) + end + + Player:SendMessage( table.concat(PlayerTable, " ") ) + return true +end \ No newline at end of file diff --git a/Plugins/Core/pluginlist.lua b/Plugins/Core/pluginlist.lua new file mode 100644 index 000000000..6cb767868 --- /dev/null +++ b/Plugins/Core/pluginlist.lua @@ -0,0 +1,13 @@ +function HandlePluginListCommand( Split, Player ) + local PluginManager = cRoot:Get():GetPluginManager() + local PluginList = PluginManager:GetAllPlugins() + + local PluginTable = {} + for i, Plugin in ipairs( PluginList ) do + table.insert(PluginTable, Plugin:GetName() ) + end + + Player:SendMessage( cChatColor.Green .. "Loaded plugins:" ) + Player:SendMessage( cChatColor.Gold .. table.concat(PluginTable, cChatColor.Gold.." ") ) + return true +end \ No newline at end of file diff --git a/Plugins/Core/reload.lua b/Plugins/Core/reload.lua new file mode 100644 index 000000000..e2b338ba1 --- /dev/null +++ b/Plugins/Core/reload.lua @@ -0,0 +1,6 @@ +function HandleReloadCommand( Split, Player ) + Server = cRoot:Get():GetServer() + Server:SendMessage( cChatColor.Green .. "Reloading all plugins." ) + cRoot:Get():GetPluginManager():ReloadPlugins() + return true +end \ No newline at end of file diff --git a/Plugins/Core/spawn.lua b/Plugins/Core/spawn.lua new file mode 100644 index 000000000..73034d9cf --- /dev/null +++ b/Plugins/Core/spawn.lua @@ -0,0 +1,6 @@ +function HandleSpawnCommand( Split, Player ) + World = Player:GetWorld() + Player:TeleportTo( World:GetSpawnX(), World:GetSpawnY(), World:GetSpawnZ() ) + LOGINFO( Player:GetName() .. " returned to spawn." ) + return true +end \ No newline at end of file diff --git a/Plugins/Core/teleport.lua b/Plugins/Core/teleport.lua new file mode 100644 index 000000000..9fffec9a2 --- /dev/null +++ b/Plugins/Core/teleport.lua @@ -0,0 +1,18 @@ +function HandleTPCommand( Split, Player ) + if( #Split ~= 2 ) then + Player:SendMessage( cChatColor.Green .. "Usage: /tp [PlayerName]" ) + return true + end + local World = Player:GetWorld() + local OtherPlayer = World:GetPlayer( Split[2] ) + if( OtherPlayer == nil ) then + Player:SendMessage( cChatColor.Green .. "Can't find player " .. Split[2] ) + elseif( OtherPlayer == Player ) then + Player:SendMessage( cChatColor.Green .. "Already there :)" ) + else + Player:TeleportTo( OtherPlayer ) + Player:SendMessage( cChatColor.Green .. "You teleported to "..OtherPlayer:GetName().."!" ) + OtherPlayer:SendMessage( cChatColor.Green .. Player:GetName().." teleported to you!" ) + end + return true +end \ No newline at end of file diff --git a/Plugins/Core/time.lua b/Plugins/Core/time.lua new file mode 100644 index 000000000..425d69e6a --- /dev/null +++ b/Plugins/Core/time.lua @@ -0,0 +1,18 @@ +function HandleTimeCommand( Split, Player ) + if( #Split ~= 2 ) then + Player:SendMessage( cChatColor.Green .. "Usage: /time [Day/Night]" ) + return true; + end + + local Server = cRoot:Get():GetServer() + if( string.upper( Split[2] ) == "DAY") then + Player:GetWorld():SetWorldTime( 0 ) + Server:SendMessage( cChatColor.Green .. Player:GetName() .. " set the time to Day.") + elseif( string.upper( Split[2] ) == "NIGHT") then + Player:GetWorld():SetWorldTime( 12000 + 1000 ) + Server:SendMessage( cChatColor.Green .. Player:GetName() .. " set the time to Night.") + else + Player:SendMessage( cChatColor.Green .. "Usage: /time [Day/Night]" ) + end + return true +end \ No newline at end of file diff --git a/Plugins/Core/top.lua b/Plugins/Core/top.lua new file mode 100644 index 000000000..0f7a8f95f --- /dev/null +++ b/Plugins/Core/top.lua @@ -0,0 +1,11 @@ +function HandleTopCommand( Split, Player ) + local World = Player:GetWorld() + + local PlayerPos = Player:GetPosition() + local Height = World:GetHeight( math.floor(PlayerPos.x), math.floor(PlayerPos.z) ) + + Player:TeleportTo( PlayerPos.x, Height+1, PlayerPos.z ) + Player:SendMessage("Teleported to the top block") + + return true +end \ No newline at end of file diff --git a/Plugins/Core/unban.lua b/Plugins/Core/unban.lua new file mode 100644 index 000000000..9defbe323 --- /dev/null +++ b/Plugins/Core/unban.lua @@ -0,0 +1,20 @@ +function HandleUnbanCommand( Split, Player ) + if( #Split < 2 ) then + Player:SendMessage( cChatColor.Green .. "Usage: /unban [Player]" ) + return true + end + + if( BannedPlayersIni:GetValueB("Banned", Split[2], false) == false ) then + Player:SendMessage( cChatColor.Green .. Split[2] .. " is not banned!" ) + return true + end + + BannedPlayersIni:SetValueB("Banned", Split[2], false, false) + BannedPlayersIni:WriteFile() + + local Server = cRoot:Get():GetServer() + LOGINFO( Player:GetName() .. " is unbanning " .. Split[2] ) + Server:SendMessage( "Unbanning " .. Split[2] ) + + return true +end \ No newline at end of file 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/Plugins/NewTest/ban.lua b/Plugins/NewTest/ban.lua deleted file mode 100644 index a6a662c3c..000000000 --- a/Plugins/NewTest/ban.lua +++ /dev/null @@ -1,30 +0,0 @@ -function HandleBanCommand( Split, Player ) - if( #Split < 2 ) then - Player:SendMessage( cChatColor.Green .. "Usage: /ban [Player] " ) - return true - end - - local World = Player:GetWorld() - local OtherPlayer = World:GetPlayer( Split[2] ) - if( OtherPlayer == nil ) then - Player:SendMessage( cChatColor.Green .. "Could not find player " .. Split[2] ) - return true - end - - local Reason = "You have been banned" - if( #Split > 2 ) then - Reason = table.concat(Split, " ", 3) - end - - local Server = cRoot:Get():GetServer() - LOGINFO( Player:GetName() .. " is banning " .. OtherPlayer:GetName() .. " ( "..Reason..") " ) - Server:SendMessage( "Banning " .. OtherPlayer:GetName() ) - - local ClientHandle = OtherPlayer:GetClientHandle() - ClientHandle:Kick( Reason ) - - BannedPlayersIni:SetValueB("Banned", OtherPlayer:GetName(), true) - BannedPlayersIni:WriteFile() - - return true -end \ No newline at end of file diff --git a/Plugins/NewTest/gamemode.lua b/Plugins/NewTest/gamemode.lua deleted file mode 100644 index 1e73b46fd..000000000 --- a/Plugins/NewTest/gamemode.lua +++ /dev/null @@ -1,10 +0,0 @@ -function HandleChangeGMCommand( Split, Player ) - if( #Split ~= 2 ) then - Player:SendMessage( cChatColor.Green .. "Usage: /gm [GameMode (0|1)]" ) - return true - end - - Player:SetGameMode(Split[2]) - - return true -end \ No newline at end of file diff --git a/Plugins/NewTest/gotoworld.lua b/Plugins/NewTest/gotoworld.lua deleted file mode 100644 index d5113b667..000000000 --- a/Plugins/NewTest/gotoworld.lua +++ /dev/null @@ -1,15 +0,0 @@ -function HandleGotoWorldCommand( Split, Player ) - if( #Split ~= 2 ) then - Player:SendMessage( cChatColor.Green .. "Usage: /gotoworld [WorldName]" ) - return true - end - - if( Player:MoveToWorld(Split[2]) == false ) then - Player:SendMessage( cChatColor.Green .. "Could not move to world '" .. Split[2] .. "'!" ) - return true - end - - - Player:SendMessage( cChatColor.Green .. "Moved successfully to '" .. Split[2] .. "'! :D" ) - return true -end \ No newline at end of file diff --git a/Plugins/NewTest/help.lua b/Plugins/NewTest/help.lua deleted file mode 100644 index 02ef25ebd..000000000 --- a/Plugins/NewTest/help.lua +++ /dev/null @@ -1,54 +0,0 @@ -function HandleHelpCommand( Split, Player ) - local PluginManager = cRoot:Get():GetPluginManager() - - local LinesPerPage = 9 - local CurrentPage = 1 - local CurrentLine = 0 - - if( #Split == 2 ) then - CurrentPage = tonumber(Split[2]) - end - - local Pages = {} - - local PluginList = PluginManager:GetAllPlugins() - for i, Plugin in ipairs( PluginList ) do - local Commands = Plugin:GetCommands() - for i, v in ipairs( Commands ) do - if( Player:HasPermission( v.Permission ) ) then - local PageNum = math.floor( CurrentLine/LinesPerPage )+1 - if( Pages[ PageNum ] == nil ) then Pages[ PageNum ] = {} end -- Create page - - if( Pages[ PageNum ].ShownName ~= Plugin:GetName() and SHOW_PLUGIN_NAMES == true ) then - if( CurrentLine == LinesPerPage * PageNum -1 ) then -- Don't add if it's the last line of the page, it looks silly - -- Add it to the next page instead - CurrentLine = CurrentLine+1 - PageNum = math.floor( CurrentLine/LinesPerPage )+1 - - if( Pages[ PageNum ] == nil ) then Pages[ PageNum ] = {} end -- Create page - table.insert( Pages[ PageNum ], cChatColor.Gold .. Plugin:GetName() ) - else - Pages[ PageNum ].ShownName = Plugin:GetName() - table.insert( Pages[ PageNum ], cChatColor.Gold .. Plugin:GetName() ) - end - CurrentLine = CurrentLine+1 - PageNum = math.floor( CurrentLine/LinesPerPage )+1 - if( Pages[ PageNum ] == nil ) then Pages[ PageNum ] = {} end -- Create page - end - local Message = cChatColor.Blue .. v.Command .. v.Description; - table.insert( Pages[ PageNum ], Message ) - CurrentLine = CurrentLine+1 - end - end - end - - Player:SendMessage( cChatColor.Purple .. "- All commands - " .. cChatColor.Gold .. "[Page " .. (CurrentPage) .."/"..#Pages.."]" ) - - if( Pages[CurrentPage] ~= nil ) then - for i, v in ipairs(Pages[CurrentPage]) do - Player:SendMessage( v ) - end - end - - return true -end \ No newline at end of file diff --git a/Plugins/NewTest/item.lua b/Plugins/NewTest/item.lua deleted file mode 100644 index 942fa8ce6..000000000 --- a/Plugins/NewTest/item.lua +++ /dev/null @@ -1,65 +0,0 @@ -function HandleItemCommand( Split, Player ) - if( #Split ~= 2 and #Split ~=3 ) then - Player:SendMessage( cChatColor.Green .. "Usage: /item [ItemID/Name:Dmg] " ) - return true - end - - local FoundItem = false - - local ItemSyntax = Split[2] -- Contains item string with optional metadata - local ItemData = StringSplit( Split[2], ":" ) - - -- Default item values - local ItemID = 0 - local ItemMeta = 0 - local ItemAmount = 1 - - if( #ItemData > 0 ) then - ItemID = ItemData[1] - end - - if( tonumber(ItemID) ~= nil ) then -- Definitely a number - ItemID = tonumber(ItemID) - if( IsValidItem( ItemID ) ) then - FoundItem = true - end - end - - if( FoundItem == false ) then - if ( HAVE_ITEM_NAMES == true ) then - local Item = ItemsTable[ ItemID ] - if( Item ~= nil ) then - ItemID = Item.m_ItemID - ItemMeta = Item.m_ItemHealth - FoundItem = true - end - end - end - - -- Override metadata from item in list, if metadata was given - if( #ItemData > 1 and tonumber( ItemData[2] ) ~= nil ) then -- Metadata is given, and is a number - ItemMeta = tonumber( ItemData[2] ) - end - - if( FoundItem == false ) then - Player:SendMessage( cChatColor.Green .. "Invalid Item ID / Name !" ) - return true - end - - if( #Split == 3 ) then - ItemAmount = tonumber( Split[3] ) - if( ItemAmount == nil or ItemAmount < 1 or ItemAmount > 512 ) then - Player:SendMessage( cChatColor.Green .. "Invalid Amount !" ) - return true - end - end - - local NewItem = cItem( ItemID, ItemAmount, ItemMeta ) - if( Player:GetInventory():AddItem( NewItem ) == true ) then - Player:SendMessage( cChatColor.Green .. "There you go !" ) - LOG("Gave " .. Player:GetName() .. " " .. ItemAmount .. " times " .. ItemID .. ":" .. ItemMeta) - else - Player:SendMessage( cChatColor.Green .. "Not enough space in inventory !" ) - end - return true -end \ No newline at end of file diff --git a/Plugins/NewTest/kick.lua b/Plugins/NewTest/kick.lua deleted file mode 100644 index ff4f8a705..000000000 --- a/Plugins/NewTest/kick.lua +++ /dev/null @@ -1,27 +0,0 @@ -function HandleKickCommand( Split, Player ) - if( #Split < 2 ) then - Player:SendMessage( cChatColor.Green .. "Usage: /kick [Player] " ) - return true - end - - local World = Player:GetWorld() - local OtherPlayer = World:GetPlayer( Split[2] ) - if( OtherPlayer == nil ) then - Player:SendMessage( cChatColor.Green .. "Could not find player " .. Split[2] ) - return true - end - - local Reason = "You have been kicked" - if( #Split > 2 ) then - Reason = table.concat(Split, " ", 3) - end - - local Server = cRoot:Get():GetServer() - LOGINFO( Player:GetName() .. " is kicking " .. OtherPlayer:GetName() .. " ( "..Reason..") " ) - Server:SendMessage( "Kicking " .. OtherPlayer:GetName() ) - - local ClientHandle = OtherPlayer:GetClientHandle() - ClientHandle:Kick( Reason ) - - return true -end \ No newline at end of file diff --git a/Plugins/NewTest/main.lua b/Plugins/NewTest/main.lua deleted file mode 100644 index 3dfa3f2f1..000000000 --- a/Plugins/NewTest/main.lua +++ /dev/null @@ -1,132 +0,0 @@ ----- Some settings ----- -SHOW_PLUGIN_NAMES = true -- If true, plugin name will be shown before commands - -- This is overwritten in the Initialize() function ------------------------- - --- Global variables -PLUGIN = {} -- Reference to own plugin object -BannedPlayersIni = {} -WhiteListIni = {} -ItemsTable = {} - -function Initialize( Plugin ) - PLUGIN = Plugin - - Plugin:SetName( "NewCore" ) - Plugin:SetVersion( 8 ) - - PluginManager = cRoot:Get():GetPluginManager() - PluginManager:AddHook( Plugin, cPluginManager.E_PLUGIN_PLAYER_JOIN ) - PluginManager:AddHook( Plugin, cPluginManager.E_PLUGIN_LOGIN ) - PluginManager:AddHook( Plugin, cPluginManager.E_PLUGIN_BLOCK_PLACE ) - PluginManager:AddHook( Plugin, cPluginManager.E_PLUGIN_KILLED ) - - Plugin:AddCommand("/help", " - [Page] Show this message", "core.help") - Plugin:AddCommand("/pluginlist", " - Show list of plugins", "core.pluginlist") - Plugin:AddCommand("/tp", " - [Player] - Teleport yourself to a player", "core.teleport") - Plugin:AddCommand("/item", " - [ItemID/Name] - Spawn an item for yourself", "core.item") - Plugin:AddCommand("/list", " - Shows list of connected players", "core.playerlist") - Plugin:AddCommand("/motd", " - Show message of the day", "core.motd") - Plugin:AddCommand("/reload", " - Reload all plugins", "core.reload") - Plugin:AddCommand("/time", " - [Day/Night] - Sets the time of day", "core.time") - Plugin:AddCommand("/spawn", " - Return to the spawn", "core.spawn") - Plugin:AddCommand("/kick", " - [Player] - Kick a player", "core.kick") - Plugin:AddCommand("/ban", " - [Player] - Ban a player", "core.ban") - Plugin:AddCommand("/unban", " - [Player] - Unban a player", "core.unban") - Plugin:AddCommand("/top", " - Teleport yourself to the top most block", "core.top") - Plugin:AddCommand("/gm", " - [Gamemode (0|1)] - Change your gamemode", "core.changegm") - Plugin:AddCommand("/gotoworld", " - Move to a different world!", "core.gotoworld") - - Plugin:BindCommand( "/help", "core.help", HandleHelpCommand ) - Plugin:BindCommand( "/pluginlist", "core.pluginlist", HandlePluginListCommand ) - Plugin:BindCommand( "/tp", "core.teleport", HandleTPCommand ) - Plugin:BindCommand( "/item", "core.item", HandleItemCommand ) - Plugin:BindCommand( "/i", "core.item", HandleItemCommand ) - Plugin:BindCommand( "/list", "core.playerlist", HandlePlayerListCommand ) - Plugin:BindCommand( "/who", "core.playerlist", HandlePlayerListCommand ) - Plugin:BindCommand( "/playerlist", "core.playerlist", HandlePlayerListCommand ) - Plugin:BindCommand( "/motd", "core.motd", HandleMOTDCommand ) - Plugin:BindCommand( "/reload", "core.reload", HandleReloadCommand ) - Plugin:BindCommand( "/time", "core.time", HandleTimeCommand ) - Plugin:BindCommand( "/spawn", "core.spawn", HandleSpawnCommand ) - Plugin:BindCommand( "/home", "core.spawn", HandleSpawnCommand ) - Plugin:BindCommand( "/kick", "core.kick", HandleKickCommand ) - Plugin:BindCommand( "/ban", "core.ban", HandleBanCommand ) - Plugin:BindCommand( "/unban", "core.unban", HandleUnbanCommand ) - Plugin:BindCommand( "/top", "core.top", HandleTopCommand ) - Plugin:BindCommand( "/gm", "core.changegm", HandleChangeGMCommand ) - Plugin:BindCommand( "/gotoworld", "core.gotoworld", HandleGotoWorldCommand ) - - - local IniFile = cIniFile("settings.ini") - if ( IniFile:ReadFile() == true ) then - SHOW_PLUGIN_NAMES = IniFile:GetValueB("HelpPlugin", "ShowPluginNames", true ) - end - - local itemsINI = cIniFile("items.ini") - if ( itemsINI:ReadFile() == true ) then - local KeyID = itemsINI:FindKey('Items') - - LOGINFO("Core: loaded " .. itemsINI:GetNumValues( KeyID ) .. " item names.") - - for i = 0, itemsINI:GetNumValues('Items') do - local ItemName = itemsINI:GetValueName( KeyID, i ) - local ItemSyntax = itemsINI:GetValue(KeyID, i, "0") - - local ItemData = StringSplit(ItemSyntax, ":") -- [1] = ID, [2] = perhaps meta/dmg - --LOGINFO( "#ItemData: " .. #ItemData ) - if( #ItemData > 0 ) then - --LOGINFO("ItemData[0]: "..ItemData[1]) - local ItemID = tonumber( ItemData[1] ) - if( ItemID > 0 ) then - local ItemMeta = 0 - if( #ItemData > 1 ) then - ItemMeta = tonumber( ItemData[2] ) - end - ItemsTable[ ItemName ] = cItem( ItemID, 1, ItemMeta ) - LOGINFO("Got item: " .. ItemName .. "-> " .. ItemsTable[ ItemName ].m_ItemID ..":" .. ItemsTable[ ItemName ].m_ItemHealth ) - end - end - end - - HAVE_ITEM_NAMES = true - end - - -- Load whitelist, and add default values and stuff - WhiteListIni = cIniFile("whitelist.ini") - if ( WhiteListIni:ReadFile() == true ) then - if( WhiteListIni:GetValueB("WhiteListSettings", "WhiteListOn", false) == true ) then - if( WhiteListIni:GetNumValues("WhiteList") > 0 ) then - LOGINFO("Core: loaded " .. WhiteListIni:GetNumValues('WhiteList') .. " whitelisted players.") - else - LOGWARN("WARNING: WhiteList is on, but there are no people in the whitelist!") - end - end - else - WhiteListIni:SetValueB("WhiteListSettings", "WhiteListOn", false ) - WhiteListIni:SetValue("WhiteList", "", "") -- So it adds an empty header - WhiteListIni:DeleteValue("WhiteList", "") -- And remove the value - WhiteListIni:KeyComment("WhiteList", "PlayerName=1") - if( WhiteListIni:WriteFile() == false ) then - LOGWARN("WARNING: Could not write to whitelist.ini") - end - end - - -- Load banned players, and add default values and stuff - BannedPlayersIni = cIniFile("banned.ini") - if ( BannedPlayersIni:ReadFile() == true ) then - if( BannedPlayersIni:GetNumValues("Banned") > 0 ) then - LOGINFO("Core: loaded " .. BannedPlayersIni:GetNumValues("Banned") .. " banned players.") - end - else - BannedPlayersIni:SetValue("Banned", "", "") -- So it adds an empty header - BannedPlayersIni:DeleteValue("Banned", "") -- And remove the value - BannedPlayersIni:KeyComment("Banned", "PlayerName=1") - if( BannedPlayersIni:WriteFile() == false ) then - LOGWARN("WARNING: Could not write to banned.ini") - end - end - - 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/NewTest/motd.lua deleted file mode 100644 index 49cdcecad..000000000 --- a/Plugins/NewTest/motd.lua +++ /dev/null @@ -1,10 +0,0 @@ -function HandleMOTDCommand( Split, Player ) - ShowMOTDTo( Player ) - return true -end - -function ShowMOTDTo( Player ) - Player:SendMessage( cChatColor.Gold .. "Welcome to the MCServer test server!" ); - Player:SendMessage( cChatColor.Gold .. "http://mcserver.ae-c.net/" ); - Player:SendMessage( cChatColor.Gold .. "Type /help for all commands" ); -end \ No newline at end of file diff --git a/Plugins/NewTest/onblockplace.lua b/Plugins/NewTest/onblockplace.lua deleted file mode 100644 index ba75bf5c2..000000000 --- a/Plugins/NewTest/onblockplace.lua +++ /dev/null @@ -1,60 +0,0 @@ -function OnBlockPlace( Block, Player ) - - -- dont check if the direction is in the air - if Block.m_Direction ~= -1 then - - local X = Block.m_PosX - local Y = Block.m_PosY - local Z = Block.m_PosZ - X, Y, Z = AddDirection( X, Y, Z, Block.m_Direction ) - if( Y >= 128 or Y < 0 ) then - return true - end - - local collision = false - local World = Player:GetWorld() - local PlayerList = World:GetAllPlayers() - - -- check if a player occupies the placement location - for i, Player in ipairs( PlayerList ) do - - -- drop the decimals, we only care about the full block X,Y,Z - local PlayerX = math.floor(Player:GetPosX(), 0) - local PlayerY = math.floor(Player:GetPosY(), 0) - local PlayerZ = math.floor(Player:GetPosZ(), 0) - - local BlockX = Block.m_PosX - local BlockY = Block.m_PosY - local BlockZ = Block.m_PosZ - - -- player height is 2 blocks, so we check the position and then offset it up one - -- so they can't place a block on there face - - if Block.m_Direction == 0 then if PlayerY == BlockY-2 and PlayerX == BlockX and PlayerZ == BlockZ then collision = true end end - if Block.m_Direction == 1 then if PlayerY == BlockY+1 and PlayerX == BlockX and PlayerZ == BlockZ then collision = true end end - - if Block.m_Direction == 2 then if PlayerY == BlockY and PlayerX == BlockX and PlayerZ == BlockZ-1 then collision = true end end - if Block.m_Direction == 2 then if PlayerY+1 == BlockY and PlayerX == BlockX and PlayerZ == BlockZ-1 then collision = true end end - - if Block.m_Direction == 3 then if PlayerY == BlockY and PlayerX == BlockX and PlayerZ == BlockZ+1 then collision = true end end - if Block.m_Direction == 3 then if PlayerY+1 == BlockY and PlayerX == BlockX and PlayerZ == BlockZ+1 then collision = true end end - - if Block.m_Direction == 4 then if PlayerY == BlockY and PlayerX == BlockX-1 and PlayerZ == BlockZ then collision = true end end - if Block.m_Direction == 4 then if PlayerY+1 == BlockY and PlayerX == BlockX-1 and PlayerZ == BlockZ then collision = true end end - - if Block.m_Direction == 5 then if PlayerY == BlockY and PlayerX == BlockX+1 and PlayerZ == BlockZ then collision = true end end - if Block.m_Direction == 5 then if PlayerY+1 == BlockY and PlayerX == BlockX+1 and PlayerZ == BlockZ then collision = true end end - - end - - if collision then - return true - else - return false - end - - end - - return false - -end \ No newline at end of file diff --git a/Plugins/NewTest/onkilled.lua b/Plugins/NewTest/onkilled.lua deleted file mode 100644 index a8a92f667..000000000 --- a/Plugins/NewTest/onkilled.lua +++ /dev/null @@ -1,24 +0,0 @@ -function OnKilled( Killed, Killer ) - if( Killer == nil ) then - local KilledPlayer = tolua.cast( Killed, "cPlayer") - if( not KilledPlayer:IsA("cPlayer") or KilledPlayer == nil ) then - return false - end - - local Server = cRoot:Get():GetServer() - Server:SendMessage( cChatColor.Red .. KilledPlayer:GetName() .. " died" ) - else - local KilledPlayer = tolua.cast( Killed, "cPlayer") - if( not KilledPlayer:IsA("cPlayer") or KilledPlayer == nil ) then - return false - end - local KillerPlayer = tolua.cast( Killer, "cPlayer") - if( not KillerPlayer:IsA("cPlayer") or KillerPlayer == nil ) then - return false - end - - local Server = cRoot:Get():GetServer() - Server:SendMessage( cChatColor.Red .. KilledPlayer:GetName() .. " was killed by " .. KillerPlayer:GetName() .. "!" ) - end - return false -end \ No newline at end of file diff --git a/Plugins/NewTest/onlogin.lua b/Plugins/NewTest/onlogin.lua deleted file mode 100644 index a706f8024..000000000 --- a/Plugins/NewTest/onlogin.lua +++ /dev/null @@ -1,20 +0,0 @@ -function OnLogin( PacketData ) - if( PacketData.m_Username ~= "" ) then - if( BannedPlayersIni:GetValueB("Banned", PacketData.m_Username, false) == true ) then - local Server = cRoot:Get():GetServer() - Server:SendMessage( PacketData.m_Username .. " tried to join, but is banned!" ) - LOGINFO( PacketData.m_Username .. " tried to join, but is banned!") - return true -- Player is banned, return true to deny access - end - if( WhiteListIni:GetValueB("WhiteListSettings", "WhiteListOn", false ) == true ) then - if( WhiteListIni:GetValueB("WhiteList", PacketData.m_Username, false ) == false ) then -- not on whitelist - local Server = cRoot:Get():GetServer() - Server:SendMessage( PacketData.m_Username .. " tried to join, but is not on the whitelist." ) - LOGINFO( PacketData.m_Username .. " tried to join, but is not on the whitelist." ) - return true -- Deny access to the server - end - end - end - - return false -end \ No newline at end of file diff --git a/Plugins/NewTest/onplayerjoin.lua b/Plugins/NewTest/onplayerjoin.lua deleted file mode 100644 index e8263f608..000000000 --- a/Plugins/NewTest/onplayerjoin.lua +++ /dev/null @@ -1,4 +0,0 @@ -function OnPlayerJoin( Player ) - ShowMOTDTo( Player ) - return false -end \ No newline at end of file diff --git a/Plugins/NewTest/playerlist.lua b/Plugins/NewTest/playerlist.lua deleted file mode 100644 index c120f068f..000000000 --- a/Plugins/NewTest/playerlist.lua +++ /dev/null @@ -1,16 +0,0 @@ -function HandlePlayerListCommand( Split, Player ) - local World = Player:GetWorld() - local PlayerList = World:GetAllPlayers() - - local Message = cChatColor.Green .. "Connected players: (".. cChatColor.White.. #PlayerList .. cChatColor.Green .. ")" - Player:SendMessage( Message ) - - local PlayerTable = {} - for i, TempPlayer in ipairs( PlayerList ) do - local PlayerName = TempPlayer:GetName() - table.insert(PlayerTable, PlayerName ) - end - - Player:SendMessage( table.concat(PlayerTable, " ") ) - return true -end \ No newline at end of file diff --git a/Plugins/NewTest/pluginlist.lua b/Plugins/NewTest/pluginlist.lua deleted file mode 100644 index 6cb767868..000000000 --- a/Plugins/NewTest/pluginlist.lua +++ /dev/null @@ -1,13 +0,0 @@ -function HandlePluginListCommand( Split, Player ) - local PluginManager = cRoot:Get():GetPluginManager() - local PluginList = PluginManager:GetAllPlugins() - - local PluginTable = {} - for i, Plugin in ipairs( PluginList ) do - table.insert(PluginTable, Plugin:GetName() ) - end - - Player:SendMessage( cChatColor.Green .. "Loaded plugins:" ) - Player:SendMessage( cChatColor.Gold .. table.concat(PluginTable, cChatColor.Gold.." ") ) - return true -end \ No newline at end of file diff --git a/Plugins/NewTest/reload.lua b/Plugins/NewTest/reload.lua deleted file mode 100644 index e2b338ba1..000000000 --- a/Plugins/NewTest/reload.lua +++ /dev/null @@ -1,6 +0,0 @@ -function HandleReloadCommand( Split, Player ) - Server = cRoot:Get():GetServer() - Server:SendMessage( cChatColor.Green .. "Reloading all plugins." ) - cRoot:Get():GetPluginManager():ReloadPlugins() - return true -end \ No newline at end of file diff --git a/Plugins/NewTest/spawn.lua b/Plugins/NewTest/spawn.lua deleted file mode 100644 index 73034d9cf..000000000 --- a/Plugins/NewTest/spawn.lua +++ /dev/null @@ -1,6 +0,0 @@ -function HandleSpawnCommand( Split, Player ) - World = Player:GetWorld() - Player:TeleportTo( World:GetSpawnX(), World:GetSpawnY(), World:GetSpawnZ() ) - LOGINFO( Player:GetName() .. " returned to spawn." ) - return true -end \ No newline at end of file diff --git a/Plugins/NewTest/teleport.lua b/Plugins/NewTest/teleport.lua deleted file mode 100644 index 9fffec9a2..000000000 --- a/Plugins/NewTest/teleport.lua +++ /dev/null @@ -1,18 +0,0 @@ -function HandleTPCommand( Split, Player ) - if( #Split ~= 2 ) then - Player:SendMessage( cChatColor.Green .. "Usage: /tp [PlayerName]" ) - return true - end - local World = Player:GetWorld() - local OtherPlayer = World:GetPlayer( Split[2] ) - if( OtherPlayer == nil ) then - Player:SendMessage( cChatColor.Green .. "Can't find player " .. Split[2] ) - elseif( OtherPlayer == Player ) then - Player:SendMessage( cChatColor.Green .. "Already there :)" ) - else - Player:TeleportTo( OtherPlayer ) - Player:SendMessage( cChatColor.Green .. "You teleported to "..OtherPlayer:GetName().."!" ) - OtherPlayer:SendMessage( cChatColor.Green .. Player:GetName().." teleported to you!" ) - end - return true -end \ No newline at end of file diff --git a/Plugins/NewTest/time.lua b/Plugins/NewTest/time.lua deleted file mode 100644 index 425d69e6a..000000000 --- a/Plugins/NewTest/time.lua +++ /dev/null @@ -1,18 +0,0 @@ -function HandleTimeCommand( Split, Player ) - if( #Split ~= 2 ) then - Player:SendMessage( cChatColor.Green .. "Usage: /time [Day/Night]" ) - return true; - end - - local Server = cRoot:Get():GetServer() - if( string.upper( Split[2] ) == "DAY") then - Player:GetWorld():SetWorldTime( 0 ) - Server:SendMessage( cChatColor.Green .. Player:GetName() .. " set the time to Day.") - elseif( string.upper( Split[2] ) == "NIGHT") then - Player:GetWorld():SetWorldTime( 12000 + 1000 ) - Server:SendMessage( cChatColor.Green .. Player:GetName() .. " set the time to Night.") - else - Player:SendMessage( cChatColor.Green .. "Usage: /time [Day/Night]" ) - end - return true -end \ No newline at end of file diff --git a/Plugins/NewTest/top.lua b/Plugins/NewTest/top.lua deleted file mode 100644 index 0f7a8f95f..000000000 --- a/Plugins/NewTest/top.lua +++ /dev/null @@ -1,11 +0,0 @@ -function HandleTopCommand( Split, Player ) - local World = Player:GetWorld() - - local PlayerPos = Player:GetPosition() - local Height = World:GetHeight( math.floor(PlayerPos.x), math.floor(PlayerPos.z) ) - - Player:TeleportTo( PlayerPos.x, Height+1, PlayerPos.z ) - Player:SendMessage("Teleported to the top block") - - return true -end \ No newline at end of file diff --git a/Plugins/NewTest/unban.lua b/Plugins/NewTest/unban.lua deleted file mode 100644 index 9defbe323..000000000 --- a/Plugins/NewTest/unban.lua +++ /dev/null @@ -1,20 +0,0 @@ -function HandleUnbanCommand( Split, Player ) - if( #Split < 2 ) then - Player:SendMessage( cChatColor.Green .. "Usage: /unban [Player]" ) - return true - end - - if( BannedPlayersIni:GetValueB("Banned", Split[2], false) == false ) then - Player:SendMessage( cChatColor.Green .. Split[2] .. " is not banned!" ) - return true - end - - BannedPlayersIni:SetValueB("Banned", Split[2], false, false) - BannedPlayersIni:WriteFile() - - local Server = cRoot:Get():GetServer() - LOGINFO( Player:GetName() .. " is unbanning " .. Split[2] ) - Server:SendMessage( "Unbanning " .. Split[2] ) - - return true -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,48 +8262,39 @@ public: } else { 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); @@ -8105,6 +8304,49 @@ public: } 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)) { + 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)) { @@ -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 -- cgit v1.2.3