Commit b7acd8c3 authored by nanahira's avatar nanahira

merge

parents 33770246 c4395e62
...@@ -371,6 +371,59 @@ if settings.modules.challonge.enabled ...@@ -371,6 +371,59 @@ if settings.modules.challonge.enabled
challonge = require('challonge').createClient({ challonge = require('challonge').createClient({
apiKey: settings.modules.challonge.api_key apiKey: settings.modules.challonge.api_key
}) })
challonge_cache = []
challonge_queue_callbacks = [[], []]
is_requesting = [false, false]
get_callback = (challonge_type, _callback) ->
return ((err, data) ->
if !err and data
challonge_cache[challonge_type] = data
_callback(err, data)
while challonge_queue_callbacks[challonge_type].length
cur_callback = challonge_queue_callbacks[challonge_type][0]
challonge_queue_callbacks[challonge_type].splice(0, 1)
cur_callback(err, data)
is_requesting[challonge_type] = false
return
)
challonge.participants._index = (_data) ->
if challonge_cache[0]
_data.callback(null, challonge_cache[0])
else if is_requesting[0]
challonge_queue_callbacks[0].push(_data.callback)
else
_data.callback = get_callback(0, _data.callback)
is_requesting[0] = true
challonge.participants.index(_data)
return
challonge.matches._index = (_data) ->
if challonge_cache[1]
_data.callback(null, challonge_cache[1])
else if is_requesting[1]
challonge_queue_callbacks[1].push(_data.callback)
else
_data.callback = get_callback(1, _data.callback)
is_requesting[1] = true
challonge.matches.index(_data)
return
refresh_challonge_cache = () ->
challonge_cache[0] = null
challonge_cache[1] = null
challonge.participants._index({
id: settings.modules.challonge.tournament_id,
callback: (() ->
challonge.matches._index({
id: settings.modules.challonge.tournament_id,
callback: (() ->
return
)
})
return
)
})
return
refresh_challonge_cache()
setInterval(refresh_challonge_cache, 30000)
if settings.modules.vip.enabled if settings.modules.vip.enabled
for k,v of vip_info.cdkeys when v.length == 0 for k,v of vip_info.cdkeys when v.length == 0
...@@ -1071,6 +1124,8 @@ class Room ...@@ -1071,6 +1124,8 @@ class Room
callback: (err, data) -> callback: (err, data) ->
if err if err
log.warn("Errored pushing scores to Challonge.", err) log.warn("Errored pushing scores to Challonge.", err)
else
refresh_challonge_cache()
return return
}) })
if @player_datas.length and settings.modules.cloud_replay.enabled if @player_datas.length and settings.modules.cloud_replay.enabled
...@@ -1758,7 +1813,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)-> ...@@ -1758,7 +1813,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
client.write buffer client.write buffer
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)
challonge.participants.index({ challonge.participants._index({
id: settings.modules.challonge.tournament_id, id: settings.modules.challonge.tournament_id,
callback: (err, data) -> callback: (err, data) ->
if err or !data if err or !data
...@@ -1775,7 +1830,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)-> ...@@ -1775,7 +1830,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
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({ challonge.matches._index({
id: settings.modules.challonge.tournament_id, id: settings.modules.challonge.tournament_id,
callback: (err, data) -> callback: (err, data) ->
if client.closed if client.closed
...@@ -3103,6 +3158,8 @@ ygopro.stoc_follow 'CHANGE_SIDE', false, (buffer, info, client, server)-> ...@@ -3103,6 +3158,8 @@ ygopro.stoc_follow 'CHANGE_SIDE', false, (buffer, info, client, server)->
callback: (err, data) -> callback: (err, data) ->
if err if err
log.warn("Errored pushing scores to Challonge.", err) log.warn("Errored pushing scores to Challonge.", err)
else
refresh_challonge_cache()
return return
}) })
if room.random_type or room.arena if room.random_type or room.arena
......
// Generated by CoffeeScript 1.12.7 // Generated by CoffeeScript 1.12.7
(function() { (function() {
var CLIENT_check_vip, CLIENT_get_absolute_pos, CLIENT_get_authorize_key, CLIENT_get_kick_reconnect_target, CLIENT_get_partner, 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_vip_status, CLIENT_use_cdkey, 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_players_banned, ROOM_players_oppentlist, ROOM_unwelcome, ROOM_validate, Room, SERVER_clear_disconnect, VIP_generate_cdkeys, _, addCallback, badwords, ban_user, bunyan, challonge, chat_color, concat_name, config, cppversion, crypto, date, default_config, default_data, dialogues, disconnect_list, duel_log, e, exec, execFile, fs, geoip, get_memory_usage, http, http_server, https, https_server, import_datas, imported, j, k, l, len, len1, lflists, list, loadJSON, load_dialogues, load_dialogues_custom, load_tips, load_words, log, long_resolve_cards, memory_usage, merge, moment, net, oldbadwords, oldconfig, olddialogues, oldduellog, oldtips, oldwords, options, os, path, pgClient, pg_client, pg_query, redis, redisdb, ref, ref1, ref2, release_disconnect, report_to_big_brother, request, requestListener, roomlist, setting_change, setting_save, settings, spawn, spawnSync, spawn_windbot, tips, url, users_cache, v, vip_info, wait_room_start, wait_room_start_arena, windbot_looplimit, windbots, words, ygopro, zlib; var CLIENT_check_vip, CLIENT_get_absolute_pos, CLIENT_get_authorize_key, CLIENT_get_kick_reconnect_target, CLIENT_get_partner, 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_vip_status, CLIENT_use_cdkey, 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_players_banned, ROOM_players_oppentlist, ROOM_unwelcome, ROOM_validate, Room, SERVER_clear_disconnect, VIP_generate_cdkeys, _, addCallback, badwords, ban_user, bunyan, challonge, challonge_cache, challonge_queue_callbacks, chat_color, concat_name, 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, k, l, len, len1, lflists, list, loadJSON, load_dialogues, load_dialogues_custom, load_tips, load_words, log, long_resolve_cards, memory_usage, merge, moment, net, oldbadwords, oldconfig, olddialogues, oldduellog, oldtips, oldwords, options, os, path, pgClient, pg_client, pg_query, redis, redisdb, ref, ref1, ref2, 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, v, vip_info, wait_room_start, wait_room_start_arena, windbot_looplimit, windbots, words, ygopro, zlib;
net = require('net'); net = require('net');
...@@ -461,6 +461,61 @@ ...@@ -461,6 +461,61 @@
challonge = require('challonge').createClient({ challonge = require('challonge').createClient({
apiKey: settings.modules.challonge.api_key apiKey: settings.modules.challonge.api_key
}); });
challonge_cache = [];
challonge_queue_callbacks = [[], []];
is_requesting = [false, false];
get_callback = function(challonge_type, _callback) {
return (function(err, data) {
var cur_callback;
if (!err && data) {
challonge_cache[challonge_type] = data;
}
_callback(err, data);
while (challonge_queue_callbacks[challonge_type].length) {
cur_callback = challonge_queue_callbacks[challonge_type][0];
challonge_queue_callbacks[challonge_type].splice(0, 1);
cur_callback(err, data);
}
is_requesting[challonge_type] = false;
});
};
challonge.participants._index = function(_data) {
if (challonge_cache[0]) {
_data.callback(null, challonge_cache[0]);
} else if (is_requesting[0]) {
challonge_queue_callbacks[0].push(_data.callback);
} else {
_data.callback = get_callback(0, _data.callback);
is_requesting[0] = true;
challonge.participants.index(_data);
}
};
challonge.matches._index = function(_data) {
if (challonge_cache[1]) {
_data.callback(null, challonge_cache[1]);
} else if (is_requesting[1]) {
challonge_queue_callbacks[1].push(_data.callback);
} else {
_data.callback = get_callback(1, _data.callback);
is_requesting[1] = true;
challonge.matches.index(_data);
}
};
refresh_challonge_cache = function() {
challonge_cache[0] = null;
challonge_cache[1] = null;
challonge.participants._index({
id: settings.modules.challonge.tournament_id,
callback: (function() {
challonge.matches._index({
id: settings.modules.challonge.tournament_id,
callback: (function() {})
});
})
});
};
refresh_challonge_cache();
setInterval(refresh_challonge_cache, 30000);
} }
if (settings.modules.vip.enabled) { if (settings.modules.vip.enabled) {
...@@ -1401,6 +1456,8 @@ ...@@ -1401,6 +1456,8 @@
callback: function(err, data) { callback: function(err, data) {
if (err) { if (err) {
log.warn("Errored pushing scores to Challonge.", err); log.warn("Errored pushing scores to Challonge.", err);
} else {
refresh_challonge_cache();
} }
} }
}); });
...@@ -2189,7 +2246,7 @@ ...@@ -2189,7 +2246,7 @@
} }
} 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);
challonge.participants.index({ challonge.participants._index({
id: settings.modules.challonge.tournament_id, id: settings.modules.challonge.tournament_id,
callback: function(err, data) { callback: function(err, data) {
var found, user; var found, user;
...@@ -2213,7 +2270,7 @@ ...@@ -2213,7 +2270,7 @@
return; return;
} }
client.challonge_info = found; client.challonge_info = found;
challonge.matches.index({ challonge.matches._index({
id: settings.modules.challonge.tournament_id, id: settings.modules.challonge.tournament_id,
callback: function(err, data) { callback: function(err, data) {
var len4, len5, match, o, p, player, ref5, ref6; var len4, len5, match, o, p, player, ref5, ref6;
...@@ -3953,6 +4010,8 @@ ...@@ -3953,6 +4010,8 @@
callback: function(err, data) { callback: function(err, data) {
if (err) { if (err) {
log.warn("Errored pushing scores to Challonge.", err); log.warn("Errored pushing scores to Challonge.", err);
} else {
refresh_challonge_cache();
} }
} }
}); });
......
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