Giving direct access to GatheringParticipantCommunicationChannel.

This commit is contained in:
marcins78
2013-01-18 14:21:33 +00:00
parent 69563e6c0d
commit afd9cd2353
2 changed files with 18 additions and 34 deletions

View File

@@ -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);

View File

@@ -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<String, Integer> secondsLeft = new HashMap<String, Integer>();
for (Map.Entry<String, Integer> 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<String, Integer> secondsLeft = new HashMap<String, Integer>();
for (Map.Entry<String, Integer> 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 {