From 7e010e7f8fc3983c3bd85fe17da27e06bdb4c7d9 Mon Sep 17 00:00:00 2001 From: faketruth Date: Mon, 3 Oct 2011 19:39:53 +0000 Subject: Setting files Plugins git-svn-id: http://mc-server.googlecode.com/svn/trunk@5 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- Plugins/ChatLog.lua | 41 +++ Plugins/Core.lua | 663 ++++++++++++++++++++++++++++++++++++++++++++++++ Plugins/Fire.lua | 149 +++++++++++ Plugins/MagicCarpet.lua | 169 ++++++++++++ 4 files changed, 1022 insertions(+) create mode 100644 Plugins/ChatLog.lua create mode 100644 Plugins/Core.lua create mode 100644 Plugins/Fire.lua create mode 100644 Plugins/MagicCarpet.lua (limited to 'Plugins') diff --git a/Plugins/ChatLog.lua b/Plugins/ChatLog.lua new file mode 100644 index 000000000..9f86a7086 --- /dev/null +++ b/Plugins/ChatLog.lua @@ -0,0 +1,41 @@ +local ChatLogPlugin = {} +ChatLogPlugin.__index = ChatLogPlugin + +function ChatLogPlugin:new() + local t = {} + setmetatable(t, ChatLogPlugin) + local w = Lua__cPlugin:new() + tolua.setpeer(w, t) + w:tolua__set_instance(w) + return w +end + +function ChatLogPlugin:OnDisable() + Log( self:GetName() .. " v." .. self:GetVersion() .. " is shutting down..." ) +end + +function ChatLogPlugin:Initialize() + self:SetName( "ChatLog" ) + self:SetVersion( 1 ) + + PluginManager = cRoot:Get():GetPluginManager() + PluginManager:AddHook( self, cPluginManager.E_PLUGIN_CHAT ) + + self.Logger = cMCLogger:new_local("ChatLog"..GetTime()..".txt") + self.Logger:LogSimple("--- ChatLog started ---", 1); + + Log( "Initialized " .. self:GetName() .. " v." .. self:GetVersion() ) + return true +end + +function ChatLogPlugin:OnChat( Message, Player ) + Server = cRoot:Get():GetServer() + + -- Lets get loggin' + self.Logger:LogSimple(Player:GetName() .. ": " .. Message, 1); + + return false +end + +Plugin = ChatLogPlugin:new() +cRoot:Get():GetPluginManager():AddPlugin( Plugin ) diff --git a/Plugins/Core.lua b/Plugins/Core.lua new file mode 100644 index 000000000..e124a9261 --- /dev/null +++ b/Plugins/Core.lua @@ -0,0 +1,663 @@ +---- Some settings ----- +SHOW_PLUGIN_NAMES = true -- If true, plugin name will be shown before commands + -- This is overwritten in the Initialize() function +------------------------ + +local BannedPlayersIni = {} +local WhiteListIni = {} + +CorePlugin = {} +CorePlugin.__index = CorePlugin + +function CorePlugin:new() + local t = {} + setmetatable(t, CorePlugin) + local w = Lua__cPlugin:new() + tolua.setpeer(w, t) + w:tolua__set_instance(w) + return w +end + +function CorePlugin:OnDisable() + LOG( self:GetName() .. " v." .. self:GetVersion() .. " is shutting down..." ) +end + +function CorePlugin:Initialize() + self:SetName( "Core" ) + self:SetVersion( 6 ) + + PluginManager = cRoot:Get():GetPluginManager() + PluginManager:AddHook( self, cPluginManager.E_PLUGIN_PLAYER_JOIN ) + PluginManager:AddHook( self, cPluginManager.E_PLUGIN_LOGIN ) + PluginManager:AddHook( self, cPluginManager.E_PLUGIN_BLOCK_PLACE ) + PluginManager:AddHook( self, cPluginManager.E_PLUGIN_KILLED ) + + self:AddCommand("/help", " - [Page] Show this message", "core.help") + self:AddCommand("/pluginlist", " - Show list of plugins", "core.pluginlist") + self:AddCommand("/tp", " - [Player] - Teleport yourself to a player", "core.teleport") + self:AddCommand("/item", " - [ItemID/Name] - Spawn an item for yourself", "core.item") + self:AddCommand("/list", " - Shows list of connected players", "core.playerlist") + self:AddCommand("/motd", " - Show message of the day", "core.motd") + self:AddCommand("/reload", " - Reload all plugins", "core.reload") + self:AddCommand("/time", " - [Day/Night] - Sets the time of day", "core.time") + self:AddCommand("/spawn", " - Return to the spawn", "core.spawn") + self:AddCommand("/kick", " - [Player] - Kick a player", "core.kick") + self:AddCommand("/ban", " - [Player] - Ban a player", "core.ban") + self:AddCommand("/unban", " - [Player] - Unban a player", "core.unban") + self:AddCommand("/top", " - Teleport yourself to the top most block", "core.top") + + self:BindCommand( "/help", "core.help", HandleHelpCommand ) + self:BindCommand( "/pluginlist","core.pluginlist", HandlePluginListCommand ) + self:BindCommand( "/tp", "core.teleport", HandleTPCommand ) + self:BindCommand( "/item", "core.item", HandleItemCommand ) + self:BindCommand( "/i", "core.item", HandleItemCommand ) + self:BindCommand( "/list", "core.playerlist", HandlePlayerListCommand ) + self:BindCommand( "/who", "core.playerlist", HandlePlayerListCommand ) + self:BindCommand( "/playerlist","core.playerlist", HandlePlayerListCommand ) + self:BindCommand( "/motd", "core.motd", HandleMOTDCommand ) + self:BindCommand( "/reload", "core.reload", HandleReloadCommand ) + self:BindCommand( "/time", "core.time", HandleTimeCommand ) + self:BindCommand( "/spawn", "core.spawn", HandleSpawnCommand ) + self:BindCommand( "/home", "core.spawn", HandleSpawnCommand ) + self:BindCommand( "/kick", "core.kick", HandleKickCommand ) + self:BindCommand( "/ban", "core.ban", HandleBanCommand ) + self:BindCommand( "/unban", "core.unban", HandleUnbanCommand ) + self:BindCommand( "/top", "core.top", HandleTopCommand ) + + local IniFile = cIniFile("settings.ini") + if ( IniFile:ReadFile() == true ) then + SHOW_PLUGIN_NAMES = IniFile:GetValueB("HelpPlugin", "ShowPluginNames", true ) + end + + itemsINI = cIniFile("items.ini") + if ( itemsINI:ReadFile() == true ) then + LOGINFO("Core: loaded " .. itemsINI:GetNumValues('Items') .. " item names.") + 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 " .. self:GetName() .. " v." .. self:GetVersion() ) + return true +end + +function HandleTopCommand( Split, Player ) + local World = cRoot:Get():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 + +function HandleKickCommand( Split, Player ) + if( #Split < 2 ) then + Player:SendMessage( cChatColor.Green .. "Usage: /kick [Player] " ) + return true + end + + local World = cRoot:Get():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 + +function HandleBanCommand( Split, Player ) + if( #Split < 2 ) then + Player:SendMessage( cChatColor.Green .. "Usage: /ban [Player] " ) + return true + end + + local World = cRoot:Get():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 + +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 + +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 + +function HandleSpawnCommand( Split, Player ) + World = cRoot:Get():GetWorld() + Player:TeleportTo( World:GetSpawnX(), World:GetSpawnY(), World:GetSpawnZ() ) + LOGINFO( Player:GetName() .. " returned to spawn." ) + return true +end + +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 + cRoot:Get():GetWorld():SetWorldTime( 0 ) + Server:SendMessage( cChatColor.Green .. Player:GetName() .. " set the time to Day.") + elseif( string.upper( Split[2] ) == "NIGHT") then + cRoot:Get():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 + +function HandleReloadCommand( Split, Player ) + Server = cRoot:Get():GetServer() + Server:SendMessage( cChatColor.Green .. "Reloading all plugins." ) + cRoot:Get():GetPluginManager():ReloadPlugins() + return true +end + +function HandlePlayerListCommand( Split, Player ) + local World = cRoot:Get():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 + +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 + +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 + +function HandleItemCommand( Split, Player ) + if( #Split ~= 2 and #Split ~=3 ) then + Player:SendMessage( cChatColor.Green .. "Usage: /item [ItemID/Name] " ) + return true + end + + foundItem = false + + ItemID = tonumber( Split[2] ) + if( ItemID == nil or not isValidItem( ItemID ) ) then + -- nothing + else + foundItem = true + end + + if not foundItem then + if ( HAVE_ITEM_NAMES == true ) then + itemValue = itemsINI:GetValueI('Items', ''..Split[2]..'', 0) + if itemValue ~= 0 then + ItemID = itemValue + if( ItemID == nil or not isValidItem( tonumber(itemValue) ) ) then + -- nothing + else + foundItem = true + end + end + end + end + + if not foundItem then + Player:SendMessage( cChatColor.Green .. "Invalid Item ID / Name !" ) + return true + end + + local Amount = 1 + if( #Split == 3 ) then + Amount = tonumber( Split[3] ) + if( Amount == nil or Amount < 1 or Amount > 512 ) then + Player:SendMessage( cChatColor.Green .. "Invalid Amount !" ) + return true + end + end + + local NewItem = cItem( ItemID, Amount ) + if( Player:GetInventory():AddItem( NewItem ) == true ) then + Player:SendMessage( cChatColor.Green .. "There you go !" ) + LOG("Gave " .. Player:GetName() .. " " .. Amount .. " times " .. ItemID ) + else + Player:SendMessage( cChatColor.Green .. "Not enough space in inventory !" ) + end + return true +end + +function HandleTPCommand( Split, Player ) + if( #Split ~= 2 ) then + Player:SendMessage( cChatColor.Green .. "Usage: /tp [PlayerName]" ) + return true + end + local World = cRoot:Get():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 + +function CorePlugin:OnPlayerJoin( Player ) + ShowMOTDTo( Player ) + return false +end + +function CorePlugin: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 = cRoot:Get():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 + +function CorePlugin: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 + +function CorePlugin: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 + +Plugin = CorePlugin:new() +cRoot:Get():GetPluginManager():AddPlugin( Plugin ) + +------------------------------------------------ +-- Now some webadmin stuffs! -- +------------------------------------------------ +local PlayerListWeb = {} +PlayerListWeb.__index = PlayerListWeb + +function PlayerListWeb:new() + local t = {} + setmetatable(t, PlayerListWeb) + local w = Lua__cWebPlugin:new() + tolua.setpeer(w, t) + w:tolua__set_instance(w) + return w +end + +function PlayerListWeb:HandleRequest( Request ) + local World = cRoot:Get():GetWorld() + local Content = "" + Content = Content .. "
Connected Players: " .. World:GetNumPlayers() .. "
" + Content = Content .. "
    " + + local PlayerList = World:GetAllPlayers() + for i, Player in ipairs( PlayerList ) do + Content = Content .. "
  • " .. Player:GetName() + end + + Content = Content .. "
