From 12906c026d414c752d3c0ba9481f425b24b29c67 Mon Sep 17 00:00:00 2001 From: faketruth Date: Mon, 20 Aug 2012 12:20:20 +0000 Subject: Moved files used by MCServer to a special MCServer folder git-svn-id: http://mc-server.googlecode.com/svn/trunk@763 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- MCServer/Plugins/ChatLog/plugin.lua | 17 +++ MCServer/Plugins/Core/ban.lua | 30 ++++ MCServer/Plugins/Core/coords.lua | 4 + MCServer/Plugins/Core/gamemode.lua | 10 ++ MCServer/Plugins/Core/gotoworld.lua | 15 ++ MCServer/Plugins/Core/help.lua | 54 +++++++ MCServer/Plugins/Core/item.lua | 65 ++++++++ MCServer/Plugins/Core/kick.lua | 27 ++++ MCServer/Plugins/Core/main.lua | 147 ++++++++++++++++++ MCServer/Plugins/Core/motd.lua | 10 ++ MCServer/Plugins/Core/onblockdig.lua | 10 ++ MCServer/Plugins/Core/onblockplace.lua | 63 ++++++++ MCServer/Plugins/Core/oncraftingnorecipe.lua | 214 +++++++++++++++++++++++++++ MCServer/Plugins/Core/onkilled.lua | 24 +++ MCServer/Plugins/Core/onlogin.lua | 20 +++ MCServer/Plugins/Core/onplayerjoin.lua | 4 + MCServer/Plugins/Core/playerlist.lua | 14 ++ MCServer/Plugins/Core/pluginlist.lua | 13 ++ MCServer/Plugins/Core/regeneratechunk.lua | 18 +++ MCServer/Plugins/Core/reload.lua | 6 + MCServer/Plugins/Core/spawn.lua | 6 + MCServer/Plugins/Core/stop.lua | 6 + MCServer/Plugins/Core/teleport.lua | 23 +++ MCServer/Plugins/Core/time.lua | 18 +++ MCServer/Plugins/Core/top.lua | 11 ++ MCServer/Plugins/Core/unban.lua | 20 +++ MCServer/Plugins/Core/viewdistance.lua | 10 ++ MCServer/Plugins/Core/web_manageplugins.lua | 93 ++++++++++++ MCServer/Plugins/Core/web_permissions.lua | 79 ++++++++++ MCServer/Plugins/Core/web_playerlist.lua | 36 +++++ MCServer/Plugins/Core/web_whitelist.lua | 79 ++++++++++ MCServer/Plugins/MagicCarpet/objects.lua | 97 ++++++++++++ MCServer/Plugins/MagicCarpet/plugin.lua | 65 ++++++++ MCServer/Plugins/SquirrelChatLog.nut | 13 ++ MCServer/Plugins/sTick/main.lua | 20 +++ MCServer/Plugins/sTick/onblockplace.lua | 18 +++ 36 files changed, 1359 insertions(+) create mode 100644 MCServer/Plugins/ChatLog/plugin.lua create mode 100644 MCServer/Plugins/Core/ban.lua create mode 100644 MCServer/Plugins/Core/coords.lua create mode 100644 MCServer/Plugins/Core/gamemode.lua create mode 100644 MCServer/Plugins/Core/gotoworld.lua create mode 100644 MCServer/Plugins/Core/help.lua create mode 100644 MCServer/Plugins/Core/item.lua create mode 100644 MCServer/Plugins/Core/kick.lua create mode 100644 MCServer/Plugins/Core/main.lua create mode 100644 MCServer/Plugins/Core/motd.lua create mode 100644 MCServer/Plugins/Core/onblockdig.lua create mode 100644 MCServer/Plugins/Core/onblockplace.lua create mode 100644 MCServer/Plugins/Core/oncraftingnorecipe.lua create mode 100644 MCServer/Plugins/Core/onkilled.lua create mode 100644 MCServer/Plugins/Core/onlogin.lua create mode 100644 MCServer/Plugins/Core/onplayerjoin.lua create mode 100644 MCServer/Plugins/Core/playerlist.lua create mode 100644 MCServer/Plugins/Core/pluginlist.lua create mode 100644 MCServer/Plugins/Core/regeneratechunk.lua create mode 100644 MCServer/Plugins/Core/reload.lua create mode 100644 MCServer/Plugins/Core/spawn.lua create mode 100644 MCServer/Plugins/Core/stop.lua create mode 100644 MCServer/Plugins/Core/teleport.lua create mode 100644 MCServer/Plugins/Core/time.lua create mode 100644 MCServer/Plugins/Core/top.lua create mode 100644 MCServer/Plugins/Core/unban.lua create mode 100644 MCServer/Plugins/Core/viewdistance.lua create mode 100644 MCServer/Plugins/Core/web_manageplugins.lua create mode 100644 MCServer/Plugins/Core/web_permissions.lua create mode 100644 MCServer/Plugins/Core/web_playerlist.lua create mode 100644 MCServer/Plugins/Core/web_whitelist.lua create mode 100644 MCServer/Plugins/MagicCarpet/objects.lua create mode 100644 MCServer/Plugins/MagicCarpet/plugin.lua create mode 100644 MCServer/Plugins/SquirrelChatLog.nut create mode 100644 MCServer/Plugins/sTick/main.lua create mode 100644 MCServer/Plugins/sTick/onblockplace.lua (limited to 'MCServer/Plugins') diff --git a/MCServer/Plugins/ChatLog/plugin.lua b/MCServer/Plugins/ChatLog/plugin.lua new file mode 100644 index 000000000..e18a8e642 --- /dev/null +++ b/MCServer/Plugins/ChatLog/plugin.lua @@ -0,0 +1,17 @@ +function Initialize( Plugin ) + Plugin:SetName( "ChatLog" ) + Plugin:SetVersion( 2 ) + + PluginManager = cRoot:Get():GetPluginManager() + PluginManager:AddHook( Plugin, cPluginManager.E_PLUGIN_CHAT ) + + LOG( "Initialized " .. Plugin:GetName() .. " v." .. Plugin:GetVersion() ) + return true +end + +function OnChat( Message, Player ) + -- Lets get loggin' + LOGINFO("[" .. Player:GetName() .. "]: " .. Message); + + return false +end \ No newline at end of file diff --git a/MCServer/Plugins/Core/ban.lua b/MCServer/Plugins/Core/ban.lua new file mode 100644 index 000000000..a6a662c3c --- /dev/null +++ b/MCServer/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/MCServer/Plugins/Core/coords.lua b/MCServer/Plugins/Core/coords.lua new file mode 100644 index 000000000..07cda1a92 --- /dev/null +++ b/MCServer/Plugins/Core/coords.lua @@ -0,0 +1,4 @@ +function HandleCoordsCommand( Split, Player ) + Player:SendMessage(cChatColor.Green .. string.format("[X:%0.2f] [Y:%0.2f] [Z:%0.2f]", Player:GetPosX(), Player:GetPosY(), Player:GetPosZ() ) ) + return true +end \ No newline at end of file diff --git a/MCServer/Plugins/Core/gamemode.lua b/MCServer/Plugins/Core/gamemode.lua new file mode 100644 index 000000000..1e73b46fd --- /dev/null +++ b/MCServer/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/MCServer/Plugins/Core/gotoworld.lua b/MCServer/Plugins/Core/gotoworld.lua new file mode 100644 index 000000000..d5113b667 --- /dev/null +++ b/MCServer/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/MCServer/Plugins/Core/help.lua b/MCServer/Plugins/Core/help.lua new file mode 100644 index 000000000..02ef25ebd --- /dev/null +++ b/MCServer/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/MCServer/Plugins/Core/item.lua b/MCServer/Plugins/Core/item.lua new file mode 100644 index 000000000..942fa8ce6 --- /dev/null +++ b/MCServer/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/MCServer/Plugins/Core/kick.lua b/MCServer/Plugins/Core/kick.lua new file mode 100644 index 000000000..ff4f8a705 --- /dev/null +++ b/MCServer/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/MCServer/Plugins/Core/main.lua b/MCServer/Plugins/Core/main.lua new file mode 100644 index 000000000..fead7638b --- /dev/null +++ b/MCServer/Plugins/Core/main.lua @@ -0,0 +1,147 @@ +---- 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.HOOK_PLAYER_JOIN) + PluginManager:AddHook(Plugin, cPluginManager.HOOK_LOGIN) + PluginManager:AddHook(Plugin, cPluginManager.HOOK_BLOCK_PLACE) + PluginManager:AddHook(Plugin, cPluginManager.HOOK_BLOCK_DIG) + PluginManager:AddHook(Plugin, cPluginManager.HOOK_KILLED) + PluginManager:AddHook(Plugin, cPluginManager.HOOK_CRAFTING_NO_RECIPE) + + 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("/stop", " - Stops the server", "core.stop") + 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:AddCommand("/coords", " - Show your current server coordinates", "core.coords") + Plugin:AddCommand("/viewdistance", " - [".. cClientHandle.MIN_VIEW_DISTANCE .."-".. cClientHandle.MAX_VIEW_DISTANCE .."] - Change your view distance", "core.viewdistance") + Plugin:AddCommand("/regeneratechunk", " - - Regenerates a chunk", "core.regeneratechunk") + + 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( "/stop", "core.stop", HandleStopCommand ) + 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 ) + Plugin:BindCommand( "/coords", "core.coords", HandleCoordsCommand ) + Plugin:BindCommand( "/viewdistance", "core.viewdistance", HandleViewDistanceCommand ) + Plugin:BindCommand( "/regeneratechunk", "core.regeneratechunk", HandleRegenerateChunkCommand ) + + 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 + if( #ItemData > 0 ) then + 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( "Playerlist", HandleRequest_PlayerList ) + WebPlugin:AddTab( "Whitelist", HandleRequest_WhiteList ) + WebPlugin:AddTab( "Permissions", HandleRequest_Permissions ) + WebPlugin:AddTab( "Manage Plugins", HandleRequest_ManagePlugins ) + WebPlugin:AddTab( "Ini Editor", HandleRequest_IniEditor ) + + LOG( "Initialized " .. Plugin:GetName() .. " v." .. Plugin:GetVersion() ) + return true +end \ No newline at end of file diff --git a/MCServer/Plugins/Core/motd.lua b/MCServer/Plugins/Core/motd.lua new file mode 100644 index 000000000..49cdcecad --- /dev/null +++ b/MCServer/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/MCServer/Plugins/Core/onblockdig.lua b/MCServer/Plugins/Core/onblockdig.lua new file mode 100644 index 000000000..65e48576c --- /dev/null +++ b/MCServer/Plugins/Core/onblockdig.lua @@ -0,0 +1,10 @@ +function OnBlockDig(Player, BlockX, BlockY, BlockZ, BlockFace, Status, OldBlockType, OldBlockMeta) + -- dont check if the direction is in the air + if (BlockFace ~= -1) then + + if (Player:HasPermission("core.build") == false) then + return true + end + end + return false +end \ No newline at end of file diff --git a/MCServer/Plugins/Core/onblockplace.lua b/MCServer/Plugins/Core/onblockplace.lua new file mode 100644 index 000000000..9032f8207 --- /dev/null +++ b/MCServer/Plugins/Core/onblockplace.lua @@ -0,0 +1,63 @@ +function OnBlockPlace(Player, BlockX, BlockY, BlockZ, BlockFace, HeldItem) + + -- dont check if the direction is in the air + if (BlockFace == -1) then + return false + end + + if( Player:HasPermission("core.build") == false ) then + return true + end + + -- TODO: If the placed block is not a block (torch etc.), allow it without checking for collisions + + local X = BlockX + local Y = BlockY + local Z = BlockZ + X, Y, Z = AddDirection(X, Y, Z, BlockFace) + if (Y >= 256 or Y < 0) then + return true + end + + local CheckCollision = function(Player) + -- 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) + + -- player height is 2 blocks, so we check the position and then offset it up one + -- so they can't place a block in anyone's face + + local collision = false + if ((BlockFace == BLOCK_FACE_TOP) and (PlayerY == BlockY - 2) and (PlayerX == BlockX) and (PlayerZ == BlockZ)) then + collision = true + end + + if ((BlockFace == BLOCK_FACE_BOTTOM) and (PlayerY == BlockY + 1) and (PlayerX == BlockX) and (PlayerZ == BlockZ)) then + collision = true + end + + if ((BlockFace == BLOCK_FACE_NORTH) and (PlayerX == BlockX) and (PlayerZ == BlockZ - 1)) then + if ((PlayerY == BlockY) or (PlayerY + 1 == BlockY)) then collision = true end + end + + if ((BlockFace == BLOCK_FACE_SOUTH) and (PlayerX == BlockX) and (PlayerZ == BlockZ + 1)) then + if ((PlayerY == BlockY) or (PlayerY + 1 == BlockY)) then collision = true end + end + + if ((BlockFace == BLOCK_FACE_WEST) and (PlayerX == BlockX - 1) and (PlayerZ == BlockZ)) then + if ((PlayerY == BlockY) or (PlayerY + 1 == BlockY)) then collision = true end + end + + if ((BlockFace == BLOCK_FACE_EAST) and (PlayerX == BlockX + 1) and (PlayerZ == BlockZ)) then + if ((PlayerY == BlockY) or (PlayerY + 1 == BlockY)) then collision = true end + end + + return collision + end + + if (Player:GetWorld():ForEachPlayer(CheckCollision) == false) then + return true + end + return false +end \ No newline at end of file diff --git a/MCServer/Plugins/Core/oncraftingnorecipe.lua b/MCServer/Plugins/Core/oncraftingnorecipe.lua new file mode 100644 index 000000000..2006e410f --- /dev/null +++ b/MCServer/Plugins/Core/oncraftingnorecipe.lua @@ -0,0 +1,214 @@ + +-- Implements item-repair using the HOOK_CRAFTING_NO_RECIPE hook +-- Based on Fixies plugin v2 by Taugeshtu + + +-- how much "extra" points are healed per a repair operation (fraction of full health) +BONUS = 0.1 + + + + + +function OnCraftingNoRecipe(Player, Grid, Recipe) + local _do_fix = false + local Items = {} + for x = 0, Grid:GetWidth() - 1 do + for y = 0, Grid:GetHeight() - 1 do + local Item = Grid:GetItem(x, y) + if (Item.m_ItemID ~= E_ITEM_EMPTY) then + table.insert(Items, Item) + end + end + end + + if (#Items ~= 2) then + -- Only two items together can be fixed + return false + end + + if (Items[1].m_ItemID ~= Items[2].m_ItemID) then + -- Only items of the same type may be fixed + return false + end + + if ( + (Items[1].m_ItemHealth == 0) or + (Items[2].m_ItemHealth == 0) + ) + then + -- Only damaged items may be fixed + return false + end + + local _ID = Items[1].m_ItemID + local _least_hp = math.max(Items[1].m_ItemHealth, Items[2].m_ItemHealth) + local _most_hp = math.min(Items[1].m_ItemHealth, Items[2].m_ItemHealth) + local _item_hp = 0 + + -- TODO: This could be refactored into better code, using an _ID-indexed table for _item_hp + + if ( + (_ID == E_ITEM_WOODEN_SHOVEL) or + (_ID == E_ITEM_WOODEN_AXE) or + (_ID == E_ITEM_WOODEN_PICKAXE) or + (_ID == E_ITEM_WOODEN_SWORD) or + (_ID == E_ITEM_WOODEN_HOE) + ) + then + _item_hp = 60 + _do_fix = true + end + + if ( + (_ID == E_ITEM_STONE_SHOVEL) or + (_ID == E_ITEM_STONE_AXE) or + (_ID == E_ITEM_STONE_PICKAXE) or + (_ID == E_ITEM_STONE_SWORD) or + (_ID == E_ITEM_STONE_HOE) + ) + then + _item_hp = 132 + _do_fix = true + end + + if ( + (_ID == E_ITEM_IRON_SHOVEL) or + (_ID == E_ITEM_IRON_AXE) or + (_ID == E_ITEM_IRON_PICKAXE) or + (_ID == E_ITEM_IRON_SWORD) or + (_ID == E_ITEM_IRON_HOE) + ) + then + _item_hp = 251 + _do_fix = true + end + + if ( + (_ID == E_ITEM_GOLD_SHOVEL) or + (_ID == E_ITEM_GOLD_AXE) or + (_ID == E_ITEM_GOLD_PICKAXE) or + (_ID == E_ITEM_GOLD_SWORD) or + (_ID == E_ITEM_GOLD_HOE) + ) + then + _item_hp = 33 + _do_fix = true + end + + if ( + (_ID == E_ITEM_DIAMOND_SHOVEL) or + (_ID == E_ITEM_DIAMOND_AXE) or + (_ID == E_ITEM_DIAMOND_PICKAXE) or + (_ID == E_ITEM_DIAMOND_SWORD) or + (_ID == E_ITEM_DIAMOND_HOE) + ) + then + _item_hp = 1562 + _do_fix = true + end + + if (_ID == E_ITEM_LEATHER_CAP) then + _item_hp = 56 + _do_fix = true + end + if (_ID == E_ITEM_LEATHER_TUNIC) then + _item_hp = 82 + _do_fix = true + end + if (_ID == E_ITEM_LEATHER_PANTS) then + _item_hp = 76 + _do_fix = true + end + if (_ID == E_ITEM_LEATHER_BOOTS) then + _item_hp = 66 + _do_fix = true + end + + + if (_ID == E_ITEM_CHAIN_HELMET) then + _item_hp = 78 + _do_fix = true + end + if (_ID == E_ITEM_CHAIN_CHESTPLATE) then + _item_hp = 114 + _do_fix = true + end + if (_ID == E_ITEM_CHAIN_LEGGINGS) then + _item_hp = 106 + _do_fix = true + end + if (_ID == E_ITEM_CHAIN_BOOTS) then + _item_hp = 92 + _do_fix = true + end + + + if (_ID == E_ITEM_IRON_HELMET) then + _item_hp = 166 + _do_fix = true + end + if (_ID == E_ITEM_IRON_CHESTPLATE) then + _item_hp = 242 + _do_fix = true + end + if (_ID == E_ITEM_IRON_LEGGINGS) then + _item_hp = 226 + _do_fix = true + end + if (_ID == E_ITEM_IRON_BOOTS) then + _item_hp = 196 + _do_fix = true + end + + + if (_ID == E_ITEM_GOLD_HELMET) then + _item_hp = 78 + _do_fix = true + end + if (_ID == E_ITEM_GOLD_CHESTPLATE) then + _item_hp = 114 + _do_fix = true + end + if (_ID == E_ITEM_GOLD_LEGGINGS) then + _item_hp = 106 + _do_fix = true + end + if (_ID == E_ITEM_GOLD_BOOTS) then + _item_hp = 92 + _do_fix = true + end + + + if (_ID == E_ITEM_DIAMOND_HELMET) then + _item_hp = 364 + _do_fix = true + end + if (_ID == E_ITEM_DIAMOND_CHESTPLATE)then + _item_hp = 529 + _do_fix = true + end + if (_ID == E_ITEM_DIAMOND_LEGGINGS) then + _item_hp = 496 + _do_fix = true + end + if (_ID == E_ITEM_DIAMOND_BOOTS) then + _item_hp = 430 + _do_fix = true + end + -- ///////////////////////////////////////////////////// + + if (_do_fix == true) then + local _hp = _most_hp - (_item_hp - _least_hp) - _item_hp * BONUS + _hp = math.max(_hp, 0) + Recipe:SetResult(_ID, 1, _hp) + Recipe:SetIngredient(Items[1].x, Items[1].y, Items[1]); + Recipe:SetIngredient(Items[2].x, Items[2].y, Items[2]); + return true + end + return false +end + + + + diff --git a/MCServer/Plugins/Core/onkilled.lua b/MCServer/Plugins/Core/onkilled.lua new file mode 100644 index 000000000..a8a92f667 --- /dev/null +++ b/MCServer/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/MCServer/Plugins/Core/onlogin.lua b/MCServer/Plugins/Core/onlogin.lua new file mode 100644 index 000000000..a706f8024 --- /dev/null +++ b/MCServer/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/MCServer/Plugins/Core/onplayerjoin.lua b/MCServer/Plugins/Core/onplayerjoin.lua new file mode 100644 index 000000000..e8263f608 --- /dev/null +++ b/MCServer/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/MCServer/Plugins/Core/playerlist.lua b/MCServer/Plugins/Core/playerlist.lua new file mode 100644 index 000000000..f06dfed85 --- /dev/null +++ b/MCServer/Plugins/Core/playerlist.lua @@ -0,0 +1,14 @@ +function HandlePlayerListCommand( Split, Player ) + + local PlayerTable = {} + local AppendToTable = function( Player ) + table.insert(PlayerTable, Player:GetName() ) + end + Player:GetWorld():ForEachPlayer( AppendToTable ) + + local Message = cChatColor.Green .. "Connected players: (".. cChatColor.White.. #PlayerTable .. cChatColor.Green .. ")" + Player:SendMessage( Message ) + + Player:SendMessage( table.concat(PlayerTable, " ") ) + return true +end \ No newline at end of file diff --git a/MCServer/Plugins/Core/pluginlist.lua b/MCServer/Plugins/Core/pluginlist.lua new file mode 100644 index 000000000..7b007f7db --- /dev/null +++ b/MCServer/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: (" .. #PluginTable .. ")" ) + Player:SendMessage( cChatColor.Gold .. table.concat(PluginTable, cChatColor.Gold.." ") ) + return true +end \ No newline at end of file diff --git a/MCServer/Plugins/Core/regeneratechunk.lua b/MCServer/Plugins/Core/regeneratechunk.lua new file mode 100644 index 000000000..b4b2874fc --- /dev/null +++ b/MCServer/Plugins/Core/regeneratechunk.lua @@ -0,0 +1,18 @@ +function HandleRegenerateChunkCommand( Split, Player ) + if( (#Split == 2) or (#Split > 3) ) then + Player:SendMessage( cChatColor.Green .. "Usage: /regeneratechunk " ) + return true + end + + local X = Player:GetChunkX() + local Z = Player:GetChunkZ() + + if( #Split == 3 ) then + X = Split[2] + Z = Split[3] + end + + Player:SendMessage(cChatColor.Green .. "Regenerating chunk ["..X..", "..Z.."]") + Player:GetWorld():RegenerateChunk(X, Z) + return true +end \ No newline at end of file diff --git a/MCServer/Plugins/Core/reload.lua b/MCServer/Plugins/Core/reload.lua new file mode 100644 index 000000000..e2b338ba1 --- /dev/null +++ b/MCServer/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/MCServer/Plugins/Core/spawn.lua b/MCServer/Plugins/Core/spawn.lua new file mode 100644 index 000000000..73034d9cf --- /dev/null +++ b/MCServer/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/MCServer/Plugins/Core/stop.lua b/MCServer/Plugins/Core/stop.lua new file mode 100644 index 000000000..0a06fc7d3 --- /dev/null +++ b/MCServer/Plugins/Core/stop.lua @@ -0,0 +1,6 @@ +function HandleStopCommand( Split, Player ) + Server = cRoot:Get():GetServer() + Server:SendMessage( cChatColor.Green .. "Stopping the server..." ) + cRoot:Get():ServerCommand("stop") + return true +end \ No newline at end of file diff --git a/MCServer/Plugins/Core/teleport.lua b/MCServer/Plugins/Core/teleport.lua new file mode 100644 index 000000000..90eb3529a --- /dev/null +++ b/MCServer/Plugins/Core/teleport.lua @@ -0,0 +1,23 @@ +function HandleTPCommand( Split, Player ) + if( #Split ~= 2 ) then + Player:SendMessage( cChatColor.Green .. "Usage: /tp [PlayerName]" ) + return true + end + + World = Player:GetWorld() + + local TeleportDestination = function(OtherPlayer) + if( OtherPlayer == Player ) then + Player:SendMessage( cChatColor.Green .. "Already there :)" ) + else + Player:TeleportToEntity( OtherPlayer ) + Player:SendMessage( cChatColor.Green .. "You teleported to "..OtherPlayer:GetName().."!" ) + OtherPlayer:SendMessage( cChatColor.Green .. Player:GetName().." teleported to you!" ) + end + end + + if (not(World:DoWithPlayer(Split[2], TeleportDestination))) then + Player:SendMessage( cChatColor.Green .. "Can't find player " .. Split[2] ) + end + return true +end \ No newline at end of file diff --git a/MCServer/Plugins/Core/time.lua b/MCServer/Plugins/Core/time.lua new file mode 100644 index 000000000..425d69e6a --- /dev/null +++ b/MCServer/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/MCServer/Plugins/Core/top.lua b/MCServer/Plugins/Core/top.lua new file mode 100644 index 000000000..0f7a8f95f --- /dev/null +++ b/MCServer/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/MCServer/Plugins/Core/unban.lua b/MCServer/Plugins/Core/unban.lua new file mode 100644 index 000000000..9defbe323 --- /dev/null +++ b/MCServer/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/MCServer/Plugins/Core/viewdistance.lua b/MCServer/Plugins/Core/viewdistance.lua new file mode 100644 index 000000000..43d2a7de8 --- /dev/null +++ b/MCServer/Plugins/Core/viewdistance.lua @@ -0,0 +1,10 @@ +function HandleViewDistanceCommand( Split, Player ) + if( #Split ~= 2 ) then + Player:SendMessage( cChatColor.Green .. "Usage: /viewdistance [".. cClientHandle.MIN_VIEW_DISTANCE .."-".. cClientHandle.MAX_VIEW_DISTANCE .."]" ) + return true + end + + Player:GetClientHandle():SetViewDistance( Split[2] ) + Player:SendMessage(cChatColor.Green .. "Your viewdistance has been set to " .. Player:GetClientHandle():GetViewDistance() ) + return true +end \ No newline at end of file diff --git a/MCServer/Plugins/Core/web_manageplugins.lua b/MCServer/Plugins/Core/web_manageplugins.lua new file mode 100644 index 000000000..3030efc7a --- /dev/null +++ b/MCServer/Plugins/Core/web_manageplugins.lua @@ -0,0 +1,93 @@ +local function Button_RemovePlugin( Name, Index ) + return "
" +end + +local function HandlePluginListChanges( Request, SettingsIni ) + local Content = "" + if( Request.PostParams["RemovePlugin"] ~= nil + and Request.PostParams["PluginName"] ~= nil + and Request.PostParams["PluginIndex"] ~= nil ) then -- Removing a plugin + + local KeyIdx = SettingsIni:FindKey("Plugins") + local PluginIdx = Request.PostParams["PluginIndex"] + + local PluginName = SettingsIni:GetValue( KeyIdx, PluginIdx ) + if( (PluginName == Request.PostParams["PluginName"]) and (SettingsIni:DeleteValueByID( KeyIdx, PluginIdx ) == true) ) then + SettingsIni:WriteFile() + Content = "Removed plugin '" .. PluginName .. "'" + else + Content = "Whoops! Something went wrong!" + end + + + elseif( Request.PostParams["AddPlugin"] ~= nil + and Request.PostParams["PluginName"] ~= nil ) then -- Add a plugin + + SettingsIni:SetValue("Plugins", "NewPlugin", Request.PostParams["PluginName"], true ) + SettingsIni:WriteFile() + + Content = "Added plugin '".. Request.PostParams["PluginName"] .."'" + + end + + if( #Content > 0 ) then + return "

