# -*- coding: utf-8 -*- """ reset_role_lib.py —— 删角工具(复用 apilot.host 的删角链, 独立于 quest_bot3)。 """ import json import random import sys import time HERE = __file__.rsplit("/", 1)[0] ROOT = "/Users/zlwu/work/00code/传奇" sys.path.insert(0, ROOT) sys.path.insert(0, HERE) from encode6bitbuf_final import decode6, encode6 # noqa: E402 from combat_bot import log # noqa: E402 from apilot.host import Host # noqa: E402 GAME_ID = 206923 CHANNEL = "110585" def _list_roles(h, zone, port): h._send(2001, random.randint(1, 2**30), zone, port, 0, 0, h.build_2001_body(h.uid, h.jwt)) f529 = h._wait_for(529, 15)[0] if f529 is None: raise RuntimeError("529 超时") key32 = decode6(f529.body).split(b"/")[0] h._send(104, 0, 0, 0, 0, 1, encode6(key32)) _, sid = h._recv_with_pre(530, 15) if not sid: raise RuntimeError("530 超时") h.nc.set_sdata(sid) h._send(100, random.randint(1, 2**30), zone, port, sid, 2, f"{h.uid}/{sid}/{zone}/{CHANNEL}/{GAME_ID}/".encode() + key32) dl = time.time() + 15 while time.time() < dl: for f in h.pump(0.2): if f.msg_id == 520 and f.body: b = f.body if all(0x3C <= c <= 0x7B for c in b[:200]): b = decode6(b) try: return json.loads(b), sid except Exception: pass raise RuntimeError("520 角色列表超时") def delete_roles(zone, user, pwd, names): h = Host(zone, user, pwd, state_dir="/tmp/quest3_reset") h.http_login() h.boot_lua() for port in (8041, 8021, 8061, 8001): try: h.connect_login_gate(port) roles, sid = _list_roles(h, zone, port) break except Exception as e: log(f" 端口{port}: {str(e)[:60]}") h.nc.disconnect() else: raise SystemExit("[!] 登录链失败, 无法删角") lst = roles.get("list") or [] log(f" 当前角色: {[c.get('chr') for c in lst]}") for c in lst: nm = c.get("chr") if nm in names: h._tail = 2 ok = h._delete_role(c["UserID"], 15) log(f" 删角 {nm}(last={c.get('last')}): {'✓ 523' if ok else '✗ 失败'}") h.nc.disconnect()