diff --git a/gemp-lotr/gemp-lotr-async/src/main/java/com/gempukku/lotro/async/handler/HallRequestHandler.java b/gemp-lotr/gemp-lotr-async/src/main/java/com/gempukku/lotro/async/handler/HallRequestHandler.java index f631abdfc..4bc5c9121 100644 --- a/gemp-lotr/gemp-lotr-async/src/main/java/com/gempukku/lotro/async/handler/HallRequestHandler.java +++ b/gemp-lotr/gemp-lotr-async/src/main/java/com/gempukku/lotro/async/handler/HallRequestHandler.java @@ -539,6 +539,13 @@ public class HallRequestHandler extends LotroServerRequestHandler implements Uri _hall.setAttribute("channelNumber", String.valueOf(channelNumber)); } + @Override + public void newPlayerGame(String gameId) { + Element newGame = _doc.createElement("newGame"); + newGame.setAttribute("id", gameId); + _hall.appendChild(newGame); + } + @Override public void serverTime(String serverTime) { _hall.setAttribute("serverTime", serverTime); @@ -632,17 +639,5 @@ public class HallRequestHandler extends LotroServerRequestHandler implements Uri table.setAttribute("id", tableId); _hall.appendChild(table); } - - @Override - public void runningPlayerGame(String gameId) { - Element runningGame = _doc.createElement("game"); - runningGame.setAttribute("id", gameId); - _hall.appendChild(runningGame); - } - - @Override - public void playerBusy(boolean busy) { - _hall.setAttribute("busy", String.valueOf(busy)); - } } } diff --git a/gemp-lotr/gemp-lotr-async/src/main/web/css/gemp-001/hall.css b/gemp-lotr/gemp-lotr-async/src/main/web/css/gemp-001/hall.css index 6c42685eb..fdbd593f2 100644 --- a/gemp-lotr/gemp-lotr-async/src/main/web/css/gemp-001/hall.css +++ b/gemp-lotr/gemp-lotr-async/src/main/web/css/gemp-001/hall.css @@ -168,3 +168,7 @@ table.tables td, table.tables th { .userList { border-left: 1px solid #FFFFFF; } + +tr.played { + background-color: #990000; +} \ No newline at end of file diff --git a/gemp-lotr/gemp-lotr-async/src/main/web/js/gemp-015/hallUi.js b/gemp-lotr/gemp-lotr-async/src/main/web/js/gemp-015/hallUi.js index e68a9cbc7..c33b2b866 100644 --- a/gemp-lotr/gemp-lotr-async/src/main/web/js/gemp-015/hallUi.js +++ b/gemp-lotr/gemp-lotr-async/src/main/web/js/gemp-015/hallUi.js @@ -42,14 +42,14 @@ var GempLotrHallUI = Class.extend({ var hallSettingsStr = $.cookie("hallSettings"); if (hallSettingsStr == null) - hallSettingsStr="0|0|1|1|0"; + hallSettingsStr = "0|0|1|1|0"; var hallSettings = hallSettingsStr.split("|"); - this.addQueuesTable(hallSettings[0]=="1"); - this.addTournamentsTable(hallSettings[1]=="1"); - this.addWaitingTablesTable(hallSettings[2]=="1"); - this.addPlayingTablesTable(hallSettings[3]=="1"); - this.addFinishedTablesTable(hallSettings[4]=="1"); + this.addQueuesTable(hallSettings[0] == "1"); + this.addTournamentsTable(hallSettings[1] == "1"); + this.addWaitingTablesTable(hallSettings[2] == "1"); + this.addPlayingTablesTable(hallSettings[3] == "1"); + this.addFinishedTablesTable(hallSettings[4] == "1"); this.div.append(this.tablesDiv); @@ -122,14 +122,14 @@ var GempLotrHallUI = Class.extend({ }); var that = this; - var toggle =function() { - if (toggleContent.button("option", "icons")["primary"] == "ui-icon-circlesmall-minus") - toggleContent.button("option", "icons", {primary: "ui-icon-circlesmall-plus"}); - else - toggleContent.button("option", "icons", {primary: "ui-icon-circlesmall-minus"}); - content.toggle("blind", {}, 200); - that.updateHallSettings(); - }; + var toggle = function() { + if (toggleContent.button("option", "icons")["primary"] == "ui-icon-circlesmall-minus") + toggleContent.button("option", "icons", {primary: "ui-icon-circlesmall-plus"}); + else + toggleContent.button("option", "icons", {primary: "ui-icon-circlesmall-minus"}); + content.toggle("blind", {}, 200); + that.updateHallSettings(); + }; toggleContent.css({width: "13px", height: "15px"}); toggleContent.click(toggle); @@ -163,14 +163,14 @@ var GempLotrHallUI = Class.extend({ }); var that = this; - var toggle=function() { - if (toggleContent.button("option", "icons")["primary"] == "ui-icon-circlesmall-minus") - toggleContent.button("option", "icons", {primary: "ui-icon-circlesmall-plus"}); - else - toggleContent.button("option", "icons", {primary: "ui-icon-circlesmall-minus"}); - content.toggle("blind", {}, 200); + var toggle = function() { + if (toggleContent.button("option", "icons")["primary"] == "ui-icon-circlesmall-minus") + toggleContent.button("option", "icons", {primary: "ui-icon-circlesmall-plus"}); + else + toggleContent.button("option", "icons", {primary: "ui-icon-circlesmall-minus"}); + content.toggle("blind", {}, 200); that.updateHallSettings(); - }; + }; toggleContent.css({width: "13px", height: "15px"}); toggleContent.click(toggle); header.append(toggleContent); @@ -203,14 +203,14 @@ var GempLotrHallUI = Class.extend({ }); var that = this; - var toggle=function() { - if (toggleContent.button("option", "icons")["primary"] == "ui-icon-circlesmall-minus") - toggleContent.button("option", "icons", {primary: "ui-icon-circlesmall-plus"}); - else - toggleContent.button("option", "icons", {primary: "ui-icon-circlesmall-minus"}); - content.toggle("blind", {}, 200); - that.updateHallSettings(); - }; + var toggle = function() { + if (toggleContent.button("option", "icons")["primary"] == "ui-icon-circlesmall-minus") + toggleContent.button("option", "icons", {primary: "ui-icon-circlesmall-plus"}); + else + toggleContent.button("option", "icons", {primary: "ui-icon-circlesmall-minus"}); + content.toggle("blind", {}, 200); + that.updateHallSettings(); + }; toggleContent.css({width: "13px", height: "15px"}); toggleContent.click(toggle); header.append(toggleContent); @@ -243,14 +243,14 @@ var GempLotrHallUI = Class.extend({ }); var that = this; - var toggle=function() { - if (toggleContent.button("option", "icons")["primary"] == "ui-icon-circlesmall-minus") - toggleContent.button("option", "icons", {primary: "ui-icon-circlesmall-plus"}); - else - toggleContent.button("option", "icons", {primary: "ui-icon-circlesmall-minus"}); - content.toggle("blind", {}, 200); + var toggle = function() { + if (toggleContent.button("option", "icons")["primary"] == "ui-icon-circlesmall-minus") + toggleContent.button("option", "icons", {primary: "ui-icon-circlesmall-plus"}); + else + toggleContent.button("option", "icons", {primary: "ui-icon-circlesmall-minus"}); + content.toggle("blind", {}, 200); that.updateHallSettings(); - }; + }; toggleContent.css({width: "13px", height: "15px"}); toggleContent.click(toggle); header.append(toggleContent); @@ -283,14 +283,14 @@ var GempLotrHallUI = Class.extend({ }); var that = this; - var toggle=function() { - if (toggleContent.button("option", "icons")["primary"] == "ui-icon-circlesmall-minus") - toggleContent.button("option", "icons", {primary: "ui-icon-circlesmall-plus"}); - else - toggleContent.button("option", "icons", {primary: "ui-icon-circlesmall-minus"}); - content.toggle("blind", {}, 200); + var toggle = function() { + if (toggleContent.button("option", "icons")["primary"] == "ui-icon-circlesmall-minus") + toggleContent.button("option", "icons", {primary: "ui-icon-circlesmall-plus"}); + else + toggleContent.button("option", "icons", {primary: "ui-icon-circlesmall-minus"}); + content.toggle("blind", {}, 200); that.updateHallSettings(); - }; + }; toggleContent.css({width: "13px", height: "15px"}); toggleContent.click(toggle); header.append(toggleContent); @@ -312,12 +312,12 @@ var GempLotrHallUI = Class.extend({ updateHallSettings: function() { var icons = $(".ui-button-icon-primary", this.tablesDiv); - var getSettingValue= + var getSettingValue = function(index) { - return $(icons[index]).hasClass("ui-icon-circlesmall-minus")?"1":"0"; + return $(icons[index]).hasClass("ui-icon-circlesmall-minus") ? "1" : "0"; }; - var newHallSettings = getSettingValue(0)+"|"+getSettingValue(1)+"|"+getSettingValue(2)+"|"+getSettingValue(3)+"|"+getSettingValue(4); + var newHallSettings = getSettingValue(0) + "|" + getSettingValue(1) + "|" + getSettingValue(2) + "|" + getSettingValue(3) + "|" + getSettingValue(4); $.cookie("hallSettings", newHallSettings, { expires:365 }); }, @@ -444,8 +444,6 @@ var GempLotrHallUI = Class.extend({ if (serverTime != null) $(".serverTime").text("Server time: " + serverTime); - var busy = root.getAttribute("busy") == "true"; - var queues = root.getElementsByTagName("queue"); for (var i = 0; i < queues.length; i++) { var queue = queues[i]; @@ -571,6 +569,7 @@ var GempLotrHallUI = Class.extend({ var players = new Array(); if (playersAttr.length > 0) players = playersAttr.split(","); + var playing = table.getAttribute("playing"); var winner = table.getAttribute("winner"); var row = $(""); @@ -588,7 +587,7 @@ var GempLotrHallUI = Class.extend({ row.append("" + playersStr + ""); var lastField = $(""); - if (status == "WAITING" && !busy) { + if (status == "WAITING") { var that = this; var but = $(""); @@ -605,7 +604,14 @@ var GempLotrHallUI = Class.extend({ lastField.append(but); } - if (status == "PLAYING" && watchable == "true") { + if (playing == "true") { + var participantId = getUrlParam("participantId"); + var participantIdAppend = ""; + if (participantId != null) + participantIdAppend = "&participantId=" + participantId; + + lastField.append("Play the game"); + } else if (status == "PLAYING" && watchable == "true") { var participantId = getUrlParam("participantId"); var participantIdAppend = ""; if (participantId != null) @@ -659,6 +665,8 @@ var GempLotrHallUI = Class.extend({ } this.animateRowUpdate(".table" + id); + if (playing) + row.addClass("played"); } } else if (action == "remove") { $(".table" + id, this.tablesDiv).remove(); @@ -671,8 +679,7 @@ var GempLotrHallUI = Class.extend({ $(".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"); + var games = root.getElementsByTagName("newGame"); if (games.length > 0) { var waitingGameId = games[0].getAttribute("id"); var participantId = getUrlParam("participantId"); @@ -680,8 +687,7 @@ var GempLotrHallUI = Class.extend({ if (participantId != null) participantIdAppend = "&participantId=" + participantId; this.tablesDiv.append(""); - skipReload = true; - setTimeout("location.href = '/gemp-lotr/game.html?gameId=" + waitingGameId + participantIdAppend + "'", 3000); + window.open("/gemp-lotr/game.html?gameId=" + waitingGameId + participantIdAppend, "_blank"); } if (!this.supportedFormatsInitialized) { @@ -694,29 +700,17 @@ var GempLotrHallUI = Class.extend({ this.supportedFormatsInitialized = true; } - if (busy) { - this.supportedFormatsSelect.hide(); - this.decksSelect.hide(); - this.createTableButton.hide(); - if (this.leaveTableButton.css("display") == "none") - this.leaveTableButton.css("display", ""); - } else { - if (this.supportedFormatsSelect.css("display") == "none") - this.supportedFormatsSelect.css("display", ""); - if (this.decksSelect.css("display") == "none") - this.decksSelect.css("display", ""); - if (this.createTableButton.css("display") == "none") - this.createTableButton.css("display", ""); - this.leaveTableButton.hide(); - } + if (this.supportedFormatsSelect.css("display") == "none") + this.supportedFormatsSelect.css("display", ""); + if (this.decksSelect.css("display") == "none") + this.decksSelect.css("display", ""); + if (this.createTableButton.css("display") == "none") + this.createTableButton.css("display", ""); + this.leaveTableButton.hide(); - var that = this; - - if (!skipReload) { - setTimeout(function () { - that.updateHall(); - }, 100); - } + setTimeout(function () { + that.updateHall(); + }, 100); } } }); \ No newline at end of file diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/HallChannelVisitor.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/HallChannelVisitor.java index d56bec629..849e63829 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/HallChannelVisitor.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/HallChannelVisitor.java @@ -7,8 +7,7 @@ public interface HallChannelVisitor { public void motdChanged(String motd); public void serverTime(String serverTime); - public void runningPlayerGame(String gameId); - public void playerBusy(boolean busy); + public void newPlayerGame(String gameId); public void addTournamentQueue(String queueId, Map props); public void updateTournamentQueue(String queueId, Map props); diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/HallCommunicationChannel.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/HallCommunicationChannel.java index 26422ec63..df11e9848 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/HallCommunicationChannel.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/HallCommunicationChannel.java @@ -2,12 +2,10 @@ package com.gempukku.lotro.hall; import com.gempukku.lotro.game.Player; import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang.mutable.MutableBoolean; import org.apache.commons.lang.mutable.MutableObject; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; +import java.util.*; public class HallCommunicationChannel { private int _channelNumber; @@ -16,6 +14,7 @@ public class HallCommunicationChannel { private Map> _tournamentQueuePropsOnClient = new LinkedHashMap>(); private Map> _tournamentPropsOnClient = new LinkedHashMap>(); private Map> _tablePropsOnClient = new LinkedHashMap>(); + private Set _playedGames = new HashSet(); public HallCommunicationChannel(int channelNumber) { _channelNumber = channelNumber; @@ -33,7 +32,7 @@ public class HallCommunicationChannel { return _lastConsumed; } - public synchronized boolean hasChangesInCommunicationChannel(HallServer hallServer, Player player) { + public synchronized boolean hasChangesInCommunicationChannel(HallServer hallServer, final Player player) { updateLastAccess(); final MutableObject newMotd = new MutableObject(); @@ -41,6 +40,7 @@ public class HallCommunicationChannel { final Map> tournamentQueuesOnServer = new LinkedHashMap>(); final Map> tablesOnServer = new LinkedHashMap>(); final Map> tournamentsOnServer = new LinkedHashMap>(); + final MutableBoolean hasNewGames = new MutableBoolean(false); hallServer.processHall(player, new HallInfoVisitor() { @@ -48,10 +48,6 @@ public class HallCommunicationChannel { public void serverTime(String time) { } - @Override - public void playerBusy(boolean busy) { - } - @Override public void motd(String motd) { newMotd.setValue(motd); @@ -67,6 +63,7 @@ public class HallCommunicationChannel { props.put("format", formatName); props.put("tournament", tournamentName); props.put("players", StringUtils.join(playerIds, ",")); + props.put("playing", String.valueOf(playerIds.contains(player.getName()))); if (winner != null) props.put("winner", winner); @@ -109,9 +106,14 @@ public class HallCommunicationChannel { @Override public void runningPlayerGame(String gameId) { + if (!_playedGames.contains(gameId)) + hasNewGames.setValue(true); } }); + if (hasNewGames.booleanValue()) + return true; + if (newMotd.getValue() != null && !newMotd.getValue().equals(_lastMotd)) return true; @@ -142,7 +144,7 @@ public class HallCommunicationChannel { return false; } - public synchronized void processCommunicationChannel(HallServer hallServer, Player player, final HallChannelVisitor hallChannelVisitor) { + public synchronized void processCommunicationChannel(HallServer hallServer, final Player player, final HallChannelVisitor hallChannelVisitor) { updateLastAccess(); hallChannelVisitor.channelNumber(_channelNumber); @@ -151,6 +153,7 @@ public class HallCommunicationChannel { final Map> tournamentQueuesOnServer = new LinkedHashMap>(); final Map> tablesOnServer = new LinkedHashMap>(); final Map> tournamentsOnServer = new LinkedHashMap>(); + final Set playedGamesOnServer = new HashSet(); hallServer.processHall(player, new HallInfoVisitor() { @@ -159,11 +162,6 @@ public class HallCommunicationChannel { hallChannelVisitor.serverTime(time); } - @Override - public void playerBusy(boolean busy) { - hallChannelVisitor.playerBusy(busy); - } - @Override public void motd(String motd) { newMotd.setValue(motd); @@ -179,6 +177,7 @@ public class HallCommunicationChannel { props.put("format", formatName); props.put("tournament", tournamentName); props.put("players", StringUtils.join(playerIds, ",")); + props.put("playing", String.valueOf(playerIds.contains(player.getName()))); if (winner != null) props.put("winner", winner); @@ -221,7 +220,7 @@ public class HallCommunicationChannel { @Override public void runningPlayerGame(String gameId) { - hallChannelVisitor.runningPlayerGame(gameId); + playedGamesOnServer.add(gameId); } }); @@ -239,6 +238,12 @@ public class HallCommunicationChannel { hallChannelVisitor.motdChanged(newMotdStr); _lastMotd = newMotdStr; } + + for (String gameId : playedGamesOnServer) { + if (!_playedGames.contains(gameId)) + hallChannelVisitor.newPlayerGame(gameId); + } + _playedGames = playedGamesOnServer; } private void notifyAboutTables(HallChannelVisitor hallChannelVisitor, Map> tablesOnServer) { diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/HallInfoVisitor.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/HallInfoVisitor.java index f5cd0bc0b..2157cae18 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/HallInfoVisitor.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/HallInfoVisitor.java @@ -9,8 +9,6 @@ public interface HallInfoVisitor { public void serverTime(String time); - public void playerBusy(boolean busy); - public void motd(String motd); public void visitTable(String tableId, String gameId, boolean watchable, TableStatus status, String statusDescription, String formatName, String tournamentName, List playerIds, String winner); 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 ef0e016b0..757955565 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 @@ -157,9 +157,6 @@ public class HallServer extends AbstractServer { _hallDataAccessLock.writeLock().lock(); try { - if (isPlayerBusy(player.getName())) - throw new HallException("You can't start a table, as you are considered busy"); - League league = null; LeagueSerieData leagueSerie = null; CollectionType collectionType = _allCardsCollectionType; @@ -204,9 +201,6 @@ public class HallServer extends AbstractServer { _hallDataAccessLock.writeLock().lock(); try { - if (isPlayerBusy(player.getName())) - throw new HallException("You can't join a queue, as you are considered busy"); - TournamentQueue tournamentQueue = _tournamentQueues.get(queueId); if (tournamentQueue == null) throw new HallException("Tournament queue already finished accepting players, try again in a few seconds"); @@ -234,13 +228,13 @@ public class HallServer extends AbstractServer { _hallDataAccessLock.writeLock().lock(); try { - if (isPlayerBusy(player.getName())) - throw new HallException("You can't join a table, as you are considered busy"); - AwaitingTable awaitingTable = _awaitingTables.get(tableId); if (awaitingTable == null) throw new HallException("Table is already taken or was removed"); + if (awaitingTable.hasPlayer(player.getName())) + throw new HallException("You can't play against yourself"); + if (awaitingTable.getLeague() != null && !_leagueService.isPlayerInLeague(awaitingTable.getLeague(), player)) throw new HallException("You're not in that league"); @@ -444,7 +438,6 @@ public class HallServer extends AbstractServer { _hallDataAccessLock.readLock().lock(); try { visitor.serverTime(DateUtils.getStringDateWithHour()); - visitor.playerBusy(isPlayerBusy(player.getName())); if (_motd != null) visitor.motd(_motd); @@ -647,27 +640,6 @@ public class HallServer extends AbstractServer { } private boolean isPlayerBusy(String playerId) { - for (AwaitingTable awaitingTable : _awaitingTables.values()) - if (awaitingTable.hasPlayer(playerId)) - return true; - - for (RunningTable runningTable : _runningTables.values()) { - String gameId = runningTable.getGameId(); - LotroGameMediator lotroGameMediator = _lotroServer.getGameById(gameId); - if (lotroGameMediator != null && !lotroGameMediator.isFinished() && lotroGameMediator.getPlayersPlaying().contains(playerId)) - return true; - } - - for (TournamentQueue tournamentQueue : _tournamentQueues.values()) { - if (tournamentQueue.isPlayerSignedUp(playerId)) - return true; - } - - for (Tournament runningTournament : _runningTournaments.values()) { - if (runningTournament.isPlayerInCompetition(playerId)) - return true; - } - return false; }