Commit 09131e88 authored by nanahira's avatar nanahira

rework challonge

parent bb5f09a8
Pipeline #13284 passed with stages
in 14 minutes and 46 seconds
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Challonge = void 0;
const axios_1 = __importDefault(require("axios"));
const bunyan_1 = require("bunyan");
const moment_1 = __importDefault(require("moment"));
const p_queue_1 = __importDefault(require("p-queue"));
class Challonge {
config;
constructor(config) {
this.config = config;
}
queue = new p_queue_1.default({ concurrency: 1 });
log = (0, bunyan_1.createLogger)({ name: 'challonge' });
previous;
previousTime;
async getTournamentProcess(noCache = false) {
if (!noCache && this.previous && this.previousTime.isAfter((0, moment_1.default)().subtract(this.config.cache_ttl, 'ms'))) {
return this.previous;
}
try {
const { data: { tournament } } = await axios_1.default.get(`https://api.challonge.com/v1/tournaments/${this.config.tournament_id}.json`, {
params: {
api_key: this.config.api_key,
include_participants: 1,
include_matches: 1,
},
});
this.previous = tournament;
this.previousTime = (0, moment_1.default)();
return tournament;
}
catch (e) {
this.log.error(`Failed to get tournament ${this.config.tournament_id}`, e);
return;
}
}
async getTournament(noCache = false) {
if (noCache) {
return this.getTournamentProcess(noCache);
}
return this.queue.add(() => this.getTournamentProcess());
}
async putScore(matchId, match, retried = 0) {
try {
await axios_1.default.put(`https://api.challonge.com/v1/tournaments/${this.config.tournament_id}/matches/${matchId}.json`, {
api_key: this.config.api_key,
match: match,
});
this.previous = undefined;
this.previousTime = undefined;
return true;
}
catch (e) {
this.log.error(`Failed to put score for match ${matchId}`, e);
if (retried < 5) {
this.log.info(`Retrying match ${matchId}`);
return this.putScore(matchId, match, retried + 1);
}
else {
this.log.error(`Failed to put score for match ${matchId} after 5 retries`);
return false;
}
}
}
}
exports.Challonge = Challonge;
//# sourceMappingURL=challonge.js.map
\ No newline at end of file
import axios from 'axios';
import { createLogger } from 'bunyan';
import moment, { Moment } from 'moment';
import PQueue from 'p-queue';
export interface Match {
attachment_count?: any;
created_at: string;
group_id?: any;
has_attachment: boolean;
id: number;
identifier: string;
location?: any;
loser_id?: any;
player1_id: number;
player1_is_prereq_match_loser: boolean;
player1_prereq_match_id?: any;
player1_votes?: any;
player2_id: number;
player2_is_prereq_match_loser: boolean;
player2_prereq_match_id?: any;
player2_votes?: any;
round: number;
scheduled_time?: any;
started_at: string;
state: string;
tournament_id: number;
underway_at?: any;
updated_at: string;
winner_id?: any;
prerequisite_match_ids_csv: string;
scores_csv: string;
}
export interface MatchWrapper {
match: Match;
}
export interface Participant {
active: boolean;
checked_in_at?: any;
created_at: string;
final_rank?: any;
group_id?: any;
icon?: any;
id: number;
invitation_id?: any;
invite_email?: any;
misc?: any;
name: string;
on_waiting_list: boolean;
seed: number;
tournament_id: number;
updated_at: string;
challonge_username?: any;
challonge_email_address_verified?: any;
removable: boolean;
participatable_or_invitation_attached: boolean;
confirm_remove: boolean;
invitation_pending: boolean;
display_name_with_invitation_email_address: string;
email_hash?: any;
username?: any;
attached_participatable_portrait_url?: any;
can_check_in: boolean;
checked_in: boolean;
reactivatable: boolean;
}
export interface ParticipantWrapper {
participant: Participant;
}
export interface Tournament {
accept_attachments: boolean;
allow_participant_match_reporting: boolean;
anonymous_voting: boolean;
category?: any;
check_in_duration?: any;
completed_at?: any;
created_at: string;
created_by_api: boolean;
credit_capped: boolean;
description: string;
game_id: number;
group_stages_enabled: boolean;
hide_forum: boolean;
hide_seeds: boolean;
hold_third_place_match: boolean;
id: number;
max_predictions_per_user: number;
name: string;
notify_users_when_matches_open: boolean;
notify_users_when_the_tournament_ends: boolean;
open_signup: boolean;
participants_count: number;
prediction_method: number;
predictions_opened_at?: any;
private: boolean;
progress_meter: number;
pts_for_bye: string;
pts_for_game_tie: string;
pts_for_game_win: string;
pts_for_match_tie: string;
pts_for_match_win: string;
quick_advance: boolean;
ranked_by: string;
require_score_agreement: boolean;
rr_pts_for_game_tie: string;
rr_pts_for_game_win: string;
rr_pts_for_match_tie: string;
rr_pts_for_match_win: string;
sequential_pairings: boolean;
show_rounds: boolean;
signup_cap?: any;
start_at?: any;
started_at: string;
started_checking_in_at?: any;
state: string;
swiss_rounds: number;
teams: boolean;
tie_breaks: string[];
tournament_type: string;
updated_at: string;
url: string;
description_source: string;
subdomain?: any;
full_challonge_url: string;
live_image_url: string;
sign_up_url?: any;
review_before_finalizing: boolean;
accepting_predictions: boolean;
participants_locked: boolean;
game_name: string;
participants_swappable: boolean;
team_convertable: boolean;
group_stages_were_started: boolean;
participants: ParticipantWrapper[];
matches: MatchWrapper[];
}
export interface TournamentWrapper {
tournament: Tournament;
}
export interface MatchPost {
scores_csv: string;
winner_id: number;
}
export interface ChallongeConfig {
api_key: string;
tournament_id: string;
cache_ttl: number;
}
export class Challonge {
constructor(private config: ChallongeConfig) { }
private queue = new PQueue({ concurrency: 1 })
private log = createLogger({ name: 'challonge' });
private previous: Tournament;
private previousTime: Moment;
private async getTournamentProcess(noCache = false) {
if(!noCache && this.previous && this.previousTime.isAfter(moment().subtract(this.config.cache_ttl, 'ms'))) {
return this.previous;
}
try {
const { data: { tournament } } = await axios.get<TournamentWrapper>(
`https://api.challonge.com/v1/tournaments/${this.config.tournament_id}.json`,
{
params: {
api_key: this.config.api_key,
include_participants: 1,
include_matches: 1,
},
},
);
this.previous = tournament;
this.previousTime = moment();
return tournament;
} catch (e) {
this.log.error(`Failed to get tournament ${this.config.tournament_id}`, e);
return;
}
}
async getTournament(noCache = false) {
if (noCache) {
return this.getTournamentProcess(noCache);
}
return this.queue.add(() => this.getTournamentProcess())
}
async putScore(matchId: number, match: MatchPost, retried = 0) {
try {
await axios.put(
`https://api.challonge.com/v1/tournaments/${this.config.tournament_id}/matches/${matchId}.json`,
{
api_key: this.config.api_key,
match: match,
},
);
this.previous = undefined;
this.previousTime = undefined;
return true;
} catch (e) {
this.log.error(`Failed to put score for match ${matchId}`, e);
if (retried < 5) {
this.log.info(`Retrying match ${matchId}`);
return this.putScore(matchId, match, retried + 1);
} else {
this.log.error(`Failed to put score for match ${matchId} after 5 retries`);
return false;
}
}
}
}
......@@ -140,11 +140,8 @@
"post_score_midduel": true,
"cache_ttl": 60000,
"no_match_mode": false,
"options": {
"apiKey": "123"
},
"tournament_id": "456",
"use_custom_module": false
"api_key": "123",
"tournament_id": "456"
},
"deck_log": {
"enabled": false,
......
......@@ -12,7 +12,6 @@
"async": "^3.2.0",
"axios": "^0.19.2",
"bunyan": "^1.8.14",
"challonge": "^2.2.0",
"deepmerge": "^4.2.2",
"formidable": "^1.2.6",
"geoip-country-lite": "^1.0.0",
......@@ -22,6 +21,7 @@
"moment": "^2.29.1",
"mysql": "^2.18.1",
"node-os-utils": "^1.3.2",
"p-queue": "6.6.2",
"pg": "^6.4.2",
"q": "^1.5.1",
"querystring": "^0.2.0",
......@@ -380,11 +380,6 @@
"node": ">=4"
}
},
"node_modules/challonge": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/challonge/-/challonge-2.2.0.tgz",
"integrity": "sha512-7OhS4yZiUWCU8CBoadlB5Vb5EMb1mQuEVXkE9P8f5YYCd0LC4z3WhDN5uCx0swdpltZhPStxFY+2ZztWiN696Q=="
},
"node_modules/chownr": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/chownr/-/chownr-1.1.4.tgz",
......@@ -789,6 +784,11 @@
"node": ">=4"
}
},
"node_modules/eventemitter3": {
"version": "4.0.7",
"resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-4.0.7.tgz",
"integrity": "sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw=="
},
"node_modules/extend": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/extend/-/extend-3.0.2.tgz",
......@@ -1785,6 +1785,14 @@
"node": "*"
}
},
"node_modules/p-finally": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/p-finally/-/p-finally-1.0.0.tgz",
"integrity": "sha1-P7z7FbiZpEEjs0ttzBi3JDNqLK4=",
"engines": {
"node": ">=4"
}
},
"node_modules/p-limit": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.3.0.tgz",
......@@ -1810,6 +1818,32 @@
"node": ">=8"
}
},
"node_modules/p-queue": {
"version": "6.6.2",
"resolved": "https://registry.npmjs.org/p-queue/-/p-queue-6.6.2.tgz",
"integrity": "sha512-RwFpb72c/BhQLEXIZ5K2e+AhgNVmIejGlTgiB9MzZ0e93GRvqZ7uSi0dvRF7/XIXDeNkra2fNHBxTyPDGySpjQ==",
"dependencies": {
"eventemitter3": "^4.0.4",
"p-timeout": "^3.2.0"
},
"engines": {
"node": ">=8"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/p-timeout": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/p-timeout/-/p-timeout-3.2.0.tgz",
"integrity": "sha512-rhIwUycgwwKcP9yTOOFK/AKsAopjjCakVqLHePO3CC6Mir1Z99xT+R63jZxAT5lFZLa2inS5h+ZS2GvR99/FBg==",
"dependencies": {
"p-finally": "^1.0.0"
},
"engines": {
"node": ">=8"
}
},
"node_modules/p-try": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz",
......@@ -3299,11 +3333,6 @@
"supports-color": "^5.3.0"
}
},
"challonge": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/challonge/-/challonge-2.2.0.tgz",
"integrity": "sha512-7OhS4yZiUWCU8CBoadlB5Vb5EMb1mQuEVXkE9P8f5YYCd0LC4z3WhDN5uCx0swdpltZhPStxFY+2ZztWiN696Q=="
},
"chownr": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/chownr/-/chownr-1.1.4.tgz",
......@@ -3602,6 +3631,11 @@
"resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz",
"integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A=="
},
"eventemitter3": {
"version": "4.0.7",
"resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-4.0.7.tgz",
"integrity": "sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw=="
},
"extend": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/extend/-/extend-3.0.2.tgz",
......@@ -4406,6 +4440,11 @@
"resolved": "https://registry.npmjs.org/over/-/over-0.0.5.tgz",
"integrity": "sha1-8phS5w/X4l82DgE6jsRMgq7bVwg="
},
"p-finally": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/p-finally/-/p-finally-1.0.0.tgz",
"integrity": "sha1-P7z7FbiZpEEjs0ttzBi3JDNqLK4="
},
"p-limit": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.3.0.tgz",
......@@ -4422,6 +4461,23 @@
"p-limit": "^2.2.0"
}
},
"p-queue": {
"version": "6.6.2",
"resolved": "https://registry.npmjs.org/p-queue/-/p-queue-6.6.2.tgz",
"integrity": "sha512-RwFpb72c/BhQLEXIZ5K2e+AhgNVmIejGlTgiB9MzZ0e93GRvqZ7uSi0dvRF7/XIXDeNkra2fNHBxTyPDGySpjQ==",
"requires": {
"eventemitter3": "^4.0.4",
"p-timeout": "^3.2.0"
}
},
"p-timeout": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/p-timeout/-/p-timeout-3.2.0.tgz",
"integrity": "sha512-rhIwUycgwwKcP9yTOOFK/AKsAopjjCakVqLHePO3CC6Mir1Z99xT+R63jZxAT5lFZLa2inS5h+ZS2GvR99/FBg==",
"requires": {
"p-finally": "^1.0.0"
}
},
"p-try": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz",
......
......@@ -14,7 +14,6 @@
"async": "^3.2.0",
"axios": "^0.19.2",
"bunyan": "^1.8.14",
"challonge": "^2.2.0",
"deepmerge": "^4.2.2",
"formidable": "^1.2.6",
"geoip-country-lite": "^1.0.0",
......@@ -24,6 +23,7 @@
"moment": "^2.29.1",
"mysql": "^2.18.1",
"node-os-utils": "^1.3.2",
"p-queue": "6.6.2",
"pg": "^6.4.2",
"q": "^1.5.1",
"querystring": "^0.2.0",
......
......@@ -196,23 +196,6 @@ moment_long_ago_string = global.moment_long_ago_string = null
rooms_count = 0
challonge = null
challonge_cache = {
participants: null
matches: null
}
challonge_queue_callbacks = {
participants: []
matches: []
}
is_challonge_requesting = {
participants: null
matches: null
}
get_callback = () ->
replaced_index = () ->
refresh_challonge_cache = () ->
class ResolveData
constructor: (@func) ->
......@@ -304,9 +287,9 @@ init = () ->
delete settings.hostinfo.enable_priority
imported = true
#import the old Challonge api key option
if settings.modules.challonge.api_key
settings.modules.challonge.options.apiKey = settings.modules.challonge.api_key
delete settings.modules.challonge.api_key
if settings.modules.challonge.options
settings.modules.challonge.api_key = settings.modules.challonge.options.api_key
delete settings.modules.challonge.options
imported = true
#import the old random_duel.blank_pass_match option
if settings.modules.random_duel.blank_pass_match == true
......@@ -465,64 +448,8 @@ init = () ->
log.warn 'ARENA INIT POST ERROR', e
if settings.modules.challonge.enabled
challonge_module_name = 'challonge'
if settings.modules.challonge.use_custom_module
challonge_module_name = settings.modules.challonge.use_custom_module
challonge = global.challonge = require(challonge_module_name).createClient(settings.modules.challonge.options)
challonge_cache = {
participants: null
matches: null
}
challonge_queue_callbacks = {
participants: []
matches: []
}
is_challonge_requesting = {
participants: null
matches: null
}
get_callback = (challonge_type, resolve_data) ->
return ((err, data) ->
if settings.modules.challonge.cache_ttl and !err and data
challonge_cache[challonge_type] = data
is_challonge_requesting[challonge_type] = null
resolve_data.resolve(err, data)
while challonge_queue_callbacks[challonge_type].length
cur_resolve_data = challonge_queue_callbacks[challonge_type].splice(0, 1)[0]
cur_resolve_data.resolve(err, data)
return
)
replaced_index = (challonge_type) ->
return (_data) ->
resolve_data = new ResolveData(_data.callback)
if settings.modules.challonge.cache_ttl and !_data.no_cache and challonge_cache[challonge_type]
resolve_data.resolve(null, challonge_cache[challonge_type])
else if is_challonge_requesting[challonge_type] and moment_now.diff(is_challonge_requesting[challonge_type]) <= 5000
challonge_queue_callbacks[challonge_type].push(resolve_data)
else
_data.callback = get_callback(challonge_type, resolve_data)
is_challonge_requesting[challonge_type] = moment_now_string
try
challonge[challonge_type].index(_data)
catch err
_data.callback(err, null)
return
for challonge_type in ["participants", "matches"]
challonge[challonge_type]._index = replaced_index(challonge_type)
challonge.matches._update = (_data) ->
try
challonge.matches.update(_data)
catch err
log.warn("Errored pushing scores to Challonge.", err)
return
refresh_challonge_cache = global.refresh_challonge_cache = () ->
if settings.modules.challonge.cache_ttl
challonge_cache.participants = null
challonge_cache.matches = null
return
refresh_challonge_cache()
if settings.modules.challonge.cache_ttl
setInterval(refresh_challonge_cache, settings.modules.challonge.cache_ttl)
Challonge = require('./challonge').Challonge
challonge = new Challonge(settings.modules.challonge)
if settings.modules.tips.get
load_tips()
......@@ -1476,17 +1403,7 @@ class Room
if settings.modules.challonge.enabled and @duel_stage != ygopro.constants.DUEL_STAGE.BEGIN and @hostinfo.mode != 2 and !@kicked
room_name = @name
challonge.matches._update({
id: settings.modules.challonge.tournament_id,
matchId: @challonge_info.id,
match: @get_challonge_score(),
callback: (err, data) ->
if err
log.warn("Errored pushing scores to Challonge.", room_name, err)
else
refresh_challonge_cache()
return
})
@post_challonge_score()
if @player_datas.length and settings.modules.cloud_replay.enabled
replay_id = @cloud_replay_id
if @has_ygopro_error
......@@ -1558,28 +1475,34 @@ class Room
return null
challonge_duel_log = {}
if @scores[@dueling_players[0].name_vpass] > @scores[@dueling_players[1].name_vpass]
challonge_duel_log.winnerId = @dueling_players[0].challonge_info.id
challonge_duel_log.winner_id = @dueling_players[0].challonge_info.id
else if @scores[@dueling_players[0].name_vpass] < @scores[@dueling_players[1].name_vpass]
challonge_duel_log.winnerId = @dueling_players[1].challonge_info.id
challonge_duel_log.winner_id = @dueling_players[1].challonge_info.id
else
challonge_duel_log.winnerId = "tie"
challonge_duel_log.winner_id = "tie"
if settings.modules.challonge.post_detailed_score
if @dueling_players[0].challonge_info.id == @challonge_info.player1Id and @dueling_players[1].challonge_info.id == @challonge_info.player2Id
challonge_duel_log.scoresCsv = @scores[@dueling_players[0].name_vpass] + "-" + @scores[@dueling_players[1].name_vpass]
else if @dueling_players[1].challonge_info.id == @challonge_info.player1Id and @dueling_players[0].challonge_info.id == @challonge_info.player2Id
challonge_duel_log.scoresCsv = @scores[@dueling_players[1].name_vpass] + "-" + @scores[@dueling_players[0].name_vpass]
if @dueling_players[0].challonge_info.id == @challonge_info.player1_id and @dueling_players[1].challonge_info.id == @challonge_info.player2_id
challonge_duel_log.scores_csv = @scores[@dueling_players[0].name_vpass] + "-" + @scores[@dueling_players[1].name_vpass]
else if @dueling_players[1].challonge_info.id == @challonge_info.player1_id and @dueling_players[0].challonge_info.id == @challonge_info.player2_id
challonge_duel_log.scores_csv = @scores[@dueling_players[1].name_vpass] + "-" + @scores[@dueling_players[0].name_vpass]
else
challonge_duel_log.scoresCsv = "0-0"
challonge_duel_log.scores_csv = "0-0"
log.warn("Score mismatch.", @name)
else
if challonge_duel_log.winnerId == @challonge_info.player1Id
challonge_duel_log.scoresCsv = "1-0"
else if challonge_duel_log.winnerId == @challonge_info.player2Id
challonge_duel_log.scoresCsv = "0-1"
if challonge_duel_log.winner_id == @challonge_info.player1_id
challonge_duel_log.scores_csv = "1-0"
else if challonge_duel_log.winner_id == @challonge_info.player2_id
challonge_duel_log.scores_csv = "0-1"
else
challonge_duel_log.scoresCsv = "0-0"
challonge_duel_log.scores_csv = "0-0"
return challonge_duel_log
post_challonge_score: (noWinner) ->
matchResult = @get_challonge_score()
if noWinner
delete matchResult.winner_id
challonge.putScore(@challonge_info.id, matchResult)
get_roomlist_hostinfo: () -> # Just for supporting websocket roomlist in old MyCard client....
#ret = _.clone(@hostinfo)
#ret.enable_priority = (@hostinfo.duel_rule != 5)
......@@ -2318,69 +2241,40 @@ ygopro.ctos_follow 'JOIN_GAME', true, (buffer, info, client, server, datas)->
ygopro.stoc_send_chat(client, '${loading_user_info}', ygopro.constants.COLORS.BABYBLUE)
client.setTimeout(300000) #连接后超时5分钟
recover_match = info.pass.match(/^(RC|RECOVER)(\d*)T(\d*)$/)
_async.auto({
participant_data: (done) ->
challonge.participants._index({
id: settings.modules.challonge.tournament_id,
callback: done
})
return
,
match_data: (done) ->
challonge.matches._index({
id: settings.modules.challonge.tournament_id,
callback: done,
no_cache: !!recover_match
})
return
}, (err, datas) ->
if err or !datas.participant_data or !datas.match_data
log.warn("Failed loading Challonge user info", err)
if !client.closed
ygopro.stoc_die(client, '${challonge_match_load_failed}')
return
if client.closed
return
found = false
for k,user of datas.participant_data
if user.participant and user.participant.name and deck_name_match(user.participant.name, client.name)
found = user.participant
break
if !found
tournament_data = await challonge.getTournament(!!recover_match)
if !tournament_data
if !client.closed
ygopro.stoc_die(client, '${challonge_match_load_failed}')
return
matching_participant = tournament_data.participants.find((p) => p.participant.name and deck_name_match(p.participant.name, client.name))
unless matching_participant
if !client.closed
ygopro.stoc_die(client, '${challonge_user_not_found}')
return
client.challonge_info = found
found = false
for k,match of datas.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)
found = match.match
break
if !found
return
client.challonge_info = matching_participant.participant
matching_match = tournament_data.matches.find((match) => match.match and !match.match.winner_id and match.match.state != "complete" and match.match.player1_id and match.match.player2_id and (match.match.player1_id == client.challonge_info.id or match.match.player2_id == client.challonge_info.id))
unless matching_match
if !client.closed
ygopro.stoc_die(client, '${challonge_match_not_found}')
return
#if found.winnerId
# ygopro.stoc_die(client, '${challonge_match_already_finished}')
# return
create_room_name = found.id.toString()
if !settings.modules.challonge.no_match_mode
create_room_name = 'M#' + create_room_name
if recover_match
create_room_name = recover_match[0] + ',' + create_room_name
else if recover_match
create_room_name = recover_match[0] + '#' + create_room_name
room = await ROOM_find_or_create_by_name(create_room_name)
if room
room.challonge_info = found
# room.max_player = 2
room.welcome = "${challonge_match_created}"
if !room
ygopro.stoc_die(client, settings.modules.full)
else if room.error
ygopro.stoc_die(client, room.error)
else
room.join_player(client)
return
)
create_room_name = matching_match.match.id.toString()
if !settings.modules.challonge.no_match_mode
create_room_name = 'M#' + create_room_name
if recover_match
create_room_name = recover_match[0] + ',' + create_room_name
else if recover_match
create_room_name = recover_match[0] + '#' + create_room_name
room = await ROOM_find_or_create_by_name(create_room_name)
if room
room.challonge_info = matching_match.match
# room.max_player = 2
room.welcome = "${challonge_match_created}"
if !room
ygopro.stoc_die(client, settings.modules.full)
else if room.error
ygopro.stoc_die(client, room.error)
else
room.join_player(client)
else if !client.name or client.name==""
ygopro.stoc_die(client, "${bad_user_name}")
......@@ -3557,20 +3451,7 @@ ygopro.stoc_follow 'CHANGE_SIDE', false, (buffer, info, client, server, datas)->
, 60000
client.side_interval = sinterval
if settings.modules.challonge.enabled and settings.modules.challonge.post_score_midduel and room.hostinfo.mode != 2 and client.pos == 0
temp_log = JSON.parse(JSON.stringify(room.get_challonge_score()))
delete temp_log.winnerId
room_name = room.name
challonge.matches._update({
id: settings.modules.challonge.tournament_id,
matchId: room.challonge_info.id,
match: temp_log,
callback: (err, data) ->
if err
log.warn("Errored pushing scores to Challonge.", room_name, err)
else
refresh_challonge_cache()
return
})
room.post_challonge_score(true)
if room.random_type or room.arena
if client.pos == 0
room.waiting_for_player = client
......
// Generated by CoffeeScript 2.6.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_unwelcome, ROOM_validate, ReplayParser, ResolveData, Room, SERVER_clear_disconnect, SERVER_kick, SOCKET_flush_data, _, _async, addCallback, athleticChecker, auth, axios, badwordR, badwords, ban_user, bunyan, challonge, challonge_cache, challonge_queue_callbacks, checkFileExists, createDirectoryIfNotExists, crypto, dataManager, deck_name_match, dialogues, disconnect_list, exec, execFile, fs, geoip, getDuelLogQueryFromQs, 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, moment_long_ago_string, moment_now, moment_now_string, net, netRequestHandler, os, osu, path, qs, real_windbot_server_ip, refresh_challonge_cache, release_disconnect, replaced_index, report_to_big_brother, request, roomlist, rooms_count, 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;
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_unwelcome, ROOM_validate, ReplayParser, ResolveData, Room, SERVER_clear_disconnect, SERVER_kick, SOCKET_flush_data, _, _async, addCallback, athleticChecker, auth, axios, badwordR, badwords, ban_user, bunyan, challonge, checkFileExists, createDirectoryIfNotExists, crypto, dataManager, deck_name_match, dialogues, disconnect_list, exec, execFile, fs, geoip, getDuelLogQueryFromQs, getSeedTimet, get_memory_usage, http, httpRequestListener, importOldConfig, import_datas, init, lflists, loadJSON, loadJSONAsync, loadLFList, loadRemoteData, load_dialogues, load_tips, log, long_resolve_cards, memory_usage, merge, moment, moment_long_ago_string, moment_now, moment_now_string, net, netRequestHandler, os, osu, path, qs, real_windbot_server_ip, release_disconnect, report_to_big_brother, request, roomlist, rooms_count, 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');
......@@ -240,27 +240,6 @@
challonge = null;
challonge_cache = {
participants: null,
matches: null
};
challonge_queue_callbacks = {
participants: [],
matches: []
};
is_challonge_requesting = {
participants: null,
matches: null
};
get_callback = function() {};
replaced_index = function() {};
refresh_challonge_cache = function() {};
ResolveData = (function() {
class ResolveData {
constructor(func) {
......@@ -307,7 +286,7 @@
};
init = async function() {
var AthleticChecker, DataManager, challonge_module_name, challonge_type, chat_color, config, cppversion, defaultConfig, default_data, dirPath, dns, e, get_rooms_count, 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;
var AthleticChecker, Challonge, DataManager, chat_color, config, cppversion, defaultConfig, default_data, dirPath, dns, e, get_rooms_count, http_server, https, https_server, imported, j, l, len, len1, mkdirList, options, pgClient, pg_client, pg_query, plugin_filename, plugin_list, plugin_path, postData;
log.info('Reading config.');
await createDirectoryIfNotExists("./config");
await importOldConfig();
......@@ -392,9 +371,9 @@
imported = true;
}
//import the old Challonge api key option
if (settings.modules.challonge.api_key) {
settings.modules.challonge.options.apiKey = settings.modules.challonge.api_key;
delete settings.modules.challonge.api_key;
if (settings.modules.challonge.options) {
settings.modules.challonge.api_key = settings.modules.challonge.options.api_key;
delete settings.modules.challonge.options;
imported = true;
}
//import the old random_duel.blank_pass_match option
......@@ -584,81 +563,8 @@
}
}
if (settings.modules.challonge.enabled) {
challonge_module_name = 'challonge';
if (settings.modules.challonge.use_custom_module) {
challonge_module_name = settings.modules.challonge.use_custom_module;
}
challonge = global.challonge = require(challonge_module_name).createClient(settings.modules.challonge.options);
challonge_cache = {
participants: null,
matches: null
};
challonge_queue_callbacks = {
participants: [],
matches: []
};
is_challonge_requesting = {
participants: null,
matches: null
};
get_callback = function(challonge_type, resolve_data) {
return (function(err, data) {
var cur_resolve_data;
if (settings.modules.challonge.cache_ttl && !err && data) {
challonge_cache[challonge_type] = data;
}
is_challonge_requesting[challonge_type] = null;
resolve_data.resolve(err, data);
while (challonge_queue_callbacks[challonge_type].length) {
cur_resolve_data = challonge_queue_callbacks[challonge_type].splice(0, 1)[0];
cur_resolve_data.resolve(err, data);
}
});
};
replaced_index = function(challonge_type) {
return function(_data) {
var err, resolve_data;
resolve_data = new ResolveData(_data.callback);
if (settings.modules.challonge.cache_ttl && !_data.no_cache && challonge_cache[challonge_type]) {
resolve_data.resolve(null, challonge_cache[challonge_type]);
} else if (is_challonge_requesting[challonge_type] && moment_now.diff(is_challonge_requesting[challonge_type]) <= 5000) {
challonge_queue_callbacks[challonge_type].push(resolve_data);
} else {
_data.callback = get_callback(challonge_type, resolve_data);
is_challonge_requesting[challonge_type] = moment_now_string;
try {
challonge[challonge_type].index(_data);
} catch (error1) {
err = error1;
_data.callback(err, null);
}
}
};
};
ref = ["participants", "matches"];
for (j = 0, len = ref.length; j < len; j++) {
challonge_type = ref[j];
challonge[challonge_type]._index = replaced_index(challonge_type);
}
challonge.matches._update = function(_data) {
var err;
try {
challonge.matches.update(_data);
} catch (error1) {
err = error1;
log.warn("Errored pushing scores to Challonge.", err);
}
};
refresh_challonge_cache = global.refresh_challonge_cache = function() {
if (settings.modules.challonge.cache_ttl) {
challonge_cache.participants = null;
challonge_cache.matches = null;
}
};
refresh_challonge_cache();
if (settings.modules.challonge.cache_ttl) {
setInterval(refresh_challonge_cache, settings.modules.challonge.cache_ttl);
}
Challonge = require('./challonge').Challonge;
challonge = new Challonge(settings.modules.challonge);
}
if (settings.modules.tips.get) {
load_tips();
......@@ -666,9 +572,9 @@
if (settings.modules.tips.enabled) {
if (settings.modules.tips.interval) {
setInterval(function() {
var l, len1, room;
for (l = 0, len1 = ROOM_all.length; l < len1; l++) {
room = ROOM_all[l];
var j, len, room;
for (j = 0, len = ROOM_all.length; j < len; j++) {
room = ROOM_all[j];
if (room && room.established && room.duel_stage !== ygopro.constants.END) {
if (room.duel_stage !== ygopro.constants.DUEL_STAGE.DUELING) {
ygopro.stoc_send_random_tip_to_room(room);
......@@ -679,9 +585,9 @@
}
if (settings.modules.tips.interval_ingame) {
setInterval(function() {
var l, len1, room;
for (l = 0, len1 = ROOM_all.length; l < len1; l++) {
room = ROOM_all[l];
var j, len, room;
for (j = 0, len = ROOM_all.length; j < len; j++) {
room = ROOM_all[j];
if (room && room.established && room.duel_stage !== ygopro.constants.END) {
if (room.duel_stage === ygopro.constants.DUEL_STAGE.DUELING) {
ygopro.stoc_send_random_tip_to_room(room);
......@@ -711,9 +617,9 @@
}
if (settings.modules.random_duel.enabled) {
setInterval(async function() {
var l, len1, room, time_passed;
for (l = 0, len1 = ROOM_all.length; l < len1; l++) {
room = ROOM_all[l];
var j, len, room, time_passed;
for (j = 0, len = ROOM_all.length; j < len; j++) {
room = ROOM_all[j];
if (!(room && room.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN && room.random_type && room.last_active_time && room.waiting_for_player && room.get_disconnected_count() === 0 && (!settings.modules.side_timeout || room.duel_stage !== ygopro.constants.DUEL_STAGE.SIDING) && !room.recovered)) {
continue;
}
......@@ -736,9 +642,9 @@
}
if (settings.modules.mycard.enabled) {
setInterval(function() {
var l, len1, len2, m, player, room, time_passed, waited_time;
for (l = 0, len1 = ROOM_all.length; l < len1; l++) {
room = ROOM_all[l];
var j, l, len, len1, player, room, time_passed, waited_time;
for (j = 0, len = ROOM_all.length; j < len; j++) {
room = ROOM_all[j];
if (!(room && room.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN && room.arena && room.last_active_time && room.waiting_for_player && room.get_disconnected_count() === 0 && (!settings.modules.side_timeout || room.duel_stage !== ygopro.constants.DUEL_STAGE.SIDING) && !room.recovered)) {
continue;
}
......@@ -756,8 +662,8 @@
}
}
if (true) { // settings.modules.arena_mode.punish_quit_before_match
for (m = 0, len2 = ROOM_all.length; m < len2; m++) {
room = ROOM_all[m];
for (l = 0, len1 = ROOM_all.length; l < len1; l++) {
room = ROOM_all[l];
if (!(room && room.arena && room.duel_stage === ygopro.constants.DUEL_STAGE.BEGIN && room.get_playing_player().length < 2)) {
continue;
}
......@@ -777,13 +683,13 @@
}
if (settings.modules.heartbeat_detection.enabled) {
setInterval(function() {
var l, len1, len2, m, player, ref1, room;
for (l = 0, len1 = ROOM_all.length; l < len1; l++) {
room = ROOM_all[l];
var j, l, len, len1, player, ref, room;
for (j = 0, len = ROOM_all.length; j < len; j++) {
room = ROOM_all[j];
if (room && room.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN && (room.hostinfo.time_limit === 0 || room.duel_stage !== ygopro.constants.DUEL_STAGE.DUELING) && !room.windbot) {
ref1 = room.get_playing_player();
for (m = 0, len2 = ref1.length; m < len2; m++) {
player = ref1[m];
ref = room.get_playing_player();
for (l = 0, len1 = ref.length; l < len1; l++) {
player = ref[l];
if (player && (room.duel_stage !== ygopro.constants.DUEL_STAGE.SIDING || player.selected_preduel)) {
CLIENT_heartbeat_register(player, true);
}
......@@ -796,10 +702,10 @@
spawn_windbot();
}
setInterval(function() {
var l, len1, results, room;
var j, len, results, room;
results = [];
for (l = 0, len1 = ROOM_all.length; l < len1; l++) {
room = ROOM_all[l];
for (j = 0, len = ROOM_all.length; j < len; j++) {
room = ROOM_all[j];
if (!(room && room.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN && room.hostinfo.auto_death && !room.auto_death_triggered && moment_now.diff(room.start_time) > 60000 * room.hostinfo.auto_death)) {
continue;
}
......@@ -830,13 +736,13 @@
https_server.listen(settings.modules.http.ssl.port);
}
mkdirList = ["./plugins", settings.modules.tournament_mode.deck_path, settings.modules.tournament_mode.replay_path, settings.modules.tournament_mode.log_save_path, settings.modules.deck_log.local];
for (l = 0, len1 = mkdirList.length; l < len1; l++) {
dirPath = mkdirList[l];
for (j = 0, len = mkdirList.length; j < len; j++) {
dirPath = mkdirList[j];
await createDirectoryIfNotExists(dirPath);
}
plugin_list = (await fs.promises.readdir("./plugins"));
for (m = 0, len2 = plugin_list.length; m < len2; m++) {
plugin_filename = plugin_list[m];
for (l = 0, len1 = plugin_list.length; l < len1; l++) {
plugin_filename = plugin_list[l];
plugin_path = process.cwd() + "/plugins/" + plugin_filename;
require(plugin_path);
log.info("Plugin loaded:", plugin_filename);
......@@ -1945,18 +1851,7 @@
// log.info 'SCORE POST OK', response.statusCode, response.statusMessage, @name, body
if (settings.modules.challonge.enabled && this.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN && this.hostinfo.mode !== 2 && !this.kicked) {
room_name = this.name;
challonge.matches._update({
id: settings.modules.challonge.tournament_id,
matchId: this.challonge_info.id,
match: this.get_challonge_score(),
callback: function(err, data) {
if (err) {
log.warn("Errored pushing scores to Challonge.", room_name, err);
} else {
refresh_challonge_cache();
}
}
});
this.post_challonge_score();
}
if (this.player_datas.length && settings.modules.cloud_replay.enabled) {
replay_id = this.cloud_replay_id;
......@@ -2061,33 +1956,42 @@
}
challonge_duel_log = {};
if (this.scores[this.dueling_players[0].name_vpass] > this.scores[this.dueling_players[1].name_vpass]) {
challonge_duel_log.winnerId = this.dueling_players[0].challonge_info.id;
challonge_duel_log.winner_id = this.dueling_players[0].challonge_info.id;
} else if (this.scores[this.dueling_players[0].name_vpass] < this.scores[this.dueling_players[1].name_vpass]) {
challonge_duel_log.winnerId = this.dueling_players[1].challonge_info.id;
challonge_duel_log.winner_id = this.dueling_players[1].challonge_info.id;
} else {
challonge_duel_log.winnerId = "tie";
challonge_duel_log.winner_id = "tie";
}
if (settings.modules.challonge.post_detailed_score) {
if (this.dueling_players[0].challonge_info.id === this.challonge_info.player1Id && this.dueling_players[1].challonge_info.id === this.challonge_info.player2Id) {
challonge_duel_log.scoresCsv = this.scores[this.dueling_players[0].name_vpass] + "-" + this.scores[this.dueling_players[1].name_vpass];
} else if (this.dueling_players[1].challonge_info.id === this.challonge_info.player1Id && this.dueling_players[0].challonge_info.id === this.challonge_info.player2Id) {
challonge_duel_log.scoresCsv = this.scores[this.dueling_players[1].name_vpass] + "-" + this.scores[this.dueling_players[0].name_vpass];
if (this.dueling_players[0].challonge_info.id === this.challonge_info.player1_id && this.dueling_players[1].challonge_info.id === this.challonge_info.player2_id) {
challonge_duel_log.scores_csv = this.scores[this.dueling_players[0].name_vpass] + "-" + this.scores[this.dueling_players[1].name_vpass];
} else if (this.dueling_players[1].challonge_info.id === this.challonge_info.player1_id && this.dueling_players[0].challonge_info.id === this.challonge_info.player2_id) {
challonge_duel_log.scores_csv = this.scores[this.dueling_players[1].name_vpass] + "-" + this.scores[this.dueling_players[0].name_vpass];
} else {
challonge_duel_log.scoresCsv = "0-0";
challonge_duel_log.scores_csv = "0-0";
log.warn("Score mismatch.", this.name);
}
} else {
if (challonge_duel_log.winnerId === this.challonge_info.player1Id) {
challonge_duel_log.scoresCsv = "1-0";
} else if (challonge_duel_log.winnerId === this.challonge_info.player2Id) {
challonge_duel_log.scoresCsv = "0-1";
if (challonge_duel_log.winner_id === this.challonge_info.player1_id) {
challonge_duel_log.scores_csv = "1-0";
} else if (challonge_duel_log.winner_id === this.challonge_info.player2_id) {
challonge_duel_log.scores_csv = "0-1";
} else {
challonge_duel_log.scoresCsv = "0-0";
challonge_duel_log.scores_csv = "0-0";
}
}
return challonge_duel_log;
}
post_challonge_score(noWinner) {
var matchResult;
matchResult = this.get_challonge_score();
if (noWinner) {
delete matchResult.winner_id;
}
return challonge.putScore(this.challonge_info.id, matchResult);
}
get_roomlist_hostinfo() { // Just for supporting websocket roomlist in old MyCard client....
//ret = _.clone(@hostinfo)
//ret.enable_priority = (@hostinfo.duel_rule != 5)
......@@ -2739,7 +2643,7 @@
});
ygopro.ctos_follow('JOIN_GAME', true, async function(buffer, info, client, server, datas) {
var available_logs, check_buffer_indentity, create_room_with_action, decrypted_buffer, duelLog, e, exactBan, i, id, index, j, l, len, len1, len2, len3, m, n, pre_room, recover_match, ref, ref1, replay, replay_id, replays, room, secret, struct, userData, userDataRes, userUrl;
var available_logs, check_buffer_indentity, create_room_name, create_room_with_action, decrypted_buffer, duelLog, e, exactBan, i, id, index, j, l, len, len1, len2, len3, m, matching_match, matching_participant, n, pre_room, recover_match, ref, ref1, replay, replay_id, replays, room, secret, struct, tournament_data, userData, userDataRes, userUrl;
//log.info info
info.pass = info.pass.trim();
client.pass = info.pass;
......@@ -3057,83 +2961,54 @@
ygopro.stoc_send_chat(client, '${loading_user_info}', ygopro.constants.COLORS.BABYBLUE);
client.setTimeout(300000); //连接后超时5分钟
recover_match = info.pass.match(/^(RC|RECOVER)(\d*)T(\d*)$/);
_async.auto({
participant_data: function(done) {
challonge.participants._index({
id: settings.modules.challonge.tournament_id,
callback: done
});
},
match_data: function(done) {
challonge.matches._index({
id: settings.modules.challonge.tournament_id,
callback: done,
no_cache: !!recover_match
});
}
}, async function(err, datas) {
var create_room_name, found, k, match, ref2, ref3, room, user;
if (client.closed) {
return;
}
if (err || !datas.participant_data || !datas.match_data) {
log.warn("Failed loading Challonge user info", err);
tournament_data = (await challonge.getTournament(!!recover_match));
if (!tournament_data) {
if (!client.closed) {
ygopro.stoc_die(client, '${challonge_match_load_failed}');
return;
}
found = false;
ref2 = datas.participant_data;
for (k in ref2) {
user = ref2[k];
if (user.participant && user.participant.name && deck_name_match(user.participant.name, client.name)) {
found = user.participant;
break;
}
}
if (!found) {
return;
}
matching_participant = tournament_data.participants.find((p) => {
return p.participant.name && deck_name_match(p.participant.name, client.name);
});
if (!matching_participant) {
if (!client.closed) {
ygopro.stoc_die(client, '${challonge_user_not_found}');
return;
}
client.challonge_info = found;
found = false;
ref3 = datas.match_data;
for (k in ref3) {
match = ref3[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)) {
found = match.match;
break;
}
}
if (!found) {
return;
}
client.challonge_info = matching_participant.participant;
matching_match = tournament_data.matches.find((match) => {
return match.match && !match.match.winner_id && match.match.state !== "complete" && match.match.player1_id && match.match.player2_id && (match.match.player1_id === client.challonge_info.id || match.match.player2_id === client.challonge_info.id);
});
if (!matching_match) {
if (!client.closed) {
ygopro.stoc_die(client, '${challonge_match_not_found}');
return;
}
//if found.winnerId
// ygopro.stoc_die(client, '${challonge_match_already_finished}')
// return
create_room_name = found.id.toString();
if (!settings.modules.challonge.no_match_mode) {
create_room_name = 'M#' + create_room_name;
if (recover_match) {
create_room_name = recover_match[0] + ',' + create_room_name;
}
} else if (recover_match) {
create_room_name = recover_match[0] + '#' + create_room_name;
}
room = (await ROOM_find_or_create_by_name(create_room_name));
if (room) {
room.challonge_info = found;
// room.max_player = 2
room.welcome = "${challonge_match_created}";
}
if (!room) {
ygopro.stoc_die(client, settings.modules.full);
} else if (room.error) {
ygopro.stoc_die(client, room.error);
} else {
room.join_player(client);
return;
}
create_room_name = matching_match.match.id.toString();
if (!settings.modules.challonge.no_match_mode) {
create_room_name = 'M#' + create_room_name;
if (recover_match) {
create_room_name = recover_match[0] + ',' + create_room_name;
}
});
} else if (recover_match) {
create_room_name = recover_match[0] + '#' + create_room_name;
}
room = (await ROOM_find_or_create_by_name(create_room_name));
if (room) {
room.challonge_info = matching_match.match;
// room.max_player = 2
room.welcome = "${challonge_match_created}";
}
if (!room) {
ygopro.stoc_die(client, settings.modules.full);
} else if (room.error) {
ygopro.stoc_die(client, room.error);
} else {
room.join_player(client);
}
}
} else if (!client.name || client.name === "") {
ygopro.stoc_die(client, "${bad_user_name}");
......@@ -4740,7 +4615,7 @@
});
ygopro.stoc_follow('CHANGE_SIDE', false, async function(buffer, info, client, server, datas) {
var room, room_name, sinterval, temp_log;
var room, sinterval;
room = ROOM_all[client.rid];
if (!room) {
return;
......@@ -4772,21 +4647,7 @@
client.side_interval = sinterval;
}
if (settings.modules.challonge.enabled && settings.modules.challonge.post_score_midduel && room.hostinfo.mode !== 2 && client.pos === 0) {
temp_log = JSON.parse(JSON.stringify(room.get_challonge_score()));
delete temp_log.winnerId;
room_name = room.name;
challonge.matches._update({
id: settings.modules.challonge.tournament_id,
matchId: room.challonge_info.id,
match: temp_log,
callback: function(err, data) {
if (err) {
log.warn("Errored pushing scores to Challonge.", room_name, err);
} else {
refresh_challonge_cache();
}
}
});
room.post_challonge_score(true);
}
if (room.random_type || room.arena) {
if (client.pos === 0) {
......
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