Commit cc917435 authored by nanahira's avatar nanahira

Merge branch 'mc'

parents ad5d1fb4 b10a8e8f
...@@ -276,6 +276,7 @@ loadLFList = (path) -> ...@@ -276,6 +276,7 @@ loadLFList = (path) ->
catch catch
init = () -> init = () ->
log.info('Reading config.')
await createDirectoryIfNotExists("./config") await createDirectoryIfNotExists("./config")
await importOldConfig() await importOldConfig()
defaultConfig = await loadJSONAsync('./data/default_config.json') defaultConfig = await loadJSONAsync('./data/default_config.json')
...@@ -296,6 +297,7 @@ init = () -> ...@@ -296,6 +297,7 @@ init = () ->
imported = true imported = true
#import the old passwords to new admin user system #import the old passwords to new admin user system
if settings.modules.http.password if settings.modules.http.password
log.info('Migrating http user.')
await auth.add_user("olduser", settings.modules.http.password, true, { await auth.add_user("olduser", settings.modules.http.password, true, {
"get_rooms": true, "get_rooms": true,
"shout": true, "shout": true,
...@@ -308,6 +310,7 @@ init = () -> ...@@ -308,6 +310,7 @@ init = () ->
delete settings.modules.http.password delete settings.modules.http.password
imported = true imported = true
if settings.modules.tournament_mode.password if settings.modules.tournament_mode.password
log.info('Migrating tournament user.')
await auth.add_user("tournament", settings.modules.tournament_mode.password, true, { await auth.add_user("tournament", settings.modules.tournament_mode.password, true, {
"duel_log": true, "duel_log": true,
"download_replay": true, "download_replay": true,
...@@ -318,12 +321,14 @@ init = () -> ...@@ -318,12 +321,14 @@ init = () ->
delete settings.modules.tournament_mode.password delete settings.modules.tournament_mode.password
imported = true imported = true
if settings.modules.pre_util.password if settings.modules.pre_util.password
log.info('Migrating pre-dash user.')
await auth.add_user("pre", settings.modules.pre_util.password, true, { await auth.add_user("pre", settings.modules.pre_util.password, true, {
"pre_dashboard": true "pre_dashboard": true
}) })
delete settings.modules.pre_util.password delete settings.modules.pre_util.password
imported = true imported = true
if settings.modules.update_util.password if settings.modules.update_util.password
log.info('Migrating update-dash user.')
await auth.add_user("update", settings.modules.update_util.password, true, { await auth.add_user("update", settings.modules.update_util.password, true, {
"update_dashboard": true "update_dashboard": true
}) })
...@@ -353,10 +358,12 @@ init = () -> ...@@ -353,10 +358,12 @@ init = () ->
imported = true imported = true
#finish #finish
if imported if imported
log.info('Saving migrated settings.')
await setting_save(settings) await setting_save(settings)
if settings.modules.mysql.enabled if settings.modules.mysql.enabled
DataManager = require('./data-manager/DataManager.js').DataManager DataManager = require('./data-manager/DataManager.js').DataManager
dataManager = global.dataManager = new DataManager(settings.modules.mysql.db, log) dataManager = global.dataManager = new DataManager(settings.modules.mysql.db, log)
log.info('Connecting to database.')
await dataManager.init() await dataManager.init()
else else
log.warn("Some functions may be limited without MySQL .") log.warn("Some functions may be limited without MySQL .")
...@@ -382,6 +389,7 @@ init = () -> ...@@ -382,6 +389,7 @@ init = () ->
log.warn("Cannot record random match scores because no MySQL.") log.warn("Cannot record random match scores because no MySQL.")
# 读取数据 # 读取数据
log.info('Loading data.')
default_data = await loadJSONAsync('./data/default_data.json') default_data = await loadJSONAsync('./data/default_data.json')
try try
tips = global.tips = await loadJSONAsync('./config/tips.json') tips = global.tips = await loadJSONAsync('./config/tips.json')
...@@ -415,11 +423,13 @@ init = () -> ...@@ -415,11 +423,13 @@ init = () ->
try try
chat_color = await loadJSONAsync('./config/chat_color.json') chat_color = await loadJSONAsync('./config/chat_color.json')
if chat_color if chat_color
log.info("Migrating chat color.")
await dataManager.migrateChatColors(chat_color.save_list); await dataManager.migrateChatColors(chat_color.save_list);
await fs.promises.rename('./config/chat_color.json', './config/chat_color.json.bak') await fs.promises.rename('./config/chat_color.json', './config/chat_color.json.bak')
log.info("Chat color migrated.") log.info("Chat color migrated.")
catch catch
try try
log.info("Reading YGOPro version.")
cppversion = parseInt((await fs.promises.readFile('ygopro/gframe/game.cpp', 'utf8')).match(/PRO_VERSION = ([x\dABCDEF]+)/)[1], '16') cppversion = parseInt((await fs.promises.readFile('ygopro/gframe/game.cpp', 'utf8')).match(/PRO_VERSION = ([x\dABCDEF]+)/)[1], '16')
await setting_change(settings, "version", cppversion) await setting_change(settings, "version", cppversion)
log.info "ygopro version 0x"+settings.version.toString(16), "(from source code)" log.info "ygopro version 0x"+settings.version.toString(16), "(from source code)"
...@@ -427,10 +437,12 @@ init = () -> ...@@ -427,10 +437,12 @@ init = () ->
#settings.version = settings.version_default #settings.version = settings.version_default
log.info "ygopro version 0x"+settings.version.toString(16), "(from config)" log.info "ygopro version 0x"+settings.version.toString(16), "(from config)"
# load the lflist of current date # load the lflist of current date
log.info("Reading banlists.")
await loadLFList('ygopro/expansions/lflist.conf') await loadLFList('ygopro/expansions/lflist.conf')
await loadLFList('ygopro/lflist.conf') await loadLFList('ygopro/lflist.conf')
if settings.modules.windbot.enabled if settings.modules.windbot.enabled
log.info("Reading bot list.")
windbots = global.windbots = (await loadJSONAsync(settings.modules.windbot.botlist)).windbots windbots = global.windbots = (await loadJSONAsync(settings.modules.windbot.botlist)).windbots
real_windbot_server_ip = global.real_windbot_server_ip = settings.modules.windbot.server_ip real_windbot_server_ip = global.real_windbot_server_ip = settings.modules.windbot.server_ip
if !settings.modules.windbot.server_ip.includes("127.0.0.1") if !settings.modules.windbot.server_ip.includes("127.0.0.1")
...@@ -477,6 +489,7 @@ init = () -> ...@@ -477,6 +489,7 @@ init = () ->
arena: settings.modules.arena_mode.mode arena: settings.modules.arena_mode.mode
}) })
try try
log.info("Sending arena init post.")
await axios.post(settings.modules.arena_mode.init_post.url + "?" + postData) await axios.post(settings.modules.arena_mode.init_post.url + "?" + postData)
catch e catch e
log.warn 'ARENA INIT POST ERROR', e log.warn 'ARENA INIT POST ERROR', e
...@@ -641,6 +654,7 @@ init = () -> ...@@ -641,6 +654,7 @@ init = () ->
, 1000 , 1000
log.info("Starting server.")
net.createServer(netRequestHandler).listen settings.port, -> net.createServer(netRequestHandler).listen settings.port, ->
log.info "server started", settings.port log.info "server started", settings.port
return return
...@@ -1325,6 +1339,9 @@ class Room ...@@ -1325,6 +1339,9 @@ class Room
if (rule.match /(^|,|,)(OT|TCG)(,|,|$)/) if (rule.match /(^|,|,)(OT|TCG)(,|,|$)/)
@hostinfo.rule = 2 @hostinfo.rule = 2
if (rule.match /(^|,|,)(CN|CCG|CHINESE)(,|,|$)/)
@hostinfo.rule = 4
if (param = rule.match /(^|,|,)LP(\d+)(,|,|$)/) if (param = rule.match /(^|,|,)LP(\d+)(,|,|$)/)
start_lp = parseInt(param[2]) start_lp = parseInt(param[2])
if (start_lp <= 0) then start_lp = 1 if (start_lp <= 0) then start_lp = 1
...@@ -1512,7 +1529,7 @@ class Room ...@@ -1512,7 +1529,7 @@ class Room
if error if error
log.warn 'SCORE POST ERROR', error log.warn 'SCORE POST ERROR', error
else else
if response.statusCode != 204 and response.statusCode != 200 if response.statusCode >= 300
log.warn 'SCORE POST FAIL', response.statusCode, response.statusMessage, @name, body log.warn 'SCORE POST FAIL', response.statusCode, response.statusMessage, @name, body
#else #else
# log.info 'SCORE POST OK', response.statusCode, response.statusMessage, @name, body # log.info 'SCORE POST OK', response.statusCode, response.statusMessage, @name, body
...@@ -3159,7 +3176,7 @@ ygopro.stoc_follow 'DUEL_START', false, (buffer, info, client, server, datas)-> ...@@ -3159,7 +3176,7 @@ ygopro.stoc_follow 'DUEL_START', false, (buffer, info, client, server, datas)->
if error if error
log.warn 'DECK POST ERROR', error log.warn 'DECK POST ERROR', error
else else
if response.statusCode != 200 if response.statusCode > 300
log.warn 'DECK POST FAIL', response.statusCode, client.name, body log.warn 'DECK POST FAIL', response.statusCode, client.name, body
#else #else
#log.info 'DECK POST OK', response.statusCode, client.name, body #log.info 'DECK POST OK', response.statusCode, client.name, body
...@@ -3200,7 +3217,7 @@ report_to_big_brother = global.report_to_big_brother = (roomname, sender, ip, le ...@@ -3200,7 +3217,7 @@ report_to_big_brother = global.report_to_big_brother = (roomname, sender, ip, le
if error if error
log.warn 'BIG BROTHER ERROR', error log.warn 'BIG BROTHER ERROR', error
else else
if response.statusCode != 200 if response.statusCode >= 300
log.warn 'BIG BROTHER FAIL', response.statusCode, roomname, body log.warn 'BIG BROTHER FAIL', response.statusCode, roomname, body
#else #else
#log.info 'BIG BROTHER OK', response.statusCode, roomname, body #log.info 'BIG BROTHER OK', response.statusCode, roomname, body
......
...@@ -366,6 +366,7 @@ ...@@ -366,6 +366,7 @@
init = async function() { init = async function() {
var AthleticChecker, DataManager, challonge_module_name, challonge_type, chat_color, config, cppversion, defaultConfig, default_data, dirPath, dns, e, http_server, https, https_server, imported, j, l, len, len1, len2, m, mkdirList, options, pgClient, pg_client, pg_query, plugin_filename, plugin_list, plugin_path, postData, ref, vip_info; var AthleticChecker, DataManager, challonge_module_name, challonge_type, chat_color, config, cppversion, defaultConfig, default_data, dirPath, dns, e, http_server, https, https_server, imported, j, l, len, len1, len2, m, mkdirList, options, pgClient, pg_client, pg_query, plugin_filename, plugin_list, plugin_path, postData, ref, vip_info;
log.info('Reading config.');
await createDirectoryIfNotExists("./config"); await createDirectoryIfNotExists("./config");
await importOldConfig(); await importOldConfig();
defaultConfig = (await loadJSONAsync('./data/default_config.json')); defaultConfig = (await loadJSONAsync('./data/default_config.json'));
...@@ -394,6 +395,7 @@ ...@@ -394,6 +395,7 @@
} }
//import the old passwords to new admin user system //import the old passwords to new admin user system
if (settings.modules.http.password) { if (settings.modules.http.password) {
log.info('Migrating http user.');
await auth.add_user("olduser", settings.modules.http.password, true, { await auth.add_user("olduser", settings.modules.http.password, true, {
"get_rooms": true, "get_rooms": true,
"shout": true, "shout": true,
...@@ -407,6 +409,7 @@ ...@@ -407,6 +409,7 @@
imported = true; imported = true;
} }
if (settings.modules.tournament_mode.password) { if (settings.modules.tournament_mode.password) {
log.info('Migrating tournament user.');
await auth.add_user("tournament", settings.modules.tournament_mode.password, true, { await auth.add_user("tournament", settings.modules.tournament_mode.password, true, {
"duel_log": true, "duel_log": true,
"download_replay": true, "download_replay": true,
...@@ -418,6 +421,7 @@ ...@@ -418,6 +421,7 @@
imported = true; imported = true;
} }
if (settings.modules.pre_util.password) { if (settings.modules.pre_util.password) {
log.info('Migrating pre-dash user.');
await auth.add_user("pre", settings.modules.pre_util.password, true, { await auth.add_user("pre", settings.modules.pre_util.password, true, {
"pre_dashboard": true "pre_dashboard": true
}); });
...@@ -425,6 +429,7 @@ ...@@ -425,6 +429,7 @@
imported = true; imported = true;
} }
if (settings.modules.update_util.password) { if (settings.modules.update_util.password) {
log.info('Migrating update-dash user.');
await auth.add_user("update", settings.modules.update_util.password, true, { await auth.add_user("update", settings.modules.update_util.password, true, {
"update_dashboard": true "update_dashboard": true
}); });
...@@ -468,11 +473,13 @@ ...@@ -468,11 +473,13 @@
} }
//finish //finish
if (imported) { if (imported) {
log.info('Saving migrated settings.');
await setting_save(settings); await setting_save(settings);
} }
if (settings.modules.mysql.enabled) { if (settings.modules.mysql.enabled) {
DataManager = require('./data-manager/DataManager.js').DataManager; DataManager = require('./data-manager/DataManager.js').DataManager;
dataManager = global.dataManager = new DataManager(settings.modules.mysql.db, log); dataManager = global.dataManager = new DataManager(settings.modules.mysql.db, log);
log.info('Connecting to database.');
await dataManager.init(); await dataManager.init();
} else { } else {
log.warn("Some functions may be limited without MySQL ."); log.warn("Some functions may be limited without MySQL .");
...@@ -503,6 +510,7 @@ ...@@ -503,6 +510,7 @@
} }
} }
// 读取数据 // 读取数据
log.info('Loading data.');
default_data = (await loadJSONAsync('./data/default_data.json')); default_data = (await loadJSONAsync('./data/default_data.json'));
try { try {
tips = global.tips = (await loadJSONAsync('./config/tips.json')); tips = global.tips = (await loadJSONAsync('./config/tips.json'));
...@@ -544,6 +552,7 @@ ...@@ -544,6 +552,7 @@
try { try {
chat_color = (await loadJSONAsync('./config/chat_color.json')); chat_color = (await loadJSONAsync('./config/chat_color.json'));
if (chat_color) { if (chat_color) {
log.info("Migrating chat color.");
await dataManager.migrateChatColors(chat_color.save_list); await dataManager.migrateChatColors(chat_color.save_list);
await fs.promises.rename('./config/chat_color.json', './config/chat_color.json.bak'); await fs.promises.rename('./config/chat_color.json', './config/chat_color.json.bak');
log.info("Chat color migrated."); log.info("Chat color migrated.");
...@@ -553,6 +562,7 @@ ...@@ -553,6 +562,7 @@
} }
} }
try { try {
log.info("Reading YGOPro version.");
cppversion = parseInt(((await fs.promises.readFile('ygopro/gframe/game.cpp', 'utf8'))).match(/PRO_VERSION = ([x\dABCDEF]+)/)[1], '16'); cppversion = parseInt(((await fs.promises.readFile('ygopro/gframe/game.cpp', 'utf8'))).match(/PRO_VERSION = ([x\dABCDEF]+)/)[1], '16');
await setting_change(settings, "version", cppversion); await setting_change(settings, "version", cppversion);
log.info("ygopro version 0x" + settings.version.toString(16), "(from source code)"); log.info("ygopro version 0x" + settings.version.toString(16), "(from source code)");
...@@ -561,9 +571,11 @@ ...@@ -561,9 +571,11 @@
log.info("ygopro version 0x" + settings.version.toString(16), "(from config)"); log.info("ygopro version 0x" + settings.version.toString(16), "(from config)");
} }
// load the lflist of current date // load the lflist of current date
log.info("Reading banlists.");
await loadLFList('ygopro/expansions/lflist.conf'); await loadLFList('ygopro/expansions/lflist.conf');
await loadLFList('ygopro/lflist.conf'); await loadLFList('ygopro/lflist.conf');
if (settings.modules.windbot.enabled) { if (settings.modules.windbot.enabled) {
log.info("Reading bot list.");
windbots = global.windbots = ((await loadJSONAsync(settings.modules.windbot.botlist))).windbots; windbots = global.windbots = ((await loadJSONAsync(settings.modules.windbot.botlist))).windbots;
real_windbot_server_ip = global.real_windbot_server_ip = settings.modules.windbot.server_ip; real_windbot_server_ip = global.real_windbot_server_ip = settings.modules.windbot.server_ip;
if (!settings.modules.windbot.server_ip.includes("127.0.0.1")) { if (!settings.modules.windbot.server_ip.includes("127.0.0.1")) {
...@@ -613,6 +625,7 @@ ...@@ -613,6 +625,7 @@
arena: settings.modules.arena_mode.mode arena: settings.modules.arena_mode.mode
}); });
try { try {
log.info("Sending arena init post.");
await axios.post(settings.modules.arena_mode.init_post.url + "?" + postData); await axios.post(settings.modules.arena_mode.init_post.url + "?" + postData);
} catch (error1) { } catch (error1) {
e = error1; e = error1;
...@@ -840,6 +853,7 @@ ...@@ -840,6 +853,7 @@
} }
return results; return results;
}, 1000); }, 1000);
log.info("Starting server.");
net.createServer(netRequestHandler).listen(settings.port, function() { net.createServer(netRequestHandler).listen(settings.port, function() {
log.info("server started", settings.port); log.info("server started", settings.port);
}); });
...@@ -1738,6 +1752,9 @@ ...@@ -1738,6 +1752,9 @@
if (rule.match(/(^|,|,)(OT|TCG)(,|,|$)/)) { if (rule.match(/(^|,|,)(OT|TCG)(,|,|$)/)) {
this.hostinfo.rule = 2; this.hostinfo.rule = 2;
} }
if (rule.match(/(^|,|,)(CN|CCG|CHINESE)(,|,|$)/)) {
this.hostinfo.rule = 4;
}
if ((param = rule.match(/(^|,|,)LP(\d+)(,|,|$)/))) { if ((param = rule.match(/(^|,|,)LP(\d+)(,|,|$)/))) {
start_lp = parseInt(param[2]); start_lp = parseInt(param[2]);
if (start_lp <= 0) { if (start_lp <= 0) {
...@@ -2003,7 +2020,7 @@ ...@@ -2003,7 +2020,7 @@
if (error) { if (error) {
log.warn('SCORE POST ERROR', error); log.warn('SCORE POST ERROR', error);
} else { } else {
if (response.statusCode !== 204 && response.statusCode !== 200) { if (response.statusCode >= 300) {
log.warn('SCORE POST FAIL', response.statusCode, response.statusMessage, this.name, body); log.warn('SCORE POST FAIL', response.statusCode, response.statusMessage, this.name, body);
} }
} }
...@@ -4230,7 +4247,7 @@ ...@@ -4230,7 +4247,7 @@
if (error) { if (error) {
log.warn('DECK POST ERROR', error); log.warn('DECK POST ERROR', error);
} else { } else {
if (response.statusCode !== 200) { if (response.statusCode > 300) {
log.warn('DECK POST FAIL', response.statusCode, client.name, body); log.warn('DECK POST FAIL', response.statusCode, client.name, body);
} }
} }
...@@ -4288,7 +4305,7 @@ ...@@ -4288,7 +4305,7 @@
if (error) { if (error) {
log.warn('BIG BROTHER ERROR', error); log.warn('BIG BROTHER ERROR', error);
} else { } else {
if (response.statusCode !== 200) { if (response.statusCode >= 300) {
log.warn('BIG BROTHER FAIL', response.statusCode, roomname, body); log.warn('BIG BROTHER FAIL', response.statusCode, roomname, body);
} }
} }
......
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