feat(client-info): 本地镜像的 ClientInfo 显示 SRV: CN1/CN2

This commit is contained in:
TermiNexus committed 2026-10-19 21:43:33 +08:00
1 parent 5466aa9078
commit e10428a3a5
1 file changed
+12 -5
+12 -5
View File
@@ -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, '<script src="/ws_hook.js"></script></head>');
// 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 = '<script>window.__HORNET_SRV__=' + Srv + ';</script>';
if (WS_HOOK) Head += '<script src="/ws_hook.js"></script>';
let Html = fs.readFileSync(File, 'utf8');
Html = /<\/head>/i.test(Html) ? Html.replace(/<\/head>/i, Head + '</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)'));
});