From e10428a3a51f7ab617e9fc90ed442fedfb5b9dfe Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Mon, 19 Oct 2026 21:43:33 +0800 Subject: [PATCH] =?UTF-8?q?feat(client-info):=20=E6=9C=AC=E5=9C=B0?= =?UTF-8?q?=E9=95=9C=E5=83=8F=E7=9A=84=20ClientInfo=20=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=20SRV:=20CN1/CN2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 3DTank/tools/serve.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/3DTank/tools/serve.js b/3DTank/tools/serve.js index 435dae7..fc29736 100644 --- a/3DTank/tools/serve.js +++ b/3DTank/tools/serve.js @@ -399,12 +399,19 @@ const Server = http.createServer((Req, Res) => { } const Ext = path.extname(File).toLowerCase(); const Type = MIME[Ext] || 'application/octet-stream'; - // --ws-hook:HTML 里注入抓包脚本(在主脚本之前 → 先于游戏创建 WebSocket) - if (WS_HOOK && (Ext === '.html' || Ext === '.htm')) { - const Html = fs.readFileSync(File, 'utf8').replace(/<\/head>/i, ''); + // HTML 注入: + // ① window.__HORNET_SRV__ —— 当前配置的目标服务器编号(ClientInfo 里显示 SRV: CN1 / CN2) + // ② --ws-hook 时再注入抓包脚本(必须排在游戏主脚本之前) + if (Ext === '.html' || Ext === '.htm') { + const SrvMatch = /c([12])\.3dtank\.com/.exec(CONFIG_UPSTREAM); + const Srv = SrvMatch ? SrvMatch[1] : '1'; + let Head = ''; + if (WS_HOOK) Head += ''; + let Html = fs.readFileSync(File, 'utf8'); + Html = /<\/head>/i.test(Html) ? Html.replace(/<\/head>/i, Head + '') : (Head + Html); const Buf = Buffer.from(Html, 'utf8'); Res.writeHead(200, { 'Content-Type': Type, 'Content-Length': Buf.length, 'Cache-Control': 'no-cache' }); - if (VERBOSE) console.log('[200] ' + Buf.length + '\t' + UrlPath + ' (已注入 ws_hook)'); + if (VERBOSE) console.log('[200] ' + Buf.length + '\t' + UrlPath + ' (已注入 SRV=' + Srv + (WS_HOOK ? ' + ws_hook' : '') + ')'); Res.end(Buf); return; } @@ -427,6 +434,6 @@ Server.listen(PORT, () => { console.log(' 404 记录 : ' + MISSING_LOG); console.log(' config.xml: ' + (RELAY_PORT > 0 ? ('中继改写 → ws://localhost:' + RELAY_PORT + '/(动态生成,不落盘)') - : (!REAL_CONFIG && fs.existsSync(LOCAL_CONFIG) ? '本地覆盖 ' + LOCAL_CONFIG : '回源 c1.3dtank.com(--real-config)'))); + : (!REAL_CONFIG && fs.existsSync(LOCAL_CONFIG) ? '本地覆盖 ' + LOCAL_CONFIG : '回源 ' + CONFIG_UPSTREAM + '(--real-config)'))); console.log(' ws 抓包 : ' + (WS_HOOK ? '已开启(HTML 注入 /ws_hook.js;保存用 __ws_save__())' : '关闭(要抓包加 --ws-hook,勿用 URL hash)')); });