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
|
@ -38,7 +38,7 @@ function rules.load()
|
||||||
return 0
|
return 0
|
||||||
end
|
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
|
if amount == 0 then return 0 end
|
||||||
|
|
||||||
|
|
|
@ -103,13 +103,17 @@ function sprees.load()
|
||||||
|
|
||||||
local fileName = settings.get("g_fileSprees")
|
local fileName = settings.get("g_fileSprees")
|
||||||
|
|
||||||
local amount, array = files.loadCFG(fileName, "[a-z]+", true)
|
|
||||||
|
|
||||||
for i = 0, sprees.RECORD_NUM - 1 do
|
for i = 0, sprees.RECORD_NUM - 1 do
|
||||||
spreeMessages[i] = {}
|
spreeMessages[i] = {}
|
||||||
spreeMessagesByType[i] = {}
|
spreeMessagesByType[i] = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if fileName == "" then
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
|
||||||
|
local amount, array = files.loadFromCFG(fileName, "[a-z]+")
|
||||||
|
|
||||||
for name, block in pairs(array) do
|
for name, block in pairs(array) do
|
||||||
for _, spree in ipairs(block) do
|
for _, spree in ipairs(block) do
|
||||||
for k, v in pairs(spree) do
|
for k, v in pairs(spree) do
|
||||||
|
|
|
@ -82,18 +82,22 @@ end
|
||||||
function greetings.load()
|
function greetings.load()
|
||||||
local fileName = settings.get("g_fileGreetings")
|
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
|
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"])] = {
|
levelGreetings[tonumber(greeting["level"])] = {
|
||||||
["text"] = greeting["greeting"],
|
["text"] = greeting["greeting"],
|
||||||
["sound"] = greeting["sound"],
|
["sound"] = greeting["sound"],
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
for id, greeting in ipairs(array["user"]) do
|
for _, greeting in ipairs(array["user"]) do
|
||||||
userGreetings[greeting["guid"]] = {
|
userGreetings[greeting["guid"]] = {
|
||||||
["text"] = greeting["greeting"],
|
["text"] = greeting["greeting"],
|
||||||
["sound"] = greeting["sound"],
|
["sound"] = greeting["sound"],
|
||||||
|
|
|
@ -36,38 +36,14 @@ function files.ls(directory)
|
||||||
return entries
|
return entries
|
||||||
end
|
end
|
||||||
|
|
||||||
function files.create(fileName)
|
function files.loadFromCFG(fileName, idExpr, fileCreate)
|
||||||
local fileDescriptor, fileLength = et.trap_FS_FOpenFile(fileName, et.FS_WRITE)
|
local fileDescriptor, fileLength = et.trap_FS_FOpenFile(fileName, et.FS_READ)
|
||||||
|
|
||||||
return fileDescriptor, fileLength
|
|
||||||
end
|
|
||||||
|
|
||||||
function files.open(fileName, fileMode, fileCreate)
|
|
||||||
local fileDescriptor, fileLength = et.trap_FS_FOpenFile(fileName, fileMode)
|
|
||||||
|
|
||||||
if fileLength == -1 then
|
if fileLength == -1 then
|
||||||
if not fileCreate then
|
return nil
|
||||||
error("failed to open "..fileName.."\n")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
fileDescriptor, fileLength = files.create(fileName)
|
local fileString = et.trap_FS_Read(fileDescriptor, fileLength).."\n\n"
|
||||||
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 arrayCount = 0
|
local arrayCount = 0
|
||||||
local array = {}
|
local array = {}
|
||||||
|
|
||||||
|
@ -93,8 +69,8 @@ function files.loadCFG(fileName, idExpr, fileCreate)
|
||||||
return arrayCount, array
|
return arrayCount, array
|
||||||
end
|
end
|
||||||
|
|
||||||
function files.save(fileName, array)
|
function files.saveToCFG(fileName, array)
|
||||||
local fileDescriptor = files.open(fileName, et.FS_WRITE)
|
local fileDescriptor, fileLength = et.trap_FS_FOpenFile(fileName, et.FS_WRITE)
|
||||||
local arrayCount = 0
|
local arrayCount = 0
|
||||||
|
|
||||||
for id, subdata in pairs(array) do
|
for id, subdata in pairs(array) do
|
||||||
|
|
|
@ -23,7 +23,7 @@ local settings = require (wolfa_getLuaPath()..".util.settings")
|
||||||
local logs = {}
|
local logs = {}
|
||||||
|
|
||||||
function logs.writeChat(clientId, type, ...)
|
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
|
local logLine
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ function logs.writeChat(clientId, type, ...)
|
||||||
end
|
end
|
||||||
|
|
||||||
function logs.writeAdmin(clientId, command, victimId, ...)
|
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
|
local logLine
|
||||||
|
|
||||||
|
|
|
@ -75,7 +75,7 @@ function settings.load()
|
||||||
end
|
end
|
||||||
|
|
||||||
local files = require (wolfa_getLuaPath()..".util.files")
|
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 blocksname, settings in pairs(array) do
|
||||||
for k, v in pairs(settings[1]) do
|
for k, v in pairs(settings[1]) do
|
||||||
|
|
Loading…
Reference in a new issue