Commit f7408480 authored by nanahira's avatar nanahira

use latest coffeescript

parent 09cdcc3f
// Generated by CoffeeScript 1.12.7
// Generated by CoffeeScript 2.5.1
(function() {
var WebSocketServer, _delete, broadcast, create, init, room_data, server, settings, start, update, url;
......@@ -31,7 +31,7 @@
}
return results;
})(),
options: room.get_old_hostinfo(),
options: room.get_old_hostinfo(), // Should be updated when MyCard client updates
arena: settings.modules.arena_mode.enabled && room.arena && settings.modules.arena_mode.mode
};
};
......@@ -50,7 +50,7 @@
results = [];
for (i = 0, len = ROOM_all.length; i < len; i++) {
room = ROOM_all[i];
if (room && room.established && (connection.filter === 'started' || !room["private"]) && ((room.duel_stage !== 0) === (connection.filter === 'started'))) {
if (room && room.established && (connection.filter === 'started' || !room.private) && ((room.duel_stage !== 0) === (connection.filter === 'started'))) {
results.push(room_data(room));
}
}
......@@ -61,19 +61,19 @@
};
create = function(room) {
if (!room["private"]) {
if (!room.private) {
return broadcast('create', room_data(room), 'waiting');
}
};
update = function(room) {
if (!room["private"]) {
if (!room.private) {
return broadcast('update', room_data(room), 'waiting');
}
};
start = function(room) {
if (!room["private"]) {
if (!room.private) {
broadcast('delete', room.name, 'waiting');
}
return broadcast('create', room_data(room), 'started');
......@@ -83,7 +83,7 @@
if (room.duel_stage !== 0) {
return broadcast('delete', room.name, 'started');
} else {
if (!room["private"]) {
if (!room.private) {
return broadcast('delete', room.name, 'waiting');
}
}
......@@ -116,7 +116,7 @@
create: create,
update: update,
start: start,
"delete": _delete
delete: _delete
};
}).call(this);
// Generated by CoffeeScript 1.12.7
/*
Main script of new dashboard account system.
The account list file is stored at `./config/admin_user.json`. The users are stored at `users`.
The key is the username. The `permissions` field could be a string, using a permission set from the example, or an object, to define a specific set of permissions.
eg. An account for a judge could be as follows, to use the default permission of judges,
// Generated by CoffeeScript 2.5.1
(function() {
/*
Main script of new dashboard account system.
The account list file is stored at `./config/admin_user.json`. The users are stored at `users`.
The key is the username. The `permissions` field could be a string, using a permission set from the example, or an object, to define a specific set of permissions.
eg. An account for a judge could be as follows, to use the default permission of judges,
"username": {
"password": "123456",
"enabled": true,
"permissions": "judge"
},
or as follows, to use a specific set of permissions.
or as follows, to use a specific set of permissions.
"username": {
"password": "123456",
"enabled": true,
......@@ -26,8 +26,6 @@ or as follows, to use a specific set of permissions.
}
},
*/
(function() {
var add_log, bunyan, check_permission, default_data, fs, loadJSON, log, moment, reload, save, setting_save, users;
fs = require('fs');
......@@ -122,11 +120,8 @@ or as follows, to use a specific set of permissions.
return permission[permission_required];
};
this.auth = function(name, pass, permission_required, action, no_log) {
this.auth = function(name, pass, permission_required, action = 'unknown', no_log) {
var user;
if (action == null) {
action = 'unknown';
}
reload();
user = users.users[name];
if (!user) {
......
// Generated by CoffeeScript 1.12.7
// Generated by CoffeeScript 2.5.1
(function() {
// 标准库
var CLIENT_get_authorize_key, CLIENT_get_kick_reconnect_target, CLIENT_heartbeat_register, CLIENT_heartbeat_unregister, CLIENT_import_data, CLIENT_is_able_to_kick_reconnect, CLIENT_is_able_to_reconnect, CLIENT_is_banned_by_mc, CLIENT_is_player, CLIENT_kick, CLIENT_kick_reconnect, CLIENT_pre_reconnect, CLIENT_reconnect, CLIENT_reconnect_register, CLIENT_reconnect_unregister, CLIENT_send_pre_reconnect_info, CLIENT_send_reconnect_info, CLIENT_send_replays, Cloud_replay_ids, ROOM_all, ROOM_bad_ip, ROOM_ban_player, ROOM_clear_disconnect, ROOM_connected_ip, ROOM_find_by_name, ROOM_find_by_pid, ROOM_find_by_port, ROOM_find_by_title, ROOM_find_or_create_ai, ROOM_find_or_create_by_name, ROOM_find_or_create_random, ROOM_kick, ROOM_player_flee, ROOM_player_get_score, ROOM_player_lose, ROOM_player_win, ROOM_players_banned, ROOM_players_oppentlist, ROOM_players_scores, ROOM_unwelcome, ROOM_validate, Room, SERVER_clear_disconnect, SERVER_kick, SOCKET_flush_data, _, _async, addCallback, auth, badwords, ban_user, bunyan, challonge, challonge_cache, challonge_module_name, challonge_queue_callbacks, chat_color, config, cppversion, crypto, date, deck_name_match, default_config, default_data, dialogues, disconnect_list, dns, duel_log, e, exec, execFile, fs, geoip, get_callback, get_memory_usage, http, http_server, https, https_server, import_datas, imported, is_requesting, j, l, len, len1, len2, lflists, list, loadJSON, load_dialogues, load_tips, log, long_resolve_cards, m, memory_usage, merge, moment, net, oldbadwords, oldconfig, olddialogues, oldduellog, oldtips, options, os, path, pgClient, pg_client, pg_query, plugin_filename, plugin_list, plugin_path, real_windbot_server_ip, redis, redisdb, ref, ref1, refresh_challonge_cache, release_disconnect, report_to_big_brother, request, requestListener, roomlist, setting_change, setting_save, settings, spawn, spawnSync, spawn_windbot, tips, url, users_cache, wait_room_start, wait_room_start_arena, windbot_looplimit, windbot_process, windbots, ygopro, zlib;
net = require('net');
......@@ -26,6 +27,7 @@
_async = require('async');
// 三方库
_ = global._ = require('underscore');
_.str = require('underscore.string');
......@@ -66,6 +68,10 @@
loadJSON = require('load-json-file').sync;
//heapdump = require 'heapdump'
// 配置
// 导入旧配置
if (!fs.existsSync('./config')) {
fs.mkdirSync('./config');
}
......@@ -119,6 +125,7 @@
delete oldconfig.ban.badword_level3;
}
if (!_.isEmpty(oldconfig)) {
// log.info oldconfig
fs.writeFileSync('./config/config.json', JSON.stringify(oldconfig, null, 2));
log.info('imported old config from config.user.json');
}
......@@ -144,6 +151,7 @@
setting_change = global.setting_change = function(settings, path, val, callback) {
var key, target;
if (_.isString(val)) {
// path should be like "modules:welcome"
log.info("setting changed", path, val);
}
path = path.split(':');
......@@ -161,6 +169,7 @@
setting_save(settings, callback);
};
// 读取配置
default_config = loadJSON('./data/default_config.json');
try {
......@@ -177,19 +186,23 @@
auth = global.auth = require('./ygopro-auth.js');
//import old configs
imported = false;
//reset http.quick_death_rule from true to 1
if (settings.modules.http.quick_death_rule === true) {
settings.modules.http.quick_death_rule = 1;
imported = true;
}
//import the old redis port
if (settings.modules.cloud_replay.redis_port) {
settings.modules.cloud_replay.redis.port = settings.modules.cloud_replay.redis_port;
delete settings.modules.cloud_replay.redis_port;
imported = true;
}
//import the old passwords to new admin user system
if (settings.modules.http.password) {
auth.add_user("olduser", settings.modules.http.password, true, {
"get_rooms": true,
......@@ -232,6 +245,7 @@
imported = true;
}
//import the old enable_priority hostinfo
if (settings.hostinfo.enable_priority || settings.hostinfo.enable_priority === false) {
if (settings.hostinfo.enable_priority) {
settings.hostinfo.duel_rule = 3;
......@@ -242,16 +256,19 @@
imported = true;
}
//import the old Challonge api key option
if (settings.modules.challonge.api_key) {
settings.modules.challonge.options.apiKey = settings.modules.challonge.api_key;
delete settings.modules.challonge.api_key;
imported = true;
}
//finish
if (imported) {
setting_save(settings);
}
// 读取数据
default_data = loadJSON('./data/default_data.json');
try {
......@@ -294,13 +311,16 @@
setting_change(settings, "version", cppversion);
log.info("ygopro version 0x" + settings.version.toString(16), "(from source code)");
} catch (error1) {
//settings.version = settings.version_default
log.info("ygopro version 0x" + settings.version.toString(16), "(from config)");
}
// load the lflist of current date
lflists = global.lflists = [];
try {
ref = fs.readFileSync('ygopro/expansions/lflist.conf', 'utf8').match(/!.*/g);
// expansions/lflist
for (j = 0, len = ref.length; j < len; j++) {
list = ref[j];
date = list.match(/!([\d\.]+)/);
......@@ -318,6 +338,7 @@
try {
ref1 = fs.readFileSync('ygopro/lflist.conf', 'utf8').match(/!.*/g);
// lflist
for (l = 0, len1 = ref1.length; l < len1; l++) {
list = ref1[l];
date = list.match(/!([\d\.]+)/);
......@@ -359,6 +380,7 @@
long_resolve_cards = global.long_resolve_cards = loadJSON('./data/long_resolve_cards.json');
}
// 组件
ygopro = global.ygopro = require('./ygopro.js');
if (settings.modules.http.websocket_roomlist) {
......@@ -369,6 +391,7 @@
geoip = require('geoip-country-lite');
}
// cache users of mycard login
users_cache = {};
if (settings.modules.mycard.enabled) {
......@@ -382,6 +405,7 @@
log.warn("PostgreSQL Query ERROR: ", err);
});
pg_query.on('row', function(row) {
//log.info "load user", row.username, row.id
users_cache[row.username] = row.id;
});
pg_query.on('end', function(result) {
......@@ -397,8 +421,7 @@
ak: settings.modules.arena_mode.init_post.accesskey,
arena: settings.modules.arena_mode.mode
}
}, (function(_this) {
return function(error, response, body) {
}, (error, response, body) => {
if (error) {
log.warn('ARENA INIT POST ERROR', error);
} else {
......@@ -406,11 +429,12 @@
log.warn('ARENA INIT POST FAIL', response.statusCode, response.statusMessage, body);
}
}
};
})(this));
});
}
}
//else
// log.info 'ARENA INIT POST OK', response.statusCode, response.statusMessage
if (settings.modules.challonge.enabled) {
challonge_module_name = 'challonge';
if (settings.modules.challonge.use_custom_module) {
......@@ -486,11 +510,24 @@
}
};
refresh_challonge_cache();
// challonge.participants._index({
// id: settings.modules.challonge.tournament_id,
// callback: (() ->
// challonge.matches._index({
// id: settings.modules.challonge.tournament_id,
// callback: (() ->
// return
// )
// })
// return
// )
// })
if (settings.modules.challonge.cache_ttl) {
setInterval(refresh_challonge_cache, settings.modules.challonge.cache_ttl);
}
}
// 获取可用内存
memory_usage = global.memory_usage = 0;
get_memory_usage = get_memory_usage = function() {
......@@ -534,6 +571,7 @@
ROOM_bad_ip = global.ROOM_bad_ip = {};
// ban a user manually and permanently
ban_user = global.ban_user = function(name, callback) {
var bad_ip;
settings.ban.banned_user.push(name);
......@@ -550,7 +588,7 @@
bad_ip.push(player.ip);
ROOM_bad_ip[bad_ip] = 99;
settings.ban.banned_ip.push(player.ip);
ygopro.stoc_send_chat_to_room(room, player.name + " ${kicked_by_system}", ygopro.constants.COLORS.RED);
ygopro.stoc_send_chat_to_room(room, `${player.name} \${kicked_by_system}`, ygopro.constants.COLORS.RED);
CLIENT_send_replays(player, room);
CLIENT_kick(player);
}
......@@ -560,11 +598,9 @@
}, callback);
};
ROOM_ban_player = global.ROOM_ban_player = function(name, ip, reason, countadd) {
// automatically ban user to use random duel
ROOM_ban_player = global.ROOM_ban_player = function(name, ip, reason, countadd = 1) {
var bannedplayer, bantime;
if (countadd == null) {
countadd = 1;
}
if (settings.modules.test_mode.no_ban_player) {
return;
}
......@@ -593,6 +629,7 @@
}
};
//log.info("banned", name, ip, reason, bannedplayer.count)
ROOM_kick = function(name, callback) {
var found;
found = false;
......@@ -609,7 +646,7 @@
room.kicked = true;
room.send_replays();
room.process.kill();
room["delete"]();
room.delete();
done();
}, function(err) {
callback(null, found);
......@@ -660,16 +697,17 @@
name = player.name_vpass;
score = ROOM_players_scores[name];
if (!score) {
return player.name + " ${random_score_blank}";
return `${player.name} \${random_score_blank}`;
}
total = score.win + score.lose;
if (score.win < 2 && total < 3) {
return player.name + " ${random_score_not_enough}";
return `${player.name} \${random_score_not_enough}`;
}
if (score.combo >= 2) {
return "${random_score_part1}" + player.name + " ${random_score_part2} " + (Math.ceil(score.win / total * 100)) + "${random_score_part3} " + (Math.ceil(score.flee / total * 100)) + "${random_score_part4_combo}" + score.combo + "${random_score_part5_combo}";
return `\${random_score_part1}${player.name} \${random_score_part2} ${Math.ceil(score.win / total * 100)}\${random_score_part3} ${Math.ceil(score.flee / total * 100)}\${random_score_part4_combo}${score.combo}\${random_score_part5_combo}`;
} else {
return "${random_score_part1}" + player.name + " ${random_score_part2} " + (Math.ceil(score.win / total * 100)) + "${random_score_part3} " + (Math.ceil(score.flee / total * 100)) + "${random_score_part4}";
//return player.name + " 的今日战绩:胜率" + Math.ceil(score.win/total*100) + "%,逃跑率" + Math.ceil(score.flee/total*100) + "%," + score.combo + "连胜中!"
return `\${random_score_part1}${player.name} \${random_score_part2} ${Math.ceil(score.win / total * 100)}\${random_score_part3} ${Math.ceil(score.flee / total * 100)}\${random_score_part4}`;
}
};
......@@ -679,19 +717,19 @@
scores_pair = _.pairs(ROOM_players_scores);
scores_by_lose = _.sortBy(scores_pair, function(score) {
return score[1].lose;
}).reverse();
}).reverse(); // 败场由高到低
scores_by_win = _.sortBy(scores_by_lose, function(score) {
return score[1].win;
}).reverse();
}).reverse(); // 然后胜场由低到高,再逆转,就是先排胜场再排败场
scores = _.first(scores_by_win, 10);
//log.info scores
request.post({
url: settings.modules.random_duel.post_match_scores,
form: {
accesskey: settings.modules.random_duel.post_match_accesskey,
rank: JSON.stringify(scores)
}
}, (function(_this) {
return function(error, response, body) {
}, (error, response, body) => {
if (error) {
log.warn('RANDOM SCORE POST ERROR', error);
} else {
......@@ -699,8 +737,9 @@
log.warn('RANDOM SCORE POST FAIL', response.statusCode, response.statusMessage, body);
}
}
};
})(this));
});
//else
// log.info 'RANDOM SCORE POST OK', response.statusCode, response.statusMessage
}, 60000);
}
......@@ -730,18 +769,18 @@
if (bannedplayer) {
if (bannedplayer.count > 6 && moment() < bannedplayer.time) {
return {
"error": "${random_banned_part1}" + (bannedplayer.reasons.join('${random_ban_reason_separator}')) + "${random_banned_part2}" + (moment(bannedplayer.time).fromNow(true)) + "${random_banned_part3}"
"error": `\${random_banned_part1}${bannedplayer.reasons.join('${random_ban_reason_separator}')}\${random_banned_part2}${moment(bannedplayer.time).fromNow(true)}\${random_banned_part3}`
};
}
if (bannedplayer.count > 3 && moment() < bannedplayer.time && bannedplayer.need_tip && type !== 'T') {
bannedplayer.need_tip = false;
return {
"error": "${random_deprecated_part1}" + (bannedplayer.reasons.join('${random_ban_reason_separator}')) + "${random_deprecated_part2}" + (moment(bannedplayer.time).fromNow(true)) + "${random_deprecated_part3}"
"error": `\${random_deprecated_part1}${bannedplayer.reasons.join('${random_ban_reason_separator}')}\${random_deprecated_part2}${moment(bannedplayer.time).fromNow(true)}\${random_deprecated_part3}`
};
} else if (bannedplayer.need_tip) {
bannedplayer.need_tip = false;
return {
"error": "${random_warn_part1}" + (bannedplayer.reasons.join('${random_ban_reason_separator}')) + "${random_warn_part2}"
"error": `\${random_warn_part1}${bannedplayer.reasons.join('${random_ban_reason_separator}')}\${random_warn_part2}`
};
} else if (bannedplayer.count > 2) {
bannedplayer.need_tip = true;
......@@ -754,6 +793,7 @@
});
if (result) {
result.welcome = '${random_duel_enter_room_waiting}';
//log.info 'found room', player_name
} else if (memory_usage < 90) {
type = type ? type : 'S';
name = type + ',RANDOM#' + Math.floor(Math.random() * 100000);
......@@ -763,6 +803,7 @@
result.welcome = '${random_duel_enter_room_new}';
result.deprecated = playerbanned;
} else {
//log.info 'create room', player_name, name
return null;
}
if (result.random_type === 'M') {
......@@ -806,7 +847,7 @@
}
result = new Room(name);
result.windbot = windbot;
result["private"] = true;
result.private = true;
return result;
};
......@@ -867,10 +908,10 @@
for (m = 0, len2 = ref2.length; m < len2; m++) {
player = ref2[m];
if (player && player === bad_player) {
ygopro.stoc_send_chat(player, "${unwelcome_warn_part1}" + reason + "${unwelcome_warn_part2}", ygopro.constants.COLORS.RED);
ygopro.stoc_send_chat(player, `\${unwelcome_warn_part1}${reason}\${unwelcome_warn_part2}`, ygopro.constants.COLORS.RED);
} else if (player && player.pos !== 7 && player !== bad_player) {
player.flee_free = true;
ygopro.stoc_send_chat(player, "${unwelcome_tip_part1}" + reason + "${unwelcome_tip_part2}", ygopro.constants.COLORS.BABYBLUE);
ygopro.stoc_send_chat(player, `\${unwelcome_tip_part1}${reason}\${unwelcome_tip_part2}`, ygopro.constants.COLORS.BABYBLUE);
}
}
};
......@@ -949,6 +990,9 @@
if (!settings.modules.reconnect.enabled || !room || client.system_kicked || client.flee_free || disconnect_list[CLIENT_get_authorize_key(client)] || client.is_post_watcher || !CLIENT_is_player(client, room) || room.duel_stage === ygopro.constants.DUEL_STAGE.BEGIN || room.windbot || (settings.modules.reconnect.auto_surrender_after_disconnect && room.hostinfo.mode !== 1) || (room.random_type && room.get_disconnected_count() > 1)) {
return false;
}
// for player in room.players
// if player != client and CLIENT_get_authorize_key(player) == CLIENT_get_authorize_key(client)
// return false # some issues may occur in this case, so return false
dinfo = {
room_id: room_id,
old_client: client,
......@@ -957,10 +1001,12 @@
};
tmot = setTimeout(function() {
room.disconnect(client, error);
//SERVER_kick(dinfo.old_server)
}, settings.modules.reconnect.wait_time);
dinfo.timeout = tmot;
disconnect_list[CLIENT_get_authorize_key(client)] = dinfo;
ygopro.stoc_send_chat_to_room(room, (client.name + " ${disconnect_from_game}") + (error ? ": " + error : ''));
//console.log("#{client.name} ${disconnect_from_game}")
ygopro.stoc_send_chat_to_room(room, `${client.name} \${disconnect_from_game}` + (error ? `: ${error}` : ''));
if (client.time_confirm_required) {
client.time_confirm_required = false;
ygopro.ctos_send(client.server, 'TIME_CONFIRM');
......@@ -1128,7 +1174,7 @@
break;
case ygopro.constants.DUEL_STAGE.FIRSTGO:
ygopro.stoc_send(client, 'DUEL_START');
if (client === room.selecting_tp) {
if (client === room.selecting_tp) { // and !client.selected_preduel
ygopro.stoc_send(client, 'SELECT_TP');
}
client.reconnecting = false;
......@@ -1187,7 +1233,8 @@
}
CLIENT_import_data(client, dinfo.old_client, room);
CLIENT_send_reconnect_info(client, client.server, room);
ygopro.stoc_send_chat_to_room(room, client.name + " ${reconnect_to_game}");
//console.log("#{client.name} ${reconnect_to_game}")
ygopro.stoc_send_chat_to_room(room, `${client.name} \${reconnect_to_game}`);
CLIENT_reconnect_unregister(client, true);
};
......@@ -1218,12 +1265,13 @@
}
CLIENT_import_data(client, player, room);
CLIENT_send_reconnect_info(client, client.server, room);
ygopro.stoc_send_chat_to_room(room, client.name + " ${reconnect_to_game}");
//console.log("#{client.name} ${reconnect_to_game}")
ygopro.stoc_send_chat_to_room(room, `${client.name} \${reconnect_to_game}`);
CLIENT_reconnect_unregister(client, true);
};
if (settings.modules.reconnect.enabled) {
disconnect_list = {};
disconnect_list = {}; // {old_client, old_server, room_id, timeout, deckbuf}
}
CLIENT_heartbeat_unregister = global.CLIENT_heartbeat_unregister = function(client) {
......@@ -1232,6 +1280,7 @@
}
clearTimeout(client.heartbeat_timeout);
delete client.heartbeat_timeout;
//log.info(2, client.name)
return true;
};
......@@ -1259,6 +1308,7 @@
client.destroy();
}
}, settings.modules.heartbeat_detection.wait_time);
//log.info(1, client.name)
return true;
};
......@@ -1298,14 +1348,16 @@
return true;
};
Room = (function() {
function Room(name, hostinfo) {
Room = class Room {
constructor(name, hostinfo) {
var death_time, draw_count, duel_rule, lflist, param, rule, start_hand, start_lp, time_limit;
this.hostinfo = hostinfo;
this.name = name;
//@alive = true
this.players = [];
this.player_datas = [];
this.status = 'starting';
//@started = false
this.established = false;
this.watcher_buffers = [];
this.recorder_buffers = [];
......@@ -1429,7 +1481,7 @@
if (rule.match(/(^|,|,)(NOSHUFFLE|NS)(,|,|$)/)) {
this.hostinfo.no_shuffle_deck = true;
}
if (rule.match(/(^|,|,)(IGPRIORITY|PR)(,|,|$)/)) {
if (rule.match(/(^|,|,)(IGPRIORITY|PR)(,|,|$)/)) { // deprecated
this.hostinfo.duel_rule = 4;
}
if ((param = rule.match(/(^|,|,)(DUELRULE|MR)(\d+)(,|,|$)/))) {
......@@ -1450,7 +1502,7 @@
}
}
}
this.hostinfo.replay_mode = 0;
this.hostinfo.replay_mode = 0; // 0x1: Save the replays in file. 0x2: Block the replays to observers.
if (settings.modules.tournament_mode.enabled) {
this.hostinfo.replay_mode |= 0x1;
}
......@@ -1463,32 +1515,27 @@
cwd: 'ygopro'
});
this.process_pid = this.process.pid;
this.process.on('error', (function(_this) {
return function(err) {
_.each(_this.players, function(player) {
this.process.on('error', (err) => {
_.each(this.players, function(player) {
return ygopro.stoc_die(player, "${create_room_failed}");
});
_this["delete"]();
};
})(this));
this.process.on('exit', (function(_this) {
return function(code) {
if (!_this.disconnector) {
_this.disconnector = 'server';
this.delete();
});
this.process.on('exit', (code) => {
if (!this.disconnector) {
this.disconnector = 'server';
}
_this["delete"]();
};
})(this));
this.delete();
});
this.process.stdout.setEncoding('utf8');
this.process.stdout.once('data', (function(_this) {
return function(data) {
_this.established = true;
if (!_this.windbot && settings.modules.http.websocket_roomlist) {
roomlist.create(_this);
}
_this.port = parseInt(data);
_.each(_this.players, function(player) {
player.server.connect(_this.port, '127.0.0.1', function() {
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', function() {
var buffer, len2, m, ref2;
ref2 = player.pre_establish_buffers;
for (m = 0, len2 = ref2.length; m < len2; m++) {
......@@ -1499,37 +1546,35 @@
player.pre_establish_buffers = [];
});
});
if (_this.windbot) {
setTimeout(function() {
return _this.add_windbot(_this.windbot);
if (this.windbot) {
setTimeout(() => {
return this.add_windbot(this.windbot);
}, 200);
}
};
})(this));
this.process.stderr.on('data', (function(_this) {
return function(data) {
});
this.process.stderr.on('data', (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) {
_this.send_replays();
_this.process.kill();
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) {
this.send_replays();
this.process.kill();
}
};
})(this));
});
} catch (error1) {
this.error = "${create_room_failed}";
}
}
Room.prototype["delete"] = function() {
delete() {
var end_time, formatted_replays, index, len2, log_rep_id, m, name, player_ips, player_names, recorder_buffer, ref2, ref3, 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 = [];
ref2 = this.scores;
for (name in ref2) {
......@@ -1557,12 +1602,14 @@
}
}
}
if (score_array.length === 1) {
if (score_array.length === 1) { // same name
//log.info score_array[0].name
ROOM_player_win(score_array[0].name_vpass);
ROOM_player_lose(score_array[0].name_vpass);
}
}
if (settings.modules.arena_mode.enabled && this.arena) {
//log.info 'SCORE', score_array, @start_time
end_time = moment().format();
if (!this.start_time) {
this.start_time = end_time;
......@@ -1609,18 +1656,18 @@
end: end_time,
arena: this.arena
}
}, (function(_this) {
return function(error, response, body) {
}, (error, response, body) => {
if (error) {
log.warn('SCORE POST ERROR', error);
} else {
if (response.statusCode !== 204 && response.statusCode !== 200) {
log.warn('SCORE POST FAIL', response.statusCode, response.statusMessage, _this.name, body);
log.warn('SCORE POST FAIL', response.statusCode, response.statusMessage, this.name, body);
}
}
};
})(this));
});
}
//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;
challonge.matches._update({
......@@ -1650,7 +1697,9 @@
zlib.deflate(recorder_buffer, function(err, replay_buffer) {
var date_time, recorded_ip;
replay_buffer = replay_buffer.toString('binary');
//log.info err, replay_buffer
date_time = moment().format('YYYY-MM-DD HH:mm:ss');
//replay_id=Math.floor(Math.random()*100000000)
redisdb.hmset("replay:" + replay_id, "replay_id", replay_id, "replay_buffer", replay_buffer, "player_names", player_names, "date_time", date_time);
if (!log_rep_id && !settings.modules.cloud_replay.never_expire) {
redisdb.expire("replay:" + replay_id, 60 * 60 * 24);
......@@ -1686,11 +1735,12 @@
ROOM_all[index] = null;
}
if (!this.windbot && this.established && settings.modules.http.websocket_roomlist) {
roomlist["delete"](this);
//ROOM_all.splice(index, 1) unless index == -1
roomlist.delete(this);
}
}
};
Room.prototype.get_playing_player = function() {
get_playing_player() {
var playing_player;
playing_player = [];
_.each(this.players, function(player) {
......@@ -1699,9 +1749,9 @@
}
});
return playing_player;
};
}
Room.prototype.get_host = function() {
get_host() {
var host_player;
host_player = null;
_.each(this.players, function(player) {
......@@ -1710,9 +1760,9 @@
}
});
return host_player;
};
}
Room.prototype.get_disconnected_count = function() {
get_disconnected_count() {
var found, len2, m, player, ref2;
if (!settings.modules.reconnect.enabled) {
return 0;
......@@ -1726,9 +1776,9 @@
}
}
return found;
};
}
Room.prototype.get_challonge_score = function() {
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;
......@@ -1760,16 +1810,16 @@
}
}
return challonge_duel_log;
};
}
Room.prototype.get_old_hostinfo = function() {
get_old_hostinfo() { // Just for supporting websocket roomlist in old MyCard client....
var ret;
ret = _.clone(this.hostinfo);
ret.enable_priority = this.hostinfo.duel_rule !== 5;
return ret;
};
}
Room.prototype.send_replays = function() {
send_replays() {
var len2, len3, m, n, player, ref2, ref3;
if (!(settings.modules.replay_delay && this.replays.length && this.hostinfo.mode === 1)) {
return false;
......@@ -1785,23 +1835,23 @@
CLIENT_send_replays(player, this);
}
return true;
};
}
Room.prototype.add_windbot = function(botdata) {
add_windbot(botdata) {
this.windbot = botdata;
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))
}, (function(_this) {
return function(error, response, body) {
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) => {
if (error) {
log.warn('windbot add error', error, _this.name);
ygopro.stoc_send_chat_to_room(_this, "${add_windbot_failed}", ygopro.constants.COLORS.RED);
log.warn('windbot add error', error, this.name);
ygopro.stoc_send_chat_to_room(this, "${add_windbot_failed}", ygopro.constants.COLORS.RED);
}
});
}
};
})(this));
};
Room.prototype.connect = function(client) {
//else
//log.info "windbot added"
connect(client) {
var host_player;
this.players.push(client);
client.join_time = moment();
......@@ -1809,9 +1859,11 @@
client.abuse_count = 0;
host_player = this.get_host();
if (host_player && (host_player !== client)) {
// 进来时已经有人在等待了,互相记录为匹配过
ROOM_players_oppentlist[host_player.ip] = client.ip;
ROOM_players_oppentlist[client.ip] = host_player.ip;
} else {
// 第一个玩家刚进来,还没就位
ROOM_players_oppentlist[client.ip] = null;
}
}
......@@ -1830,21 +1882,23 @@
client.pre_establish_buffers = [];
});
}
};
}
Room.prototype.disconnect = function(client, error) {
disconnect(client, error) {
var index, left_name, len2, len3, m, n, player, ref2, ref3;
if (client.had_new_reconnection) {
return;
}
if (client.is_post_watcher) {
ygopro.stoc_send_chat_to_room(this, (client.name + " ${quit_watch}") + (error ? ": " + error : ''));
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);
}
//client.room = null
SERVER_kick(client.server);
} else {
//log.info(client.name, @duel_stage != ygopro.constants.DUEL_STAGE.BEGIN, @disconnector, @random_type, @players.length)
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) {
ref2 = this.players;
......@@ -1887,22 +1941,24 @@
}
if (this.players.length && !(this.windbot && client.is_host) && !(this.arena && this.duel_stage === ygopro.constants.DUEL_STAGE.BEGIN && client.pos <= 3)) {
left_name = (settings.modules.hide_name && this.duel_stage === ygopro.constants.DUEL_STAGE.BEGIN ? "********" : client.name);
ygopro.stoc_send_chat_to_room(this, (left_name + " ${left_game}") + (error ? ": " + error : ''));
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
this.send_replays();
this.process.kill();
this["delete"]();
//client.room = null
this.delete();
}
if (!CLIENT_reconnect_unregister(client, false, true)) {
SERVER_kick(client.server);
}
}
};
}
Room.prototype.start_death = function() {
start_death() {
var oppo_pos, win_pos;
if (this.duel_stage === ygopro.constants.DUEL_STAGE.BEGIN || this.death) {
return false;
......@@ -1916,7 +1972,7 @@
break;
default:
this.death = (this.turn ? this.turn + 4 : 5);
ygopro.stoc_send_chat_to_room(this, "${death_start}", ygopro.constants.COLORS.BABYBLUE);
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) {
......@@ -1958,21 +2014,20 @@
}
}
return true;
};
}
Room.prototype.cancel_death = function() {
cancel_death() {
if (this.duel_stage === ygopro.constants.DUEL_STAGE.BEGIN || !this.death) {
return false;
}
this.death = 0;
ygopro.stoc_send_chat_to_room(this, "${death_cancel}", ygopro.constants.COLORS.BABYBLUE);
return true;
};
return Room;
}
})();
};
// 网络连接
net.createServer(function(client) {
var connect_count, server;
client.ip = client.remoteAddress;
......@@ -1982,18 +2037,25 @@
connect_count++;
}
ROOM_connected_ip[client.ip] = connect_count;
//log.info "connect", client.ip, ROOM_connected_ip[client.ip]
// server stand for the connection to ygopro server process
server = new net.Socket();
client.server = server;
server.client = client;
client.setTimeout(2000);
client.setTimeout(2000); //连接前超时2秒
// 释放处理
client.on('close', function(had_error) {
var room;
//log.info "client closed", client.name, had_error
room = ROOM_all[client.rid];
connect_count = ROOM_connected_ip[client.ip];
if (connect_count > 0) {
connect_count--;
}
ROOM_connected_ip[client.ip] = connect_count;
//log.info "disconnect", client.ip, ROOM_connected_ip[client.ip]
if (!client.closed) {
client.closed = true;
if (settings.modules.heartbeat_detection.enabled) {
......@@ -2010,12 +2072,14 @@
});
client.on('error', function(error) {
var room;
//log.info "client error", client.name, error
room = ROOM_all[client.rid];
connect_count = ROOM_connected_ip[client.ip];
if (connect_count > 0) {
connect_count--;
}
ROOM_connected_ip[client.ip] = connect_count;
//log.info "err disconnect", client.ip, ROOM_connected_ip[client.ip]
if (!client.closed) {
client.closed = true;
if (room) {
......@@ -2040,12 +2104,16 @@
if (!server.client) {
return;
}
//log.info "server closed", server.client.name, had_error
room = ROOM_all[server.client.rid];
if (room && !server.system_kicked && !server.had_new_reconnection) {
//log.info "server close", server.client.ip, ROOM_connected_ip[server.client.ip]
room.disconnector = 'server';
}
if (!server.client.closed) {
ygopro.stoc_send_chat(server.client, "${server_closed}", ygopro.constants.COLORS.RED);
//if room and settings.modules.replay_delay
// room.send_replays()
CLIENT_kick(server.client);
SERVER_clear_disconnect(server);
}
......@@ -2056,12 +2124,16 @@
if (!server.client) {
return;
}
//log.info "server error", client.name, error
room = ROOM_all[server.client.rid];
if (room && !server.system_kicked && !server.had_new_reconnection) {
//log.info "server err close", client.ip, ROOM_connected_ip[client.ip]
room.disconnector = 'server';
}
if (!server.client.closed) {
ygopro.stoc_send_chat(server.client, "${server_error}: " + error, ygopro.constants.COLORS.RED);
ygopro.stoc_send_chat(server.client, `\${server_error}: ${error}`, ygopro.constants.COLORS.RED);
//if room and settings.modules.replay_delay
// room.send_replays()
CLIENT_kick(server.client);
SERVER_clear_disconnect(server);
}
......@@ -2087,13 +2159,15 @@
CLIENT_kick(client);
return;
}
ygopro.stoc_send_chat(client, "${cloud_replay_playing} R#" + replay.replay_id + " " + replay.player_names + " " + replay.date_time, ygopro.constants.COLORS.BABYBLUE);
ygopro.stoc_send_chat(client, `\${cloud_replay_playing} R#${replay.replay_id} ${replay.player_names} ${replay.date_time}`, ygopro.constants.COLORS.BABYBLUE);
client.write(replay_buffer, function() {
CLIENT_kick(client);
});
});
};
}
// 需要重构
// 客户端到服务端(ctos)协议分析
client.pre_establish_buffers = new Array();
client.on('data', function(ctos_buffer) {
var b, bad_ip_count, buffer, cancel, ctos_event, ctos_message_length, ctos_proto, datas, info, len2, len3, len4, len5, looplimit, m, n, o, p, ref2, ref3, result, room, struct;
......@@ -2103,8 +2177,10 @@
room.watcher.write(ctos_buffer);
}
} else {
//ctos_buffer = Buffer.alloc(0)
ctos_message_length = 0;
ctos_proto = 0;
//ctos_buffer = Buffer.concat([ctos_buffer, data], ctos_buffer.length + data.length) #buffer的错误使用方式,好孩子不要学
datas = [];
looplimit = 0;
while (true) {
......@@ -2126,6 +2202,7 @@
}
} else {
if (ctos_buffer.length >= 2 + ctos_message_length) {
//console.log "CTOS", ygopro.constants.CTOS[ctos_proto]
cancel = false;
if (settings.modules.reconnect.enabled && client.pre_reconnecting && ygopro.constants.CTOS[ctos_proto] !== 'UPDATE_DECK') {
cancel = true;
......@@ -2185,6 +2262,7 @@
}
}
looplimit++;
//log.info(looplimit)
if (looplimit > 800 || ROOM_bad_ip[client.ip] > 5) {
log.info("error ctos", client.name, client.ip);
bad_ip_count = ROOM_bad_ip[client.ip];
......@@ -2213,10 +2291,16 @@
}
}
});
// 服务端到客户端(stoc)
server.on('data', function(stoc_buffer) {
var b, buffer, cancel, datas, info, len2, len3, len4, looplimit, m, n, o, ref2, ref3, result, stoc_event, stoc_message_length, stoc_proto, struct;
//stoc_buffer = Buffer.alloc(0)
stoc_message_length = 0;
stoc_proto = 0;
//stoc_buffer = Buffer.concat([stoc_buffer, data], stoc_buffer.length + data.length) #buffer的错误使用方式,好孩子不要学
//unless ygopro.stoc_follows[stoc_proto] and ygopro.stoc_follows[stoc_proto].synchronous
//server.client.write data
datas = [];
looplimit = 0;
while (true) {
......@@ -2238,6 +2322,7 @@
}
} else {
if (stoc_buffer.length >= 2 + stoc_message_length) {
//console.log "STOC", ygopro.constants.STOC[stoc_proto]
cancel = false;
b = stoc_buffer.slice(3, stoc_message_length - 1 + 3);
info = null;
......@@ -2292,6 +2377,7 @@
}
}
looplimit++;
//log.info(looplimit)
if (looplimit > 800) {
log.info("error stoc", server.client.name);
server.destroy();
......@@ -2322,8 +2408,12 @@
return parsed_deck_name && (player_name === parsed_deck_name[1] || player_name === parsed_deck_name[2]);
};
// 功能模块
// return true to cancel a synchronous message
ygopro.ctos_follow('PLAYER_INFO', true, function(buffer, info, client, server, datas) {
var geo, lang, name, name_full, struct, vpass;
// checkmate use username$password, but here don't
// so remove the password
name_full = info.name.split("$");
name = name_full[0];
vpass = name_full[1];
......@@ -2343,6 +2433,7 @@
client.rag = true;
}
if (settings.modules.mycard.enabled) {
//console.log(name)
request({
url: settings.modules.mycard.ban_get,
json: true,
......@@ -2350,6 +2441,7 @@
user: name
}
}, function(error, response, body) {
//console.log(body)
if (_.isString(body)) {
log.warn("ban get bad json", body);
} else if (error || !body) {
......@@ -2367,7 +2459,7 @@
client.vpass = vpass;
client.name_vpass = vpass ? name + "$" + vpass : name;
if (!settings.modules.i18n.auto_pick || client.is_local) {
client.lang = settings.modules.i18n["default"];
client.lang = settings.modules.i18n.default;
} else {
geo = geoip.lookup(client.ip);
if (!geo) {
......@@ -2377,6 +2469,7 @@
if (lang = settings.modules.i18n.map[geo.country]) {
client.lang = lang;
} else {
//log.info("Not in map", geo.country, client.name, client.ip)
client.lang = settings.modules.i18n.fallback;
}
}
......@@ -2386,6 +2479,7 @@
ygopro.ctos_follow('JOIN_GAME', false, function(buffer, info, client, server, datas) {
var check_buffer_indentity, create_room_with_action, len2, len3, m, n, name, pre_room, ref2, ref3, replay_id, room;
//log.info info
info.pass = info.pass.trim();
client.pass = info.pass;
if (CLIENT_is_able_to_reconnect(client) || CLIENT_is_able_to_kick_reconnect(client)) {
......@@ -2406,10 +2500,11 @@
}
return;
}
ygopro.stoc_send_chat(client, "<" + (id - 0 + 1) + "> R#" + replay_id + " " + replay.player_names + " " + replay.date_time, ygopro.constants.COLORS.BABYBLUE);
ygopro.stoc_send_chat(client, `<${id - 0 + 1}> R#${replay_id} ${replay.player_names} ${replay.date_time}`, ygopro.constants.COLORS.BABYBLUE);
});
});
});
// 强行等待异步执行完毕_(:з」∠)_
setTimeout((function() {
ygopro.stoc_send(client, 'ERROR_MSG', {
msg: 1,
......@@ -2438,7 +2533,7 @@
} else if (info.pass.toUpperCase() === "W" && settings.modules.cloud_replay.enabled) {
replay_id = Cloud_replay_ids[Math.floor(Math.random() * Cloud_replay_ids.length)];
redisdb.hgetall("replay:" + replay_id, client.open_cloud_replay);
} else if (info.version !== settings.version) {
} else if (info.version !== settings.version) { // and (info.version < 9020 or settings.version != 4927) #强行兼容23333版
ygopro.stoc_send_chat(client, settings.modules.update, ygopro.constants.COLORS.RED);
ygopro.stoc_send(client, 'ERROR_MSG', {
msg: 4,
......@@ -2453,6 +2548,12 @@
ygopro.stoc_die(client, '${invalid_password_length}');
return;
}
//if info.version >= 9020 and settings.version == 4927 #强行兼容23333版
// info.version = settings.version
// struct = ygopro.structs["CTOS_JoinGame"]
// struct._setBuff(buffer)
// struct.set("version", info.version)
// buffer = struct.buffer
buffer = Buffer.from(info.pass.slice(0, 8), 'base64');
if (buffer.length !== 6) {
ygopro.stoc_die(client, '${invalid_password_payload}');
......@@ -2461,7 +2562,7 @@
check_buffer_indentity = function(buf) {
var checksum, i, m, ref2;
checksum = 0;
for (i = m = 0, ref2 = buf.length; 0 <= ref2 ? m < ref2 : m > ref2; i = 0 <= ref2 ? ++m : --m) {
for (i = m = 0, ref2 = buf.length; (0 <= ref2 ? m < ref2 : m > ref2); i = 0 <= ref2 ? ++m : --m) {
checksum += buf.readUInt8(i);
}
return (checksum & 0xFF) === 0;
......@@ -2476,6 +2577,11 @@
ygopro.stoc_die(client, '${invalid_password_unauthorized}');
return;
}
// 1 create public room
// 2 create private room
// 3 join room by id
// 4 create or join room by id (use for match)
// 5 join room by title
switch (action) {
case 1:
case 2:
......@@ -2533,7 +2639,7 @@
room = new Room(name, options);
if (room) {
room.title = room_title;
room["private"] = action === 2;
room.private = action === 2;
}
break;
case 3:
......@@ -2560,7 +2666,7 @@
ygopro.stoc_die(client, '${invalid_password_unauthorized}');
return;
}
room["private"] = true;
room.private = true;
room.arena = settings.modules.arena_mode.mode;
if (room.arena === "athletic") {
room.max_player = 2;
......@@ -2586,10 +2692,10 @@
ygopro.stoc_die(client, room.error);
} else if (room.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN) {
if (settings.modules.cloud_replay.enable_halfway_watch && !room.hostinfo.no_watch) {
client.setTimeout(300000);
client.setTimeout(300000); //连接后超时5分钟
client.rid = _.indexOf(ROOM_all, room);
client.is_post_watcher = true;
ygopro.stoc_send_chat_to_room(room, client.name + " ${watch_join}");
ygopro.stoc_send_chat_to_room(room, `${client.name} \${watch_join}`);
room.watchers.push(client);
ygopro.stoc_send_chat(client, "${watch_watching}", ygopro.constants.COLORS.BABYBLUE);
ref3 = room.watcher_buffers;
......@@ -2603,7 +2709,8 @@
} else if (room.hostinfo.no_watch && room.players.length >= (room.hostinfo.mode === 2 ? 4 : 2)) {
ygopro.stoc_die(client, "${watch_denied_room}");
} else {
client.setTimeout(300000);
//client.room = room
client.setTimeout(300000); //连接后超时5分钟
client.rid = _.indexOf(ROOM_all, room);
room.connect(client);
}
......@@ -2661,6 +2768,7 @@
return;
}
}
//TODO: query database directly, like preload.
request({
baseUrl: settings.modules.mycard.auth_base_url,
url: '/users/' + encodeURIComponent(client.name) + '.json',
......@@ -2713,10 +2821,10 @@
pre_room = ROOM_find_by_name(info.pass);
if (pre_room && pre_room.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN && settings.modules.cloud_replay.enable_halfway_watch && !pre_room.hostinfo.no_watch) {
room = pre_room;
client.setTimeout(300000);
client.setTimeout(300000); //连接后超时5分钟
client.rid = _.indexOf(ROOM_all, room);
client.is_post_watcher = true;
ygopro.stoc_send_chat_to_room(room, client.name + " ${watch_join}");
ygopro.stoc_send_chat_to_room(room, `${client.name} \${watch_join}`);
room.watchers.push(client);
ygopro.stoc_send_chat(client, "${watch_watching}", ygopro.constants.COLORS.BABYBLUE);
ref2 = room.watcher_buffers;
......@@ -2726,7 +2834,7 @@
}
} else {
ygopro.stoc_send_chat(client, '${loading_user_info}', ygopro.constants.COLORS.BABYBLUE);
client.setTimeout(300000);
client.setTimeout(300000); //连接后超时5分钟
_async.auto({
participant_data: function(done) {
challonge.participants._index({
......@@ -2777,9 +2885,13 @@
ygopro.stoc_die(client, '${challonge_match_not_found}');
return;
}
//if found.winnerId
// ygopro.stoc_die(client, '${challonge_match_already_finished}')
// return
room = ROOM_find_or_create_by_name('M#' + found.id);
if (room) {
room.challonge_info = found;
// room.max_player = 2
room.welcome = "${challonge_match_created}";
}
if (!room) {
......@@ -2788,9 +2900,10 @@
ygopro.stoc_die(client, room.error);
} else if (room.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN) {
if (settings.modules.cloud_replay.enable_halfway_watch && !room.hostinfo.no_watch) {
//client.setTimeout(300000) #连接后超时5分钟
client.rid = _.indexOf(ROOM_all, room);
client.is_post_watcher = true;
ygopro.stoc_send_chat_to_room(room, client.name + " ${watch_join}");
ygopro.stoc_send_chat_to_room(room, `${client.name} \${watch_join}`);
room.watchers.push(client);
ygopro.stoc_send_chat(client, "${watch_watching}", ygopro.constants.COLORS.BABYBLUE);
ref5 = room.watcher_buffers;
......@@ -2813,6 +2926,8 @@
ygopro.stoc_die(client, "${challonge_player_already_in}");
return;
}
//client.room = room
//client.setTimeout(300000) #连接后超时5分钟
client.rid = _.indexOf(ROOM_all, room);
room.connect(client);
}
......@@ -2823,12 +2938,12 @@
} else if (ROOM_connected_ip[client.ip] > 5) {
log.warn("MULTI LOGIN", client.name, client.ip);
ygopro.stoc_die(client, "${too_much_connection}" + client.ip);
} else if (_.indexOf(settings.ban.banned_user, client.name) > -1) {
} else if (_.indexOf(settings.ban.banned_user, client.name) > -1) { //账号被封
settings.ban.banned_ip.push(client.ip);
setting_save(settings);
log.warn("BANNED USER LOGIN", client.name, client.ip);
ygopro.stoc_die(client, "${banned_user_login}");
} else if (_.indexOf(settings.ban.banned_ip, client.ip) > -1) {
} else if (_.indexOf(settings.ban.banned_ip, client.ip) > -1) { //IP被封
log.warn("BANNED IP LOGIN", client.name, client.ip);
ygopro.stoc_die(client, "${banned_ip_login}");
} else if (!settings.modules.tournament_mode.enabled && !settings.modules.challonge.enabled && _.any(badwords.level3, function(badword) {
......@@ -2855,6 +2970,15 @@
} else if (info.pass.length && !ROOM_validate(info.pass)) {
ygopro.stoc_die(client, "${invalid_password_room}");
} else {
//if info.version >= 9020 and settings.version == 4927 #强行兼容23333版
// info.version = settings.version
// struct = ygopro.structs["CTOS_JoinGame"]
// struct._setBuff(buffer)
// struct.set("version", info.version)
// buffer = struct.buffer
// #ygopro.stoc_send_chat(client, "看起来你是YGOMobile的用户,请记得更新先行卡补丁,否则会看到白卡", ygopro.constants.COLORS.GREEN)
//log.info 'join_game',info.pass, client.name
room = ROOM_find_or_create_by_name(info.pass, client.ip);
if (!room) {
ygopro.stoc_die(client, "${server_full}");
......@@ -2862,10 +2986,10 @@
ygopro.stoc_die(client, room.error);
} else if (room.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN) {
if (settings.modules.cloud_replay.enable_halfway_watch && !room.hostinfo.no_watch) {
client.setTimeout(300000);
client.setTimeout(300000); //连接后超时5分钟
client.rid = _.indexOf(ROOM_all, room);
client.is_post_watcher = true;
ygopro.stoc_send_chat_to_room(room, client.name + " ${watch_join}");
ygopro.stoc_send_chat_to_room(room, `${client.name} \${watch_join}`);
room.watchers.push(client);
ygopro.stoc_send_chat(client, "${watch_watching}", ygopro.constants.COLORS.BABYBLUE);
ref3 = room.watcher_buffers;
......@@ -2879,7 +3003,7 @@
} else if (room.hostinfo.no_watch && room.players.length >= (room.hostinfo.mode === 2 ? 4 : 2)) {
ygopro.stoc_die(client, "${watch_denied_room}");
} else {
client.setTimeout(300000);
client.setTimeout(300000); //连接后超时5分钟
client.rid = _.indexOf(ROOM_all, room);
room.connect(client);
}
......@@ -2888,6 +3012,7 @@
ygopro.stoc_follow('JOIN_GAME', false, function(buffer, info, client, server, datas) {
var len2, m, player, recorder, ref2, room, watcher;
//欢迎信息
room = ROOM_all[client.rid];
if (!(room && !client.reconnecting)) {
return;
......@@ -2901,7 +3026,7 @@
if (room.welcome) {
ygopro.stoc_send_chat(client, room.welcome, ygopro.constants.COLORS.BABYBLUE);
}
if (settings.modules.arena_mode.enabled && !client.is_local) {
if (settings.modules.arena_mode.enabled && !client.is_local) { //and not client.score_shown
request({
url: settings.modules.arena_mode.get_score + encodeURIComponent(client.name),
json: true
......@@ -2912,11 +3037,13 @@
} else if (!body || _.isString(body)) {
log.warn('LOAD SCORE FAIL', client.name, response.statusCode, response.statusMessage, body);
} else {
//log.info 'LOAD SCORE', client.name, body
rank_txt = body.arena_rank > 0 ? "${rank_arena}" + body.arena_rank : "${rank_blank}";
ygopro.stoc_send_chat(client, client.name + "${exp_value_part1}" + body.exp + "${exp_value_part2}${exp_value_part3}" + (Math.round(body.pt)) + rank_txt + "${exp_value_part4}", ygopro.constants.COLORS.BABYBLUE);
ygopro.stoc_send_chat(client, `${client.name}\${exp_value_part1}${body.exp}\${exp_value_part2}\${exp_value_part3}${Math.round(body.pt)}${rank_txt}\${exp_value_part4}`, ygopro.constants.COLORS.BABYBLUE);
}
});
}
//client.score_shown = true
if (settings.modules.random_duel.record_match_scores && room.random_type === 'M') {
ygopro.stoc_send_chat_to_room(room, ROOM_player_get_score(client), ygopro.constants.COLORS.GREEN);
ref2 = room.players;
......@@ -2968,7 +3095,7 @@
ref3 = room.watchers;
for (n = 0, len3 = ref3.length; n < len3; n++) {
w = ref3[n];
if (w) {
if (w) { //a WTF fix
w.write(data);
}
}
......@@ -2977,6 +3104,8 @@
}
});
// 登场台词
//log.error "watcher error", error
load_dialogues = global.load_dialogues = function(callback) {
request({
url: settings.modules.dialogues.get,
......@@ -3037,14 +3166,19 @@
client.last_game_msg = buffer;
client.last_game_msg_title = ygopro.constants.MSG[msg];
}
// log.info(client.name, client.last_game_msg_title)
} else if (ygopro.constants.MSG[msg] !== 'RETRY') {
client.last_game_msg = buffer;
client.last_game_msg_title = ygopro.constants.MSG[msg];
}
if ((msg >= 10 && msg < 30) || msg === 132 || (msg >= 140 && msg <= 144)) {
// log.info(client.name, client.last_game_msg_title)
if ((msg >= 10 && msg < 30) || msg === 132 || (msg >= 140 && msg <= 144)) { //SELECT和ANNOUNCE开头的消息
room.waiting_for_player = client;
room.last_active_time = moment();
}
//log.info("#{ygopro.constants.MSG[msg]}等待#{room.waiting_for_player.name}")
//log.info 'MSG', ygopro.constants.MSG[msg]
if (ygopro.constants.MSG[msg] === 'START') {
playertype = buffer.readUInt8(1);
client.is_first = !(playertype & 0xf);
......@@ -3072,6 +3206,7 @@
client.last_game_msg = null;
}
}
//ygopro.stoc_send_chat_to_room(room, "LP跟踪调试信息: #{client.name} 初始LP #{client.lp}")
if (ygopro.constants.MSG[msg] === 'HINT') {
hint_type = buffer.readUInt8(1);
if (hint_type === 3) {
......@@ -3143,6 +3278,8 @@
pos = pos * 2;
}
reason = buffer.readUInt8(2);
//log.info {winner: pos, reason: reason}
//room.duels.push {winner: pos, reason: reason}
room.winner = pos;
room.turn = 0;
room.duel_stage = ygopro.constants.DUEL_STAGE.END;
......@@ -3157,6 +3294,7 @@
}
if (room && !room.finished && room.dueling_players[pos]) {
room.winner_name = room.dueling_players[pos].name_vpass;
//log.info room.dueling_players, pos
room.scores[room.winner_name] = room.scores[room.winner_name] + 1;
if (room.match_kill) {
room.match_kill = false;
......@@ -3174,6 +3312,7 @@
if (ygopro.constants.MSG[msg] === 'MATCH_KILL' && client.pos === 0) {
room.match_kill = true;
}
//lp跟踪
if (ygopro.constants.MSG[msg] === 'DAMAGE' && client.pos === 0) {
pos = buffer.readUInt8(1);
if (!client.is_first) {
......@@ -3230,6 +3369,8 @@
ygopro.stoc_send_chat_to_room(room, "${lp_low_self}", ygopro.constants.COLORS.PINK);
}
}
//track card count
//todo: track card count in tag mode
if (ygopro.constants.MSG[msg] === 'MOVE' && room.hostinfo.mode !== 2) {
pos = buffer.readUInt8(5);
if (!client.is_first) {
......@@ -3258,12 +3399,13 @@
client.card_count += count;
}
}
// check panel confirming cards in heartbeat
if (settings.modules.heartbeat_detection.enabled && ygopro.constants.MSG[msg] === 'CONFIRM_CARDS') {
check = false;
count = buffer.readInt8(2);
max_loop = 3 + (count - 1) * 7;
deck_found = 0;
limbo_found = 0;
limbo_found = 0; // support custom cards which may be in location 0 in KoishiPro or EdoPro
for (i = n = 3, ref5 = max_loop; n <= ref5; i = n += 7) {
loc = buffer.readInt8(i + 5);
if ((loc & 0x41) > 0) {
......@@ -3277,9 +3419,11 @@
}
}
if (check) {
//console.log("Confirming cards:" + client.name)
client.heartbeat_protected = true;
}
}
// chain detection
if (settings.modules.heartbeat_detection.enabled && client.pos === 0) {
if (ygopro.constants.MSG[msg] === 'CHAINING') {
card = buffer.readUInt32LE(1);
......@@ -3295,6 +3439,7 @@
if (found) {
room.long_resolve_card = card;
} else {
// console.log(0,card)
delete room.long_resolve_card;
}
} else if (ygopro.constants.MSG[msg] === 'CHAINED' && room.long_resolve_card) {
......@@ -3303,9 +3448,11 @@
room.long_resolve_chain = [];
}
room.long_resolve_chain[chain] = true;
// console.log(1,chain)
delete room.long_resolve_card;
} else if (ygopro.constants.MSG[msg] === 'CHAIN_SOLVING' && room.long_resolve_chain) {
chain = buffer.readInt8(1);
// console.log(2,chain)
if (room.long_resolve_chain[chain]) {
ref6 = room.get_playing_player();
for (p = 0, len4 = ref6.length; p < len4; p++) {
......@@ -3315,12 +3462,15 @@
}
} else if ((ygopro.constants.MSG[msg] === 'CHAIN_NEGATED' || ygopro.constants.MSG[msg] === 'CHAIN_DISABLED') && room.long_resolve_chain) {
chain = buffer.readInt8(1);
// console.log(3,chain)
delete room.long_resolve_chain[chain];
} else if (ygopro.constants.MSG[msg] === 'CHAIN_END') {
// console.log(4,chain)
delete room.long_resolve_card;
delete room.long_resolve_chain;
}
}
//登场台词
if (settings.modules.dialogues.enabled) {
if (ygopro.constants.MSG[msg] === 'SUMMONING' || ygopro.constants.MSG[msg] === 'SPSUMMONING' || ygopro.constants.MSG[msg] === 'CHAINING') {
card = buffer.readUInt32LE(1);
......@@ -3345,6 +3495,7 @@
return false;
});
//房间管理
ygopro.ctos_follow('HS_TOOBSERVER', true, function(buffer, info, client, server, datas) {
var len2, m, player, ref2, room;
room = ROOM_all[client.rid];
......@@ -3380,18 +3531,18 @@
player = ref2[m];
if (player && player.pos === info.pos && player !== client) {
if (room.arena === "athletic" || settings.modules.challonge.enabled) {
ygopro.stoc_send_chat_to_room(room, client.name + " ${kicked_by_system}", ygopro.constants.COLORS.RED);
ygopro.stoc_send_chat_to_room(room, `${client.name} \${kicked_by_system}`, ygopro.constants.COLORS.RED);
CLIENT_kick(client);
return true;
}
client.kick_count = client.kick_count ? client.kick_count + 1 : 1;
if (client.kick_count >= 5 && room.random_type) {
ygopro.stoc_send_chat_to_room(room, client.name + " ${kicked_by_system}", ygopro.constants.COLORS.RED);
ygopro.stoc_send_chat_to_room(room, `${client.name} \${kicked_by_system}`, ygopro.constants.COLORS.RED);
ROOM_ban_player(player.name, player.ip, "${random_ban_reason_zombie}");
CLIENT_kick(client);
return true;
}
ygopro.stoc_send_chat_to_room(room, player.name + " ${kicked_by_player}", ygopro.constants.COLORS.RED);
ygopro.stoc_send_chat_to_room(room, `${player.name} \${kicked_by_player}`, ygopro.constants.COLORS.RED);
}
}
return false;
......@@ -3401,8 +3552,12 @@
var is_host, selftype;
selftype = info.type & 0xf;
is_host = ((info.type >> 4) & 0xf) !== 0;
// if room and room.hostinfo.no_watch and selftype == 7
// ygopro.stoc_die(client, "${watch_denied_room}")
// return true
client.is_host = is_host;
client.pos = selftype;
//console.log "TYPE_CHANGE to #{client.name}:", info, selftype, is_host
return false;
});
......@@ -3484,6 +3639,7 @@
}
}
if (room.ready_player_count_without_host >= room.max_player - 1) {
//log.info "all ready"
setTimeout((function() {
wait_room_start(ROOM_all[client.rid], settings.modules.random_duel.ready_time);
}), 1000);
......@@ -3503,9 +3659,9 @@
return true;
}
client.reconnecting = false;
if (client.time_confirm_required) {
if (client.time_confirm_required) { // client did not send TIME_CONFIRM
client.waiting_for_last = true;
} else if (client.last_game_msg && client.last_game_msg_title !== 'WAITING') {
} else if (client.last_game_msg && client.last_game_msg_title !== 'WAITING') { // client sent TIME_CONFIRM
if (client.last_hint_msg) {
ygopro.stoc_send(client, 'GAME_MSG', client.last_hint_msg);
}
......@@ -3549,7 +3705,7 @@
time -= 1;
if (time) {
if (!(time % 5)) {
ygopro.stoc_send_chat_to_room(room, "" + (time <= 9 ? ' ' : '') + time + "${kick_count_down}", time <= 9 ? ygopro.constants.COLORS.RED : ygopro.constants.COLORS.LIGHTBLUE);
ygopro.stoc_send_chat_to_room(room, `${time <= 9 ? ' ' : ''}${time}\${kick_count_down}`, time <= 9 ? ygopro.constants.COLORS.RED : ygopro.constants.COLORS.LIGHTBLUE);
}
setTimeout((function() {
wait_room_start(room, time);
......@@ -3560,7 +3716,7 @@
player = ref2[m];
if (player && player.is_host) {
ROOM_ban_player(player.name, player.ip, "${random_ban_reason_zombie}");
ygopro.stoc_send_chat_to_room(room, player.name + " ${kicked_by_system}", ygopro.constants.COLORS.RED);
ygopro.stoc_send_chat_to_room(room, `${player.name} \${kicked_by_system}`, ygopro.constants.COLORS.RED);
CLIENT_kick(player);
}
}
......@@ -3581,11 +3737,11 @@
continue;
}
display_name = (settings.modules.hide_name && player !== room.waiting_for_player ? "********" : room.waiting_for_player.name);
ygopro.stoc_send_chat(player, "" + (room.waiting_for_player_time <= 9 ? ' ' : '') + room.waiting_for_player_time + "${kick_count_down_arena_part1} " + display_name + " ${kick_count_down_arena_part2}", room.waiting_for_player_time <= 9 ? ygopro.constants.COLORS.RED : ygopro.constants.COLORS.LIGHTBLUE);
ygopro.stoc_send_chat(player, `${room.waiting_for_player_time <= 9 ? ' ' : ''}${room.waiting_for_player_time}\${kick_count_down_arena_part1} ${display_name} \${kick_count_down_arena_part2}`, room.waiting_for_player_time <= 9 ? ygopro.constants.COLORS.RED : ygopro.constants.COLORS.LIGHTBLUE);
}
}
} else {
ygopro.stoc_send_chat_to_room(room, room.waiting_for_player.name + " ${kicked_by_system}", ygopro.constants.COLORS.RED);
ygopro.stoc_send_chat_to_room(room, `${room.waiting_for_player.name} \${kicked_by_system}`, ygopro.constants.COLORS.RED);
CLIENT_kick(room.waiting_for_player);
if (room.waiting_for_player_interval) {
clearInterval(room.waiting_for_player_interval);
......@@ -3595,6 +3751,7 @@
}
};
//tip
ygopro.stoc_send_random_tip = function(client) {
if (settings.modules.tips.enabled && tips.tips.length) {
ygopro.stoc_send_chat(client, "Tip: " + tips.tips[Math.floor(Math.random() * tips.tips.length)]);
......@@ -3647,13 +3804,14 @@
if (!(room && !client.reconnecting)) {
return;
}
if (room.duel_stage === ygopro.constants.DUEL_STAGE.BEGIN) {
if (room.duel_stage === ygopro.constants.DUEL_STAGE.BEGIN) { //first start
room.duel_stage = ygopro.constants.DUEL_STAGE.FINGER;
room.start_time = moment().format();
room.turn = 0;
if (!room.windbot && settings.modules.http.websocket_roomlist) {
roomlist.start(room);
}
//room.duels = []
room.dueling_players = [];
ref2 = room.players;
for (m = 0, len2 = ref2.length; m < len2; m++) {
......@@ -3668,13 +3826,14 @@
name: player.name
});
if (room.random_type === 'T') {
// 双打房不记录匹配过
ROOM_players_oppentlist[player.ip] = null;
}
}
if (room.hostinfo.auto_death) {
ygopro.stoc_send_chat_to_room(room, "${auto_death_part1}" + room.hostinfo.auto_death + "${auto_death_part2}", ygopro.constants.COLORS.BABYBLUE);
ygopro.stoc_send_chat_to_room(room, `\${auto_death_part1}${room.hostinfo.auto_death}\${auto_death_part2}`, ygopro.constants.COLORS.BABYBLUE);
}
} else if (room.duel_stage === ygopro.constants.DUEL_STAGE.SIDING && client.pos < 4) {
} else if (room.duel_stage === ygopro.constants.DUEL_STAGE.SIDING && client.pos < 4) { // side deck verified
client.selected_preduel = true;
if (client.side_tcount) {
clearInterval(client.side_interval);
......@@ -3715,6 +3874,7 @@
} else {
deck_arena = deck_arena + 'custom';
}
//log.info "DECK LOG START", client.name, room.arena
if (settings.modules.deck_log.local) {
deck_name = moment().format('YYYY-MM-DD HH-mm-ss') + ' ' + room.process_pid + ' ' + client.pos + ' ' + client.ip.slice(7) + ' ' + client.name.replace(/[\/\\\?\*]/g, '_');
fs.writeFile(settings.modules.deck_log.local + deck_name + '.ydk', deck_text, 'utf-8', function(err) {
......@@ -3742,6 +3902,8 @@
}
});
}
//else
//log.info 'DECK POST OK', response.statusCode, client.name, body
client.deck_saved = true;
}
});
......@@ -3788,6 +3950,8 @@
});
};
//else
//log.info 'BIG BROTHER OK', response.statusCode, roomname, body
ygopro.ctos_follow('CHAT', true, function(buffer, info, client, server, datas) {
var cancel, ccolor, cip, cmd, cmsg, cname, color, cvalue, msg, name, oldmsg, ref2, room, struct, windbot;
room = ROOM_all[client.rid];
......@@ -3901,6 +4065,8 @@
}
}
}
//when '/test'
// ygopro.stoc_send_hint_card_to_room(room, 2333365)
if (msg.length > 100) {
log.warn("SPAM WORD", client.name, client.ip, msg);
if (client.abuse_count) {
......@@ -3939,12 +4105,14 @@
}
} else if (client.rag && room.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN) {
client.rag = false;
//ygopro.stoc_send_chat(client, "${chat_warn_level0}", ygopro.constants.COLORS.RED)
cancel = true;
} else if (_.any(settings.ban.spam_word, function(badword) {
var regexp;
regexp = new RegExp(badword, 'i');
return msg.match(regexp);
}, msg)) {
//log.warn "SPAM WORD", client.name, client.ip, oldmsg
client.abuse_count = client.abuse_count + 2;
ygopro.stoc_send_chat(client, "${chat_warn_level0}", ygopro.constants.COLORS.RED);
cancel = true;
......@@ -3961,6 +4129,7 @@
} else {
_.each(badwords.level1, function(badword) {
var regexp;
//log.info msg
regexp = new RegExp(badword, "ig");
msg = msg.replace(regexp, "**");
}, msg);
......@@ -3986,7 +4155,7 @@
ROOM_unwelcome(room, client, "${random_ban_reason_abuse}");
}
if (client.abuse_count >= 5) {
ygopro.stoc_send_chat_to_room(room, client.name + " ${chat_banned}", ygopro.constants.COLORS.RED);
ygopro.stoc_send_chat_to_room(room, `${client.name} \${chat_banned}`, ygopro.constants.COLORS.RED);
ROOM_ban_player(client.name, client.ip, "${random_ban_reason_abuse}");
}
return cancel;
......@@ -4018,14 +4187,15 @@
if (!room) {
return false;
}
if (info.mainc > 256 || info.sidec > 256) {
//log.info info
if (info.mainc > 256 || info.sidec > 256) { // Prevent attack, see https://github.com/Fluorohydride/ygopro/issues/2174
CLIENT_kick(client);
return true;
}
buff_main = (function() {
var m, ref2, results;
results = [];
for (i = m = 0, ref2 = info.mainc; 0 <= ref2 ? m < ref2 : m > ref2; i = 0 <= ref2 ? ++m : --m) {
for (i = m = 0, ref2 = info.mainc; (0 <= ref2 ? m < ref2 : m > ref2); i = 0 <= ref2 ? ++m : --m) {
results.push(info.deckbuf[i]);
}
return results;
......@@ -4033,7 +4203,7 @@
buff_side = (function() {
var m, ref2, ref3, results;
results = [];
for (i = m = ref2 = info.mainc, ref3 = info.mainc + info.sidec; ref2 <= ref3 ? m < ref3 : m > ref3; i = ref2 <= ref3 ? ++m : --m) {
for (i = m = ref2 = info.mainc, ref3 = info.mainc + info.sidec; (ref2 <= ref3 ? m < ref3 : m > ref3); i = ref2 <= ref3 ? ++m : --m) {
results.push(info.deckbuf[i]);
}
return results;
......@@ -4106,12 +4276,15 @@
struct.set("sidec", deck_side.length);
struct.set("deckbuf", deckbuf);
buffer = struct.buffer;
ygopro.stoc_send_chat(client, "${deck_correct_part1} " + found_deck + " ${deck_correct_part2}", ygopro.constants.COLORS.BABYBLUE);
//log.info("deck ok: " + client.name)
ygopro.stoc_send_chat(client, `\${deck_correct_part1} ${found_deck} \${deck_correct_part2}`, ygopro.constants.COLORS.BABYBLUE);
} else {
ygopro.stoc_send_chat(client, "${deck_incorrect_part1} " + found_deck + " ${deck_incorrect_part2}", ygopro.constants.COLORS.RED);
//log.info("bad deck: " + client.name + " / " + buff_main + " / " + buff_side)
ygopro.stoc_send_chat(client, `\${deck_incorrect_part1} ${found_deck} \${deck_incorrect_part2}`, ygopro.constants.COLORS.RED);
}
} else {
ygopro.stoc_send_chat(client, client.name + "${deck_not_found}", ygopro.constants.COLORS.RED);
//log.info("player deck not found: " + client.name)
ygopro.stoc_send_chat(client, `${client.name}\${deck_not_found}`, ygopro.constants.COLORS.RED);
}
}
return false;
......@@ -4225,6 +4398,7 @@
return;
}
client.selected_preduel = true;
// room.selecting_tp = false
if (!(room.random_type || room.arena)) {
return;
}
......@@ -4318,7 +4492,7 @@
client.selected_preduel = false;
if (settings.modules.side_timeout) {
client.side_tcount = settings.modules.side_timeout;
ygopro.stoc_send_chat(client, "${side_timeout_part1}" + settings.modules.side_timeout + "${side_timeout_part2}", ygopro.constants.COLORS.BABYBLUE);
ygopro.stoc_send_chat(client, `\${side_timeout_part1}${settings.modules.side_timeout}\${side_timeout_part2}`, ygopro.constants.COLORS.BABYBLUE);
sinterval = setInterval(function() {
if (!(room && client && client.side_tcount && room.duel_stage === ygopro.constants.DUEL_STAGE.SIDING)) {
clearInterval(sinterval);
......@@ -4327,12 +4501,13 @@
if (client.side_tcount === 1) {
ygopro.stoc_send_chat_to_room(room, client.name + "${side_overtime_room}", ygopro.constants.COLORS.BABYBLUE);
ygopro.stoc_send_chat(client, "${side_overtime}", ygopro.constants.COLORS.RED);
//room.scores[client.name_vpass] = -9
CLIENT_send_replays(client, room);
CLIENT_kick(client);
return clearInterval(sinterval);
} else {
client.side_tcount = client.side_tcount - 1;
return ygopro.stoc_send_chat(client, "${side_remain_part1}" + client.side_tcount + "${side_remain_part2}", ygopro.constants.COLORS.BABYBLUE);
return ygopro.stoc_send_chat(client, `\${side_remain_part1}${client.side_tcount}\${side_remain_part2}`, ygopro.constants.COLORS.BABYBLUE);
}
}, 60000);
client.side_interval = sinterval;
......@@ -4374,6 +4549,7 @@
Cloud_replay_ids.push(room.cloud_replay_id);
}
if (!room.replays[room.duel_count - 1]) {
// console.log("Replay saved: ", room.duel_count - 1, client.pos)
room.replays[room.duel_count - 1] = buffer;
}
if (settings.modules.tournament_mode.enabled && settings.modules.tournament_mode.replay_safe) {
......@@ -4424,7 +4600,7 @@
});
}
if (settings.modules.cloud_replay.enabled) {
ygopro.stoc_send_chat(client, "${cloud_replay_delay_part1}R#" + room.cloud_replay_id + "${cloud_replay_delay_part2}", ygopro.constants.COLORS.BABYBLUE);
ygopro.stoc_send_chat(client, `\${cloud_replay_delay_part1}R#${room.cloud_replay_id}\${cloud_replay_delay_part2}`, ygopro.constants.COLORS.BABYBLUE);
}
return settings.modules.tournament_mode.block_replay_to_player || settings.modules.replay_delay && room.hostinfo.mode === 1;
} else {
......@@ -4441,15 +4617,17 @@
return;
}
time_passed = Math.floor((moment() - room.last_active_time) / 1000);
//log.info time_passed
if (time_passed >= settings.modules.random_duel.hang_timeout) {
room.last_active_time = moment();
ROOM_ban_player(room.waiting_for_player.name, room.waiting_for_player.ip, "${random_ban_reason_AFK}");
room.scores[room.waiting_for_player.name_vpass] = -9;
ygopro.stoc_send_chat_to_room(room, room.waiting_for_player.name + " ${kicked_by_system}", ygopro.constants.COLORS.RED);
//log.info room.waiting_for_player.name, room.scores[room.waiting_for_player.name_vpass]
ygopro.stoc_send_chat_to_room(room, `${room.waiting_for_player.name} \${kicked_by_system}`, ygopro.constants.COLORS.RED);
CLIENT_send_replays(room.waiting_for_player, room);
CLIENT_kick(room.waiting_for_player);
} else if (time_passed >= (settings.modules.random_duel.hang_timeout - 20) && !(time_passed % 10)) {
ygopro.stoc_send_chat_to_room(room, room.waiting_for_player.name + " ${afk_warn_part1}" + (settings.modules.random_duel.hang_timeout - time_passed) + "${afk_warn_part2}", ygopro.constants.COLORS.RED);
ygopro.stoc_send_chat_to_room(room, `${room.waiting_for_player.name} \${afk_warn_part1}${settings.modules.random_duel.hang_timeout - time_passed}\${afk_warn_part2}`, ygopro.constants.COLORS.RED);
ROOM_unwelcome(room, room.waiting_for_player, "${random_ban_reason_AFK}");
}
done();
......@@ -4466,14 +4644,16 @@
return;
}
time_passed = Math.floor((moment() - room.last_active_time) / 1000);
//log.info time_passed
if (time_passed >= settings.modules.random_duel.hang_timeout) {
room.last_active_time = moment();
ygopro.stoc_send_chat_to_room(room, room.waiting_for_player.name + " ${kicked_by_system}", ygopro.constants.COLORS.RED);
ygopro.stoc_send_chat_to_room(room, `${room.waiting_for_player.name} \${kicked_by_system}`, ygopro.constants.COLORS.RED);
room.scores[room.waiting_for_player.name_vpass] = -9;
//log.info room.waiting_for_player.name, room.scores[room.waiting_for_player.name_vpass]
CLIENT_send_replays(room.waiting_for_player, room);
CLIENT_kick(room.waiting_for_player);
} else if (time_passed >= (settings.modules.random_duel.hang_timeout - 20) && !(time_passed % 10)) {
ygopro.stoc_send_chat_to_room(room, room.waiting_for_player.name + " ${afk_warn_part1}" + (settings.modules.random_duel.hang_timeout - time_passed) + "${afk_warn_part2}", ygopro.constants.COLORS.RED);
ygopro.stoc_send_chat_to_room(room, `${room.waiting_for_player.name} \${afk_warn_part1}${settings.modules.random_duel.hang_timeout - time_passed}\${afk_warn_part2}`, ygopro.constants.COLORS.RED);
}
done();
});
......@@ -4529,6 +4709,7 @@
});
}, 1000);
// spawn windbot
windbot_looplimit = 0;
windbot_process = global.windbot_process = null;
......@@ -4577,6 +4758,7 @@
global.rebooted = false;
//http
if (settings.modules.http) {
addCallback = function(callback, text) {
if (!callback) {
......@@ -4588,6 +4770,9 @@
var archive_args, archive_name, archive_process, check, death_room_found, duellog, error, filename, getpath, len2, len3, m, n, parseQueryString, pass_validated, ref2, replay, room, roomsjson, u;
parseQueryString = true;
u = url.parse(request.url, parseQueryString);
//pass_validated = u.query.pass == settings.modules.http.password
//console.log(u.query.username, u.query.pass)
if (u.pathname === '/api/getrooms') {
pass_validated = auth.auth(u.query.username, u.query.pass, "get_rooms", "get_rooms", true);
if (!settings.modules.http.public_roomlist && !pass_validated) {
......@@ -4672,14 +4857,11 @@
archive_process = spawn(settings.modules.tournament_mode.replay_archive_tool, archive_args, {
cwd: settings.modules.tournament_mode.replay_path
});
archive_process.on('error', (function(_this) {
return function(err) {
archive_process.on('error', (err) => {
response.writeHead(403);
response.end("Failed packing replays. " + err);
};
})(this));
archive_process.on('exit', (function(_this) {
return function(code) {
});
archive_process.on('exit', (code) => {
return fs.readFile(settings.modules.tournament_mode.replay_path + archive_name, function(error, buffer) {
if (error) {
response.writeHead(403);
......@@ -4692,20 +4874,15 @@
response.end(buffer);
}
});
};
})(this));
});
archive_process.stdout.setEncoding('utf8');
archive_process.stdout.on('data', (function(_this) {
return function(data) {
archive_process.stdout.on('data', (data) => {
return log.info("archive process: " + data);
};
})(this));
});
archive_process.stderr.setEncoding('utf8');
archive_process.stderr.on('data', (function(_this) {
return function(data) {
archive_process.stderr.on('data', (data) => {
return log.warn("archive error: " + data);
};
})(this));
});
} catch (error1) {
error = error1;
response.writeHead(403);
......@@ -4760,6 +4937,10 @@
});
}
} else if (u.pathname === '/api/message') {
//if !pass_validated
// response.writeHead(200)
// response.end(addCallback(u.query.callback, "['密码错误', 0]"))
// return
if (u.query.shout) {
if (!auth.auth(u.query.username, u.query.pass, "shout", "shout")) {
response.writeHead(200);
......
// Generated by CoffeeScript 1.12.7
// Generated by CoffeeScript 2.5.1
(function() {
var Struct, _, declaration, field, i, len, loadJSON, name, result, structs_declaration, type, typedefs;
......@@ -14,14 +14,17 @@
this.i18ns = loadJSON('./data/i18n.json');
structs_declaration = loadJSON('./data/structs.json');
//常量/类型声明
structs_declaration = loadJSON('./data/structs.json'); //结构体声明
typedefs = loadJSON('./data/typedefs.json');
typedefs = loadJSON('./data/typedefs.json'); //类型声明
this.proto_structs = loadJSON('./data/proto_structs.json');
this.proto_structs = loadJSON('./data/proto_structs.json'); //消息与结构体的对应,未完成,对着duelclient.cpp加
this.constants = loadJSON('./data/constants.json');
this.constants = loadJSON('./data/constants.json'); //network.h里定义的常量
//结构体定义
this.structs = {};
for (name in structs_declaration) {
......@@ -35,7 +38,7 @@
result.chars(field.name, field.length * 2, field.encoding);
break;
default:
throw "unsupported encoding: " + field.encoding;
throw `unsupported encoding: ${field.encoding}`;
}
} else {
type = field.type;
......@@ -43,7 +46,7 @@
type = typedefs[type];
}
if (field.length) {
result.array(field.name, field.length, type);
result.array(field.name, field.length, type); //不支持结构体
} else {
if (this.structs[type]) {
result.struct(field.name, this.structs[type]);
......@@ -56,6 +59,7 @@
this.structs[name] = result;
}
//消息跟踪函数 需要重构, 另暂时只支持异步, 同步没做.
this.stoc_follows = {};
this.stoc_follows_before = {};
......@@ -154,11 +158,13 @@
});
};
//消息发送函数,至少要把俩合起来....
this.stoc_send = function(socket, proto, info) {
var buffer, header, key, ref, struct, value;
if (socket.closed) {
return;
}
//console.log proto, proto_structs.STOC[proto], structs[proto_structs.STOC[proto]]
if (typeof info === 'undefined') {
buffer = "";
} else if (Buffer.isBuffer(info)) {
......@@ -169,7 +175,7 @@
struct.set(info);
buffer = struct.buffer();
}
if (typeof proto === 'string') {
if (typeof proto === 'string') { //需要重构
ref = this.constants.STOC;
for (key in ref) {
value = ref[key];
......@@ -196,6 +202,7 @@
if (socket.closed) {
return;
}
//console.log proto, proto_structs.CTOS[proto], structs[proto_structs.CTOS[proto]]
if (typeof info === 'undefined') {
buffer = "";
} else if (Buffer.isBuffer(info)) {
......@@ -206,7 +213,7 @@
struct.set(info);
buffer = struct.buffer();
}
if (typeof proto === 'string') {
if (typeof proto === 'string') { //需要重构
ref = this.constants.CTOS;
for (key in ref) {
value = ref[key];
......@@ -228,11 +235,9 @@
}
};
this.stoc_send_chat = function(client, msg, player) {
//util
this.stoc_send_chat = function(client, msg, player = 8) {
var j, len1, line, o, r, re, ref, ref1;
if (player == null) {
player = 8;
}
if (!client) {
console.log("err stoc_send_chat");
return;
......@@ -256,11 +261,8 @@
}
};
this.stoc_send_chat_to_room = function(room, msg, player) {
this.stoc_send_chat_to_room = function(room, msg, player = 8) {
var client, j, k, len1, len2, ref, ref1;
if (player == null) {
player = 8;
}
if (!room) {
console.log("err stoc_send_chat_to_room");
return;
......
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