Added inactive watchdog hint in frontend.

This commit is contained in:
genxium
2022-12-20 16:01:44 +08:00
parent 9eb6ad26ef
commit 727e66787f
8 changed files with 130 additions and 136 deletions

View File

@@ -23,9 +23,9 @@ var constants = {
FILE_NAME: {
TREASURE_PICKEDUP: "TreasurePicked",
CRASHED_BY_TRAP_BULLET: "CrashedByTrapBullet",
HIGH_SCORE_TREASURE_PICKED:"HighScoreTreasurePicked",
COUNT_DOWN_10SEC_TO_END:"countDown10SecToEnd",
BGM: "BGM"
HIGH_SCORE_TREASURE_PICKED: "HighScoreTreasurePicked",
COUNT_DOWN_10SEC_TO_END: "countDown10SecToEnd",
BGM: "BGM"
}
},
ROUTE_PATH: (_ROUTE_PATH = {
@@ -55,39 +55,40 @@ var constants = {
},
RET_CODE: {
/**
* NOTE: The "RET_CODE"s from 1000-1015 are reserved for the websocket "WebsocketStdCloseCode"s.
* NOTE: The "RET_CODE"s from 1000-1015 are reserved for the websocket "WebsocketStdCloseCode"s, custom codes should be between 3000-4999
*
* References
* - https://tools.ietf.org/html/rfc6455#section-7.4
* - https://godoc.org/github.com/gorilla/websocket#pkg-constants.
*/
"__comment__": "基础",
"OK": 9000,
"UNKNOWN_ERROR": 9001,
"INVALID_REQUEST_PARAM": 9002,
"IS_TEST_ACC": 9003,
"MYSQL_ERROR": 9004,
"NONEXISTENT_ACT": 9005,
"LACK_OF_DIAMOND": 9006,
"LACK_OF_GOLD": 9007,
"LACK_OF_ENERGY": 9008,
"NONEXISTENT_ACT_HANDLER": 9009,
"LOCALLY_NO_AVAILABLE_ROOM": 9010,
"LOCALLY_NO_SPECIFIED_ROOM": 9011,
"PLAYER_NOT_ADDABLE_TO_ROOM": 9012,
"PLAYER_NOT_READDABLE_TO_ROOM": 9013,
"PLAYER_NOT_FOUND": 9014,
"PLAYER_CHEATING": 9015,
"__comment__": "Websocket",
"OK": 3000,
"UNKNOWN_ERROR": 3001,
"INVALID_REQUEST_PARAM": 3002,
"IS_TEST_ACC": 3003,
"MYSQL_ERROR": 3004,
"NONEXISTENT_ACT": 3005,
"LACK_OF_DIAMOND": 3006,
"LACK_OF_GOLD": 3007,
"LACK_OF_ENERGY": 3008,
"NONEXISTENT_ACT_HANDLER": 3009,
"LOCALLY_NO_AVAILABLE_ROOM": 3010,
"LOCALLY_NO_SPECIFIED_ROOM": 3011,
"PLAYER_NOT_ADDABLE_TO_ROOM": 3012,
"PLAYER_NOT_READDABLE_TO_ROOM": 3013,
"PLAYER_NOT_FOUND": 3014,
"PLAYER_CHEATING": 3015,
"WECHAT_SERVER_ERROR": 3016,
"IS_BOT_ACC": 3017,
"ACTIVE_WATCHDOG": 3018,
"BATTLE_STOPPED": 3019,
"__comment__": "SMS",
"SMS_CAPTCHA_REQUESTED_TOO_FREQUENTLY": 5001,
"SMS_CAPTCHA_NOT_MATCH": 5002,
"__comment__": "OTHERS",
"INVALID_TOKEN": 2001,
"DUPLICATED": 2002,
"INCORRECT_HANDLE": 2004,
"NONEXISTENT_HANDLE": 2005,
"INCORRECT_PASSWORD": 2006,
"INCORRECT_CAPTCHA": 2007,
"INVALID_EMAIL_LITERAL": 2008,
@@ -99,9 +100,14 @@ var constants = {
"FAILED_TO_DELETE": 2015,
"FAILED_TO_CREATE": 2016,
"INCORRECT_PHONE_NUMBER": 2018,
"PASSWORD_RESET_CODE_GENERATION_PER_EMAIL_TOO_FREQUENTLY": 4000,
"TRADE_CREATION_TOO_FREQUENTLY": 4002,
"MAP_NOT_UNLOCKED": 4003,
"INSUFFICIENT_MEM_TO_ALLOCATE_CONNECTION": 2019,
"PASSWORD_RESET_CODE_GENERATION_PER_EMAIL_TOO_FREQUENTLY": 2020,
"TRADE_CREATION_TOO_FREQUENTLY": 2021,
"MAP_NOT_UNLOCKED": 2022,
"GET_SMS_CAPTCHA_RESP_ERROR_CODE": 2023,
"SMS_CAPTCHA_REQUESTED_TOO_FREQUENTLY": 2024,
"SMS_CAPTCHA_NOT_MATCH": 2025,
"NOT_IMPLEMENTED_YET": 65535
},

View File

@@ -440,7 +440,7 @@
"array": [
0,
0,
216.50635094610968,
215.95961841836203,
0,
0,
0,

View File

@@ -11,6 +11,7 @@ window.ALL_MAP_STATES = {
};
window.ALL_BATTLE_STATES = {
NONE: -1,
WAITING: 0,
IN_BATTLE: 1,
IN_SETTLEMENT: 2,
@@ -222,15 +223,19 @@ cc.Class({
onDestroy() {
const self = this;
console.warn("+++++++ Map onDestroy()");
if (null == self.battleState || ALL_BATTLE_STATES.WAITING == self.battleState) {
if (null == self.battleState || ALL_BATTLE_STATES.IN_BATTLE != self.battleState) {
window.clearBoundRoomIdInBothVolatileAndPersistentStorage();
}
if (null != window.handleBattleColliderInfo) {
window.handleBattleColliderInfo = null;
}
if (null != window.handleClientSessionError) {
window.handleClientSessionError = null;
}
},
onManualRejoinRequired(labelString) {
const self = this;
self.battleState = ALL_BATTLE_STATES.NONE; // Effectively stops "update(dt)"
self.showPopupInCanvas(self.gameRuleNode);
self.popupSimplePressToGo(labelString, false);
},
popupSimplePressToGo(labelString, hideYesButton) {
@@ -334,16 +339,6 @@ cc.Class({
self.showCriticalCoordinateLabels = false;
console.warn("+++++++ Map onLoad()");
window.handleClientSessionError = function() {
console.warn('+++++++ Common handleClientSessionError()');
if (ALL_BATTLE_STATES.IN_SETTLEMENT == self.battleState) {
console.log("Battled ended by settlement");
} else {
console.warn("Connection lost, going back to login page");
window.clearLocalStorageAndBackToLoginScene(true);
}
};
const mapNode = self.node;
const canvasNode = mapNode.parent;
@@ -759,6 +754,8 @@ cc.Class({
if (ALL_BATTLE_STATES.IN_BATTLE != self.battleState) {
return;
}
window.closeWSConnection(constants.RET_CODE.BATTLE_STOPPED);
self.battleState = ALL_BATTLE_STATES.IN_SETTLEMENT;
self.countdownNanos = null;
self.logBattleStats();
if (self.musicEffectManagerScriptIns) {
@@ -769,7 +766,6 @@ cc.Class({
const resultPanelScriptIns = resultPanelNode.getComponent("ResultPanel");
resultPanelScriptIns.showPlayerInfo(self.playerRichInfoDict);
window.clearBoundRoomIdInBothVolatileAndPersistentStorage();
self.battleState = ALL_BATTLE_STATES.IN_SETTLEMENT;
self.showPopupInCanvas(resultPanelNode);
// Clear player info
@@ -945,6 +941,7 @@ cc.Class({
showPopupInCanvas(toShowNode) {
const self = this;
toShowNode.active = true;
self.disableInputControls();
self.transitToState(ALL_MAP_STATES.SHOWING_MODAL_POPUP);
safelyAddChild(self.widgetsAboveAllNode, toShowNode);

View File

@@ -12,7 +12,6 @@ window.DOWNSYNC_MSG_ACT_INPUT_BATCH = 2;
window.DOWNSYNC_MSG_ACT_BATTLE_STOPPED = 3;
window.DOWNSYNC_MSG_ACT_FORCED_RESYNC = 4;
window.sendSafely = function(msgStr) {
/**
* - "If the data can't be sent (for example, because it needs to be buffered but the buffer is full), the socket is closed automatically."
@@ -28,10 +27,13 @@ window.sendUint8AsBase64Safely = function(msgUint8Arr) {
window.clientSession.send(_uint8ToBase64(msgUint8Arr));
}
window.closeWSConnection = function() {
if (null == window.clientSession || window.clientSession.readyState != WebSocket.OPEN) return;
window.closeWSConnection = function(code, reason) {
if (null == window.clientSession || window.clientSession.readyState != WebSocket.OPEN) {
console.log(`"window.clientSession" is already closed or destroyed.`);
return;
}
console.log(`Closing "window.clientSession" from the client-side.`);
window.clientSession.close();
window.clientSession.close(code, reason);
}
window.getBoundRoomIdFromPersistentStorage = function() {
@@ -184,39 +186,33 @@ window.initPersistentSessionClient = function(onopenCb, expectedRoomId) {
clientSession.onerror = function(evt) {
console.error("Error caught on the WS clientSession: ", evt);
if (window.handleClientSessionError) {
window.handleClientSessionError();
}
window.clearLocalStorageAndBackToLoginScene(true);
};
clientSession.onclose = function(evt) {
// [WARNING] The callback "onclose" might be called AFTER the webpage is refreshed with "1001 == evt.code".
console.warn("The WS clientSession is closed: ", evt, clientSession);
if (false == evt.wasClean) {
/*
Chrome doesn't allow the use of "CustomCloseCode"s (yet) and will callback with a "WebsocketStdCloseCode 1006" and "false == evt.wasClean" here. See https://tools.ietf.org/html/rfc6455#section-7.4 for more information.
*/
if (window.handleClientSessionError) {
window.handleClientSessionError();
}
} else {
switch (evt.code) {
case constants.RET_CODE.PLAYER_NOT_ADDABLE_TO_ROOM:
case constants.RET_CODE.PLAYER_NOT_READDABLE_TO_ROOM:
window.clearBoundRoomIdInBothVolatileAndPersistentStorage();
break;
case constants.RET_CODE.UNKNOWN_ERROR:
case constants.RET_CODE.MYSQL_ERROR:
case constants.RET_CODE.PLAYER_NOT_FOUND:
case constants.RET_CODE.PLAYER_CHEATING:
case 1006: // Peer(i.e. the backend) gone unexpectedly
if (window.handleClientSessionError) {
window.handleClientSessionError();
}
break;
default:
break;
}
console.warn(`The WS clientSession is closed: evt=${JSON.stringify(evt)}, evt.code=${evt.code}`);
switch (evt.code) {
case constants.RET_CODE.BATTLE_STOPPED:
// deliberately do nothing
break;
case constants.RET_CODE.PLAYER_NOT_ADDABLE_TO_ROOM:
case constants.RET_CODE.PLAYER_NOT_READDABLE_TO_ROOM:
window.clearBoundRoomIdInBothVolatileAndPersistentStorage(); // To favor the player to join other rooms
mapIns.onManualRejoinRequired("Couldn't join any room at the moment, please retry");
break;
case constants.RET_CODE.ACTIVE_WATCHDOG:
mapIns.onManualRejoinRequired("Disconnected due to long-time inactivity, please rejoin");
break;
case constants.RET_CODE.UNKNOWN_ERROR:
case constants.RET_CODE.MYSQL_ERROR:
case constants.RET_CODE.PLAYER_NOT_FOUND:
case constants.RET_CODE.PLAYER_CHEATING:
case 1006: // Peer(i.e. the backend) gone unexpectedly
window.clearLocalStorageAndBackToLoginScene(true);
break;
default:
break;
}
};
};
@@ -227,19 +223,7 @@ window.clearLocalStorageAndBackToLoginScene = function(shouldRetainBoundRoomIdIn
if (window.mapIns && window.mapIns.musicEffectManagerScriptIns) {
window.mapIns.musicEffectManagerScriptIns.stopAllMusic();
}
/**
* Here I deliberately removed the callback in the "common `handleClientSessionError` callback"
* within which another invocation to `clearLocalStorageAndBackToLoginScene` will be made.
*
* It'll be re-assigned to the common one upon reentrance of `Map.onLoad`.
*
* -- YFLu 2019-04-06
*/
window.handleClientSessionError = () => {
console.warn("+++++++ Special handleClientSessionError() assigned within `clearLocalStorageAndBackToLoginScene`");
// TBD.
window.handleClientSessionError = null; // To ensure that it's called at most once.
};
window.closeWSConnection();
window.clearSelfPlayer();
if (true != shouldRetainBoundRoomIdInBothVolatileAndPersistentStorage) {