From 03e29802cdde309f3734ab7b6dd17ab60b9a359f Mon Sep 17 00:00:00 2001 From: "nielsbreu@gmail.com" Date: Sun, 24 Mar 2013 15:44:44 +0000 Subject: Updated core plugin. Added limited world. Configurable through webadmin. Added a Manage server page in webadmin where you can reload/restart/stop the server. You can add players to groups with the webadmin. without the player have to relog first You can change someone's group in-game with a command, without the player have to relog first Hardcore mode Improved death messages git-svn-id: http://mc-server.googlecode.com/svn/trunk@1306 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- MCServer/Plugins/Core/console.lua | 36 +++++++++- MCServer/Plugins/Core/main.lua | 19 ++++-- MCServer/Plugins/Core/onchunkgenerating.lua | 21 ++++++ MCServer/Plugins/Core/onkilling.lua | 99 +++++++++++++++++++++++----- MCServer/Plugins/Core/onplayermoving.lua | 21 ++++++ MCServer/Plugins/Core/rank.lua | 33 ++++++++++ MCServer/Plugins/Core/stop.lua | 4 +- MCServer/Plugins/Core/web_manageserver.lua | 24 +++++++ MCServer/Plugins/Core/web_permissions.lua | 56 +++++++++++++--- MCServer/Plugins/Core/web_serversettings.lua | 14 ++++ 10 files changed, 291 insertions(+), 36 deletions(-) create mode 100644 MCServer/Plugins/Core/onchunkgenerating.lua create mode 100644 MCServer/Plugins/Core/onplayermoving.lua create mode 100644 MCServer/Plugins/Core/rank.lua create mode 100644 MCServer/Plugins/Core/web_manageserver.lua (limited to 'MCServer') diff --git a/MCServer/Plugins/Core/console.lua b/MCServer/Plugins/Core/console.lua index 25c484e79..5a1ce8ef2 100644 --- a/MCServer/Plugins/Core/console.lua +++ b/MCServer/Plugins/Core/console.lua @@ -17,6 +17,7 @@ function InitConsoleCommands() PluginMgr:BindConsoleCommand("save-all", HandleConsoleSaveAll, "Saves all chunks"); PluginMgr:BindConsoleCommand("say", HandleConsoleSay, "Sends a chat message to all players"); PluginMgr:BindConsoleCommand("unload", HandleConsoleUnload, "Unloads all unused chunks"); + PluginMgr:BindConsoleCommand("rank", HandleConsoleRank, " [Player] [Rank] - to add someone to a group"); end @@ -166,8 +167,39 @@ function HandleConsoleUnload(Split) return true; end - - +function HandleConsoleRank(Split) + if Split[2] == nil or Split[3] == nil then + LOG("Usage: /rank [Player] [Group]") + return true + end + local GroupsIni = cIniFile("groups.ini") + if( GroupsIni:ReadFile() == false ) then + LOG("Could not read groups.ini!") + end + if GroupsIni:FindKey(Split[3]) == -1 then + LOG("Group does not exist") + return true + end + local UsersIni = cIniFile("users.ini") + if( UsersIni:ReadFile() == false ) then + LOG("Could not read users.ini!") + end + UsersIni:DeleteKey(Split[2]) + UsersIni:GetValueSet(Split[2], "Groups", Split[3]) + UsersIni:WriteFile() + local loopPlayers = function( Player ) + if Player:GetName() == Split[2] then + Player:SendMessage( cChatColor.Green .. "You were moved to group " .. Split[3] ) + Player:LoadPermissionsFromDisk() + end + end + local loopWorlds = function ( World ) + World:ForEachPlayer( loopPlayers ) + end + cRoot:Get():ForEachWorld( loopWorlds ) + LOG("Player " .. Split[2] .. " Was moved to " .. Split[3]) + return true +end function HandleConsole(Split) diff --git a/MCServer/Plugins/Core/main.lua b/MCServer/Plugins/Core/main.lua index 579ee4df3..7f595fcdf 100644 --- a/MCServer/Plugins/Core/main.lua +++ b/MCServer/Plugins/Core/main.lua @@ -19,7 +19,7 @@ function Initialize(Plugin) PLUGIN = Plugin Plugin:SetName("Core") - Plugin:SetVersion(10) + Plugin:SetVersion(12) PluginManager = cRoot:Get():GetPluginManager() PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_JOINED) @@ -29,13 +29,17 @@ function Initialize(Plugin) PluginManager:AddHook(Plugin, cPluginManager.HOOK_KILLING) PluginManager:AddHook(Plugin, cPluginManager.HOOK_CRAFTING_NO_RECIPE) PluginManager:AddHook(Plugin, cPluginManager.HOOK_CHAT) -- used in web_chat.lua - + PluginManager:AddHook(Plugin, cPluginManager.HOOK_CHUNK_GENERATING) + PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_MOVING) + PluginManager:BindCommand("/back", "core.back", HandleBackCommand, " - Return to your last position"); PluginManager:BindCommand("/save-all", "core.save-all", HandleSaveAllCommand, " - Saves all your worlds"); PluginManager:BindCommand("/help", "core.help", HandleHelpCommand, " [Page] - Show available commands"); + PluginManager:BindCommand("/rank", "core.rank", HandleRankCommand, " [Player] [Rank] - to add someone to a group"); PluginManager:BindCommand("/pluginlist", "core.pluginlist", HandlePluginListCommand, " - Show list of plugins"); PluginManager:BindCommand("/tp", "core.teleport", HandleTPCommand, " [Player] - Teleport yourself to a player"); PluginManager:BindCommand("/item", "core.item", HandleItemCommand, " [ItemType/Name] - Give yourself an item"); + PluginManager:BindCommand("/i", "core.item", HandleItemCommand, ""); PluginManager:BindCommand("/list", "core.playerlist", HandlePlayerListCommand, " - Shows list of connected players"); PluginManager:BindCommand("/who", "core.playerlist", HandlePlayerListCommand, " - Shows list of connected players"); PluginManager:BindCommand("/playerlist", "core.playerlist", HandlePlayerListCommand, " - Shows list of connected players"); @@ -55,10 +59,14 @@ function Initialize(Plugin) PluginManager:BindCommand("/viewdistance", "core.viewdistance", HandleViewDistanceCommand, " [".. cClientHandle.MIN_VIEW_DISTANCE .."-".. cClientHandle.MAX_VIEW_DISTANCE .."] - Change your view distance") InitConsoleCommands(); - - local IniFile = cIniFile("settings.ini") + + -- Load the settings + IniFile = cIniFile("Settings.ini") if ( IniFile:ReadFile() == true ) then - SHOW_PLUGIN_NAMES = IniFile:GetValueB("HelpPlugin", "ShowPluginNames", true ) + HardCore = IniFile:GetValueSet("GameMode", "Hardcore", "false") + LimitWorld = IniFile:GetValueSetB("Worlds", "LimitWorld", true) + LimitWorldWidth = IniFile:GetValueSetI("Worlds", "LimitWorldWidth", 200) + SHOW_PLUGIN_NAMES = IniFile:GetValueSetB("HelpPlugin", "ShowPluginNames", true ) end -- Load whitelist, and add default values and stuff @@ -96,6 +104,7 @@ function Initialize(Plugin) end end + Plugin:AddWebTab("Manage Server", HandleRequest_ManageServer); Plugin:AddWebTab("Server Settings", HandleRequest_ServerSettings); Plugin:AddWebTab("Chat", HandleRequest_Chat); Plugin:AddWebTab("Playerlist", HandleRequest_PlayerList); diff --git a/MCServer/Plugins/Core/onchunkgenerating.lua b/MCServer/Plugins/Core/onchunkgenerating.lua new file mode 100644 index 000000000..4c97329bd --- /dev/null +++ b/MCServer/Plugins/Core/onchunkgenerating.lua @@ -0,0 +1,21 @@ +function OnChunkGenerating(World, ChunkX, ChunkZ, ChunkDesc) + if LimitWorld == true then + SpawnX = math.floor(World:GetSpawnX() / 16) + SpawnZ = math.floor(World:GetSpawnZ() / 16) + if ( (SpawnX + LimitWorldWidth) < ChunkX ) or ( (SpawnX - LimitWorldWidth) > ChunkX ) then + FillBlocks(World, ChunkX, ChunkZ, ChunkDesc) + end + if ( (SpawnZ + LimitWorldWidth) < ChunkZ ) or ( (SpawnZ - LimitWorldWidth) > ChunkZ ) then + FillBlocks(World, ChunkX, ChunkZ, ChunkDesc) + end + end +end + +function FillBlocks(World, ChunkX, ChunkZ, ChunkDesc) + ChunkDesc:FillBlocks(0,0) + ChunkDesc:SetUseDefaultBiomes(false) + ChunkDesc:SetUseDefaultHeight(false) + ChunkDesc:SetUseDefaultComposition(false) + ChunkDesc:SetUseDefaultStructures(false) + ChunkDesc:SetUseDefaultFinish(false) +end \ No newline at end of file diff --git a/MCServer/Plugins/Core/onkilling.lua b/MCServer/Plugins/Core/onkilling.lua index 19bf0ea9d..b3361355f 100644 --- a/MCServer/Plugins/Core/onkilling.lua +++ b/MCServer/Plugins/Core/onkilling.lua @@ -1,24 +1,87 @@ function OnKilling(Victim, Killer) - if (Killer == nil) then - local KilledPlayer = tolua.cast(Victim, "cPlayer") - if( not KilledPlayer:IsA("cPlayer") or KilledPlayer == nil ) then - return false + if Victim:IsPlayer() == true then + Server = cRoot:Get():GetServer() + if Killer == nil then + if Victim:IsOnFire() then + Server:SendMessage( cChatColor.Red .. "Player " .. Victim:GetName() .. " burned away." ) + CheckHardcore(Victim) + return false + end + if Victim:GetWorld():GetBlock(Victim:GetPosX(), Victim:GetPosY(), Victim:GetPosZ()) == 10 or Victim:GetWorld():GetBlock(Victim:GetPosX(), Victim:GetPosY(), Victim:GetPosZ()) == 11 then + Server:SendMessage( cChatColor.Red .. Victim:GetName() .. " tried to swim in lava" ) + CheckHardcore(Victim) + return false + end + else + if Killer:IsPlayer() == true then + Server:SendMessage( cChatColor.Red .. "Player " .. Victim:GetName() .. " is killed by " .. Killer:GetName() ) + CheckHardcore(Victim) + return false + elseif Killer:IsMob() == true then + if Killer:IsA("cZombie") then + Server:SendMessage( cChatColor.Red .. "Player " .. Victim:GetName() .. " is eaten by a zombie") + CheckHardcore(Victim) + return false + elseif Killer:IsA("cSkeleton") then + Server:SendMessage( cChatColor.Red .. "Player " .. Victim:GetName() .. " is killed by a skeleton" ) + CheckHardcore(Victim) + return false + elseif Killer:IsA("cCreeper") then + Server:SendMessage( cChatColor.Red .. "Player " .. Victim:GetName() .. " is killed by a creeper") + CheckHardcore(Victim) + return false + elseif Killer:IsA("cSpider") then + Server:SendMessage( cChatColor.Red .. "Player " .. Victim:GetName() .. " is killed by a spider") + CheckHardcore(Victim) + return false + elseif Killer:IsA("cCaveSpider") then + Server:SendMessage( cChatColor.Red .. "Player " .. Victim:GetName() .. " is killed by a cavespider") + CheckHardcore(Victim) + return false + elseif Killer:IsA("cBlaze") then + Server:SendMessage( cChatColor.Red .. "Player " .. Victim:GetName() .. " is killed by a blaze") + CheckHardcore(Victim) + return false + elseif Killer:IsA("cEnderman") then + Server:SendMessage( cChatColor.Red .. "Player " .. Victim:GetName() .. " is slain by a enderman") + CheckHardcore(Victim) + return false + elseif Killer:IsA("cSilverfish") then + Server:SendMessage( cChatColor.Red .. "Player " .. Victim:GetName() .. " is killed by a silverfish") + CheckHardcore(Victim) + return false + elseif Killer:IsA("cSlime") then + Server:SendMessage( cChatColor.Red .. "Player " .. Victim:GetName() .. " is killed by a slime") + CheckHardcore(Victim) + return false + elseif Killer:IsA("cWitch") then + Server:SendMessage( cChatColor.Red .. "Player " .. Victim:GetName() .. " is killed by a witch") + CheckHardcore(Victim) + return false + elseif Killer:IsA("cZombiepigman") then + Server:SendMessage( cChatColor.Red .. "Player " .. Victim:GetName() .. " is slain by a zombiepigman") + CheckHardcore(Victim) + return false + elseif Killer:IsA("cMagmacube") then + Server:SendMessage( cChatColor.Red .. "Player " .. Victim:GetName() .. " is killed by a magmacube") + CheckHardcore(Victim) + return false + elseif Killer:IsA("cWolf") then + Server:SendMessage( cChatColor.Red .. "Player " .. Victim:GetName() .. " is killed by a wolf") + CheckHardcore(Victim) + return false + end + end end + Server:SendMessage( cChatColor.Red .. Victim:GetName() .. " Died") + end +end - local Server = cRoot:Get():GetServer() - Server:SendMessage( cChatColor.Red .. KilledPlayer:GetName() .. " died" ) - else - local KilledPlayer = tolua.cast(Victim, "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 +function CheckHardcore(Victim) + if HardCore == "true" then + if Victim:IsPlayer() == true then + local KilledPlayer = tolua.cast(Victim, "cPlayer") + BanPlayer(KilledPlayer:GetName(), "You Died") 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/onplayermoving.lua b/MCServer/Plugins/Core/onplayermoving.lua new file mode 100644 index 000000000..a3a188894 --- /dev/null +++ b/MCServer/Plugins/Core/onplayermoving.lua @@ -0,0 +1,21 @@ +function OnPlayerMoving( Player ) + if LimitWorld == true then + local World = Player:GetWorld() + local SpawnX = math.floor(World:GetSpawnX() / 16) + local SpawnZ = math.floor(World:GetSpawnZ() / 16) + local X = math.floor(Player:GetPosX() / 16) + local Z = math.floor(Player:GetPosZ() / 16) + if ( (SpawnX + LimitWorldWidth - 1) < X ) then + Player:TeleportTo(Player:GetPosX() - 1, Player:GetPosY(), Player:GetPosZ()) + end + if ( (SpawnX - LimitWorldWidth + 1) > X ) then + Player:TeleportTo(Player:GetPosX() + 1, Player:GetPosY(), Player:GetPosZ()) + end + if ( (SpawnZ + LimitWorldWidth - 1) < Z ) then + Player:TeleportTo(Player:GetPosX(), Player:GetPosY(), Player:GetPosZ() - 1) + end + if ( (SpawnZ - LimitWorldWidth + 1) > Z ) then + Player:TeleportTo(Player:GetPosX(), Player:GetPosY(), Player:GetPosZ() + 1) + end + end +end \ No newline at end of file diff --git a/MCServer/Plugins/Core/rank.lua b/MCServer/Plugins/Core/rank.lua new file mode 100644 index 000000000..e178f0a2b --- /dev/null +++ b/MCServer/Plugins/Core/rank.lua @@ -0,0 +1,33 @@ +function HandleRankCommand( Split, Player ) + if Split[2] == nil or Split[3] == nil then + Player:SendMessage(cChatColor.Rose .. "Usage: /rank [Player] [Group]") + return true + end + local GroupsIni = cIniFile("groups.ini") + if( GroupsIni:ReadFile() == false ) then + LOG("Could not read groups.ini!") + end + if GroupsIni:FindKey(Split[3]) == -1 then + Player:SendMessage(cChatColor.Rose .. "Group does not exist") + return true + end + local UsersIni = cIniFile("users.ini") + if( UsersIni:ReadFile() == false ) then + LOG("Could not read users.ini!") + end + UsersIni:DeleteKey(Split[2]) + UsersIni:GetValueSet(Split[2], "Groups", Split[3]) + UsersIni:WriteFile() + local loopPlayers = function( Player ) + if Player:GetName() == Split[2] then + Player:SendMessage( cChatColor.Green .. "You were moved to group " .. Split[3] ) + Player:LoadPermissionsFromDisk() + end + end + local loopWorlds = function ( World ) + World:ForEachPlayer( loopPlayers ) + end + cRoot:Get():ForEachWorld( loopWorlds ) + Player:SendMessage(cChatColor.Green .. "Player " .. Split[2] .. " Was moved to " .. Split[3]) + return true +end \ No newline at end of file diff --git a/MCServer/Plugins/Core/stop.lua b/MCServer/Plugins/Core/stop.lua index 0a06fc7d3..4b4cca3b6 100644 --- a/MCServer/Plugins/Core/stop.lua +++ b/MCServer/Plugins/Core/stop.lua @@ -1,6 +1,8 @@ function HandleStopCommand( Split, Player ) Server = cRoot:Get():GetServer() + PluginManager = cRoot:Get():GetPluginManager() Server:SendMessage( cChatColor.Green .. "Stopping the server..." ) - cRoot:Get():ServerCommand("stop") + PluginManager:ExecuteConsoleCommand("stop") + --cRoot:Get():ServerCommand("stop") return true end \ No newline at end of file diff --git a/MCServer/Plugins/Core/web_manageserver.lua b/MCServer/Plugins/Core/web_manageserver.lua new file mode 100644 index 000000000..f617eb46a --- /dev/null +++ b/MCServer/Plugins/Core/web_manageserver.lua @@ -0,0 +1,24 @@ +function HandleRequest_ManageServer( Request ) + local Content = "" + if( Request.PostParams["RestartServer"] ~= nil ) then + cRoot:Get():ServerCommand("restart") + elseif( Request.PostParams["ReloadServer"] ~= nil ) then + cRoot:Get():GetPluginManager():ReloadPlugins() + elseif( Request.PostParams["StopServer"] ~= nil ) then + cRoot:Get():ServerCommand("stop") + end + Content = Content .. [[ +
]] + + Content = Content .. [[ + + + + + +

restart the server

reload the server

stop the server
+ + ]] + return Content +end + diff --git a/MCServer/Plugins/Core/web_permissions.lua b/MCServer/Plugins/Core/web_permissions.lua index 4fce502e1..962078bb2 100644 --- a/MCServer/Plugins/Core/web_permissions.lua +++ b/MCServer/Plugins/Core/web_permissions.lua @@ -1,11 +1,6 @@ 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 .. "" @@ -36,11 +31,6 @@ 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 .. "
" @@ -69,9 +59,55 @@ local function ShowGroupsTable() return Content end +local function AddPlayers( Request ) + local Content = "

