Commit 0eb5b04c authored by nanahira's avatar nanahira

Merge branch 'master' into tcg_random

parents 15262d4c 80382ef0
...@@ -621,7 +621,8 @@ ROOM_unwelcome = (room, bad_player, reason)-> ...@@ -621,7 +621,8 @@ ROOM_unwelcome = (room, bad_player, reason)->
CLIENT_kick = (client) -> CLIENT_kick = (client) ->
client.system_kicked = true client.system_kicked = true
if settings.modules.reconnect.enabled and client.closed if settings.modules.reconnect.enabled and client.closed
client.server.destroy() if client.server and !client.had_new_reconnection
client.server.destroy()
else else
client.destroy() client.destroy()
return return
...@@ -940,8 +941,6 @@ class Room ...@@ -940,8 +941,6 @@ class Room
@duel_count = 0 @duel_count = 0
@death = 0 @death = 0
@turn = 0 @turn = 0
if settings.modules.challonge.enabled
@challonge_duel_log = {}
ROOM_all.push this ROOM_all.push this
@hostinfo ||= JSON.parse(JSON.stringify(settings.hostinfo)) @hostinfo ||= JSON.parse(JSON.stringify(settings.hostinfo))
...@@ -1158,11 +1157,11 @@ class Room ...@@ -1158,11 +1157,11 @@ class Room
# log.info 'SCORE POST OK', response.statusCode, response.statusMessage, @name, body # log.info 'SCORE POST OK', response.statusCode, response.statusMessage, @name, body
return return
if settings.modules.challonge.enabled and @started and !@kicked if settings.modules.challonge.enabled and @started and @hostinfo.mode != 2 and !@kicked
challonge.matches.update({ challonge.matches.update({
id: settings.modules.challonge.tournament_id, id: settings.modules.challonge.tournament_id,
matchId: @challonge_info.id, matchId: @challonge_info.id,
match: @challonge_duel_log, match: @get_challonge_score(),
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)
...@@ -1240,6 +1239,33 @@ class Room ...@@ -1240,6 +1239,33 @@ class Room
found++ found++
return found return found
get_challonge_score: ->
if !settings.modules.challonge.enabled or !@started or @hostinfo.mode == 2
return null
challonge_duel_log = {}
if @scores[@dueling_players[0].name] > @scores[@dueling_players[1].name]
challonge_duel_log.winnerId = @dueling_players[0].challonge_info.id
else if @scores[@dueling_players[0].name] < @scores[@dueling_players[1].name]
challonge_duel_log.winnerId = @dueling_players[1].challonge_info.id
else
challonge_duel_log.winnerId = "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] + "-" + @scores[@dueling_players[1].name]
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] + "-" + @scores[@dueling_players[0].name]
else
challonge_duel_log.scoresCsv = "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"
else
challonge_duel_log.scoresCsv = "0-0"
return challonge_duel_log
add_windbot: (botdata)-> add_windbot: (botdata)->
@windbot = botdata @windbot = botdata
request request
...@@ -1893,7 +1919,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)-> ...@@ -1893,7 +1919,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
return return
found = false found = false
for k,match of data for k,match of data
if match and match.match and !match.match.winnerId and match.match.player1Id and match.match.player2Id and (match.match.player1Id == client.challonge_info.id or match.match.player2Id == client.challonge_info.id) 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 found = match.match
break break
if !found if !found
...@@ -2279,28 +2305,6 @@ ygopro.stoc_follow 'GAME_MSG', true, (buffer, info, client, server)-> ...@@ -2279,28 +2305,6 @@ ygopro.stoc_follow 'GAME_MSG', true, (buffer, info, client, server)->
else if room.hostinfo.mode == 2 and settings.modules.vip.enabled and room.dueling_players[pos + 1].vip and vip_info.players[room.dueling_players[pos + 1].name].victory else if room.hostinfo.mode == 2 and settings.modules.vip.enabled and room.dueling_players[pos + 1].vip and vip_info.players[room.dueling_players[pos + 1].name].victory
for line in _.lines vip_info.players[room.dueling_players[pos + 1].name].victory for line in _.lines vip_info.players[room.dueling_players[pos + 1].name].victory
ygopro.stoc_send_chat_to_room(room, line, ygopro.constants.COLORS.PINK) ygopro.stoc_send_chat_to_room(room, line, ygopro.constants.COLORS.PINK)
if settings.modules.challonge.enabled and !room.kicked
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 settings.modules.challonge.post_detailed_score
if room.dueling_players[0].challonge_info.id == room.challonge_info.player1Id and room.dueling_players[1].challonge_info.id == room.challonge_info.player2Id
room.challonge_duel_log.scoresCsv = room.scores[room.dueling_players[0].name] + "-" + room.scores[room.dueling_players[1].name]
else if room.dueling_players[1].challonge_info.id == room.challonge_info.player1Id and room.dueling_players[0].challonge_info.id == room.challonge_info.player2Id
room.challonge_duel_log.scoresCsv = room.scores[room.dueling_players[1].name] + "-" + room.scores[room.dueling_players[0].name]
else
room.challonge_duel_log.scoresCsv = "0-0"
log.warn("Score mismatch.", room.name)
else
if room.challonge_duel_log.winnerId == room.challonge_info.player1Id
room.challonge_duel_log.scoresCsv = "1-0"
else if room.challonge_duel_log.winnerId == room.challonge_info.player2Id
room.challonge_duel_log.scoresCsv = "0-1"
else
room.challonge_duel_log.scoresCsv = "0-0"
if room.death if room.death
if settings.modules.http.quick_death_rule == 1 or settings.modules.http.quick_death_rule == 3 if settings.modules.http.quick_death_rule == 1 or settings.modules.http.quick_death_rule == 3
room.death = -1 room.death = -1
...@@ -3239,8 +3243,8 @@ ygopro.stoc_follow 'CHANGE_SIDE', false, (buffer, info, client, server)-> ...@@ -3239,8 +3243,8 @@ 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) ygopro.stoc_send_chat(client, "${side_remain_part1}#{client.side_tcount}${side_remain_part2}", ygopro.constants.COLORS.BABYBLUE)
, 60000 , 60000
client.side_interval = sinterval client.side_interval = sinterval
if settings.modules.challonge.enabled and settings.modules.challonge.post_score_midduel and client.pos == 0 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.challonge_duel_log)) temp_log = JSON.parse(JSON.stringify(room.get_challonge_score()))
delete temp_log.winnerId delete temp_log.winnerId
challonge.matches.update({ challonge.matches.update({
id: settings.modules.challonge.tournament_id, id: settings.modules.challonge.tournament_id,
......
...@@ -795,7 +795,9 @@ ...@@ -795,7 +795,9 @@
CLIENT_kick = function(client) { CLIENT_kick = function(client) {
client.system_kicked = true; client.system_kicked = true;
if (settings.modules.reconnect.enabled && client.closed) { if (settings.modules.reconnect.enabled && client.closed) {
client.server.destroy(); if (client.server && !client.had_new_reconnection) {
client.server.destroy();
}
} else { } else {
client.destroy(); client.destroy();
} }
...@@ -1204,9 +1206,6 @@ ...@@ -1204,9 +1206,6 @@
this.duel_count = 0; this.duel_count = 0;
this.death = 0; this.death = 0;
this.turn = 0; this.turn = 0;
if (settings.modules.challonge.enabled) {
this.challonge_duel_log = {};
}
ROOM_all.push(this); ROOM_all.push(this);
this.hostinfo || (this.hostinfo = JSON.parse(JSON.stringify(settings.hostinfo))); this.hostinfo || (this.hostinfo = JSON.parse(JSON.stringify(settings.hostinfo)));
delete this.hostinfo.comment; delete this.hostinfo.comment;
...@@ -1493,11 +1492,11 @@ ...@@ -1493,11 +1492,11 @@
}; };
})(this)); })(this));
} }
if (settings.modules.challonge.enabled && this.started && !this.kicked) { if (settings.modules.challonge.enabled && this.started && this.hostinfo.mode !== 2 && !this.kicked) {
challonge.matches.update({ challonge.matches.update({
id: settings.modules.challonge.tournament_id, id: settings.modules.challonge.tournament_id,
matchId: this.challonge_info.id, matchId: this.challonge_info.id,
match: this.challonge_duel_log, match: this.get_challonge_score(),
callback: function(err, data) { callback: function(err, data) {
if (err) { if (err) {
log.warn("Errored pushing scores to Challonge.", err); log.warn("Errored pushing scores to Challonge.", err);
...@@ -1599,6 +1598,40 @@ ...@@ -1599,6 +1598,40 @@
return found; return found;
}; };
Room.prototype.get_challonge_score = function() {
var challonge_duel_log;
if (!settings.modules.challonge.enabled || !this.started || this.hostinfo.mode === 2) {
return null;
}
challonge_duel_log = {};
if (this.scores[this.dueling_players[0].name] > this.scores[this.dueling_players[1].name]) {
challonge_duel_log.winnerId = this.dueling_players[0].challonge_info.id;
} else if (this.scores[this.dueling_players[0].name] < this.scores[this.dueling_players[1].name]) {
challonge_duel_log.winnerId = this.dueling_players[1].challonge_info.id;
} else {
challonge_duel_log.winnerId = "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] + "-" + this.scores[this.dueling_players[1].name];
} 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] + "-" + this.scores[this.dueling_players[0].name];
} else {
challonge_duel_log.scoresCsv = "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";
} else {
challonge_duel_log.scoresCsv = "0-0";
}
}
return challonge_duel_log;
};
Room.prototype.add_windbot = function(botdata) { Room.prototype.add_windbot = function(botdata) {
this.windbot = botdata; this.windbot = botdata;
request({ request({
...@@ -2349,7 +2382,7 @@ ...@@ -2349,7 +2382,7 @@
found = false; found = false;
for (k in data) { for (k in data) {
match = data[k]; match = data[k];
if (match && match.match && !match.match.winnerId && match.match.player1Id && match.match.player2Id && (match.match.player1Id === client.challonge_info.id || match.match.player2Id === client.challonge_info.id)) { 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; found = match.match;
break; break;
} }
...@@ -2800,33 +2833,6 @@ ...@@ -2800,33 +2833,6 @@
} }
} }
} }
if (settings.modules.challonge.enabled && !room.kicked) {
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 (settings.modules.challonge.post_detailed_score) {
if (room.dueling_players[0].challonge_info.id === room.challonge_info.player1Id && room.dueling_players[1].challonge_info.id === room.challonge_info.player2Id) {
room.challonge_duel_log.scoresCsv = room.scores[room.dueling_players[0].name] + "-" + room.scores[room.dueling_players[1].name];
} else if (room.dueling_players[1].challonge_info.id === room.challonge_info.player1Id && room.dueling_players[0].challonge_info.id === room.challonge_info.player2Id) {
room.challonge_duel_log.scoresCsv = room.scores[room.dueling_players[1].name] + "-" + room.scores[room.dueling_players[0].name];
} else {
room.challonge_duel_log.scoresCsv = "0-0";
log.warn("Score mismatch.", room.name);
}
} else {
if (room.challonge_duel_log.winnerId === room.challonge_info.player1Id) {
room.challonge_duel_log.scoresCsv = "1-0";
} else if (room.challonge_duel_log.winnerId === room.challonge_info.player2Id) {
room.challonge_duel_log.scoresCsv = "0-1";
} else {
room.challonge_duel_log.scoresCsv = "0-0";
}
}
}
if (room.death) { if (room.death) {
if (settings.modules.http.quick_death_rule === 1 || settings.modules.http.quick_death_rule === 3) { if (settings.modules.http.quick_death_rule === 1 || settings.modules.http.quick_death_rule === 3) {
room.death = -1; room.death = -1;
...@@ -4130,8 +4136,8 @@ ...@@ -4130,8 +4136,8 @@
}, 60000); }, 60000);
client.side_interval = sinterval; client.side_interval = sinterval;
} }
if (settings.modules.challonge.enabled && settings.modules.challonge.post_score_midduel && client.pos === 0) { 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.challonge_duel_log)); temp_log = JSON.parse(JSON.stringify(room.get_challonge_score()));
delete temp_log.winnerId; delete temp_log.winnerId;
challonge.matches.update({ challonge.matches.update({
id: settings.modules.challonge.tournament_id, id: settings.modules.challonge.tournament_id,
......
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