You've already forked ComfyFactorio
mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2025-11-29 22:47:52 +02:00
Add the ability to connect to other servers via ingame
This commit is contained in:
@@ -28,6 +28,9 @@ local Public = {}
|
||||
local server_time = {secs = nil, tick = 0}
|
||||
local server_ups = {ups = 60}
|
||||
local start_data = {server_id = nil, server_name = nil, start_time = nil}
|
||||
local instances = {
|
||||
data = {}
|
||||
}
|
||||
local requests = {}
|
||||
|
||||
Global.register(
|
||||
@@ -35,13 +38,15 @@ Global.register(
|
||||
server_time = server_time,
|
||||
server_ups = server_ups,
|
||||
start_data = start_data,
|
||||
requests = requests
|
||||
requests = requests,
|
||||
instances = instances
|
||||
},
|
||||
function(tbl)
|
||||
server_time = tbl.server_time
|
||||
server_ups = tbl.server_ups
|
||||
start_data = tbl.start_data
|
||||
requests = tbl.requests
|
||||
instances = tbl.instances
|
||||
end
|
||||
)
|
||||
|
||||
@@ -494,6 +499,26 @@ function Public.ping(func_token)
|
||||
raw_print(message)
|
||||
end
|
||||
|
||||
--- The backend sets instances with data so a player
|
||||
-- can easily connect to another one via in-game.
|
||||
-- @param data<table>
|
||||
function Public.set_instances(data)
|
||||
if not data then
|
||||
return
|
||||
end
|
||||
if not type(data) == 'table' then
|
||||
return
|
||||
end
|
||||
for id, tbl in pairs(data) do
|
||||
instances.data[id] = tbl
|
||||
end
|
||||
end
|
||||
|
||||
--- Gets each available/non-available instance
|
||||
function Public.get_instances()
|
||||
return instances.data
|
||||
end
|
||||
|
||||
local function double_escape(str)
|
||||
-- Excessive escaping because the data is serialized twice.
|
||||
return str:gsub('\\', '\\\\\\\\'):gsub('"', '\\\\\\"'):gsub('\n', '\\\\n')
|
||||
|
||||
Reference in New Issue
Block a user