MOTD is sent to client, only if it has changed since last Hall update.

This commit is contained in:
marcins78
2013-01-02 12:17:08 +00:00
parent ddd18aff1e
commit 4a9efac4ad
5 changed files with 21 additions and 10 deletions

View File

@@ -4,6 +4,7 @@ import java.util.Map;
public interface HallChannelVisitor {
public void channelNumber(int channelNumber);
public void motdChanged(String motd);
public void serverTime(String serverTime);
public void runningPlayerGame(String gameId);

View File

@@ -2,6 +2,7 @@ package com.gempukku.lotro.hall;
import com.gempukku.lotro.game.Player;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.mutable.MutableObject;
import java.util.HashMap;
import java.util.List;
@@ -10,6 +11,7 @@ import java.util.Map;
public class HallCommunicationChannel {
private int _channelNumber;
private long _lastConsumed;
private String _lastMotd;
private Map<String, Map<String, String>> _tournamentQueuePropsOnClient = new HashMap<String, Map<String, String>>();
private Map<String, Map<String, String>> _tablePropsOnClient = new HashMap<String, Map<String, String>>();
@@ -27,6 +29,7 @@ public class HallCommunicationChannel {
public synchronized void processCommunicationChannel(HallServer hallServer, Player player, final HallChannelVisitor hallChannelVisitor) {
hallChannelVisitor.channelNumber(_channelNumber);
final MutableObject newMotd = new MutableObject();
final Map<String, Map<String, String>> tournamentsOnServer = new HashMap<String, Map<String, String>>();
final Map<String, Map<String, String>> tablesOnServer = new HashMap<String, Map<String, String>>();
@@ -43,6 +46,11 @@ public class HallCommunicationChannel {
hallChannelVisitor.playerBusy(busy);
}
@Override
public void motd(String motd) {
newMotd.setValue(motd);
}
@Override
public void visitTable(String tableId, String gameId, boolean watchable, TableStatus status, String statusDescription, String formatName, String tournamentName, List<String> playerIds, String winner) {
Map<String, String> props = new HashMap<String, String>();
@@ -116,6 +124,9 @@ public class HallCommunicationChannel {
if (!_tablePropsOnClient.containsKey(tableOnServer.getKey()))
hallChannelVisitor.addTable(tableOnServer.getKey(), tableOnServer.getValue());
if (newMotd.getValue() != null && !newMotd.equals(_lastMotd))
hallChannelVisitor.motdChanged((String) newMotd.getValue());
_tablePropsOnClient = tablesOnServer;
_lastConsumed = System.currentTimeMillis();

View File

@@ -11,6 +11,8 @@ public interface HallInfoVisitor {
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<String> playerIds, String winner);
public void visitTournamentQueue(String tournamentQueueKey, int cost, String collectionName, String formatName, String tournamentQueueName, String tournamentPrizes,

View File

@@ -97,10 +97,6 @@ public class HallServer extends AbstractServer {
}
}
public String getMOTD() {
return _motd;
}
public void setMOTD(String motd) {
_motd = motd;
}
@@ -304,6 +300,8 @@ public class HallServer extends AbstractServer {
try {
visitor.serverTime(DateUtils.getStringDateWithHour());
visitor.playerBusy(isPlayerBusy(player.getName()));
if (_motd != null)
visitor.motd(_motd);
// First waiting
for (Map.Entry<String, AwaitingTable> tableInformation : _awaitingTables.entrySet()) {

View File

@@ -139,9 +139,6 @@ public class HallResource extends AbstractResource {
Element hall = doc.createElement("hall");
hall.setAttribute("currency", String.valueOf(_collectionManager.getPlayerCollection(resourceOwner, "permanent").getCurrency()));
String motd = _hallServer.getMOTD();
if (motd != null)
hall.setAttribute("motd", motd);
_hallServer.processHall(resourceOwner, channelNumber, new SerializeHallInfoVisitor(doc, hall));
@@ -167,9 +164,6 @@ public class HallResource extends AbstractResource {
Element hall = doc.createElement("hall");
hall.setAttribute("currency", String.valueOf(_collectionManager.getPlayerCollection(resourceOwner, "permanent").getCurrency()));
String motd = _hallServer.getMOTD();
if (motd != null)
hall.setAttribute("motd", motd);
_hallServer.signupUserForHall(resourceOwner, new SerializeHallInfoVisitor(doc, hall));
for (Map.Entry<String, LotroFormat> format : _formatLibrary.getHallFormats().entrySet()) {
@@ -297,6 +291,11 @@ public class HallResource extends AbstractResource {
_hall.setAttribute("serverTime", serverTime);
}
@Override
public void motdChanged(String motd) {
_hall.setAttribute("motd", motd);
}
@Override
public void addTournamentQueue(String queueId, Map<String, String> props) {
Element queue = _doc.createElement("queue");