From de993dc51a06268e9aa7a6b258fa767afd4b4785 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Fri, 19 Oct 2018 19:50:28 +0100 Subject: [PATCH] Bug Bash --- FactorioSoftmodManager.lua | 32 +++++---- control.lua | 2 +- modules/ExpGamingBot/autoChat/control.lua | 79 +++++++++++---------- modules/ExpGamingBot/autoChat/softmod.json | 1 + modules/ExpGamingCommands/bonus/control.lua | 2 +- modules/ExpGamingCore/Command/control.lua | 8 +-- modules/ExpGamingCore/Command/locale/en.cfg | 2 +- modules/ExpGamingCore/Gui/control.lua | 2 +- modules/ExpGamingCore/Gui/src/inputs.lua | 2 +- modules/ExpGamingCore/Gui/src/left.lua | 2 + modules/ExpGamingCore/Server/control.lua | 14 ++-- modules/ExpGamingLib/control.lua | 6 +- modules/ExpGamingPlayer/polls/control.lua | 13 ++-- modules/GuiAnnouncements/control.lua | 11 ++- modules/WarpPoints/src/commands.lua | 6 +- 15 files changed, 100 insertions(+), 82 deletions(-) diff --git a/FactorioSoftmodManager.lua b/FactorioSoftmodManager.lua index d539699b..21f51194 100644 --- a/FactorioSoftmodManager.lua +++ b/FactorioSoftmodManager.lua @@ -235,7 +235,7 @@ Manager.sandbox = setmetatable({ loaded_modules={}, -- this is over riden later module_verbose=false, module_exports=false, - _no_error_in_sandbox=true + _no_error_verbose=true },{ __metatable=false, __index=ReadOnlyManager, @@ -253,8 +253,8 @@ Manager.sandbox = setmetatable({ local success = table.remove(rtn,1) -- this is to allow modules to be access with out the need of using Mangaer[name] also keeps global clean setmetatable(_G,old_mt) - if success then return sandbox, success, rtn - else return sandbox, success, rtn[1] end + if success then return success, rtn, sandbox + else return success, rtn[1], sandbox end else return setmetatable({},{__index=tbl}) end end }) @@ -274,7 +274,7 @@ Manager.require = setmetatable({ local raw_require = rawget(tbl,'__require') local env = env or {} -- runs in a sand box becuase sandbox everything - local sandbox, success, data = Manager.sandbox(raw_require,env,path) + local success, data = Manager.sandbox(raw_require,env,path) -- if there was no error then it assumed the path existed and returns the data if success then return unpack(data) else @@ -319,7 +319,7 @@ Manager.loadModules = setmetatable({}, for module_name,path in pairs(moduleIndex) do Manager.verbose('Loading module: "'..module_name..'"; path: '..path) -- runs the module in a sandbox env - local sandbox, success, module = Manager.sandbox(Manager.require.__require,{module_name=setupModuleName(module_name),module_path=path},path..'/control') + local success, module, sandbox = Manager.sandbox(Manager.require.__require,{module_name=setupModuleName(module_name),module_path=path},path..'/control') -- extracts the module into a global index table for later use if success then -- verbose to notifie of any globals that were attempted to be created @@ -375,7 +375,7 @@ Manager.loadModules = setmetatable({}, if type(data) == 'table' and data.init and data.on_init == nil then data.on_init = data.init data.init = nil end if type(data) == 'table' and data.on_init and type(data.on_init) == 'function' then Manager.verbose('Initiating module: "'..module_name..'"') - local sandbox, success, err = Manager.sandbox(data.on_init,{module_name=setupModuleName(module_name),module_path=moduleIndex[tostring(module_name)]},data) + local success, err = Manager.sandbox(data.on_init,{module_name=setupModuleName(module_name),module_path=moduleIndex[tostring(module_name)]},data) if success then Manager.verbose('Successfully Initiated: "'..module_name..'"') else @@ -393,7 +393,7 @@ Manager.loadModules = setmetatable({}, if type(data) == 'table' and data.post and data.on_post == nil then data.on_post = data.post data.post = nil end if type(data) == 'table' and data.on_post and type(data.on_post) == 'function' then Manager.verbose('Post for module: "'..module_name..'"') - local sandbox, success, err = Manager.sandbox(data.on_post,{module_name=setupModuleName(module_name),module_path=moduleIndex[tostring(module_name)]},data) + local success, err = Manager.sandbox(data.on_post,{module_name=setupModuleName(module_name),module_path=moduleIndex[tostring(module_name)]},data) if success then Manager.verbose('Successful post: "'..module_name..'"') else @@ -446,6 +446,14 @@ Manager.error = setmetatable({ if type(handler_name) == 'string' and type(callback) == 'function' then Manager.error[handler_name]=callback elseif type(handler_name) == 'function' then table.insert(Manager.error,handler_name) else Manager.error('Handler is not a function',2) end + end, + in_pcall=function(level) + local level = level and level+1 or 2 + while true do + if not debug.getinfo(level) then return false end + if debug.getinfo(level).name == 'pcall' then return level end + level=level+1 + end end },{ __metatalbe=false, @@ -453,9 +461,9 @@ Manager.error = setmetatable({ -- if no params then return the error constant if err == nil then return rawget(tbl,'__error_const') end -- if the error constant is given crash game - if err == rawget(tbl,'__error_const') then Manager.verbose('Force Stop','errorCaught') rawget(tbl,'__error_call')('Force Stop',2) end + if err == rawget(tbl,'__error_const') then Manager.verbose('Force Crash','errorCaught') rawset(tbl,'__crash',true) rawget(tbl,'__error_call')('Force Crash',2) end -- other wise treat the call as if its been passed an err string - if _G._no_error_in_sandbox and ReadOnlyManager.currentState == 'moduleEnv' then else Manager.verbose('An error has occurred: '..err,'errorCaught') end + if not _no_error_verbose or Manager.currentState ~= 'moduleEnv' then Manager.verbose('An error has occurred: '..err,'errorCaught') end if #tbl > 0 then -- there is at least one error handler loaded; loops over the error handlers for handler_name,callback in pairs(tbl) do @@ -476,7 +484,7 @@ Manager.error = setmetatable({ end local args = {...} local trace = args[1] and type(args[1]) == 'number' and args[1]+1 or 2 - rawget(tbl,'__error_call')(err,trace) + if tbl.in_pcall(2) then rawget(tbl,'__error_call')(err,trace) end end, __index=function(tbl,key) -- this allows the __error_handler to be called from many different names @@ -503,7 +511,7 @@ Manager.error = setmetatable({ local function next_pair(tbl,k) local v k, v = next(tbl, k) - if k == '__error_call' or k == '__error_const' or k == '__error_handler' or k == '__crash' then return next_pair(tbl,k) end + if k == '__error_call' or k == '__error_const' or k == '__error_handler' or k == '__crash' or k == 'in_pcall' then return next_pair(tbl,k) end if type(v) == 'function' then return k,v end end return next_pair, tbl, nil @@ -560,7 +568,7 @@ Manager.event = setmetatable({ for module_name,callback in pairs(event_functions) do -- loops over the call backs and which module it is from if type(callback) ~= 'function' then error('Invalid Event Callback: "'..event_name..'/'..module_name..'"') end - local sandbox, success, err = Manager.sandbox(callback,{module_name=setupModuleName(module_name),module_path=moduleIndex[tostring(module_name)]},new_callback,...) + local success, err = Manager.sandbox(callback,{module_name=setupModuleName(module_name),module_path=moduleIndex[tostring(module_name)]},new_callback,...) if not success then local chache = tbl.error_chache local error_message = 'Event Failed: "'..module_name..'/'..tbl.names[event_name]..'" ('..err..')' diff --git a/control.lua b/control.lua index 1c352a55..c5e46030 100644 --- a/control.lua +++ b/control.lua @@ -6,7 +6,7 @@ Manager.setVerbose{ moduleLoad=false, -- when a module is required by the manager moduleInit=false, -- when and within the initation of a module modulePost=false, -- when and within the post of a module - moduleEnv=false, -- during module runtime, this is a global option set within each module for fine control + moduleEnv=true, -- during module runtime, this is a global option set within each module for fine control eventRegistered=false, -- when a module registers its event handlers errorCaught=true, -- when an error is caught during runtime output=Manager._verbose -- can be: can be: print || log || other function diff --git a/modules/ExpGamingBot/autoChat/control.lua b/modules/ExpGamingBot/autoChat/control.lua index aa40b6e7..ac0b65cb 100644 --- a/modules/ExpGamingBot/autoChat/control.lua +++ b/modules/ExpGamingBot/autoChat/control.lua @@ -6,6 +6,7 @@ -- Module Require local Game = require('FactorioStdLib.Game@^0.8.0') +local Server = require('ExpGamingCore.Server@^4.0.0') local Role -- ExpGamingCore.Role@^4.0.0 -- Local Varibles @@ -36,84 +37,84 @@ local messages = { -- comands start with ! (all messages are also commands) local command_syntax = '!' local commands = { - ['online']=function(player) return {'chat-bot.players-online',#game.connected_players} end, - ['playtime']=function(player) return {'chat-bot.map-time',tick_to_display_format(game.tick)} end, - ['players']=function(player) return {'chat-bot.players',#game.players} end, - ['dev']={'chat-bot.not-real-dev'}, - ['blame']=function(player) local names = {'Cooldude2606','arty714','badgamernl',player.name} return {'chat-bot.blame',names[math.random(#names)]} end, - ['readme']={'chat-bot.read-readme'}, - ['magic']={'chat-bot.magic'}, - ['aids']={'chat-bot.aids'}, - ['riot']={'chat-bot.riot'}, - ['lenny']={'chat-bot.lenny'}, - ['feedback']={'chat-bot.feedback'}, - ['wiki']={'chat-bot.wiki'}, - ['hodor']=function(player) local options = {'?','.','!','!!!'} return {'chat-bot.hodor',options[math.random(#options)]} end, - ['evolution']=function(player) return {'chat-bot.current-evolution',string.format('%.2f',game.forces['enemy'].evolution_factor)} end, + ['online']=function(player) return {'ExpGamingBot-autoChat.players-online',#game.connected_players} end, + ['playtime']=function(player) return {'ExpGamingBot-autoChat.map-time',tick_to_display_format(game.tick)} end, + ['players']=function(player) return {'ExpGamingBot-autoChat.players',#game.players} end, + ['dev']={'ExpGamingBot-autoChat.not-real-dev'}, + ['blame']=function(player) local names = {'Cooldude2606','arty714','badgamernl',player.name} return {'ExpGamingBot-autoChat.blame',names[math.random(#names)]} end, + ['readme']={'ExpGamingBot-autoChat.read-readme'}, + ['magic']={'ExpGamingBot-autoChat.magic'}, + ['aids']={'ExpGamingBot-autoChat.aids'}, + ['riot']={'ExpGamingBot-autoChat.riot'}, + ['lenny']={'ExpGamingBot-autoChat.lenny'}, + ['feedback']={'ExpGamingBot-autoChat.feedback'}, + ['wiki']={'ExpGamingBot-autoChat.wiki'}, + ['hodor']=function(player) local options = {'?','.','!','!!!'} return {'ExpGamingBot-autoChat.hodor',options[math.random(#options)]} end, + ['evolution']=function(player) return {'ExpGamingBot-autoChat.current-evolution',string.format('%.2f',game.forces['enemy'].evolution_factor)} end, --Jokes about food and drink - ['whattoeat']={'chat-bot.food'}, + ['whattoeat']={'ExpGamingBot-autoChat.food'}, ['makepopcorn']=function(player) Server.new_thread{ timeout=math.floor(180*(math.random()+0.5)),data=player.name }:on_event('timeout',function(self) - if self.data then game.print{'chat-bot.message',{'chat-bot.get-popcorn-2',self.data}} end - end):open() return {'chat-bot.get-popcorn-1'} end, + if self.data then game.print{'ExpGamingBot-autoChat.message',{'ExpGamingBot-autoChat.get-popcorn-2',self.data}} end + end):open() return {'ExpGamingBot-autoChat.get-popcorn-1'} end, ['orderpizza']=function(player) Server.new_thread{ timeout=math.floor(180*(math.random()+0.5)),data={player.name,0}, reopen=true }:on_event('timeout',function(self) - if self.data[2]==0 then game.print{'chat-bot.message',{'chat-bot.order-pizza-2',self.data[1]}} - elseif self.data[2]==1 then game.print{'chat-bot.message',{'chat-bot.order-pizza-3',self.data[1]}} self.reopen = false + if self.data[2]==0 then game.print{'ExpGamingBot-autoChat.message',{'ExpGamingBot-autoChat.order-pizza-2',self.data[1]}} + elseif self.data[2]==1 then game.print{'ExpGamingBot-autoChat.message',{'ExpGamingBot-autoChat.order-pizza-3',self.data[1]}} self.reopen = false end self.data[2]=self.data[2]+1 - end):open() return {'chat-bot.order-pizza-1'} end, + end):open() return {'ExpGamingBot-autoChat.order-pizza-1'} end, ['passsomesnaps']=function(player) Server.new_thread{ timeout=math.floor(180*(math.random()+0.5)),data={player.name,0}, reopen=true }:on_event('timeout',function(self) - if self.data[2]==0 then game.print{'chat-bot.message',{'chat-bot.get-snaps-2',self.data[1]}} - elseif self.data[2]==1 then game.print{'chat-bot.message',{'chat-bot.get-snaps-3',self.data[1]}} self.reopen = false + if self.data[2]==0 then game.print{'ExpGamingBot-autoChat.message',{'ExpGamingBot-autoChat.get-snaps-2',self.data[1]}} + elseif self.data[2]==1 then game.print{'ExpGamingBot-autoChat.message',{'ExpGamingBot-autoChat.get-snaps-3',self.data[1]}} self.reopen = false end self.data[2]=self.data[2]+1 - end):open() return {'chat-bot.get-snaps-1'} end, + end):open() return {'ExpGamingBot-autoChat.get-snaps-1'} end, ['makecocktail']=function(player) Server.new_thread{ timeout=math.floor(180*(math.random()+0.5)),data={player.name,0}, reopen=true }:on_event('timeout',function(self) - if self.data[2]==0 then game.print{'chat-bot.message',{'chat-bot.get-cocktail-2',self.data[1]}} - elseif self.data[2]==1 then game.print{'chat-bot.message',{'chat-bot.get-cocktail-3',self.data[1]}} self.reopen = false + if self.data[2]==0 then game.print{'ExpGamingBot-autoChat.message',{'ExpGamingBot-autoChat.get-cocktail-2',self.data[1]}} + elseif self.data[2]==1 then game.print{'ExpGamingBot-autoChat.message',{'ExpGamingBot-autoChat.get-cocktail-3',self.data[1]}} self.reopen = false end self.data[2]=self.data[2]+1 - end):open() return {'chat-bot.get-cocktail-1'} end, + end):open() return {'ExpGamingBot-autoChat.get-cocktail-1'} end, ['makecoffee']=function(player) Server.new_thread{ timeout=math.floor(180*(math.random()+0.5)),data=player.name }:on_event('timeout',function(self) - if self.data then game.print{'chat-bot.message',{'chat-bot.make-coffee-2',self.data}} end - end):open() return {'chat-bot.make-coffee-1'} end, + if self.data then game.print{'ExpGamingBot-autoChat.message',{'ExpGamingBot-autoChat.make-coffee-2',self.data}} end + end):open() return {'ExpGamingBot-autoChat.make-coffee-1'} end, ['orderpizza']=function(player) Server.new_thread{ timeout=math.floor(180*(math.random()+0.5)),data={player.name,0}, reopen=true }:on_event('timeout',function(self) - if self.data[2]==0 then game.print{'chat-bot.message',{'chat-bot.order-pizza-2',self.data[1]}} - elseif self.data[2]==1 then game.print{'chat-bot.message',{'chat-bot.order-pizza-3',self.data[1]}} self.reopen = false + if self.data[2]==0 then game.print{'ExpGamingBot-autoChat.message',{'ExpGamingBot-autoChat.order-pizza-2',self.data[1]}} + elseif self.data[2]==1 then game.print{'ExpGamingBot-autoChat.message',{'ExpGamingBot-autoChat.order-pizza-3',self.data[1]}} self.reopen = false end self.data[2]=self.data[2] + 1 - end):open() return {'chat-bot.order-pizza-1'} end, + end):open() return {'ExpGamingBot-autoChat.order-pizza-1'} end, ['maketea']=function(player) Server.new_thread{ timeout=math.floor(180*(math.random()+0.5)),data=player.name }:on_event('timeout',function(self) - if self.data then game.print{'chat-bot.message',{'chat-bot.make-tea-2',self.data}} end - end):open() return {'chat-bot.make-tea-1'} end, + if self.data then game.print{'ExpGamingBot-autoChat.message',{'ExpGamingBot-autoChat.make-tea-2',self.data}} end + end):open() return {'ExpGamingBot-autoChat.make-tea-1'} end, ['popcorn']=function(player) Server.new_thread{ timeout=math.floor(180*(math.random()+0.5)),data=player.name }:on_event('timeout',function(self) - if self.data then game.print{'chat-bot.message',{'chat-bot.get-popcorn-2',self.data}} end - end):open() return {'chat-bot.get-popcorn-1'} end, + if self.data then game.print{'ExpGamingBot-autoChat.message',{'ExpGamingBot-autoChat.get-popcorn-2',self.data}} end + end):open() return {'ExpGamingBot-autoChat.get-popcorn-1'} end, ['meadplease']=function(player) Server.new_thread{ timeout=math.floor(180*(math.random()+0.5)),data=player.name }:on_event('timeout',function(self) - if self.data then game.print{'chat-bot.message',{'chat-bot.get-mead-2',self.data}} end - end):open() return {'chat-bot.get-mead-1'} end, + if self.data then game.print{'ExpGamingBot-autoChat.message',{'ExpGamingBot-autoChat.get-mead-2',self.data}} end + end):open() return {'ExpGamingBot-autoChat.get-mead-1'} end, ['passabeer']=function(player) Server.new_thread{ timeout=math.floor(180*(math.random()+0.5)),data=player.name }:on_event('timeout',function(self) - if self.data then game.print{'chat-bot.message',{'chat-bot.get-beer-2',self.data}} end - end):open() return {'chat-bot.get-beer-1'} end + if self.data then game.print{'ExpGamingBot-autoChat.message',{'ExpGamingBot-autoChat.get-beer-2',self.data}} end + end):open() return {'ExpGamingBot-autoChat.get-beer-1'} end } -- Module Define diff --git a/modules/ExpGamingBot/autoChat/softmod.json b/modules/ExpGamingBot/autoChat/softmod.json index aced75b3..22f4c342 100644 --- a/modules/ExpGamingBot/autoChat/softmod.json +++ b/modules/ExpGamingBot/autoChat/softmod.json @@ -12,6 +12,7 @@ ], "dependencies": { "FactorioStdLib.Game": "^0.8.0", + "ExpGamingCore.Server": "^4.0.0", "ExpGamingCore.Role": "?^4.0.0" }, "collection": "ExpGamingBot_4.0.0" diff --git a/modules/ExpGamingCommands/bonus/control.lua b/modules/ExpGamingCommands/bonus/control.lua index 3ef95ddc..452005d9 100644 --- a/modules/ExpGamingCommands/bonus/control.lua +++ b/modules/ExpGamingCommands/bonus/control.lua @@ -33,7 +33,7 @@ script.on_event(defines.events.on_player_respawned,function(event) local player = Game.get_player(event) local bonus = global[player.index] if bonus then - for _,setting in pairs(settings) do player[key] = setting*math.floor(bonus)*0.01 end + for key,setting in pairs(settings) do player[key] = setting*math.floor(bonus)*0.01 end end end) diff --git a/modules/ExpGamingCore/Command/control.lua b/modules/ExpGamingCore/Command/control.lua index e601441b..d2c35215 100644 --- a/modules/ExpGamingCore/Command/control.lua +++ b/modules/ExpGamingCore/Command/control.lua @@ -59,7 +59,7 @@ commands.validate = { ['string-inf']=function(value,event) return tostring(value) end, ['string-len']=function(value,event,max) local rtn = tostring(value) and tostring(value):len() <= max and tostring(value) or nil - if not rtn then return commands.error{'ExpGamingCore_Command.error-string-len'} end return rtn end, + if not rtn then return commands.error{'ExpGamingCore_Command.error-string-len',max} end return rtn end, ['number']=function(value,event) local rtn = tonumber(value) or nil if not rtn then return commands.error{'ExpGamingCore_Command.error-number'} end return rtn end, @@ -68,10 +68,10 @@ commands.validate = { if not rtn then return commands.error{'ExpGamingCore_Command.error-number'} end return rtn end, ['number-range']=function(value,event,min,max) local rtn = tonumber(value) and tonumber(value) > min and tonumber(value) <= max and tonumber(value) or nil - if not rtn then return commands.error{'ExpGamingCore_Command.error-number-range'} end return rtn end, + if not rtn then return commands.error{'ExpGamingCore_Command.error-number-range',min,max} end return rtn end, ['number-range-int']=function(value,event,min,max) local rtn = tonumber(value) and math.floor(tonumber(value)) > min and math.floor(tonumber(value)) <= max and math.floor(tonumber(value)) or nil - if not rtn then return commands.error{'ExpGamingCore_Command.error-number-range'} end return rtn end, + if not rtn then return commands.error{'ExpGamingCore_Command.error-number-range',min,max} end return rtn end, ['player']=function(value,event) local rtn = Game.get_player(value) or nil if not rtn then return commands.error{'ExpGamingCore_Command.error-player',value} end return rtn end, @@ -266,7 +266,7 @@ commands.add_command = function(name, description, inputs, callback) or commands.format_inputs(name) data[name].help = help commands._add_command(name,help,function(...) - local success, err = pcall(run_custom_command,...) + local success, err = Manager.sandbox(run_custom_command,{},...) if not success then error(err) end end) return data[name] diff --git a/modules/ExpGamingCore/Command/locale/en.cfg b/modules/ExpGamingCore/Command/locale/en.cfg index fe10d443..4a6cbc66 100644 --- a/modules/ExpGamingCore/Command/locale/en.cfg +++ b/modules/ExpGamingCore/Command/locale/en.cfg @@ -2,7 +2,7 @@ unauthorized=401 - Unauthorized: Access is denied due to invalid credentials error-string-len=Invalid Length, Max: __1__ error-number=Invalid Number: Command failed to run -error-number-range=Invalid Range, Min: __1__, Max: __2__ +error-number-range=Invalid Range, Min (exclusive): __1__, Max (inclusive): __2__ error-player=Invaild Player Name, __1__ ,try using tab key to auto-complete the name error-player-online=Player is offline: Command failed to run error-player-alive=Player is dead: Command failed to run diff --git a/modules/ExpGamingCore/Gui/control.lua b/modules/ExpGamingCore/Gui/control.lua index 28fff4b1..bb864a27 100644 --- a/modules/ExpGamingCore/Gui/control.lua +++ b/modules/ExpGamingCore/Gui/control.lua @@ -38,7 +38,7 @@ Gui.inputs = require(module_path..'/src/inputs',{Gui=Gui}) table.merge(events,Gui.inputs._events) Gui.inputs._events = nil -Gui.left = require(module_path..'/src/left',{Gui=Gui,order_config=order_config}) +Gui.left = require(module_path..'/src/left',{Gui=Gui,order_config=order_config,self_global=global}) Gui.popup = require(module_path..'/src/popup',{Gui=Gui}) Gui.toolbar = require(module_path..'/src/toolbar',{Gui=Gui,order_config=order_config}) diff --git a/modules/ExpGamingCore/Gui/src/inputs.lua b/modules/ExpGamingCore/Gui/src/inputs.lua index df89f08e..cbd7d404 100644 --- a/modules/ExpGamingCore/Gui/src/inputs.lua +++ b/modules/ExpGamingCore/Gui/src/inputs.lua @@ -128,7 +128,7 @@ function inputs._event_handler(event) if element then verbose('There was a gui event ('..Event.names[event.name]..') with element: '..event.element.name) if not is_type(element.events[event.name],'function') then return end - local success, err = pcall(element.events[event.name],event) + local success, err = Manager.sandbox(element.events[event.name],{},event) if not success then if is_type(element._error,'function') then pcall(element._error) else error(err) end diff --git a/modules/ExpGamingCore/Gui/src/left.lua b/modules/ExpGamingCore/Gui/src/left.lua index eb9a1a82..3f084bfb 100644 --- a/modules/ExpGamingCore/Gui/src/left.lua +++ b/modules/ExpGamingCore/Gui/src/left.lua @@ -28,6 +28,8 @@ left.hide = Gui.inputs{ end end) +local global = self_global + -- used for debugging function left.override_open(state) global.over_ride_left_can_open = state diff --git a/modules/ExpGamingCore/Server/control.lua b/modules/ExpGamingCore/Server/control.lua index ea7200e6..64f50b59 100644 --- a/modules/ExpGamingCore/Server/control.lua +++ b/modules/ExpGamingCore/Server/control.lua @@ -177,7 +177,7 @@ function Server._thread_handler(event) if thread and thread:valid() then if is_type(thread._events[event_id],'function') then -- runs the function in the same env it was created (avoids desyncs) - local sandbox, success, err = Manager.sandbox(thread._events[event_id],thread._env,thread,event) + local success, err = Manager.sandbox(thread._events[event_id],thread._env,thread,event) -- if there is an error it asks the thread to deal with it if not success then thread:error(err) end end @@ -223,11 +223,11 @@ function Server.interface(callback,use_thread,env,...) callback = is_type(callback,'function') and callback or loadstring(callback) local env = table.remove(thread.data,1) if is_type(env,'table') and env._env == true then - local sandbox, success, err = Manager.sandbox(callback,env,unpack(thread.data)) + local success, err = Manager.sandbox(callback,env,unpack(thread.data)) if not success then error(err) end return err else - local sandbox, success, err = Manager.sandbox(callback,{},env,unpack(thread.data)) + local success, err = Manager.sandbox(callback,{},env,unpack(thread.data)) if not success then error(err) end return err end @@ -243,11 +243,11 @@ function Server.interface(callback,use_thread,env,...) _callback = rtn end if is_type(env,'table') and env._env == true then - local sandbox, success, err = Manager.sandbox(_callback,env,...) + local success, err = Manager.sandbox(_callback,env,...) if not success then return success,err else return success, unpack(err) end else - local sandbox, success, err = Manager.sandbox(_callback,{},env,...) + local success, err = Manager.sandbox(_callback,{},env,...) if not success then return success,err else return success, unpack(err) end end @@ -392,13 +392,13 @@ function Server._thread:resolve(...) local _return = false -- checks if the resolve haddler is still present if is_type(self._resolve,'function') then - local sandbox, success, err = Manager.sandbox(self._resolve,self._env,self,...) + local success, err = Manager.sandbox(self._resolve,self._env,self,...) if success then -- if it was successful then it will attemp to call the success handler if is_type(self._success,'function') then -- interface is used as a way to delay the success call till the next tick Server.interface(function(thread,err) - local sandbox, success, err = Manager.sandbox(thread._success,thread._env,thread,err) + local success, err = Manager.sandbox(thread._success,thread._env,thread,err) if not success then thread:error(err) end end,true,self,err) -- later returns true if there was a call to the success handler diff --git a/modules/ExpGamingLib/control.lua b/modules/ExpGamingLib/control.lua index cf5e9b82..d7f7c97b 100644 --- a/modules/ExpGamingLib/control.lua +++ b/modules/ExpGamingLib/control.lua @@ -24,8 +24,8 @@ end -- @usage get_env() returns current ENV with _G keys removed -- @treturn table the env table with _G keys removed -- @warning does not work from console -function ExpLib.get_env() - local level = 2 +function ExpLib.get_env(level) + local level = level and level+1 or 2 local env = setmetatable({},{__index=_G}) while true do if not debug.getinfo(level-1) then break end @@ -53,7 +53,7 @@ function ExpLib.add_metatable(tbl,callback,string) local string = ExpLib.is_type(string,'function') and string or ExpLib.is_type(string,'string') and function() return string end or table.tostring return setmetatable(tbl,{ __tostring=string, - __concat=function(val1,val2) return type(val1) == 'string' and val1..string() or string()..val2 end, + __concat=function(val1,val2) return type(val1) == 'string' and val1..string(val2) or string(val1)..val2 end, __call=callback }) end diff --git a/modules/ExpGamingPlayer/polls/control.lua b/modules/ExpGamingPlayer/polls/control.lua index 6a92100d..60236409 100644 --- a/modules/ExpGamingPlayer/polls/control.lua +++ b/modules/ExpGamingPlayer/polls/control.lua @@ -27,7 +27,7 @@ local global = global{ -- Function Define local function _poll_end(self) - local uuid = self.data.poll_uuid + local uuid = tostring(self.data.poll_uuid) local poll = global.active[uuid] if not poll then return end local highest = {nil,-1} @@ -37,7 +37,6 @@ local function _poll_end(self) if _result > highest[2] then highest = {answer,_result} end _votes[answer] = _result end - local uuid = poll.uuid poll.uuid = nil poll.votes = _votes poll.answers = nil @@ -46,6 +45,7 @@ local function _poll_end(self) global.active[uuid] = nil game.print({'ExpGamingPlayer-polls.end',poll.question},defines.textcolor.info) game.print({'ExpGamingPlayer-polls.winner',highest[1]},defines.textcolor.info) + verbose('Ended Poll: '..poll.question..' ('..uuid..') Highest: '..highest[1]) end local function _poll_data(question,answers) @@ -61,7 +61,8 @@ local function _poll_data(question,answers) timeout=poll_time_out*60 }:on_event('timeout',_poll_end):open() -- This time out is known to cause desyncs and so I have moved it to a hard coded function - global.active[poll.uuid]=poll + global.active[tostring(poll.uuid)]=poll + verbose('Created Poll: '..question..' ('..poll.uuid..')') return poll.uuid end @@ -212,17 +213,17 @@ ThisModule.Gui = Gui.popup{ frame.style.right_padding = 5 frame.style.bottom_padding = 5 local uuid = data.uuid - local poll = global.active[uuid] + local poll = global.active[tostring(uuid)] if not poll then return end local flow = frame.add{ type='flow', - name=uuid, + name=tostring(uuid), direction='vertical' } flow.add{type='label',caption={'ExpGamingPlayer-polls.time-left',poll_time_out}} flow.add{type='label',caption='Question: '..poll.question} flow.add{type='label',name='answer',caption='Your Answer: None'} - opption_drop_down:draw(flow) + opption_drop_down(flow) end }:add_left{ caption='utility/item_editor_icon', diff --git a/modules/GuiAnnouncements/control.lua b/modules/GuiAnnouncements/control.lua index ac89d552..c2f73c86 100644 --- a/modules/GuiAnnouncements/control.lua +++ b/modules/GuiAnnouncements/control.lua @@ -42,11 +42,16 @@ local send_popup = Gui.inputs{ local role = Role.get_highest(player) local _role = Role.get(event.element.parent.role.caption); if not _role then return end local sent_by = {'GuiAnnouncements.sent-by',player.name,role.name} - local role_name = _role.name..'s'; if rank_name == Role.meta.default.name..'s' then rank_name = 'Everyone' end - local sent_to = {'GuiAnnouncements.sent-to',rank_name} + local role_name = _role.name..'s'; if role_name == Role.meta.default.name..'s' then role_name = 'Everyone' end + local sent_to = {'GuiAnnouncements.sent-to',role_name} local message = event.element.parent.parent.message.text - Gui.popup.open('announcements',{sent_by=sent_by,sent_to=sent_to,message=message},_role:get_players(true)) + local players = _role:get_players(true) + if _role.index == Role.meta.default.index then players = game.connected_players end + Gui.popup.open('announcements',{sent_by=sent_by,sent_to=sent_to,message=message},players) + player_return('Announcement sent to '..#players..' players ('..role_name..')',defines.textcolor.info,player) + verbose('Announcement sent to '..#players..' players ('..role_name..') by '..player.name..'('..role.name..') with message: '..message) event.element.parent.parent.message.text = '' + Gui.left.close('announcements',player) end) ThisModule.Gui = Gui.popup{ diff --git a/modules/WarpPoints/src/commands.lua b/modules/WarpPoints/src/commands.lua index 305605df..24c542cd 100644 --- a/modules/WarpPoints/src/commands.lua +++ b/modules/WarpPoints/src/commands.lua @@ -7,9 +7,9 @@ commands.add_command('make-warp', 'Make a warp point at your location', { if not game.player then return end local position = game.player.position local name = args.name - if game.player.gui.top[name] then player_return({'warp-system.name-used'},defines.textcolor.med) return commands.error end - if warps.warps[name] then player_return({'warp-system.name-used'},defines.textcolor.med) return commands.error end - if position.x^2 + position.y^2 < 100 then player_return({'warp-system.too-close'},defines.textcolor.med) return commands.error end + if game.player.gui.top[name] then player_return({'WarpPoints.name-used'},defines.textcolor.med) return commands.error end + if warps.warps[name] then player_return({'WarpPoints.name-used'},defines.textcolor.med) return commands.error end + if position.x^2 + position.y^2 < 100 then player_return({'WarpPoints.too-close'},defines.textcolor.med) return commands.error end -- to do add a test for all warps self.make_warp_point(position,game.player.surface,game.player.force,name) end) \ No newline at end of file