From bceb8540a19e5875c137a899ae2a77a4257ca716 Mon Sep 17 00:00:00 2001 From: Fabian Dill Date: Tue, 20 Jul 2021 21:19:53 +0200 Subject: [PATCH] assorted fixes --- BaseClasses.py | 2 +- FactorioClient.py | 6 ++++-- MultiServer.py | 2 ++ NetUtils.py | 16 +++++++++------- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/BaseClasses.py b/BaseClasses.py index ed606738..ea236b90 100644 --- a/BaseClasses.py +++ b/BaseClasses.py @@ -24,6 +24,7 @@ class MultiWorld(): plando_connections: List[PlandoConnection] er_seeds: Dict[int, str] worlds: Dict[int, "AutoWorld.World"] + is_race: bool = False class AttributeProxy(): def __init__(self, rule): @@ -68,7 +69,6 @@ class MultiWorld(): self.fix_palaceofdarkness_exit = self.AttributeProxy(lambda player: self.shuffle[player] not in ['vanilla', 'simple', 'restricted', 'dungeonssimple']) self.fix_trock_exit = self.AttributeProxy(lambda player: self.shuffle[player] not in ['vanilla', 'simple', 'restricted', 'dungeonssimple']) self.NOTCURSED = self.AttributeProxy(lambda player: not self.CURSED[player]) - self.is_race = False for player in range(1, players + 1): def set_player_attr(attr, val): diff --git a/FactorioClient.py b/FactorioClient.py index 9798c6c4..d0fa1ec8 100644 --- a/FactorioClient.py +++ b/FactorioClient.py @@ -424,13 +424,15 @@ if __name__ == '__main__': options = Utils.get_options() executable = options["factorio_options"]["executable"] bin_dir = os.path.dirname(executable) + if not os.path.exists(bin_dir): + raise FileNotFoundError(f"Path {bin_dir} does not exist or could not be accessed.") if not os.path.isdir(bin_dir): - raise FileNotFoundError(bin_dir) + raise FileNotFoundError(f"Path {bin_dir} is not a directory.") if not os.path.exists(executable): if os.path.exists(executable + ".exe"): executable = executable + ".exe" else: - raise FileNotFoundError(executable) + raise FileNotFoundError(f"Path {executable} is not an executable file.") server_args = ("--rcon-port", rcon_port, "--rcon-password", rcon_password, *args.factorio_server_args) diff --git a/MultiServer.py b/MultiServer.py index 324c4380..56bc6c83 100644 --- a/MultiServer.py +++ b/MultiServer.py @@ -1017,6 +1017,8 @@ async def process_client_cmd(ctx: Context, client: Client, args: dict): if clients: # likely same player with a "ghosted" slot. We bust the ghost. if "uuid" in args and ctx.client_ids[team, slot] == args["uuid"]: + await ctx.send_msgs(clients[0], [{"cmd": "Print", "text": "You are getting kicked " + "by yourself reconnecting."}]) await clients[0].socket.close() # we have to await the DC of the ghost, so not to create data pasta client.name = ctx.player_names[(team, slot)] client.team = team diff --git a/NetUtils.py b/NetUtils.py index 1438f9fe..6c1f7292 100644 --- a/NetUtils.py +++ b/NetUtils.py @@ -109,9 +109,9 @@ class Node: for endpoint in self.endpoints: asyncio.create_task(self.send_encoded_msgs(endpoint, msgs)) - async def send_msgs(self, endpoint: Endpoint, msgs: typing.Iterable[dict]): - if not endpoint.socket or not endpoint.socket.open or endpoint.socket.closed: - return + async def send_msgs(self, endpoint: Endpoint, msgs: typing.Iterable[dict]) -> bool: + if not endpoint.socket or not endpoint.socket.open: + return False msg = self.dumper(msgs) try: await endpoint.socket.send(msg) @@ -121,18 +121,20 @@ class Node: else: if self.log_network: logging.info(f"Outgoing message: {msg}") + return True - async def send_encoded_msgs(self, endpoint: Endpoint, msg: str): - if not endpoint.socket or not endpoint.socket.open or endpoint.socket.closed: - return + async def send_encoded_msgs(self, endpoint: Endpoint, msg: str) -> bool: + if not endpoint.socket or not endpoint.socket.open: + return False try: await endpoint.socket.send(msg) except websockets.ConnectionClosed: - logging.exception("Exception during send_msgs") + logging.exception("Exception during send_encoded_msgs") await self.disconnect(endpoint) else: if self.log_network: logging.info(f"Outgoing message: {msg}") + return True async def disconnect(self, endpoint): if endpoint in self.endpoints: