Add support for TOML-formatted configs (refs #60)

* added lua-toml as dependency
* removed cvars.cfg
* removed wolfadmin.cfg
* added wolfadmin.toml
* created compatibility checks for old configs
This commit is contained in:
Timo Smit 2017-03-14 22:43:15 +01:00
parent a24eefa248
commit 8d14486d61
4 changed files with 160 additions and 45 deletions

View File

@ -1,28 +0,0 @@
// WolfAdmin specific CVARs
set g_fileGreetings "greetings.cfg"
set g_fileRules "rules.cfg"
set g_fileSprees "sprees.cfg"
set g_welcomeMessage "^dwolfadmin: ^9This server is running WolfAdmin, type ^7/wolfadmin ^9for more information."
set g_welcomeArea 3
set g_greetingArea 3
set g_botGreetings 1
set g_evenerInterval 30
set g_evenerPlayerSelection 0
set g_evenerMinDifference 2
set g_evenerMaxDifference 5
set g_voteNextMapTimeout 0
set g_restrictedVotes ""
set g_renameLimit 80
set g_playerHistory 1
set g_spreeMessages 7
set g_spreeRecords 1
set g_botRecords 1
set g_announceRevives 1

View File

@ -1,9 +0,0 @@
[db]
type = sqlite3
file = wolfadmin.db
hostname = localhost
port = 3306
database = wolfadmin
username = wolfadmin
password = suchasecret

64
config/wolfadmin.toml Normal file
View File

@ -0,0 +1,64 @@
# Sample config file for WolfAdmin. Adjust to your needs.
# See http://dev.timosmit.com/wolfadmin/
# http://dev.timosmit.com/wolfadmin/configuration.html
[main]
# os = "unix"
standalone = 1
debug = 0
[db]
type = "sqlite3"
file = "wolfadmin.db"
# the settings below are only used for type 'mysql', uncomment if needed
# hostname = "localhost"
# port = 3306
# database = "wolfadmin"
# username = "wolfadmin"
# password = "suchasecret"
[logs]
chat = "chat.log"
admin = "admin.log"
[omnibot]
minbots = -1
maxbots = 10
[admin]
history = 1
maxrenames = 80
[balancer]
mindif = 2
maxdif = 5
selection = 0
interval = 30
[game]
announcerevives = 1
[voting]
timeout = 0
restricted = []
[banners]
welcome = "^dwolfadmin: ^9This server is running WolfAdmin, type ^7/wolfadmin ^9for more information."
area = 3
[rules]
file = "rules.cfg"
[greetings]
file = "greetings.cfg"
area = 3
bots = 1
[records]
bots = 1
[sprees]
file = "sprees.cfg"
messages = 7
records = 1

View File

@ -15,6 +15,7 @@
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
local toml = require "toml"
local events = require (wolfa_getLuaPath()..".util.events")
local settings = {}
@ -54,6 +55,68 @@ local data = {
["sv_os"] = "unix"
}
local cfgStructure = {
["main"] = {
["os"] = "sv_os",
["standalone"] = "g_standalone",
["debug"] = "g_debugWolfAdmin",
},
["db"] = {
["type"] = "db_type",
["file"] = "db_file",
["hostname"] = "db_hostname",
["port"] = "db_port",
["database"] = "db_database",
["username"] = "db_username",
["password"] = "db_password",
},
["logs"] = {
["chat"] = "g_logChat",
["admin"] = "g_logAdmin"
},
["omnibot"] = {
["minbots"] = "omnibot_minbots",
["maxbots"] = "omnibot_maxbots"
},
["admin"] = {
["history"] = "g_playerHistory",
["maxrenames"] = "g_renameLimit"
},
["balancer"] = {
["mindif"] = "g_evenerMinDifference",
["maxdif"] = "g_evenerMaxDifference",
["selection"] = "g_evenerPlayerSelection",
["interval"] = "g_evenerInterval"
},
["game"] = {
["announcerevives"] = "g_announceRevives"
},
["voting"] = {
["timeout"] = "g_voteNextMapTimeout",
["restricted"] = "g_restrictedVotes"
},
["banners"] = {
["welcome"] = "g_welcomeMessage",
["area"] = "g_welcomeArea"
},
["rules"] = {
["file"] = "g_fileRules"
},
["greetings"] = {
["file"] = "g_fileGreetings",
["area"] = "g_greetingsArea",
["bots"] = "g_botGreetings"
},
["records"] = {
["bots"] = "g_botRecords"
},
["sprees"] = {
["file"] = "g_fileSprees",
["messages"] = "g_spreeMessages",
["records"] = "g_spreeRecords"
}
}
function settings.get(name)
return data[name]
end
@ -72,17 +135,42 @@ function settings.load()
data[setting] = (cvar ~= "" and tonumber(cvar) or default)
end
end
local files = require (wolfa_getLuaPath()..".util.files")
local _, array = files.loadFromCFG("wolfadmin.cfg", "[a-z]+")
for blocksname, settings in pairs(array) do
for k, v in pairs(settings[1]) do
data[blocksname.."_"..k] = v
local fileDescriptor, fileLength = et.trap_FS_FOpenFile("wolfadmin.toml", et.FS_READ)
if fileLength ~= -1 then
local fileString = et.trap_FS_Read(fileDescriptor, fileLength)
et.trap_FS_FCloseFile(fileDescriptor)
local fileTable = toml.parse(fileString)
for module, settings in pairs(fileTable) do
for setting, value in pairs(settings) do
if cfgStructure[module][setting] then
data[cfgStructure[module][setting]] = value
end
end
end
-- compatibility for 1.1.* and lower
if type(data["g_restrictedVotes"]) == "table" then
data["g_restrictedVotes"] = table.concat(data["g_restrictedVotes"], " ")
end
else
-- compatibility for 1.1.* and lower
outputDebug("Using .cfg files is deprecated as of 1.2.0. Please consider updating to .toml files.", 3)
local files = require (wolfa_getLuaPath()..".util.files")
local _, array = files.loadFromCFG("wolfadmin.cfg", "[a-z]+")
for blocksname, settings in pairs(array) do
for k, v in pairs(settings[1]) do
data[cfgStructure[blocksname][k]] = v
end
end
end
local platform = string.lower(et.trap_Cvar_Get("sv_os"))
local platform = string.lower(data["sv_os"])
if not (platform == "unix" or platform == "windows") then
settings.set("sv_os", settings.determineOS())
end