" + return Content +end + +WebPlugin = PlayerListWeb:new() +WebPlugin:SetName("PlayerList") + +------------------------------------------------ +-- Reload web plugin -- +------------------------------------------------ +local ReloadWeb = {} +ReloadWeb.__index = ReloadWeb + +function ReloadWeb:new() + local t = {} + setmetatable(t, ReloadWeb) + local w = Lua__cWebPlugin:new() + tolua.setpeer(w, t) + w:tolua__set_instance(w) + return w +end + +function ReloadWeb:HandleRequest( Request ) + local World = cRoot:Get():GetWorld() + local Content = "" + + if( Request.Params:get("reload") ~= "" ) then + Content = Content .. "" + Content = Content .. "
Reloading plugins...
" + cRoot:Get():GetPluginManager():ReloadPlugins() + else + Content = Content .. "
Click the reload button to reload all plugins!
" + Content = Content .. "
" + Content = Content .. "" + Content = Content .. "
" + end + return Content +end + +WebPlugin = ReloadWeb:new() +WebPlugin:SetName("Reload") + +------------------------------------------------ +-- Whitelist web plugin -- +------------------------------------------------ +local WhiteListWeb = {} +WhiteListWeb.__index = WhiteListWeb + +function WhiteListWeb:new() + local t = {} + setmetatable(t, WhiteListWeb) + local w = Lua__cWebPlugin:new() + tolua.setpeer(w, t) + w:tolua__set_instance(w) + return w +end + +local function HTMLDeleteButton( name ) + return "
" +end + +function WhiteListWeb:HandleRequest( Request ) + local World = cRoot:Get():GetWorld() + + 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" + end + + + local Content = "" + Content = Content .. "

