Просмотр исходного кода

fix(Login): 桌面登录期处理 MPay 弹窗,避免误判未知页面

- 登录循环每轮及截图后各查一次弹窗 HWND(防竞态),回车关闭并确认消失;
  重弹超过 5 次抛 GameStuckError 交 Restart 重建客户端
- 本仓库登录实现在 tasks/Restart/login.py 的 LoginHandler,落点相应改到
  _app_handle_login 主循环与 app_handle_login 外层
- 登录成功后标记登录态;close_unknown_pages 改调设备层 app_lost_login(),
  任务层不再出现 is_desktop 与 MPay 字样
User 1 месяц назад
Родитель
Сommit
3252b0716e
2 измененных файлов с 41 добавлено и 0 удалено
  1. 6 0
      tasks/GameUi/navigator.py
  2. 35 0
      tasks/Restart/login.py

+ 6 - 0
tasks/GameUi/navigator.py

@@ -710,6 +710,12 @@ class GameUi(BaseTask, GameUiAssets):
         """
 
         self.maybe_screenshot(skip_first_screenshot)
+
+        # 客户端掉回登录态(掉线/被顶号)时页面上的标志全部不可信,点关闭动作
+        # 没有意义,交回 Restart 处理(登录流程会关掉弹窗)
+        if self.device.app_lost_login():
+            raise GameNotRunningError('Client dropped back to login')
+
         logger.warning("Try switch to a supported page")
         for action in [*self.navigator.local_unknown_closers, *self.DEFAULT_UNKNOWN_CLOSERS]:
             action_name = self._action_name(action)

+ 35 - 0
tasks/Restart/login.py

@@ -11,6 +11,10 @@ from tasks.Component.GeneralBuff.assets import GeneralBuffAssets
 from tasks.base_task import BaseTask
 import time
 
+# 登录期间 MPay 弹窗「关掉又重弹」的容忍上限,超过说明回车已走不出去,交 Restart 重建
+DESKTOP_MPAY_CLOSE_LIMIT = 5
+
+
 class LoginHandler(BaseTask, RestartAssets, GameUiAssets, GeneralBuffAssets):
     character: str
 
@@ -31,8 +35,33 @@ class LoginHandler(BaseTask, RestartAssets, GameUiAssets, GeneralBuffAssets):
         confirm_timer = Timer(1.5, count=2).start()
         orientation_timer = Timer(10)
         login_success = False
+        # 本次登录已处理过的 MPay 弹窗次数,用于给「关掉又重弹」封顶
+        popup_handled = 0
+
+        def handle_desktop_login_popup() -> bool:
+            """登录期间处理 MPay 弹窗,返回是否刚关闭了弹窗。
+
+            MPay 是独立顶层窗口,主窗口截图识别不到,只能按 HWND 枚举检查。
+            """
+            nonlocal popup_handled
+            if not self.device.is_desktop or not self.device.find_desktop_login_popup():
+                return False
+            popup_handled += 1
+            if popup_handled > DESKTOP_MPAY_CLOSE_LIMIT:
+                raise GameStuckError(
+                    f'Desktop MPay login popup reappeared more than {DESKTOP_MPAY_CLOSE_LIMIT} times')
+            if not self.device.desktop_confirm_login_popup():
+                # 弹窗可能恰好在确认函数最后一次枚举后自行关闭,重新确认避免误判卡死
+                if not self.device.find_desktop_login_popup():
+                    return True
+                # 弹窗仍存活时不能继续识别页面,否则 MPay 会被当成未知页面
+                raise GameStuckError('Desktop MPay login popup cannot be closed')
+            return True
 
         while 1:
+            # MPay 可能在启动后、重登时或登录中途反复出现,每轮都要处理
+            if handle_desktop_login_popup():
+                continue
             # Watch device rotation
             if not login_success and orientation_timer.reached():
                 # Screen may rotate after starting an app
@@ -40,6 +69,9 @@ class LoginHandler(BaseTask, RestartAssets, GameUiAssets, GeneralBuffAssets):
                 orientation_timer.reset()
 
             self.device.screenshot()
+            # 截图与窗口枚举有竞态,截图后再查一次,避免刚出现的 MPay 进入图像识别
+            if handle_desktop_login_popup():
+                continue
             # https://github.com/runhey/OnmyojiAutoScript/pull/1761
             if not self.device.check_screen_size_sample():
                 continue
@@ -152,6 +184,9 @@ class LoginHandler(BaseTask, RestartAssets, GameUiAssets, GeneralBuffAssets):
             self.device.click_record_clear()
             try:
                 self._app_handle_login()
+                # 桌面:登录成功后标记登录态,app_is_running 才会判定为已在游戏中
+                if self.device.is_desktop:
+                    self.device.desktop_mark_logged_in()
                 if self.config.restart.harvest_config.enable:
                     self.harvest()
                 return True