Commit 4077e873 authored by nanahira's avatar nanahira

fix

parent 8aea545b
...@@ -18,7 +18,8 @@ ...@@ -18,7 +18,8 @@
"moment": "latest", "moment": "latest",
"request": "latest", "request": "latest",
"underscore": "latest", "underscore": "latest",
"underscore.string": "latest" "underscore.string": "latest",
"ws": "^5.2.0"
}, },
"license": "AGPL-3.0", "license": "AGPL-3.0",
"scripts": { "scripts": {
......
...@@ -1480,34 +1480,43 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)-> ...@@ -1480,34 +1480,43 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
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 or !data.participant or client.name != data.participant.name log.info("user info", client.name, data)
if err or !data
if err if err
log.warn("Failed loading Challonge user info", err) log.warn("Failed loading Challonge user info", err)
ygopro.stoc_die(client, '${challonge_match_load_failed}')
return
found = false
for user in data
if user.participant.name == client.name
found = user.participant
break
if !found
ygopro.stoc_die(client, '${challonge_user_not_found}') ygopro.stoc_die(client, '${challonge_user_not_found}')
return return
client.challonge_info = data.participant client.challonge_info = found
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 or !data.match_list if err or !data
if err if err
log.warn("Failed loading Challonge match info", err) log.warn("Failed loading Challonge match info", err)
ygopro.stoc_die(client, '${challonge_match_load_failed}') ygopro.stoc_die(client, '${challonge_match_load_failed}')
return return
found_match = false found = false
for match in data.match_list for match in data
if data.match_list.player1_id == client.challonge_info.id or data.match_list.player2_id == client.challonge_info.id if data.match.player1_id == client.challonge_info.id or data.match.player2_id == client.challonge_info.id
found_match = data.match_list found = data.match_list
break break
if !found_match if !found
ygopro.stoc_die(client, '${challonge_match_not_found}') ygopro.stoc_die(client, '${challonge_match_not_found}')
return return
if found_match.winner_id if found.winner_id
ygopro.stoc_die(client, '${challonge_match_already_finished}') ygopro.stoc_die(client, '${challonge_match_already_finished}')
return return
room = ROOM_find_or_create_by_name('M#' + found_match.id) room = ROOM_find_or_create_by_name('M#' + found.id)
if room if room
room.challonge_info = found_match room.challonge_info = found
room.max_player = 2 room.max_player = 2
room.welcome = "${challonge_match_created}" room.welcome = "${challonge_match_created}"
if !room if !room
......
...@@ -1808,45 +1808,58 @@ ...@@ -1808,45 +1808,58 @@
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) {
if (err || !data || !data.participant || client.name !== data.participant.name) { var found, len4, o, user;
log.info("user info", client.name, data);
if (err || !data) {
if (err) { if (err) {
log.warn("Failed loading Challonge user info", err); log.warn("Failed loading Challonge user info", err);
} }
ygopro.stoc_die(client, '${challonge_match_load_failed}');
return;
}
found = false;
for (o = 0, len4 = data.length; o < len4; o++) {
user = data[o];
if (user.participant.name === client.name) {
found = user.participant;
break;
}
}
if (!found) {
ygopro.stoc_die(client, '${challonge_user_not_found}'); ygopro.stoc_die(client, '${challonge_user_not_found}');
return; return;
} }
client.challonge_info = data.participant; client.challonge_info = found;
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_match, len4, len5, match, o, p, ref4, ref5; var len5, len6, match, p, q, ref4;
if (err || !data || !data.match_list) { if (err || !data) {
if (err) { if (err) {
log.warn("Failed loading Challonge match info", err); log.warn("Failed loading Challonge match info", err);
} }
ygopro.stoc_die(client, '${challonge_match_load_failed}'); ygopro.stoc_die(client, '${challonge_match_load_failed}');
return; return;
} }
found_match = false; found = false;
ref4 = data.match_list; for (p = 0, len5 = data.length; p < len5; p++) {
for (o = 0, len4 = ref4.length; o < len4; o++) { match = data[p];
match = ref4[o]; if (data.match.player1_id === client.challonge_info.id || data.match.player2_id === client.challonge_info.id) {
if (data.match_list.player1_id === client.challonge_info.id || data.match_list.player2_id === client.challonge_info.id) { found = data.match_list;
found_match = data.match_list;
break; break;
} }
} }
if (!found_match) { if (!found) {
ygopro.stoc_die(client, '${challonge_match_not_found}'); ygopro.stoc_die(client, '${challonge_match_not_found}');
return; return;
} }
if (found_match.winner_id) { if (found.winner_id) {
ygopro.stoc_die(client, '${challonge_match_already_finished}'); ygopro.stoc_die(client, '${challonge_match_already_finished}');
return; return;
} }
room = ROOM_find_or_create_by_name('M#' + found_match.id); room = ROOM_find_or_create_by_name('M#' + found.id);
if (room) { if (room) {
room.challonge_info = found_match; room.challonge_info = found;
room.max_player = 2; room.max_player = 2;
room.welcome = "${challonge_match_created}"; room.welcome = "${challonge_match_created}";
} }
...@@ -1862,9 +1875,9 @@ ...@@ -1862,9 +1875,9 @@
ygopro.stoc_send_chat_to_room(room, client.name + " ${watch_join}"); ygopro.stoc_send_chat_to_room(room, client.name + " ${watch_join}");
room.watchers.push(client); room.watchers.push(client);
ygopro.stoc_send_chat(client, "${watch_watching}", ygopro.constants.COLORS.BABYBLUE); ygopro.stoc_send_chat(client, "${watch_watching}", ygopro.constants.COLORS.BABYBLUE);
ref5 = room.watcher_buffers; ref4 = room.watcher_buffers;
for (p = 0, len5 = ref5.length; p < len5; p++) { for (q = 0, len6 = ref4.length; q < len6; q++) {
buffer = ref5[p]; buffer = ref4[q];
client.write(buffer); client.write(buffer);
} }
} else { } else {
......
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