diff --git a/sonorancad/configuration/callcommands_config.dist.lua b/sonorancad/configuration/callcommands_config.dist.lua index 346d1df..c972028 100644 --- a/sonorancad/configuration/callcommands_config.dist.lua +++ b/sonorancad/configuration/callcommands_config.dist.lua @@ -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 diff --git a/sonorancad/configuration/dispatchnotify_config.dist.lua b/sonorancad/configuration/dispatchnotify_config.dist.lua index 0402039..4e722f3 100644 --- a/sonorancad/configuration/dispatchnotify_config.dist.lua +++ b/sonorancad/configuration/dispatchnotify_config.dist.lua @@ -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 diff --git a/sonorancad/configuration/frameworksupport_config.dist.lua b/sonorancad/configuration/frameworksupport_config.dist.lua index 084e26a..91f53b8 100644 --- a/sonorancad/configuration/frameworksupport_config.dist.lua +++ b/sonorancad/configuration/frameworksupport_config.dist.lua @@ -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 diff --git a/sonorancad/configuration/postals_config.dist.lua b/sonorancad/configuration/postals_config.dist.lua index 0be54f3..44be03d 100644 --- a/sonorancad/configuration/postals_config.dist.lua +++ b/sonorancad/configuration/postals_config.dist.lua @@ -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 diff --git a/sonorancad/configuration/trafficstop_config.dist.lua b/sonorancad/configuration/trafficstop_config.dist.lua index 9685b86..a362b6b 100644 --- a/sonorancad/configuration/trafficstop_config.dist.lua +++ b/sonorancad/configuration/trafficstop_config.dist.lua @@ -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 diff --git a/sonorancad/configuration/wraithv2_config.dist.lua b/sonorancad/configuration/wraithv2_config.dist.lua index a137cf2..42c0b8f 100644 --- a/sonorancad/configuration/wraithv2_config.dist.lua +++ b/sonorancad/configuration/wraithv2_config.dist.lua @@ -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 diff --git a/sonorancad/core/configuration.lua b/sonorancad/core/configuration.lua index e2901c7..5040ab4 100644 --- a/sonorancad/core/configuration.lua +++ b/sonorancad/core/configuration.lua @@ -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( @@ -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( @@ -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 diff --git a/sonorancad/submodules/ts3integration/sv_ts3integration.js b/sonorancad/submodules/ts3integration/sv_ts3integration.js index a80bb15..bb5dd43 100644 --- a/sonorancad/submodules/ts3integration/sv_ts3integration.js +++ b/sonorancad/submodules/ts3integration/sv_ts3integration.js @@ -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 . */ -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");