CommonClient: consolidate Connect packet sending
This commit is contained in:
parent
a27d09f81a
commit
47c5c407ef
|
@ -230,6 +230,17 @@ class CommonContext():
|
||||||
self.password = await self.console_input()
|
self.password = await self.console_input()
|
||||||
return self.password
|
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):
|
async def console_input(self):
|
||||||
self.input_requests += 1
|
self.input_requests += 1
|
||||||
return await self.input_queue.get()
|
return await self.input_queue.get()
|
||||||
|
@ -554,11 +565,7 @@ if __name__ == '__main__':
|
||||||
logger.info('Enter slot name:')
|
logger.info('Enter slot name:')
|
||||||
self.auth = await self.console_input()
|
self.auth = await self.console_input()
|
||||||
|
|
||||||
await self.send_msgs([{"cmd": 'Connect',
|
await self.send_connect()
|
||||||
'password': self.password, 'name': self.auth, 'version': Utils.version_tuple,
|
|
||||||
'tags': self.tags,
|
|
||||||
'uuid': Utils.get_unique_identifier(), 'game': self.game
|
|
||||||
}])
|
|
||||||
|
|
||||||
def on_package(self, cmd: str, args: dict):
|
def on_package(self, cmd: str, args: dict):
|
||||||
if cmd == "Connected":
|
if cmd == "Connected":
|
||||||
|
|
|
@ -72,15 +72,7 @@ class FactorioContext(CommonContext):
|
||||||
raise Exception("Cannot connect to a server with unknown own identity, "
|
raise Exception("Cannot connect to a server with unknown own identity, "
|
||||||
"bridge to Factorio first.")
|
"bridge to Factorio first.")
|
||||||
|
|
||||||
await self.send_msgs([{
|
await self.send_connect()
|
||||||
"cmd": 'Connect',
|
|
||||||
'password': self.password,
|
|
||||||
'name': self.auth,
|
|
||||||
'version': Utils.version_tuple,
|
|
||||||
'tags': self.tags,
|
|
||||||
'uuid': Utils.get_unique_identifier(),
|
|
||||||
'game': "Factorio"
|
|
||||||
}])
|
|
||||||
|
|
||||||
def on_print(self, args: dict):
|
def on_print(self, args: dict):
|
||||||
super(FactorioContext, self).on_print(args)
|
super(FactorioContext, self).on_print(args)
|
||||||
|
|
|
@ -143,12 +143,7 @@ class Context(CommonContext):
|
||||||
self.awaiting_rom = False
|
self.awaiting_rom = False
|
||||||
self.auth = self.rom
|
self.auth = self.rom
|
||||||
auth = base64.b64encode(self.rom).decode()
|
auth = base64.b64encode(self.rom).decode()
|
||||||
await self.send_msgs([{"cmd": 'Connect',
|
await self.send_connect(name=auth)
|
||||||
'password': self.password, 'name': auth, 'version': Utils.version_tuple,
|
|
||||||
'tags': self.tags,
|
|
||||||
'uuid': Utils.get_unique_identifier(),
|
|
||||||
'game': self.game
|
|
||||||
}])
|
|
||||||
|
|
||||||
def on_deathlink(self, data: dict):
|
def on_deathlink(self, data: dict):
|
||||||
if not self.killing_player_task or self.killing_player_task.done():
|
if not self.killing_player_task or self.killing_player_task.done():
|
||||||
|
|
Loading…
Reference in New Issue