feat: 优化扫雷游戏重连认证流程,增强点击事件拦截日志,并规范 Nakama 消息发送的 op_code 类型。

This commit is contained in:
邹方成 2026-01-04 13:25:24 +08:00
parent d507122f2f
commit 1b2315b4ea
2 changed files with 40 additions and 7 deletions

View File

@ -615,7 +615,8 @@ export default {
//
try {
console.log('[重连] 开始重新连接...');
await nakamaManager.authenticateWithGameToken(this.gameToken);
const session = await nakamaManager.authenticateWithGameToken(this.gameToken, this.stableUserId);
this.myUserId = session.user_id;
this.isConnected = true;
console.log('[重连] 认证成功');
@ -809,12 +810,42 @@ export default {
this.addLog('system', '已切断匹配信号');
},
handleCellClick(idx) {
if (this.isSpectator) return;
// showResultModal || showSettlement
if (!this.gameState || !this.gameState.gameStarted || this.showResultModal || this.showSettlement) return;
if (!this.isMyTurn) return;
if (this.gameState.grid[idx].revealed) return;
console.log('[handleCellClick] 收到点击事件, 格子:', idx, 'isMyTurn:', this.isMyTurn);
if (this.isSpectator) {
console.warn('[点击拦截] 处于观众模式');
return;
}
if (!this.gameState) {
console.warn('[点击拦截] 游戏数据未就绪');
return;
}
if (!this.gameState.gameStarted) {
console.warn('[点击拦截] 游戏尚未开始');
return;
}
if (this.showResultModal || this.showSettlement) {
console.warn('[点击拦截] 结算界面显示中');
return;
}
if (!this.isMyTurn) {
const currentPlayerInTurn = this.gameState?.turnOrder?.[this.gameState?.currentTurnIndex];
console.warn('[点击拦截] 非当前玩家回合', {
myUserId: this.myUserId,
currentTurnIndex: this.gameState?.currentTurnIndex,
turnOrder: this.gameState?.turnOrder,
currentPlayerInTurn,
isMyTurn: this.isMyTurn
});
return;
}
if (this.gameState.grid[idx].revealed) {
console.warn('[点击拦截] 该格子已揭示', { idx, cell: this.gameState.grid[idx] });
return;
}
console.log(`[发送指令] 准备发送 - matchId: ${this.matchId}, OpCode: 3, 格子: ${idx}`);
nakamaManager.sendMatchState(this.matchId, 3, JSON.stringify({ index: idx }));
console.log(`[发送指令] 已调用 sendMatchState`);
},
refreshAndPlayAgain() {
uni.removeStorageSync('minesweeper_last_match_id');

View File

@ -356,10 +356,12 @@ class NakamaManager {
*/
sendMatchState(matchId, opCode, data) {
const payload = typeof data === 'string' ? data : JSON.stringify(data);
const op = parseInt(opCode);
console.log(`[Nakama] Sending state: Match=${matchId}, OpCode=${op}`);
this._sendNoResponse({
match_data_send: {
match_id: matchId,
op_code: String(opCode),
op_code: op,
data: this._base64Encode(payload)
}
});