Fixed resync.

This commit is contained in:
genxium 2023-02-26 23:25:47 +08:00
parent 21806a3754
commit 8cd5f1d475
7 changed files with 39 additions and 49 deletions

View File

@ -85,25 +85,19 @@ func (p *playerController) SMSCaptchaGet(c *gin.Context) {
c.Set(api.RET, Constants.RetCode.SmsCaptchaRequestedTooFrequently) c.Set(api.RET, Constants.RetCode.SmsCaptchaRequestedTooFrequently)
return return
} }
Logger.Info("A new SmsCaptcha record is needed for: ", zap.String("key", redisKey))
pass := false pass := false
var succRet int var succRet int
if Conf.General.ServerEnv == SERVER_ENV_TEST { if Conf.General.ServerEnv == SERVER_ENV_TEST {
player, err := models.GetPlayerByName(req.Num) player, err := models.GetPlayerByName(req.Num)
Logger.Info("A new SmsCaptcha record is needed for: ", zap.String("key", redisKey), zap.Any("player", player))
if nil == err && nil != player { if nil == err && nil != player {
pass = true pass = true
succRet = Constants.RetCode.IsTestAcc succRet = Constants.RetCode.IsTestAcc
} }
} }
if !pass { /*
player, err := models.GetPlayerByName(req.Num) // Real phonenum is not supported yet!
if nil == err && nil != player {
pass = true
succRet = Constants.RetCode.IsBotAcc
}
}
if !pass { if !pass {
if RE_PHONE_NUM.MatchString(req.Num) { if RE_PHONE_NUM.MatchString(req.Num) {
succRet = Constants.RetCode.Ok succRet = Constants.RetCode.Ok
@ -119,6 +113,7 @@ func (p *playerController) SMSCaptchaGet(c *gin.Context) {
} }
} }
} }
*/
if !pass { if !pass {
c.Set(api.RET, Constants.RetCode.InvalidRequestParam) c.Set(api.RET, Constants.RetCode.InvalidRequestParam)
return return
@ -481,16 +476,6 @@ func (p *playerController) maybeCreateNewPlayer(req smsCaptchaReq) (*models.Play
Logger.Info("Got a test env player:", zap.Any("phonenum", req.Num), zap.Any("playerId", player.Id)) Logger.Info("Got a test env player:", zap.Any("phonenum", req.Num), zap.Any("playerId", player.Id))
return player, nil return player, nil
} }
} else {
botPlayer, err := models.GetPlayerByName(req.Num)
if err != nil {
Logger.Error("Seeking bot player error:", zap.Error(err))
return nil, err
}
if botPlayer != nil {
Logger.Info("Got a bot player:", zap.Any("phonenum", req.Num), zap.Any("playerId", botPlayer.Id))
return botPlayer, nil
}
} }
bind, err := models.GetPlayerAuthBinding(Constants.AuthChannel.Sms, extAuthID) bind, err := models.GetPlayerAuthBinding(Constants.AuthChannel.Sms, extAuthID)

View File

