This commit is contained in:
Cooldude2606
2018-10-19 19:50:28 +01:00
parent b64dd778da
commit de993dc51a
15 changed files with 100 additions and 82 deletions

View File

@@ -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]

View File

@@ -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

View File

@@ -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})

View File

@@ -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

View File

@@ -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

View File

@@ -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