mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2025-01-20 03:29:47 +02:00
improved server callback
This commit is contained in:
parent
36bb982133
commit
552088b099
@ -699,6 +699,16 @@ function Public.query_online_players()
|
||||
raw_print(message)
|
||||
end
|
||||
|
||||
local function command_handler(callback, ...)
|
||||
if type(callback) == 'function' then
|
||||
local success, err = pcall(callback,...)
|
||||
return success, err
|
||||
else
|
||||
local success, err = pcall(loadstring(callback),...)
|
||||
return success, err
|
||||
end
|
||||
end
|
||||
|
||||
--- The command 'cc' is only used by the server so it can communicate through the webpanel api to the instances that it starts.
|
||||
-- Doing this, enables achivements and the webpanel can communicate without any interruptions.
|
||||
commands.add_command(
|
||||
@ -707,14 +717,13 @@ commands.add_command(
|
||||
function(cmd)
|
||||
local player = game.player
|
||||
if player then return end
|
||||
local param = cmd.parameter
|
||||
|
||||
if param == nil then return end
|
||||
|
||||
local func, err = loadstring(param)
|
||||
if not func then raw_print(err) return end
|
||||
local _, err2 = pcall(func)
|
||||
if err2 then raw_print(err2) return end
|
||||
local callback = cmd.parameter
|
||||
if not callback then return end
|
||||
if not string.find(callback,'%s') and not string.find(callback,'return') then callback = 'return '..callback end
|
||||
local success, err = command_handler(callback)
|
||||
if not success and type(err) == 'string' then local _end = string.find(err,'stack traceback') if _end then err = string.sub(err,0,_end-2) end end
|
||||
if err or err == false then raw_print(err) end
|
||||
end)
|
||||
|
||||
--- The [JOIN] nad [LEAVE] messages Factorio sends to stdout aren't sent in all cases of
|
||||
|
Loading…
x
Reference in New Issue
Block a user