Factorio: fix reconnect

This commit is contained in:
Fabian Dill 2021-07-29 15:25:45 +02:00
parent 7f5afddb38
commit eaae4af832
1 changed files with 8 additions and 14 deletions

View File

@ -44,7 +44,6 @@ def get_kivy_app():
from kivy.uix.tabbedpanel import TabbedPanel, TabbedPanelItem from kivy.uix.tabbedpanel import TabbedPanel, TabbedPanelItem
from kivy.lang import Builder from kivy.lang import Builder
class FactorioManager(App): class FactorioManager(App):
def __init__(self, ctx): def __init__(self, ctx):
super(FactorioManager, self).__init__() super(FactorioManager, self).__init__()
@ -94,9 +93,6 @@ def get_kivy_app():
except Exception as e: except Exception as e:
logger.exception(e) logger.exception(e)
def on_address(self, text: str):
print(text)
class LogtoUI(logging.Handler): class LogtoUI(logging.Handler):
def __init__(self, on_log): def __init__(self, on_log):
@ -132,6 +128,7 @@ def get_kivy_app():
Builder.load_file(Utils.local_path("data", "client.kv")) Builder.load_file(Utils.local_path("data", "client.kv"))
return FactorioManager return FactorioManager
class FactorioCommandProcessor(ClientCommandProcessor): class FactorioCommandProcessor(ClientCommandProcessor):
ctx: FactorioContext ctx: FactorioContext
@ -145,15 +142,6 @@ class FactorioCommandProcessor(ClientCommandProcessor):
return True return True
return False return False
def _cmd_connect(self, address: str = "") -> bool:
"""Connect to a MultiWorld Server"""
if not self.ctx.auth:
if self.ctx.rcon_client:
get_info(self.ctx, self.ctx.rcon_client) # retrieve current auth code
else:
self.output("Cannot connect to a server with unknown own identity, bridge to Factorio first.")
return super(FactorioCommandProcessor, self)._cmd_connect(address)
def _cmd_resync(self): def _cmd_resync(self):
"""Manually trigger a resync.""" """Manually trigger a resync."""
self.ctx.awaiting_bridge = True self.ctx.awaiting_bridge = True
@ -175,6 +163,13 @@ class FactorioContext(CommonContext):
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 not self.auth:
if self.rcon_client:
get_info(self, self.rcon_client) # retrieve current auth code
else:
raise Exception("Cannot connect to a server with unknown own identity, "
"bridge to Factorio first.")
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,
'tags': ['AP'], 'tags': ['AP'],
@ -340,7 +335,6 @@ async def factorio_spinup_server(ctx: FactorioContext):
if not rcon_client and "Starting RCON interface at IP ADDR:" in msg: if not rcon_client and "Starting RCON interface at IP ADDR:" in msg:
rcon_client = factorio_rcon.RCONClient("localhost", rcon_port, rcon_password) rcon_client = factorio_rcon.RCONClient("localhost", rcon_port, rcon_password)
get_info(ctx, rcon_client) get_info(ctx, rcon_client)
await asyncio.sleep(0.01) await asyncio.sleep(0.01)
except Exception as e: except Exception as e: