probe_srvlist.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. """Parse the srvlist response to find the full server structure."""
  2. import asyncio
  3. import httpx
  4. import json
  5. import sys
  6. import os
  7. sys.path.insert(0, os.path.join(os.path.dirname(__file__), os.pardir, "src"))
  8. from cq2_sdk.env_loader import load_env
  9. load_env()
  10. async def main():
  11. gameid = os.environ.get("CQ2_GAMEID", "206923")
  12. target_sid = int(os.environ.get("CQ2_SERVER_ID", "14414738"))
  13. target_name = os.environ.get("CQ2_SERVER_NAME", "玖扬复古176")
  14. async with httpx.AsyncClient(timeout=15) as c:
  15. r = await c.get(f"https://list-box.dhsf.xqhuyu.com/box_serverlist/{gameid}.txt")
  16. data = r.json()
  17. print(f"Top-level keys: {list(data.keys())[:5]}")
  18. print(f"Total groups: {len(data)}")
  19. print()
  20. # Find target server
  21. for gid, g in data.items():
  22. tree = g.get("tree", [])
  23. for s in tree:
  24. sid = s.get("serverid", 0)
  25. name = s.get("server_name", "")
  26. if sid == target_sid or target_name in name:
  27. print(f"MATCH: group={gid} sid={sid} name={name}")
  28. print(f" group list_name: {g.get('list_name')}")
  29. print(f" server keys: {list(s.keys())}")
  30. print(f" full server: {json.dumps(s, ensure_ascii=False, indent=2)[:800]}")
  31. print()
  32. # Show one example server structure if no match
  33. print("=== Example server structure (first server in first group) ===")
  34. first_gid = next(iter(data.keys()))
  35. first_group = data[first_gid]
  36. if first_group.get("tree"):
  37. example = first_group["tree"][0]
  38. print(f" keys: {list(example.keys())}")
  39. print(f" full: {json.dumps(example, ensure_ascii=False, indent=2)[:800]}")
  40. asyncio.run(main())