diff --git a/battle_srv/models/room.go b/battle_srv/models/room.go index 465d28d..a9ead09 100644 --- a/battle_srv/models/room.go +++ b/battle_srv/models/room.go @@ -434,6 +434,8 @@ func (pR *Room) StartBattle() { switch thatPlayerBattleState { case PlayerBattleStateIns.DISCONNECTED: case PlayerBattleStateIns.LOST: + case PlayerBattleStateIns.EXPELLED_DURING_GAME: + case PlayerBattleStateIns.EXPELLED_IN_DISMISSAL: continue } kickoffFrame := pR.RenderFrameBuffer.GetByFrameId(0).(*RoomDownsyncFrame) @@ -761,10 +763,16 @@ func (pR *Room) OnDismissed() { } func (pR *Room) expelPlayerDuringGame(playerId int32) { - defer pR.onPlayerExpelledDuringGame(playerId) + if signalToCloseConnOfThisPlayer, existent := pR.PlayerSignalToCloseDict[playerId]; existent { + signalToCloseConnOfThisPlayer(Constants.RetCode.UnknownError, "") // TODO: Specify an error code + } + pR.onPlayerExpelledDuringGame(playerId) } func (pR *Room) expelPlayerForDismissal(playerId int32) { + if signalToCloseConnOfThisPlayer, existent := pR.PlayerSignalToCloseDict[playerId]; existent { + signalToCloseConnOfThisPlayer(Constants.RetCode.UnknownError, "") // TODO: Specify an error code + } pR.onPlayerExpelledForDismissal(playerId) } @@ -1441,6 +1449,15 @@ func (pR *Room) printBarrier(barrierCollider *resolv.Object) { func (pR *Room) downsyncToAllPlayers(upperToSendInputFrameId int32, unconfirmedMask uint64, prohibitsInputsBufferLock bool) { for playerId, player := range pR.Players { + thatPlayerBattleState := atomic.LoadInt32(&(player.BattleState)) + switch thatPlayerBattleState { + case PlayerBattleStateIns.DISCONNECTED: + case PlayerBattleStateIns.LOST: + case PlayerBattleStateIns.EXPELLED_DURING_GAME: + case PlayerBattleStateIns.EXPELLED_IN_DISMISSAL: + case PlayerBattleStateIns.READDED_PENDING_BATTLE_COLLIDER_ACK: // This is the reason why battleState filter is put at "downsyncToAllPlayers" instead of "downsyncToSinglePlayer" + continue + } pR.downsyncToSinglePlayer(playerId, player, pR.LastAllConfirmedInputFrameId, unconfirmedMask, prohibitsInputsBufferLock) } } @@ -1501,12 +1518,12 @@ func (pR *Room) downsyncToSinglePlayer(playerId int32, player *Player, upperToSe panic(fmt.Sprintf("Required refRenderFrameId=%v for roomId=%v, renderFrameId=%v, playerId=%v, playerLastSentInputFrameId=%v, j=%v doesn't exist! InputsBuffer=%v, RenderFrameBuffer=%v", refRenderFrameId, pR.Id, pR.RenderFrameId, playerId, player.LastSentInputFrameId, j, pR.InputsBufferString(false), pR.RenderFrameBufferString())) } - Logger.Warn(fmt.Sprintf("Sending refRenderFrameId=%v for roomId=%v, , playerId=%v, playerJoinIndex=%v, renderFrameId=%v, curDynamicsRenderFrameId=%v, playerLastSentInputFrameId=%v, lowerToSentInputFrameId=%v, upperToSendInputFrameId=%v, j=%v: InputsBuffer=%v", refRenderFrameId, pR.Id, playerId, player.JoinIndex, pR.RenderFrameId, pR.CurDynamicsRenderFrameId, player.LastSentInputFrameId, lowerToSentInputFrameId, upperToSendInputFrameId, j, pR.InputsBufferString(false))) refRenderFrame := tmp.(*RoomDownsyncFrame) for playerId, player := range pR.Players { refRenderFrame.Players[playerId].ColliderRadius = player.ColliderRadius // hardcoded for now } refRenderFrame.BackendUnconfirmedMask = unconfirmedMask + Logger.Warn(fmt.Sprintf("Sending refRenderFrameId=%v for roomId=%v, , playerId=%v, playerJoinIndex=%v, renderFrameId=%v, curDynamicsRenderFrameId=%v, playerLastSentInputFrameId=%v, lowerToSentInputFrameId=%v, upperToSendInputFrameId=%v, j=%v: InputsBuffer=%v", refRenderFrameId, pR.Id, playerId, player.JoinIndex, pR.RenderFrameId, pR.CurDynamicsRenderFrameId, player.LastSentInputFrameId, lowerToSentInputFrameId, upperToSendInputFrameId, j, pR.InputsBufferString(false))) pR.sendSafely(refRenderFrame, toSendInputFrameDownsyncs, DOWNSYNC_MSG_ACT_FORCED_RESYNC, playerId) } else { pR.sendSafely(nil, toSendInputFrameDownsyncs, DOWNSYNC_MSG_ACT_INPUT_BATCH, playerId) diff --git a/frontend/assets/scripts/Map.js b/frontend/assets/scripts/Map.js index 34bbecf..93d049c 100644 --- a/frontend/assets/scripts/Map.js +++ b/frontend/assets/scripts/Map.js @@ -485,7 +485,7 @@ cc.Class({ ++barrierIdCounter; const collisionBarrierIndex = (self.collisionBarrierIndexPrefix + barrierIdCounter); self.collisionSysMap.set(collisionBarrierIndex, newBarrierCollider); - console.log(`Created new barrier collider: ${newBarrierCollider}`); + // console.log(`Created new barrier collider: ${collisionBarrierIndex}`); } self.selfPlayerInfo = JSON.parse(cc.sys.localStorage.getItem('selfPlayer')); @@ -926,9 +926,6 @@ cc.Class({ const self = this; if (null == self.findingPlayerNode.parent) return; self.findingPlayerNode.parent.removeChild(self.findingPlayerNode); - if (null != rdf) { - self._initPlayerRichInfoDict(rdf.players); - } }, onBattleReadyToStart(rdf) { diff --git a/frontend/assets/scripts/WsSessionMgr.js b/frontend/assets/scripts/WsSessionMgr.js index 231dc46..033c92d 100644 --- a/frontend/assets/scripts/WsSessionMgr.js +++ b/frontend/assets/scripts/WsSessionMgr.js @@ -146,9 +146,10 @@ window.initPersistentSessionClient = function(onopenCb, expectedRoomId) { } try { const resp = window.pb.protos.WsResp.decode(new Uint8Array(evt.data)); + // console.log(`Got non-empty onmessage decoded: resp.act=${resp.act}`); switch (resp.act) { case window.DOWNSYNC_MSG_ACT_HB_REQ: - window.handleHbRequirements(resp); // 获取boundRoomId并存储到localStorage + window.handleHbRequirements(resp); break; case window.DOWNSYNC_MSG_ACT_PLAYER_ADDED_AND_ACKED: mapIns.onPlayerAdded(resp.rdf); @@ -167,11 +168,9 @@ window.initPersistentSessionClient = function(onopenCb, expectedRoomId) { break; case window.DOWNSYNC_MSG_ACT_FORCED_RESYNC: if (null == resp.inputFrameDownsyncBatch || 0 >= resp.inputFrameDownsyncBatch.length) { - console.error(`Got empty inputFrameDownsyncBatch upon resync@localRenderFrameId=${mapIns.renderFrameId}, @lastAllConfirmedRenderFrameId=${mapIns.lastAllConfirmedRenderFrameId}, @lastAllConfirmedInputFrameId=${mapIns.lastAllConfirmedInputFrameId}, @chaserRenderFrameId=${mapIns.chaserRenderFrameId}, @localRecentInputCache=${mapIns._stringifyRecentInputCache(false)}, the incoming resp= -${JSON.stringify(resp, null, 2)}`); + console.error(`Got empty inputFrameDownsyncBatch upon resync@localRenderFrameId=${mapIns.renderFrameId}, @lastAllConfirmedRenderFrameId=${mapIns.lastAllConfirmedRenderFrameId}, @lastAllConfirmedInputFrameId=${mapIns.lastAllConfirmedInputFrameId}, @chaserRenderFrameId=${mapIns.chaserRenderFrameId}, @localRecentInputCache=${mapIns._stringifyRecentInputCache(false)}, the incoming resp=${JSON.stringify(resp, null, 2)}`); return; } - const inputFrameIdConsecutive = (resp.inputFrameDownsyncBatch[0].inputFrameId == mapIns.lastAllConfirmedInputFrameId + 1); mapIns.onRoomDownsyncFrame(resp.rdf, resp.inputFrameDownsyncBatch); break; default: