Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion G2DManager_s.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ G2DHelp = {
}

addCommandHandler("g2d",function(player,command,...)
if not DGSConfig.enableG2DCMD then return end
if not DGSConfig.G2DCMD then return end
local account = getPlayerAccount(player)
if account then
local accn = getAccountName(account)
Expand Down
18 changes: 18 additions & 0 deletions meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -967,5 +967,23 @@
<right name="function.loadstring" access="true" />
<right name="general.ModifyOtherObjects" access="true" />
</aclrequest>

<settings>
<setting name="*testFile" value="true" friendlyname="Enable Test File" group="General" accept="boolean" desc="Enable or disable loading of DGS test file." />
<setting name="*compatibilityChecks" value="true" friendlyname="Enable Compatibility Check" group="General" accept="boolean" desc="Enable or disable compatibility check warnings." />
<setting name="*debugging" value="true" friendlyname="Enable Debugging" group="General" accept="boolean" desc="Enable or disable /debugdgs command." />

<setting name="*updateCheck" value="true" friendlyname="Enable Update Check" group="Updater" accept="boolean" desc="Enable or disable automatic update checks." />
<setting name="*updateCheckInterval" value="120" friendlyname="Update Check Interval" group="Updater" accept="number" desc="Interval in minutes between automatic update checks." />
<setting name="*updateCheckNoticeInterval" value="120" friendlyname="Update Check Notice Interval" group="Updater" accept="number" desc="Interval in minutes between update check notices." />
<setting name="*updateCommand" value="updatedgs" friendlyname="Update Command" group="Updater" accept="string" desc="Command to trigger a DGS update." />
<setting name="*updater" value="true" friendlyname="Enable Update System" group="Updater" accept="boolean" desc="Enable or disable the DGS update system." />
<setting name="*metaBackup" value="true" friendlyname="Enable Meta Backup" group="Updater" accept="boolean" desc="Enable or disable backup of meta.xml when updating." />
<setting name="*metaStyleBackup" value="true" friendlyname="Enable Style Meta Backup" group="Updater" accept="boolean" desc="Enable or disable backup of style files from meta.xml when updating." />

<setting name="*G2DCMD" value="true" friendlyname="Enable G2D Command Line" group="CMD" accept="boolean" desc="Enable or disable GUI to DGS command line." />
<setting name="*CMD" value="true" friendlyname="Enable Built-in CMD" group="CMD" accept="boolean" desc="Enable or disable DGS built-in CMD /dgscmd." />
</settings>

<download_priority_group>999</download_priority_group>
</meta>
131 changes: 77 additions & 54 deletions server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,80 +21,103 @@ end

-----------Config Loader
DGSConfig = {
updateCheck = true, -- Enable:true;Disable:false
updateCheckInterval = 120, -- Minutes
updateCheckNoticeInterval = 120, -- Minutes
updateCommand = "updatedgs", -- Command of update dgs
enableUpdateSystem = true , -- Enable update system
enableMetaBackup = true, -- Backup meta.xml
enableStyleMetaBackup = true, -- Backup style files meta index from meta.xml
enableG2DCMD = true, -- Enable GUI To DGS command line
enableBuiltInCMD = true, -- Enable DGS Built-in CMD /dgscmd
enableTestFile = true, -- Loads DGS Test File (If you want to save some bytes of memory, disable this by set to false)
enableCompatibilityCheck = true, -- Enable compatibility check warnings
enableDebug = true, -- Enable /debugdgs
updateCheck = true,
updateCheckInterval = 120,
updateCheckNoticeInterval = 120,
updateCommand = "updatedgs",
updater = true,
metaBackup = true,
metaStyleBackup = true,
G2DCMD = true,
CMD = true,
testFile = true,
compatibilityChecks = true,
debugging = true,
}

function loadConfig()
if fileExists("config.txt") then
local file = fileOpen ("config.txt")
if file then
local configUpdateRequired = false
local str = fileRead(file,fileGetSize(file))
fileClose(file)
local fnc = loadstring(str)
if fnc then
local dgsConfig = {}
setfenv(fnc,{dgsConfig=dgsConfig})
fnc()
for name,value in pairs(DGSConfig) do
if dgsConfig[name] == nil then
configUpdateRequired = true
else
DGSConfig[name] = dgsConfig[name]
if hasObjectPermissionTo(resource,"function.loadstring",true) then
local str = fileRead(file,fileGetSize(file))
fileClose(file)
local fnc = loadstring(str)
if fnc then
local convertSettings = {
["enableUpdateSystem"] = "updater",
["enableMetaBackup"] = "metaBackup",
["enableStyleMetaBackup"] = "metaStyleBackup",
["enableG2DCMD"] = "G2DCMD",
["enableBuiltInCMD"] = "CMD",
["enableTestFile"] = "testFile",
["enableCompatibilityCheck"] = "compatibilityChecks",
["enableDebug"] = "debugging"
}
local dgsConfig = {}
local customSettings
setfenv(fnc,{dgsConfig=dgsConfig})
fnc()
for name,value in pairs(dgsConfig) do
local setting = convertSettings[name]
if setting or get(name) then
set("*"..(setting or name),value)
else
customSettings = true
end
end
outputDGSMessage("Old config file has been converting to meta settings.","Config")
if customSettings then
outputDGSMessage("However, custom settings were detected, so the file was not deleted.","Config")
fileRename("config.txt","deleted/config.txt")
else
fileDelete("config.txt")
outputDGSMessage("The old config file was deleted.","Config")
end
end
outputDGSMessage("The config file has been loaded.","Config")
else
configUpdateRequired = true
outputDGSMessage("Invalid config file.","Config",2)
end
if configUpdateRequired then
fileDelete("config.txt")
file = fileCreate("config.txt")
str = ""
for k,v in pairs(DGSConfig) do
local value = type(v) == "string" and '"'..v..'"' or tostring(v)
str = str.."\r\ndgsConfig."..k.." = "..value
end
fileWrite(file,str:sub(3))
fileClose(file)
outputDGSMessage("The config file has been updated.","Config")
outputDGSMessage("Failed to convert the old config file to MTA settings since function.loadstring is disabled. config.txt was backed up","Config",2)
fileRename("config.txt","deleted/config.txt")
end
else
outputDGSMessage("Failed to open the config file.","Config",2)
end
else
local file = fileCreate("config.txt")
local str = ""
for k,v in pairs(DGSConfig) do
local value = type(v) == "string" and '"'..v..'"' or tostring(v)
str = str.."\r\ndgsConfig."..k.." = "..value
outputDGSMessage("Failed to open the old config file.","Config",2)
end
fileWrite(file,str:sub(3))
fileClose(file)
outputDGSMessage("Config file was created.","Config")
end

for setting,defaultValue in pairs (DGSConfig) do
local value = get("*"..setting)
if type(defaultValue) == "boolean" then
value = value == "true" or value == true
elseif type(defaultValue) == "number" then
value = tonumber(value) or defaultValue
end
DGSConfig[setting] = value
end

setElementData(resourceRoot,"DGS-allowCMD",DGSConfig.enableBuiltInCMD)
setElementData(resourceRoot,"DGS-enableDebug",DGSConfig.enableDebug)
setElementData(resourceRoot,"DGS-enableCompatibilityCheck",DGSConfig.enableCompatibilityCheck)
setElementData(resourceRoot,"DGS-allowCMD",DGSConfig.CMD)
setElementData(resourceRoot,"DGS-enableDebug",DGSConfig.debugging)
setElementData(resourceRoot,"DGS-enableCompatibilityCheck",DGSConfig.compatibilityChecks)
if DGSConfig.enableG2DCMD then
outputDGSMessage("G2D command line is enabled.","Config")
end
end
loadConfig()

local settingsPrefix = string.format("*%s.", getResourceName(resource))
addEventHandler("onSettingChange", root,
function (gsetting,_,jsonValue)
if string.sub(gsetting,1,#settingsPrefix) == settingsPrefix then
local setting = string.sub(gsetting,#settingsPrefix+1)
local value = fromJSON(jsonValue)
if setting == "CMD" then
setElementData(resourceRoot,"DGS-allowCMD",value == true or value == "true")
elseif setting == "debugging" then
setElementData(resourceRoot,"DGS-enableDebug",value == true or value == "true")
end
end
end)


-----------Remote Stuff
addEvent("DGSI_RequestQRCode",true)
addEvent("DGSI_RequestRemoteImage",true)
Expand Down
11 changes: 5 additions & 6 deletions update.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ local verRaw = fileRead(check,fileGetSize(check))
fileClose(check)
setElementData(resourceRoot,"Version",verRaw)
local version = tonumber(verRaw) or 0
if not DGSConfig.enableUpdateSystem then return end
if not DGSConfig.updater then return end

local _fetchRemote = fetchRemote
function fetchRemote(...)
Expand Down Expand Up @@ -55,7 +55,6 @@ if DGSConfig.updateCheckAuto then
checkUpdate()
updatePeriodTimer = setTimer(checkUpdate,DGSConfig.updateCheckInterval*3600000,0)
end

addCommandHandler(DGSConfig.updateCommand,function(player)
local account = getPlayerAccount(player)
local isPermit = hasObjectPermissionTo(player,"command."..DGSConfig.updateCommand,false)
Expand Down Expand Up @@ -134,7 +133,7 @@ function checkFiles()
local path = xmlNodeGetAttribute(v,"src")
if string.find(path,"styleMapper.lua") then break end
if path == "meta.xml" then break end
if string.find(path,"test.lua") and not DGSConfig.enableTestFile then break end
if string.find(path,"test.lua") and not DGSConfig.testFile then break end
local sha = ""
if fileExists(path) then
local file = fileOpen(path)
Expand Down Expand Up @@ -199,7 +198,7 @@ function DownloadFinish()
fileDelete("meta.xml")
end
recoverStyleMapper()
if not DGSConfig.enableTestFile then --Remove test.lua from meta.xml
if not DGSConfig.testFile then --Remove test.lua from meta.xml
local xml = xmlLoadFile("meta.xml")
for k,v in ipairs(xmlNodeGetChildren(xml)) do
if xmlNodeGetName(v) == "script" then
Expand Down Expand Up @@ -238,7 +237,7 @@ end)
styleBackupStr = ""
locator = [[ <export]]
function backupStyleMapper()
if DGSConfig.enableMetaBackup then
if DGSConfig.metaBackup then
fileCopy("meta.xml","meta.xml.bak",true)
end
if not fileExists("meta.xml") then return outputDGSMessage("Please rename the meta xml as meta.xml",nil,"Updater",2) end
Expand All @@ -253,7 +252,7 @@ function backupStyleMapper()
if fileExists("styleMapperBackup.bak") then
fileDelete("styleMapperBackup.bak")
end
if DGSConfig.enableStyleMetaBackup then
if DGSConfig.metaStyleBackup then
local file = fileCreate("styleMapperBackup.bak")
fileWrite(file,styleBackupStr)
fileClose(file)
Expand Down