INFO: " .. Content .. "

" + else + return "" + end +end + +function HandleRequest_ManagePlugins( Request ) + local Content = "" + + if( Request.PostParams["reload"] ~= nil ) then + Content = Content .. "" + Content = Content .. "

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

" + cRoot:Get():GetPluginManager():ReloadPlugins() + return Content + end + + local PluginManager = cRoot:Get():GetPluginManager() + local PluginList = PluginManager:GetAllPlugins() + + Content = Content .. "

Currently active plugins

" + Content = Content .. "" + for k, Plugin in pairs(PluginList) do + Content = Content .. "" + end + Content = Content .. "
" .. Plugin:GetName() .. " V. " .. Plugin:GetVersion() .. "
" + + local SettingsIni = cIniFile("settings.ini") + if( SettingsIni:ReadFile() == true ) then + Content = Content .. "

Plugins according to settings.ini

" + + Content = Content .. HandlePluginListChanges( Request, SettingsIni ) + + Content = Content .. "" + + local KeyIdx = SettingsIni:FindKey("Plugins") + local NumValues = SettingsIni:GetNumValues( KeyIdx ) + for i = 0, NumValues-1 do + local ValueName = SettingsIni:GetValueName(KeyIdx, i ) + local PluginName = SettingsIni:GetValue(KeyIdx, i) + Content = Content .. "" + Content = Content .. "" + Content = Content .. "" + Content = Content .. "" + end + Content = Content .. "
" .. ValueName .. ": " .. PluginName .. "" .. Button_RemovePlugin( PluginName, i ) .. "
" + end + + Content = Content .. "

