Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.

Commit

Permalink
fix: Config loading
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan2139 committed Oct 25, 2024
1 parent 6745450 commit 6231c08
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 23 deletions.
3 changes: 2 additions & 1 deletion sonorancad/configuration/callcommands_config.dist.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
Plugin Configuration
Put all needed configuration in this file.
]] local config = {
]]
local config = {
enabled = false,
pluginName = "callcommands", -- name your plugin here
pluginAuthor = "SonoranCAD", -- author
Expand Down
3 changes: 2 additions & 1 deletion sonorancad/configuration/dispatchnotify_config.dist.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
Put all needed configuration in this file.
]] local config = {
]]
local config = {
enabled = true,
configVersion = "3.0",
pluginName = "dispatchnotify", -- name your plugin here
Expand Down
6 changes: 4 additions & 2 deletions sonorancad/configuration/frameworksupport_config.dist.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
--[[
Sonoran Plugins
Sonoran Plugins
frameworksupport Plugin Configuration
Put all needed configuration in this file.
]] local config = {
]]
local config = {
enabled = true,
configVersion = "1.2",
pluginName = "frameworksupport", -- name your plugin here
Expand Down
3 changes: 2 additions & 1 deletion sonorancad/configuration/postals_config.dist.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
Plugin Configuration
Put all needed configuration in this file.
]] local config = {
]]
local config = {
enabled = false,
pluginName = "postals", -- name your plugin here
pluginAuthor = "SonoranCAD", -- author
Expand Down
3 changes: 2 additions & 1 deletion sonorancad/configuration/trafficstop_config.dist.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
Plugin Configuration
Put all needed configuration in this file.
]] config = {
]]
local config = {
enabled = false,
pluginName = "trafficstop", -- name your plugin here
pluginAuthor = "SonoranCAD", -- author
Expand Down
3 changes: 2 additions & 1 deletion sonorancad/configuration/wraithv2_config.dist.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
Plugin Configuration
Put all needed configuration in this file.
]] local config = {
]]
local config = {
enabled = false,
pluginName = "wraithv2", -- name your plugin here
pluginAuthor = "SonoranCAD", -- author
Expand Down
38 changes: 24 additions & 14 deletions sonorancad/core/configuration.lua
Original file line number Diff line number Diff line change
Expand Up @@ -116,22 +116,27 @@ Config.GetPluginConfig = function(pluginName)
disableReason = 'Missing configuration file'
}
else
local loadedPlugin, pluginError = load(correctConfig)
local configChunk = correctConfig:match("local config = {.-\n}") .. "\nreturn config"
if not configChunk then
errorLog("No config table found in the string.")
end
local tempEnv = {}
setmetatable(tempEnv, { __index = _G }) -- Allow access to global functions if needed
local loadedPlugin, pluginError = load(configChunk, 'config', 't', tempEnv)
if loadedPlugin then
-- Execute and capture the returned config table
local success, res = pcall(loadedPlugin)
if not success then
errorLog(
('Plugin %s failed to load due to error: %s'):format(
pluginName, res))
errorLog(('Plugin %s failed to load due to error: %s'):format(pluginName, res))
Config.plugins[pluginName] = {
enabled = false,
disableReason = 'Failed to load'
}
return {enabled = false, disableReason = 'Failed to load'}
end
if _G.config and type(_G.config) == "table" then
if res and type(res) == "table" then
-- Assign the extracted config to Config.plugins[pluginName]
Config.plugins[pluginName] = _G.config
Config.plugins[pluginName] = res
else
-- Handle case where config is not available
errorLog(
Expand Down Expand Up @@ -228,22 +233,27 @@ Config.LoadPlugin = function(pluginName, cb)
disableReason = 'Missing configuration file'
})
else
local loadedPlugin, pluginError = load(correctConfig)
local configChunk = correctConfig:match("local config = {.-\n}") .. "\nreturn config"
if not configChunk then
errorLog("No config table found in the string.")
end
local tempEnv = {}
setmetatable(tempEnv, { __index = _G }) -- Allow access to global functions if needed
local loadedPlugin, pluginError = load(configChunk, 'config', 't', tempEnv)
if loadedPlugin then
-- Execute and capture the returned config table
local success, res = pcall(loadedPlugin)
if not success then
errorLog(
('Plugin %s failed to load due to error: %s'):format(
pluginName, res))
errorLog(('Plugin %s failed to load due to error: %s'):format(pluginName, res))
Config.plugins[pluginName] = {
enabled = false,
disableReason = 'Failed to load'
}
return {enabled = false, disableReason = 'Failed to load'}
end
if _G.config and type(_G.config) == "table" then
if res and type(res) == "table" then
-- Assign the extracted config to Config.plugins[pluginName]
Config.plugins[pluginName] = _G.config
Config.plugins[pluginName] = res
else
-- Handle case where config is not available
errorLog(
Expand All @@ -253,10 +263,10 @@ Config.LoadPlugin = function(pluginName, cb)
enabled = false,
disableReason = 'Invalid or missing config'
}
return cb({
return {
enabled = false,
disableReason = 'Invalid or missing config'
})
}
end
if Config.critError then
Config.plugins[pluginName].enabled = false
Expand Down
2 changes: 0 additions & 2 deletions sonorancad/submodules/ts3integration/sv_ts3integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program in the file "LICENSE". If not, see <http://www.gnu.org/licenses/>.
*/
const fs = require('fs');
const path = require('path');
const { TeamSpeak, QueryProtocol } = require("ts3-nodejs-library");
const configFilePath = path.join(__dirname, "../../configuration/ts3integration_config.json");
const distFilePath = path.join(__dirname, "../../configuration/ts3integration_config.dist.json");
Expand Down

0 comments on commit 6231c08

Please sign in to comment.