FactorioClient: Batch-Send RCON commands when receiving catch-up locations and multiple items.
This commit is contained in:
parent
21a5170337
commit
30ac7baa2c
|
@ -109,9 +109,10 @@ class FactorioContext(CommonContext):
|
||||||
def on_package(self, cmd: str, args: dict):
|
def on_package(self, cmd: str, args: dict):
|
||||||
if cmd == "Connected":
|
if cmd == "Connected":
|
||||||
# catch up sync anything that is already cleared.
|
# catch up sync anything that is already cleared.
|
||||||
for tech in args["checked_locations"]:
|
if args["checked_locations"]:
|
||||||
item_name = f"ap-{tech}-"
|
self.rcon_client.send_commands({item_name: f'/ap-get-technology {item_name}\t-1' for
|
||||||
self.rcon_client.send_command(f'/ap-get-technology {item_name}\t-1')
|
item_name in args["checked_locations"]})
|
||||||
|
|
||||||
|
|
||||||
async def game_watcher(ctx: FactorioContext):
|
async def game_watcher(ctx: FactorioContext):
|
||||||
bridge_logger = logging.getLogger("FactorioWatcher")
|
bridge_logger = logging.getLogger("FactorioWatcher")
|
||||||
|
@ -195,11 +196,15 @@ async def factorio_server_watcher(ctx: FactorioContext):
|
||||||
if ctx.mod_version < Utils.Version(0, 1, 6):
|
if ctx.mod_version < Utils.Version(0, 1, 6):
|
||||||
ctx.rcon_client.send_command("/sc game.print('Starting Archipelago Bridge')")
|
ctx.rcon_client.send_command("/sc game.print('Starting Archipelago Bridge')")
|
||||||
ctx.rcon_client.send_command("/sc game.print('Starting Archipelago Bridge')")
|
ctx.rcon_client.send_command("/sc game.print('Starting Archipelago Bridge')")
|
||||||
|
if not ctx.server:
|
||||||
|
logger.info("Established bridge to Factorio Server. "
|
||||||
|
"Ready to connect to Archipelago via /connect")
|
||||||
|
|
||||||
if not ctx.awaiting_bridge and "Archipelago Bridge Data available for game tick " in msg:
|
if not ctx.awaiting_bridge and "Archipelago Bridge Data available for game tick " in msg:
|
||||||
ctx.awaiting_bridge = True
|
ctx.awaiting_bridge = True
|
||||||
|
|
||||||
if ctx.rcon_client:
|
if ctx.rcon_client:
|
||||||
|
commands = {}
|
||||||
while ctx.send_index < len(ctx.items_received):
|
while ctx.send_index < len(ctx.items_received):
|
||||||
transfer_item: NetworkItem = ctx.items_received[ctx.send_index]
|
transfer_item: NetworkItem = ctx.items_received[ctx.send_index]
|
||||||
item_id = transfer_item.item
|
item_id = transfer_item.item
|
||||||
|
@ -209,8 +214,10 @@ async def factorio_server_watcher(ctx: FactorioContext):
|
||||||
else:
|
else:
|
||||||
item_name = Factorio.item_id_to_name[item_id]
|
item_name = Factorio.item_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}\t{ctx.send_index}\t{player_name}')
|
commands[ctx.send_index] = f'/ap-get-technology {item_name}\t{ctx.send_index}\t{player_name}'
|
||||||
ctx.send_index += 1
|
ctx.send_index += 1
|
||||||
|
if commands:
|
||||||
|
ctx.rcon_client.send_commands(commands)
|
||||||
await asyncio.sleep(0.1)
|
await asyncio.sleep(0.1)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
4
Fill.py
4
Fill.py
|
@ -123,11 +123,11 @@ def distribute_items_restrictive(world: MultiWorld, fill_locations=None):
|
||||||
world.random.shuffle(fill_locations)
|
world.random.shuffle(fill_locations)
|
||||||
|
|
||||||
restitempool, fill_locations = fast_fill(world, restitempool, fill_locations)
|
restitempool, fill_locations = fast_fill(world, restitempool, fill_locations)
|
||||||
unplaced = [item for item in progitempool + restitempool]
|
unplaced = progitempool + restitempool
|
||||||
unfilled = [location.name for location in fill_locations]
|
unfilled = [location.name for location in fill_locations]
|
||||||
|
|
||||||
if unplaced or unfilled:
|
if unplaced or unfilled:
|
||||||
raise FillError(f'Unplaced items({len(unplaced)}): {unplaced} - Unfilled Locations({len(unfilled)}): {unfilled}')
|
logging.warning(f'Unplaced items({len(unplaced)}): {unplaced} - Unfilled Locations({len(unfilled)}): {unfilled}')
|
||||||
|
|
||||||
|
|
||||||
def fast_fill(world: MultiWorld, item_pool: typing.List, fill_locations: typing.List) -> typing.Tuple[typing.List, typing.List]:
|
def fast_fill(world: MultiWorld, item_pool: typing.List, fill_locations: typing.List) -> typing.Tuple[typing.List, typing.List]:
|
||||||
|
|
Loading…
Reference in New Issue