Commit 21d63ddc authored by nanahira's avatar nanahira

fully support replay recover

parent 59dcd5c1
Pipeline #37821 passed with stages
in 12 minutes and 46 seconds
...@@ -1362,15 +1362,12 @@ class Room ...@@ -1362,15 +1362,12 @@ class Room
@hostinfo.start_lp, @hostinfo.start_hand, @hostinfo.draw_count, @hostinfo.time_limit, @hostinfo.replay_mode] @hostinfo.start_lp, @hostinfo.start_hand, @hostinfo.draw_count, @hostinfo.time_limit, @hostinfo.replay_mode]
if firstSeed if firstSeed
if Array.isArray(firstSeed)
# new replay with extended header and long seed # new replay with extended header and long seed
firstSeedBuf = Buffer.allocUnsafe(firstSeed.length * 4) firstSeedBuf = Buffer.allocUnsafe(firstSeed.length * 4)
for i in [0...firstSeed.length] for i in [0...firstSeed.length]
firstSeedBuf.writeUInt32LE(firstSeed[i], i * 4) firstSeedBuf.writeUInt32LE(firstSeed[i], i * 4)
param.push(firstSeedBuf.toString('base64')) param.push(firstSeedBuf.toString('base64'))
else console.log(firstSeed, firstSeedBuf.toString('base64'))
# old replay with short seed
param.push(firstSeed.toString())
try try
@process = spawn './ygopro', param, {cwd: 'ygopro'} @process = spawn './ygopro', param, {cwd: 'ygopro'}
...@@ -1515,7 +1512,12 @@ class Room ...@@ -1515,7 +1512,12 @@ class Room
return false return false
try try
@recover_replay = await ReplayParser.fromFile(settings.modules.tournament_mode.replay_path + @recover_duel_log.replayFileName) @recover_replay = await ReplayParser.fromFile(settings.modules.tournament_mode.replay_path + @recover_duel_log.replayFileName)
@spawn(if @recover_replay.header.seed_sequence.length then @recover_replay.header.seed_sequence else @recover_replay.header.seed) if !@recover_replay.header.seedSequence.length
# it's old replay, unsupported
log.warn("LOAD RECOVER REPLAY FAIL: Old replay format, unsupported", @recover_duel_log.replayFileName)
@terminate()
return false
@spawn(@recover_replay.header.seedSequence)
return true return true
catch e catch e
log.warn("LOAD RECOVER REPLAY FAIL", e.toString()) log.warn("LOAD RECOVER REPLAY FAIL", e.toString())
......
...@@ -1771,17 +1771,13 @@ ...@@ -1771,17 +1771,13 @@
var e, firstSeedBuf, i, j, param, ref; var e, firstSeedBuf, i, j, param, ref;
param = [0, this.hostinfo.lflist, this.hostinfo.rule, this.hostinfo.mode, this.hostinfo.duel_rule, (this.hostinfo.no_check_deck ? 'T' : 'F'), (this.hostinfo.no_shuffle_deck ? 'T' : 'F'), this.hostinfo.start_lp, this.hostinfo.start_hand, this.hostinfo.draw_count, this.hostinfo.time_limit, this.hostinfo.replay_mode]; param = [0, this.hostinfo.lflist, this.hostinfo.rule, this.hostinfo.mode, this.hostinfo.duel_rule, (this.hostinfo.no_check_deck ? 'T' : 'F'), (this.hostinfo.no_shuffle_deck ? 'T' : 'F'), this.hostinfo.start_lp, this.hostinfo.start_hand, this.hostinfo.draw_count, this.hostinfo.time_limit, this.hostinfo.replay_mode];
if (firstSeed) { if (firstSeed) {
if (Array.isArray(firstSeed)) {
// new replay with extended header and long seed // new replay with extended header and long seed
firstSeedBuf = Buffer.allocUnsafe(firstSeed.length * 4); firstSeedBuf = Buffer.allocUnsafe(firstSeed.length * 4);
for (i = j = 0, ref = firstSeed.length; (0 <= ref ? j < ref : j > ref); i = 0 <= ref ? ++j : --j) { for (i = j = 0, ref = firstSeed.length; (0 <= ref ? j < ref : j > ref); i = 0 <= ref ? ++j : --j) {
firstSeedBuf.writeUInt32LE(firstSeed[i], i * 4); firstSeedBuf.writeUInt32LE(firstSeed[i], i * 4);
} }
param.push(firstSeedBuf.toString('base64')); param.push(firstSeedBuf.toString('base64'));
} else { console.log(firstSeed, firstSeedBuf.toString('base64'));
// old replay with short seed
param.push(firstSeed.toString());
}
} }
try { try {
this.process = spawn('./ygopro', param, { this.process = spawn('./ygopro', param, {
...@@ -1997,7 +1993,13 @@ ...@@ -1997,7 +1993,13 @@
} }
try { try {
this.recover_replay = (await ReplayParser.fromFile(settings.modules.tournament_mode.replay_path + this.recover_duel_log.replayFileName)); this.recover_replay = (await ReplayParser.fromFile(settings.modules.tournament_mode.replay_path + this.recover_duel_log.replayFileName));
this.spawn(this.recover_replay.header.seed_sequence.length ? this.recover_replay.header.seed_sequence : this.recover_replay.header.seed); if (!this.recover_replay.header.seedSequence.length) {
// it's old replay, unsupported
log.warn("LOAD RECOVER REPLAY FAIL: Old replay format, unsupported", this.recover_duel_log.replayFileName);
this.terminate();
return false;
}
this.spawn(this.recover_replay.header.seedSequence);
return true; return true;
} catch (error1) { } catch (error1) {
e = error1; e = error1;
...@@ -2328,9 +2330,9 @@ ...@@ -2328,9 +2330,9 @@
finish_recover(fail) { finish_recover(fail) {
var buffer, j, len, player, ref, results; var buffer, j, len, player, ref, results;
if (fail) { if (fail) {
ygopro.stoc_send_chat_to_room(this, "${recover_fail}", ygopro.constants.COLORS.RED); return ygopro.stoc_send_chat_to_room(this, "${recover_fail}", ygopro.constants.COLORS.RED);
return this.terminate();
} else { } else {
// @terminate()
ygopro.stoc_send_chat_to_room(this, "${recover_success}", ygopro.constants.COLORS.BABYBLUE); ygopro.stoc_send_chat_to_room(this, "${recover_success}", ygopro.constants.COLORS.BABYBLUE);
this.recovering = false; this.recovering = false;
ref = this.get_playing_player(); ref = this.get_playing_player();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment