release: prepare Web 2.0.1 automatic strategies and private updates
This commit is contained in:
+24
-10
@@ -354,7 +354,7 @@ class AccountWorker:
|
||||
elif self.demo:
|
||||
message = "离线演示不执行自动重登"
|
||||
elif self._auto_relogin_inflight:
|
||||
state, message = "authenticating", "正在使用服务器保存的密码重新登录原区服、原角色;策略保持停止"
|
||||
state, message = "authenticating", "正在使用服务器保存的密码重新登录原区服、原角色;激活成功后将尝试开启已勾选的策略"
|
||||
elif not self.active_identity or self.schedule.disconnected_at is not None and not self._auto_relogin_target:
|
||||
state, message = "blocked", "没有可确认的原区服和角色会话,请先手动登录并选择区服"
|
||||
elif self.schedule.disconnected_at is not None:
|
||||
@@ -459,8 +459,8 @@ class AccountWorker:
|
||||
self._auto_relogin_blocked = False
|
||||
self.schedule.game_resumed()
|
||||
self.engine.heartbeat_enabled = True
|
||||
if previous != "online":
|
||||
self.log("游戏连接已确认;策略保持停止")
|
||||
if previous != "online" and not activated:
|
||||
self.log("游戏连接已确认;" + ("已勾选的策略继续运行" if self.running else "策略保持停止"))
|
||||
|
||||
def status(self):
|
||||
with self.lock:
|
||||
@@ -913,9 +913,8 @@ class AccountWorker:
|
||||
self.check_intent()
|
||||
if session_identity(client.session) != identity or int(snapshot.raw.get("master", {}).get("id") or 0) != target.role_id:
|
||||
raise ValueError("进服后的角色与掉线前不匹配,已停止自动重登")
|
||||
result = self._activate_client(client, snapshot)
|
||||
result = self._activate_client(client, snapshot, login_message="自动重登成功,已恢复原区服和原角色")
|
||||
client = None # The worker now owns this client.
|
||||
self.log("自动重登成功,已恢复原区服和原角色的监控;策略保持停止")
|
||||
return result
|
||||
except Exception as error:
|
||||
with self.lock:
|
||||
@@ -1049,7 +1048,7 @@ class AccountWorker:
|
||||
def _session_stamp(session):
|
||||
return tuple(getattr(session, field) for field in Session.__dataclass_fields__)
|
||||
|
||||
def _activate_client(self, client, snapshot):
|
||||
def _activate_client(self, client, snapshot, *, login_message="登录成功"):
|
||||
self.check_intent()
|
||||
session = client.session
|
||||
role_id = int(snapshot.raw.get("master", {}).get("id") or 0)
|
||||
@@ -1085,6 +1084,18 @@ class AccountWorker:
|
||||
self.schedule.poll_finished(self.config)
|
||||
self._game_succeeded(activated=True)
|
||||
self._invalidate_views(clear=True)
|
||||
# Activation and its new start authorization share the final
|
||||
# generation check/lock. Never queue a start that could outlive
|
||||
# a stop, logout or policy replacement during persistence.
|
||||
try:
|
||||
self._start({}, require_selection=False)
|
||||
except ValueError as error:
|
||||
message = login_message + ";策略保持停止:" + self.safe_text(str(error))
|
||||
else:
|
||||
message = login_message + ";策略已自动开启,仅执行已勾选的规则"
|
||||
result = {"connected": True, "running": self._running,
|
||||
"has_saved_password": self._has_saved_password, "message": message}
|
||||
self.log(message)
|
||||
except Exception:
|
||||
with self.lock:
|
||||
self.engine, self.active_identity, self.demo = old_engine, previous_identity, old_demo
|
||||
@@ -1104,7 +1115,7 @@ class AccountWorker:
|
||||
self.manager._release_identity(self, previous_identity)
|
||||
if old_client is not None and old_client is not client:
|
||||
old_client.close()
|
||||
return {"connected": True, "running": False, "has_saved_password": self._has_saved_password}
|
||||
return result
|
||||
|
||||
def _login(self, payload):
|
||||
self.check_intent()
|
||||
@@ -1234,7 +1245,7 @@ class AccountWorker:
|
||||
self._invalidate_views()
|
||||
return {"connected": False, "running": False, "has_saved_password": False}
|
||||
|
||||
def _start(self, payload):
|
||||
def _start(self, payload, *, require_selection=True):
|
||||
self.check_intent()
|
||||
if not self.demo:
|
||||
self._require_game()
|
||||
@@ -1245,10 +1256,13 @@ class AccountWorker:
|
||||
other = any(value[section]["enabled"] for section in ("quest_policy", "daily_policy", "sweep_policy", "explore_policy", "progression_policy"))
|
||||
other = other or bool(policy["breakthrough_targets"]) or policy["gift_enabled"]
|
||||
ranch = policy["enabled"] and any(policy[field] for field in ("buy", "fill", "dispatch", "collect", "feed"))
|
||||
if not ranch and not other:
|
||||
if require_selection and not ranch and not other:
|
||||
raise ValueError("请先勾选至少一项功能,并启用对应策略")
|
||||
if ranch and not other and not any(rule["enabled"] for rule in policy["egg_rules"].values()):
|
||||
if require_selection and ranch and not other and not any(rule["enabled"] for rule in policy["egg_rules"].values()):
|
||||
raise ValueError("请先在背包魔物蛋勾选要孵化的蛋,并设置优先级和孵出后的去向")
|
||||
if (self.engine._progression_pending() or self.engine.explore_planner.pending(self.engine.snapshot)
|
||||
or self.engine._breakthrough_pending):
|
||||
raise ValueError("存在未确认的任务、战斗、探险或突破请求,禁止自动重发;请先核对")
|
||||
with self.lock:
|
||||
self.check_intent()
|
||||
self._running = self.engine.auto = True
|
||||
|
||||
Reference in New Issue
Block a user