diag_gateway.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. """Diagnose the real game-gateway host/port for zone 14426767 (today 16:00).
  2. Findings so far:
  3. - .env CQ2_GATE_HOST=jycq-206923.dhsf.xqhuyu.com is DEAD (DNS fails) — it was a guess
  4. - probe_gateway.py (prior RE work): real gateway = gfgame.dhsf.xqhuyu.com,
  5. per-zone ports live in cached ResServerlist.txt_206923 (compact keys:
  6. d=serverId p=port i=host s=state t=group)
  7. - C1's start_info has a signed modlist URL — possibly the FRESH zone list
  8. This script:
  9. 1. Dump 玖扬 group (t=1000514) entries from cached srvlist: d/p/i/s
  10. 2. Fetch the signed modlist URL from run_6_env.json, detect format,
  11. look for zone 14426767
  12. 3. DNS + TCP probe gfgame.dhsf.xqhuyu.com and known IPs on the port matrix
  13. """
  14. import asyncio
  15. import json
  16. import socket
  17. import sys
  18. from pathlib import Path
  19. _HERE = Path(__file__).resolve().parent
  20. sys.path.insert(0, str(_HERE.parent / "src"))
  21. from cq2_sdk.env_loader import load_env
  22. load_env(_HERE.parent / ".env")
  23. import httpx
  24. CACHED_SRVLIST = Path(r"D:\ProgramFiles\996box\GameBoxDownload\1\cq\cache_206923\ResServerlist.txt_206923")
  25. ENV_DUMP = _HERE.parent / "env_dumps" / "run_6_env.json"
  26. TARGET_ZONE = 14426767 # today 16:00, B3's pick
  27. print("=== [1] cached srvlist: 玖扬 group (t=1000514) ===")
  28. try:
  29. data = json.loads(CACHED_SRVLIST.read_text(encoding="utf-8"))
  30. servers = data["serverData"]
  31. jy = [s for s in servers if str(s.get("t")) == "1000514"]
  32. print(f"total serverData: {len(servers)}, 玖扬 group: {len(jy)}")
  33. for s in jy[-12:]: # 最新 12 个
  34. print(f" d={s.get('d'):<9} p={s.get('p'):<6} i={s.get('i') or '(default gfgame)':<28} s={s.get('s')}")
  35. hit = [s for s in servers if str(s.get("d")) == str(TARGET_ZONE)]
  36. print(f" target {TARGET_ZONE} in cached: {'YES p=' + str(hit[0]['p']) if hit else 'NO (file is stale, need modlist)'}")
  37. ports_jy = sorted({int(s['p']) for s in jy if s.get('p')})
  38. print(f" 玖扬 port set: {ports_jy}")
  39. except Exception as e:
  40. print(f" FAIL: {type(e).__name__}: {e}")
  41. print("\n=== [2] modlist from run_6_env.json ===")
  42. try:
  43. env = json.loads(ENV_DUMP.read_text(encoding="utf-8"))
  44. modlist_url = env.get("modlist", "")
  45. print(f" url: {modlist_url[:90]}...")
  46. r = httpx.get(modlist_url, headers={"User-Agent": "996Box/5.1.1.9007"},
  47. timeout=15, verify=False)
  48. print(f" http {r.status_code}, {len(r.content)} bytes")
  49. try:
  50. mdata = r.json()
  51. if isinstance(mdata, dict) and "serverData" in mdata:
  52. mservers = mdata["serverData"]
  53. mhit = [s for s in mservers if str(s.get("d")) == str(TARGET_ZONE)]
  54. print(f" serverData entries: {len(mservers)}")
  55. if mhit:
  56. s = mhit[0]
  57. print(f" *** TARGET {TARGET_ZONE}: p={s.get('p')} i={s.get('i') or '(default gfgame)'} s={s.get('s')} ***")
  58. else:
  59. jym = [s for s in mservers if str(s.get("t")) == "1000514"]
  60. print(f" 玖扬 in modlist: {len(jym)}")
  61. for s in jym[-6:]:
  62. print(f" d={s.get('d'):<9} p={s.get('p'):<6} i={s.get('i') or '(default)'} s={s.get('s')}")
  63. else:
  64. print(f" keys: {list(mdata.keys())[:10] if isinstance(mdata, dict) else type(mdata).__name__}")
  65. except Exception:
  66. print(f" not JSON; head: {r.text[:200]!r}")
  67. except Exception as e:
  68. print(f" FAIL: {type(e).__name__}: {e}")
  69. print("\n=== [3] gateway probes ===")
  70. async def tcp_ok(host: str, port: int) -> bool:
  71. try:
  72. r, w = await asyncio.wait_for(asyncio.open_connection(host, port), timeout=4)
  73. w.close()
  74. return True
  75. except Exception:
  76. return False
  77. async def probes():
  78. gh = "gfgame.dhsf.xqhuyu.com"
  79. try:
  80. infos = socket.getaddrinfo(gh, None)
  81. addrs = sorted({i[4][0] for i in infos})
  82. print(f" DNS {gh} -> {addrs}")
  83. except Exception as e:
  84. addrs = []
  85. print(f" DNS {gh} FAIL: {e}")
  86. targets = [gh] + ["47.118.169.147", "47.118.169.153", "47.118.172.233"]
  87. ports = [8001, 8021, 8041, 8061, 8081, 12000]
  88. for t in targets:
  89. results = await asyncio.gather(*(tcp_ok(t, p) for p in ports))
  90. marks = " ".join(f"{p}:{'OPEN' if o else '-'}" for p, o in zip(ports, results))
  91. print(f" {t:<24} {marks}")
  92. asyncio.run(probes())