SC2: fix client freezing on exit while SC2 is running (#1011)

This commit is contained in:
Fabian Dill 2022-09-12 02:08:33 +02:00 committed by GitHub
parent b2aa251c47
commit ef46979bd8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 1 deletions

View File

@ -136,6 +136,11 @@ class SC2Context(CommonContext):
last_loc_list = None
difficulty_override = -1
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):
if password_requested and not self.password:
@ -354,6 +359,8 @@ class SC2Context(CommonContext):
async def shutdown(self):
await super(SC2Context, self).shutdown()
if self.last_bot:
self.last_bot.want_close = True
if self.sc2_run_task:
self.sc2_run_task.cancel()
@ -481,7 +488,7 @@ class ArchipelagoBot(sc2.bot_ai.BotAI):
setup_done: bool
ctx: SC2Context
mission_id: int
want_close: bool = False
can_read_game = False
last_received_update: int = 0
@ -489,12 +496,17 @@ class ArchipelagoBot(sc2.bot_ai.BotAI):
def __init__(self, ctx: SC2Context, mission_id):
self.setup_done = False
self.ctx = ctx
self.ctx.last_bot = self
self.mission_id = mission_id
self.boni = [False for _ in range(max_bonus)]
super(ArchipelagoBot, self).__init__()
async def on_step(self, iteration: int):
if self.want_close:
self.want_close = False
await self._client.leave()
return
game_state = 0
if not self.setup_done:
self.setup_done = True