-- Use a table for fast concatenation of strings
local SiteContent = {}
function Output(String)
table.insert(SiteContent, String)
end
local function GetDefaultPage()
local PM = cRoot:Get():GetPluginManager()
local SubTitle = "Current Game"
local Content = ""
Content = Content .. "
Plugins:
"
PM:ForEachPlugin(
function (a_CBPlugin)
if (a_CBPlugin:IsLoaded()) then
Content = Content .. "
";
return Content, SubTitle
end
function ShowPage(WebAdmin, TemplateRequest)
SiteContent = {}
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 = cWebAdmin:GetPage(TemplateRequest.Request)
local PageContent = PluginPage.Content
local SubTitle = PluginPage.PluginFolder
if (PluginPage.UrlPath ~= "") then
SubTitle = PluginPage.PluginFolder .. " - " .. PluginPage.TabTitle
end
if (PageContent == "") then
PageContent, SubTitle = GetDefaultPage()
end
Output([[
]] .. Title .. [[
Welcome back, ]] .. TemplateRequest.Request.Username .. [[Log out
]])
-- 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
)
-- Translate the plugin name into the folder name (-> title)
local pluginWebTitle = cPluginManager:Get():GetPluginFolderName(pluginName) or pluginName
Output("
" .. pluginWebTitle .. "
\n");
-- Output each tab:
for _, tab in pairs(pluginTabs) do
Output("