读档GUID检查;同步存档缩短长度
This commit is contained in:
parent
7433b5117d
commit
ae57ae2cf5
@ -2810,6 +2810,10 @@ var terndefs_f6783a0a_522d_417e_8407_94c67b692e50 = [
|
||||
"!doc": "发送一个HTTP请求 [异步]<br/>type: 请求类型,只能为GET或POST<br/>url: 目标地址<br/>formData: 如果是POST请求则为表单数据<br/>success: 成功后的回调<br/>error: 失败后的回调",
|
||||
"!type": "fn(type: string, url: string, formData: ?, success?: fn(data: string), error?: fn(message: string), mimeType?: string, responseType?: string, onprogress?: fn(loaded: number, total: number))"
|
||||
},
|
||||
"getGuid": {
|
||||
"!doc": "获得或生成浏览器唯一的guid",
|
||||
"!type": "fn() -> string"
|
||||
},
|
||||
"getLocalStorage": {
|
||||
"!doc": "获得本地存储",
|
||||
"!type": "fn(key: string, defaultValue?: ?)"
|
||||
|
||||
@ -1762,6 +1762,10 @@ control.prototype._doSL_load_afterGet = function (id, data) {
|
||||
core.myconfirm("存档版本不匹配!\n你想回放此存档的录像吗?\n可以随时停止录像播放以继续游戏。", _replay);
|
||||
return;
|
||||
}
|
||||
if (data.hero.flags.__events__ && data.guid != core.getGuid()) {
|
||||
core.myconfirm("此存档可能存在风险,你想要播放录像么?", _replay);
|
||||
return;
|
||||
}
|
||||
core.ui.closePanel();
|
||||
core.loadData(data, function() {
|
||||
core.removeFlag('__fromLoad__');
|
||||
@ -1776,7 +1780,9 @@ control.prototype._doSL_load_afterGet = function (id, data) {
|
||||
control.prototype._doSL_replayLoad_afterGet = function (id, data) {
|
||||
if (!data) return core.drawTip("无效的存档");
|
||||
if (data.version != core.firstData.version) return core.drawTip("存档版本不匹配");
|
||||
if (data.hard != core.status.hard) core.drawTip("游戏难度不匹配!");
|
||||
if (data.hard != core.status.hard) return core.drawTip("游戏难度不匹配!");
|
||||
if (data.hero.flags.__events__ && data.guid != core.getGuid())
|
||||
return core.drawTip("此存档可能存在风险,无法读档");
|
||||
var route = core.subarray(core.status.route, core.decodeRoute(data.route));
|
||||
if (route == null || data.hero.flags.__seed__ != core.getFlag('__seed__'))
|
||||
return core.drawTip("无法从此存档回放录像");
|
||||
@ -1832,6 +1838,7 @@ control.prototype._syncSave_http = function (type, saves) {
|
||||
formData.append('type', 'save');
|
||||
formData.append('name', core.firstData.name);
|
||||
formData.append('data', JSON.stringify(saves));
|
||||
formData.append('shorten', '1');
|
||||
|
||||
core.http("POST", "/games/sync.php", formData, function (data) {
|
||||
var response = JSON.parse(data);
|
||||
@ -1852,12 +1859,16 @@ control.prototype._syncSave_http = function (type, saves) {
|
||||
control.prototype.syncLoad = function () {
|
||||
core.myprompt("请输入存档编号+密码", null, function (idpassword) {
|
||||
if (!idpassword) return core.ui.drawSyncSave();
|
||||
if (!/^\d{6}\w{4}$/.test(idpassword)) {
|
||||
core.drawText("不合法的存档编号+密码;应当为6位数字+4位数字字母的组合,如\r[yellow]123456abcd\r。");
|
||||
if (!/^\d{6}\w{4}$/.test(idpassword) && !/^\d{4}\w{3}$/.test(idpassword)) {
|
||||
core.drawText("不合法的存档编号+密码!");
|
||||
return;
|
||||
}
|
||||
core.ui.drawWaiting("正在同步,请稍候...");
|
||||
if (idpassword.length == 7) {
|
||||
core.control._syncLoad_http(idpassword.substring(0, 4), idpassword.substring(3));
|
||||
} else {
|
||||
core.control._syncLoad_http(idpassword.substring(0, 6), idpassword.substring(6));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -1055,57 +1055,16 @@ utils.prototype.hideWithAnimate = function (obj, speed, callback) {
|
||||
}, speed);
|
||||
}
|
||||
|
||||
utils.prototype._encodeCanvas = function (ctx) {
|
||||
var list = [];
|
||||
var width = ctx.canvas.width, height = ctx.canvas.height;
|
||||
ctx.mozImageSmoothingEnabled = false;
|
||||
ctx.webkitImageSmoothingEnabled = false;
|
||||
ctx.msImageSmoothingEnabled = false;
|
||||
ctx.imageSmoothingEnabled = false;
|
||||
|
||||
var imgData = ctx.getImageData(0, 0, width, height);
|
||||
for (var i = 0; i < imgData.data.length; i += 4) {
|
||||
list.push(Math.sign(imgData.data[i + 3]));
|
||||
}
|
||||
// compress 01 to array
|
||||
var prev = 0, cnt = 0, arr = [];
|
||||
for (var i = 0; i < list.length; i++) {
|
||||
if (list[i] != prev) {
|
||||
arr.push(cnt);
|
||||
prev = list[i];
|
||||
cnt = 0;
|
||||
}
|
||||
cnt++;
|
||||
}
|
||||
arr.push(cnt);
|
||||
return arr;
|
||||
}
|
||||
|
||||
////// 解析arr数组,并绘制到tempCanvas上 //////
|
||||
utils.prototype._decodeCanvas = function (arr, width, height) {
|
||||
// 清空tempCanvas
|
||||
var tempCanvas = core.bigmap.tempCanvas;
|
||||
tempCanvas.canvas.width = width;
|
||||
tempCanvas.canvas.height = height;
|
||||
tempCanvas.clearRect(0, 0, width, height);
|
||||
|
||||
if (!arr) return null;
|
||||
// to byte array
|
||||
var curr = 0, list = [];
|
||||
arr.forEach(function (x) {
|
||||
for (var i = 0; i < x; i++) list.push(curr);
|
||||
curr = 1 - curr;
|
||||
})
|
||||
|
||||
var imgData = tempCanvas.getImageData(0, 0, width, height);
|
||||
for (var i = 0; i < imgData.data.length; i += 4) {
|
||||
var index = i / 4;
|
||||
if (list[index]) {
|
||||
imgData.data[i] = 255;
|
||||
imgData.data[i + 3] = 255;
|
||||
}
|
||||
}
|
||||
tempCanvas.putImageData(imgData, 0, 0);
|
||||
////// 生成浏览器唯一的 guid //////
|
||||
utils.prototype.getGuid = function () {
|
||||
var guid = localStorage.getItem('guid');
|
||||
if (guid != null) return guid;
|
||||
guid = 'xxxxxxxx_xxxx_4xxx_yxxx_xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
||||
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
|
||||
return v.toString(16);
|
||||
});
|
||||
localStorage.setItem('guid', guid);
|
||||
return guid;
|
||||
}
|
||||
|
||||
utils.prototype.same = function (a, b) {
|
||||
|
||||
@ -949,6 +949,7 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a =
|
||||
'route': core.encodeRoute(core.status.route),
|
||||
'values': values,
|
||||
'version': core.firstData.version,
|
||||
'guid': core.getGuid(),
|
||||
"time": new Date().getTime()
|
||||
};
|
||||
|
||||
|
||||
@ -231,7 +231,7 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 =
|
||||
var data = core.status.event.data.current;
|
||||
var choices = data.choices;
|
||||
var topIndex = core.actions.HSIZE - parseInt((choices.length - 1) / 2) + (core.status.event.ui.offset || 0);
|
||||
if (keycode == 88) { // X
|
||||
if (keycode == 88 || keycode == 27) { // X, ESC
|
||||
core.actions._clickAction(core.actions.HSIZE, topIndex + choices.length - 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
3
runtime.d.ts
vendored
3
runtime.d.ts
vendored
@ -2564,6 +2564,9 @@ declare class utils {
|
||||
*/
|
||||
http(type: 'GET' | 'POST', url: string, formData: FormData, success: () => void, error: () => void): void
|
||||
|
||||
/** 获得浏览器唯一的guid */
|
||||
getGuid(): string
|
||||
|
||||
/** 解压缩一个数据 */
|
||||
decompress(value: any): any
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user