Updated logs in frontend.

This commit is contained in:
yflu 2022-10-25 00:05:38 +08:00
parent c69aa25353
commit fe826b393b
4 changed files with 42 additions and 49 deletions

View File

@ -1159,11 +1159,11 @@ func (pR *Room) applyInputFrameDownsyncDynamics(fromRenderFrameId int32, toRende
playerShape := playerCollider.Shape.(*resolv.ConvexPolygon) playerShape := playerCollider.Shape.(*resolv.ConvexPolygon)
barrierShape := collision.Objects[0].Shape.(*resolv.ConvexPolygon) barrierShape := collision.Objects[0].Shape.(*resolv.ConvexPolygon)
if overlapped, pushbackX, pushbackY := CalcPushbacks(oldDx, oldDy, playerShape, barrierShape); overlapped { if overlapped, pushbackX, pushbackY := CalcPushbacks(oldDx, oldDy, playerShape, barrierShape); overlapped {
Logger.Info(fmt.Sprintf("Collided & overlapped: player.X=%v, player.Y=%v, oldDx=%v, oldDy=%v, playerShape=%v, toCheckBarrier=%v, pushbackX=%v, pushbackY=%v", playerCollider.X, playerCollider.Y, oldDx, oldDy, ConvexPolygonStr(playerShape), ConvexPolygonStr(barrierShape), pushbackX, pushbackY)) Logger.Debug(fmt.Sprintf("Collided & overlapped: player.X=%v, player.Y=%v, oldDx=%v, oldDy=%v, playerShape=%v, toCheckBarrier=%v, pushbackX=%v, pushbackY=%v", playerCollider.X, playerCollider.Y, oldDx, oldDy, ConvexPolygonStr(playerShape), ConvexPolygonStr(barrierShape), pushbackX, pushbackY))
dx -= pushbackX dx -= pushbackX
dy -= pushbackY dy -= pushbackY
} else { } else {
Logger.Info(fmt.Sprintf("Collider BUT not overlapped: player.X=%v, player.Y=%v, oldDx=%v, oldDy=%v, playerShape=%v, toCheckBarrier=%v", playerCollider.X, playerCollider.Y, oldDx, oldDy, ConvexPolygonStr(playerShape), ConvexPolygonStr(barrierShape))) Logger.Debug(fmt.Sprintf("Collider BUT not overlapped: player.X=%v, player.Y=%v, oldDx=%v, oldDy=%v, playerShape=%v, toCheckBarrier=%v", playerCollider.X, playerCollider.Y, oldDx, oldDy, ConvexPolygonStr(playerShape), ConvexPolygonStr(barrierShape)))
} }
} }
playerCollider.X += dx playerCollider.X += dx

View File

