mirror of
https://github.com/etlegacy/wolfadmin.git
synced 2024-11-10 06:41:53 +00:00
Cleaned up files module
This commit is contained in:
parent
0105d181ab
commit
291b109c06
6 changed files with 34 additions and 50 deletions
|
@ -27,25 +27,25 @@ function rules.get(shortcut)
|
|||
if shortcut then
|
||||
return data[shortcut]
|
||||
end
|
||||
|
||||
|
||||
return data
|
||||
end
|
||||
|
||||
function rules.load()
|
||||
local fileName = settings.get("g_fileRules")
|
||||
|
||||
|
||||
if fileName == "" then
|
||||
return 0
|
||||
end
|
||||
|
||||
local amount, array = files.loadCFG(fileName, "[a-z]+", true)
|
||||
|
||||
|
||||
local amount, array = files.loadFromCFG(fileName, "[a-z]+")
|
||||
|
||||
if amount == 0 then return 0 end
|
||||
|
||||
|
||||
for id, rule in ipairs(array["rule"]) do
|
||||
data[rule["shortcut"]] = rule["rule"]
|
||||
end
|
||||
|
||||
|
||||
return amount
|
||||
end
|
||||
|
||||
|
|
|
@ -103,13 +103,17 @@ function sprees.load()
|
|||
|
||||
local fileName = settings.get("g_fileSprees")
|
||||
|
||||
local amount, array = files.loadCFG(fileName, "[a-z]+", true)
|
||||
|
||||
for i = 0, sprees.RECORD_NUM - 1 do
|
||||
spreeMessages[i] = {}
|
||||
spreeMessagesByType[i] = {}
|
||||
end
|
||||
|
||||
if fileName == "" then
|
||||
return 0
|
||||
end
|
||||
|
||||
local amount, array = files.loadFromCFG(fileName, "[a-z]+")
|
||||
|
||||
for name, block in pairs(array) do
|
||||
for _, spree in ipairs(block) do
|
||||
for k, v in pairs(spree) do
|
||||
|
|
|
@ -81,19 +81,23 @@ end
|
|||
|
||||
function greetings.load()
|
||||
local fileName = settings.get("g_fileGreetings")
|
||||
|
||||
local amount, array = files.loadCFG(fileName, "[a-z]+", true)
|
||||
|
||||
|
||||
if fileName == "" then
|
||||
return 0
|
||||
end
|
||||
|
||||
local amount, array = files.loadFromCFG(fileName, "[a-z]+")
|
||||
|
||||
if amount == 0 then return 0 end
|
||||
|
||||
for id, greeting in ipairs(array["level"]) do
|
||||
|
||||
for _, greeting in ipairs(array["level"]) do
|
||||
levelGreetings[tonumber(greeting["level"])] = {
|
||||
["text"] = greeting["greeting"],
|
||||
["sound"] = greeting["sound"],
|
||||
}
|
||||
end
|
||||
|
||||
for id, greeting in ipairs(array["user"]) do
|
||||
|
||||
for _, greeting in ipairs(array["user"]) do
|
||||
userGreetings[greeting["guid"]] = {
|
||||
["text"] = greeting["greeting"],
|
||||
["sound"] = greeting["sound"],
|
||||
|
|
|
@ -36,38 +36,14 @@ function files.ls(directory)
|
|||
return entries
|
||||
end
|
||||
|
||||
function files.create(fileName)
|
||||
local fileDescriptor, fileLength = et.trap_FS_FOpenFile(fileName, et.FS_WRITE)
|
||||
|
||||
return fileDescriptor, fileLength
|
||||
end
|
||||
function files.loadFromCFG(fileName, idExpr, fileCreate)
|
||||
local fileDescriptor, fileLength = et.trap_FS_FOpenFile(fileName, et.FS_READ)
|
||||
|
||||
function files.open(fileName, fileMode, fileCreate)
|
||||
local fileDescriptor, fileLength = et.trap_FS_FOpenFile(fileName, fileMode)
|
||||
|
||||
if fileLength == -1 then
|
||||
if not fileCreate then
|
||||
error("failed to open "..fileName.."\n")
|
||||
end
|
||||
|
||||
fileDescriptor, fileLength = files.create(fileName)
|
||||
return nil
|
||||
end
|
||||
|
||||
if fileMode == et.FS_READ then
|
||||
local fileString = et.trap_FS_Read(fileDescriptor, fileLength)
|
||||
|
||||
et.trap_FS_FCloseFile(fileDescriptor)
|
||||
|
||||
return fileString
|
||||
else
|
||||
return fileDescriptor
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
function files.loadCFG(fileName, idExpr, fileCreate)
|
||||
local fileString = files.open(fileName, et.FS_READ, fileCreate).."\n\n"
|
||||
local fileString = et.trap_FS_Read(fileDescriptor, fileLength).."\n\n"
|
||||
local arrayCount = 0
|
||||
local array = {}
|
||||
|
||||
|
@ -93,8 +69,8 @@ function files.loadCFG(fileName, idExpr, fileCreate)
|
|||
return arrayCount, array
|
||||
end
|
||||
|
||||
function files.save(fileName, array)
|
||||
local fileDescriptor = files.open(fileName, et.FS_WRITE)
|
||||
function files.saveToCFG(fileName, array)
|
||||
local fileDescriptor, fileLength = et.trap_FS_FOpenFile(fileName, et.FS_WRITE)
|
||||
local arrayCount = 0
|
||||
|
||||
for id, subdata in pairs(array) do
|
||||
|
|
|
@ -23,7 +23,7 @@ local settings = require (wolfa_getLuaPath()..".util.settings")
|
|||
local logs = {}
|
||||
|
||||
function logs.writeChat(clientId, type, ...)
|
||||
local fileDescriptor = files.open(settings.get("g_logChat"), et.FS_APPEND)
|
||||
local fileDescriptor, fileLength = et.trap_FS_FOpenFile(settings.get("g_logChat"), et.FS_APPEND)
|
||||
|
||||
local logLine
|
||||
|
||||
|
@ -45,7 +45,7 @@ function logs.writeChat(clientId, type, ...)
|
|||
end
|
||||
|
||||
function logs.writeAdmin(clientId, command, victimId, ...)
|
||||
local fileDescriptor = files.open(settings.get("g_logAdmin"), et.FS_APPEND)
|
||||
local fileDescriptor, fileLength = et.trap_FS_FOpenFile(settings.get("g_logAdmin"), et.FS_APPEND)
|
||||
|
||||
local logLine
|
||||
|
||||
|
|
|
@ -75,8 +75,8 @@ function settings.load()
|
|||
end
|
||||
|
||||
local files = require (wolfa_getLuaPath()..".util.files")
|
||||
local amount, array = files.loadCFG("wolfadmin.cfg", "[a-z]+", true)
|
||||
|
||||
local amount, 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
|
||||
|
|
Loading…
Reference in a new issue