From 0a1c14c4f7dddab86625bf9a8322006463dd8517 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=A4=AA?= Date: Sat, 22 Mar 2014 19:06:32 +1100 Subject: [PATCH 1/4] Add error messages for tournaments --- js/client-chat-tournament.js | 38 ++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/js/client-chat-tournament.js b/js/client-chat-tournament.js index 643a28441d..25dee55339 100644 --- a/js/client-chat-tournament.js +++ b/js/client-chat-tournament.js @@ -391,6 +391,44 @@ this.room.$chat.append("
The tournament was forcibly ended.
"); break; + case 'error': + var appendError = (function(message) { + this.room.$chat.append("
" + message + "
"); + }).bind(this); + + switch (data[0]) { + case 'BracketFrozen': + case 'AlreadyStarted': + appendError("The tournament has already started."); + break; + + case 'BracketNotFrozen': + case 'NotStarted': + appendError("The tournament hasn't started yet."); + break; + + case 'UserAlreadyAdded': + appendError("You are already in the tournament."); + break; + + case 'AltUserAlreadyAdded': + appendError("One of your alts is already in the tournament."); + break; + + case 'UserNotAdded': + appendError("You aren't in the tournament."); + break; + + case 'InvalidMatch': + appendError("That isn't a valid tournament matchup."); + break; + + default: + appendError("Unknown error: " + data[0]); + break; + } + break; + default: return true; } From 63bb1ecc408fc4533f424b176564b2dc603fd765 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=A4=AA?= Date: Sat, 22 Mar 2014 20:04:26 +1100 Subject: [PATCH 2/4] Implement the tournaments info packet handler --- js/client-chat-tournament.js | 19 ++++++++++++++++--- style/client.css | 6 ++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/js/client-chat-tournament.js b/js/client-chat-tournament.js index 25dee55339..1f755da9d0 100644 --- a/js/client-chat-tournament.js +++ b/js/client-chat-tournament.js @@ -216,11 +216,24 @@ TournamentBox.prototype.parseMessage = function (data, isBroadcast) { if (Config.server.id !== "battletower") return true; + var cmd = data.shift().toLowerCase(); if (isBroadcast) { - // TODO - return true; + switch (cmd) { + case 'info': + var $infoList = $(''); + JSON.parse(data.join('|')).forEach(function (tournament) { + var $info = $('
  • '); + $info.text(": " + BattleFormats[tournament.format].name + " " + tournament.generator + (tournament.isStarted ? " (Started)" : "")); + $info.prepend($('').attr('href', app.root + toRoomid(tournament.room).toLowerCase()).text(tournament.room)); + $infoList.append($info); + }); + this.room.$chat.append($('
    ').append($('
    ').append($infoList))); + break; + + default: + return true; + } } else { - var cmd = data.shift().toLowerCase(); switch (cmd) { case 'create': var format = BattleFormats[data[0]].name; diff --git a/style/client.css b/style/client.css index b8e4f40df7..69576511a0 100644 --- a/style/client.css +++ b/style/client.css @@ -981,6 +981,12 @@ a.ilink:hover { /* Tournaments */ +.tournaments-info > ul { + list-style: none; + margin: 0; + padding: 0; +} + .tournament-wrapper { display: none; position: absolute; From e246b3c626594560858fdb5f2fefc2aec61863be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=A4=AA?= Date: Sat, 22 Mar 2014 20:07:46 +1100 Subject: [PATCH 3/4] Add tournament error handler for 'NotEnoughUsers' --- js/client-chat-tournament.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/js/client-chat-tournament.js b/js/client-chat-tournament.js index 1f755da9d0..f0bacdaacd 100644 --- a/js/client-chat-tournament.js +++ b/js/client-chat-tournament.js @@ -432,6 +432,10 @@ appendError("You aren't in the tournament."); break; + case 'NotEnoughUsers': + appendError("There isn't enough users."); + break; + case 'InvalidMatch': appendError("That isn't a valid tournament matchup."); break; From 5724863637a3ab34921dff97a6de2fd0f670b505 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=A4=AA?= Date: Sat, 22 Mar 2014 20:08:23 +1100 Subject: [PATCH 4/4] Lift battletower-only restriction on tournaments --- js/client-chat-tournament.js | 1 - 1 file changed, 1 deletion(-) diff --git a/js/client-chat-tournament.js b/js/client-chat-tournament.js index f0bacdaacd..70db6e6941 100644 --- a/js/client-chat-tournament.js +++ b/js/client-chat-tournament.js @@ -215,7 +215,6 @@ }; TournamentBox.prototype.parseMessage = function (data, isBroadcast) { - if (Config.server.id !== "battletower") return true; var cmd = data.shift().toLowerCase(); if (isBroadcast) { switch (cmd) {