Commit b99743ad authored by nanahira's avatar nanahira

add reboot

parent 22894ab5
...@@ -3348,6 +3348,7 @@ setInterval ()-> ...@@ -3348,6 +3348,7 @@ setInterval ()->
# spawn windbot # spawn windbot
windbot_looplimit = 0 windbot_looplimit = 0
windbot_process = null
spawn_windbot = () -> spawn_windbot = () ->
if /^win/.test(process.platform) if /^win/.test(process.platform)
...@@ -3361,13 +3362,13 @@ spawn_windbot = () -> ...@@ -3361,13 +3362,13 @@ spawn_windbot = () ->
windbot_process = spawn windbot_bin, windbot_parameters, {cwd: 'windbot'} windbot_process = spawn windbot_bin, windbot_parameters, {cwd: 'windbot'}
windbot_process.on 'error', (err)-> windbot_process.on 'error', (err)->
log.warn 'WindBot ERROR', err log.warn 'WindBot ERROR', err
if windbot_looplimit < 1000 if windbot_looplimit < 1000 and !rebooted
windbot_looplimit++ windbot_looplimit++
spawn_windbot() spawn_windbot()
return return
windbot_process.on 'exit', (code)-> windbot_process.on 'exit', (code)->
log.warn 'WindBot EXIT', code log.warn 'WindBot EXIT', code
if windbot_looplimit < 1000 if windbot_looplimit < 1000 and !rebooted
windbot_looplimit++ windbot_looplimit++
spawn_windbot() spawn_windbot()
return return
...@@ -3384,6 +3385,7 @@ spawn_windbot = () -> ...@@ -3384,6 +3385,7 @@ spawn_windbot = () ->
if settings.modules.windbot.enabled and settings.modules.windbot.spawn if settings.modules.windbot.enabled and settings.modules.windbot.spawn
spawn_windbot() spawn_windbot()
rebooted = false
#http #http
if settings.modules.http if settings.modules.http
...@@ -3633,6 +3635,26 @@ if settings.modules.http ...@@ -3633,6 +3635,26 @@ if settings.modules.http
else else
response.end(addCallback(u.query.callback, "['room not found', '" + u.query.deathcancel + "']")) 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.started
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"
else else
response.writeHead(400) response.writeHead(400)
response.end() response.end()
......
// Generated by CoffeeScript 1.12.7 // Generated by CoffeeScript 1.12.7
(function() { (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_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, SOCKET_flush_data, _, addCallback, auth, badwords, ban_user, bunyan, challonge, challonge_cache, challonge_module_name, challonge_queue_callbacks, chat_color, config, cppversion, crypto, date, default_config, default_data, dialogues, disconnect_list, 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, lflists, list, loadJSON, load_dialogues, load_tips, log, long_resolve_cards, memory_usage, merge, moment, net, oldbadwords, oldconfig, olddialogues, oldduellog, oldtips, options, os, path, pgClient, pg_client, pg_query, 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, 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_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, SOCKET_flush_data, _, addCallback, auth, badwords, ban_user, bunyan, challonge, challonge_cache, challonge_module_name, challonge_queue_callbacks, chat_color, config, cppversion, crypto, date, default_config, default_data, dialogues, disconnect_list, 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, lflists, list, loadJSON, load_dialogues, load_tips, log, long_resolve_cards, memory_usage, merge, moment, net, oldbadwords, oldconfig, olddialogues, oldduellog, oldtips, options, os, path, pgClient, pg_client, pg_query, 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;
net = require('net'); net = require('net');
...@@ -4318,8 +4318,10 @@ ...@@ -4318,8 +4318,10 @@
windbot_looplimit = 0; windbot_looplimit = 0;
windbot_process = null;
spawn_windbot = function() { spawn_windbot = function() {
var windbot_bin, windbot_parameters, windbot_process; var windbot_bin, windbot_parameters;
if (/^win/.test(process.platform)) { if (/^win/.test(process.platform)) {
windbot_bin = 'WindBot.exe'; windbot_bin = 'WindBot.exe';
windbot_parameters = []; windbot_parameters = [];
...@@ -4334,14 +4336,14 @@ ...@@ -4334,14 +4336,14 @@
}); });
windbot_process.on('error', function(err) { windbot_process.on('error', function(err) {
log.warn('WindBot ERROR', err); log.warn('WindBot ERROR', err);
if (windbot_looplimit < 1000) { if (windbot_looplimit < 1000 && !rebooted) {
windbot_looplimit++; windbot_looplimit++;
spawn_windbot(); spawn_windbot();
} }
}); });
windbot_process.on('exit', function(code) { windbot_process.on('exit', function(code) {
log.warn('WindBot EXIT', code); log.warn('WindBot EXIT', code);
if (windbot_looplimit < 1000) { if (windbot_looplimit < 1000 && !rebooted) {
windbot_looplimit++; windbot_looplimit++;
spawn_windbot(); spawn_windbot();
} }
...@@ -4360,6 +4362,8 @@ ...@@ -4360,6 +4362,8 @@
spawn_windbot(); spawn_windbot();
} }
rebooted = false;
if (settings.modules.http) { if (settings.modules.http) {
addCallback = function(callback, text) { addCallback = function(callback, text) {
if (!callback) { if (!callback) {
...@@ -4368,7 +4372,7 @@ ...@@ -4368,7 +4372,7 @@
return callback + "( " + text + " );"; return callback + "( " + text + " );";
}; };
requestListener = function(request, response) { 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, m, n, o, p, parseQueryString, pass_validated, player, q, ref2, replay, room, roomsjson, u; 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;
parseQueryString = true; parseQueryString = true;
u = url.parse(request.url, parseQueryString); u = url.parse(request.url, parseQueryString);
if (u.pathname === '/api/getrooms') { if (u.pathname === '/api/getrooms') {
...@@ -4675,6 +4679,33 @@ ...@@ -4675,6 +4679,33 @@
} else { } else {
response.end(addCallback(u.query.callback, "['room not found', '" + u.query.deathcancel + "']")); 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.started) {
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";
} else { } else {
response.writeHead(400); response.writeHead(400);
response.end(); 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