Commit ec322fef authored by nanahira's avatar nanahira

async for dashboard

parent d6a52232
......@@ -132,11 +132,15 @@ try
catch e
log.info e unless e.code == 'ENOENT'
setting_save = global.setting_save = (settings) ->
fs.writeFileSync(settings.file, JSON.stringify(settings, null, 2))
setting_save = global.setting_save = (settings, callback) ->
if !callback
callback = (err) ->
if(err)
log.warn("setting save fail", err.toString())
fs.writeFile(settings.file, JSON.stringify(settings, null, 2), callback)
return
setting_change = global.setting_change = (settings, path, val) ->
setting_change = global.setting_change = (settings, path, val, callback) ->
# path should be like "modules:welcome"
log.info("setting changed", path, val) if _.isString(val)
path=path.split(':')
......@@ -149,7 +153,7 @@ setting_change = global.setting_change = (settings, path, val) ->
target=target[key]
key = path.shift()
target[key] = val
setting_save(settings)
setting_save(settings, callback)
return
# 读取配置
......@@ -450,20 +454,27 @@ ROOM_connected_ip = global.ROOM_connected_ip = {}
ROOM_bad_ip = global.ROOM_bad_ip = {}
# ban a user manually and permanently
ban_user = global.ban_user = (name) ->
ban_user = global.ban_user = (name, callback) ->
settings.ban.banned_user.push(name)
setting_save(settings)
bad_ip=0
for room in ROOM_all when room and room.established
for player in room.players
if player and (player.name == name or player.ip == bad_ip)
bad_ip = []
_async.each(ROOM_all.filter((room)->
return room and room.established
), (room, done)->
_async.each(["players", "watchers"], (player_type, _done)->
_async.each(room[player_type].filter((player)->
return player and (player.name == name or bad_ip.indexOf(player.ip) != -1)
), (player, __done)->
bad_ip = 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)
CLIENT_send_replays(player, room)
CLIENT_kick(player)
continue
__done()
, _done)
, done)
, callback)
return
# automatically ban user to use random duel
......@@ -484,6 +495,28 @@ ROOM_ban_player = global.ROOM_ban_player = (name, ip, reason, countadd = 1)->
#log.info("banned", name, ip, reason, bannedplayer.count)
return
ROOM_kick = (name, callback)->
rooms = ROOM_all.filter((room)->
return room and room.established and (name == "all" or name == room.process_pid.toString() or name == room.name)
)
if !rooms.length
callback(null, false)
_async.each(rooms, (room, done)->
if room.duel_stage != ygopro.constants.DUEL_STAGE.BEGIN
room.scores[room.dueling_players[0].name_vpass] = 0
room.scores[room.dueling_players[1].name_vpass] = 0
room.kicked = true
room.send_replays()
room.process.kill()
room.delete()
done()
return
, (err)->
callback(null, true)
return
)
ROOM_player_win = global.ROOM_player_win = (name)->
if !ROOM_players_scores[name]
ROOM_players_scores[name]={win:0, lose:0, flee:0, combo:0}
......@@ -2366,7 +2399,7 @@ ygopro.stoc_follow 'JOIN_GAME', false, (buffer, info, client, server, datas)->
return
# 登场台词
load_dialogues = global.load_dialogues = () ->
load_dialogues = global.load_dialogues = (callback) ->
request
url: settings.modules.dialogues.get
json: true
......@@ -2378,6 +2411,8 @@ load_dialogues = global.load_dialogues = () ->
else
setting_change(dialogues, "dialogues", body)
log.info "dialogues loaded", _.size dialogues.dialogues
if callback
callback(error, body)
return
return
......@@ -2824,7 +2859,7 @@ ygopro.stoc_send_random_tip_to_room = (room)->
ygopro.stoc_send_chat_to_room(room, "Tip: " + tips.tips[Math.floor(Math.random() * tips.tips.length)])
return
load_tips = global.load_tips = ()->
load_tips = global.load_tips = (callback)->
request
url: settings.modules.tips.get
json: true
......@@ -2836,6 +2871,8 @@ load_tips = global.load_tips = ()->
else
setting_change(tips, "tips", body)
log.info "tips loaded", tips.tips.length
if callback
callback(error, body)
return
return
......@@ -3506,13 +3543,13 @@ spawn_windbot = global.spawn_windbot = () ->
windbot_process = spawn windbot_bin, windbot_parameters, {cwd: 'windbot'}
windbot_process.on 'error', (err)->
log.warn 'WindBot ERROR', err
if windbot_looplimit < 1000 and !rebooted
if windbot_looplimit < 1000 and !global.rebooted
windbot_looplimit++
spawn_windbot()
return
windbot_process.on 'exit', (code)->
log.warn 'WindBot EXIT', code
if windbot_looplimit < 1000 and !rebooted
if windbot_looplimit < 1000 and !global.rebooted
windbot_looplimit++
spawn_windbot()
return
......@@ -3529,7 +3566,7 @@ spawn_windbot = global.spawn_windbot = () ->
if settings.modules.windbot.enabled and settings.modules.windbot.spawn
spawn_windbot()
rebooted = false
global.rebooted = false
#http
if settings.modules.http
......@@ -3687,18 +3724,26 @@ if settings.modules.http
return
if u.query.stop == 'false'
u.query.stop = false
setting_change(settings, 'modules:stop', u.query.stop)
response.writeHead(200)
response.end(addCallback(u.query.callback, "['stop ok', '" + u.query.stop + "']"))
setting_change(settings, 'modules:stop', u.query.stop, (err)->
response.writeHead(200)
if(err)
response.end(addCallback(u.query.callback, "['stop fail', '" + u.query.stop + "']"))
else
response.end(addCallback(u.query.callback, "['stop ok', '" + u.query.stop + "']"))
)
else if u.query.welcome
if !auth.auth(u.query.username, u.query.pass, "change_settings", "change_welcome")
response.writeHead(200)
response.end(addCallback(u.query.callback, "['密码错误', 0]"))
return
setting_change(settings, 'modules:welcome', u.query.welcome)
response.writeHead(200)
response.end(addCallback(u.query.callback, "['welcome ok', '" + u.query.welcome + "']"))
setting_change(settings, 'modules:welcome', (err)->
response.writeHead(200)
if(err)
response.end(addCallback(u.query.callback, "['welcome fail', '" + u.query.welcome + "']"))
else
response.end(addCallback(u.query.callback, "['welcome ok', '" + u.query.welcome + "']"))
)
else if u.query.getwelcome
if !auth.auth(u.query.username, u.query.pass, "change_settings", "get_welcome")
......@@ -3713,98 +3758,112 @@ if settings.modules.http
response.writeHead(200)
response.end(addCallback(u.query.callback, "['密码错误', 0]"))
return
load_tips()
response.writeHead(200)
response.end(addCallback(u.query.callback, "['loading tip', '" + settings.modules.tips.get + "']"))
load_tips((err)->
response.writeHead(200)
if(err)
response.end(addCallback(u.query.callback, "['tip fail', '" + u.query.loadtips + "']"))
else
response.end(addCallback(u.query.callback, "['tip ok', '" + u.query.loadtips + "']"))
)
else if u.query.loaddialogues
if !auth.auth(u.query.username, u.query.pass, "change_settings", "change_dialogues")
response.writeHead(200)
response.end(addCallback(u.query.callback, "['密码错误', 0]"))
return
load_dialogues()
response.writeHead(200)
response.end(addCallback(u.query.callback, "['loading dialogues', '" + settings.modules.dialogues.get + "']"))
load_dialogues((err)->
response.writeHead(200)
if(err)
response.end(addCallback(u.query.callback, "['dialogues fail', '" + u.query.loaddialogues + "']"))
else
response.end(addCallback(u.query.callback, "['dialogues ok', '" + u.query.loaddialogues + "']"))
)
else if u.query.ban
if !auth.auth(u.query.username, u.query.pass, "ban_user", "ban_user")
response.writeHead(200)
response.end(addCallback(u.query.callback, "['密码错误', 0]"))
return
ban_user(u.query.ban)
response.writeHead(200)
response.end(addCallback(u.query.callback, "['ban ok', '" + u.query.ban + "']"))
ban_user(u.query.ban, (err)->
response.writeHead(200)
if(err)
response.end(addCallback(u.query.callback, "['ban fail', '" + u.query.ban + "']"))
else
response.end(addCallback(u.query.callback, "['ban ok', '" + u.query.ban + "']"))
)
else if u.query.kick
if !auth.auth(u.query.username, u.query.pass, "kick_user", "kick_user")
response.writeHead(200)
response.end(addCallback(u.query.callback, "['密码错误', 0]"))
return
kick_room_found = false
for room in ROOM_all when room and room.established and (u.query.kick == "all" or u.query.kick == room.process_pid.toString() or u.query.kick == room.name)
kick_room_found = true
if room.duel_stage != ygopro.constants.DUEL_STAGE.BEGIN
room.scores[room.dueling_players[0].name_vpass] = 0
room.scores[room.dueling_players[1].name_vpass] = 0
room.kicked = true
room.send_replays()
room.process.kill()
room.delete()
response.writeHead(200)
if kick_room_found
response.end(addCallback(u.query.callback, "['kick ok', '" + u.query.kick + "']"))
else
response.end(addCallback(u.query.callback, "['room not found', '" + u.query.kick + "']"))
ROOM_kick(u.query.kick, (err, found)->
response.writeHead(200)
if err
response.end(addCallback(u.query.callback, "['kick fail', '" + u.query.kick + "']"))
else if found
response.end(addCallback(u.query.callback, "['kick ok', '" + u.query.kick + "']"))
else
response.end(addCallback(u.query.callback, "['room not found', '" + u.query.kick + "']"))
)
else if u.query.death
if !auth.auth(u.query.username, u.query.pass, "start_death", "start_death")
response.writeHead(200)
response.end(addCallback(u.query.callback, "['密码错误', 0]"))
return
rooms = ROOM_all.filter((room)->
return room and (u.query.death == "all" or u.query.death == room.process_pid.toString() or u.query.death == room.name)
)
death_room_found = false
for room in ROOM_all when room and (u.query.death == "all" or u.query.death == room.process_pid.toString() or u.query.death == room.name)
_async.each(rooms, (room, done)->
if room.start_death()
death_room_found = true
response.writeHead(200)
if death_room_found
response.end(addCallback(u.query.callback, "['death ok', '" + u.query.death + "']"))
else
response.end(addCallback(u.query.callback, "['room not found', '" + u.query.death + "']"))
done()
, () ->
response.writeHead(200)
if death_room_found
response.end(addCallback(u.query.callback, "['death ok', '" + u.query.death + "']"))
else
response.end(addCallback(u.query.callback, "['room not found', '" + u.query.death + "']"))
)
else if u.query.deathcancel
if !auth.auth(u.query.username, u.query.pass, "start_death", "cancel_death")
response.writeHead(200)
response.end(addCallback(u.query.callback, "['密码错误', 0]"))
return
rooms = ROOM_all.filter((room)->
return room and (u.query.deathcancel == "all" or u.query.deathcancel == room.process_pid.toString() or u.query.deathcancel == room.name)
)
death_room_found = false
for room in ROOM_all when room and (u.query.deathcancel == "all" or u.query.deathcancel == room.process_pid.toString() or u.query.deathcancel == room.name)
_async.each(rooms, (room, done)->
if room.cancel_death()
death_room_found = true
response.writeHead(200)
if death_room_found
response.end(addCallback(u.query.callback, "['death cancel ok', '" + u.query.deathcancel + "']"))
else
response.end(addCallback(u.query.callback, "['room not found', '" + u.query.deathcancel + "']"))
done()
, () ->
response.writeHead(200)
if death_room_found
response.end(addCallback(u.query.callback, "['death cancel ok', '" + u.query.deathcancel + "']"))
else
response.end(addCallback(u.query.callback, "['room not found', '" + u.query.deathcancel + "']"))
)
else if u.query.reboot
if !auth.auth(u.query.username, u.query.pass, "stop", "reboot")
response.writeHead(200)
response.end(addCallback(u.query.callback, "['密码错误', 0]"))
return
for room in ROOM_all when room
if room.duel_stage != ygopro.constants.DUEL_STAGE.BEGIN
room.scores[room.dueling_players[0].name_vpass] = 0
room.scores[room.dueling_players[1].name_vpass] = 0
room.kicked = true
room.send_replays()
room.process.kill()
room.delete()
rebooted = true
if windbot_process
windbot_process.kill()
response.writeHead(200)
response.end(addCallback(u.query.callback, "['reboot ok', '" + u.query.reboot + "']"))
throw "rebooted"
ROOM_kick("all", (err, found)->
global.rebooted = true
if windbot_process
windbot_process.kill()
response.writeHead(200)
response.end(addCallback(u.query.callback, "['reboot ok', '" + u.query.reboot + "']"))
process.exit()
)
else
response.writeHead(400)
......
// Generated by CoffeeScript 1.12.7
(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_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, rebooted, 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;
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');
......@@ -130,11 +130,18 @@
}
}
setting_save = global.setting_save = function(settings) {
fs.writeFileSync(settings.file, JSON.stringify(settings, null, 2));
setting_save = global.setting_save = function(settings, callback) {
if (!callback) {
callback = function(err) {
if (err) {
return log.warn("setting save fail", err.toString());
}
};
}
fs.writeFile(settings.file, JSON.stringify(settings, null, 2), callback);
};
setting_change = global.setting_change = function(settings, path, val) {
setting_change = global.setting_change = function(settings, path, val, callback) {
var key, target;
if (_.isString(val)) {
log.info("setting changed", path, val);
......@@ -151,7 +158,7 @@
key = path.shift();
target[key] = val;
}
setting_save(settings);
setting_save(settings, callback);
};
default_config = loadJSON('./data/default_config.json');
......@@ -527,29 +534,28 @@
ROOM_bad_ip = global.ROOM_bad_ip = {};
ban_user = global.ban_user = function(name) {
var bad_ip, len2, len3, m, n, player, ref2, room;
ban_user = global.ban_user = function(name, callback) {
var bad_ip;
settings.ban.banned_user.push(name);
setting_save(settings);
bad_ip = 0;
for (m = 0, len2 = ROOM_all.length; m < len2; m++) {
room = ROOM_all[m];
if (room && room.established) {
ref2 = room.players;
for (n = 0, len3 = ref2.length; n < len3; n++) {
player = ref2[n];
if (player && (player.name === name || player.ip === bad_ip)) {
bad_ip = 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);
CLIENT_send_replays(player, room);
CLIENT_kick(player);
continue;
}
}
}
}
bad_ip = [];
_async.each(ROOM_all.filter(function(room) {
return room && room.established;
}), function(room, done) {
return _async.each(["players", "watchers"], function(player_type, _done) {
return _async.each(room[player_type].filter(function(player) {
return player && (player.name === name || bad_ip.indexOf(player.ip) !== -1);
}), function(player, __done) {
bad_ip = 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);
CLIENT_send_replays(player, room);
CLIENT_kick(player);
return __done();
}, _done);
}, done);
}, callback);
};
ROOM_ban_player = global.ROOM_ban_player = function(name, ip, reason, countadd) {
......@@ -585,6 +591,29 @@
}
};
ROOM_kick = function(name, callback) {
var rooms;
rooms = ROOM_all.filter(function(room) {
return room && room.established && (name === "all" || name === room.process_pid.toString() || name === room.name);
});
if (!rooms.length) {
callback(null, false);
}
return _async.each(rooms, function(room, done) {
if (room.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN) {
room.scores[room.dueling_players[0].name_vpass] = 0;
room.scores[room.dueling_players[1].name_vpass] = 0;
}
room.kicked = true;
room.send_replays();
room.process.kill();
room["delete"]();
done();
}, function(err) {
callback(null, true);
});
};
ROOM_player_win = global.ROOM_player_win = function(name) {
if (!ROOM_players_scores[name]) {
ROOM_players_scores[name] = {
......@@ -2940,7 +2969,7 @@
}
});
load_dialogues = global.load_dialogues = function() {
load_dialogues = global.load_dialogues = function(callback) {
request({
url: settings.modules.dialogues.get,
json: true
......@@ -2953,6 +2982,9 @@
setting_change(dialogues, "dialogues", body);
log.info("dialogues loaded", _.size(dialogues.dialogues));
}
if (callback) {
callback(error, body);
}
});
};
......@@ -3567,7 +3599,7 @@
}
};
load_tips = global.load_tips = function() {
load_tips = global.load_tips = function(callback) {
request({
url: settings.modules.tips.get,
json: true
......@@ -3580,6 +3612,9 @@
setting_change(tips, "tips", body);
log.info("tips loaded", tips.tips.length);
}
if (callback) {
callback(error, body);
}
});
};
......@@ -4504,14 +4539,14 @@
});
windbot_process.on('error', function(err) {
log.warn('WindBot ERROR', err);
if (windbot_looplimit < 1000 && !rebooted) {
if (windbot_looplimit < 1000 && !global.rebooted) {
windbot_looplimit++;
spawn_windbot();
}
});
windbot_process.on('exit', function(code) {
log.warn('WindBot EXIT', code);
if (windbot_looplimit < 1000 && !rebooted) {
if (windbot_looplimit < 1000 && !global.rebooted) {
windbot_looplimit++;
spawn_windbot();
}
......@@ -4530,7 +4565,7 @@
spawn_windbot();
}
rebooted = false;
global.rebooted = false;
if (settings.modules.http) {
addCallback = function(callback, text) {
......@@ -4540,7 +4575,7 @@
return callback + "( " + text + " );";
};
requestListener = function(request, response) {
var archive_args, archive_name, archive_process, check, death_room_found, duellog, error, filename, getpath, kick_room_found, len2, len3, len4, len5, len6, len7, m, n, o, p, parseQueryString, pass_validated, player, q, r, ref2, replay, room, roomsjson, u;
var archive_args, archive_name, archive_process, check, death_room_found, duellog, error, filename, getpath, len2, len3, m, n, parseQueryString, pass_validated, player, ref2, replay, room, rooms, roomsjson, u;
parseQueryString = true;
u = url.parse(request.url, parseQueryString);
if (u.pathname === '/api/getrooms') {
......@@ -4738,18 +4773,28 @@
if (u.query.stop === 'false') {
u.query.stop = false;
}
setting_change(settings, 'modules:stop', u.query.stop);
response.writeHead(200);
response.end(addCallback(u.query.callback, "['stop ok', '" + u.query.stop + "']"));
setting_change(settings, 'modules:stop', u.query.stop, function(err) {
response.writeHead(200);
if (err) {
return response.end(addCallback(u.query.callback, "['stop fail', '" + u.query.stop + "']"));
} else {
return response.end(addCallback(u.query.callback, "['stop ok', '" + u.query.stop + "']"));
}
});
} else if (u.query.welcome) {
if (!auth.auth(u.query.username, u.query.pass, "change_settings", "change_welcome")) {
response.writeHead(200);
response.end(addCallback(u.query.callback, "['密码错误', 0]"));
return;
}
setting_change(settings, 'modules:welcome', u.query.welcome);
response.writeHead(200);
response.end(addCallback(u.query.callback, "['welcome ok', '" + u.query.welcome + "']"));
setting_change(settings, 'modules:welcome', function(err) {
response.writeHead(200);
if (err) {
return response.end(addCallback(u.query.callback, "['welcome fail', '" + u.query.welcome + "']"));
} else {
return response.end(addCallback(u.query.callback, "['welcome ok', '" + u.query.welcome + "']"));
}
});
} else if (u.query.getwelcome) {
if (!auth.auth(u.query.username, u.query.pass, "change_settings", "get_welcome")) {
response.writeHead(200);
......@@ -4764,124 +4809,119 @@
response.end(addCallback(u.query.callback, "['密码错误', 0]"));
return;
}
load_tips();
response.writeHead(200);
response.end(addCallback(u.query.callback, "['loading tip', '" + settings.modules.tips.get + "']"));
load_tips(function(err) {
response.writeHead(200);
if (err) {
return response.end(addCallback(u.query.callback, "['tip fail', '" + u.query.loadtips + "']"));
} else {
return response.end(addCallback(u.query.callback, "['tip ok', '" + u.query.loadtips + "']"));
}
});
} else if (u.query.loaddialogues) {
if (!auth.auth(u.query.username, u.query.pass, "change_settings", "change_dialogues")) {
response.writeHead(200);
response.end(addCallback(u.query.callback, "['密码错误', 0]"));
return;
}
load_dialogues();
response.writeHead(200);
response.end(addCallback(u.query.callback, "['loading dialogues', '" + settings.modules.dialogues.get + "']"));
load_dialogues(function(err) {
response.writeHead(200);
if (err) {
return response.end(addCallback(u.query.callback, "['dialogues fail', '" + u.query.loaddialogues + "']"));
} else {
return response.end(addCallback(u.query.callback, "['dialogues ok', '" + u.query.loaddialogues + "']"));
}
});
} else if (u.query.ban) {
if (!auth.auth(u.query.username, u.query.pass, "ban_user", "ban_user")) {
response.writeHead(200);
response.end(addCallback(u.query.callback, "['密码错误', 0]"));
return;
}
ban_user(u.query.ban);
response.writeHead(200);
response.end(addCallback(u.query.callback, "['ban ok', '" + u.query.ban + "']"));
ban_user(u.query.ban, function(err) {
response.writeHead(200);
if (err) {
return response.end(addCallback(u.query.callback, "['ban fail', '" + u.query.ban + "']"));
} else {
return response.end(addCallback(u.query.callback, "['ban ok', '" + u.query.ban + "']"));
}
});
} else if (u.query.kick) {
if (!auth.auth(u.query.username, u.query.pass, "kick_user", "kick_user")) {
response.writeHead(200);
response.end(addCallback(u.query.callback, "['密码错误', 0]"));
return;
}
kick_room_found = false;
for (o = 0, len4 = ROOM_all.length; o < len4; o++) {
room = ROOM_all[o];
if (!(room && room.established && (u.query.kick === "all" || u.query.kick === room.process_pid.toString() || u.query.kick === room.name))) {
continue;
}
kick_room_found = true;
if (room.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN) {
room.scores[room.dueling_players[0].name_vpass] = 0;
room.scores[room.dueling_players[1].name_vpass] = 0;
ROOM_kick(u.query.kick, function(err, found) {
response.writeHead(200);
if (err) {
return response.end(addCallback(u.query.callback, "['kick fail', '" + u.query.kick + "']"));
} else if (found) {
return response.end(addCallback(u.query.callback, "['kick ok', '" + u.query.kick + "']"));
} else {
return response.end(addCallback(u.query.callback, "['room not found', '" + u.query.kick + "']"));
}
room.kicked = true;
room.send_replays();
room.process.kill();
room["delete"]();
}
response.writeHead(200);
if (kick_room_found) {
response.end(addCallback(u.query.callback, "['kick ok', '" + u.query.kick + "']"));
} else {
response.end(addCallback(u.query.callback, "['room not found', '" + u.query.kick + "']"));
}
});
} else if (u.query.death) {
if (!auth.auth(u.query.username, u.query.pass, "start_death", "start_death")) {
response.writeHead(200);
response.end(addCallback(u.query.callback, "['密码错误', 0]"));
return;
}
rooms = ROOM_all.filter(function(room) {
return room && (u.query.death === "all" || u.query.death === room.process_pid.toString() || u.query.death === room.name);
});
death_room_found = false;
for (p = 0, len5 = ROOM_all.length; p < len5; p++) {
room = ROOM_all[p];
if (room && (u.query.death === "all" || u.query.death === room.process_pid.toString() || u.query.death === room.name)) {
if (room.start_death()) {
death_room_found = true;
}
_async.each(rooms, function(room, done) {
if (room.start_death()) {
death_room_found = true;
}
}
response.writeHead(200);
if (death_room_found) {
response.end(addCallback(u.query.callback, "['death ok', '" + u.query.death + "']"));
} else {
response.end(addCallback(u.query.callback, "['room not found', '" + u.query.death + "']"));
}
return done();
}, function() {
response.writeHead(200);
if (death_room_found) {
return response.end(addCallback(u.query.callback, "['death ok', '" + u.query.death + "']"));
} else {
return response.end(addCallback(u.query.callback, "['room not found', '" + u.query.death + "']"));
}
});
} else if (u.query.deathcancel) {
if (!auth.auth(u.query.username, u.query.pass, "start_death", "cancel_death")) {
response.writeHead(200);
response.end(addCallback(u.query.callback, "['密码错误', 0]"));
return;
}
rooms = ROOM_all.filter(function(room) {
return room && (u.query.deathcancel === "all" || u.query.deathcancel === room.process_pid.toString() || u.query.deathcancel === room.name);
});
death_room_found = false;
for (q = 0, len6 = ROOM_all.length; q < len6; q++) {
room = ROOM_all[q];
if (room && (u.query.deathcancel === "all" || u.query.deathcancel === room.process_pid.toString() || u.query.deathcancel === room.name)) {
if (room.cancel_death()) {
death_room_found = true;
}
_async.each(rooms, function(room, done) {
if (room.cancel_death()) {
death_room_found = true;
}
}
response.writeHead(200);
if (death_room_found) {
response.end(addCallback(u.query.callback, "['death cancel ok', '" + u.query.deathcancel + "']"));
} else {
response.end(addCallback(u.query.callback, "['room not found', '" + u.query.deathcancel + "']"));
}
return done();
}, function() {
response.writeHead(200);
if (death_room_found) {
return response.end(addCallback(u.query.callback, "['death cancel ok', '" + u.query.deathcancel + "']"));
} else {
return response.end(addCallback(u.query.callback, "['room not found', '" + u.query.deathcancel + "']"));
}
});
} else if (u.query.reboot) {
if (!auth.auth(u.query.username, u.query.pass, "stop", "reboot")) {
response.writeHead(200);
response.end(addCallback(u.query.callback, "['密码错误', 0]"));
return;
}
for (r = 0, len7 = ROOM_all.length; r < len7; r++) {
room = ROOM_all[r];
if (!(room)) {
continue;
}
if (room.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN) {
room.scores[room.dueling_players[0].name_vpass] = 0;
room.scores[room.dueling_players[1].name_vpass] = 0;
ROOM_kick("all", function(err, found) {
global.rebooted = true;
if (windbot_process) {
windbot_process.kill();
}
room.kicked = true;
room.send_replays();
room.process.kill();
room["delete"]();
}
rebooted = true;
if (windbot_process) {
windbot_process.kill();
}
response.writeHead(200);
response.end(addCallback(u.query.callback, "['reboot ok', '" + u.query.reboot + "']"));
throw "rebooted";
response.writeHead(200);
response.end(addCallback(u.query.callback, "['reboot ok', '" + u.query.reboot + "']"));
return process.exit();
});
} else {
response.writeHead(400);
response.end();
......
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