From fb36fb03f7e116801ab07bce9865e50b141b89f3 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Fri, 26 Oct 2018 21:08:34 +0100 Subject: [PATCH] Update to ExpGamingCore.Command for when command-run is printed --- FactorioSoftmodManager.lua | 2 +- modules/ExpGamingCore/Command/control.lua | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/FactorioSoftmodManager.lua b/FactorioSoftmodManager.lua index dc213a88..07807b07 100644 --- a/FactorioSoftmodManager.lua +++ b/FactorioSoftmodManager.lua @@ -7,7 +7,7 @@ local moduleIndex = require("/modules/index") local Manager = {} -- this is a constant that is used to represent the server -SERVER = setmetatable({index=0,name='',online_time=0,afk_time=0,print=print},{__index=function(tbl,key) if type(game.player[key]) == 'function' then return function() end else return nil end end}) +SERVER = setmetatable({index=0,name='',online_time=0,afk_time=0,print=print,admin=true},{__index=function(tbl,key) if type(game.players[1][key]) == 'function' then return function() end else return nil end end}) --- Setup for metatable of the Manager to force read only nature -- @usage Manager() -- runs Manager.loadModdules() diff --git a/modules/ExpGamingCore/Command/control.lua b/modules/ExpGamingCore/Command/control.lua index f0d927af..523152ab 100644 --- a/modules/ExpGamingCore/Command/control.lua +++ b/modules/ExpGamingCore/Command/control.lua @@ -206,21 +206,21 @@ end -- @tparam table command the event rasied by the command local function run_custom_command(command) local data = commands.data[command.name] - local player_name = Game.get_player(command) and Game.get_player(command).name or 'server' + local player = Game.get_player(command) or SERVER -- runs all middle ware if any, if there is no middle where then it relyis on .default_admin_only if #middleware > 0 then for _,callback in pairs(middleware) do local success, err = pcall(callback,player_name,command.name,command) if not success then error(err) elseif not err then player_return({'ExpGamingCore_Command.unauthorized'},defines.textcolor.crit) - logMessage(player_name,command,'Failed to use command (Unauthorized)',commands.validate_args(command)) - if game.player then game.player.play_sound{path='utility/cannot_build'} end + logMessage(player.name,command,'Failed to use command (Unauthorized)',commands.validate_args(command)) + game.player.play_sound{path='utility/cannot_build'} return end - end elseif data.default_admin_only == true and game.player and not game.player.admin then + end elseif data.default_admin_only == true and player and not player.admin then player_return({'ExpGamingCore_Command.unauthorized'},defines.textcolor.crit) - logMessage(player_name,command,'Failed to use command (Unauthorized)',commands.validate_args(command)) - if game.player then game.player.play_sound{path='utility/cannot_build'} end + logMessage(player.name,command,'Failed to use command (Unauthorized)',commands.validate_args(command)) + game.player.play_sound{path='utility/cannot_build'} return end -- gets the args for the command @@ -228,15 +228,15 @@ local function run_custom_command(command) if args == commands.error then if is_type(err,'table') then table.insert(err,command.name) table.insert(err,commands.format_inputs(data)) player_return(err,defines.textcolor.high) else player_return({'ExpGamingCore_Command.invalid-inputs',command.name,commands.format_inputs(data)},defines.textcolor.high) end - logMessage(player_name,command,'Failed to use command (Invalid Args)',args) - if game.player then game.player.play_sound{path='utility/deconstruct_big'} end + logMessage(player.name,command,'Failed to use command (Invalid Args)',args) + player.play_sound{path='utility/deconstruct_big'} return end -- runs the command local success, err = pcall(data.callback,command,args) if not success then error(err) end - if err ~= commands.error and player_name ~= 'server' then player_return({'ExpGamingCore_Command.command-ran'},defines.textcolor.info) end - logMessage(player_name,command,'Used command',args) + if err ~= commands.error and player ~= SERVER then player_return({'ExpGamingCore_Command.command-ran'},defines.textcolor.info) end + logMessage(player.name,command,'Used command',args) end --- Used to define commands