pipeline_bot_probe.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. """probe_zone_login.py — 最小登录服探针: 逐帧打印 33 区登录链的应答。"""
  2. import socket
  3. import sys
  4. sys.path.insert(0, "src")
  5. from pbot.codec.bitbuf import decode6, encode6 # noqa: E402
  6. from pbot.codec.frame import FrameSplitter # noqa: E402
  7. from pbot.transport.gateway import ( # noqa: E402
  8. CHANNEL, GAME_ID, GatewayConnection)
  9. ZONE = int(sys.argv[1]) if len(sys.argv) > 1 else 14605092
  10. PORT = int(sys.argv[2]) if len(sys.argv) > 2 else 8041
  11. UID = sys.argv[3] if len(sys.argv) > 3 else "1186115037"
  12. JWT = sys.argv[4]
  13. conn = GatewayConnection(ZONE, PORT) if False else None
  14. import random # noqa: E402
  15. from pbot.types import ZoneId # noqa: E402
  16. from pbot.errors import TransportError # noqa: E402
  17. def recv_print(c: GatewayConnection, tag: str, wait: float = 6.0) -> list:
  18. frames = c.recv_frames(wait)
  19. for f in frames:
  20. body_preview = f.body[:60]
  21. try:
  22. dec = decode6(f.body)
  23. body_preview = dec[:80]
  24. except Exception: # noqa: BLE001
  25. pass
  26. print(f" [{tag}] SC{f.msg_id} recog={f.recog} p1={f.p1} p2={f.p2} "
  27. f"p3={f.p3} body={body_preview}")
  28. return frames
  29. c = GatewayConnection(ZoneId(ZONE), PORT)
  30. try:
  31. body2001 = f"{UID}/".encode() + encode6(JWT.encode()) + b"/" \
  32. + encode6(CHANNEL.encode()) + b"/1/0"
  33. _ = c.send_frame(2001, random.randint(1, 2**30), ZONE, PORT, 0, body2001, tail=0)
  34. frames = recv_print(c, "L1")
  35. key32 = None
  36. for f in frames:
  37. if f.msg_id == 529:
  38. key32 = decode6(f.body).split(b"/")[0]
  39. if not key32:
  40. print("!! 无 529")
  41. sys.exit(1)
  42. _ = c.send_frame(104, 0, 0, 0, 0, encode6(key32), tail=1)
  43. frames = recv_print(c, "L2", 4)
  44. sid = 0
  45. for f in frames:
  46. if f.msg_id == 530:
  47. sid = f.pre
  48. print(f"sid={sid}")
  49. body100 = f"{UID}/{sid}/{ZONE}/{CHANNEL}/{GAME_ID}/".encode() + key32
  50. _ = c.send_frame(100, random.randint(1, 2**30), ZONE, PORT, sid, body100, tail=2)
  51. print("-- CS100 已发, 等应答(最长 8s) --")
  52. frames = recv_print(c, "L3", 8)
  53. if not frames:
  54. print("!! CS100 零应答")
  55. finally:
  56. c.close()