@ -440,7 +440,7 @@
"array": [ "array": [
0, 0,
0, 0,
344.6781107062066, 344.75930058781137,
0, 0,
0, 0,
0, 0,

View File

@ -67,19 +67,6 @@ cc.Class({
onLoad() { onLoad() {
//kobako: 腾讯统计代码
//WARN: 打包到微信小游戏的时候会导致出错
/*
(function() {
var mta = document.createElement("script");
mta.src = "//pingjs.qq.com/h5/stats.js?v2.0.4";
mta.setAttribute("name", "MTAH5");
mta.setAttribute("sid", "500674632");
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(mta, s);
})();
*/
window.atFirstLocationHref = window.location.href.split('#')[0]; window.atFirstLocationHref = window.location.href.split('#')[0];
const self = this; const self = this;
self.getRetCodeList(); self.getRetCodeList();
@ -97,10 +84,8 @@ cc.Class({
self.smsLoginCaptchaLabel.active = true; self.smsLoginCaptchaLabel.active = true;
self.loginButton.active = true; self.loginButton.active = true;
self.checkPhoneNumber = self.checkPhoneNumber.bind(self); self.onLoginButtonClicked = self.onLoginButtonClicked.bind(self);
self.checkIntAuthTokenExpire = self.checkIntAuthTokenExpire.bind(self); self.onSMSCaptchaGetButtonClicked = self.onSMSCaptchaGetButtonClicked.bind(self);
self.checkCaptcha = self.checkCaptcha.bind(self);
self.onSMSCaptchaGetButtonClicked = self.onSMSCaptchaGetButtonClicked.bind(self);
self.smsLoginCaptchaButton.on('click', self.onSMSCaptchaGetButtonClicked); self.smsLoginCaptchaButton.on('click', self.onSMSCaptchaGetButtonClicked);
self.loadingNode = cc.instantiate(this.loadingPrefab); self.loadingNode = cc.instantiate(this.loadingPrefab);
@ -125,11 +110,12 @@ cc.Class({
window.WsReq = protoRoot.lookupType("treasurehunterx.WsReq"); window.WsReq = protoRoot.lookupType("treasurehunterx.WsReq");
window.WsResp = protoRoot.lookupType("treasurehunterx.WsResp"); window.WsResp = protoRoot.lookupType("treasurehunterx.WsResp");
self.checkIntAuthTokenExpire().then( self.checkIntAuthTokenExpire().then(
() => { (intAuthToken) => {
const intAuthToken = JSON.parse(cc.sys.localStorage.getItem('selfPlayer')).intAuthToken; console.log("Successfully found `intAuthToken` in local cache");
self.useTokenLogin(intAuthToken); self.useTokenLogin(intAuthToken);
}, },
() => { () => {
console.warn("Failed to find `intAuthToken` in local cache");
window.clearBoundRoomIdInBothVolatileAndPersistentStorage(); window.clearBoundRoomIdInBothVolatileAndPersistentStorage();
} }
); );
@ -221,11 +207,28 @@ cc.Class({
checkIntAuthTokenExpire() { checkIntAuthTokenExpire() {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (!cc.sys.localStorage.getItem('selfPlayer')) { if (!cc.sys.localStorage.getItem('selfPlayer')) {
console.warn("Couldn't find selfPlayer key in local cache");
reject(); reject();
return; return;
} }
const selfPlayer = JSON.parse(cc.sys.localStorage.getItem('selfPlayer')); const selfPlayer = JSON.parse(cc.sys.localStorage.getItem('selfPlayer'));
(selfPlayer.intAuthToken && new Date().getTime() < selfPlayer.expiresAt) ? resolve() : reject(); if (null == selfPlayer) {
console.warn("Couldn't find selfPlayer object in local cache");
reject();
return;
}
if (null == selfPlayer.intAuthToken) {
console.warn("Couldn't find selfPlayer object with key `intAuthToken` in local cache");
reject();
return;
}
if (new Date().getTime() > selfPlayer.expiresAt) {
console.warn("Couldn't find unexpired selfPlayer `intAuthToken` in local cache");
reject();
return;
}
resolve(selfPlayer.intAuthToken);
}) })
}, },
@ -278,13 +281,15 @@ cc.Class({
intAuthToken: _intAuthToken intAuthToken: _intAuthToken
}, },
success: function(resp) { success: function(resp) {
console.log("Login attempt `useTokenLogin` succeeded.");
self.onLoggedIn(resp); self.onLoggedIn(resp);
}, },
error: function(xhr, status, errMsg) { error: function(xhr, status, errMsg) {
console.log("Login attempt `useTokenLogin` failed, about to execute `clearBoundRoomIdInBothVolatileAndPersistentStorage`."); console.warn("Login attempt `useTokenLogin` failed, about to execute `clearBoundRoomIdInBothVolatileAndPersistentStorage`.");
window.clearBoundRoomIdInBothVolatileAndPersistentStorage() window.clearBoundRoomIdInBothVolatileAndPersistentStorage()
}, },
timeout: function() { timeout: function() {
console.warn("Login attempt `useTokenLogin` timed out, about to enable interactive controls.");
self.enableInteractiveControls(true); self.enableInteractiveControls(true);
}, },
}); });
@ -335,7 +340,7 @@ cc.Class({
onLoggedIn(res) { onLoggedIn(res) {
const self = this; const self = this;
cc.log(`OnLoggedIn ${JSON.stringify(res)}.`) console.log("OnLoggedIn ", JSON.stringify(res))
if (res.ret === self.retCodeDict.OK) { if (res.ret === self.retCodeDict.OK) {
self.enableInteractiveControls(false); self.enableInteractiveControls(false);
const date = Number(res.expiresAt); const date = Number(res.expiresAt);
@ -360,6 +365,7 @@ cc.Class({
); );
cc.director.loadScene('default_map'); cc.director.loadScene('default_map');
} else { } else {
console.log("OnLoggedIn failed, about to remove `selfPlayer` in local cache.")
cc.sys.localStorage.removeItem("selfPlayer"); cc.sys.localStorage.removeItem("selfPlayer");
window.clearBoundRoomIdInBothVolatileAndPersistentStorage(); window.clearBoundRoomIdInBothVolatileAndPersistentStorage();
self.enableInteractiveControls(true); self.enableInteractiveControls(true);

View File

@ -104,18 +104,6 @@ window.getExpectedRoomIdSync = function() {
return null; return null;
}; };
window.unsetClientSessionCloseOrErrorFlag = function() {
cc.sys.localStorage.removeItem("ClientSessionCloseOrErrorFlag");
return;
}
window.setClientSessionCloseOrErrorFlag = function() {
const oldVal = cc.sys.localStorage.getItem("ClientSessionCloseOrErrorFlag");
if (true == oldVal) return false;
cc.sys.localStorage.setItem("ClientSessionCloseOrErrorFlag", true);
return true;
}
window.initPersistentSessionClient = function(onopenCb, expectedRoomId) { window.initPersistentSessionClient = function(onopenCb, expectedRoomId) {
if (window.clientSession && window.clientSession.readyState == WebSocket.OPEN) { if (window.clientSession && window.clientSession.readyState == WebSocket.OPEN) {
if (null != onopenCb) { if (null != onopenCb) {
@ -123,8 +111,10 @@ window.initPersistentSessionClient = function(onopenCb, expectedRoomId) {
} }
return; return;
} }
const intAuthToken = cc.sys.localStorage.getItem("selfPlayer") ? JSON.parse(cc.sys.localStorage.getItem('selfPlayer')).intAuthToken : ""; const selfPlayerStr = cc.sys.localStorage.getItem("selfPlayer");
const selfPlayer = null == selfPlayerStr ? null : JSON.parse(selfPlayerStr);
const intAuthToken = null == selfPlayer ? "" : selfPlayer.intAuthToken;
let urlToConnect = backendAddress.PROTOCOL.replace('http', 'ws') + '://' + backendAddress.HOST + ":" + backendAddress.PORT + backendAddress.WS_PATH_PREFIX + "?intAuthToken=" + intAuthToken; let urlToConnect = backendAddress.PROTOCOL.replace('http', 'ws') + '://' + backendAddress.HOST + ":" + backendAddress.PORT + backendAddress.WS_PATH_PREFIX + "?intAuthToken=" + intAuthToken;
@ -141,11 +131,12 @@ window.initPersistentSessionClient = function(onopenCb, expectedRoomId) {
const currentHistoryState = window.history && window.history.state ? window.history.state : {}; const currentHistoryState = window.history && window.history.state ? window.history.state : {};
window.clientSession = null; // Important for checking whether the "onclose" event is still relevant!
const clientSession = new WebSocket(urlToConnect); const clientSession = new WebSocket(urlToConnect);
clientSession.binaryType = 'arraybuffer'; // Make 'event.data' of 'onmessage' an "ArrayBuffer" instead of a "Blob" clientSession.binaryType = 'arraybuffer'; // Make 'event.data' of 'onmessage' an "ArrayBuffer" instead of a "Blob"
clientSession.onopen = function(event) { clientSession.onopen = function(event) {
console.log("The WS clientSession is opened."); console.log("The WS clientSession is opened. clientSession.id=", clientSession.id);
window.clientSession = clientSession; window.clientSession = clientSession;
if (null == onopenCb) return; if (null == onopenCb) return;
onopenCb(); onopenCb();
@ -208,9 +199,6 @@ window.initPersistentSessionClient = function(onopenCb, expectedRoomId) {
}; };
clientSession.onerror = function(event) { clientSession.onerror = function(event) {
if (!window.setClientSessionCloseOrErrorFlag()) {
return;
}
console.error("Error caught on the WS clientSession: ", event); console.error("Error caught on the WS clientSession: ", event);
if (window.clientSessionPingInterval) { if (window.clientSessionPingInterval) {
clearInterval(window.clientSessionPingInterval); clearInterval(window.clientSessionPingInterval);
@ -218,14 +206,14 @@ window.initPersistentSessionClient = function(onopenCb, expectedRoomId) {
if (window.handleClientSessionCloseOrError) { if (window.handleClientSessionCloseOrError) {
window.handleClientSessionCloseOrError(); window.handleClientSessionCloseOrError();
} }
window.unsetClientSessionCloseOrErrorFlag();
}; };
clientSession.onclose = function(event) { clientSession.onclose = function(event) {
if (!window.setClientSessionCloseOrErrorFlag()) { if (null == window.clientSession) {
return; console.log("Received an outdated WS clientSession onclose event: ", event, clientSession);
} return;
console.warn("The WS clientSession is closed: ", event); }
console.warn("The WS clientSession is closed: ", event, clientSession);
if (window.clientSessionPingInterval) { if (window.clientSessionPingInterval) {
clearInterval(window.clientSessionPingInterval); clearInterval(window.clientSessionPingInterval);
} }
@ -248,7 +236,6 @@ window.initPersistentSessionClient = function(onopenCb, expectedRoomId) {
window.handleClientSessionCloseOrError(); window.handleClientSessionCloseOrError();
} }
} }
window.unsetClientSessionCloseOrErrorFlag();
}; };
}; };