chore(framework): 真机联调脚本 login-live.ts(复用框架+ws transport)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Generated
+33
-1
@@ -9,8 +9,10 @@
|
|||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^26.0.1",
|
"@types/node": "^26.0.1",
|
||||||
|
"@types/ws": "^8.18.1",
|
||||||
"tsx": "^4.22.4",
|
"tsx": "^4.22.4",
|
||||||
"typescript": "^6.0.3"
|
"typescript": "^6.0.3",
|
||||||
|
"ws": "^8.21.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@esbuild/aix-ppc64": {
|
"node_modules/@esbuild/aix-ppc64": {
|
||||||
@@ -438,6 +440,15 @@
|
|||||||
"undici-types": "~8.3.0"
|
"undici-types": "~8.3.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@types/ws": {
|
||||||
|
"version": "8.18.1",
|
||||||
|
"resolved": "https://registry.npmmirror.com/@types/ws/-/ws-8.18.1.tgz",
|
||||||
|
"integrity": "sha512-ThVF6DCVhA8kUGy+aazFQ4kXQ7E1Ty7A3ypFOe0IcJV8O/M511G99AW24irKrW56Wt44yG9+ij8FaqoBGkuBXg==",
|
||||||
|
"dev": true,
|
||||||
|
"dependencies": {
|
||||||
|
"@types/node": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/esbuild": {
|
"node_modules/esbuild": {
|
||||||
"version": "0.28.1",
|
"version": "0.28.1",
|
||||||
"resolved": "https://registry.npmmirror.com/esbuild/-/esbuild-0.28.1.tgz",
|
"resolved": "https://registry.npmmirror.com/esbuild/-/esbuild-0.28.1.tgz",
|
||||||
@@ -529,6 +540,27 @@
|
|||||||
"resolved": "https://registry.npmmirror.com/undici-types/-/undici-types-8.3.0.tgz",
|
"resolved": "https://registry.npmmirror.com/undici-types/-/undici-types-8.3.0.tgz",
|
||||||
"integrity": "sha512-j375ScV60dom+YkPFIfTLcOiPxkN/buHz5GobjLhixFuANaNs3C9l4GmrWqejgXWJ7BbJcFYpTEUkS1Ge8bpZQ==",
|
"integrity": "sha512-j375ScV60dom+YkPFIfTLcOiPxkN/buHz5GobjLhixFuANaNs3C9l4GmrWqejgXWJ7BbJcFYpTEUkS1Ge8bpZQ==",
|
||||||
"dev": true
|
"dev": true
|
||||||
|
},
|
||||||
|
"node_modules/ws": {
|
||||||
|
"version": "8.21.0",
|
||||||
|
"resolved": "https://registry.npmmirror.com/ws/-/ws-8.21.0.tgz",
|
||||||
|
"integrity": "sha512-Vsp28b7DRcimFQvrqu2Wek3z1iYxDCWqHYB8Qsnk/S4RfaCQzPGPyBNuVjJV3cd6UiKtUtp6sNM77gWvzcCH+g==",
|
||||||
|
"dev": true,
|
||||||
|
"engines": {
|
||||||
|
"node": ">=10.0.0"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"bufferutil": "^4.0.1",
|
||||||
|
"utf-8-validate": ">=5.0.2"
|
||||||
|
},
|
||||||
|
"peerDependenciesMeta": {
|
||||||
|
"bufferutil": {
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
"utf-8-validate": {
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,9 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^26.0.1",
|
"@types/node": "^26.0.1",
|
||||||
|
"@types/ws": "^8.18.1",
|
||||||
"tsx": "^4.22.4",
|
"tsx": "^4.22.4",
|
||||||
"typescript": "^6.0.3"
|
"typescript": "^6.0.3",
|
||||||
|
"ws": "^8.21.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,76 @@
|
|||||||
|
// 真机联调脚本(手动跑,非单测):复用框架代码,对真实配置服 + 本地游戏服跑 player_login 往返。
|
||||||
|
// 运行:node --import tsx scripts/login-live.ts (cwd: cocoscreator_projects)
|
||||||
|
import WebSocket from 'ws';
|
||||||
|
import { resolveBootstrap } from '../YouleNexus/assets/framework/config/bootstrap.ts';
|
||||||
|
import { HttpConfigFetcher } from '../YouleNexus/assets/framework/config/remote-config-fetcher.ts';
|
||||||
|
import { resolveRuntimeMode } from '../YouleNexus/assets/framework/config/runtime-mode.ts';
|
||||||
|
import { NetClient } from '../YouleNexus/assets/framework/net/net-client.ts';
|
||||||
|
import { parseLoginResponse } from '../YouleNexus/assets/framework/protocol/login.ts';
|
||||||
|
import type { Transport } from '../YouleNexus/assets/framework/net/transport.ts';
|
||||||
|
|
||||||
|
/** Node 侧 Transport:用 ws 包实现框架的 Transport 接口(等价生产的 CocosWebSocketTransport)。 */
|
||||||
|
class WsTransport implements Transport {
|
||||||
|
private ws: WebSocket | null = null;
|
||||||
|
private openCb?: () => void;
|
||||||
|
private msgCb?: (f: string) => void;
|
||||||
|
private closeCb?: () => void;
|
||||||
|
connect(url: string): void {
|
||||||
|
const ws = new WebSocket(url);
|
||||||
|
this.ws = ws;
|
||||||
|
ws.on('open', () => this.openCb?.());
|
||||||
|
ws.on('message', (data: any) => this.msgCb?.(data.toString()));
|
||||||
|
ws.on('close', () => this.closeCb?.());
|
||||||
|
ws.on('error', (e: any) => console.log('[ws error]', e?.message ?? e));
|
||||||
|
}
|
||||||
|
send(frame: string): void { this.ws?.send(frame); }
|
||||||
|
close(): void { try { this.ws?.close(); } catch { /* ignore */ } }
|
||||||
|
onOpen(cb: () => void): void { this.openCb = cb; }
|
||||||
|
onMessage(cb: (f: string) => void): void { this.msgCb = cb; }
|
||||||
|
onClose(cb: () => void): void { this.closeCb = cb; }
|
||||||
|
}
|
||||||
|
|
||||||
|
async function main(): Promise<void> {
|
||||||
|
const mode = resolveRuntimeMode(true, 'debug'); // 强制 debug
|
||||||
|
console.log('== 联调开始 (mode=' + mode + ', profile=staging) ==');
|
||||||
|
|
||||||
|
const result = await resolveBootstrap({
|
||||||
|
mode,
|
||||||
|
win: {},
|
||||||
|
search: '?profile=staging',
|
||||||
|
fetcher: new HttpConfigFetcher(),
|
||||||
|
isNative: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log('profile :', result.profile.name);
|
||||||
|
console.log('servers :', result.servers, '(serverOverride 生效)');
|
||||||
|
console.log('identity :', result.identity);
|
||||||
|
console.log('account :', result.account);
|
||||||
|
const data = (result.rawConfig as any)?.data;
|
||||||
|
console.log('rawConfig :', data ? '顶层键=' + Object.keys(data).join(',') : null);
|
||||||
|
|
||||||
|
const net = new NetClient({
|
||||||
|
servers: result.servers,
|
||||||
|
transportFactory: () => new WsTransport(),
|
||||||
|
debug: true,
|
||||||
|
});
|
||||||
|
net.setIdentity({ ...result.identity, ...(result.account ?? {}) } as any);
|
||||||
|
|
||||||
|
net.on('open', () => console.log('[event] open(已连上本地服)'));
|
||||||
|
net.on('login', (loginData: any) => {
|
||||||
|
const parsed = parseLoginResponse(loginData);
|
||||||
|
console.log('[event] login → parseLoginResponse:', parsed);
|
||||||
|
console.log(parsed.ok ? `✅ 登录成功 playerid=${parsed.playerid} inRoom=${parsed.inRoom} hasBattle=${parsed.hasBattle}` : '❌ 登录失败 state≠0');
|
||||||
|
setTimeout(() => { net.stop(); process.exit(0); }, 500);
|
||||||
|
});
|
||||||
|
net.on('message', (m: any) => console.log('[event] message route=' + m.route + ' rpc=' + m.rpc));
|
||||||
|
net.on('slow', () => console.log('[event] slow(收包超时)'));
|
||||||
|
net.on('reconnecting', (s: any) => console.log('[event] reconnecting →', s));
|
||||||
|
net.on('serverSwitch', (s: any) => console.log('[event] serverSwitch →', s));
|
||||||
|
net.on('kicked', (d: any) => console.log('[event] kicked', d));
|
||||||
|
|
||||||
|
net.start();
|
||||||
|
|
||||||
|
setTimeout(() => { console.log('⏱ 15s 内未完成登录,结束。'); net.stop(); process.exit(2); }, 15000);
|
||||||
|
}
|
||||||
|
|
||||||
|
main().catch((e) => { console.error('❌ 联调异常:', e?.message ?? e); process.exit(1); });
|
||||||
Reference in New Issue
Block a user