From 9b159f045d2631e8931040b07f05e2a49bebc96c Mon Sep 17 00:00:00 2001 From: oc Date: Fri, 26 Oct 2018 19:36:48 +0800 Subject: [PATCH] Console Opened & Save Hashcode --- libs/control.js | 30 ++++++++++++++++++++++++++---- libs/events.js | 5 +++++ libs/utils.js | 31 +++++++++++++++++++++++++++++-- 3 files changed, 60 insertions(+), 6 deletions(-) diff --git a/libs/control.js b/libs/control.js index c15c547c..c205e65c 100644 --- a/libs/control.js +++ b/libs/control.js @@ -190,6 +190,11 @@ control.prototype.setRequestAnimationFrame = function () { // 执行用户的并行事件处理内容 functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a.plugins.parallelDo(timestamp); + // 检查控制台状态 + if (core.utils.consoleOpened()) { + core.setFlag('consoleOpened', true); + } + window.requestAnimationFrame(draw); } window.requestAnimationFrame(draw); @@ -2213,7 +2218,12 @@ control.prototype.doSL = function (id, type) { } }, function(err) { console.info(err); - core.drawTip("存档失败,请将控制台的报错信息反馈给管理员。"); + if (core.platform.useLocalForage) { + alert("存档失败,请将控制台的报错信息反馈给管理员。"); + } + else { + alert("存档空间不足,请先使用垃圾存档清理工具进行清理!"); + } }) return; } @@ -2222,7 +2232,11 @@ control.prototype.doSL = function (id, type) { core.getLocalForage(id=='autoSave'?id:"save"+id, null, function(data) { if (!core.isset(data)) { - core.drawTip("无效的存档"); + alert("无效的存档"); + return; + } + if (core.isset(data.hashCode) && data.hashCode != core.utils.hashCode(data.hero)) { + alert("存档校验失败,请勿修改存档文件!"); return; } if (data.version != core.firstData.version) { @@ -2250,7 +2264,7 @@ control.prototype.doSL = function (id, type) { }); }, function(err) { console.log(err); - core.drawTip("无效的存档"); + alert("无效的存档"); }) return; @@ -2270,6 +2284,10 @@ control.prototype.doSL = function (id, type) { core.drawTip("游戏难度不匹配!"); return; } + if (core.isset(data.hashCode) && data.hashCode != core.utils.hashCode(data.hero)) { + alert("存档校验失败,请勿修改存档文件!"); + return; + } var route = core.subarray(core.status.route, core.decodeRoute(data.route)); if (!core.isset(route) || data.hero.flags.seed!=core.getFlag('seed')) { core.drawTip("无法从此存档回放录像"); @@ -2389,6 +2407,9 @@ control.prototype.syncLoad = function () { ////// 存档到本地 ////// control.prototype.saveData = function() { + var hero = core.clone(core.status.hero); + var hashCode = core.utils.hashCode(hero); + var data = { 'floorId': core.status.floorId, 'hero': core.clone(core.status.hero), @@ -2398,7 +2419,8 @@ control.prototype.saveData = function() { 'values': core.clone(core.values), 'shops': {}, 'version': core.firstData.version, - "time": new Date().getTime() + "time": new Date().getTime(), + "hashCode": hashCode }; // set shop times for (var shop in core.status.shops) { diff --git a/libs/events.js b/libs/events.js index bfb5ba3f..b25f8c92 100644 --- a/libs/events.js +++ b/libs/events.js @@ -242,6 +242,11 @@ events.prototype.gameOver = function (ending, fromReplay, norank) { core.restart(); }) } + else if (core.hasFlag('consoleOpened')) { + core.drawText("\t[系统提示]本存档开启过控制台,无法上传成绩", function () { + core.restart(); + }) + } else { confirmUpload(); } diff --git a/libs/utils.js b/libs/utils.js index 9a05a0a1..ee7a845c 100644 --- a/libs/utils.js +++ b/libs/utils.js @@ -127,8 +127,12 @@ utils.prototype.removeLocalStorage = function (key) { utils.prototype.setLocalForage = function (key, value, successCallback, errorCallback) { if (!core.platform.useLocalForage) { - this.setLocalStorage(key, value); - if (core.isset(successCallback)) successCallback(); + if (this.setLocalStorage(key, value)) { + if (core.isset(successCallback)) successCallback(); + } + else { + if (core.isset(errorCallback)) errorCallback(); + } return; } @@ -722,6 +726,29 @@ utils.prototype.hide = function (obj, speed, callback) { }, speed); } +utils.prototype.consoleOpened = function () { + var threshold = 160; + var widthThreshold = window.outerWidth - window.innerWidth > threshold; + var heightThreshold = window.outerHeight - window.innerHeight > threshold; + return !(heightThreshold && widthThreshold) && + ((window.Firebug && window.Firebug.chrome && window.Firebug.chrome.isInitialized) + || widthThreshold || heightThreshold); +} + +utils.prototype.hashCode = function (obj) { + if (typeof obj == 'string') { + var hash = 0, i, chr; + if (obj.length === 0) return hash; + for (i = 0; i < obj.length; i++) { + chr = obj.charCodeAt(i); + hash = ((hash << 5) - hash) + chr; + hash |= 0; + } + return hash; + } + return this.hashCode(JSON.stringify(obj).split("").sort().join("")); +} + utils.prototype._export = function (floorIds) { if (!core.isset(floorIds)) floorIds = [core.status.floorId]; else if (floorIds=='all') floorIds = core.clone(core.floorIds);