Commit bbbd3f43 authored by nanahira's avatar nanahira

use async for challonge

parent a757af6a
This diff is collapsed.
...@@ -11,19 +11,20 @@ ...@@ -11,19 +11,20 @@
], ],
"author": "zh99998 <zh99998@gmail.com>, mercury233 <me@mercury233.me>, Nanahira <78877@qq.com>", "author": "zh99998 <zh99998@gmail.com>, mercury233 <me@mercury233.me>, Nanahira <78877@qq.com>",
"dependencies": { "dependencies": {
"async": "^3.2.0",
"bunyan": "latest", "bunyan": "latest",
"challonge": "latest",
"deepmerge": "latest", "deepmerge": "latest",
"formidable": "latest",
"geoip-country-lite": "latest",
"load-json-file": "latest", "load-json-file": "latest",
"moment": "latest", "moment": "latest",
"pg": "^6.4.2",
"redis": "latest", "redis": "latest",
"formidable": "latest",
"request": "latest", "request": "latest",
"sqlite3": "latest",
"underscore": "latest", "underscore": "latest",
"underscore.string": "latest", "underscore.string": "latest",
"sqlite3": "latest",
"geoip-country-lite": "latest",
"challonge": "latest",
"pg": "^6.4.2",
"ws": "^1.1.1" "ws": "^1.1.1"
}, },
"license": "AGPL-3.0", "license": "AGPL-3.0",
......
...@@ -10,6 +10,7 @@ exec = require('child_process').exec ...@@ -10,6 +10,7 @@ exec = require('child_process').exec
execFile = require('child_process').execFile execFile = require('child_process').execFile
spawn = require('child_process').spawn spawn = require('child_process').spawn
spawnSync = require('child_process').spawnSync spawnSync = require('child_process').spawnSync
_async = require('async')
# 三方库 # 三方库
_ = global._ = require 'underscore' _ = global._ = require 'underscore'
...@@ -2121,18 +2122,31 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server, datas)-> ...@@ -2121,18 +2122,31 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server, datas)->
else else
ygopro.stoc_send_chat(client, '${loading_user_info}', ygopro.constants.COLORS.BABYBLUE) ygopro.stoc_send_chat(client, '${loading_user_info}', ygopro.constants.COLORS.BABYBLUE)
client.setTimeout(300000) #连接后超时5分钟 client.setTimeout(300000) #连接后超时5分钟
_async.parallel([
(done) ->
challonge.participants._index({ challonge.participants._index({
id: settings.modules.challonge.tournament_id, id: settings.modules.challonge.tournament_id,
callback: (err, data) -> callback: done
})
return
,
(done) ->
challonge.matches._index({
id: settings.modules.challonge.tournament_id,
callback: done
})
return
], (err, datas) ->
if client.closed if client.closed
return return
if err or !data participant_data = datas[0]
if err match_data = datas[1]
if err or !participant_data or !match_data
log.warn("Failed loading Challonge user info", err) log.warn("Failed loading Challonge user info", err)
ygopro.stoc_die(client, '${challonge_match_load_failed}') ygopro.stoc_die(client, '${challonge_match_load_failed}')
return return
found = false found = false
for k,user of data for k,user of participant_data
if user.participant and user.participant.name and deck_name_match(user.participant.name, client.name) if user.participant and user.participant.name and deck_name_match(user.participant.name, client.name)
found = user.participant found = user.participant
break break
...@@ -2140,18 +2154,8 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server, datas)-> ...@@ -2140,18 +2154,8 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server, datas)->
ygopro.stoc_die(client, '${challonge_user_not_found}') ygopro.stoc_die(client, '${challonge_user_not_found}')
return return
client.challonge_info = found client.challonge_info = found
challonge.matches._index({
id: settings.modules.challonge.tournament_id,
callback: (err, data) ->
if client.closed
return
if err or !data
if err
log.warn("Failed loading Challonge match info", err)
ygopro.stoc_die(client, '${challonge_match_load_failed}')
return
found = false found = false
for k,match of data for k,match of match_data
if match and match.match and !match.match.winnerId and match.match.state != "complete" and match.match.player1Id and match.match.player2Id and (match.match.player1Id == client.challonge_info.id or match.match.player2Id == client.challonge_info.id) if match and match.match and !match.match.winnerId and match.match.state != "complete" and match.match.player1Id and match.match.player2Id and (match.match.player1Id == client.challonge_info.id or match.match.player2Id == client.challonge_info.id)
found = match.match found = match.match
break break
...@@ -2193,9 +2197,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server, datas)-> ...@@ -2193,9 +2197,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server, datas)->
client.rid = _.indexOf(ROOM_all, room) client.rid = _.indexOf(ROOM_all, room)
room.connect(client) room.connect(client)
return return
}) )
return
})
else if !client.name or client.name=="" else if !client.name or client.name==""
ygopro.stoc_die(client, "${bad_user_name}") ygopro.stoc_die(client, "${bad_user_name}")
......
// 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_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, _, 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_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;
net = require('net'); net = require('net');
...@@ -24,6 +24,8 @@ ...@@ -24,6 +24,8 @@
spawnSync = require('child_process').spawnSync; spawnSync = require('child_process').spawnSync;
_async = require('async');
_ = global._ = require('underscore'); _ = global._ = require('underscore');
_.str = require('underscore.string'); _.str = require('underscore.string');
...@@ -2668,23 +2670,33 @@ ...@@ -2668,23 +2670,33 @@
} else { } else {
ygopro.stoc_send_chat(client, '${loading_user_info}', ygopro.constants.COLORS.BABYBLUE); ygopro.stoc_send_chat(client, '${loading_user_info}', ygopro.constants.COLORS.BABYBLUE);
client.setTimeout(300000); client.setTimeout(300000);
_async.parallel([
function(done) {
challonge.participants._index({ challonge.participants._index({
id: settings.modules.challonge.tournament_id, id: settings.modules.challonge.tournament_id,
callback: function(err, data) { callback: done
var found, k, user; });
}, function(done) {
challonge.matches._index({
id: settings.modules.challonge.tournament_id,
callback: done
});
}
], function(err, datas) {
var found, k, len3, len4, match, match_data, n, o, participant_data, player, ref3, ref4, user;
if (client.closed) { if (client.closed) {
return; return;
} }
if (err || !data) { participant_data = datas[0];
if (err) { match_data = datas[1];
if (err || !participant_data || !match_data) {
log.warn("Failed loading Challonge user info", err); log.warn("Failed loading Challonge user info", err);
}
ygopro.stoc_die(client, '${challonge_match_load_failed}'); ygopro.stoc_die(client, '${challonge_match_load_failed}');
return; return;
} }
found = false; found = false;
for (k in data) { for (k in participant_data) {
user = data[k]; user = participant_data[k];
if (user.participant && user.participant.name && deck_name_match(user.participant.name, client.name)) { if (user.participant && user.participant.name && deck_name_match(user.participant.name, client.name)) {
found = user.participant; found = user.participant;
break; break;
...@@ -2695,23 +2707,9 @@ ...@@ -2695,23 +2707,9 @@
return; return;
} }
client.challonge_info = found; client.challonge_info = found;
challonge.matches._index({
id: settings.modules.challonge.tournament_id,
callback: function(err, data) {
var len3, len4, match, n, o, player, ref3, ref4;
if (client.closed) {
return;
}
if (err || !data) {
if (err) {
log.warn("Failed loading Challonge match info", err);
}
ygopro.stoc_die(client, '${challonge_match_load_failed}');
return;
}
found = false; found = false;
for (k in data) { for (k in match_data) {
match = data[k]; match = match_data[k];
if (match && match.match && !match.match.winnerId && match.match.state !== "complete" && match.match.player1Id && match.match.player2Id && (match.match.player1Id === client.challonge_info.id || match.match.player2Id === client.challonge_info.id)) { if (match && match.match && !match.match.winnerId && match.match.state !== "complete" && match.match.player1Id && match.match.player2Id && (match.match.player1Id === client.challonge_info.id || match.match.player2Id === client.challonge_info.id)) {
found = match.match; found = match.match;
break; break;
...@@ -2760,9 +2758,6 @@ ...@@ -2760,9 +2758,6 @@
client.rid = _.indexOf(ROOM_all, room); client.rid = _.indexOf(ROOM_all, room);
room.connect(client); room.connect(client);
} }
}
});
}
}); });
} }
} else if (!client.name || client.name === "") { } else if (!client.name || client.name === "") {
......
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