Skip to content

Commit

Permalink
CommonClient: consolidate Connect packet sending
Browse files Browse the repository at this point in the history
  • Loading branch information
Berserker66 committed Nov 21, 2021
1 parent a27d09f commit 47c5c40
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 20 deletions.
17 changes: 12 additions & 5 deletions CommonClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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":
Expand Down
10 changes: 1 addition & 9 deletions FactorioClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 1 addition & 6 deletions SNIClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit 47c5c40

Please sign in to comment.