Commit 91adc9a3 authored by nanahira's avatar nanahira

Merge branch 'mc'

parents 9af039eb 2ec6ae0d
......@@ -123,6 +123,8 @@
"challonge": {
"enabled": false,
"post_detailed_score": true,
"post_score_midduel": true,
"cache_ttl": 60000,
"api_key": "123",
"tournament_id": "456"
},
......
......@@ -375,12 +375,13 @@ if settings.modules.challonge.enabled
challonge = require('challonge').createClient({
apiKey: settings.modules.challonge.api_key
})
challonge_cache = []
if settings.modules.challonge.cache_ttl
challonge_cache = []
challonge_queue_callbacks = [[], []]
is_requesting = [false, false]
get_callback = (challonge_type, _callback) ->
return ((err, data) ->
if !err and data
if settings.modules.challonge.cache_ttl and !err and data
challonge_cache[challonge_type] = data
_callback(err, data)
while challonge_queue_callbacks[challonge_type].length
......@@ -390,7 +391,7 @@ if settings.modules.challonge.enabled
return
)
challonge.participants._index = (_data) ->
if challonge_cache[0]
if settings.modules.challonge.cache_ttl and challonge_cache[0]
_data.callback(null, challonge_cache[0])
else if is_requesting[0]
challonge_queue_callbacks[0].push(_data.callback)
......@@ -400,7 +401,7 @@ if settings.modules.challonge.enabled
challonge.participants.index(_data)
return
challonge.matches._index = (_data) ->
if challonge_cache[1]
if settings.modules.challonge.cache_ttl and challonge_cache[1]
_data.callback(null, challonge_cache[1])
else if is_requesting[1]
challonge_queue_callbacks[1].push(_data.callback)
......@@ -410,8 +411,9 @@ if settings.modules.challonge.enabled
challonge.matches.index(_data)
return
refresh_challonge_cache = () ->
challonge_cache[0] = null
challonge_cache[1] = null
if settings.modules.challonge.cache_ttl
challonge_cache[0] = null
challonge_cache[1] = null
return
refresh_challonge_cache()
# challonge.participants._index({
......@@ -426,7 +428,8 @@ if settings.modules.challonge.enabled
# return
# )
# })
setInterval(refresh_challonge_cache, 60000)
if settings.modules.challonge.cache_ttl
setInterval(refresh_challonge_cache, settings.modules.challonge.cache_ttl)
if settings.modules.vip.enabled
for k,v of vip_info.cdkeys when v.length == 0
......@@ -3177,7 +3180,7 @@ ygopro.stoc_follow 'CHANGE_SIDE', false, (buffer, info, client, server)->
ygopro.stoc_send_chat(client, "${side_remain_part1}#{client.side_tcount}${side_remain_part2}", ygopro.constants.COLORS.BABYBLUE)
, 60000
client.side_interval = sinterval
if settings.modules.challonge.enabled and client.pos == 0
if settings.modules.challonge.enabled and settings.modules.challonge.post_score_midduel and client.pos == 0
temp_log = JSON.parse(JSON.stringify(room.challonge_duel_log))
delete temp_log.winnerId
challonge.matches.update({
......
......@@ -466,13 +466,15 @@
challonge = require('challonge').createClient({
apiKey: settings.modules.challonge.api_key
});
challonge_cache = [];
if (settings.modules.challonge.cache_ttl) {
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) {
if (settings.modules.challonge.cache_ttl && !err && data) {
challonge_cache[challonge_type] = data;
}
_callback(err, data);
......@@ -484,7 +486,7 @@
});
};
challonge.participants._index = function(_data) {
if (challonge_cache[0]) {
if (settings.modules.challonge.cache_ttl && challonge_cache[0]) {
_data.callback(null, challonge_cache[0]);
} else if (is_requesting[0]) {
challonge_queue_callbacks[0].push(_data.callback);
......@@ -495,7 +497,7 @@
}
};
challonge.matches._index = function(_data) {
if (challonge_cache[1]) {
if (settings.modules.challonge.cache_ttl && challonge_cache[1]) {
_data.callback(null, challonge_cache[1]);
} else if (is_requesting[1]) {
challonge_queue_callbacks[1].push(_data.callback);
......@@ -506,11 +508,15 @@
}
};
refresh_challonge_cache = function() {
challonge_cache[0] = null;
challonge_cache[1] = null;
if (settings.modules.challonge.cache_ttl) {
challonge_cache[0] = null;
challonge_cache[1] = null;
}
};
refresh_challonge_cache();
setInterval(refresh_challonge_cache, 60000);
if (settings.modules.challonge.cache_ttl) {
setInterval(refresh_challonge_cache, settings.modules.challonge.cache_ttl);
}
}
if (settings.modules.vip.enabled) {
......@@ -4036,7 +4042,7 @@
}, 60000);
client.side_interval = sinterval;
}
if (settings.modules.challonge.enabled && client.pos === 0) {
if (settings.modules.challonge.enabled && settings.modules.challonge.post_score_midduel && client.pos === 0) {
temp_log = JSON.parse(JSON.stringify(room.challonge_duel_log));
delete temp_log.winnerId;
challonge.matches.update({
......
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