Whitelisted players

" + Content = Content .. "" + local KeyNum = WhiteListIni:FindKey("WhiteList") + local NumValues = WhiteListIni:GetNumValues(KeyNum) + for Num = 0, NumValues-1 do + if( WhiteListIni:GetValue(KeyNum, Num, "0") == "1" ) then + local PlayerName = WhiteListIni:GetValueName(KeyNum, Num ) + Content = Content .. "" + end + end + Content = Content .. "
" .. PlayerName .. "" .. HTMLDeleteButton( PlayerName ) .. "
" + Content = Content .. "

Add player to whitelist

" + Content = Content .. "
" + Content = Content .. "" + Content = Content .. "
" + Content = Content .. "
" + Content = Content .. "" + Content = Content .. "
" + Content = Content .. "
"..UpdateMessage + return Content +end + +WebPlugin = WhiteListWeb:new() +WebPlugin:SetName("WhiteList") \ No newline at end of file diff --git a/Plugins/Fire.lua b/Plugins/Fire.lua new file mode 100644 index 000000000..88bff84da --- /dev/null +++ b/Plugins/Fire.lua @@ -0,0 +1,149 @@ +local FirePlugin = {} +FirePlugin.__index = FirePlugin + +FireBlocks = {} + +function FirePlugin:new() + local t = {} + setmetatable(t, FirePlugin) + local w = Lua__cPlugin:new() + tolua.setpeer(w, t) + w:tolua__set_instance(w) + return w +end + +function IsForeverBurnable( BlockID ) + if( BlockID == E_BLOCK_BLOODSTONE ) then + return true + end + return false +end + +function IsBurnable( BlockID ) + if( BlockID == E_BLOCK_LEAVES or BlockID == E_BLOCK_LOG ) then + return true + end + + return false +end + +function FindBurnableAround( X, Y, Z ) + World = cRoot:Get():GetWorld() + + ListBurnables = {} + if( IsBurnable( World:GetBlock(X-1, Y, Z) ) ) then + table.insert( ListBurnables, { ["x"] = X-1, ["y"] = Y, ["z"] = Z } ) + end + if( IsBurnable( World:GetBlock(X+1, Y, Z) ) ) then + table.insert( ListBurnables, { ["x"] = X+1, ["y"] = Y, ["z"] = Z } ) + end + if( IsBurnable( World:GetBlock(X, Y-1, Z) ) ) then + table.insert( ListBurnables, { ["x"] = X, ["y"] = Y-1, ["z"] = Z } ) + end + if( IsBurnable( World:GetBlock(X, Y+1, Z) ) ) then + table.insert( ListBurnables, { ["x"] = X, ["y"] = Y+1, ["z"] = Z } ) + end + if( IsBurnable( World:GetBlock(X, Y, Z-1) ) ) then + table.insert( ListBurnables, { ["x"] = X, ["y"] = Y, ["z"] = Z-1 } ) + end + if( IsBurnable( World:GetBlock(X, Y, Z+1) ) ) then + table.insert( ListBurnables, { ["x"] = X, ["y"] = Y, ["z"] = Z+1 } ) + end + + return ListBurnables +end + +function FirePlugin:OnDisable() + Log( self:GetName() .. " v." .. self:GetVersion() .. " is shutting down..." ) +end + +function FirePlugin:Initialize() + self:SetName( "Fire" ) + self:SetVersion( 1 ) + + PluginManager = cRoot:Get():GetPluginManager() + PluginManager:AddHook( self, cPluginManager.E_PLUGIN_TICK ) + PluginManager:AddHook( self, cPluginManager.E_PLUGIN_BLOCK_PLACE ) + PluginManager:AddHook( self, cPluginManager.E_PLUGIN_BLOCK_DIG ) + + Log( "Initialized " .. self:GetName() .. " v." .. self:GetVersion() ) + return true +end + +function FirePlugin:OnBlockPlace( PacketData, Player ) + + if( PacketData.m_ItemType == E_BLOCK_FIRE or PacketData.m_ItemType == E_ITEM_FLINT_AND_STEEL ) then + if( PacketData.m_Direction > -1 ) then + local X = PacketData.m_PosX + local Y = PacketData.m_PosY + local Z = PacketData.m_PosZ + + X, Y, Z = AddDirection( X, Y, Z, PacketData.m_Direction ) + + --Since flint and steel doesn't do anything on the server side yet + if( PacketData.m_ItemType == E_ITEM_FLINT_AND_STEEL ) then + local World = cRoot:Get():GetWorld() + World:SetBlock( X, Y, Z, E_BLOCK_FIRE, 0 ) + end + + if( not IsForeverBurnable( World:GetBlock( X, Y-1, Z ) ) ) then + table.insert( FireBlocks, { ["x"] = X, ["y"] = Y, ["z"] = Z } ) + end + end + end + + return false -- dont forbid placing the fire +end + +-- To put out fires! :D +function FirePlugin:OnBlockDig( PacketData, Player ) + if( PacketData.m_Direction < 0 ) then + return false + end + + local X = PacketData.m_PosX + local Y = PacketData.m_PosY + local Z = PacketData.m_PosZ + + X, Y, Z = AddDirection( X, Y, Z, PacketData.m_Direction ) + + local World = cRoot:Get():GetWorld() + if( World:GetBlock( X, Y, Z ) == E_BLOCK_FIRE ) then + World:SetBlock( X, Y, Z, E_BLOCK_AIR, 0 ) + end + + return false +end + +NumTicks = 0 +function FirePlugin:Tick( DeltaTime ) + if( NumTicks < 10 ) then -- Only spread every 10 ticks, to make sure it doesnt happen too fast + NumTicks = NumTicks + 1 + return + end + NumTicks = 0 + + World = cRoot:Get():GetWorld() + + NewTable = {} + for key,val in pairs(FireBlocks) do + X = val["x"] + Y = val["y"] + Z = val["z"] + Burnables = FindBurnableAround(X, Y, Z) + if( math.random(10) > 5 ) then + table.insert( NewTable, val ) + elseif( #Burnables > 0 ) then + ToBurn = Burnables[ math.random( #Burnables ) ] + World:SetBlock( ToBurn["x"], ToBurn["y"], ToBurn["z"], E_BLOCK_FIRE, 0 ) + table.insert( NewTable, ToBurn ) + table.insert( NewTable, val ) + else + World:SetBlock( X, Y, Z, 0, 0 ) + end + end + FireBlocks = NewTable +end + +Plugin = FirePlugin:new() +cRoot:Get():GetPluginManager():AddPlugin( Plugin ) diff --git a/Plugins/MagicCarpet.lua b/Plugins/MagicCarpet.lua new file mode 100644 index 000000000..69ccd0d5c --- /dev/null +++ b/Plugins/MagicCarpet.lua @@ -0,0 +1,169 @@ +-- Location object +cLocation = {} +function cLocation:new( x, y, z ) + local object = { x = x, y = y, z = z } + setmetatable(object, { __index = cLocation }) + return object +end + +-- Offsets +cFibers = { } +function cFibers:new() + local object = { + cLocation:new( 2, -1, 2 ), + cLocation:new( 2, -1, 1 ), + cLocation:new( 2, -1, 0 ), + cLocation:new( 2, -1, -1 ), + cLocation:new( 2, -1, -2 ), + cLocation:new( 1, -1, 2 ), + cLocation:new( 1, -1, 1 ), + cLocation:new( 1, -1, 0 ), + cLocation:new( 1, -1, -1 ), + cLocation:new( 1, -1, -2 ), + cLocation:new( 0, -1, 2 ), + cLocation:new( 0, -1, 1 ), + cLocation:new( 0, -1, 0 ), + cLocation:new( 0, -1, -1 ), + cLocation:new( 0, -1, -2 ), + cLocation:new( -1, -1, 2 ), + cLocation:new( -1, -1, 1 ), + cLocation:new( -1, -1, 0 ), + cLocation:new( -1, -1, -1 ), + cLocation:new( -1, -1, -2 ), + cLocation:new( -2, -1, 2 ), + cLocation:new( -2, -1, 1 ), + cLocation:new( -2, -1, 0 ), + cLocation:new( -2, -1, -1 ), + cLocation:new( -2, -1, -2 ), + imadeit = false, + } + setmetatable(object, { __index = cFibers }) + return object; +end + +-- Carpet object +cCarpet = {} +function cCarpet:new() + local object = { Location = cLocation:new(0,0,0), + Fibers = cFibers:new(), + } + setmetatable(object, { __index = cCarpet }) + return object +end + +function cCarpet:remove() + local World = cRoot:Get():GetWorld() + for i, fib in ipairs( self.Fibers ) do + local x = self.Location.x + fib.x + local y = self.Location.y + fib.y + local z = self.Location.z + fib.z + local BlockID = World:GetBlock( x, y, z ) + if( fib.imadeit == true and BlockID == E_BLOCK_GLASS ) then + World:SetBlock( x, y, z, 0, 0 ) + fib.imadeit = false + end + end +end + +function cCarpet:draw() + local World = cRoot:Get():GetWorld() + for i, fib in ipairs( self.Fibers ) do + local x = self.Location.x + fib.x + local y = self.Location.y + fib.y + local z = self.Location.z + fib.z + local BlockID = World:GetBlock( x, y, z ) + if( BlockID == 0 ) then + fib.imadeit = true + World:SetBlock( x, y, z, E_BLOCK_GLASS, 0 ) + else + fib.imadeit = false + end + end +end + +function cCarpet:moveTo( NewPos ) + local x = math.floor( NewPos.x ) + local y = math.floor( NewPos.y ) + local z = math.floor( NewPos.z ) + if( self.Location.x ~= x or self.Location.y ~= y or self.Location.z ~= z ) then + self:remove() + self.Location = cLocation:new( x, y, z ) + self:draw() + end +end + + +MagicCarpetPlugin = {} +MagicCarpetPlugin.__index = MagicCarpetPlugin + +function MagicCarpetPlugin:new() + local t = {} + setmetatable(t, MagicCarpetPlugin) + local w = Lua__cPlugin:new() + tolua.setpeer(w, t) + w:tolua__set_instance(w) + return w +end + +function MagicCarpetPlugin:Initialize() + self:SetName( "MagicCarpet" ) + self:SetVersion( 1 ) + + PluginManager = cRoot:Get():GetPluginManager() + PluginManager:AddHook( self, cPluginManager.E_PLUGIN_PLAYER_MOVE) + PluginManager:AddHook( self, cPluginManager.E_PLUGIN_DISCONNECT) + + self:AddCommand("/mc", " - Spawns a magical carpet!", "magiccarpet") + self:BindCommand( "/mc", "magiccarpet", HandleCarpetCommand ) + + self.Carpets = {} + + Log( "Initialized " .. self:GetName() .. " v." .. self:GetVersion() ) + return true +end + +function MagicCarpetPlugin:OnDisable() + Log( self:GetName() .. " v." .. self:GetVersion() .. " is shutting down..." ) + for i, Carpet in pairs( self.Carpets ) do + Carpet:remove() + end +end + +function HandleCarpetCommand( Split, Player ) + Carpet = self.Carpets[ Player ] + if( Carpet == nil ) then + self.Carpets[ Player ] = cCarpet:new() + Player:SendMessage("You're on a magic carpet!" ) + else + Carpet:remove() + self.Carpets[ Player ] = nil + Player:SendMessage("The carpet vanished!" ) + end + + return true +end + +function MagicCarpetPlugin:OnDisconnect( Reason, Player ) + local Carpet = self.Carpets[ Player ] + if( Carpet ~= nil ) then + Carpet:remove() + end + self.Carpets[ Player ] = nil +end + +function MagicCarpetPlugin:OnPlayerMove( Player ) + local Carpet = self.Carpets[ Player ] + if( Carpet == nil ) then + return + end + + if( Player:GetPitch() == 90 ) then + Carpet:moveTo( cLocation:new( Player:GetPosX(), Player:GetPosY()-1, Player:GetPosZ() ) ) + else + Carpet:moveTo( cLocation:new( Player:GetPosX(), Player:GetPosY(), Player:GetPosZ() ) ) + end +end + +Plugin = MagicCarpetPlugin:new() +cRoot:Get():GetPluginManager():AddPlugin( Plugin ) + -- cgit v1.2.3