@ -74,7 +74,7 @@ func Test_SMSCaptchaGet_illegalPhone(t *testing.T) {
func Test_SMSCaptchaGet_testAcc(t *testing.T) { func Test_SMSCaptchaGet_testAcc(t *testing.T) {
player, err := getTestPlayer() player, err := getTestPlayer()
if err == nil && player != nil { if nil == err && nil != player {
resp := mustDoSmsCaptchaGetReq(fakeSMSCaptchReq(player.Name), t) resp := mustDoSmsCaptchaGetReq(fakeSMSCaptchReq(player.Name), t)
if resp.Ret != Constants.RetCode.IsTestAcc { if resp.Ret != Constants.RetCode.IsTestAcc {
t.Fail() t.Fail()

View File

@ -801,7 +801,7 @@ func (pR *Room) OnDismissed() {
pR.PlayerSignalToCloseDict = make(map[int32]SignalToCloseConnCbType) pR.PlayerSignalToCloseDict = make(map[int32]SignalToCloseConnCbType)
pR.PlayerSecondarySignalToCloseDict = make(map[int32]SignalToCloseConnCbType) pR.PlayerSecondarySignalToCloseDict = make(map[int32]SignalToCloseConnCbType)
pR.JoinIndexBooleanArr = make([]bool, pR.Capacity) pR.JoinIndexBooleanArr = make([]bool, pR.Capacity)
pR.RenderCacheSize = 256 pR.RenderCacheSize = 1024
pR.RenderFrameBuffer = resolv.NewRingBuffer(pR.RenderCacheSize) pR.RenderFrameBuffer = resolv.NewRingBuffer(pR.RenderCacheSize)
pR.InputsBuffer = resolv.NewRingBuffer((pR.RenderCacheSize >> 1) + 1) pR.InputsBuffer = resolv.NewRingBuffer((pR.RenderCacheSize >> 1) + 1)
pR.rdfIdToActuallyUsedInput = make(map[int32]*pb.InputFrameDownsync) pR.rdfIdToActuallyUsedInput = make(map[int32]*pb.InputFrameDownsync)

View File

@ -241,7 +241,7 @@
"ctor": "Float64Array", "ctor": "Float64Array",
"array": [ "array": [
-379.577, -379.577,
90.576, 140,
0, 0,
0, 0,
0, 0,
@ -468,7 +468,7 @@
"ctor": "Float64Array", "ctor": "Float64Array",
"array": [ "array": [
0, 0,
-68.939, -13.057,
0, 0,
0, 0,
0, 0,

View File

@ -461,7 +461,7 @@
"array": [ "array": [
0, 0,
0, 0,
210.43877906529718, 209.57814771583418,
0, 0,
0, 0,
0, 0,

View File

@ -518,7 +518,7 @@
"array": [ "array": [
0, 0,
0, 0,
210.43877906529718, 217.5376534000385,
0, 0,
0, 0,
0, 0,

View File

@ -865,13 +865,20 @@ cc.Class({
_markConfirmationIfApplicable() { _markConfirmationIfApplicable() {
const self = this; const self = this;
let newAllConfirmedCnt = 0; let newAllConfirmedCnt = 0;
while (self.recentInputCache.GetStFrameId() <= self.lastAllConfirmedInputFrameId && self.lastAllConfirmedInputFrameId < self.recentInputCache.GetEdFrameId()) { let candidateInputFrameId = (self.lastAllConfirmedInputFrameId + 1);
const inputFrameDownsync = self.recentInputCache.GetByFrameId(self.lastAllConfirmedInputFrameId); if (candidateInputFrameId < self.recentInputCache.GetStFrameId()) {
candidateInputFrameId = self.recentInputCache.GetStFrameId();
}
while (self.recentInputCache.GetStFrameId() <= candidateInputFrameId && candidateInputFrameId < self.recentInputCache.GetEdFrameId()) {
const inputFrameDownsync = gopkgs.GetInputFrameDownsync(self.recentInputCache, candidateInputFrameId);
if (null == inputFrameDownsync) break; if (null == inputFrameDownsync) break;
if (self._allConfirmed(inputFrameDownsync.ConfirmedList)) break; if (self._allConfirmed(inputFrameDownsync.GetConfirmedList())) break;
++self.lastAllConfirmedInputFrameId; ++candidateInputFrameId;
++newAllConfirmedCnt; ++newAllConfirmedCnt;
} }
if (0 < newAllConfirmedCnt) {
self.lastAllConfirmedInputFrameId = candidateInputFrameId;
}
return newAllConfirmedCnt; return newAllConfirmedCnt;
}, },
@ -897,19 +904,17 @@ cc.Class({
continue; continue;
} }
// [WARNING] Now that "inputFrameDownsyncId > self.lastAllConfirmedInputFrameId", we should make an update immediately because unlike its backend counterpart "Room.LastAllConfirmedInputFrameId", the frontend "mapIns.lastAllConfirmedInputFrameId" might inevitably get gaps among discrete values due to "either type#1 or type#2 forceConfirmation" -- and only "onInputFrameDownsyncBatch" can catch this! // [WARNING] Now that "inputFrameDownsyncId > self.lastAllConfirmedInputFrameId", we should make an update immediately because unlike its backend counterpart "Room.LastAllConfirmedInputFrameId", the frontend "mapIns.lastAllConfirmedInputFrameId" might inevitably get gaps among discrete values due to "either type#1 or type#2 forceConfirmation" -- and only "onInputFrameDownsyncBatch" can catch this!
self.lastAllConfirmedInputFrameId = inputFrameDownsyncId; const localInputFrame = gopkgs.GetInputFrameDownsync(self.recentInputCache, inputFrameDownsyncId);
const localInputFrame = self.recentInputCache.GetByFrameId(inputFrameDownsyncId);
if (null != localInputFrame if (null != localInputFrame
&& &&
null == firstPredictedYetIncorrectInputFrameId null == firstPredictedYetIncorrectInputFrameId
&& &&
!self.equalInputLists(localInputFrame.InputList, inputFrameDownsync.inputList) !self.equalInputLists(localInputFrame.GetInputList(), inputFrameDownsync.inputList)
) { ) {
firstPredictedYetIncorrectInputFrameId = inputFrameDownsyncId; firstPredictedYetIncorrectInputFrameId = inputFrameDownsyncId;
} }
// [WARNING] Take all "inputFrameDownsync" from backend as all-confirmed, it'll be later checked by "rollbackAndChase". // [WARNING] Take all "inputFrameDownsync" from backend as all-confirmed, it'll be later checked by "rollbackAndChase".
inputFrameDownsync.confirmedList = (1 << self.playerRichInfoDict.size) - 1; inputFrameDownsync.confirmedList = (1 << window.boundRoomCapacity) - 1;
const inputFrameDownsyncLocal = gopkgs.NewInputFrameDownsync(inputFrameDownsync.inputFrameId, inputFrameDownsync.inputList, inputFrameDownsync.confirmedList); // "battle.InputFrameDownsync" in "jsexport" const inputFrameDownsyncLocal = gopkgs.NewInputFrameDownsync(inputFrameDownsync.inputFrameId, inputFrameDownsync.inputList, inputFrameDownsync.confirmedList); // "battle.InputFrameDownsync" in "jsexport"
for (let j in self.playerRichInfoArr) { for (let j in self.playerRichInfoArr) {
const jj = parseInt(j); const jj = parseInt(j);
@ -1007,7 +1012,7 @@ fromUDP=${fromUDP}`);
// the returned "gopkgs.NewInputFrameDownsync.InputList" is immutable, thus we can only modify the values in "newInputList" and "newConfirmedList"! // the returned "gopkgs.NewInputFrameDownsync.InputList" is immutable, thus we can only modify the values in "newInputList" and "newConfirmedList"!
let newInputList = existingInputFrame.InputList.slice(); let newInputList = existingInputFrame.InputList.slice();
newInputList[peerJoinIndex - 1] = peerEncodedInput; newInputList[peerJoinIndex - 1] = peerEncodedInput;
let newConfirmedList = (existingInputFrame.ConfirmedList | peerJoinIndex); let newConfirmedList = (existingInputFrame.ConfirmedList | peerJoinIndexMask);
const newInputFrameDownsyncLocal = gopkgs.NewInputFrameDownsync(inputFrameId, newInputList, newConfirmedList); const newInputFrameDownsyncLocal = gopkgs.NewInputFrameDownsync(inputFrameId, newInputList, newConfirmedList);
//console.log(`Updated encoded input of peerJoinIndex=${peerJoinIndex} to ${peerEncodedInput} for inputFrameId=${inputFrameId}/renderedInputFrameIdUpper=${renderedInputFrameIdUpper} from ${JSON.stringify(inputFrame)}; newInputFrameDownsyncLocal=${self.gopkgsInputFrameDownsyncStr(newInputFrameDownsyncLocal)}; existingInputFrame=${self.gopkgsInputFrameDownsyncStr(existingInputFrame)}`); //console.log(`Updated encoded input of peerJoinIndex=${peerJoinIndex} to ${peerEncodedInput} for inputFrameId=${inputFrameId}/renderedInputFrameIdUpper=${renderedInputFrameIdUpper} from ${JSON.stringify(inputFrame)}; newInputFrameDownsyncLocal=${self.gopkgsInputFrameDownsyncStr(newInputFrameDownsyncLocal)}; existingInputFrame=${self.gopkgsInputFrameDownsyncStr(existingInputFrame)}`);
self.recentInputCache.SetByFrameId(newInputFrameDownsyncLocal, inputFrameId); self.recentInputCache.SetByFrameId(newInputFrameDownsyncLocal, inputFrameId);