From 39caf003a70c64007146c020c1a1785f0013b9dc Mon Sep 17 00:00:00 2001 From: Timo Smit Date: Wed, 15 Mar 2017 13:43:16 +0100 Subject: [PATCH] Ported greetings, rules and spree messages to TOML format --- config/greetings.cfg | 8 -- config/greetings.toml | 7 ++ config/rules.cfg | 40 ---------- config/rules.toml | 39 +++++++++ config/sprees.cfg | 100 ------------------------ config/sprees.toml | 94 ++++++++++++++++++++++ config/wolfadmin.toml | 6 +- luamods/wolfadmin/admin/rules.lua | 38 +++++++-- luamods/wolfadmin/game/sprees.lua | 56 ++++++++++--- luamods/wolfadmin/players/greetings.lua | 68 ++++++++++++---- luamods/wolfadmin/util/settings.lua | 6 +- 11 files changed, 272 insertions(+), 190 deletions(-) delete mode 100644 config/greetings.cfg create mode 100644 config/greetings.toml delete mode 100644 config/rules.cfg create mode 100644 config/rules.toml delete mode 100644 config/sprees.cfg create mode 100644 config/sprees.toml diff --git a/config/greetings.cfg b/config/greetings.cfg deleted file mode 100644 index 8a314e6..0000000 --- a/config/greetings.cfg +++ /dev/null @@ -1,8 +0,0 @@ -[level] -level = 0 -greeting = Welcome ^7[N]^9! - -[user] -guid = XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -greeting = Welcome the console! - diff --git a/config/greetings.toml b/config/greetings.toml new file mode 100644 index 0000000..2cabac8 --- /dev/null +++ b/config/greetings.toml @@ -0,0 +1,7 @@ +[[level]] +level = 0 +greeting = "Welcome ^7[N]^9!" + +[[user]] +guid = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" +greeting = "Welcome the console!" diff --git a/config/rules.cfg b/config/rules.cfg deleted file mode 100644 index a43b9f0..0000000 --- a/config/rules.cfg +++ /dev/null @@ -1,40 +0,0 @@ -[rule] -shortcut = sk -rule = ^1NO ^7spawnkilling^9! - -[rule] -shortcut = tk -rule = ^1NO ^7teamkilling^9! - -[rule] -shortcut = tb -rule = ^1NO ^7teambleeding^9! - -[rule] -shortcut = xp -rule = ^1NO ^7XP whoring^9! - -[rule] -shortcut = lan -rule = ^7English ^9in ^7main ^9and ^7team chat^9. - -[rule] -shortcut = chat -rule = ^1NO ^7insulting ^9or ^7swearing^9! - -[rule] -shortcut = advert -rule = ^7Do ^1NOT ^7advertise^9! - -[rule] -shortcut = push -rule = ^7Do ^1NOT ^9push your ^7team mates^9! - -[rule] -shortcut = level -rule = ^7Do ^1NOT ^9ask for ^7admin levels^9! - -[rule] -shortcut = bug -rule = ^7Do ^1NOT ^9use ^7map bugs^9/^7exploits^9! - diff --git a/config/rules.toml b/config/rules.toml new file mode 100644 index 0000000..9038a94 --- /dev/null +++ b/config/rules.toml @@ -0,0 +1,39 @@ +[[rule]] +shortcut = "sk" +rule = "^1NO ^7spawnkilling^9!" + +[[rule]] +shortcut = "tk" +rule = "^1NO ^7teamkilling^9!" + +[[rule]] +shortcut = "tb" +rule = "^1NO ^7teambleeding^9!" + +[[rule]] +shortcut = "xp" +rule = "^1NO ^7XP whoring^9!" + +[[rule]] +shortcut = "lan" +rule = "^7English ^9in ^7main ^9and ^7team chat^9." + +[[rule]] +shortcut = "chat" +rule = "^1NO ^7insulting ^9or ^7swearing^9!" + +[[rule]] +shortcut = "advert" +rule = "^7Do ^1NOT ^7advertise^9!" + +[[rule]] +shortcut = "push" +rule = "^7Do ^1NOT ^9push your ^7team mates^9!" + +[[rule]] +shortcut = "level" +rule = "^7Do ^1NOT ^9ask for ^7admin levels^9!" + +[[rule]] +shortcut = "bug" +rule = "^7Do ^1NOT ^9use ^7map bugs^9/^7exploits^9!" diff --git a/config/sprees.cfg b/config/sprees.cfg deleted file mode 100644 index 2cffee6..0000000 --- a/config/sprees.cfg +++ /dev/null @@ -1,100 +0,0 @@ -[kill] -amount = 5 -msg = ^dis on a ^2killing spree^d! -sound = killingspree.wav - -[kill] -amount = 10 -msg = ^dis on a ^2rampage^d! -sound = rampage.wav - -[kill] -amount = 15 -msg = ^dis ^2dominating^d! -sound = dominating.wav - -[kill] -amount = 20 -msg = ^drevels in his ^2bloodbath^d! -sound = unstoppable.wav - -[kill] -amount = 25 -msg = ^dis a walking ^2slaughterhouse^d! -sound = godlike.wav - -[kill] -amount = 30 -msg = ^dwreaks ^2havoc ^dupon his foes^d! -sound = wickedsick.wav - -[kill] -amount = 35 -msg = ^dcuts through enemies like a ^2god ^2of ^2war^d! -sound = potter.wav - -[kill] -amount = 40 -msg = ^dis the ^2prophet of doom^d! -sound = holyshit.wav - -[death] -amount = 10 -msg = ^dmust be having a bad day! -sound = humiliation.wav - -[death] -amount = 15 -msg = ^dhis day just got worse! -sound = humiliation.wav - -[death] -amount = 20 -msg = ^dtries to kill with flowers! -sound = humiliation.wav - -[death] -amount = 25 -msg = ^dis getting his ass kicked! -sound = humiliation.wav - -[death] -amount = 30 -msg = ^dis a death magnet! -sound = humiliation.wav - -[death] -amount = 40 -msg = ^dneeds remedial combat training! -sound = humiliation.wav - -[death] -amount = 50 -msg = ^dstill can't kill shit! -sound = humiliation.wav - -[revive] -amount = 3 -msg = ^dis on a ^2revive spree^d! -sound = - -[revive] -amount = 5 -msg = ^dis a ^2health dealer^d! -sound = - -[revive] -amount = 10 -msg = ^dis a ^2perfect nurse^d! -sound = - -[revive] -amount = 15 -msg = ^dis a ^2syringe maniac^d! -sound = - -[revive] -amount = 25 -msg = ^dis the new ^2Dr. Frankenstein^d! -sound = - diff --git a/config/sprees.toml b/config/sprees.toml new file mode 100644 index 0000000..3803599 --- /dev/null +++ b/config/sprees.toml @@ -0,0 +1,94 @@ +[[kill]] +amount = 5 +msg = "^dis on a ^2killing spree^d!" +sound = "killingspree.wav" + +[[kill]] +amount = 10 +msg = "^dis on a ^2rampage^d!" +sound = "rampage.wav" + +[[kill]] +amount = 15 +msg = "^dis ^2dominating^d!" +sound = "dominating.wav" + +[[kill]] +amount = 20 +msg = "^drevels in his ^2bloodbath^d!" +sound = "unstoppable.wav" + +[[kill]] +amount = 25 +msg = "^dis a walking ^2slaughterhouse^d!" +sound = "godlike.wav" + +[[kill]] +amount = 30 +msg = "^dwreaks ^2havoc ^dupon his foes^d!" +sound = "wickedsick.wav" + +[[kill]] +amount = 35 +msg = "^dcuts through enemies like a ^2god ^2of ^2war^d!" +sound = "potter.wav" + +[[kill]] +amount = 40 +msg = "^dis the ^2prophet of doom^d!" +sound = "holyshit.wav" + +[[death]] +amount = 10 +msg = "^dmust be having a bad day!" +sound = "humiliation.wav" + +[[death]] +amount = 15 +msg = "^dhis day just got worse!" +sound = "humiliation.wav" + +[[death]] +amount = 20 +msg = "^dtries to kill with flowers!" +sound = "humiliation.wav" + +[[death]] +amount = 25 +msg = "^dis getting his ass kicked!" +sound = "humiliation.wav" + +[[death]] +amount = 30 +msg = "^dis a death magnet!" +sound = "humiliation.wav" + +[[death]] +amount = 40 +msg = "^dneeds remedial combat training!" +sound = "humiliation.wav" + +[[death]] +amount = 50 +msg = "^dstill can't kill shit!" +sound = "humiliation.wav" + +[[revive]] +amount = 3 +msg = "^dis on a ^2revive spree^d!" + +[[revive]] +amount = 5 +msg = "^dis a ^2health dealer^d!" + +[[revive]] +amount = 10 +msg = "^dis a ^2perfect nurse^d!" + +[[revive]] +amount = 15 +msg = "^dis a ^2syringe maniac^d!" + +[[revive]] +amount = 25 +msg = "^dis the new ^2Dr. Frankenstein^d!" diff --git a/config/wolfadmin.toml b/config/wolfadmin.toml index 606cb6e..7af5380 100644 --- a/config/wolfadmin.toml +++ b/config/wolfadmin.toml @@ -48,10 +48,10 @@ welcome = "^dwolfadmin: ^9This server is running WolfAdmin, type ^7/wolfadmin ^9 area = 3 [rules] -file = "rules.cfg" +file = "rules.toml" [greetings] -file = "greetings.cfg" +file = "greetings.toml" area = 3 bots = 1 @@ -59,6 +59,6 @@ bots = 1 bots = 1 [sprees] -file = "sprees.cfg" +file = "sprees.toml" messages = 7 records = 1 diff --git a/luamods/wolfadmin/admin/rules.lua b/luamods/wolfadmin/admin/rules.lua index 4b049b3..912d3fe 100644 --- a/luamods/wolfadmin/admin/rules.lua +++ b/luamods/wolfadmin/admin/rules.lua @@ -19,6 +19,8 @@ local events = require (wolfa_getLuaPath()..".util.events") local files = require (wolfa_getLuaPath()..".util.files") local settings = require (wolfa_getLuaPath()..".util.settings") +local toml = require "toml" + local rules = {} local data = {} @@ -38,17 +40,41 @@ function rules.load() return 0 end - local amount, array = files.loadFromCFG(fileName, "[a-z]+") + if string.find(fileName, ".toml") == string.len(fileName) - 4 then + local fileDescriptor, fileLength = et.trap_FS_FOpenFile(fileName, et.FS_READ) + local fileString = et.trap_FS_Read(fileDescriptor, fileLength) + + et.trap_FS_FCloseFile(fileDescriptor) + + local fileTable = toml.parse(fileString) - if amount == 0 then return 0 end + local amount - for _, rule in ipairs(array["rule"]) do - if rule["shortcut"] and rule["rule"] then - data[rule["shortcut"]] = rule["rule"] + for _, rule in ipairs(fileTable["rule"]) do + if rule["shortcut"] and rule["rule"] then + data[rule["shortcut"]] = rule["rule"] + end end + + return amount + 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 amount, array = files.loadFromCFG(fileName, "[a-z]+") + + if amount == 0 then return 0 end + + for _, rule in ipairs(array["rule"]) do + if rule["shortcut"] and rule["rule"] then + data[rule["shortcut"]] = rule["rule"] + end + end + + return amount end - return amount + return 0 end function rules.oninit(levelTime, randomSeed, restartMap) diff --git a/luamods/wolfadmin/game/sprees.lua b/luamods/wolfadmin/game/sprees.lua index afab349..d9a4709 100644 --- a/luamods/wolfadmin/game/sprees.lua +++ b/luamods/wolfadmin/game/sprees.lua @@ -27,6 +27,8 @@ local events = require (wolfa_getLuaPath()..".util.events") local files = require (wolfa_getLuaPath()..".util.files") local settings = require (wolfa_getLuaPath()..".util.settings") +local toml = require "toml" + local sprees = {} sprees.RECORD_KILL = 0 @@ -101,35 +103,63 @@ function sprees.load() end end - local fileName = settings.get("g_fileSprees") - for i = 0, sprees.RECORD_NUM - 1 do spreeMessages[i] = {} spreeMessagesByType[i] = {} end + local fileName = settings.get("g_fileSprees") + if fileName == "" then return 0 end - local amount, array = files.loadFromCFG(fileName, "[a-z]+") + if string.find(fileName, ".toml") == string.len(fileName) - 4 then + local fileDescriptor, fileLength = et.trap_FS_FOpenFile(fileName, et.FS_READ) + local fileString = et.trap_FS_Read(fileDescriptor, fileLength) - for name, block in pairs(array) do - for _, spree in ipairs(block) do - if spree["msg"] then - for k, v in pairs(spree) do - if k == "amount" then - spree[k] = tonumber(v) - end + et.trap_FS_FCloseFile(fileDescriptor) + + local fileTable = toml.parse(fileString) + + local amount + + for name, block in pairs(fileTable) do + for _, spree in ipairs(block) do + if spree["msg"] then + table.insert(spreeMessagesByType[sprees.getRecordTypeByName(name)], spree) + + spreeMessages[sprees.getRecordTypeByName(name)][spree["amount"]] = spree end - table.insert(spreeMessagesByType[sprees.getRecordTypeByName(name)], spree) + end + end + + return amount + 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 amount, array = files.loadFromCFG(fileName, "[a-z]+") - spreeMessages[sprees.getRecordTypeByName(name)][spree["amount"]] = spree + for name, block in pairs(array) do + for _, spree in ipairs(block) do + if spree["msg"] then + for k, v in pairs(spree) do + if k == "amount" then + spree[k] = tonumber(v) + end + end + table.insert(spreeMessagesByType[sprees.getRecordTypeByName(name)], spree) + + spreeMessages[sprees.getRecordTypeByName(name)][spree["amount"]] = spree + end end end + + return amount end - return amount + return 0 end function sprees.save() diff --git a/luamods/wolfadmin/players/greetings.lua b/luamods/wolfadmin/players/greetings.lua index b7d2098..131c205 100644 --- a/luamods/wolfadmin/players/greetings.lua +++ b/luamods/wolfadmin/players/greetings.lua @@ -25,6 +25,8 @@ local events = require (wolfa_getLuaPath()..".util.events") local settings = require (wolfa_getLuaPath()..".util.settings") local files = require (wolfa_getLuaPath()..".util.files") +local toml = require "toml" + local greetings = {} local userGreetings = {} @@ -86,29 +88,61 @@ function greetings.load() return 0 end - local amount, array = files.loadFromCFG(fileName, "[a-z]+") + if string.find(fileName, ".toml") == string.len(fileName) - 4 then + local fileDescriptor, fileLength = et.trap_FS_FOpenFile(fileName, et.FS_READ) + local fileString = et.trap_FS_Read(fileDescriptor, fileLength) + + et.trap_FS_FCloseFile(fileDescriptor) - if amount == 0 then return 0 end + local fileTable = toml.parse(fileString) - for _, greeting in ipairs(array["level"]) do - if greeting["text"] then - levelGreetings[tonumber(greeting["level"])] = { - ["text"] = greeting["greeting"], - ["sound"] = greeting["sound"], - } + for _, greeting in ipairs(fileTable["level"]) do + if greeting["greeting"] then + levelGreetings[greeting["level"]] = { + ["text"] = greeting["greeting"], + ["sound"] = greeting["sound"] + } + end end - end - for _, greeting in ipairs(array["user"]) do - if greeting["text"] then - userGreetings[greeting["guid"]] = { - ["text"] = greeting["greeting"], - ["sound"] = greeting["sound"], - } + for _, greeting in ipairs(fileTable["user"]) do + if greeting["greeting"] then + userGreetings[greeting["guid"]] = { + ["text"] = greeting["greeting"], + ["sound"] = greeting["sound"] + } + end end + + return #fileTable["level"] + #fileTable["user"] + 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 amount, array = files.loadFromCFG(fileName, "[a-z]+") + + for _, greeting in ipairs(array["level"]) do + if greeting["text"] then + levelGreetings[tonumber(greeting["level"])] = { + ["text"] = greeting["greeting"], + ["sound"] = greeting["sound"] + } + end + end + + for _, greeting in ipairs(array["user"]) do + if greeting["text"] then + userGreetings[greeting["guid"]] = { + ["text"] = greeting["greeting"], + ["sound"] = greeting["sound"] + } + end + end + + return amount end - - return amount + + return 0 end function greetings.oninit(levelTime, randomSeed, restartMap) diff --git a/luamods/wolfadmin/util/settings.lua b/luamods/wolfadmin/util/settings.lua index f3a9d96..9f483fb 100644 --- a/luamods/wolfadmin/util/settings.lua +++ b/luamods/wolfadmin/util/settings.lua @@ -23,9 +23,9 @@ local settings = {} local data = { ["g_logChat"] = "chat.log", ["g_logAdmin"] = "admin.log", - ["g_fileGreetings"] = "greetings.cfg", - ["g_fileRules"] = "rules.cfg", - ["g_fileSprees"] = "sprees.cfg", + ["g_fileGreetings"] = "greetings.toml", + ["g_fileRules"] = "rules.toml", + ["g_fileSprees"] = "sprees.toml", ["g_playerHistory"] = 1, ["g_spreeMessages"] = 7, ["g_spreeRecords"] = 1,