Prevent reading private room.
This commit is contained in:
@@ -27,9 +27,12 @@ public class ChatRoomMediator {
|
||||
_channelInactivityTimeoutPeriod = 1000 * secondsTimeoutPeriod;
|
||||
}
|
||||
|
||||
public List<ChatMessage> joinUser(String playerId) {
|
||||
public List<ChatMessage> joinUser(String playerId, boolean admin) throws PrivateInformationException {
|
||||
_lock.writeLock().lock();
|
||||
try {
|
||||
if (!admin && _allowedPlayers != null && !_allowedPlayers.contains(playerId))
|
||||
throw new PrivateInformationException();
|
||||
|
||||
GatheringChatRoomListener value = new GatheringChatRoomListener();
|
||||
_listeners.put(playerId, value);
|
||||
_chatRoom.joinChatRoom(playerId, value);
|
||||
|
||||
@@ -21,7 +21,7 @@ public class ChatServer extends AbstractServer {
|
||||
return chatRoom;
|
||||
}
|
||||
|
||||
public ChatRoomMediator createVoicedChatRoom(String name, Set<String> allowedUsers, int secondsTimeoutPeriod) {
|
||||
public ChatRoomMediator createPrivateChatRoom(String name, Set<String> allowedUsers, int secondsTimeoutPeriod) {
|
||||
ChatRoomMediator chatRoom = new ChatRoomMediator(secondsTimeoutPeriod, allowedUsers);
|
||||
try {
|
||||
chatRoom.sendMessage("System", "Welcome to private room: " + name, true);
|
||||
|
||||
@@ -79,18 +79,18 @@ public class LotroServer extends AbstractServer {
|
||||
return "Game" + gameId;
|
||||
}
|
||||
|
||||
public String createNewGame(LotroFormat lotroFormat, String tournamentName, final LotroGameParticipant[] participants, boolean allowSpectators, boolean allowCancelling, boolean muteSpectators, boolean competitiveTime) {
|
||||
public String createNewGame(LotroFormat lotroFormat, String tournamentName, final LotroGameParticipant[] participants, boolean allowSpectators, boolean allowCancelling, boolean allowChatAccess, boolean competitiveTime) {
|
||||
_lock.writeLock().lock();
|
||||
try {
|
||||
if (participants.length < 2)
|
||||
throw new IllegalArgumentException("There has to be at least two players");
|
||||
final String gameId = String.valueOf(_nextGameId);
|
||||
|
||||
if (muteSpectators) {
|
||||
if (!allowChatAccess) {
|
||||
Set<String> allowedUsers = new HashSet<String>();
|
||||
for (LotroGameParticipant participant : participants)
|
||||
allowedUsers.add(participant.getPlayerId());
|
||||
_chatServer.createVoicedChatRoom(getChatRoomName(gameId), allowedUsers, 30);
|
||||
_chatServer.createPrivateChatRoom(getChatRoomName(gameId), allowedUsers, 30);
|
||||
} else
|
||||
_chatServer.createChatRoom(getChatRoomName(gameId), 30);
|
||||
|
||||
|
||||
@@ -468,12 +468,12 @@ public class HallServer extends AbstractServer {
|
||||
};
|
||||
}
|
||||
|
||||
createGame(tableId, participants, listener, awaitingTable.getLotroFormat(), getTournamentName(awaitingTable), true, league == null, false, league != null);
|
||||
createGame(tableId, participants, listener, awaitingTable.getLotroFormat(), getTournamentName(awaitingTable), true, league == null, true, league != null);
|
||||
_awaitingTables.remove(tableId);
|
||||
}
|
||||
|
||||
private void createGame(String tableId, LotroGameParticipant[] participants, GameResultListener listener, LotroFormat lotroFormat, String tournamentName, boolean allowSpectators, boolean allowCancelling, boolean muteSpectators, boolean competitiveTime) {
|
||||
String gameId = _lotroServer.createNewGame(lotroFormat, tournamentName, participants, allowSpectators, allowCancelling, muteSpectators, competitiveTime);
|
||||
private void createGame(String tableId, LotroGameParticipant[] participants, GameResultListener listener, LotroFormat lotroFormat, String tournamentName, boolean allowSpectators, boolean allowCancelling, boolean allowChatAccess, boolean competitiveTime) {
|
||||
String gameId = _lotroServer.createNewGame(lotroFormat, tournamentName, participants, allowSpectators, allowCancelling, allowChatAccess, competitiveTime);
|
||||
LotroGameMediator lotroGameMediator = _lotroServer.getGameById(gameId);
|
||||
if (listener != null)
|
||||
lotroGameMediator.addGameResultListener(listener);
|
||||
@@ -631,7 +631,7 @@ public class HallServer extends AbstractServer {
|
||||
public void gameCancelled() {
|
||||
createGameInternal(participants, allowSpectators);
|
||||
}
|
||||
}, _formatLibrary.getFormat(_tournament.getFormat()), _tournament.getTournamentName(), allowSpectators, false, true, true);
|
||||
}, _formatLibrary.getFormat(_tournament.getFormat()), _tournament.getTournamentName(), allowSpectators, false, false, true);
|
||||
}
|
||||
} finally {
|
||||
_hallDataAccessLock.writeLock().unlock();
|
||||
|
||||
@@ -40,8 +40,8 @@ public class ChatResource extends AbstractResource {
|
||||
ChatRoomMediator chatRoom = _chatServer.getChatRoom(room);
|
||||
if (chatRoom == null)
|
||||
throw new WebApplicationException(Response.Status.NOT_FOUND);
|
||||
|
||||
List<ChatMessage> chatMessages = chatRoom.joinUser(resourceOwner.getName());
|
||||
try {
|
||||
List<ChatMessage> chatMessages = chatRoom.joinUser(resourceOwner.getName(), resourceOwner.getType().contains("a"));
|
||||
Collection<String> usersInRoom = chatRoom.getUsersInRoom();
|
||||
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
@@ -52,6 +52,9 @@ public class ChatResource extends AbstractResource {
|
||||
serializeChatRoomData(room, chatMessages, usersInRoom, doc);
|
||||
|
||||
return doc;
|
||||
} catch (PrivateInformationException exp) {
|
||||
throw new WebApplicationException(Response.Status.FORBIDDEN);
|
||||
}
|
||||
}
|
||||
|
||||
@Path("/{room}")
|
||||
|
||||
Reference in New Issue
Block a user