From a1b531d1222a6897ca70cfedd994f36ba97d97a7 Mon Sep 17 00:00:00 2001 From: marcins78 Date: Wed, 2 Jan 2013 16:42:05 +0000 Subject: [PATCH] UI now specifies, which queue to leave, and also added dropping from tournaments. --- .../com/gempukku/lotro/hall/HallServer.java | 26 +++++++++++++++++-- .../gempukku/lotro/server/HallResource.java | 17 ++++++++++-- .../main/webapp/js/gemp-014/communication.js | 15 +++++++++-- .../src/main/webapp/js/gemp-014/hallUi.js | 24 ++++++++--------- 4 files changed, 63 insertions(+), 19 deletions(-) diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/HallServer.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/HallServer.java index 71a2844fd..e2bd28210 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/HallServer.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/HallServer.java @@ -225,7 +225,18 @@ public class HallServer extends AbstractServer { } } - public void leaveQueues(Player player) { + public void leaveQueue(String queueId, Player player) { + _hallDataAccessLock.writeLock().lock(); + try { + TournamentQueue tournamentQueue = _tournamentQueues.get(queueId); + if (tournamentQueue != null && tournamentQueue.isPlayerSignedUp(player.getName())) + tournamentQueue.leavePlayer(_collectionsManager, player); + } finally { + _hallDataAccessLock.writeLock().unlock(); + } + } + + private void leaveQueues(Player player) { _hallDataAccessLock.writeLock().lock(); try { for (TournamentQueue tournamentQueue : _tournamentQueues.values()) { @@ -237,6 +248,17 @@ public class HallServer extends AbstractServer { } } + public void dropFromTournament(String tournamentId, Player player) { + _hallDataAccessLock.writeLock().lock(); + try { + Tournament tournament = _runningTournaments.get(tournamentId); + if (tournament != null) + tournament.dropPlayer(player.getName()); + } finally { + _hallDataAccessLock.writeLock().unlock(); + } + } + public void leaveAwaitingTables(Player player) { _hallDataAccessLock.writeLock().lock(); try { @@ -346,7 +368,7 @@ public class HallServer extends AbstractServer { tournamentQueue.getPlayerCount(), tournamentQueue.isPlayerSignedUp(player.getName())); } - for (Map.Entry tournamentEntry: _runningTournaments.entrySet()){ + for (Map.Entry tournamentEntry : _runningTournaments.entrySet()) { String tournamentKey = tournamentEntry.getKey(); Tournament tournament = tournamentEntry.getValue(); visitor.visitTournament(tournamentKey, tournament.getCollectionType().getFullName(), diff --git a/gemp-lotr/gemp-lotr-web-server/src/main/java/com/gempukku/lotro/server/HallResource.java b/gemp-lotr/gemp-lotr-web-server/src/main/java/com/gempukku/lotro/server/HallResource.java index 10b323232..d9f9cd53d 100644 --- a/gemp-lotr/gemp-lotr-web-server/src/main/java/com/gempukku/lotro/server/HallResource.java +++ b/gemp-lotr/gemp-lotr-web-server/src/main/java/com/gempukku/lotro/server/HallResource.java @@ -207,14 +207,27 @@ public class HallResource extends AbstractResource { } } - @Path("/queue/leave") + @Path("/queue/{queueId}/leave") @POST public void leaveQueue( + @PathParam("queueId") String queueId, @FormParam("participantId") String participantId, @Context HttpServletRequest request) throws ParserConfigurationException { Player resourceOwner = getResourceOwnerSafely(request, participantId); - _hallServer.leaveQueues(resourceOwner); + _hallServer.leaveQueue(queueId, resourceOwner); + } + + @Path("/tournament/{tournamentId}/leave") + @POST + public Document dropFromTournament( + @PathParam("tournamentId") String tournamentId, + @FormParam("participantId") String participantId, + @Context HttpServletRequest request) throws ParserConfigurationException { + Player resourceOwner = getResourceOwnerSafely(request, participantId); + + _hallServer.dropFromTournament(tournamentId, resourceOwner); + return null; } @Path("/{table}") diff --git a/gemp-lotr/gemp-lotr-web/src/main/webapp/js/gemp-014/communication.js b/gemp-lotr/gemp-lotr-web/src/main/webapp/js/gemp-014/communication.js index b5e888a20..f80e205e1 100644 --- a/gemp-lotr/gemp-lotr-web/src/main/webapp/js/gemp-014/communication.js +++ b/gemp-lotr/gemp-lotr-web/src/main/webapp/js/gemp-014/communication.js @@ -525,10 +525,21 @@ var GempLotrCommunication = Class.extend({ dataType:"xml" }); }, - leaveQueue:function (errorMap) { + leaveQueue:function (queueId, errorMap) { $.ajax({ type:"POST", - url:this.url + "/hall/queue/leave", + url:this.url + "/hall/queue/"+queueId+"/leave", + cache:false, + data:{ + participantId:getUrlParam("participantId")}, + error:this.errorCheck(errorMap), + dataType:"xml" + }); + }, + dropFromTournament:function(tournamentId, callback, errorMap) { + $.ajax({ + type:"POST", + url:this.url + "/hall/tournament/"+tournamentId+"/leave", cache:false, data:{ participantId:getUrlParam("participantId")}, diff --git a/gemp-lotr/gemp-lotr-web/src/main/webapp/js/gemp-014/hallUi.js b/gemp-lotr/gemp-lotr-web/src/main/webapp/js/gemp-014/hallUi.js index 14107443e..eea3aea98 100644 --- a/gemp-lotr/gemp-lotr-web/src/main/webapp/js/gemp-014/hallUi.js +++ b/gemp-lotr/gemp-lotr-web/src/main/webapp/js/gemp-014/hallUi.js @@ -372,11 +372,9 @@ var GempLotrHallUI = Class.extend({ $(but).button().click(( function(queueId) { return function() { - var deck = that.decksSelect.val(); - if (deck != null) - that.comm.leaveQueue(id, deck, function (xml) { - that.processResponse(xml); - }); + that.comm.leaveQueue(queueId, function (xml) { + that.processResponse(xml); + }); } })(id)); actionsField.append(but); @@ -419,9 +417,9 @@ var GempLotrHallUI = Class.extend({ $(but).button().click(( function(tournamentId) { return function () { - that.comm.dropFromTournament(tournamentId, function (xml) { - that.processResponse(xml); - }); + that.comm.dropFromTournament(tournamentId, function (xml) { + that.processResponse(xml); + }); }; } )(id)); @@ -559,11 +557,11 @@ var GempLotrHallUI = Class.extend({ } } - $(".count", $(".eventHeader.queues")).html("("+($("tr", $("table.queues")).length-1)+")"); - $(".count", $(".eventHeader.tournaments")).html("("+($("tr", $("table.tournaments")).length-1)+")"); - $(".count", $(".eventHeader.waitingTables")).html("("+($("tr", $("table.waitingTables")).length-1)+")"); - $(".count", $(".eventHeader.playingTables")).html("("+($("tr", $("table.playingTables")).length-1)+")"); - $(".count", $(".eventHeader.finishedTables")).html("("+($("tr", $("table.finishedTables")).length-1)+")"); + $(".count", $(".eventHeader.queues")).html("(" + ($("tr", $("table.queues")).length - 1) + ")"); + $(".count", $(".eventHeader.tournaments")).html("(" + ($("tr", $("table.tournaments")).length - 1) + ")"); + $(".count", $(".eventHeader.waitingTables")).html("(" + ($("tr", $("table.waitingTables")).length - 1) + ")"); + $(".count", $(".eventHeader.playingTables")).html("(" + ($("tr", $("table.playingTables")).length - 1) + ")"); + $(".count", $(".eventHeader.finishedTables")).html("(" + ($("tr", $("table.finishedTables")).length - 1) + ")"); var skipReload = false; var games = root.getElementsByTagName("game");