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()
 | 
			
		||||
            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 @@ if __name__ == '__main__':
 | 
			
		|||
                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":
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -72,15 +72,7 @@ class FactorioContext(CommonContext):
 | 
			
		|||
                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)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -143,12 +143,7 @@ class Context(CommonContext):
 | 
			
		|||
        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():
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue