mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-19 07:33:12 +09:00
Fix Lua UDP before startup and without script commands
send_udp and get_host_udp_port indexed script data that is only created on the first tick after patching, so calling them from on_init stopped the server. They now return nothing until then. Received packets were only polled once the host port was known, which needs script commands. Poll whenever recv_udp exists instead, it does nothing when the server runs without --enable-lua-udp. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
25c3c9991e
commit
0a6f614074
3 files changed
+64
-5
No files matched your search
@@ -12,14 +12,17 @@ local function check_patch()
|
||||
end
|
||||
end
|
||||
|
||||
-- Added in Factorio 2.0.59, indexing a missing key on a LuaObject errors
|
||||
local has_recv_udp = helpers ~= nil and pcall(function() return helpers.recv_udp end)
|
||||
|
||||
local impl = {}
|
||||
impl.events = {}
|
||||
|
||||
impl.events[defines.events.on_tick] = function()
|
||||
check_patch()
|
||||
-- Dispatch on_udp_packet_received for packets sent by the host
|
||||
local clusterio = compat.script_data.clusterio
|
||||
if clusterio and clusterio.host_udp_port then
|
||||
-- Dispatch on_udp_packet_received for packets sent by the host, this is
|
||||
-- a no-op when the server was started without --enable-lua-udp
|
||||
if has_recv_udp then
|
||||
helpers.recv_udp(0)
|
||||
end
|
||||
end
|
||||
@@ -115,7 +118,9 @@ remote.add_interface('clusterio_api', {
|
||||
end,
|
||||
|
||||
get_host_udp_port = function()
|
||||
return compat.script_data.clusterio.host_udp_port
|
||||
-- Not initialised until the first tick after the save is patched
|
||||
local clusterio = compat.script_data.clusterio
|
||||
return clusterio and clusterio.host_udp_port
|
||||
end,
|
||||
|
||||
get_file_no = function()
|
||||
|
||||
Reference in new issue
Block a user