summaryrefslogtreecommitdiffstats
path: root/Server
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2016-06-30 10:42:58 +0200
committerGitHub <noreply@github.com>2016-06-30 10:42:58 +0200
commit9af664dc739405726dd52f4fe7dce7b42f5ce18e (patch)
tree59bae2de637b5f3c629db8e55fb44a3106266709 /Server
parentSelf tests (#3242) (diff)
parentConverted cLuaState::cCallbackPtr into a UniquePtr. (diff)
downloadcuberite-9af664dc739405726dd52f4fe7dce7b42f5ce18e.tar
cuberite-9af664dc739405726dd52f4fe7dce7b42f5ce18e.tar.gz
cuberite-9af664dc739405726dd52f4fe7dce7b42f5ce18e.tar.bz2
cuberite-9af664dc739405726dd52f4fe7dce7b42f5ce18e.tar.lz
cuberite-9af664dc739405726dd52f4fe7dce7b42f5ce18e.tar.xz
cuberite-9af664dc739405726dd52f4fe7dce7b42f5ce18e.tar.zst
cuberite-9af664dc739405726dd52f4fe7dce7b42f5ce18e.zip
Diffstat (limited to 'Server')
-rw-r--r--Server/Plugins/APIDump/Classes/Plugins.lua7
-rw-r--r--Server/Plugins/APIDump/Classes/WebAdmin.lua8
-rw-r--r--Server/Plugins/Debuggers/Debuggers.lua4
-rw-r--r--Server/webadmin/template.lua62
4 files changed, 55 insertions, 26 deletions
diff --git a/Server/Plugins/APIDump/Classes/Plugins.lua b/Server/Plugins/APIDump/Classes/Plugins.lua
index d5ac5fdbd..c86adc087 100644
--- a/Server/Plugins/APIDump/Classes/Plugins.lua
+++ b/Server/Plugins/APIDump/Classes/Plugins.lua
@@ -2,7 +2,7 @@ return
{
cPlugin =
{
- Desc = [[cPlugin describes a Lua plugin. This page is dedicated to new-style plugins and contain their functions. Each plugin has its own Plugin object.
+ Desc = [[cPlugin describes a Lua plugin. This page is dedicated to new-style plugins and contain their functions. Each plugin has its own cPlugin object.
]],
Functions =
{
@@ -22,10 +22,10 @@ return
cPluginLua =
{
- Desc = "",
+ Desc = "(<b>OBSOLETE</b>) This class is no longer useful in the API and will be removed as soon as all core plugins are migrated away from it. The {{cPlugin}} class serves as the main plugin instance's interface.",
Functions =
{
- AddWebTab = { Params = "", Return = "", Notes = "Adds a new webadmin tab" },
+ AddWebTab = { Params = "Title, HandlerFn", Return = "", Notes = "<b>OBSOLETE</b> - Use {{cWebAdmin}}:AddWebTab() instead." },
},
Inherits = "cPlugin",
}, -- cPluginLua
@@ -81,6 +81,7 @@ cPluginManager.AddHook(cPluginManager.HOOK_CHAT, OnChatMessage);
GetNumLoadedPlugins = { Params = "", Return = "number", Notes = "Returns the number of loaded plugins (psLoaded only)" },
GetNumPlugins = { Params = "", Return = "number", Notes = "Returns the number of plugins, including the disabled, errored, unloaded and not-found ones" },
GetPlugin = { Params = "PluginName", Return = "{{cPlugin}}", Notes = "(<b>DEPRECATED, UNSAFE</b>) Returns a plugin handle of the specified plugin, or nil if such plugin is not loaded. Note thatdue to multithreading the handle is not guaranteed to be safe for use when stored - a single-plugin reload may have been triggered in the mean time for the requested plugin." },
+ GetPluginFolderName = { Params = "PluginName", Return = "string", Notes = "Returns the name of the folder from which the plugin was loaded (without the \"Plugins\" part). Used as a plugin's display name." },
GetPluginsPath = { Params = "", Return = "string", Notes = "Returns the path where the individual plugin folders are located. Doesn't include the path separator at the end of the returned string." },
IsCommandBound = { Params = "Command", Return = "bool", Notes = "Returns true if in-game Command is already bound (by any plugin)" },
IsConsoleCommandBound = { Params = "Command", Return = "bool", Notes = "Returns true if console Command is already bound (by any plugin)" },
diff --git a/Server/Plugins/APIDump/Classes/WebAdmin.lua b/Server/Plugins/APIDump/Classes/WebAdmin.lua
index 808335aea..a9d92b069 100644
--- a/Server/Plugins/APIDump/Classes/WebAdmin.lua
+++ b/Server/Plugins/APIDump/Classes/WebAdmin.lua
@@ -5,7 +5,15 @@ return
Desc = "",
Functions =
{
+ AddWebTab = { Params = "Title, UrlPath, HandlerFn", Return = "", Notes = "(STATIC) Adds a new web tab to webadmin. The tab uses \"Title\" as its display string and is identified in the URL using the UrlPath (https://server.domain.com/webadmin/{PluginName}/{UrlPath}). The HandlerFn is the callback function that is called when the admin accesses the page, it has the following signature:<br/><pre class=\"prettyprint lang-lua\">function ({{a_Request|HTTPRequest}}, a_UrlPath)<br/> return Content, ContentType<br/>end</pre> URLPath must not contain a '/', the recommendation is to use only 7-bit-clean ASCII character set." },
+ GetAllWebTabs = { Params = "", Return = "array-table", Notes = "(STATIC) Returns an array-table with each item describing a web tab, for all web tabs registered in the WebAdmin, for all plugins. The returned table has the following format:<br/><pre class=\"prettyprint lang-lua\">{<br/> {<br/> PluginName = \"Plugin's API name\",<br/> UrlPath = \"UrlPath given to AddWebTab\",<br/> Title = \"Title given to AddWebTab\",<br/> },<br/> ...<br/>}"},
+ GetBaseURL = { Params = "URL", Return = "string", Notes = "(STATIC) Returns the string that is the path of the base webadmin (\"../../../webadmin\") relative to the given URL." },
+ GetContentTypeFromFileExt = { Params = "FileExt", Return = "string", Notes = "(STATIC) Returns the content-type that should be used for files with the specified extension (without the dot), such as \"text/plain\" for the \"txt\" extension. If the extension is not known, returns an empty string." },
GetHTMLEscapedString = { Params = "string", Return = "string", Notes = "(STATIC) Gets the HTML-escaped representation of a requested string. This is useful for user input and game data that is not guaranteed to be escaped already." },
+ GetPage = { Params = "{{Request|HTTPRequest}}", Return = "table", Notes = "(STATIC) Returns the (inner HTML) page contents for the specified request. Calls the appropriate WebTab handler registered via AddWebTab() and returns the information from that plugin wrapped in a table with the following structure:<br/><pre class=\"prettyprint lang-lua\">{<br/> Content = \"\", -- Content returned by the plugin<br/> ContentType = \"\", -- Content type returned by the plugin, or \"text/html\" if none returned<br/> UrlPath = \"\", -- UrlPath decoded from the request<br/> TabTitle = \"\", -- Title of the tab that handled the request, as given to AddWebTab()<br/> PluginName = \"\", -- API name of the plugin that handled the request<br/> PluginFolder = \"\", -- Folder name (= display name) of the plugin that handled the request<br/>}</pre>This function is mainly used in the webadmin template file." },
+ GetPorts = { Params = "", Return = "string", Notes = "Returns a comma-separated list of ports on which the webadmin is configured to listen. Note that this list does include ports that may currently be unavailable (another server was already listening on them prior to launching Cuberite)." },
+ GetURLEncodedString = { Params = "string", Return = "string", Notes = "(STATIC) Returns the string given to it escaped by URL encoding, which makes the string suitable for transmission in an URL. Invalid characters are turned into \"%xy\" values." },
+ Reload = { Params = "", Return = "", Notes = "Reloads the webadmin's config - the allowed logins, the template script and the login page. Note that reloading will not change the \"enabled\" state of the server, and it will not update listening ports. Existing WebTabs will be kept registered even after the reload." },
},
}, -- cWebAdmin
diff --git a/Server/Plugins/Debuggers/Debuggers.lua b/Server/Plugins/Debuggers/Debuggers.lua
index 362dc4dd9..02510c866 100644
--- a/Server/Plugins/Debuggers/Debuggers.lua
+++ b/Server/Plugins/Debuggers/Debuggers.lua
@@ -1876,8 +1876,8 @@ end
function HandleConsoleSchedule(a_Split)
local prev = os.clock()
- LOG("Scheduling a task for 2 seconds in the future (current os.clock is " .. prev .. ")")
- cRoot:Get():GetDefaultWorld():ScheduleTask(40,
+ LOG("Scheduling a task for 5 seconds in the future (current os.clock is " .. prev .. ")")
+ cRoot:Get():GetDefaultWorld():ScheduleTask(5 * 20,
function ()
local current = os.clock()
local diff = current - prev
diff --git a/Server/webadmin/template.lua b/Server/webadmin/template.lua
index d80ca5f74..168f87993 100644
--- a/Server/webadmin/template.lua
+++ b/Server/webadmin/template.lua
@@ -20,7 +20,7 @@ end
-function GetDefaultPage()
+local function GetDefaultPage()
local PM = cRoot:Get():GetPluginManager()
local SubTitle = "Current Game"
@@ -55,30 +55,31 @@ end
function ShowPage(WebAdmin, TemplateRequest)
SiteContent = {}
- local BaseURL = WebAdmin:GetBaseURL(TemplateRequest.Request.Path)
+ local BaseURL = cWebAdmin:GetBaseURL(TemplateRequest.Request.Path)
local Title = "Cuberite WebAdmin"
local NumPlayers = cRoot:Get():GetServer():GetNumPlayers()
local MemoryUsageKiB = cRoot:GetPhysicalRAMUsage()
local NumChunks = cRoot:Get():GetTotalChunkCount()
- local PluginPage = WebAdmin:GetPage(TemplateRequest.Request)
+ local PluginPage = cWebAdmin:GetPage(TemplateRequest.Request)
local PageContent = PluginPage.Content
- local SubTitle = PluginPage.PluginName
- if (PluginPage.TabName ~= "") then
- SubTitle = PluginPage.PluginName .. " - " .. PluginPage.TabName
+ local SubTitle = PluginPage.PluginFolder
+ if (PluginPage.UrlPath ~= "") then
+ SubTitle = PluginPage.PluginFolder .. " - " .. PluginPage.TabTitle
end
if (PageContent == "") then
PageContent, SubTitle = GetDefaultPage()
end
+ --[[
+ -- 2016-01-15 Mattes: This wasn't used anywhere in the code, no idea what it was supposed to do
local reqParamsClass = ""
-
- for key,value in pairs(TemplateRequest.Request.Params) do
+ for key, value in pairs(TemplateRequest.Request.Params) do
reqParamsClass = reqParamsClass .. " param-" .. string.lower(string.gsub(key, "[^a-zA-Z0-9]+", "-") .. "-" .. string.gsub(value, "[^a-zA-Z0-9]+", "-"))
end
-
if (string.gsub(reqParamsClass, "%s", "") == "") then
reqParamsClass = " no-param"
end
+ --]]
Output([[
<!-- Copyright Justin S and Cuberite Team, licensed under CC-BY-SA 3.0 -->
@@ -133,20 +134,39 @@ function ShowPage(WebAdmin, TemplateRequest)
<td class="trow1 smalltext">
]])
-
- local AllPlugins = WebAdmin:GetPlugins()
- for key,value in pairs(AllPlugins) do
- local PluginWebTitle = value:GetWebTitle()
- local TabNames = value:GetTabNames()
- if (GetTableSize(TabNames) > 0) then
- Output("<div><a class='usercp_nav_item usercp_nav_pmfolder' style='text-decoration:none;'><b>"..PluginWebTitle.."</b></a></div>\n");
-
- for webname,prettyname in pairs(TabNames) do
- Output("<div><a href='" .. BaseURL .. PluginWebTitle .. "/" .. webname .. "' class='usercp_nav_item usercp_nav_sub_pmfolder'>" .. prettyname .. "</a></div>\n")
+ -- Get all tabs:
+ local perPluginTabs = {}
+ for _, tab in ipairs(cWebAdmin:GetAllWebTabs()) do
+ local pluginTabs = perPluginTabs[tab.PluginName] or {};
+ perPluginTabs[tab.PluginName] = pluginTabs
+ table.insert(pluginTabs, tab)
+ end
+
+ -- Sort by plugin:
+ local pluginNames = {}
+ for pluginName, pluginTabs in pairs(perPluginTabs) do
+ table.insert(pluginNames, pluginName)
+ end
+ table.sort(pluginNames)
+
+ -- Output by plugin, then alphabetically:
+ for _, pluginName in ipairs(pluginNames) do
+ local pluginTabs = perPluginTabs[pluginName]
+ table.sort(pluginTabs,
+ function(a_Tab1, a_Tab2)
+ return ((a_Tab1.Title or "") < (a_Tab2.Title or ""))
end
-
- Output("<br>\n");
+ )
+
+ -- Translate the plugin name into the folder name (-> title)
+ local pluginWebTitle = cPluginManager:Get():GetPluginFolderName(pluginName) or pluginName
+ Output("<div><a class='usercp_nav_item usercp_nav_pmfolder' style='text-decoration:none;'><b>" .. pluginWebTitle .. "</b></a></div>\n");
+
+ -- Output each tab:
+ for _, tab in pairs(pluginTabs) do
+ Output("<div><a href='" .. BaseURL .. pluginName .. "/" .. tab.UrlPath .. "' class='usercp_nav_item usercp_nav_sub_pmfolder'>" .. tab.Title .. "</a></div>\n")
end
+ Output("<br>\n");
end