Commit 8b1eeeb0 authored by nanahira's avatar nanahira

use axios to replace request

parent 72c22165
......@@ -174,6 +174,7 @@ settings = {}
tips = null
dialogues = null
badwords = null
chat_color = null
lflists = global.lflists = []
real_windbot_server_ip = null
long_resolve_cards = []
......@@ -182,6 +183,7 @@ athleticChecker = null
users_cache = {}
geoip = null
dataManager = null
windbots = []
disconnect_list = {} # {old_client, old_server, room_id, timeout, deckbuf}
challonge = null
......@@ -336,7 +338,7 @@ init = () ->
await loadLFList('ygopro/lflist.conf')
if settings.modules.windbot.enabled
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
if !settings.modules.windbot.server_ip.includes("127.0.0.1")
dns = require('dns')
......@@ -486,18 +488,19 @@ init = () ->
scores_by_win = _.sortBy(scores_by_lose, (score)-> return score[1].win).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)
}}, (error, response, body)=>
if error
log.warn 'RANDOM SCORE POST ERROR', error
else
if response.statusCode != 204 and response.statusCode != 200
log.warn 'RANDOM SCORE POST FAIL', response.statusCode, response.statusMessage, body
#else
# log.info 'RANDOM SCORE POST OK', response.statusCode, response.statusMessage
return
try
await axios.post(settings.modules.random_duel.post_match_scores, {
headers: { 'content-type': 'application/x-www-form-urlencoded' },
data: qs.stringify({
accesskey: settings.modules.random_duel.post_match_accesskey,
rank: JSON.stringify(scores)
responseType: "json"
})
})
catch e
log.warn 'RANDOM SCORE POST ERROR', e.toString()
return
, 60000)
......@@ -534,7 +537,6 @@ init = () ->
CLIENT_kick(room.waiting_for_player)
else if time_passed >= (settings.modules.random_duel.hang_timeout - 20) and not (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)
return
if true # settings.modules.arena_mode.punish_quit_before_match
for room in ROOM_all when room and room.arena and room.duel_stage == ygopro.constants.DUEL_STAGE.BEGIN and room.get_playing_player().length < 2
......@@ -605,6 +607,8 @@ init = () ->
require(plugin_path)
log.info("Plugin loaded:", plugin_filename)
return
# 获取可用内存
memory_usage = global.memory_usage = 0
get_memory_usage = global.get_memory_usage = ()->
......
// 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, 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_players_scores, ROOM_unwelcome, ROOM_validate, ReplayParser, ResolveData, Room, SERVER_clear_disconnect, SERVER_kick, SOCKET_flush_data, _, _async, addCallback, athleticChecker, auth, axios, badwords, ban_user, bunyan, challonge, challonge_cache, challonge_queue_callbacks, checkFileExists, createDirectoryIfNotExists, crypto, dataManager, deck_name_match, dialogues, disconnect_list, exec, execFile, fs, geoip, getSeedTimet, get_callback, get_memory_usage, http, httpRequestListener, importOldConfig, import_datas, init, is_challonge_requesting, lflists, loadJSON, loadJSONAsync, loadLFList, loadRemoteData, load_dialogues, load_tips, log, long_resolve_cards, memory_usage, merge, moment, net, netRequestHandler, os, path, qs, real_windbot_server_ip, refresh_challonge_cache, release_disconnect, replaced_index, report_to_big_brother, request, roomlist, 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, 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, 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_players_scores, ROOM_unwelcome, ROOM_validate, ReplayParser, ResolveData, Room, SERVER_clear_disconnect, SERVER_kick, SOCKET_flush_data, _, _async, addCallback, athleticChecker, auth, axios, badwords, ban_user, bunyan, challonge, challonge_cache, challonge_queue_callbacks, chat_color, checkFileExists, createDirectoryIfNotExists, crypto, dataManager, deck_name_match, dialogues, disconnect_list, exec, execFile, fs, geoip, getSeedTimet, get_callback, get_memory_usage, http, httpRequestListener, importOldConfig, import_datas, init, is_challonge_requesting, lflists, loadJSON, loadJSONAsync, loadLFList, loadRemoteData, load_dialogues, load_tips, log, long_resolve_cards, memory_usage, merge, moment, net, netRequestHandler, os, path, qs, real_windbot_server_ip, refresh_challonge_cache, release_disconnect, replaced_index, report_to_big_brother, request, roomlist, 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, ygopro, zlib;
net = require('net');
......@@ -202,6 +202,8 @@
badwords = null;
chat_color = null;
lflists = global.lflists = [];
real_windbot_server_ip = null;
......@@ -218,6 +220,8 @@
dataManager = null;
windbots = [];
disconnect_list = {}; // {old_client, old_server, room_id, timeout, deckbuf}
challonge = null;
......@@ -289,7 +293,7 @@
};
init = async function() {
var AthleticChecker, DataManager, challonge_module_name, challonge_type, chat_color, config, cppversion, defaultConfig, default_data, 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, results, windbots;
var AthleticChecker, DataManager, challonge_module_name, challonge_type, config, cppversion, defaultConfig, default_data, 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;
await createDirectoryIfNotExists("./config");
await importOldConfig();
defaultConfig = (await loadJSONAsync('./data/default_config.json'));
......@@ -434,7 +438,7 @@
await loadLFList('ygopro/expansions/lflist.conf');
await loadLFList('ygopro/lflist.conf');
if (settings.modules.windbot.enabled) {
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;
if (!settings.modules.windbot.server_ip.includes("127.0.0.1")) {
dns = require('dns');
......@@ -611,7 +615,7 @@
load_dialogues();
}
if (settings.modules.random_duel.post_match_scores) {
setInterval(function() {
setInterval(async function() {
var scores, scores_by_lose, scores_by_win, scores_pair;
scores_pair = _.pairs(ROOM_players_scores);
scores_by_lose = _.sortBy(scores_pair, function(score) {
......@@ -621,24 +625,22 @@
return score[1].win;
}).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)
}
}, (error, response, body) => {
if (error) {
log.warn('RANDOM SCORE POST ERROR', error);
} else {
if (response.statusCode !== 204 && response.statusCode !== 200) {
log.warn('RANDOM SCORE POST FAIL', response.statusCode, response.statusMessage, body);
}
}
});
//else
// log.info 'RANDOM SCORE POST OK', response.statusCode, response.statusMessage
try {
//log.info scores
await axios.post(settings.modules.random_duel.post_match_scores, {
headers: {
'content-type': 'application/x-www-form-urlencoded'
},
data: qs.stringify({
accesskey: settings.modules.random_duel.post_match_accesskey,
rank: JSON.stringify(scores),
responseType: "json"
})
});
} catch (error1) {
e = error1;
log.warn('RANDOM SCORE POST ERROR', e.toString());
}
}, 60000);
}
if (settings.modules.random_duel.enabled) {
......@@ -687,7 +689,6 @@
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);
}
}
return;
if (true) { // settings.modules.arena_mode.punish_quit_before_match
for (m = 0, len2 = ROOM_all.length; m < len2; m++) {
room = ROOM_all[m];
......@@ -768,14 +769,12 @@
await createDirectoryIfNotExists(path);
}
plugin_list = (await fs.promises.readdir("./plugins"));
results = [];
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);
results.push(log.info("Plugin loaded:", plugin_filename));
log.info("Plugin loaded:", plugin_filename);
}
return results;
};
// 获取可用内存
......
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