Add plugin to settings.ini

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

Reload

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

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

" + Content = Content .. "
" + + return Content +end \ No newline at end of file diff --git a/MCServer/Plugins/Core/web_permissions.lua b/MCServer/Plugins/Core/web_permissions.lua new file mode 100644 index 000000000..4fce502e1 --- /dev/null +++ b/MCServer/Plugins/Core/web_permissions.lua @@ -0,0 +1,79 @@ +local function ShowUsersTable() + local Content = "

Users

" + + local UsersIni = cIniFile("users.ini") + if( UsersIni:ReadFile() == false ) then + return "Could not read users.ini!" + end + + local NumUsers = UsersIni:GetNumKeys() + + Content = Content .. "" + + if( NumUsers > 0 ) then + Content = Content .. "" + + for i=0, NumUsers-1 do + local UserName = UsersIni:GetKeyName( i ) + + Content = Content .. "" + Content = Content .. "" + Content = Content .. "" + Content = Content .. "" + Content = Content .. "" + end + else + Content = Content .. "" + end + Content = Content .. "
UserGroups
" .. i .. "." .. UserName .. "" + Content = Content .. UsersIni:GetValue( UserName, "Groups", "-" ) + Content = Content .. "
None
" + + + return Content +end + +local function ShowGroupsTable() + local Content = "

