1
0
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:
Gerkiz
2022-01-18 00:07:25 +01:00
parent 547c6dadd4
commit bd906f8e7f
4 changed files with 253 additions and 1 deletions

View File

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