summaryrefslogtreecommitdiffstats
path: root/MCServer
diff options
context:
space:
mode:
authorfaketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-10-14 01:34:47 +0200
committerfaketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-10-14 01:34:47 +0200
commit41ba1a7642105ac21b67f4febac3eceef6a39f0a (patch)
treeaec9b8bfcde7f1ad44e2cb28149a41a091f60465 /MCServer
parentBetter split of the fluid simulator functionality; removed the old LavaSimulator and WaterSimulator files. (diff)
downloadcuberite-41ba1a7642105ac21b67f4febac3eceef6a39f0a.tar
cuberite-41ba1a7642105ac21b67f4febac3eceef6a39f0a.tar.gz
cuberite-41ba1a7642105ac21b67f4febac3eceef6a39f0a.tar.bz2
cuberite-41ba1a7642105ac21b67f4febac3eceef6a39f0a.tar.lz
cuberite-41ba1a7642105ac21b67f4febac3eceef6a39f0a.tar.xz
cuberite-41ba1a7642105ac21b67f4febac3eceef6a39f0a.tar.zst
cuberite-41ba1a7642105ac21b67f4febac3eceef6a39f0a.zip
Diffstat (limited to 'MCServer')
-rw-r--r--MCServer/Plugins/Core/web_manageplugins.lua140
-rw-r--r--MCServer/settings.ini8
2 files changed, 99 insertions, 49 deletions
diff --git a/MCServer/Plugins/Core/web_manageplugins.lua b/MCServer/Plugins/Core/web_manageplugins.lua
index 3030efc7a..cd785ec53 100644
--- a/MCServer/Plugins/Core/web_manageplugins.lua
+++ b/MCServer/Plugins/Core/web_manageplugins.lua
@@ -2,31 +2,93 @@ local function Button_RemovePlugin( Name, Index )
return "<form method='POST'><input type='hidden' name='PluginName' value='"..Name.."'><input type='hidden' name='PluginIndex' value='"..Index.."'><input type='submit' name='RemovePlugin' value='Remove'></form>"
end
+local function Button_EnablePlugin( Name )
+ return [[<form method="POST"><input type="hidden" name="PluginName", value="]].. Name ..[["><input type="submit" name="EnablePlugin" value="Enable"></form>]]
+end
+
+local function Button_DisablePlugin( Name )
+ return [[<form method="POST"><input type="hidden" name="PluginName", value="]].. Name ..[["><input type="submit" name="DisablePlugin" value="Disable"></form>]]
+end
+
+local function FindPluginID( SettingsIni, PluginName )
+ local KeyIdx = SettingsIni:FindKey("Plugins")
+ local NumValues = SettingsIni:GetNumValues( KeyIdx )
+
+ for i = 0, NumValues-1 do
+ LOGINFO( SettingsIni:GetValue(KeyIdx, i) )
+ if( SettingsIni:GetValue(KeyIdx, i) == PluginName ) then
+ return i
+ end
+ end
+
+ return nil
+end
+
+local function RemovePluginFromIni( SettingsIni, PluginName )
+ local KeyIdx = SettingsIni:FindKey("Plugins")
+ local PluginIdx = FindPluginID( SettingsIni, PluginName )
+
+ if( PluginIdx == nil ) then
+ LOGINFO("Got nil! NOOOO")
+ return false
+ end
+
+ local Name = SettingsIni:GetValue( KeyIdx, PluginIdx )
+ if( Name ~= PluginName ) then
+ LOGINFO("not the same name T_T '" .. Name .. "' '" .. PluginName .. "'")
+ end
+ if( (Name == PluginName) and (SettingsIni:DeleteValueByID( KeyIdx, PluginIdx ) == true) ) then
+ return SettingsIni:WriteFile()
+ end
+
+ return false
+end
+
+local function AddPluginToIni( SettingsIni, PluginName )
+ RemovePluginFromIni( SettingsIni, PluginName ) -- Make sure there are no duplicates
+
+ if( SettingsIni:SetValue("Plugins", "Plugin", PluginName, true ) == true ) then
+ return SettingsIni:WriteFile()
+ end
+
+ return false
+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
+
+ if( Request.PostParams["EnablePlugin"] ~= nil
+ and Request.PostParams["PluginName"] ~= nil ) then
- 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 .. "'"
+ local PluginName = Request.PostParams["PluginName"]
+
+ local PM = cRoot:Get():GetPluginManager()
+ if( PM:LoadPlugin( PluginName ) == false ) then
+ Content = "Could not enable '".. PluginName .."'!"
+ end
+
+ if( AddPluginToIni( SettingsIni, PluginName ) == true ) then
+ Content = "Enabled plugin '".. PluginName .."'"
else
- Content = "Whoops! Something went wrong!"
+ Content = "Enabled plugin '".. PluginName .."' but could not add it to settings.ini"
end
+
+ elseif( Request.PostParams["DisablePlugin"] ~= nil
+ and Request.PostParams["PluginName"] ~= nil ) then
- elseif( Request.PostParams["AddPlugin"] ~= nil
- and Request.PostParams["PluginName"] ~= nil ) then -- Add a plugin
+ local PluginName = Request.PostParams["PluginName"]
+
+ local PM = cRoot:Get():GetPluginManager()
+ PM:DisablePlugin( PluginName )
+
+ if( RemovePluginFromIni( SettingsIni, PluginName ) == true ) then
+ Content = "Disabled plugin '".. PluginName .."'"
+ else
+ Content = "Disabled plugin '".. PluginName .."' but could not remove it from settings.ini"
+ end
- SettingsIni:SetValue("Plugins", "NewPlugin", Request.PostParams["PluginName"], true )
- SettingsIni:WriteFile()
- Content = "Added plugin '".. Request.PostParams["PluginName"] .."'"
end
@@ -47,45 +109,33 @@ function HandleRequest_ManagePlugins( Request )
return Content
end
+ local SettingsIni = cIniFile("settings.ini")
+ if( SettingsIni:ReadFile() == true ) then
+ Content = Content .. HandlePluginListChanges( Request, SettingsIni )
+ else
+ Content = Content .. "Cannot find/modify settings.ini"
+ end
+
local PluginManager = cRoot:Get():GetPluginManager()
+ PluginManager:FindPlugins() -- Refreshes the plugin list
local PluginList = PluginManager:GetAllPlugins()
- Content = Content .. "<h4>Currently active plugins</h4>"
+ Content = Content .. "<h4>Currently installed plugins</h4>"
Content = Content .. "<table>"
for k, Plugin in pairs(PluginList) do
- Content = Content .. "<tr><td>" .. Plugin:GetName() .. " V. " .. Plugin:GetVersion() .. "</td></tr>"
- end
- Content = Content .. "</table>"
-
- local SettingsIni = cIniFile("settings.ini")
- if( SettingsIni:ReadFile() == true ) then
- Content = Content .. "<h4>Plugins according to settings.ini</h4>"
-
- Content = Content .. HandlePluginListChanges( Request, SettingsIni )
-
- Content = Content .. "<table>"
-
- 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 .. "<tr>"
- Content = Content .. "<td>" .. ValueName .. ": " .. PluginName .. "</td>"
- Content = Content .. "<td>" .. Button_RemovePlugin( PluginName, i ) .. "</td>"
- Content = Content .. "</tr>"
+ Content = Content .. "<tr><td>".. k .."</td>"
+ if( Plugin ) then
+ Content = Content .. "<td>" .. Plugin:GetName() .. " V. " .. Plugin:GetVersion() .. "</td><td>" .. Button_DisablePlugin(k) .. "</td>"
+ else
+ Content = Content .. "<td></td><td>" .. Button_EnablePlugin(k) .. "</td>"
end
- Content = Content .. "</table>"
+ Content = Content .. "</tr>"
end
-
- Content = Content .. "<h4>Add plugin to settings.ini</h4>"
- Content = Content .. "<form method='POST'>"
- Content = Content .. "<input type='text' name='PluginName'><input type='submit' name='AddPlugin' value='Add Plugin'>"
- Content = Content .. "</form>"
+ Content = Content .. "</table>"
Content = Content .. "<h4>Reload</h4>"
Content = Content .. "<form method='POST'>"
- Content = Content .. "<p>Click the reload button to reload all plugins!<br>"
+ Content = Content .. "<p>Click the reload button to reload all plugins according to <strong>settings.ini</strong>!"
Content = Content .. "<input type='submit' name='reload' value='Reload!'></p>"
Content = Content .. "</form>"
diff --git a/MCServer/settings.ini b/MCServer/settings.ini
index debdc3918..7e545c86d 100644
--- a/MCServer/settings.ini
+++ b/MCServer/settings.ini
@@ -11,10 +11,10 @@ Description=MCServer - in C++
DefaultWorld=world
[Plugins]
-; NewPlugin=sTick
-; NewPlugin=DiamondMover
-NewPlugin=Core
-NewPlugin=ChunkWorx
+; Plugin=sTick
+; Plugin=DiamondMover
+Plugin=Core
+Plugin=ChunkWorx
[HelpPlugin]
ShowPluginNames=1