Commit d8ada1a9 authored by nanahira's avatar nanahira

add challonge

parent a932ee96
......@@ -97,6 +97,11 @@
"auth_database": "postgres://233@233.mycard.moe/233",
"auth_key": "233333"
},
"challonge": {
"enabled": true,
"api_key": "123",
"tournament_id": "456"
},
"deck_log": {
"enabled": false,
"accesskey": "233",
......
......@@ -137,6 +137,11 @@
"deck_incorrect_reconnect": "Please pick your previous deck.",
"reconnect_failed": "Reconnect failed.",
"reconnecting_to_room": "Reconnecting to server...",
"challonge_user_not_found": "You are not a participant of the tournament.",
"challonge_match_load_failed": "Failed loading tournament info.",
"challonge_match_not_found": "Your current match was not found.",
"challonge_match_already_finished": "Your current match was already finished. Please call the judge for any help.",
"challonge_match_created": "A room for match only is created. Your opponent will join in automatically.",
"athletic_arena_tip": "During an athletic match, a game quit behavior is regarded as a surrender."
},
"es-es": {
......@@ -414,6 +419,11 @@
"deck_incorrect_reconnect": "请选择你在本局决斗中使用的卡组。",
"reconnect_failed": "重新连接失败。",
"reconnecting_to_room": "正在重新连接到服务器……",
"challonge_user_not_found": "未找到你的参赛信息。",
"challonge_match_load_failed": "读取比赛信息失败。",
"challonge_match_not_found": "你没有当前轮次的比赛。",
"challonge_match_already_finished": "你在当前轮次的比赛已经结束,如需重赛,请联系裁判。",
"challonge_match_created": "已建立比赛专用房间,将会自动匹配你的对手。",
"athletic_arena_tip": "在竞技匹配中,比赛开始前退出游戏也会视为投降。"
},
"ko-kr": {
......
......@@ -12,6 +12,7 @@
"author": "zh99998 <zh99998@gmail.com>, mercury233 <me@mercury233.me>",
"dependencies": {
"bunyan": "latest",
"challonge": "^2.1.1",
"deepmerge": "latest",
"load-json-file": "latest",
"moment": "latest",
......
......@@ -64,6 +64,7 @@ import_datas = [
"last_game_msg_title",
"last_hint_msg",
"start_deckbuf",
"challonge_info",
"ready_trap"
]
......@@ -250,6 +251,11 @@ if settings.modules.mycard.enabled
log.info "loading mycard user..."
pg_client.connect()
if settings.modules.challonge.enabled
challonge = require('challonge').createClient({
apiKey: settings.modules.challonge.api_key
})
# 获取可用内存
memory_usage = 0
get_memory_usage = ()->
......@@ -650,6 +656,8 @@ class Room
@duel_count = 0
@death = 0
@turn = 0
if settings.modules.challonge.enabled
@challonge_duel_log = {}
ROOM_all.push this
@hostinfo ||= JSON.parse(JSON.stringify(settings.hostinfo))
......@@ -817,6 +825,16 @@ class Room
#else
# log.info 'SCORE POST OK', response.statusCode, response.statusMessage, @name, body
return
if settings.modules.challonge.enabled
challonge.matches.update({
id: settings.modules.challonge.tournament_id,
matchId: room.challonge_info.id,
match: room.challonge_duel_log,
callback: (err, data) ->
if err
log.warn("Errored pushing scores to Challonge.", err)
return
})
if @player_datas.length and settings.modules.cloud_replay.enabled
replay_id = @cloud_replay_id
if @has_ygopro_error
......@@ -1360,6 +1378,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
}
options.lflist = _.findIndex lflists, (list)-> ((options.rule == 1) == list.tcg) and list.date.isBefore()
room = new Room(name, options)
if room
room.title = info.pass.slice(8).replace(String.fromCharCode(0xFEFF), ' ')
room.private = action == 2
when 3
......@@ -1370,6 +1389,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
return
when 4
room = ROOM_find_or_create_by_name('M#' + info.pass.slice(8))
if room
room.private = true
room.arena = settings.modules.arena_mode.mode
if room.arena == "athletic"
......@@ -1443,6 +1463,79 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
finish(buffer)
else if settings.modules.challonge.enabled
pre_room = ROOM_find_by_name(info.pass)
if pre_room and pre_room.started and settings.modules.cloud_replay.enable_halfway_watch
room = pre_room
client.setTimeout(300000) #连接后超时5分钟
client.rid = _.indexOf(ROOM_all, room)
client.is_post_watcher = true
ygopro.stoc_send_chat_to_room(room, "#{client.name} ${watch_join}")
room.watchers.push client
ygopro.stoc_send_chat(client, "${watch_watching}", ygopro.constants.COLORS.BABYBLUE)
for buffer in room.watcher_buffers
client.write buffer
else
ygopro.stoc_send_chat(client, '${loading_user_info}', ygopro.constants.COLORS.BABYBLUE)
challonge.participants.index({
id: settings.modules.challonge.tournament_id,
callback: (err, data) ->
if err or !data or !data.participant or client.name != data.participant.name
if err
log.warn("Failed loading Challonge user info", err)
ygopro.stoc_die(client, '${challonge_user_not_found}')
return
client.challonge_info = data.participant
challonge.participants.index({
id: settings.modules.challonge.tournament_id,
callback: (err, data) ->
if err or !data or !data.match_list
if err
log.warn("Failed loading Challonge match info", err)
ygopro.stoc_die(client, '${challonge_match_load_failed}')
return
found_match = false
for match in data.match_list
if data.match_list.player1_id == client.challonge_info.id or data.match_list.player2_id == client.challonge_info.id
found_match = data.match_list
break
if !found_match
ygopro.stoc_die(client, '${challonge_match_not_found}')
return
if found_match.winner_id
ygopro.stoc_die(client, '${challonge_match_already_finished}')
return
room = ROOM_find_or_create_by_name('M#' + found_match.id)
if room
room.challonge_info = found_match
room.max_player = 2
room.welcome = "${challonge_match_created}"
if !room
ygopro.stoc_die(client, "${server_full}")
else if room.error
ygopro.stoc_die(client, room.error)
else if room.started
if settings.modules.cloud_replay.enable_halfway_watch
client.setTimeout(300000) #连接后超时5分钟
client.rid = _.indexOf(ROOM_all, room)
client.is_post_watcher = true
ygopro.stoc_send_chat_to_room(room, "#{client.name} ${watch_join}")
room.watchers.push client
ygopro.stoc_send_chat(client, "${watch_watching}", ygopro.constants.COLORS.BABYBLUE)
for buffer in room.watcher_buffers
client.write buffer
else
ygopro.stoc_die(client, "${watch_denied}")
else
#client.room = room
client.setTimeout(300000) #连接后超时5分钟
client.rid = _.indexOf(ROOM_all, room)
room.connect(client)
return
})
return
})
else if !client.name or client.name==""
ygopro.stoc_die(client, "${bad_user_name}")
......@@ -2403,9 +2496,22 @@ ygopro.stoc_follow 'CHANGE_SIDE', false, (buffer, info, client, server)->
ygopro.stoc_follow 'REPLAY', true, (buffer, info, client, server)->
room=ROOM_all[client.rid]
return settings.modules.tournament_mode.enabled and settings.modules.tournament_mode.replay_safe unless room
return settings.modules.tournament_mode.enabled and settings.modules.tournament_mode.replay_safe and settings.modules.tournament_mode.block_replay_to_player unless room
if settings.modules.cloud_replay.enabled and room.random_type
Cloud_replay_ids.push room.cloud_replay_id
if settings.modules.challonge.enabled and client.pos == 0
if room.scores[room.dueling_players[0].name] > room.scores[room.dueling_players[1].name]
room.challonge_duel_log.winnerId = room.dueling_players[0].challonge_info.id
else if room.scores[room.dueling_players[0].name] < room.scores[room.dueling_players[1].name]
room.challonge_duel_log.winnerId = room.dueling_players[1].challonge_info.id
else
room.challonge_duel_log.winnerId = "tie"
if room.challonge_duel_log.winnerId == room.challonge_info.player1_id
room.challonge_duel_log.scoresCsv = "1-0"
else if room.challonge_duel_log.winnerId == room.challonge_info.player2_id
room.challonge_duel_log.scoresCsv = "0-1"
else
room.challonge_duel_log.scoresCsv = "0-0"
if settings.modules.tournament_mode.enabled and settings.modules.tournament_mode.replay_safe
if client.pos == 0
dueltime=moment().format('YYYY-MM-DD HH-mm-ss')
......
// Generated by CoffeeScript 1.12.7
(function() {
var CLIENT_get_authorize_key, CLIENT_import_data, CLIENT_is_able_to_reconnect, CLIENT_is_player, CLIENT_kick, CLIENT_pre_reconnect, CLIENT_reconnect, CLIENT_reconnect_register, CLIENT_reconnect_unregister, CLIENT_send_pre_reconnect_info, CLIENT_send_reconnect_info, 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, _, addCallback, badwords, ban_user, bunyan, chat_color, 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, j, l, len, len1, lflists, list, loadJSON, load_dialogues, load_tips, log, memory_usage, merge, moment, net, oldbadwords, oldconfig, olddialogues, oldduellog, oldtips, options, os, path, pgClient, pg_client, pg_query, redis, redisdb, ref, ref1, release_disconnect, report_to_big_brother, request, requestListener, roomlist, setting_change, setting_save, settings, spawn, spawnSync, tips, url, users_cache, wait_room_start, wait_room_start_arena, windbot_bin, windbot_parameters, windbot_process, windbots, ygopro, zlib;
var CLIENT_get_authorize_key, CLIENT_import_data, CLIENT_is_able_to_reconnect, CLIENT_is_player, CLIENT_kick, CLIENT_pre_reconnect, CLIENT_reconnect, CLIENT_reconnect_register, CLIENT_reconnect_unregister, CLIENT_send_pre_reconnect_info, CLIENT_send_reconnect_info, 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, _, addCallback, badwords, ban_user, bunyan, challonge, chat_color, 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, j, l, len, len1, lflists, list, loadJSON, load_dialogues, load_tips, log, memory_usage, merge, moment, net, oldbadwords, oldconfig, olddialogues, oldduellog, oldtips, options, os, path, pgClient, pg_client, pg_query, redis, redisdb, ref, ref1, release_disconnect, report_to_big_brother, request, requestListener, roomlist, setting_change, setting_save, settings, spawn, spawnSync, tips, url, users_cache, wait_room_start, wait_room_start_arena, windbot_bin, windbot_parameters, windbot_process, windbots, ygopro, zlib;
net = require('net');
......@@ -58,7 +58,7 @@
}
});
import_datas = ["abuse_count", "rag", "rid", "is_post_watcher", "retry_count", "name", "is_first", "lp", "card_count", "is_host", "pos", "surrend_confirm", "kick_count", "deck_saved", "main", "side", "side_interval", "side_tcount", "selected_preduel", "last_game_msg", "last_game_msg_title", "last_hint_msg", "start_deckbuf", "ready_trap"];
import_datas = ["abuse_count", "rag", "rid", "is_post_watcher", "retry_count", "name", "is_first", "lp", "card_count", "is_host", "pos", "surrend_confirm", "kick_count", "deck_saved", "main", "side", "side_interval", "side_tcount", "selected_preduel", "last_game_msg", "last_game_msg_title", "last_hint_msg", "start_deckbuf", "challonge_info", "ready_trap"];
merge = require('deepmerge');
......@@ -301,6 +301,12 @@
pg_client.connect();
}
if (settings.modules.challonge.enabled) {
challonge = require('challonge').createClient({
apiKey: settings.modules.challonge.api_key
});
}
memory_usage = 0;
get_memory_usage = function() {
......@@ -835,6 +841,9 @@
this.duel_count = 0;
this.death = 0;
this.turn = 0;
if (settings.modules.challonge.enabled) {
this.challonge_duel_log = {};
}
ROOM_all.push(this);
this.hostinfo || (this.hostinfo = JSON.parse(JSON.stringify(settings.hostinfo)));
delete this.hostinfo.comment;
......@@ -1057,6 +1066,18 @@
})(this));
}
}
if (settings.modules.challonge.enabled) {
challonge.matches.update({
id: settings.modules.challonge.tournament_id,
matchId: room.challonge_info.id,
match: room.challonge_duel_log,
callback: function(err, data) {
if (err) {
log.warn("Errored pushing scores to Challonge.", err);
}
}
});
}
if (this.player_datas.length && settings.modules.cloud_replay.enabled) {
replay_id = this.cloud_replay_id;
if (this.has_ygopro_error) {
......@@ -1551,7 +1572,7 @@
});
ygopro.ctos_follow('JOIN_GAME', false, function(buffer, info, client, server) {
var check, decrypted_buffer, finish, i, id, len2, len3, m, n, name, ref2, ref3, replay_id, room, secret;
var check, decrypted_buffer, finish, i, id, len2, len3, len4, m, n, name, o, pre_room, ref2, ref3, ref4, replay_id, room, secret;
info.pass = info.pass.trim();
if (CLIENT_is_able_to_reconnect(client)) {
CLIENT_pre_reconnect(client);
......@@ -1663,8 +1684,10 @@
return ((options.rule === 1) === list.tcg) && list.date.isBefore();
});
room = new Room(name, options);
if (room) {
room.title = info.pass.slice(8).replace(String.fromCharCode(0xFEFF), ' ');
room["private"] = action === 2;
}
break;
case 3:
name = info.pass.slice(8);
......@@ -1676,12 +1699,14 @@
break;
case 4:
room = ROOM_find_or_create_by_name('M#' + info.pass.slice(8));
if (room) {
room["private"] = true;
room.arena = settings.modules.arena_mode.mode;
if (room.arena === "athletic") {
room.max_player = 2;
room.welcome = "${athletic_arena_tip}";
}
}
break;
case 5:
title = info.pass.slice(8).replace(String.fromCharCode(0xFEFF), ' ');
......@@ -1763,6 +1788,98 @@
}
return finish(buffer);
});
} else if (settings.modules.challonge.enabled) {
pre_room = ROOM_find_by_name(info.pass);
if (pre_room && pre_room.started && settings.modules.cloud_replay.enable_halfway_watch) {
room = pre_room;
client.setTimeout(300000);
client.rid = _.indexOf(ROOM_all, room);
client.is_post_watcher = true;
ygopro.stoc_send_chat_to_room(room, client.name + " ${watch_join}");
room.watchers.push(client);
ygopro.stoc_send_chat(client, "${watch_watching}", ygopro.constants.COLORS.BABYBLUE);
ref3 = room.watcher_buffers;
for (n = 0, len3 = ref3.length; n < len3; n++) {
buffer = ref3[n];
client.write(buffer);
}
} else {
ygopro.stoc_send_chat(client, '${loading_user_info}', ygopro.constants.COLORS.BABYBLUE);
challonge.participants.index({
id: settings.modules.challonge.tournament_id,
callback: function(err, data) {
if (err || !data || !data.participant || client.name !== data.participant.name) {
if (err) {
log.warn("Failed loading Challonge user info", err);
}
ygopro.stoc_die(client, '${challonge_user_not_found}');
return;
}
client.challonge_info = data.participant;
challonge.participants.index({
id: settings.modules.challonge.tournament_id,
callback: function(err, data) {
var found_match, len4, len5, match, o, p, ref4, ref5;
if (err || !data || !data.match_list) {
if (err) {
log.warn("Failed loading Challonge match info", err);
}
ygopro.stoc_die(client, '${challonge_match_load_failed}');
return;
}
found_match = false;
ref4 = data.match_list;
for (o = 0, len4 = ref4.length; o < len4; o++) {
match = ref4[o];
if (data.match_list.player1_id === client.challonge_info.id || data.match_list.player2_id === client.challonge_info.id) {
found_match = data.match_list;
break;
}
}
if (!found_match) {
ygopro.stoc_die(client, '${challonge_match_not_found}');
return;
}
if (found_match.winner_id) {
ygopro.stoc_die(client, '${challonge_match_already_finished}');
return;
}
room = ROOM_find_or_create_by_name('M#' + found_match.id);
if (room) {
room.challonge_info = found_match;
room.max_player = 2;
room.welcome = "${challonge_match_created}";
}
if (!room) {
ygopro.stoc_die(client, "${server_full}");
} else if (room.error) {
ygopro.stoc_die(client, room.error);
} else if (room.started) {
if (settings.modules.cloud_replay.enable_halfway_watch) {
client.setTimeout(300000);
client.rid = _.indexOf(ROOM_all, room);
client.is_post_watcher = true;
ygopro.stoc_send_chat_to_room(room, client.name + " ${watch_join}");
room.watchers.push(client);
ygopro.stoc_send_chat(client, "${watch_watching}", ygopro.constants.COLORS.BABYBLUE);
ref5 = room.watcher_buffers;
for (p = 0, len5 = ref5.length; p < len5; p++) {
buffer = ref5[p];
client.write(buffer);
}
} else {
ygopro.stoc_die(client, "${watch_denied}");
}
} else {
client.setTimeout(300000);
client.rid = _.indexOf(ROOM_all, room);
room.connect(client);
}
}
});
}
});
}
} else if (!client.name || client.name === "") {
ygopro.stoc_die(client, "${bad_user_name}");
} else if (ROOM_connected_ip[client.ip] > 5) {
......@@ -1813,9 +1930,9 @@
ygopro.stoc_send_chat_to_room(room, client.name + " ${watch_join}");
room.watchers.push(client);
ygopro.stoc_send_chat(client, "${watch_watching}", ygopro.constants.COLORS.BABYBLUE);
ref3 = room.watcher_buffers;
for (n = 0, len3 = ref3.length; n < len3; n++) {
buffer = ref3[n];
ref4 = room.watcher_buffers;
for (o = 0, len4 = ref4.length; o < len4; o++) {
buffer = ref4[o];
client.write(buffer);
}
} else {
......@@ -3024,11 +3141,27 @@
var duellog, dueltime, i, len2, len3, m, n, player, ref2, ref3, replay_filename, room;
room = ROOM_all[client.rid];
if (!room) {
return settings.modules.tournament_mode.enabled && settings.modules.tournament_mode.replay_safe;
return settings.modules.tournament_mode.enabled && settings.modules.tournament_mode.replay_safe && settings.modules.tournament_mode.block_replay_to_player;
}
if (settings.modules.cloud_replay.enabled && room.random_type) {
Cloud_replay_ids.push(room.cloud_replay_id);
}
if (settings.modules.challonge.enabled && client.pos === 0) {
if (room.scores[room.dueling_players[0].name] > room.scores[room.dueling_players[1].name]) {
room.challonge_duel_log.winnerId = room.dueling_players[0].challonge_info.id;
} else if (room.scores[room.dueling_players[0].name] < room.scores[room.dueling_players[1].name]) {
room.challonge_duel_log.winnerId = room.dueling_players[1].challonge_info.id;
} else {
room.challonge_duel_log.winnerId = "tie";
}
if (room.challonge_duel_log.winnerId === room.challonge_info.player1_id) {
room.challonge_duel_log.scoresCsv = "1-0";
} else if (room.challonge_duel_log.winnerId === room.challonge_info.player2_id) {
room.challonge_duel_log.scoresCsv = "0-1";
} else {
room.challonge_duel_log.scoresCsv = "0-0";
}
}
if (settings.modules.tournament_mode.enabled && settings.modules.tournament_mode.replay_safe) {
if (client.pos === 0) {
dueltime = moment().format('YYYY-MM-DD HH-mm-ss');
......
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