-- Some HTML helper functions local function HTML_Option( value, text, selected ) if( selected == true ) then return [[]] else return [["]] end end local function HTML_Select_On_Off( name, defaultValue ) return [[]] end local function HTML_Select_Version( name, defaultValue ) return [[]] end local function ShowGeneralSettings( Request ) local Content = "" local InfoMsg = nil local SettingsIni = cIniFile("settings.ini") if( SettingsIni:ReadFile() == false ) then InfoMsg = "ERROR: Could not read settings.ini!" end if( Request.PostParams["general_submit"] ~= nil ) then SettingsIni:SetValue("Server", "Description",Request.PostParams["Server_Description"],false ) if( tonumber( Request.PostParams["Server_MaxPlayers"] ) ~= nil ) then SettingsIni:SetValue("Server", "MaxPlayers", Request.PostParams["Server_MaxPlayers"], false ) end if( tonumber( Request.PostParams["Server_Port"] ) ~= nil ) then SettingsIni:SetValue("Server", "Port", Request.PostParams["Server_Port"], false ) end if( tonumber( Request.PostParams["Server_PortsIPv6"] ) ~= nil ) then SettingsIni:SetValue("Server", "PortsIPv6", Request.PostParams["Server_PortsIPv6"], false ) end if( tonumber( Request.PostParams["Server_Version"] ) ~= nil ) then SettingsIni:SetValue("Server", "PrimaryServerVersion", Request.PostParams["Server_Version"], false ) end if( tonumber( Request.PostParams["Authentication_Authenticate"] ) ~= nil ) then SettingsIni:SetValue("Authentication", "Authenticate", Request.PostParams["Authentication_Authenticate"], false ) end if( SettingsIni:WriteFile() == false ) then InfoMsg = [[ERROR: Could not write to settings.ini!]] else InfoMsg = [[INFO: Successfully saved changes to settings.ini]] end end Content = Content .. [[

General Settings

]] if( InfoMsg ~= nil ) then Content = Content .. "

" .. InfoMsg .. "

" end Content = Content .. [[
Server
Description:
Max Players:
Port:
PortsIPv6:
Shown Version: ]] .. HTML_Select_Version("Server_Version", SettingsIni:GetValueI("Server", "PrimaryServerVersion") ) .. [[

Authentication
Authenticate: ]] .. HTML_Select_On_Off("Authentication_Authenticate", SettingsIni:GetValueI("Authentication", "Authenticate") ) .. [[

WARNING: Any changes made here might require a server restart in order to be applied!
]] return Content end local function ShowMonstersSettings( Request ) local Content = "" local InfoMsg = nil local SettingsIni = cIniFile("settings.ini") if( SettingsIni:ReadFile() == false ) then InfoMsg = "ERROR: Could not read settings.ini!" end if( Request.PostParams["monsters_submit"] ~= nil ) then if( tonumber( Request.PostParams["Monsters_AnimalsOn"] ) ~= nil ) then SettingsIni:SetValue("Monsters", "AnimalsOn", Request.PostParams["Monsters_AnimalsOn"], false ) end if( tonumber( Request.PostParams["Monsters_AnimalSpawnInterval"] ) ~= nil ) then SettingsIni:SetValue("Monsters", "AnimalSpawnInterval", Request.PostParams["Monsters_AnimalSpawnInterval"], false ) end SettingsIni:SetValue("Monsters", "Types", Request.PostParams["Monsters_Types"], false ) if( SettingsIni:WriteFile() == false ) then InfoMsg = "ERROR: Could not write to settings.ini!" else InfoMsg = "INFO: Successfully saved changes to settings.ini" end end Content = Content .. "
" Content = Content .. "

Monsters Settings

" if( InfoMsg ~= nil ) then Content = Content .. "

" .. InfoMsg .. "

" end Content = Content .. [[
Monsters
Animals On: ]] .. HTML_Select_On_Off("Monsters_AnimalsOn", SettingsIni:GetValueI("Monsters", "AnimalsOn") ) .. [[
Animal Spawn Interval:
Monster Types:

WARNING: Any changes made here might require a server restart in order to be applied!
]] return Content end local function ShowWorldsSettings( Request ) local Content = "" local InfoMsg = nil local bSaveIni = false local SettingsIni = cIniFile("settings.ini") if( SettingsIni:ReadFile() == false ) then InfoMsg = [[ERROR: Could not read settings.ini!]] end if( Request.PostParams["RemoveWorld"] ~= nil ) then Content = Content .. Request.PostParams["RemoveWorld"] local WorldIdx = string.sub( Request.PostParams["RemoveWorld"], string.len("Remove ") ) local KeyIdx = SettingsIni:FindKey("Worlds") local WorldName = SettingsIni:GetValue( KeyIdx, WorldIdx ) if( SettingsIni:DeleteValueByID( KeyIdx, WorldIdx ) == true ) then InfoMsg = "INFO: Successfully removed world " .. WorldName .. "!
" bSaveIni = true end end if( Request.PostParams["AddWorld"] ~= nil ) then if( Request.PostParams["WorldName"] ~= nil and Request.PostParams["WorldName"] ~= "" ) then SettingsIni:SetValue("Worlds", "World", Request.PostParams["WorldName"], true ) InfoMsg = "INFO: Successfully added world " .. Request.PostParams["WorldName"] .. "!
" bSaveIni = true end end if( Request.PostParams["worlds_submit"] ~= nil ) then SettingsIni:SetValue("Worlds", "DefaultWorld", Request.PostParams["Worlds_DefaultWorld"], false ) if( Request.PostParams["Worlds_World"] ~= nil ) then SettingsIni:SetValue("Worlds", "World", Request.PostParams["Worlds_World"], true ) end bSaveIni = true end if( bSaveIni == true ) then if( InfoMsg == nil ) then InfoMsg = "" end if( SettingsIni:WriteFile() == false ) then InfoMsg = InfoMsg .. "ERROR: Could not write to settings.ini!" else InfoMsg = InfoMsg .. "INFO: Successfully saved changes to settings.ini" end end Content = Content .. "

Worlds Settings

" if( InfoMsg ~= nil ) then Content = Content .. "

" .. InfoMsg .. "

" end Content = Content .. [[
]] local KeyIdx = SettingsIni:FindKey("Worlds") local NumValues = SettingsIni:GetNumValues( KeyIdx ) for i = 0, NumValues-1 do local ValueName = SettingsIni:GetValueName(KeyIdx, i ) if( ValueName == "World" ) then local WorldName = SettingsIni:GetValue(KeyIdx, i) Content = Content .. [[ ]] end end Content = Content .. [[
Worlds
Default World:
]] .. ValueName .. [[:
]] .. WorldName .. [[
Add World:

WARNING: Any changes made here might require a server restart in order to be applied!
]] return Content end function HandleRequest_ServerSettings( Request ) local Content = "" Content = Content .. [[

Server Settings

General Monsters Worlds

]] if( Request.Params["tab"] == "Monsters" ) then Content = Content .. ShowMonstersSettings( Request ) elseif( Request.Params["tab"] == "Worlds" ) then Content = Content .. ShowWorldsSettings( Request ) else Content = Content .. ShowGeneralSettings( Request ) -- Default to general settings end return Content end