Commit 17b16309 authored by nanahira's avatar nanahira

fix

parent f83dbaaa
Pipeline #29621 passed with stages
in 21 minutes and 46 seconds
...@@ -1586,885 +1586,882 @@ ...@@ -1586,885 +1586,882 @@
}); });
}; };
Room = (function() { Room = class Room {
class Room { constructor(name, hostinfo) {
constructor(name, hostinfo) { var death_time, draw_count, duel_rule, extra_mode_func, lflist, param, rule, start_hand, start_lp, time_limit;
var death_time, draw_count, duel_rule, extra_mode_func, lflist, param, rule, start_hand, start_lp, time_limit; this.hostinfo = hostinfo;
this.hostinfo = hostinfo; this.name = name;
this.name = name; //@alive = true
//@alive = true this.players = [];
this.players = []; this.player_datas = [];
this.player_datas = []; this.status = 'starting';
this.status = 'starting'; //@started = false
//@started = false this.established = false;
this.established = false; this.watcher_buffers = [];
this.watcher_buffers = []; this.recorder_buffers = [];
this.recorder_buffers = []; this.cloud_replay_id = Math.floor(Math.random() * Number.MAX_SAFE_INTEGER);
this.cloud_replay_id = Math.floor(Math.random() * Number.MAX_SAFE_INTEGER); this.watchers = [];
this.watchers = []; this.random_type = '';
this.random_type = ''; this.welcome = '';
this.welcome = ''; this.scores = {};
this.scores = {}; this.decks = {};
this.decks = {}; this.duel_count = 0;
this.duel_count = 0; this.death = 0;
this.death = 0; this.turn = 0;
this.turn = 0; this.duel_stage = ygopro.constants.DUEL_STAGE.BEGIN;
this.duel_stage = ygopro.constants.DUEL_STAGE.BEGIN; this.replays = [];
this.replays = []; this.first_list = [];
this.first_list = []; ROOM_all.push(this);
ROOM_all.push(this); this.hostinfo || (this.hostinfo = JSON.parse(JSON.stringify(settings.hostinfo)));
this.hostinfo || (this.hostinfo = JSON.parse(JSON.stringify(settings.hostinfo))); delete this.hostinfo.comment;
delete this.hostinfo.comment; if (lflists.length) {
if (lflists.length) { if (this.hostinfo.rule === 1 && this.hostinfo.lflist === 0) {
if (this.hostinfo.rule === 1 && this.hostinfo.lflist === 0) { this.hostinfo.lflist = _.findIndex(lflists, function(list) {
this.hostinfo.lflist = _.findIndex(lflists, function(list) { return list.tcg;
return list.tcg; });
});
}
} else {
this.hostinfo.lflist = -1;
} }
if (name.slice(0, 2) === 'M#') { } else {
this.hostinfo.lflist = -1;
}
if (name.slice(0, 2) === 'M#') {
this.hostinfo.mode = 1;
} else if (name.slice(0, 2) === 'T#') {
this.hostinfo.mode = 2;
this.hostinfo.start_lp = 16000;
} else if (name.slice(0, 3) === 'AI#') {
this.hostinfo.rule = 5;
this.hostinfo.lflist = -1;
this.hostinfo.time_limit = 999;
} else if ((param = name.match(/^(\d)(\d)([12345TF])(T|F)(T|F)(\d+),(\d+),(\d+)/i))) {
this.hostinfo.rule = parseInt(param[1]);
this.hostinfo.mode = parseInt(param[2]);
this.hostinfo.duel_rule = (parseInt(param[3]) ? parseInt(param[3]) : (param[3] === 'T' ? 3 : 5));
this.hostinfo.no_check_deck = param[4] === 'T';
this.hostinfo.no_shuffle_deck = param[5] === 'T';
this.hostinfo.start_lp = parseInt(param[6]);
this.hostinfo.start_hand = parseInt(param[7]);
this.hostinfo.draw_count = parseInt(param[8]);
} else if ((param = name.match(/(.+)#/)) !== null) {
rule = param[1].toUpperCase();
if (rule.match(/(^|,|,)(M|MATCH)(,|,|$)/)) {
this.hostinfo.mode = 1; this.hostinfo.mode = 1;
} else if (name.slice(0, 2) === 'T#') { }
if (rule.match(/(^|,|,)(T|TAG)(,|,|$)/)) {
this.hostinfo.mode = 2; this.hostinfo.mode = 2;
this.hostinfo.start_lp = 16000; this.hostinfo.start_lp = 16000;
} else if (name.slice(0, 3) === 'AI#') { }
if (rule.match(/(^|,|,)(TCGONLY|TO)(,|,|$)/)) {
this.hostinfo.rule = 1;
this.hostinfo.lflist = _.findIndex(lflists, function(list) {
return list.tcg;
});
}
if (rule.match(/(^|,|,)(OCGONLY|OO)(,|,|$)/)) {
this.hostinfo.rule = 0;
this.hostinfo.lflist = 0;
}
if (rule.match(/(^|,|,)(OT|TCG)(,|,|$)/)) {
this.hostinfo.rule = 5; this.hostinfo.rule = 5;
}
if (rule.match(/(^|,|,)(SC|CN|CCG|CHINESE)(,|,|$)/)) {
this.hostinfo.rule = 2;
this.hostinfo.lflist = -1; this.hostinfo.lflist = -1;
this.hostinfo.time_limit = 999; }
} else if ((param = name.match(/^(\d)(\d)([12345TF])(T|F)(T|F)(\d+),(\d+),(\d+)/i))) { if ((param = rule.match(/(^|,|,)LP(\d+)(,|,|$)/))) {
this.hostinfo.rule = parseInt(param[1]); start_lp = parseInt(param[2]);
this.hostinfo.mode = parseInt(param[2]); if (start_lp <= 0) {
this.hostinfo.duel_rule = (parseInt(param[3]) ? parseInt(param[3]) : (param[3] === 'T' ? 3 : 5)); start_lp = 1;
this.hostinfo.no_check_deck = param[4] === 'T';
this.hostinfo.no_shuffle_deck = param[5] === 'T';
this.hostinfo.start_lp = parseInt(param[6]);
this.hostinfo.start_hand = parseInt(param[7]);
this.hostinfo.draw_count = parseInt(param[8]);
} else if ((param = name.match(/(.+)#/)) !== null) {
rule = param[1].toUpperCase();
if (rule.match(/(^|,|,)(M|MATCH)(,|,|$)/)) {
this.hostinfo.mode = 1;
}
if (rule.match(/(^|,|,)(T|TAG)(,|,|$)/)) {
this.hostinfo.mode = 2;
this.hostinfo.start_lp = 16000;
}
if (rule.match(/(^|,|,)(TCGONLY|TO)(,|,|$)/)) {
this.hostinfo.rule = 1;
this.hostinfo.lflist = _.findIndex(lflists, function(list) {
return list.tcg;
});
}
if (rule.match(/(^|,|,)(OCGONLY|OO)(,|,|$)/)) {
this.hostinfo.rule = 0;
this.hostinfo.lflist = 0;
}
if (rule.match(/(^|,|,)(OT|TCG)(,|,|$)/)) {
this.hostinfo.rule = 5;
}
if (rule.match(/(^|,|,)(SC|CN|CCG|CHINESE)(,|,|$)/)) {
this.hostinfo.rule = 2;
this.hostinfo.lflist = -1;
}
if ((param = rule.match(/(^|,|,)LP(\d+)(,|,|$)/))) {
start_lp = parseInt(param[2]);
if (start_lp <= 0) {
start_lp = 1;
}
if (start_lp >= 99999) {
start_lp = 99999;
}
this.hostinfo.start_lp = start_lp;
}
if ((param = rule.match(/(^|,|,)(TIME|TM|TI)(\d+)(,|,|$)/))) {
time_limit = parseInt(param[3]);
if (time_limit < 0) {
time_limit = 180;
}
if (time_limit >= 1 && time_limit <= 60) {
time_limit = time_limit * 60;
}
if (time_limit >= 999) {
time_limit = 999;
}
this.hostinfo.time_limit = time_limit;
}
if ((param = rule.match(/(^|,|,)(START|ST)(\d+)(,|,|$)/))) {
start_hand = parseInt(param[3]);
if (start_hand <= 0) {
start_hand = 1;
}
if (start_hand >= 40) {
start_hand = 40;
}
this.hostinfo.start_hand = start_hand;
}
if ((param = rule.match(/(^|,|,)(DRAW|DR)(\d+)(,|,|$)/))) {
draw_count = parseInt(param[3]);
if (draw_count >= 35) {
draw_count = 35;
}
this.hostinfo.draw_count = draw_count;
}
if ((param = rule.match(/(^|,|,)(LFLIST|LF)(\d+)(,|,|$)/))) {
lflist = parseInt(param[3]) - 1;
this.hostinfo.lflist = lflist;
}
for (extra_mode_func of extra_mode_list) {
extra_mode_func.call(this, rule);
}
if (rule.match(/(^|,|,)(NOLFLIST|NF)(,|,|$)/)) {
this.hostinfo.lflist = -1;
}
if (rule.match(/(^|,|,)(NOUNIQUE|NU)(,|,|$)/)) {
this.hostinfo.rule = 4;
}
if (rule.match(/(^|,|,)(CUSTOM|DIY)(,|,|$)/)) {
this.hostinfo.rule = 3;
} }
if (rule.match(/(^|,|,)(NOCHECK|NC)(,|,|$)/)) { if (start_lp >= 99999) {
this.hostinfo.no_check_deck = true; start_lp = 99999;
} }
if (rule.match(/(^|,|,)(NOSHUFFLE|NS)(,|,|$)/)) { this.hostinfo.start_lp = start_lp;
this.hostinfo.no_shuffle_deck = true; }
if ((param = rule.match(/(^|,|,)(TIME|TM|TI)(\d+)(,|,|$)/))) {
time_limit = parseInt(param[3]);
if (time_limit < 0) {
time_limit = 180;
} }
if (rule.match(/(^|,|,)(IGPRIORITY|PR)(,|,|$)/)) { // deprecated if (time_limit >= 1 && time_limit <= 60) {
this.hostinfo.duel_rule = 4; time_limit = time_limit * 60;
} }
if ((param = rule.match(/(^|,|,)(DUELRULE|MR)(\d+)(,|,|$)/))) { if (time_limit >= 999) {
duel_rule = parseInt(param[3]); time_limit = 999;
if (duel_rule && duel_rule > 0 && duel_rule <= 5) {
this.hostinfo.duel_rule = duel_rule;
}
} }
if (rule.match(/(^|,|,)(NOWATCH|NW)(,|,|$)/)) { this.hostinfo.time_limit = time_limit;
this.hostinfo.no_watch = true; }
if ((param = rule.match(/(^|,|,)(START|ST)(\d+)(,|,|$)/))) {
start_hand = parseInt(param[3]);
if (start_hand <= 0) {
start_hand = 1;
} }
if ((param = rule.match(/(^|,|,)(DEATH|DH)(\d*)(,|,|$)/))) { if (start_hand >= 40) {
death_time = parseInt(param[3]); start_hand = 40;
if (death_time && death_time > 0) {
this.hostinfo.auto_death = death_time;
} else {
this.hostinfo.auto_death = 40;
}
} }
if (settings.modules.tournament_mode.enable_recover && (param = rule.match(/(^|,|,)(RC|RECOVER)(\d*)T(\d*)(,|,|$)/))) { this.hostinfo.start_hand = start_hand;
this.recovered = true; }
this.recovering = true; if ((param = rule.match(/(^|,|,)(DRAW|DR)(\d+)(,|,|$)/))) {
this.recover_from_turn = parseInt(param[4]); draw_count = parseInt(param[3]);
this.recover_duel_log_id = parseInt(param[3]); if (draw_count >= 35) {
this.recover_buffers = [[], [], [], []]; draw_count = 35;
this.welcome = "${recover_hint}";
} }
this.hostinfo.draw_count = draw_count;
}
if ((param = rule.match(/(^|,|,)(LFLIST|LF)(\d+)(,|,|$)/))) {
lflist = parseInt(param[3]) - 1;
this.hostinfo.lflist = lflist;
} }
this.hostinfo.replay_mode = 0; for (extra_mode_func of extra_mode_list) {
if (settings.modules.tournament_mode.enabled) { // 0x1: Save the replays in file extra_mode_func.call(this, rule);
this.hostinfo.replay_mode |= 0x1;
} }
if ((settings.modules.tournament_mode.enabled && settings.modules.tournament_mode.block_replay_to_player) || (this.hostinfo.mode === 1 && settings.modules.replay_delay)) { // 0x2: Block the replays to observers if (rule.match(/(^|,|,)(NOLFLIST|NF)(,|,|$)/)) {
this.hostinfo.replay_mode |= 0x2; this.hostinfo.lflist = -1;
} }
if (settings.modules.tournament_mode.enabled || this.arena) { // 0x4: Save chat in cloud replay if (rule.match(/(^|,|,)(NOUNIQUE|NU)(,|,|$)/)) {
this.hostinfo.replay_mode |= 0x4; this.hostinfo.rule = 4;
} }
if (!this.recovered) { if (rule.match(/(^|,|,)(CUSTOM|DIY)(,|,|$)/)) {
this.spawn(); this.hostinfo.rule = 3;
} }
} if (rule.match(/(^|,|,)(NOCHECK|NC)(,|,|$)/)) {
this.hostinfo.no_check_deck = true;
spawn(firstSeed) { }
var e, i, j, l, param, seeds; if (rule.match(/(^|,|,)(NOSHUFFLE|NS)(,|,|$)/)) {
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]; this.hostinfo.no_shuffle_deck = true;
if (firstSeed) { }
param.push(firstSeed); if (rule.match(/(^|,|,)(IGPRIORITY|PR)(,|,|$)/)) { // deprecated
seeds = getSeedTimet(2); this.hostinfo.duel_rule = 4;
for (i = j = 0; j < 2; i = ++j) { }
param.push(seeds[i]); if ((param = rule.match(/(^|,|,)(DUELRULE|MR)(\d+)(,|,|$)/))) {
duel_rule = parseInt(param[3]);
if (duel_rule && duel_rule > 0 && duel_rule <= 5) {
this.hostinfo.duel_rule = duel_rule;
} }
} else { }
seeds = getSeedTimet(3); if (rule.match(/(^|,|,)(NOWATCH|NW)(,|,|$)/)) {
for (i = l = 0; l < 3; i = ++l) { this.hostinfo.no_watch = true;
param.push(seeds[i]); }
if ((param = rule.match(/(^|,|,)(DEATH|DH)(\d*)(,|,|$)/))) {
death_time = parseInt(param[3]);
if (death_time && death_time > 0) {
this.hostinfo.auto_death = death_time;
} else {
this.hostinfo.auto_death = 40;
} }
} }
try { if (settings.modules.tournament_mode.enable_recover && (param = rule.match(/(^|,|,)(RC|RECOVER)(\d*)T(\d*)(,|,|$)/))) {
this.process = spawn('./ygopro', param, { this.recovered = true;
cwd: 'ygopro' this.recovering = true;
}); this.recover_from_turn = parseInt(param[4]);
this.process_pid = this.process.pid; this.recover_duel_log_id = parseInt(param[3]);
this.process.on('error', (err) => { this.recover_buffers = [[], [], [], []];
log.warn('CREATE ROOM ERROR', err); this.welcome = "${recover_hint}";
_.each(this.players, function(player) {
return ygopro.stoc_die(player, "${create_room_failed}");
});
this.delete();
});
this.process.on('exit', (code) => {
if (!this.disconnector) {
this.disconnector = 'server';
}
this.delete();
});
this.process.stdout.setEncoding('utf8');
this.process.stdout.once('data', (data) => {
this.established = true;
if (!this.windbot && settings.modules.http.websocket_roomlist) {
roomlist.create(this);
}
this.port = parseInt(data);
_.each(this.players, (player) => {
player.server.connect(this.port, '127.0.0.1', async function() {
var buffer, len, m, ref;
ref = player.pre_establish_buffers;
for (m = 0, len = ref.length; m < len; m++) {
buffer = ref[m];
await ygopro.helper.send(player.server, buffer);
}
player.established = true;
player.pre_establish_buffers = [];
});
});
if (this.windbot) {
setTimeout(() => {
return this.add_windbot(this.windbot);
}, 200);
}
});
return this.process.stderr.on('data', async(data) => {
data = "Debug: " + data;
data = data.replace(/\n$/, "");
log.info("YGOPRO " + data);
ygopro.stoc_send_chat_to_room(this, data, ygopro.constants.COLORS.RED);
this.has_ygopro_error = true;
this.ygopro_error_length = this.ygopro_error_length ? this.ygopro_error_length + data.length : data.length;
if (this.ygopro_error_length > 10000) {
await this.send_replays();
this.process.kill();
}
});
} catch (error1) {
e = error1;
log.warn('CREATE ROOM FAIL', e);
return this.error = "${create_room_failed}";
} }
} }
this.hostinfo.replay_mode = 0;
if (settings.modules.tournament_mode.enabled) { // 0x1: Save the replays in file
this.hostinfo.replay_mode |= 0x1;
}
if ((settings.modules.tournament_mode.enabled && settings.modules.tournament_mode.block_replay_to_player) || (this.hostinfo.mode === 1 && settings.modules.replay_delay)) { // 0x2: Block the replays to observers
this.hostinfo.replay_mode |= 0x2;
}
if (settings.modules.tournament_mode.enabled || this.arena) { // 0x4: Save chat in cloud replay
this.hostinfo.replay_mode |= 0x4;
}
if (!this.recovered) {
this.spawn();
}
}
delete() { spawn(firstSeed) {
var end_time, formatted_replays, index, j, len, log_rep_id, name, player_datas, recorder_buffer, ref, ref1, repbuf, replay_id, room_name, score, score_array, score_form; var e, i, j, l, param, seeds;
if (this.deleted) { 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];
return; if (firstSeed) {
param.push(firstSeed);
seeds = getSeedTimet(2);
for (i = j = 0; j < 2; i = ++j) {
param.push(seeds[i]);
} }
//log.info 'room-delete', this.name, ROOM_all.length } else {
score_array = []; seeds = getSeedTimet(3);
ref = this.scores; for (i = l = 0; l < 3; i = ++l) {
for (name in ref) { param.push(seeds[i]);
score = ref[name]; }
score_form = { }
name: name.split('$')[0], try {
score: score, this.process = spawn('./ygopro', param, {
deck: null, cwd: 'ygopro'
name_vpass: name });
}; this.process_pid = this.process.pid;
if (this.decks[name]) { this.process.on('error', (err) => {
score_form.deck = this.decks[name]; log.warn('CREATE ROOM ERROR', err);
_.each(this.players, function(player) {
return ygopro.stoc_die(player, "${create_room_failed}");
});
this.delete();
});
this.process.on('exit', (code) => {
if (!this.disconnector) {
this.disconnector = 'server';
} }
score_array.push(score_form); this.delete();
} });
if (settings.modules.random_duel.record_match_scores && this.random_type === 'M') { this.process.stdout.setEncoding('utf8');
if (score_array.length === 2) { this.process.stdout.once('data', (data) => {
if (score_array[0].score !== score_array[1].score) { this.established = true;
if (score_array[0].score > score_array[1].score) { if (!this.windbot && settings.modules.http.websocket_roomlist) {
ROOM_player_win(score_array[0].name_vpass); roomlist.create(this);
ROOM_player_lose(score_array[1].name_vpass); }
} else { this.port = parseInt(data);
ROOM_player_win(score_array[1].name_vpass); _.each(this.players, (player) => {
ROOM_player_lose(score_array[0].name_vpass); player.server.connect(this.port, '127.0.0.1', async function() {
var buffer, len, m, ref;
ref = player.pre_establish_buffers;
for (m = 0, len = ref.length; m < len; m++) {
buffer = ref[m];
await ygopro.helper.send(player.server, buffer);
} }
} player.established = true;
player.pre_establish_buffers = [];
});
});
if (this.windbot) {
setTimeout(() => {
return this.add_windbot(this.windbot);
}, 200);
} }
if (score_array.length === 1) { // same name });
//log.info score_array[0].name return this.process.stderr.on('data', async(data) => {
ROOM_player_win(score_array[0].name_vpass); data = "Debug: " + data;
ROOM_player_lose(score_array[0].name_vpass); data = data.replace(/\n$/, "");
log.info("YGOPRO " + data);
ygopro.stoc_send_chat_to_room(this, data, ygopro.constants.COLORS.RED);
this.has_ygopro_error = true;
this.ygopro_error_length = this.ygopro_error_length ? this.ygopro_error_length + data.length : data.length;
if (this.ygopro_error_length > 10000) {
await this.send_replays();
this.process.kill();
} }
});
} catch (error1) {
e = error1;
log.warn('CREATE ROOM FAIL', e);
return this.error = "${create_room_failed}";
}
}
delete() {
var end_time, formatted_replays, index, j, len, log_rep_id, name, player_datas, recorder_buffer, ref, ref1, repbuf, replay_id, room_name, score, score_array, score_form;
if (this.deleted) {
return;
}
//log.info 'room-delete', this.name, ROOM_all.length
score_array = [];
ref = this.scores;
for (name in ref) {
score = ref[name];
score_form = {
name: name.split('$')[0],
score: score,
deck: null,
name_vpass: name
};
if (this.decks[name]) {
score_form.deck = this.decks[name];
} }
if (settings.modules.arena_mode.enabled && this.arena) { score_array.push(score_form);
//log.info 'SCORE', score_array, @start_time }
end_time = moment_now_string; if (settings.modules.random_duel.record_match_scores && this.random_type === 'M') {
if (!this.start_time) { if (score_array.length === 2) {
this.start_time = end_time; if (score_array[0].score !== score_array[1].score) {
} if (score_array[0].score > score_array[1].score) {
if (score_array.length !== 2) { ROOM_player_win(score_array[0].name_vpass);
if (!score_array[0]) { ROOM_player_lose(score_array[1].name_vpass);
score_array[0] = {
name: null,
score: -5,
deck: null
};
}
if (!score_array[1]) {
score_array[1] = {
name: null,
score: -5,
deck: null
};
}
score_array[0].score = -5;
score_array[1].score = -5;
}
formatted_replays = [];
ref1 = this.replays;
for (j = 0, len = ref1.length; j < len; j++) {
repbuf = ref1[j];
if (repbuf) {
formatted_replays.push(repbuf.toString("base64"));
}
}
request.post({
url: settings.modules.arena_mode.post_score,
form: {
accesskey: settings.modules.arena_mode.accesskey,
usernameA: score_array[0].name,
usernameB: score_array[1].name,
userscoreA: score_array[0].score,
userscoreB: score_array[1].score,
userdeckA: score_array[0].deck,
userdeckB: score_array[1].deck,
first: JSON.stringify(this.first_list),
replays: JSON.stringify(formatted_replays),
start: this.start_time,
end: end_time,
arena: this.arena
}
}, (error, response, body) => {
if (error) {
log.warn('SCORE POST ERROR', error);
} else { } else {
if (response.statusCode >= 300) { ROOM_player_win(score_array[1].name_vpass);
log.warn('SCORE POST FAIL', response.statusCode, response.statusMessage, this.name, body); ROOM_player_lose(score_array[0].name_vpass);
}
} }
});
}
//else
// log.info 'SCORE POST OK', response.statusCode, response.statusMessage, @name, body
if (settings.modules.challonge.enabled && this.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN && this.hostinfo.mode !== 2 && !this.kicked) {
room_name = this.name;
this.post_challonge_score();
}
if (this.player_datas.length && settings.modules.cloud_replay.enabled) {
replay_id = this.cloud_replay_id;
if (this.has_ygopro_error) {
log_rep_id = true;
} }
recorder_buffer = Buffer.concat(this.recorder_buffers);
player_datas = this.player_datas;
zlib.deflate(recorder_buffer, function(err, replay_buffer) {
dataManager.saveCloudReplay(replay_id, replay_buffer, player_datas).catch(function(err) {
return log.warn(`Replay save error: R#${replay_id} ${err.toString()}`);
});
if (log_rep_id) {
log.info("error replay: R#" + replay_id);
}
});
}
this.watcher_buffers = [];
this.recorder_buffers = [];
this.players = [];
if (this.watcher) {
this.watcher.destroy();
}
if (this.recorder) {
this.recorder.destroy();
} }
this.deleted = true; if (score_array.length === 1) { // same name
index = _.indexOf(ROOM_all, this); //log.info score_array[0].name
if (settings.modules.reconnect.enabled) { ROOM_player_win(score_array[0].name_vpass);
ROOM_clear_disconnect(index); ROOM_player_lose(score_array[0].name_vpass);
}
if (index !== -1) {
ROOM_all[index] = null;
}
if (!this.windbot && this.established && settings.modules.http.websocket_roomlist) {
//ROOM_all.splice(index, 1) unless index == -1
roomlist.delete(this);
} }
} }
if (settings.modules.arena_mode.enabled && this.arena) {
async initialize_recover() { //log.info 'SCORE', score_array, @start_time
var e; end_time = moment_now_string;
this.recover_duel_log = (await dataManager.getDuelLogFromId(this.recover_duel_log_id)); if (!this.start_time) {
if (!this.recover_duel_log || !fs.existsSync(settings.modules.tournament_mode.replay_path + this.recover_duel_log.replayFileName)) { this.start_time = end_time;
this.terminate();
return false;
} }
try { if (score_array.length !== 2) {
this.recover_replay = (await ReplayParser.fromFile(settings.modules.tournament_mode.replay_path + this.recover_duel_log.replayFileName)); if (!score_array[0]) {
this.spawn(this.recover_replay.header.seed); score_array[0] = {
return true; name: null,
} catch (error1) { score: -5,
e = error1; deck: null
log.warn("LOAD RECOVER REPLAY FAIL", e.toString()); };
this.terminate(); }
return false; if (!score_array[1]) {
score_array[1] = {
name: null,
score: -5,
deck: null
};
}
score_array[0].score = -5;
score_array[1].score = -5;
}
formatted_replays = [];
ref1 = this.replays;
for (j = 0, len = ref1.length; j < len; j++) {
repbuf = ref1[j];
if (repbuf) {
formatted_replays.push(repbuf.toString("base64"));
}
} }
} request.post({
url: settings.modules.arena_mode.post_score,
get_playing_player() { form: {
var playing_player; accesskey: settings.modules.arena_mode.accesskey,
playing_player = []; usernameA: score_array[0].name,
_.each(this.players, function(player) { usernameB: score_array[1].name,
if (player.pos < 4) { userscoreA: score_array[0].score,
playing_player.push(player); userscoreB: score_array[1].score,
userdeckA: score_array[0].deck,
userdeckB: score_array[1].deck,
first: JSON.stringify(this.first_list),
replays: JSON.stringify(formatted_replays),
start: this.start_time,
end: end_time,
arena: this.arena
}
}, (error, response, body) => {
if (error) {
log.warn('SCORE POST ERROR', error);
} else {
if (response.statusCode >= 300) {
log.warn('SCORE POST FAIL', response.statusCode, response.statusMessage, this.name, body);
}
} }
}); });
return playing_player;
} }
//else
get_host() { // log.info 'SCORE POST OK', response.statusCode, response.statusMessage, @name, body
var host_player; if (settings.modules.challonge.enabled && this.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN && this.hostinfo.mode !== 2 && !this.kicked) {
host_player = null; room_name = this.name;
_.each(this.players, function(player) { this.post_challonge_score();
if (player.is_host) { }
host_player = player; if (this.player_datas.length && settings.modules.cloud_replay.enabled) {
replay_id = this.cloud_replay_id;
if (this.has_ygopro_error) {
log_rep_id = true;
}
recorder_buffer = Buffer.concat(this.recorder_buffers);
player_datas = this.player_datas;
zlib.deflate(recorder_buffer, function(err, replay_buffer) {
dataManager.saveCloudReplay(replay_id, replay_buffer, player_datas).catch(function(err) {
return log.warn(`Replay save error: R#${replay_id} ${err.toString()}`);
});
if (log_rep_id) {
log.info("error replay: R#" + replay_id);
} }
}); });
return host_player;
} }
this.watcher_buffers = [];
this.recorder_buffers = [];
this.players = [];
if (this.watcher) {
this.watcher.destroy();
}
if (this.recorder) {
this.recorder.destroy();
}
this.deleted = true;
index = _.indexOf(ROOM_all, this);
if (settings.modules.reconnect.enabled) {
ROOM_clear_disconnect(index);
}
if (index !== -1) {
ROOM_all[index] = null;
}
if (!this.windbot && this.established && settings.modules.http.websocket_roomlist) {
//ROOM_all.splice(index, 1) unless index == -1
roomlist.delete(this);
}
}
async initialize_recover() {
var e;
this.recover_duel_log = (await dataManager.getDuelLogFromId(this.recover_duel_log_id));
if (!this.recover_duel_log || !fs.existsSync(settings.modules.tournament_mode.replay_path + this.recover_duel_log.replayFileName)) {
this.terminate();
return false;
}
try {
this.recover_replay = (await ReplayParser.fromFile(settings.modules.tournament_mode.replay_path + this.recover_duel_log.replayFileName));
this.spawn(this.recover_replay.header.seed);
return true;
} catch (error1) {
e = error1;
log.warn("LOAD RECOVER REPLAY FAIL", e.toString());
this.terminate();
return false;
}
}
get_disconnected_count() { get_playing_player() {
var found, j, len, player, ref; var playing_player;
if (!settings.modules.reconnect.enabled) { playing_player = [];
return 0; _.each(this.players, function(player) {
if (player.pos < 4) {
playing_player.push(player);
} }
found = 0; });
ref = this.get_playing_player(); return playing_player;
for (j = 0, len = ref.length; j < len; j++) { }
player = ref[j];
if (player.isClosed) { get_host() {
found++; var host_player;
} host_player = null;
_.each(this.players, function(player) {
if (player.is_host) {
host_player = player;
} }
return found; });
} return host_player;
}
get_challonge_score() { get_disconnected_count() {
var challonge_duel_log; var found, j, len, player, ref;
if (!settings.modules.challonge.enabled || this.duel_stage === ygopro.constants.DUEL_STAGE.BEGIN || this.hostinfo.mode === 2) { if (!settings.modules.reconnect.enabled) {
return null; return 0;
}
found = 0;
ref = this.get_playing_player();
for (j = 0, len = ref.length; j < len; j++) {
player = ref[j];
if (player.isClosed) {
found++;
} }
challonge_duel_log = {}; }
if (this.scores[this.dueling_players[0].name_vpass] > this.scores[this.dueling_players[1].name_vpass]) { return found;
challonge_duel_log.winner_id = this.dueling_players[0].challonge_info.id; }
} else if (this.scores[this.dueling_players[0].name_vpass] < this.scores[this.dueling_players[1].name_vpass]) {
challonge_duel_log.winner_id = this.dueling_players[1].challonge_info.id; get_challonge_score() {
var challonge_duel_log;
if (!settings.modules.challonge.enabled || this.duel_stage === ygopro.constants.DUEL_STAGE.BEGIN || this.hostinfo.mode === 2) {
return null;
}
challonge_duel_log = {};
if (this.scores[this.dueling_players[0].name_vpass] > this.scores[this.dueling_players[1].name_vpass]) {
challonge_duel_log.winner_id = this.dueling_players[0].challonge_info.id;
} else if (this.scores[this.dueling_players[0].name_vpass] < this.scores[this.dueling_players[1].name_vpass]) {
challonge_duel_log.winner_id = this.dueling_players[1].challonge_info.id;
} else {
challonge_duel_log.winner_id = "tie";
}
if (settings.modules.challonge.post_detailed_score) {
if (this.dueling_players[0].challonge_info.id === this.challonge_info.player1_id && this.dueling_players[1].challonge_info.id === this.challonge_info.player2_id) {
challonge_duel_log.scores_csv = this.scores[this.dueling_players[0].name_vpass] + "-" + this.scores[this.dueling_players[1].name_vpass];
} else if (this.dueling_players[1].challonge_info.id === this.challonge_info.player1_id && this.dueling_players[0].challonge_info.id === this.challonge_info.player2_id) {
challonge_duel_log.scores_csv = this.scores[this.dueling_players[1].name_vpass] + "-" + this.scores[this.dueling_players[0].name_vpass];
} else { } else {
challonge_duel_log.winner_id = "tie"; challonge_duel_log.scores_csv = "0-0";
log.warn("Score mismatch.", this.name);
} }
if (settings.modules.challonge.post_detailed_score) { } else {
if (this.dueling_players[0].challonge_info.id === this.challonge_info.player1_id && this.dueling_players[1].challonge_info.id === this.challonge_info.player2_id) { if (challonge_duel_log.winner_id === this.challonge_info.player1_id) {
challonge_duel_log.scores_csv = this.scores[this.dueling_players[0].name_vpass] + "-" + this.scores[this.dueling_players[1].name_vpass]; challonge_duel_log.scores_csv = "1-0";
} else if (this.dueling_players[1].challonge_info.id === this.challonge_info.player1_id && this.dueling_players[0].challonge_info.id === this.challonge_info.player2_id) { } else if (challonge_duel_log.winner_id === this.challonge_info.player2_id) {
challonge_duel_log.scores_csv = this.scores[this.dueling_players[1].name_vpass] + "-" + this.scores[this.dueling_players[0].name_vpass]; challonge_duel_log.scores_csv = "0-1";
} else {
challonge_duel_log.scores_csv = "0-0";
log.warn("Score mismatch.", this.name);
}
} else { } else {
if (challonge_duel_log.winner_id === this.challonge_info.player1_id) { challonge_duel_log.scores_csv = "0-0";
challonge_duel_log.scores_csv = "1-0";
} else if (challonge_duel_log.winner_id === this.challonge_info.player2_id) {
challonge_duel_log.scores_csv = "0-1";
} else {
challonge_duel_log.scores_csv = "0-0";
}
} }
return challonge_duel_log;
} }
return challonge_duel_log;
}
post_challonge_score(noWinner) { post_challonge_score(noWinner) {
var matchResult; var matchResult;
matchResult = this.get_challonge_score(); matchResult = this.get_challonge_score();
if (noWinner) { if (noWinner) {
delete matchResult.winner_id; delete matchResult.winner_id;
}
return challonge.putScore(this.challonge_info.id, matchResult);
} }
return challonge.putScore(this.challonge_info.id, matchResult);
}
get_roomlist_hostinfo() { // Just for supporting websocket roomlist in old MyCard client.... get_roomlist_hostinfo() { // Just for supporting websocket roomlist in old MyCard client....
//ret = _.clone(@hostinfo) //ret = _.clone(@hostinfo)
//ret.enable_priority = (@hostinfo.duel_rule != 5) //ret.enable_priority = (@hostinfo.duel_rule != 5)
//return ret //return ret
return this.hostinfo; return this.hostinfo;
} }
async send_replays() { async send_replays() {
var j, l, len, len1, player, ref, ref1, send_tasks; var j, l, len, len1, player, ref, ref1, send_tasks;
if (!(settings.modules.replay_delay && this.replays.length && this.hostinfo.mode === 1)) { if (!(settings.modules.replay_delay && this.replays.length && this.hostinfo.mode === 1)) {
return false; return false;
} }
send_tasks = []; send_tasks = [];
ref = this.players; ref = this.players;
for (j = 0, len = ref.length; j < len; j++) { for (j = 0, len = ref.length; j < len; j++) {
player = ref[j]; player = ref[j];
if (player) { if (player) {
send_tasks.push(CLIENT_send_replays(player, this)); send_tasks.push(CLIENT_send_replays(player, this));
}
} }
ref1 = this.watchers; }
for (l = 0, len1 = ref1.length; l < len1; l++) { ref1 = this.watchers;
player = ref1[l]; for (l = 0, len1 = ref1.length; l < len1; l++) {
if (player) { player = ref1[l];
send_tasks.push(CLIENT_send_replays(player, this)); if (player) {
} send_tasks.push(CLIENT_send_replays(player, this));
} }
await Promise.all(send_tasks);
return true;
} }
await Promise.all(send_tasks);
return true;
}
add_windbot(botdata) { add_windbot(botdata) {
this.windbot = botdata; this.windbot = botdata;
request({ request({
url: `http://${settings.modules.windbot.server_ip}:${settings.modules.windbot.port}/?name=${encodeURIComponent(botdata.name)}&deck=${encodeURIComponent(botdata.deck)}&host=${settings.modules.windbot.my_ip}&port=${settings.port}&dialog=${encodeURIComponent(botdata.dialog)}&version=${settings.version}&password=${encodeURIComponent(this.name)}` url: `http://${settings.modules.windbot.server_ip}:${settings.modules.windbot.port}/?name=${encodeURIComponent(botdata.name)}&deck=${encodeURIComponent(botdata.deck)}&host=${settings.modules.windbot.my_ip}&port=${settings.port}&dialog=${encodeURIComponent(botdata.dialog)}&version=${settings.version}&password=${encodeURIComponent(this.name)}`
}, (error, response, body) => { }, (error, response, body) => {
if (error) { if (error) {
log.warn('windbot add error', error, this.name); log.warn('windbot add error', error, this.name);
ygopro.stoc_send_chat_to_room(this, "${add_windbot_failed}", ygopro.constants.COLORS.RED); ygopro.stoc_send_chat_to_room(this, "${add_windbot_failed}", ygopro.constants.COLORS.RED);
} }
}); });
} }
//else //else
//log.info "windbot added" //log.info "windbot added"
connect(client) { connect(client) {
var host_player; var host_player;
this.players.push(client); this.players.push(client);
client.join_time = moment_now_string; client.join_time = moment_now_string;
if (this.random_type) { if (this.random_type) {
client.abuse_count = 0; client.abuse_count = 0;
host_player = this.get_host(); host_player = this.get_host();
if (host_player && (host_player !== client)) { if (host_player && (host_player !== client)) {
// 进来时已经有人在等待了,互相记录为匹配过 // 进来时已经有人在等待了,互相记录为匹配过
ROOM_players_oppentlist[host_player.ip] = client.ip; ROOM_players_oppentlist[host_player.ip] = client.ip;
ROOM_players_oppentlist[client.ip] = host_player.ip; ROOM_players_oppentlist[client.ip] = host_player.ip;
} else { } else {
// 第一个玩家刚进来,还没就位 // 第一个玩家刚进来,还没就位
ROOM_players_oppentlist[client.ip] = null; ROOM_players_oppentlist[client.ip] = null;
}
} }
if (this.established) { }
if (!this.windbot && this.duel_stage === ygopro.constants.DUEL_STAGE.BEGIN && settings.modules.http.websocket_roomlist) { if (this.established) {
roomlist.update(this); if (!this.windbot && this.duel_stage === ygopro.constants.DUEL_STAGE.BEGIN && settings.modules.http.websocket_roomlist) {
} roomlist.update(this);
client.server.connect(this.port, '127.0.0.1', async function() {
var buffer, j, len, ref;
ref = client.pre_establish_buffers;
for (j = 0, len = ref.length; j < len; j++) {
buffer = ref[j];
await ygopro.helper.send(client.server, buffer);
}
client.established = true;
client.pre_establish_buffers = [];
});
} }
client.server.connect(this.port, '127.0.0.1', async function() {
var buffer, j, len, ref;
ref = client.pre_establish_buffers;
for (j = 0, len = ref.length; j < len; j++) {
buffer = ref[j];
await ygopro.helper.send(client.server, buffer);
}
client.established = true;
client.pre_establish_buffers = [];
});
} }
}
async disconnect(client, error) { async disconnect(client, error) {
var index, j, l, left_name, len, len1, player, ref, ref1; var index, j, l, left_name, len, len1, player, ref, ref1;
if (client.had_new_reconnection) { if (client.had_new_reconnection) {
return; return;
}
if (client.is_post_watcher) {
ygopro.stoc_send_chat_to_room(this, `${client.name} \${quit_watch}` + (error ? `: ${error}` : ''));
index = _.indexOf(this.watchers, client);
if (index !== -1) {
this.watchers.splice(index, 1);
} }
if (client.is_post_watcher) { //client.room = null
ygopro.stoc_send_chat_to_room(this, `${client.name} \${quit_watch}` + (error ? `: ${error}` : '')); SERVER_kick(client.server);
index = _.indexOf(this.watchers, client); } else {
if (index !== -1) { //log.info(client.name, @duel_stage != ygopro.constants.DUEL_STAGE.BEGIN, @disconnector, @random_type, @players.length)
this.watchers.splice(index, 1); if (this.arena && this.duel_stage === ygopro.constants.DUEL_STAGE.BEGIN && this.disconnector !== 'server' && !this.arena_score_handled) {
} if (settings.modules.arena_mode.punish_quit_before_match && this.players.length === 2 && !client.arena_quit_free) {
//client.room = null ref = this.players;
SERVER_kick(client.server); for (j = 0, len = ref.length; j < len; j++) {
} else { player = ref[j];
//log.info(client.name, @duel_stage != ygopro.constants.DUEL_STAGE.BEGIN, @disconnector, @random_type, @players.length) if (player.pos !== 7) {
if (this.arena && this.duel_stage === ygopro.constants.DUEL_STAGE.BEGIN && this.disconnector !== 'server' && !this.arena_score_handled) { this.scores[player.name_vpass] = 0;
if (settings.modules.arena_mode.punish_quit_before_match && this.players.length === 2 && !client.arena_quit_free) {
ref = this.players;
for (j = 0, len = ref.length; j < len; j++) {
player = ref[j];
if (player.pos !== 7) {
this.scores[player.name_vpass] = 0;
}
}
this.scores[client.name_vpass] = -9;
} else {
ref1 = this.players;
for (l = 0, len1 = ref1.length; l < len1; l++) {
player = ref1[l];
if (player.pos !== 7) {
this.scores[player.name_vpass] = -5;
}
} }
if (this.players.length === 2 && this.arena === 'athletic' && !client.arena_quit_free) { }
this.scores[client.name_vpass] = -9; this.scores[client.name_vpass] = -9;
} else {
ref1 = this.players;
for (l = 0, len1 = ref1.length; l < len1; l++) {
player = ref1[l];
if (player.pos !== 7) {
this.scores[player.name_vpass] = -5;
} }
} }
this.arena_score_handled = true; if (this.players.length === 2 && this.arena === 'athletic' && !client.arena_quit_free) {
}
index = _.indexOf(this.players, client);
if (index !== -1) {
this.players.splice(index, 1);
}
if (this.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN && this.disconnector !== 'server' && client.pos < 4) {
this.finished = true;
if (!this.finished_by_death) {
this.scores[client.name_vpass] = -9; this.scores[client.name_vpass] = -9;
if (this.random_type && !client.flee_free && (!settings.modules.reconnect.enabled || this.get_disconnected_count() === 0) && !client.kicked_by_system && !client.kicked_by_player) {
ROOM_ban_player(client.name, client.ip, "${random_ban_reason_flee}");
if (settings.modules.random_duel.record_match_scores && this.random_type === 'M') {
ROOM_player_flee(client.name_vpass);
}
}
} }
} }
if (this.players.length && !(this.windbot && client.is_host) && !(this.arena && this.duel_stage === ygopro.constants.DUEL_STAGE.BEGIN && client.pos <= 3)) { this.arena_score_handled = true;
left_name = this.getMaskedPlayerName(client); }
ygopro.stoc_send_chat_to_room(this, `${left_name} \${left_game}` + (error ? `: ${error}` : '')); index = _.indexOf(this.players, client);
if (!this.windbot && this.duel_stage === ygopro.constants.DUEL_STAGE.BEGIN && settings.modules.http.websocket_roomlist) { if (index !== -1) {
roomlist.update(this); this.players.splice(index, 1);
}
if (this.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN && this.disconnector !== 'server' && client.pos < 4) {
this.finished = true;
if (!this.finished_by_death) {
this.scores[client.name_vpass] = -9;
if (this.random_type && !client.flee_free && (!settings.modules.reconnect.enabled || this.get_disconnected_count() === 0) && !client.kicked_by_system && !client.kicked_by_player) {
ROOM_ban_player(client.name, client.ip, "${random_ban_reason_flee}");
if (settings.modules.random_duel.record_match_scores && this.random_type === 'M') {
ROOM_player_flee(client.name_vpass);
}
} }
} else {
//client.room = null
await this.send_replays();
this.process.kill();
//client.room = null
this.delete();
} }
if (!CLIENT_reconnect_unregister(client, false, true)) { }
SERVER_kick(client.server); if (this.players.length && !(this.windbot && client.is_host) && !(this.arena && this.duel_stage === ygopro.constants.DUEL_STAGE.BEGIN && client.pos <= 3)) {
left_name = this.getMaskedPlayerName(client);
ygopro.stoc_send_chat_to_room(this, `${left_name} \${left_game}` + (error ? `: ${error}` : ''));
if (!this.windbot && this.duel_stage === ygopro.constants.DUEL_STAGE.BEGIN && settings.modules.http.websocket_roomlist) {
roomlist.update(this);
} }
} else {
//client.room = null
await this.send_replays();
this.process.kill();
//client.room = null
this.delete();
}
if (!CLIENT_reconnect_unregister(client, false, true)) {
SERVER_kick(client.server);
} }
} }
}
async start_death() { async start_death() {
var oppo_pos, win_pos; var oppo_pos, win_pos;
if (this.duel_stage === ygopro.constants.DUEL_STAGE.BEGIN || this.death) { if (this.duel_stage === ygopro.constants.DUEL_STAGE.BEGIN || this.death) {
return false; return false;
}
oppo_pos = this.hostinfo.mode === 2 ? 2 : 1;
if (this.duel_stage === ygopro.constants.DUEL_STAGE.DUELING) {
switch (settings.modules.http.quick_death_rule) {
case 3:
this.death = -2;
ygopro.stoc_send_chat_to_room(this, "${death_start_phase}", ygopro.constants.COLORS.BABYBLUE);
break;
default:
this.death = (this.turn ? this.turn + 4 : 5);
ygopro.stoc_send_chat_to_room(this, "${death_start}", ygopro.constants.COLORS.BABYBLUE); // Extra duel started in siding
} }
oppo_pos = this.hostinfo.mode === 2 ? 2 : 1; } else {
if (this.duel_stage === ygopro.constants.DUEL_STAGE.DUELING) { switch (settings.modules.http.quick_death_rule) {
switch (settings.modules.http.quick_death_rule) { case 2:
case 3: case 3:
this.death = -2; if (this.scores[this.dueling_players[0].name_vpass] === this.scores[this.dueling_players[oppo_pos].name_vpass]) {
ygopro.stoc_send_chat_to_room(this, "${death_start_phase}", ygopro.constants.COLORS.BABYBLUE); if (settings.modules.http.quick_death_rule === 3) {
break; this.death = -1;
default: ygopro.stoc_send_chat_to_room(this, "${death_start_quick}", ygopro.constants.COLORS.BABYBLUE);
this.death = (this.turn ? this.turn + 4 : 5);
ygopro.stoc_send_chat_to_room(this, "${death_start}", ygopro.constants.COLORS.BABYBLUE); // Extra duel started in siding
}
} else {
switch (settings.modules.http.quick_death_rule) {
case 2:
case 3:
if (this.scores[this.dueling_players[0].name_vpass] === this.scores[this.dueling_players[oppo_pos].name_vpass]) {
if (settings.modules.http.quick_death_rule === 3) {
this.death = -1;
ygopro.stoc_send_chat_to_room(this, "${death_start_quick}", ygopro.constants.COLORS.BABYBLUE);
} else {
this.death = 5;
ygopro.stoc_send_chat_to_room(this, "${death_start_siding}", ygopro.constants.COLORS.BABYBLUE);
}
} else { } else {
win_pos = this.scores[this.dueling_players[0].name_vpass] > this.scores[this.dueling_players[oppo_pos].name_vpass] ? 0 : oppo_pos; this.death = 5;
this.finished_by_death = true; ygopro.stoc_send_chat_to_room(this, "${death_start_siding}", ygopro.constants.COLORS.BABYBLUE);
ygopro.stoc_send_chat_to_room(this, "${death2_finish_part1}" + this.dueling_players[win_pos].name + "${death2_finish_part2}", ygopro.constants.COLORS.BABYBLUE);
if (this.hostinfo.mode === 1) {
await CLIENT_send_replays(this.dueling_players[oppo_pos - win_pos], this);
}
await ygopro.stoc_send(this.dueling_players[oppo_pos - win_pos], 'DUEL_END');
if (this.hostinfo.mode === 2) {
await ygopro.stoc_send(this.dueling_players[oppo_pos - win_pos + 1], 'DUEL_END');
}
this.scores[this.dueling_players[oppo_pos - win_pos].name_vpass] = -1;
CLIENT_kick(this.dueling_players[oppo_pos - win_pos]);
if (this.hostinfo.mode === 2) {
CLIENT_kick(this.dueling_players[oppo_pos - win_pos + 1]);
}
} }
break; } else {
case 1: win_pos = this.scores[this.dueling_players[0].name_vpass] > this.scores[this.dueling_players[oppo_pos].name_vpass] ? 0 : oppo_pos;
this.death = -1; this.finished_by_death = true;
ygopro.stoc_send_chat_to_room(this, "${death_start_quick}", ygopro.constants.COLORS.BABYBLUE); ygopro.stoc_send_chat_to_room(this, "${death2_finish_part1}" + this.dueling_players[win_pos].name + "${death2_finish_part2}", ygopro.constants.COLORS.BABYBLUE);
break; if (this.hostinfo.mode === 1) {
default: await CLIENT_send_replays(this.dueling_players[oppo_pos - win_pos], this);
this.death = 5; }
ygopro.stoc_send_chat_to_room(this, "${death_start_siding}", ygopro.constants.COLORS.BABYBLUE); await ygopro.stoc_send(this.dueling_players[oppo_pos - win_pos], 'DUEL_END');
} if (this.hostinfo.mode === 2) {
await ygopro.stoc_send(this.dueling_players[oppo_pos - win_pos + 1], 'DUEL_END');
}
this.scores[this.dueling_players[oppo_pos - win_pos].name_vpass] = -1;
CLIENT_kick(this.dueling_players[oppo_pos - win_pos]);
if (this.hostinfo.mode === 2) {
CLIENT_kick(this.dueling_players[oppo_pos - win_pos + 1]);
}
}
break;
case 1:
this.death = -1;
ygopro.stoc_send_chat_to_room(this, "${death_start_quick}", ygopro.constants.COLORS.BABYBLUE);
break;
default:
this.death = 5;
ygopro.stoc_send_chat_to_room(this, "${death_start_siding}", ygopro.constants.COLORS.BABYBLUE);
} }
return true;
} }
return true;
}
cancel_death() { cancel_death() {
if (this.duel_stage === ygopro.constants.DUEL_STAGE.BEGIN || !this.death) { if (this.duel_stage === ygopro.constants.DUEL_STAGE.BEGIN || !this.death) {
return false; return false;
}
this.death = 0;
ygopro.stoc_send_chat_to_room(this, "${death_cancel}", ygopro.constants.COLORS.BABYBLUE);
return true;
} }
this.death = 0;
ygopro.stoc_send_chat_to_room(this, "${death_cancel}", ygopro.constants.COLORS.BABYBLUE);
return true;
}
async terminate() { async terminate() {
var e; var e;
if (this.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN) { if (this.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN) {
this.scores[this.dueling_players[0].name_vpass] = 0; this.scores[this.dueling_players[0].name_vpass] = 0;
this.scores[this.dueling_players[1].name_vpass] = 0; this.scores[this.dueling_players[1].name_vpass] = 0;
} }
this.kicked = true; this.kicked = true;
await this.send_replays(); await this.send_replays();
if (this.process) { if (this.process) {
try { try {
this.process.kill(); this.process.kill();
} catch (error1) { } catch (error1) {
e = error1; e = error1;
}
} }
return this.delete();
} }
return this.delete();
}
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); ygopro.stoc_send_chat_to_room(this, "${recover_fail}", ygopro.constants.COLORS.RED);
return this.terminate(); return this.terminate();
} else { } else {
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();
results = []; results = [];
for (j = 0, len = ref.length; j < len; j++) { for (j = 0, len = ref.length; j < len; j++) {
player = ref[j]; player = ref[j];
results.push((function() { results.push((function() {
var l, len1, ref1, results1; var l, len1, ref1, results1;
ref1 = this.recover_buffers[player.pos]; ref1 = this.recover_buffers[player.pos];
results1 = []; results1 = [];
for (l = 0, len1 = ref1.length; l < len1; l++) { for (l = 0, len1 = ref1.length; l < len1; l++) {
buffer = ref1[l]; buffer = ref1[l];
results1.push(ygopro.stoc_send(player, "GAME_MSG", buffer)); results1.push(ygopro.stoc_send(player, "GAME_MSG", buffer));
} }
return results1; return results1;
}).call(this)); }).call(this));
}
return results;
} }
return results;
} }
}
async check_athletic() { async check_athletic() {
var players, room; var players, room;
players = this.get_playing_player(); players = this.get_playing_player();
room = this; room = this;
await Promise.all(players.map(async function(player) { await Promise.all(players.map(async function(player) {
var main, side, using_athletic; var main, side, using_athletic;
main = _.clone(player.main); main = _.clone(player.main);
side = _.clone(player.side); side = _.clone(player.side);
using_athletic = (await athleticChecker.checkAthletic({ using_athletic = (await athleticChecker.checkAthletic({
main: main, main: main,
side: side side: side
}));
if (!using_athletic.success) {
log.warn("GET ATHLETIC FAIL", player.name, using_athletic.message);
} else if (using_athletic.athletic) {
ygopro.stoc_send_chat_to_room(room, `${player.name}\${using_athletic_deck}`, ygopro.constants.COLORS.BABYBLUE);
}
})); }));
} if (!using_athletic.success) {
log.warn("GET ATHLETIC FAIL", player.name, using_athletic.message);
} else if (using_athletic.athletic) {
ygopro.stoc_send_chat_to_room(room, `${player.name}\${using_athletic_deck}`, ygopro.constants.COLORS.BABYBLUE);
}
}));
}
async join_post_watch(client) { async join_post_watch(client) {
var buffer, j, len, ref; var buffer, j, len, ref;
if (this.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN) { if (this.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN) {
if (settings.modules.cloud_replay.enable_halfway_watch && !this.hostinfo.no_watch) { if (settings.modules.cloud_replay.enable_halfway_watch && !this.hostinfo.no_watch) {
client.setTimeout(300000); //连接后超时5分钟 client.setTimeout(300000); //连接后超时5分钟
client.rid = _.indexOf(ROOM_all, this); client.rid = _.indexOf(ROOM_all, this);
client.is_post_watcher = true; client.is_post_watcher = true;
ygopro.stoc_send_chat_to_room(this, `${client.name} \${watch_join}`); ygopro.stoc_send_chat_to_room(this, `${client.name} \${watch_join}`);
this.watchers.push(client); this.watchers.push(client);
ygopro.stoc_send_chat(client, "${watch_watching}", ygopro.constants.COLORS.BABYBLUE); ygopro.stoc_send_chat(client, "${watch_watching}", ygopro.constants.COLORS.BABYBLUE);
ref = this.watcher_buffers; ref = this.watcher_buffers;
for (j = 0, len = ref.length; j < len; j++) { for (j = 0, len = ref.length; j < len; j++) {
buffer = ref[j]; buffer = ref[j];
await ygopro.helper.send(client, buffer); await ygopro.helper.send(client, buffer);
}
return true;
} else {
ygopro.stoc_die(client, "${watch_denied}");
return false;
} }
return true;
} else { } else {
ygopro.stoc_die(client, "${watch_denied}");
return false; return false;
} }
} else {
return false;
} }
}
join_player(client) { join_player(client) {
var j, len, player, ref; var j, len, player, ref;
if (this.error) { if (this.error) {
ygopro.stoc_die(client, this.error); ygopro.stoc_die(client, this.error);
return false; return false;
} }
if (this.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN) { if (this.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN) {
return this.join_post_watch(client); return this.join_post_watch(client);
} }
if (this.hostinfo.no_watch && this.players.length >= (this.hostinfo.mode === 2 ? 4 : 2)) { if (this.hostinfo.no_watch && this.players.length >= (this.hostinfo.mode === 2 ? 4 : 2)) {
ygopro.stoc_die(client, "${watch_denied_room}"); ygopro.stoc_die(client, "${watch_denied_room}");
return true; return true;
} }
if (this.challonge_info) { if (this.challonge_info) {
ref = this.get_playing_player(); ref = this.get_playing_player();
for (j = 0, len = ref.length; j < len; j++) { for (j = 0, len = ref.length; j < len; j++) {
player = ref[j]; player = ref[j];
if (!(player && player !== client && player.challonge_info.id === client.challonge_info.id)) { if (!(player && player !== client && player.challonge_info.id === client.challonge_info.id)) {
continue; continue;
}
ygopro.stoc_die(client, "${challonge_player_already_in}");
return false;
} }
ygopro.stoc_die(client, "${challonge_player_already_in}");
return false;
} }
client.setTimeout(300000); //连接后超时5分钟
client.rid = _.indexOf(ROOM_all, this);
this.connect(client);
return true;
} }
client.setTimeout(300000); //连接后超时5分钟
client.rid = _.indexOf(ROOM_all, this);
this.connect(client);
return true;
}
refreshLastActiveTime(longAgo) { refreshLastActiveTime(longAgo) {
if (longAgo) { if (longAgo) {
return this.last_active_time = moment_long_ago_string; return this.last_active_time = moment_long_ago_string;
} else { } else {
return this.last_active_time = moment_now_string; return this.last_active_time = moment_now_string;
}
} }
}
addRecorderBuffer(buffer) { addRecorderBuffer(buffer) {
if (settings.modules.cloud_replay.enabled) { if (settings.modules.cloud_replay.enabled) {
this.recorder_buffers.push(buffer); this.recorder_buffers.push(buffer);
}
} }
}
recordChatMessage(msg, player) { recordChatMessage(msg, player) {
var chat_buf, j, len, line, ref; var chat_buf, j, len, line, ref;
ref = ygopro.split_chat_lines(msg, player, settings.modules.i18n.default); ref = ygopro.split_chat_lines(msg, player, settings.modules.i18n.default);
for (j = 0, len = ref.length; j < len; j++) { for (j = 0, len = ref.length; j < len; j++) {
line = ref[j]; line = ref[j];
chat_buf = ygopro.helper.prepareMessage("STOC_CHAT", { chat_buf = ygopro.helper.prepareMessage("STOC_CHAT", {
player: player, player: player,
msg: line msg: line
}); });
if (settings.modules.cloud_replay.enabled && (this.arena || settings.modules.tournament_mode.enabled)) { if (settings.modules.cloud_replay.enabled && (this.arena || settings.modules.tournament_mode.enabled)) {
this.addRecorderBuffer(chat_buf); this.addRecorderBuffer(chat_buf);
}
this.watcher_buffers.push(chat_buf);
} }
this.watcher_buffers.push(chat_buf);
} }
}
}; getMaskedPlayerName(player, sight_player) {
getMaskedPlayerName(player, sight_player)(function() {
if (!settings.modules.hide_name || (sight_player && player === sight_player) || !(this.random_type || this.arena)) { if (!settings.modules.hide_name || (sight_player && player === sight_player) || !(this.random_type || this.arena)) {
return player.name; return player.name;
} }
...@@ -2475,11 +2472,9 @@ ...@@ -2475,11 +2472,9 @@
return "********"; return "********";
} }
return player.name; return player.name;
}); }
return Room;
}).call(this); };
// 网络连接 // 网络连接
netRequestHandler = function(client) { netRequestHandler = function(client) {
......
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