SC2: fix client freezing on exit while SC2 is running (#1011)
This commit is contained in:
		
							parent
							
								
									b2aa251c47
								
							
						
					
					
						commit
						ef46979bd8
					
				| 
						 | 
					@ -136,6 +136,11 @@ class SC2Context(CommonContext):
 | 
				
			||||||
    last_loc_list = None
 | 
					    last_loc_list = None
 | 
				
			||||||
    difficulty_override = -1
 | 
					    difficulty_override = -1
 | 
				
			||||||
    mission_id_to_location_ids: typing.Dict[int, typing.List[int]] = {}
 | 
					    mission_id_to_location_ids: typing.Dict[int, typing.List[int]] = {}
 | 
				
			||||||
 | 
					    last_bot: typing.Optional[ArchipelagoBot] = None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def __init__(self, *args, **kwargs):
 | 
				
			||||||
 | 
					        super(SC2Context, self).__init__(*args, **kwargs)
 | 
				
			||||||
 | 
					        self.raw_text_parser = RawJSONtoTextParser(self)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async def server_auth(self, password_requested: bool = False):
 | 
					    async def server_auth(self, password_requested: bool = False):
 | 
				
			||||||
        if password_requested and not self.password:
 | 
					        if password_requested and not self.password:
 | 
				
			||||||
| 
						 | 
					@ -354,6 +359,8 @@ class SC2Context(CommonContext):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async def shutdown(self):
 | 
					    async def shutdown(self):
 | 
				
			||||||
        await super(SC2Context, self).shutdown()
 | 
					        await super(SC2Context, self).shutdown()
 | 
				
			||||||
 | 
					        if self.last_bot:
 | 
				
			||||||
 | 
					            self.last_bot.want_close = True
 | 
				
			||||||
        if self.sc2_run_task:
 | 
					        if self.sc2_run_task:
 | 
				
			||||||
            self.sc2_run_task.cancel()
 | 
					            self.sc2_run_task.cancel()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -481,7 +488,7 @@ class ArchipelagoBot(sc2.bot_ai.BotAI):
 | 
				
			||||||
    setup_done: bool
 | 
					    setup_done: bool
 | 
				
			||||||
    ctx: SC2Context
 | 
					    ctx: SC2Context
 | 
				
			||||||
    mission_id: int
 | 
					    mission_id: int
 | 
				
			||||||
 | 
					    want_close: bool = False
 | 
				
			||||||
    can_read_game = False
 | 
					    can_read_game = False
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    last_received_update: int = 0
 | 
					    last_received_update: int = 0
 | 
				
			||||||
| 
						 | 
					@ -489,12 +496,17 @@ class ArchipelagoBot(sc2.bot_ai.BotAI):
 | 
				
			||||||
    def __init__(self, ctx: SC2Context, mission_id):
 | 
					    def __init__(self, ctx: SC2Context, mission_id):
 | 
				
			||||||
        self.setup_done = False
 | 
					        self.setup_done = False
 | 
				
			||||||
        self.ctx = ctx
 | 
					        self.ctx = ctx
 | 
				
			||||||
 | 
					        self.ctx.last_bot = self
 | 
				
			||||||
        self.mission_id = mission_id
 | 
					        self.mission_id = mission_id
 | 
				
			||||||
        self.boni = [False for _ in range(max_bonus)]
 | 
					        self.boni = [False for _ in range(max_bonus)]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        super(ArchipelagoBot, self).__init__()
 | 
					        super(ArchipelagoBot, self).__init__()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async def on_step(self, iteration: int):
 | 
					    async def on_step(self, iteration: int):
 | 
				
			||||||
 | 
					        if self.want_close:
 | 
				
			||||||
 | 
					            self.want_close = False
 | 
				
			||||||
 | 
					            await self._client.leave()
 | 
				
			||||||
 | 
					            return
 | 
				
			||||||
        game_state = 0
 | 
					        game_state = 0
 | 
				
			||||||
        if not self.setup_done:
 | 
					        if not self.setup_done:
 | 
				
			||||||
            self.setup_done = True
 | 
					            self.setup_done = True
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue