From afd9cd235396700ffa05bed9f75c052748d60039 Mon Sep 17 00:00:00 2001 From: marcins78 Date: Fri, 18 Jan 2013 14:21:33 +0000 Subject: [PATCH] Giving direct access to GatheringParticipantCommunicationChannel. --- .../async/handler/GameRequestHandler.java | 6 ++- .../lotro/game/LotroGameMediator.java | 46 ++++++------------- 2 files changed, 18 insertions(+), 34 deletions(-) diff --git a/gemp-lotr/gemp-lotr-async/src/main/java/com/gempukku/lotro/async/handler/GameRequestHandler.java b/gemp-lotr/gemp-lotr-async/src/main/java/com/gempukku/lotro/async/handler/GameRequestHandler.java index e3c18aad9..49bd2762b 100644 --- a/gemp-lotr/gemp-lotr-async/src/main/java/com/gempukku/lotro/async/handler/GameRequestHandler.java +++ b/gemp-lotr/gemp-lotr-async/src/main/java/com/gempukku/lotro/async/handler/GameRequestHandler.java @@ -14,6 +14,7 @@ import com.gempukku.lotro.game.ParticipantCommunicationVisitor; import com.gempukku.lotro.game.Player; import com.gempukku.lotro.game.state.EventSerializer; import com.gempukku.lotro.game.state.GameEvent; +import com.gempukku.lotro.game.state.GatheringParticipantCommunicationChannel; import org.jboss.netty.channel.MessageEvent; import org.jboss.netty.handler.codec.http.*; import org.jboss.netty.handler.codec.http.multipart.HttpPostRequestDecoder; @@ -108,7 +109,7 @@ public class GameRequestHandler extends LotroServerRequestHandler implements Uri @Override public boolean isChanged() { try { - return _gameMediator.hasAnyNewMessages(_resourceOwner, _channelNumber); + return _gameMediator.getCommunicationChannel(_resourceOwner, _channelNumber).hasGameEvents(); } catch (PrivateInformationException e) { return true; } catch (SubscriptionExpiredException e) { @@ -127,7 +128,8 @@ public class GameRequestHandler extends LotroServerRequestHandler implements Uri Document doc = documentBuilder.newDocument(); Element update = doc.createElement("update"); - _gameMediator.processCommunicationChannel(_resourceOwner, _channelNumber, new SerializationVisitor(doc, update)); + GatheringParticipantCommunicationChannel communicationChannel = _gameMediator.getCommunicationChannel(_resourceOwner, _channelNumber); + _gameMediator.processVisitor(communicationChannel, _channelNumber, _resourceOwner.getName(), new SerializationVisitor(doc, update)); doc.appendChild(update); diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/game/LotroGameMediator.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/game/LotroGameMediator.java index 70795eeb0..6d81918ee 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/game/LotroGameMediator.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/game/LotroGameMediator.java @@ -333,7 +333,7 @@ public class LotroGameMediator { } } - public boolean hasAnyNewMessages(Player player, int channelNumber) throws PrivateInformationException, SubscriptionConflictException, SubscriptionExpiredException { + public GatheringParticipantCommunicationChannel getCommunicationChannel(Player player, int channelNumber) throws PrivateInformationException, SubscriptionConflictException, SubscriptionExpiredException { String playerName = player.getName(); if (!player.getType().contains("a") && !_allowSpectators && !_playersPlaying.contains(playerName)) throw new PrivateInformationException(); @@ -343,7 +343,7 @@ public class LotroGameMediator { GatheringParticipantCommunicationChannel communicationChannel = _communicationChannels.get(playerName); if (communicationChannel != null) { if (communicationChannel.getChannelNumber() == channelNumber) { - return communicationChannel.hasGameEvents() || _userFeedback.hasWarning(playerName); + return communicationChannel; } else { throw new SubscriptionConflictException(); } @@ -355,39 +355,21 @@ public class LotroGameMediator { } } - public void processCommunicationChannel(Player player, int channelNumber, ParticipantCommunicationVisitor visitor) throws PrivateInformationException, SubscriptionConflictException, SubscriptionExpiredException { - String playerName = player.getName(); - if (!player.getType().contains("a") && !_allowSpectators && !_playersPlaying.contains(playerName)) - throw new PrivateInformationException(); + public void processVisitor(GatheringParticipantCommunicationChannel communicationChannel, int channelNumber, String playerName, ParticipantCommunicationVisitor visitor) { + visitor.visitChannelNumber(channelNumber); + for (GameEvent gameEvent : communicationChannel.consumeGameEvents()) + visitor.visitGameEvent(gameEvent); - _readLock.lock(); - try { - GatheringParticipantCommunicationChannel communicationChannel = _communicationChannels.get(playerName); - if (communicationChannel != null) { - if (communicationChannel.getChannelNumber() == channelNumber) { - visitor.visitChannelNumber(channelNumber); - for (GameEvent gameEvent : communicationChannel.consumeGameEvents()) - visitor.visitGameEvent(gameEvent); + String warning = _userFeedback.consumeWarning(playerName); + if (warning != null) + visitor.visitGameEvent(new GameEvent(GameEvent.Type.W).message(warning)); - String warning = _userFeedback.consumeWarning(playerName); - if (warning != null) - visitor.visitGameEvent(new GameEvent(GameEvent.Type.W).message(warning)); - - Map secondsLeft = new HashMap(); - for (Map.Entry playerClock : _playerClocks.entrySet()) { - String playerClockName = playerClock.getKey(); - secondsLeft.put(playerClockName, _maxSecondsForGamePerPlayer - playerClock.getValue() - getCurrentUserPendingTime(playerClockName)); - } - visitor.visitClock(secondsLeft); - } else { - throw new SubscriptionConflictException(); - } - } else { - throw new SubscriptionExpiredException(); - } - } finally { - _readLock.unlock(); + Map secondsLeft = new HashMap(); + for (Map.Entry playerClock : _playerClocks.entrySet()) { + String playerClockName = playerClock.getKey(); + secondsLeft.put(playerClockName, _maxSecondsForGamePerPlayer - playerClock.getValue() - getCurrentUserPendingTime(playerClockName)); } + visitor.visitClock(secondsLeft); } public void singupUserForGame(Player player, ParticipantCommunicationVisitor visitor) throws PrivateInformationException {