Factorio: correctly display player names with spaces and detect desyncs
This commit is contained in:
parent
5943c8975a
commit
c669bc3e7f
|
@ -198,7 +198,7 @@ async def factorio_server_watcher(ctx: FactorioContext):
|
||||||
else:
|
else:
|
||||||
item_name = lookup_id_to_name[item_id]
|
item_name = lookup_id_to_name[item_id]
|
||||||
factorio_server_logger.info(f"Sending {item_name} to Nauvis from {player_name}.")
|
factorio_server_logger.info(f"Sending {item_name} to Nauvis from {player_name}.")
|
||||||
ctx.rcon_client.send_command(f'/ap-get-technology {item_name} {player_name}')
|
ctx.rcon_client.send_command(f'/ap-get-technology {item_name}\t{ctx.send_index}\t{player_name}')
|
||||||
ctx.send_index += 1
|
ctx.send_index += 1
|
||||||
await asyncio.sleep(0.1)
|
await asyncio.sleep(0.1)
|
||||||
|
|
||||||
|
|
|
@ -20,4 +20,16 @@ function get_any_stack_size(name)
|
||||||
end
|
end
|
||||||
-- failsafe
|
-- failsafe
|
||||||
return 1
|
return 1
|
||||||
|
end
|
||||||
|
|
||||||
|
-- from https://stackoverflow.com/a/40180465
|
||||||
|
-- split("a,b,c", ",") => {"a", "b", "c"}
|
||||||
|
function split(s, sep)
|
||||||
|
local fields = {}
|
||||||
|
|
||||||
|
sep = sep or " "
|
||||||
|
local pattern = string.format("([^%s]+)", sep)
|
||||||
|
string.gsub(s, pattern, function(c) fields[#fields + 1] = c end)
|
||||||
|
|
||||||
|
return fields
|
||||||
end
|
end
|
|
@ -220,14 +220,20 @@ end)
|
||||||
|
|
||||||
commands.add_command("ap-get-technology", "Grant a technology, used by the Archipelago Client.", function(call)
|
commands.add_command("ap-get-technology", "Grant a technology, used by the Archipelago Client.", function(call)
|
||||||
local force = game.forces["player"]
|
local force = game.forces["player"]
|
||||||
chunks = {}
|
chunks = split(call.parameter, "\t")
|
||||||
for substring in call.parameter:gmatch("%S+") do -- split on " "
|
|
||||||
table.insert(chunks, substring)
|
|
||||||
end
|
|
||||||
local tech_name = chunks[1]
|
local tech_name = chunks[1]
|
||||||
local source = chunks[2] or "Archipelago"
|
local index = chunks[2]
|
||||||
|
local source = chunks[3] or "Archipelago"
|
||||||
local tech = force.technologies[tech_name]
|
local tech = force.technologies[tech_name]
|
||||||
|
|
||||||
if tech ~= nil then
|
if tech ~= nil then
|
||||||
|
if global.index_sync == nil then
|
||||||
|
global.index_sync = {}
|
||||||
|
end
|
||||||
|
if global.index_sync[index] ~= nil and global.index_sync[index] ~= tech then
|
||||||
|
game.print("Warning: Desync Detected. Duplicate/Missing items may occur.")
|
||||||
|
end
|
||||||
|
global.index_sync[index] = tech
|
||||||
if tech.researched ~= true then
|
if tech.researched ~= true then
|
||||||
game.print({"", "Received [technology=" .. tech.name .. "] from ", source})
|
game.print({"", "Received [technology=" .. tech.name .. "] from ", source})
|
||||||
game.play_sound({path="utility/research_completed"})
|
game.play_sound({path="utility/research_completed"})
|
||||||
|
|
Loading…
Reference in New Issue