Add exp_server_list to replace expcore/external

The controller keeps a record per instance with its name, mod pack,
Factorio version, players online, status and address, and the instance
plugin pushes the list into lua over rcon. The readme and the connect
commands read it through modules/exp_server_list, so expcore/external
and its hardcoded server fallback are removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
bbassieandClaude Opus 5.5 committed 2026-10-14 21:35:33 +00:00
1 parent b19bbbe5f3
commit 4d136853c9
31 files changed
+1367 -307

No files matched your search

+49 -52
View File
@@ -5,50 +5,56 @@ Adds a commands that allows you to request a player move to another server
local Async = require("modules/exp_util/async")
local Commands = require("modules/exp_commands")
local External = require("modules.exp_legacy.expcore.external") --- @dep expcore.external
local request_connection_async = Async.register(External.request_connection)
local ExpServerList = require("modules/exp_server_list")
local request_connection_async = Async.register(ExpServerList.request_connection)
local concat = table.concat
--- Convert a server name into a server id, is not an Commands.InputParser because it does not accept addresses
--- @param server string
--- @return boolean, LocalisedString # True for success
local function get_server_id(server)
local servers = External.get_servers_filtered(server)
local current_server = External.get_current_server()
local current_version = current_server.version
--- Find the one server matching a name, is not an Commands.InputParser because it does not accept addresses
--- @param search string
--- @return boolean, LocalisedString | ExpServerList.Server # True for success
local function find_server(search)
local current_server = ExpServerList.get_current() --- @cast current_server -nil
local found = ExpServerList.find_servers(search)
local server_names_before, server_names = {}, {}
local server_count_before, server_count = 0, 0
for next_server_id, server_details in pairs(servers) do
server_count_before = server_count_before + 1
server_names_before[server_count_before] = server_details.name
if server_details.version == current_version then
server_count = server_count + 1
server_names[server_count] = server_details.name
else
servers[next_server_id] = nil
local names_all, names = {}, {}
local matching = {} --- @type ExpServerList.Server[]
for index, server in ipairs(found) do
names_all[index] = server.name
if server.factorio_version == current_server.factorio_version then
matching[#matching + 1] = server
names[#names + 1] = server.name
end
end
if server_count > 1 then
return false, { "exp-commands_connect.too-many-matching", concat(server_names, ", ") }
elseif server_count == 1 then
local server_id, server_details = next(servers) --- @cast server_details -nil
local status = External.get_server_status(server_id)
if server_id == current_server.id then
return false, { "exp-commands_connect.same-server", server_details.name }
elseif status == "Offline" then
return false, { "exp-commands_connect.offline", server_details.name }
if #matching > 1 then
return false, { "exp-commands_connect.too-many-matching", concat(names, ", ") }
elseif #matching == 1 then
local server = matching[1]
if server.id == current_server.id then
return false, { "exp-commands_connect.same-server", server.name }
elseif not ExpServerList.is_online(server) then
return false, { "exp-commands_connect.offline", server.name }
end
return true, server_id --[[@as string]]
elseif server_count_before > 0 then
return false, { "exp-commands_connect.wrong-version", concat(server_names_before, ", ") }
return true, server
elseif #found > 0 then
return false, { "exp-commands_connect.wrong-version", concat(names_all, ", ") }
else
return false, { "exp-commands_connect.none-matching" }
end
end
--- Resolve the server argument to a server, or leave it as an address
--- @param server string
--- @param is_address boolean?
--- @return boolean, LocalisedString | ExpServerList.Server | string # True for success
local function resolve_server(server, is_address)
if is_address or not ExpServerList.get_current() then
return true, server
end
return find_server(server)
end
--- Connect to a different server
Commands.new("connect", { "exp-commands_connect.description" })
:argument("server", { "exp-commands_connect.arg-server" }, Commands.types.string)
@@ -57,15 +63,12 @@ Commands.new("connect", { "exp-commands_connect.description" })
:register(function(player, server, is_address)
--- @cast server string
--- @cast is_address boolean?
if not is_address and External.valid() then
local success, result = get_server_id(server)
if not success then
return Commands.status.invalid_input(result)
end
server = result
local success, result = resolve_server(server, is_address)
if not success then
return Commands.status.invalid_input(result)
end
request_connection_async(player, server, true)
request_connection_async(player, result, true)
end)
--- Connect another player to a different server
@@ -78,15 +81,12 @@ Commands.new("connect-player", { "exp-commands_connect.description-player" })
--- @cast other_player LuaPlayer
--- @cast server string
--- @cast is_address boolean?
if not is_address and External.valid() then
local success, result = get_server_id(server)
if not success then
return Commands.status.invalid_input(result)
end
server = result
local success, result = resolve_server(server, is_address)
if not success then
return Commands.status.invalid_input(result)
end
request_connection_async(other_player, server)
request_connection_async(other_player, result)
end)
--- Connect all players to a different server
@@ -97,15 +97,12 @@ Commands.new("connect-all", { "exp-commands_connect.description-all" })
:register(function(player, server, is_address)
--- @cast server string
--- @cast is_address boolean?
if not is_address and External.valid() then
local success, result = get_server_id(server)
if not success then
return Commands.status.invalid_input(result)
end
server = result
local success, result = resolve_server(server, is_address)
if not success then
return Commands.status.invalid_input(result)
end
for _, next_player in pairs(game.connected_players) do
request_connection_async(next_player, server)
request_connection_async(next_player, result)
end
end)