send_probe.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. """Send one CS 2001 probe frame to the game gateway while capture_cq2.py
  2. listens — validates that our Npcap capture sees the exact bytes on the wire.
  3. """
  4. import asyncio
  5. import json
  6. import random
  7. import struct
  8. import sys
  9. import base64
  10. from pathlib import Path
  11. sys.path.insert(0, "src")
  12. from cq2_sdk.utils.encoding import encode6bit
  13. # Read env.json creds
  14. raw = Path(r"D:\ProgramFiles\996box\GameBoxDownload\1\env.json").read_bytes()
  15. text = raw.decode("utf-8", errors="replace")
  16. idx = text.find("eyJ")
  17. b64 = text[idx:].rstrip()
  18. padded = b64 + "=" * ((-len(b64)) % 4)
  19. env = json.loads(base64.urlsafe_b64decode(padded).decode("utf-8", errors="replace"))
  20. account = env["uid"]
  21. pwd_enc = encode6bit(env["token"].encode()).decode("ascii")
  22. ch_enc = encode6bit(env.get("channel", "110585").encode()).decode("ascii")
  23. body = f"{account}/{pwd_enc}/{ch_enc}/0/0"
  24. param1 = random.randint(100_000_000, 2_100_000_000) & 0xFFFF00FF
  25. frame = struct.pack("<6i", 2001, 900_000, param1, 14414736, 8021, len(body.encode())) + body.encode()
  26. print(f"sending {len(frame)}B CS 2001 to gfgame:12000 ...")
  27. print(f"frame hex[:80]: {frame.hex()[:80]}")
  28. async def send():
  29. r, w = await asyncio.wait_for(
  30. asyncio.open_connection("gfgame.dhsf.xqhuyu.com", 12000), timeout=5
  31. )
  32. try:
  33. w.write(frame)
  34. await w.drain()
  35. print("sent.")
  36. try:
  37. data = await asyncio.wait_for(r.read(4096), timeout=3)
  38. print(f"reply: {len(data) if data else 0} bytes")
  39. except asyncio.TimeoutError:
  40. print("no reply (expected — server closes)")
  41. finally:
  42. w.close()
  43. try:
  44. await w.wait_closed()
  45. except Exception:
  46. pass
  47. asyncio.run(send())