Commit 35c65627 authored by nanahira's avatar nanahira

Merge branch 'koishi' into enter-room-log

parents 4793da0a 9178162a
Pipeline #16273 passed with stages
in 8 minutes and 4 seconds
......@@ -198,7 +198,6 @@
"enabled": false,
"deck_check": true,
"deck_path": "./decks/",
"replay_safe": true,
"replay_path": "./replays/",
"replay_archive_tool": "7z",
"block_replay_to_player": false,
......
......@@ -115,7 +115,19 @@ setting_save = global.setting_save = (settings) ->
log.warn("setting save fail", e.toString())
return
setting_change = global.setting_change = (settings, path, val) ->
setting_get = global.setting_get = (settings, path) ->
path = path.split(':')
if path.length == 0
return settings[path[0]]
else
target = settings
while path.length > 1
key = path.shift()
target = target[key]
key = path.shift()
return target[key]
setting_change = global.setting_change = (settings, path, val, noSave) ->
# path should be like "modules:welcome"
log.info("setting changed", path, val) if _.isString(val)
path=path.split(':')
......@@ -128,6 +140,7 @@ setting_change = global.setting_change = (settings, path, val) ->
target=target[key]
key = path.shift()
target[key] = val
if !noSave
await setting_save(settings)
return
......@@ -382,6 +395,23 @@ init = () ->
delete settings.modules.random_duel.blank_pass_match
imported = true
#finish
keysFromEnv = Object.keys(process.env).filter((key) => key.startsWith('SRVPRO_'))
if keysFromEnv.length > 0
log.info('Migrating settings from environment variables.')
for key in keysFromEnv
settingKey = key.slice(7).replace(/__/g, ':')
val = process.env[key]
valFromDefault = setting_get(defaultConfig, settingKey)
if Array.isArray(valFromDefault)
val = val.split(',')
valFromDefault = valFromDefault[0]
if typeof valFromDefault == 'number'
val = parseFloat(val)
if typeof valFromDefault == 'boolean'
val = (val != 'false') && (val != '0')
setting_change(settings, settingKey, val, true)
imported = true
if imported
log.info('Saving migrated settings.')
await setting_save(settings)
......@@ -3773,12 +3803,11 @@ ygopro.stoc_follow 'CHANGE_SIDE', false, (buffer, info, client, server, datas)->
ygopro.stoc_follow 'REPLAY', true, (buffer, info, client, server, datas)->
room=ROOM_all[client.rid]
return settings.modules.tournament_mode.enabled and settings.modules.tournament_mode.block_replay_to_player or settings.modules.replay_delay unless room
if !room.replays[room.duel_count - 1]
if room and !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.mysql.enabled or room.has_ygopro_error
if client.pos == 0
console.log('save replay')
replay_filename=moment_now.format("YYYY-MM-DD HH-mm-ss")
if room.hostinfo.mode != 2
for player,i in room.dueling_players
......@@ -3810,11 +3839,9 @@ ygopro.stoc_follow 'REPLAY', true, (buffer, info, client, server, datas)->
}
)
dataManager.saveDuelLog(room.name, room.process_pid, room.cloud_replay_id, replay_filename, room.hostinfo.mode, room.duel_count, playerInfos) # no synchronize here because too slow
if settings.modules.mysql.enabled && settings.modules.cloud_replay.enabled and settings.modules.tournament_mode.enabled and settings.modules.tournament_mode.replay_safe
if settings.modules.mysql.enabled && settings.modules.cloud_replay.enabled and settings.modules.tournament_mode.enabled
ygopro.stoc_send_chat(client, "${cloud_replay_delay_part1}R##{room.cloud_replay_id}${cloud_replay_delay_part2}", ygopro.constants.COLORS.BABYBLUE)
await return settings.modules.tournament_mode.enabled and settings.modules.tournament_mode.block_replay_to_player or settings.modules.replay_delay and room.hostinfo.mode == 1
else
await return settings.modules.replay_delay and room.hostinfo.mode == 1
# spawn windbot
windbot_looplimit = 0
......
// Generated by CoffeeScript 2.6.1
(function() {
// 标准库
var CLIENT_check_vip, CLIENT_get_absolute_pos, CLIENT_get_authorize_key, CLIENT_get_kick_reconnect_target, CLIENT_get_partner, CLIENT_get_save_data, 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, CLIENT_send_vip_status, CLIENT_use_cdkey, Q, 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_oppentlist, ROOM_unwelcome, ROOM_validate, ReplayParser, ResolveData, Room, SERVER_clear_disconnect, SERVER_kick, SOCKET_flush_data, VIP_generate_cdkeys, _, _async, addCallback, athleticChecker, auth, axios, badwordR, badwords, ban_user, bunyan, challonge, checkFileExists, concat_name, createDirectoryIfNotExists, crypto, dataManager, deck_name_match, dialogues, disconnect_list, exec, execFile, fs, geoip, getDuelLogQueryFromQs, getSeedTimet, get_memory_usage, http, httpRequestListener, importOldConfig, import_datas, init, lflists, loadJSON, loadJSONAsync, loadLFList, loadRemoteData, load_dialogues, load_dialogues_custom, load_tips, load_tips_zh, load_words, log, long_resolve_cards, memory_usage, merge, moment, moment_long_ago_string, moment_now, moment_now_string, net, netRequestHandler, os, osu, path, qs, real_windbot_server_ip, release_disconnect, report_to_big_brother, request, roomlist, rooms_count, setting_change, setting_save, settings, spawn, spawnSync, spawn_windbot, tips, url, users_cache, util, wait_room_start, wait_room_start_arena, windbot_looplimit, windbot_process, windbots, words, ygopro, zlib;
var CLIENT_check_vip, CLIENT_get_absolute_pos, CLIENT_get_authorize_key, CLIENT_get_kick_reconnect_target, CLIENT_get_partner, CLIENT_get_save_data, 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, CLIENT_send_vip_status, CLIENT_use_cdkey, Q, 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_oppentlist, ROOM_unwelcome, ROOM_validate, ReplayParser, ResolveData, Room, SERVER_clear_disconnect, SERVER_kick, SOCKET_flush_data, VIP_generate_cdkeys, _, _async, addCallback, athleticChecker, auth, axios, badwordR, badwords, ban_user, bunyan, challonge, checkFileExists, concat_name, createDirectoryIfNotExists, crypto, dataManager, deck_name_match, dialogues, disconnect_list, exec, execFile, fs, geoip, getDuelLogQueryFromQs, getSeedTimet, get_memory_usage, http, httpRequestListener, importOldConfig, import_datas, init, lflists, loadJSON, loadJSONAsync, loadLFList, loadRemoteData, load_dialogues, load_dialogues_custom, load_tips, load_tips_zh, load_words, log, long_resolve_cards, memory_usage, merge, moment, moment_long_ago_string, moment_now, moment_now_string, net, netRequestHandler, os, osu, path, qs, real_windbot_server_ip, release_disconnect, report_to_big_brother, request, roomlist, rooms_count, setting_change, setting_get, setting_save, settings, spawn, spawnSync, spawn_windbot, tips, url, users_cache, util, wait_room_start, wait_room_start_arena, windbot_looplimit, windbot_process, windbots, words, ygopro, zlib;
net = require('net');
......@@ -118,7 +118,23 @@
}
};
setting_change = global.setting_change = async function(settings, path, val) {
setting_get = global.setting_get = function(settings, path) {
var key, target;
path = path.split(':');
if (path.length === 0) {
return settings[path[0]];
} else {
target = settings;
while (path.length > 1) {
key = path.shift();
target = target[key];
}
key = path.shift();
return target[key];
}
};
setting_change = global.setting_change = async function(settings, path, val, noSave) {
var key, target;
if (_.isString(val)) {
// path should be like "modules:welcome"
......@@ -136,7 +152,9 @@
key = path.shift();
target[key] = val;
}
if (!noSave) {
await setting_save(settings);
}
};
VIP_generate_cdkeys = global.VIP_generate_cdkeys = async function(key_type, count) {
......@@ -352,7 +370,7 @@
};
init = async function() {
var AthleticChecker, Challonge, DataManager, chat_color, config, cppversion, defaultConfig, default_data, dirPath, dns, e, get_rooms_count, http_server, https, https_server, imported, j, l, len, len1, mkdirList, options, pgClient, pg_client, pg_query, plugin_filename, plugin_list, plugin_path, postData, vip_info;
var AthleticChecker, Challonge, DataManager, chat_color, config, cppversion, defaultConfig, default_data, dirPath, dns, e, get_rooms_count, http_server, https, https_server, imported, j, key, keysFromEnv, l, len, len1, len2, m, mkdirList, options, pgClient, pg_client, pg_query, plugin_filename, plugin_list, plugin_path, postData, settingKey, val, valFromDefault, vip_info;
log.info('Reading config.');
await createDirectoryIfNotExists("./config");
await importOldConfig();
......@@ -492,6 +510,30 @@
imported = true;
}
//finish
keysFromEnv = Object.keys(process.env).filter((key) => {
return key.startsWith('SRVPRO_');
});
if (keysFromEnv.length > 0) {
log.info('Migrating settings from environment variables.');
for (j = 0, len = keysFromEnv.length; j < len; j++) {
key = keysFromEnv[j];
settingKey = key.slice(7).replace(/__/g, ':');
val = process.env[key];
valFromDefault = setting_get(defaultConfig, settingKey);
if (Array.isArray(valFromDefault)) {
val = val.split(',');
valFromDefault = valFromDefault[0];
}
if (typeof valFromDefault === 'number') {
val = parseFloat(val);
}
if (typeof valFromDefault === 'boolean') {
val = (val !== 'false') && (val !== '0');
}
setting_change(settings, settingKey, val, true);
}
imported = true;
}
if (imported) {
log.info('Saving migrated settings.');
await setting_save(settings);
......@@ -609,10 +651,10 @@
if (settings.modules.max_rooms_count) {
rooms_count = 0;
get_rooms_count = function() {
var _rooms_count, j, len, room;
var _rooms_count, l, len1, room;
_rooms_count = 0;
for (j = 0, len = ROOM_all.length; j < len; j++) {
room = ROOM_all[j];
for (l = 0, len1 = ROOM_all.length; l < len1; l++) {
room = ROOM_all[l];
if (room && room.established) {
_rooms_count++;
}
......@@ -694,9 +736,9 @@
if (settings.modules.tips.enabled) {
if (settings.modules.tips.interval) {
setInterval(function() {
var j, len, room;
for (j = 0, len = ROOM_all.length; j < len; j++) {
room = ROOM_all[j];
var l, len1, room;
for (l = 0, len1 = ROOM_all.length; l < len1; l++) {
room = ROOM_all[l];
if (room && room.established && room.duel_stage !== ygopro.constants.END) {
if (room.duel_stage !== ygopro.constants.DUEL_STAGE.DUELING) {
ygopro.stoc_send_random_tip_to_room(room);
......@@ -707,9 +749,9 @@
}
if (settings.modules.tips.interval_ingame) {
setInterval(function() {
var j, len, room;
for (j = 0, len = ROOM_all.length; j < len; j++) {
room = ROOM_all[j];
var l, len1, room;
for (l = 0, len1 = ROOM_all.length; l < len1; l++) {
room = ROOM_all[l];
if (room && room.established && room.duel_stage !== ygopro.constants.END) {
if (room.duel_stage === ygopro.constants.DUEL_STAGE.DUELING) {
ygopro.stoc_send_random_tip_to_room(room);
......@@ -745,9 +787,9 @@
}
if (settings.modules.random_duel.enabled) {
setInterval(async function() {
var j, len, room, time_passed;
for (j = 0, len = ROOM_all.length; j < len; j++) {
room = ROOM_all[j];
var l, len1, room, time_passed;
for (l = 0, len1 = ROOM_all.length; l < len1; l++) {
room = ROOM_all[l];
if (!(room && room.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN && room.random_type && room.last_active_time && room.waiting_for_player && room.get_disconnected_count() === 0 && (!settings.modules.side_timeout || room.duel_stage !== ygopro.constants.DUEL_STAGE.SIDING) && !room.recovered)) {
continue;
}
......@@ -770,9 +812,9 @@
}
if (settings.modules.mycard.enabled) {
setInterval(function() {
var j, l, len, len1, player, room, time_passed, waited_time;
for (j = 0, len = ROOM_all.length; j < len; j++) {
room = ROOM_all[j];
var l, len1, len2, m, player, room, time_passed, waited_time;
for (l = 0, len1 = ROOM_all.length; l < len1; l++) {
room = ROOM_all[l];
if (!(room && room.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN && room.arena && room.last_active_time && room.waiting_for_player && room.get_disconnected_count() === 0 && (!settings.modules.side_timeout || room.duel_stage !== ygopro.constants.DUEL_STAGE.SIDING) && !room.recovered)) {
continue;
}
......@@ -790,8 +832,8 @@
}
}
if (true) { // settings.modules.arena_mode.punish_quit_before_match
for (l = 0, len1 = ROOM_all.length; l < len1; l++) {
room = ROOM_all[l];
for (m = 0, len2 = ROOM_all.length; m < len2; m++) {
room = ROOM_all[m];
if (!(room && room.arena && room.duel_stage === ygopro.constants.DUEL_STAGE.BEGIN && room.get_playing_player().length < 2)) {
continue;
}
......@@ -811,13 +853,13 @@
}
if (settings.modules.heartbeat_detection.enabled) {
setInterval(function() {
var j, l, len, len1, player, ref, room;
for (j = 0, len = ROOM_all.length; j < len; j++) {
room = ROOM_all[j];
var l, len1, len2, m, player, ref, room;
for (l = 0, len1 = ROOM_all.length; l < len1; l++) {
room = ROOM_all[l];
if (room && room.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN && (room.hostinfo.time_limit === 0 || room.duel_stage !== ygopro.constants.DUEL_STAGE.DUELING) && !room.windbot) {
ref = room.get_playing_player();
for (l = 0, len1 = ref.length; l < len1; l++) {
player = ref[l];
for (m = 0, len2 = ref.length; m < len2; m++) {
player = ref[m];
if (player && (room.duel_stage !== ygopro.constants.DUEL_STAGE.SIDING || player.selected_preduel)) {
CLIENT_heartbeat_register(player, true);
}
......@@ -830,10 +872,10 @@
spawn_windbot();
}
setInterval(function() {
var j, len, results, room;
var l, len1, results, room;
results = [];
for (j = 0, len = ROOM_all.length; j < len; j++) {
room = ROOM_all[j];
for (l = 0, len1 = ROOM_all.length; l < len1; l++) {
room = ROOM_all[l];
if (!(room && room.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN && room.hostinfo.auto_death && !room.auto_death_triggered && moment_now.diff(room.start_time) > 60000 * room.hostinfo.auto_death)) {
continue;
}
......@@ -864,13 +906,13 @@
https_server.listen(settings.modules.http.ssl.port);
}
mkdirList = ["./plugins", settings.modules.tournament_mode.deck_path, settings.modules.tournament_mode.replay_path, settings.modules.tournament_mode.log_save_path, settings.modules.deck_log.local];
for (j = 0, len = mkdirList.length; j < len; j++) {
dirPath = mkdirList[j];
for (l = 0, len1 = mkdirList.length; l < len1; l++) {
dirPath = mkdirList[l];
await createDirectoryIfNotExists(dirPath);
}
plugin_list = (await fs.promises.readdir("./plugins"));
for (l = 0, len1 = plugin_list.length; l < len1; l++) {
plugin_filename = plugin_list[l];
for (m = 0, len2 = plugin_list.length; m < len2; m++) {
plugin_filename = plugin_list[m];
plugin_path = process.cwd() + "/plugins/" + plugin_filename;
require(plugin_path);
log.info("Plugin loaded:", plugin_filename);
......@@ -5080,15 +5122,11 @@
ygopro.stoc_follow('REPLAY', true, async function(buffer, info, client, server, datas) {
var i, j, l, len, len1, player, playerInfos, ref, ref1, replay_filename, room;
room = ROOM_all[client.rid];
if (!room) {
return settings.modules.tournament_mode.enabled && settings.modules.tournament_mode.block_replay_to_player || settings.modules.replay_delay;
}
if (!room.replays[room.duel_count - 1]) {
if (room && !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.mysql.enabled || room.has_ygopro_error) {
if (client.pos === 0) {
console.log('save replay');
replay_filename = moment_now.format("YYYY-MM-DD HH-mm-ss");
if (room.hostinfo.mode !== 2) {
ref = room.dueling_players;
......@@ -5131,13 +5169,11 @@
dataManager.saveDuelLog(room.name, room.process_pid, room.cloud_replay_id, replay_filename, room.hostinfo.mode, room.duel_count, playerInfos); // no synchronize here because too slow
}
}
if (settings.modules.mysql.enabled && settings.modules.cloud_replay.enabled && settings.modules.tournament_mode.enabled && settings.modules.tournament_mode.replay_safe) {
if (settings.modules.mysql.enabled && settings.modules.cloud_replay.enabled && settings.modules.tournament_mode.enabled) {
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.enabled && settings.modules.tournament_mode.block_replay_to_player || settings.modules.replay_delay && room.hostinfo.mode === 1;
} else {
return settings.modules.replay_delay && room.hostinfo.mode === 1;
}
return settings.modules.tournament_mode.enabled && settings.modules.tournament_mode.block_replay_to_player || settings.modules.replay_delay && room.hostinfo.mode === 1;
});
// spawn windbot
......
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