Chat rooms can now be configured to not generate join/part messages (like in case of Game Hall).

This commit is contained in:
marcins78
2013-01-08 10:33:29 +00:00
parent 57b068bc82
commit 58e97bfa31
6 changed files with 18 additions and 15 deletions

View File

@@ -12,8 +12,10 @@ public class ChatRoom {
return o1.compareToIgnoreCase(o2);
}
});
private boolean _muteJoinPartMessages;
public ChatRoom() {
public ChatRoom(boolean muteJoinPartMessages) {
_muteJoinPartMessages = muteJoinPartMessages;
}
private void postMessage(String from, String message, boolean addToHistory) {
@@ -35,13 +37,13 @@ public class ChatRoom {
_chatRoomListeners.put(playerId, listener);
for (ChatMessage lastMessage : _lastMessages)
listener.messageReceived(lastMessage);
if (!wasInRoom)
if (!wasInRoom && !_muteJoinPartMessages)
postMessage("System", playerId + " joined the room", false);
}
public void partChatRoom(String playerId) {
boolean wasInRoom = (_chatRoomListeners.remove(playerId) != null);
if (wasInRoom)
if (wasInRoom && !_muteJoinPartMessages)
postMessage("System", playerId + " left the room", false);
}

View File

@@ -11,7 +11,7 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
public class ChatRoomMediator {
private Logger _logger;
private ChatRoom _chatRoom = new ChatRoom();
private ChatRoom _chatRoom;
private Map<String, GatheringChatRoomListener> _listeners = new HashMap<String, GatheringChatRoomListener>();
@@ -20,14 +20,15 @@ public class ChatRoomMediator {
private ReadWriteLock _lock = new ReentrantReadWriteLock();
public ChatRoomMediator(String roomName, int secondsTimeoutPeriod) {
this(roomName, secondsTimeoutPeriod, null);
public ChatRoomMediator(String roomName, boolean muteJoinPartMessages, int secondsTimeoutPeriod) {
this(roomName, muteJoinPartMessages, secondsTimeoutPeriod, null);
}
public ChatRoomMediator(String roomName, int secondsTimeoutPeriod, Set<String> allowedPlayers) {
public ChatRoomMediator(String roomName, boolean muteJoinPartMessages, int secondsTimeoutPeriod, Set<String> allowedPlayers) {
_logger = Logger.getLogger("chat."+roomName);
_allowedPlayers = allowedPlayers;
_channelInactivityTimeoutPeriod = 1000 * secondsTimeoutPeriod;
_chatRoom = new ChatRoom(muteJoinPartMessages);
}
public List<ChatMessage> joinUser(String playerId, boolean admin) throws PrivateInformationException {

View File

@@ -10,8 +10,8 @@ import java.util.concurrent.ConcurrentHashMap;
public class ChatServer extends AbstractServer {
private Map<String, ChatRoomMediator> _chatRooms = new ConcurrentHashMap<String, ChatRoomMediator>();
public ChatRoomMediator createChatRoom(String name, int secondsTimeoutPeriod) {
ChatRoomMediator chatRoom = new ChatRoomMediator(name, secondsTimeoutPeriod);
public ChatRoomMediator createChatRoom(String name, boolean muteJoinPartMessages, int secondsTimeoutPeriod) {
ChatRoomMediator chatRoom = new ChatRoomMediator(name, muteJoinPartMessages, secondsTimeoutPeriod);
try {
chatRoom.sendMessage("System", "Welcome to room: " + name, true);
} catch (PrivateInformationException exp) {
@@ -21,8 +21,8 @@ public class ChatServer extends AbstractServer {
return chatRoom;
}
public ChatRoomMediator createPrivateChatRoom(String name, Set<String> allowedUsers, int secondsTimeoutPeriod) {
ChatRoomMediator chatRoom = new ChatRoomMediator(name, secondsTimeoutPeriod, allowedUsers);
public ChatRoomMediator createPrivateChatRoom(String name, boolean muteJoinPartMessages, Set<String> allowedUsers, int secondsTimeoutPeriod) {
ChatRoomMediator chatRoom = new ChatRoomMediator(name, muteJoinPartMessages, secondsTimeoutPeriod, allowedUsers);
try {
chatRoom.sendMessage("System", "Welcome to private room: " + name, true);
} catch (PrivateInformationException exp) {

View File

@@ -90,9 +90,9 @@ public class LotroServer extends AbstractServer {
Set<String> allowedUsers = new HashSet<String>();
for (LotroGameParticipant participant : participants)
allowedUsers.add(participant.getPlayerId());
_chatServer.createPrivateChatRoom(getChatRoomName(gameId), allowedUsers, 30);
_chatServer.createPrivateChatRoom(getChatRoomName(gameId), false, allowedUsers, 30);
} else
_chatServer.createChatRoom(getChatRoomName(gameId), 30);
_chatServer.createChatRoom(getChatRoomName(gameId), false, 30);
LotroGameMediator lotroGameMediator = new LotroGameMediator(lotroFormat, participants, _lotroCardBlueprintLibrary,
competitiveTime ? 60 * 40 : 60 * 80, allowSpectators, allowCancelling);

View File

@@ -66,7 +66,7 @@ public class HallServer extends AbstractServer {
_collectionsManager = collectionsManager;
_tournamentPrizeSchemeRegistry = tournamentPrizeSchemeRegistry;
_pairingMechanismRegistry = pairingMechanismRegistry;
_hallChat = _chatServer.createChatRoom("Game Hall", 10);
_hallChat = _chatServer.createChatRoom("Game Hall", true, 10);
_tournamentQueues.put("fotr_queue", new SingleEliminationRecurringQueue(635, "fotr_block",
CollectionType.MY_CARDS, "fotrQueue-", "Fellowship Block", 8,

View File

@@ -132,7 +132,7 @@ public class TradeServer extends AbstractServer {
_playerOngoingTrade.put(from, tradeState);
_playerOngoingTrade.put(to, tradeState);
_chatServer.createChatRoom(getChatRoomName(from, to), 30);
_chatServer.createChatRoom(getChatRoomName(from, to), false, 30);
}
private void destroyOngoingTrade(TradeState tradeState) {