diff --git a/FactorioClient.py b/FactorioClient.py index ce5cee54..9babdc72 100644 --- a/FactorioClient.py +++ b/FactorioClient.py @@ -198,7 +198,7 @@ async def factorio_server_watcher(ctx: FactorioContext): else: item_name = lookup_id_to_name[item_id] 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 await asyncio.sleep(0.1) diff --git a/data/factorio/mod/lib.lua b/data/factorio/mod/lib.lua index 2d77bc95..a341effe 100644 --- a/data/factorio/mod/lib.lua +++ b/data/factorio/mod/lib.lua @@ -20,4 +20,16 @@ function get_any_stack_size(name) end -- failsafe 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 \ No newline at end of file diff --git a/data/factorio/mod_template/control.lua b/data/factorio/mod_template/control.lua index 56536be0..f83f04e0 100644 --- a/data/factorio/mod_template/control.lua +++ b/data/factorio/mod_template/control.lua @@ -220,14 +220,20 @@ end) commands.add_command("ap-get-technology", "Grant a technology, used by the Archipelago Client.", function(call) local force = game.forces["player"] - chunks = {} - for substring in call.parameter:gmatch("%S+") do -- split on " " - table.insert(chunks, substring) - end + chunks = split(call.parameter, "\t") 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] + 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 game.print({"", "Received [technology=" .. tech.name .. "] from ", source}) game.play_sound({path="utility/research_completed"})