Add Players

" + if( Request.PostParams["AddPlayerToGroup"] ~= nil ) then + if Request.PostParams["AddPlayer"] ~= "" then + if Request.PostParams["AddGroups"] ~= "" then + if GroupsIni:FindKey(Request.PostParams["AddGroup"]) == -1 then + return "Group does not exist" + end + UsersIni:DeleteKey(Request.PostParams["AddPlayer"]) + UsersIni:GetValueSet(Request.PostParams["AddPlayer"], "Groups", Request.PostParams["AddGroup"]) + UsersIni:WriteFile() + local loopPlayers = function( Player ) + if Player:GetName() == Request.PostParams["AddPlayer"] then + Player:SendMessage( cChatColor.Green .. "You were moved to group " .. Request.PostParams["AddGroup"] ) + Player:LoadPermissionsFromDisk() + end + end + local loopWorlds = function ( World ) + World:ForEachPlayer( loopPlayers ) + end + cRoot:Get():ForEachWorld( loopWorlds ) + end + end + end + Content = Content .. [[ + +
+ +
+ + +
Player:
Group:
+ ]] + return Content +end + function HandleRequest_Permissions( Request ) + GroupsIni = cIniFile("groups.ini") + if( GroupsIni:ReadFile() == false ) then + return "Could not read groups.ini!" + end + UsersIni = cIniFile("users.ini") + if( UsersIni:ReadFile() == false ) then + return "Could not read users.ini!" + end + local Content = "" + Content = Content .. AddPlayers( Request ) Content = Content .. ShowGroupsTable() Content = Content .. ShowUsersTable() diff --git a/MCServer/Plugins/Core/web_serversettings.lua b/MCServer/Plugins/Core/web_serversettings.lua index 65a2f12ad..5e644ca3e 100644 --- a/MCServer/Plugins/Core/web_serversettings.lua +++ b/MCServer/Plugins/Core/web_serversettings.lua @@ -52,6 +52,13 @@ local function ShowGeneralSettings( Request ) if( tonumber( Request.PostParams["Authentication_Authenticate"] ) ~= nil ) then SettingsIni:SetValue("Authentication", "Authenticate", Request.PostParams["Authentication_Authenticate"], false ) end + if( tonumber( Request.PostParams["Limit_World"] ) ~= nil ) then + SettingsIni:SetValue("Worlds", "LimitWorld", Request.PostParams["Limit_World"], false ) + end + if( tonumber( Request.PostParams["LimitWorldWidth"] ) ~= nil ) then + SettingsIni:SetValue("Worlds", "LimitWorldWidth", Request.PostParams["LimitWorldWidth"], false ) + end + if( SettingsIni:WriteFile() == false ) then InfoMsg = [[ERROR: Could not write to settings.ini!]] else @@ -88,6 +95,13 @@ local function ShowGeneralSettings( Request ) ]] .. HTML_Select_On_Off("Authentication_Authenticate", SettingsIni:GetValueI("Authentication", "Authenticate") ) .. [[
+ + + + + + +
LimitWorld
Limit World:]] .. HTML_Select_On_Off("Limit_World", SettingsIni:GetValueI("Worlds", "LimitWorld") ) .. [[
Max Chunks from spawn:

WARNING: Any changes made here might require a server restart in order to be applied!
]] -- cgit v1.2.3