Groups

" + + local GroupsIni = cIniFile("groups.ini") + if( GroupsIni:ReadFile() == false ) then + return "Could not read groups.ini!" + end + + local NumGroups = GroupsIni:GetNumKeys() + + Content = Content .. "" + if( NumGroups > 0 ) then + Content = Content .. "" + + for i=0, NumGroups-1 do + local GroupName = GroupsIni:GetKeyName( i ) + + Content = Content .. "" + Content = Content .. "" + Content = Content .. "" + Content = Content .. "" + Content = Content .. "" + Content = Content .. "" + end + else + Content = Content .. "" + end + Content = Content .. "
NamePermissionsColor
" .. i .. "." .. GroupName .. "" + Content = Content .. GroupsIni:GetValue( GroupName, "Permissions", "-" ) + Content = Content .. "" + Content = Content .. GroupsIni:GetValue( GroupName, "Color", "-" ) + Content = Content .. "
None
" + + return Content +end + +function HandleRequest_Permissions( Request ) + local Content = "" + + Content = Content .. ShowGroupsTable() + Content = Content .. ShowUsersTable() + + return Content +end \ No newline at end of file diff --git a/MCServer/Plugins/Core/web_playerlist.lua b/MCServer/Plugins/Core/web_playerlist.lua new file mode 100644 index 000000000..b7e48cc3f --- /dev/null +++ b/MCServer/Plugins/Core/web_playerlist.lua @@ -0,0 +1,36 @@ +function HandleRequest_PlayerList( Request ) + local World = cRoot:Get():GetDefaultWorld() + local Content = "" + + if( Request.Params["playerlist-kick"] ~= nil ) then + local KickPlayerName = Request.Params["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 PlayerNum = 0 + local AddPlayerToTable = function( Player ) + PlayerNum = PlayerNum + 1 + Content = Content .. "" + Content = Content .. "" + Content = Content .. "" + Content = Content .. "" + Content = Content .. "" + end + World:ForEachPlayer( AddPlayerToTable ) + + if( PlayerNum == 0 ) then + Content = Content .. "" + end + Content = Content .. "
" .. PlayerNum .. "." .. Player:GetName() .. "Kick
None
" + Content = Content .. "
" + return Content +end \ No newline at end of file diff --git a/MCServer/Plugins/Core/web_whitelist.lua b/MCServer/Plugins/Core/web_whitelist.lua new file mode 100644 index 000000000..2c9ddb953 --- /dev/null +++ b/MCServer/Plugins/Core/web_whitelist.lua @@ -0,0 +1,79 @@ +local function HTMLDeleteButton( name ) + return "
" +end + +function HandleRequest_WhiteList( Request ) + local UpdateMessage = "" + if( Request.PostParams["whitelist-add"] ~= nil ) then + local PlayerName = Request.PostParams["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.PostParams["whitelist-delete"] ~= nil ) then + local PlayerName = Request.PostParams["whitelist-delete"] + WhiteListIni:DeleteValue( "WhiteList", PlayerName ) + UpdateMessage = "Removed " .. PlayerName .. " from whitelist." + WhiteListIni:WriteFile() + elseif( Request.PostParams["whitelist-reload"] ~= nil ) then + WhiteListIni:Erase() -- Empty entire loaded ini first, otherwise weird shit goes down + WhiteListIni:ReadFile() + UpdateMessage = "Loaded from disk" + elseif( Request.Params["whitelist-setenable"] ~= nil ) then + local Enabled = Request.Params["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/MCServer/Plugins/MagicCarpet/objects.lua b/MCServer/Plugins/MagicCarpet/objects.lua new file mode 100644 index 000000000..30528cc42 --- /dev/null +++ b/MCServer/Plugins/MagicCarpet/objects.lua @@ -0,0 +1,97 @@ +-- 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 + +function cCarpet:getY() + return self.Location.y +end \ No newline at end of file diff --git a/MCServer/Plugins/MagicCarpet/plugin.lua b/MCServer/Plugins/MagicCarpet/plugin.lua new file mode 100644 index 000000000..22604c9d9 --- /dev/null +++ b/MCServer/Plugins/MagicCarpet/plugin.lua @@ -0,0 +1,65 @@ +local PLUGIN = {} +local Carpets = {} + +function Initialize( Plugin ) + PLUGIN = Plugin + + Plugin:SetName( "MagicCarpet" ) + Plugin:SetVersion( 1 ) + + PluginManager = cRoot:Get():GetPluginManager() + PluginManager:AddHook( Plugin, cPluginManager.E_PLUGIN_PLAYER_MOVE) + PluginManager:AddHook( Plugin, cPluginManager.E_PLUGIN_DISCONNECT) + + Plugin:AddCommand("/mc", " - Spawns a magical carpet!", "magiccarpet") + Plugin:BindCommand( "/mc", "magiccarpet", HandleCarpetCommand ) + + Log( "Initialized " .. Plugin:GetName() .. " v." .. Plugin:GetVersion() ) + return true +end + +function OnDisable() + Log( PLUGIN:GetName() .. " v." .. PLUGIN:GetVersion() .. " is shutting down..." ) + for i, Carpet in pairs( Carpets ) do + Carpet:remove() + end +end + +function HandleCarpetCommand( Split, Player ) + Carpet = Carpets[ Player ] + if( Carpet == nil ) then + Carpets[ Player ] = cCarpet:new() + Player:SendMessage("You're on a magic carpet!" ) + else + Carpet:remove() + Carpets[ Player ] = nil + Player:SendMessage("The carpet vanished!" ) + end + + return true +end + +function OnDisconnect( Reason, Player ) + local Carpet = Carpets[ Player ] + if( Carpet ~= nil ) then + Carpet:remove() + end + Carpets[ Player ] = nil +end + +function OnPlayerMove( Player ) + local Carpet = 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 + if( Player:GetPosY() < Carpet:getY() ) then + LOGINFO("Fell tru mc!") + Player:TeleportTo( Player:GetPosX(), Carpet:getY(), Player:GetPosZ() ) + end + Carpet:moveTo( cLocation:new( Player:GetPosX(), Player:GetPosY(), Player:GetPosZ() ) ) + end +end \ No newline at end of file diff --git a/MCServer/Plugins/SquirrelChatLog.nut b/MCServer/Plugins/SquirrelChatLog.nut new file mode 100644 index 000000000..4ef0fd595 --- /dev/null +++ b/MCServer/Plugins/SquirrelChatLog.nut @@ -0,0 +1,13 @@ +class SquirrelChatLog extends Plugin +{ + function Initialize() + { + this.AddHook(Hook.Chat); + return true; + } + + function OnChat(Message, Player) + { + ::print(Player.GetName() + ": " + Message); + } +} diff --git a/MCServer/Plugins/sTick/main.lua b/MCServer/Plugins/sTick/main.lua new file mode 100644 index 000000000..16ac7167f --- /dev/null +++ b/MCServer/Plugins/sTick/main.lua @@ -0,0 +1,20 @@ + +-- Global variables +PLUGIN = {} -- Reference to own plugin object + + + + + +function Initialize( Plugin ) + PLUGIN = Plugin + + Plugin:SetName( "sTick" ) + Plugin:SetVersion( 8 ) + + PluginManager = cRoot:Get():GetPluginManager() + PluginManager:AddHook( Plugin, cPluginManager.E_PLUGIN_BLOCK_PLACE ) + + LOG( "Initialized " .. Plugin:GetName() .. " v." .. Plugin:GetVersion() ) + return true +end \ No newline at end of file diff --git a/MCServer/Plugins/sTick/onblockplace.lua b/MCServer/Plugins/sTick/onblockplace.lua new file mode 100644 index 000000000..0216b580e --- /dev/null +++ b/MCServer/Plugins/sTick/onblockplace.lua @@ -0,0 +1,18 @@ +function OnBlockPlace( Block, Player ) + + -- dont check if the direction is in the air + if Block.m_Direction == -1 then + return false + end + + if (Block.m_ItemType ~= 280) then -- not a Stick of Ticking + return false + end + + LOG("Setting next block tick to {" .. Block.m_PosX .. ", " .. Block.m_PosY .. ", " .. Block.m_PosZ .. "}") + + Player:GetWorld():SetNextBlockTick(Block.m_PosX, Block.m_PosY, Block.m_PosZ); + + return true + +end \ No newline at end of file -- cgit v1.2.3