Factorio: Embed slot name into mod
This commit is contained in:
parent
37755cd362
commit
9c3d12dc55
|
@ -184,7 +184,6 @@ class CommonContext():
|
||||||
async def disconnect(self):
|
async def disconnect(self):
|
||||||
if self.server and not self.server.socket.closed:
|
if self.server and not self.server.socket.closed:
|
||||||
await self.server.socket.close()
|
await self.server.socket.close()
|
||||||
self.ui_node.send_connection_status(self)
|
|
||||||
if self.server_task is not None:
|
if self.server_task is not None:
|
||||||
await self.server_task
|
await self.server_task
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,7 @@ if not os.path.exists(executable):
|
||||||
|
|
||||||
threadpool = ThreadPoolExecutor(10)
|
threadpool = ThreadPoolExecutor(10)
|
||||||
|
|
||||||
|
|
||||||
class FactorioCommandProcessor(ClientCommandProcessor):
|
class FactorioCommandProcessor(ClientCommandProcessor):
|
||||||
@mark_raw
|
@mark_raw
|
||||||
def _cmd_factorio(self, text: str) -> bool:
|
def _cmd_factorio(self, text: str) -> bool:
|
||||||
|
@ -48,9 +49,10 @@ class FactorioCommandProcessor(ClientCommandProcessor):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _cmd_connect(self, address: str = "", name="") -> bool:
|
def _cmd_connect(self, address: str = "") -> bool:
|
||||||
"""Connect to a MultiWorld Server"""
|
"""Connect to a MultiWorld Server"""
|
||||||
self.ctx.auth = name
|
if not self.ctx.auth:
|
||||||
|
self.output("Cannot connect to a server with unknown own identity, bridge to Factorio first.")
|
||||||
return super(FactorioCommandProcessor, self)._cmd_connect(address)
|
return super(FactorioCommandProcessor, self)._cmd_connect(address)
|
||||||
|
|
||||||
|
|
||||||
|
@ -66,9 +68,6 @@ class FactorioContext(CommonContext):
|
||||||
async def server_auth(self, password_requested):
|
async def server_auth(self, password_requested):
|
||||||
if password_requested and not self.password:
|
if password_requested and not self.password:
|
||||||
await super(FactorioContext, self).server_auth(password_requested)
|
await super(FactorioContext, self).server_auth(password_requested)
|
||||||
if self.auth is None:
|
|
||||||
logging.info('Enter the name of your slot to join this game:')
|
|
||||||
self.auth = await self.console_input()
|
|
||||||
|
|
||||||
await self.send_msgs([{"cmd": 'Connect',
|
await self.send_msgs([{"cmd": 'Connect',
|
||||||
'password': self.password, 'name': self.auth, 'version': Utils._version_tuple,
|
'password': self.password, 'name': self.auth, 'version': Utils._version_tuple,
|
||||||
|
@ -85,7 +84,7 @@ class FactorioContext(CommonContext):
|
||||||
def on_print_json(self, args: dict):
|
def on_print_json(self, args: dict):
|
||||||
if not self.found_items and args.get("type", None) == "ItemSend" and args["receiving"] == args["sending"]:
|
if not self.found_items and args.get("type", None) == "ItemSend" and args["receiving"] == args["sending"]:
|
||||||
pass # don't want info on other player's local pickups.
|
pass # don't want info on other player's local pickups.
|
||||||
copy_data = copy.deepcopy(args["data"]) # jsontotextparser is destructive currently
|
copy_data = copy.deepcopy(args["data"]) # jsontotextparser is destructive currently
|
||||||
logger.info(self.jsontotextparser(args["data"]))
|
logger.info(self.jsontotextparser(args["data"]))
|
||||||
if self.rcon_client:
|
if self.rcon_client:
|
||||||
cleaned_text = self.raw_json_text_parser(copy_data).replace('"', '')
|
cleaned_text = self.raw_json_text_parser(copy_data).replace('"', '')
|
||||||
|
@ -105,6 +104,7 @@ async def game_watcher(ctx: FactorioContext, bridge_file: str):
|
||||||
research_data = data["research_done"]
|
research_data = data["research_done"]
|
||||||
research_data = {int(tech_name.split("-")[1]) for tech_name in research_data}
|
research_data = {int(tech_name.split("-")[1]) for tech_name in research_data}
|
||||||
victory = data["victory"]
|
victory = data["victory"]
|
||||||
|
ctx.auth = data["slot_name"]
|
||||||
|
|
||||||
if not ctx.finished_game and victory:
|
if not ctx.finished_game and victory:
|
||||||
await ctx.send_msgs([{"cmd": "StatusUpdate", "status": ClientStatus.CLIENT_GOAL}])
|
await ctx.send_msgs([{"cmd": "StatusUpdate", "status": ClientStatus.CLIENT_GOAL}])
|
||||||
|
@ -119,13 +119,17 @@ async def game_watcher(ctx: FactorioContext, bridge_file: str):
|
||||||
else:
|
else:
|
||||||
bridge_counter += 1
|
bridge_counter += 1
|
||||||
if bridge_counter >= 60:
|
if bridge_counter >= 60:
|
||||||
bridge_logger.info("Did not find Factorio Bridge file, waiting for mod to run, which requires the server to run, which requires a player to be connected.")
|
bridge_logger.info(
|
||||||
|
"Did not find Factorio Bridge file, "
|
||||||
|
"waiting for mod to run, which requires the server to run, "
|
||||||
|
"which requires a player to be connected.")
|
||||||
bridge_counter = 0
|
bridge_counter = 0
|
||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.exception(e)
|
logging.exception(e)
|
||||||
logging.error("Aborted Factorio Server Bridge")
|
logging.error("Aborted Factorio Server Bridge")
|
||||||
|
|
||||||
|
|
||||||
def stream_factorio_output(pipe, queue):
|
def stream_factorio_output(pipe, queue):
|
||||||
def queuer():
|
def queuer():
|
||||||
while 1:
|
while 1:
|
||||||
|
|
|
@ -2,6 +2,7 @@ require "lib"
|
||||||
require "util"
|
require "util"
|
||||||
|
|
||||||
FREE_SAMPLES = {{ free_samples }}
|
FREE_SAMPLES = {{ free_samples }}
|
||||||
|
SLOT_NAME = "{{ slot_name }}"
|
||||||
--SUPPRESS_INVENTORY_EVENTS = false
|
--SUPPRESS_INVENTORY_EVENTS = false
|
||||||
|
|
||||||
-- Initialize force data, either from it being created or already being part of the game when the mod was added.
|
-- Initialize force data, either from it being created or already being part of the game when the mod was added.
|
||||||
|
@ -183,7 +184,8 @@ function dumpInfo(force)
|
||||||
local research_done = {}
|
local research_done = {}
|
||||||
local data_collection = {
|
local data_collection = {
|
||||||
["research_done"] = research_done,
|
["research_done"] = research_done,
|
||||||
["victory"] = chain_lookup(global, "forcedata", force.name, "victory")
|
["victory"] = chain_lookup(global, "forcedata", force.name, "victory"),
|
||||||
|
["slot_name"] = SLOT_NAME
|
||||||
}
|
}
|
||||||
|
|
||||||
for tech_name, tech in pairs(force.technologies) do
|
for tech_name, tech in pairs(force.technologies) do
|
||||||
|
|
|
@ -70,7 +70,8 @@ def generate_mod(world: MultiWorld, player: int, seedname: str):
|
||||||
"mod_name": mod_name, "allowed_science_packs": world.max_science_pack[player].get_allowed_packs(),
|
"mod_name": mod_name, "allowed_science_packs": world.max_science_pack[player].get_allowed_packs(),
|
||||||
"tech_cost_scale": tech_cost, "custom_data": world.custom_data[player],
|
"tech_cost_scale": tech_cost, "custom_data": world.custom_data[player],
|
||||||
"tech_tree_layout_prerequisites": world.tech_tree_layout_prerequisites[player],
|
"tech_tree_layout_prerequisites": world.tech_tree_layout_prerequisites[player],
|
||||||
"rocket_recipe" : rocket_recipes[world.max_science_pack[player].value]}
|
"rocket_recipe" : rocket_recipes[world.max_science_pack[player].value],
|
||||||
|
"slot_name": world.player_names[player][0]}
|
||||||
for factorio_option in Options.factorio_options:
|
for factorio_option in Options.factorio_options:
|
||||||
template_data[factorio_option] = getattr(world, factorio_option)[player].value
|
template_data[factorio_option] = getattr(world, factorio_option)[player].value
|
||||||
control_code = control_template.render(**template_data)
|
control_code = control_template.render(**template_data)
|
||||||
|
|
Loading…
Reference in New Issue