From 47c5c407efeac8f7f3d060c5868bcd0084b78f28 Mon Sep 17 00:00:00 2001 From: Fabian Dill Date: Sun, 21 Nov 2021 02:50:24 +0100 Subject: [PATCH] CommonClient: consolidate Connect packet sending --- CommonClient.py | 17 ++++++++++++----- FactorioClient.py | 10 +--------- SNIClient.py | 7 +------ 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/CommonClient.py b/CommonClient.py index 2e0b8c5b41fe..78c17542b42c 100644 --- a/CommonClient.py +++ b/CommonClient.py @@ -230,6 +230,17 @@ async def server_auth(self, password_requested: bool = False): self.password = await self.console_input() return self.password + async def send_connect(self, **kwargs): + payload = { + "cmd": 'Connect', + 'password': self.password, 'name': self.auth, 'version': Utils.version_tuple, + 'tags': self.tags, + 'uuid': Utils.get_unique_identifier(), 'game': self.game + } + if kwargs: + payload.update(kwargs) + await self.send_msgs([payload]) + async def console_input(self): self.input_requests += 1 return await self.input_queue.get() @@ -554,11 +565,7 @@ async def server_auth(self, password_requested: bool = False): logger.info('Enter slot name:') self.auth = await self.console_input() - await self.send_msgs([{"cmd": 'Connect', - 'password': self.password, 'name': self.auth, 'version': Utils.version_tuple, - 'tags': self.tags, - 'uuid': Utils.get_unique_identifier(), 'game': self.game - }]) + await self.send_connect() def on_package(self, cmd: str, args: dict): if cmd == "Connected": diff --git a/FactorioClient.py b/FactorioClient.py index 096189e1ed2f..056dfc3f4934 100644 --- a/FactorioClient.py +++ b/FactorioClient.py @@ -72,15 +72,7 @@ async def server_auth(self, password_requested: bool = False): raise Exception("Cannot connect to a server with unknown own identity, " "bridge to Factorio first.") - await self.send_msgs([{ - "cmd": 'Connect', - 'password': self.password, - 'name': self.auth, - 'version': Utils.version_tuple, - 'tags': self.tags, - 'uuid': Utils.get_unique_identifier(), - 'game': "Factorio" - }]) + await self.send_connect() def on_print(self, args: dict): super(FactorioContext, self).on_print(args) diff --git a/SNIClient.py b/SNIClient.py index a49deae2c18e..121e3653875e 100644 --- a/SNIClient.py +++ b/SNIClient.py @@ -143,12 +143,7 @@ async def server_auth(self, password_requested: bool = False): self.awaiting_rom = False self.auth = self.rom auth = base64.b64encode(self.rom).decode() - await self.send_msgs([{"cmd": 'Connect', - 'password': self.password, 'name': auth, 'version': Utils.version_tuple, - 'tags': self.tags, - 'uuid': Utils.get_unique_identifier(), - 'game': self.game - }]) + await self.send_connect(name=auth) def on_deathlink(self, data: dict): if not self.killing_player_task or self.killing_player_task.done():