Commit 9ebbb587 authored by nanahira's avatar nanahira

tempg

parent 9387f727
...@@ -271,6 +271,45 @@ if settings.modules.challonge.enabled ...@@ -271,6 +271,45 @@ 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
setInterval(
challonge_cache[0] = null
challonge_cache[1] = null
, 10000)
# 获取可用内存 # 获取可用内存
memory_usage = 0 memory_usage = 0
...@@ -947,6 +986,8 @@ class Room ...@@ -947,6 +986,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
challonge_cache[1] = null
return return
}) })
if @player_datas.length and settings.modules.cloud_replay.enabled if @player_datas.length and settings.modules.cloud_replay.enabled
...@@ -1631,7 +1672,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)-> ...@@ -1631,7 +1672,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
...@@ -1648,7 +1689,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)-> ...@@ -1648,7 +1689,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
...@@ -2816,6 +2857,8 @@ ygopro.stoc_follow 'CHANGE_SIDE', false, (buffer, info, client, server)-> ...@@ -2816,6 +2857,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
challonge_cache[1] = null
return return
}) })
if room.random_type or room.arena if room.random_type or room.arena
......
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