feat: 优化扫雷游戏重连认证流程,增强点击事件拦截日志,并规范 Nakama 消息发送的 op_code 类型。
This commit is contained in:
parent
d507122f2f
commit
1b2315b4ea
@ -615,7 +615,8 @@ export default {
|
|||||||
// 自动重连
|
// 自动重连
|
||||||
try {
|
try {
|
||||||
console.log('[重连] 开始重新连接...');
|
console.log('[重连] 开始重新连接...');
|
||||||
await nakamaManager.authenticateWithGameToken(this.gameToken);
|
const session = await nakamaManager.authenticateWithGameToken(this.gameToken, this.stableUserId);
|
||||||
|
this.myUserId = session.user_id;
|
||||||
this.isConnected = true;
|
this.isConnected = true;
|
||||||
|
|
||||||
console.log('[重连] 认证成功');
|
console.log('[重连] 认证成功');
|
||||||
@ -809,12 +810,42 @@ export default {
|
|||||||
this.addLog('system', '已切断匹配信号');
|
this.addLog('system', '已切断匹配信号');
|
||||||
},
|
},
|
||||||
handleCellClick(idx) {
|
handleCellClick(idx) {
|
||||||
if (this.isSpectator) return;
|
console.log('[handleCellClick] 收到点击事件, 格子:', idx, 'isMyTurn:', this.isMyTurn);
|
||||||
// 增加 showResultModal || showSettlement 的拦截,防止结算后的“瞬时点击”
|
if (this.isSpectator) {
|
||||||
if (!this.gameState || !this.gameState.gameStarted || this.showResultModal || this.showSettlement) return;
|
console.warn('[点击拦截] 处于观众模式');
|
||||||
if (!this.isMyTurn) return;
|
return;
|
||||||
if (this.gameState.grid[idx].revealed) 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 }));
|
nakamaManager.sendMatchState(this.matchId, 3, JSON.stringify({ index: idx }));
|
||||||
|
console.log(`[发送指令] 已调用 sendMatchState`);
|
||||||
},
|
},
|
||||||
refreshAndPlayAgain() {
|
refreshAndPlayAgain() {
|
||||||
uni.removeStorageSync('minesweeper_last_match_id');
|
uni.removeStorageSync('minesweeper_last_match_id');
|
||||||
|
|||||||
@ -356,10 +356,12 @@ class NakamaManager {
|
|||||||
*/
|
*/
|
||||||
sendMatchState(matchId, opCode, data) {
|
sendMatchState(matchId, opCode, data) {
|
||||||
const payload = typeof data === 'string' ? data : JSON.stringify(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({
|
this._sendNoResponse({
|
||||||
match_data_send: {
|
match_data_send: {
|
||||||
match_id: matchId,
|
match_id: matchId,
|
||||||
op_code: String(opCode),
|
op_code: op,
|
||||||
data: this._base64Encode(payload)
|
data: this._base64Encode(payload)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user