Watching finals of tournament is possible, but watching people are on mute.

This commit is contained in:
marcins78@gmail.com
2012-07-16 11:40:29 +00:00
parent c5092d4814
commit 8edb3a06d8
10 changed files with 36 additions and 44 deletions

View File

@@ -23,20 +23,14 @@ public class ChatRoomMediator {
_channelInactivityTimeoutPeriod = 1000 * secondsTimeoutPeriod;
}
public synchronized List<ChatMessage> joinUser(String playerId, boolean admin) {
if (!admin && _allowedPlayers != null && !_allowedPlayers.contains(playerId))
throw new WebApplicationException(Response.Status.FORBIDDEN);
public synchronized List<ChatMessage> joinUser(String playerId) {
GatheringChatRoomListener value = new GatheringChatRoomListener();
_listeners.put(playerId, value);
_chatRoom.joinChatRoom(playerId, value);
return value.consumeMessages();
}
public synchronized List<ChatMessage> getPendingMessages(String playerId, boolean admin) {
if (!admin && _allowedPlayers != null && !_allowedPlayers.contains(playerId))
throw new WebApplicationException(Response.Status.FORBIDDEN);
public synchronized List<ChatMessage> getPendingMessages(String playerId) {
GatheringChatRoomListener gatheringChatRoomListener = _listeners.get(playerId);
if (gatheringChatRoomListener == null)
throw new WebApplicationException(Response.Status.NOT_FOUND);

View File

@@ -16,7 +16,7 @@ public class ChatServer extends AbstractServer {
return chatRoom;
}
public ChatRoomMediator createPrivateChatRoom(String name, Set<String> allowedUsers, int secondsTimeoutPeriod) {
public ChatRoomMediator createVoicedChatRoom(String name, Set<String> allowedUsers, int secondsTimeoutPeriod) {
ChatRoomMediator chatRoom = new ChatRoomMediator(secondsTimeoutPeriod, allowedUsers);
chatRoom.sendMessage("System", "Welcome to private room: " + name, true);
_chatRooms.put(name, chatRoom);

View File

@@ -29,7 +29,7 @@ public class LotroGameMediator {
private Set<String> _playersPlaying = new HashSet<String>();
private int _maxSecondsForGamePerPlayer = 60 * 80; // 80 minutes
private boolean _noSpectators;
private boolean _allowSpectators;
private boolean _cancellable;
// private final int _maxSecondsForGamePerPlayer = 60 * 40; // 40 minutes
private final int _channelInactivityTimeoutPeriod = 1000 * 60 * 5; // 5 minutes
@@ -41,9 +41,9 @@ public class LotroGameMediator {
private int _channelNextIndex = 0;
public LotroGameMediator(LotroFormat lotroFormat, LotroGameParticipant[] participants, LotroCardBlueprintLibrary library, int maxSecondsForGamePerPlayer,
boolean noSpectators, boolean cancellable) {
boolean allowSpectators, boolean cancellable) {
_maxSecondsForGamePerPlayer = maxSecondsForGamePerPlayer;
_noSpectators = noSpectators;
_allowSpectators = allowSpectators;
_cancellable = cancellable;
if (participants.length < 1)
throw new IllegalArgumentException("Game can't have less than one participant");
@@ -62,8 +62,8 @@ public class LotroGameMediator {
_userFeedback.setGame(_lotroGame);
}
public boolean isNoSpectators() {
return _noSpectators;
public boolean isAllowSpectators() {
return _allowSpectators;
}
public void setPlayerAutoPassSettings(String playerId, Set<Phase> phases) {
@@ -325,7 +325,7 @@ public class LotroGameMediator {
public void processCommunicationChannel(Player player, int channelNumber, ParticipantCommunicationVisitor visitor) {
String playerName = player.getName();
if (!player.getType().contains("a") && _noSpectators && !_playersPlaying.contains(playerName))
if (!player.getType().contains("a") && !_allowSpectators && !_playersPlaying.contains(playerName))
throw new WebApplicationException(Response.Status.FORBIDDEN);
_readLock.lock();
@@ -360,7 +360,7 @@ public class LotroGameMediator {
public void singupUserForGame(Player player, ParticipantCommunicationVisitor visitor) {
String playerName = player.getName();
if (!player.getType().contains("a") && _noSpectators && !_playersPlaying.contains(playerName))
if (!player.getType().contains("a") && !_allowSpectators && !_playersPlaying.contains(playerName))
throw new WebApplicationException(Response.Status.FORBIDDEN);
_readLock.lock();

View File

@@ -122,24 +122,22 @@ public class LotroServer extends AbstractServer {
return "Game" + gameId;
}
public synchronized String createNewGame(LotroFormat lotroFormat, String tournamentName, final LotroGameParticipant[] participants, boolean competitive, boolean tournament) {
public synchronized String createNewGame(LotroFormat lotroFormat, String tournamentName, final LotroGameParticipant[] participants, boolean allowSpectators, boolean allowCancelling, boolean muteSpectators, boolean competitiveTime
) {
if (participants.length < 2)
throw new IllegalArgumentException("There has to be at least two players");
final String gameId = String.valueOf(_nextGameId);
boolean noSpectators = tournament;
boolean cancellable = !tournament;
if (noSpectators) {
if (muteSpectators) {
Set<String> allowedUsers = new HashSet<String>();
for (LotroGameParticipant participant : participants)
allowedUsers.add(participant.getPlayerId());
_chatServer.createPrivateChatRoom(getChatRoomName(gameId), allowedUsers, 30);
_chatServer.createVoicedChatRoom(getChatRoomName(gameId), allowedUsers, 30);
} else
_chatServer.createChatRoom(getChatRoomName(gameId), 30);
LotroGameMediator lotroGameMediator = new LotroGameMediator(lotroFormat, participants, _lotroCardBlueprintLibrary,
competitive ? 60 * 40 : 60 * 80, noSpectators, cancellable);
competitiveTime ? 60 * 40 : 60 * 80, !allowSpectators, allowCancelling);
lotroGameMediator.addGameResultListener(
new GameResultListener() {
@Override

View File

@@ -266,7 +266,7 @@ public class HallServer extends AbstractServer {
LotroGameMediator lotroGameMediator = _lotroServer.getGameById(runningTable.getGameId());
if (lotroGameMediator != null) {
if (!lotroGameMediator.isFinished())
visitor.visitTable(runningGame.getKey(), runningTable.getGameId(), player.getType().contains("a") || !lotroGameMediator.isNoSpectators(), lotroGameMediator.getGameStatus(), runningTable.getFormatName(), runningTable.getTournamentName(), lotroGameMediator.getPlayersPlaying(), lotroGameMediator.getWinner());
visitor.visitTable(runningGame.getKey(), runningTable.getGameId(), player.getType().contains("a") || lotroGameMediator.isAllowSpectators(), lotroGameMediator.getGameStatus(), runningTable.getFormatName(), runningTable.getTournamentName(), lotroGameMediator.getPlayersPlaying(), lotroGameMediator.getWinner());
else
finishedTables.put(runningGame.getKey(), runningTable);
}
@@ -391,12 +391,12 @@ public class HallServer extends AbstractServer {
};
}
createGame(tableId, participants, listener, awaitingTable.getLotroFormat(), getTournamentName(awaitingTable), league != null, false);
createGame(tableId, participants, listener, awaitingTable.getLotroFormat(), getTournamentName(awaitingTable), true, league == null, false, false);
_awaitingTables.remove(tableId);
}
private void createGame(String tableId, LotroGameParticipant[] participants, GameResultListener listener, LotroFormat lotroFormat, String tournamentName, boolean competitive, boolean tournament) {
String gameId = _lotroServer.createNewGame(lotroFormat, tournamentName, participants, competitive, tournament);
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);
LotroGameMediator lotroGameMediator = _lotroServer.getGameById(gameId);
if (listener != null)
lotroGameMediator.addGameResultListener(listener);
@@ -513,14 +513,14 @@ public class HallServer extends AbstractServer {
}
@Override
public void createGame(LotroGameParticipant playerOne, LotroGameParticipant playerTwo) {
public void createGame(LotroGameParticipant playerOne, LotroGameParticipant playerTwo, boolean allowSpectators) {
final LotroGameParticipant[] participants = new LotroGameParticipant[2];
participants[0] = playerOne;
participants[1] = playerTwo;
createGameInternal(participants);
createGameInternal(participants, allowSpectators);
}
private void createGameInternal(final LotroGameParticipant[] participants) {
private void createGameInternal(final LotroGameParticipant[] participants, final boolean allowSpectators) {
_hallDataAccessLock.writeLock().lock();
try {
if (!_shutdown) {
@@ -533,9 +533,9 @@ public class HallServer extends AbstractServer {
@Override
public void gameCancelled() {
createGameInternal(participants);
createGameInternal(participants, allowSpectators);
}
}, _formatLibrary.getFormat(_tournament.getFormat()), _tournament.getTournamentName(), true, true);
}, _formatLibrary.getFormat(_tournament.getFormat()), _tournament.getTournamentName(), allowSpectators, false, true, true);
}
} finally {
_hallDataAccessLock.writeLock().unlock();

View File

@@ -207,9 +207,9 @@ public abstract class AbstractTournament implements Tournament {
}
}
private void createNewGame(TournamentCallback tournamentCallback, String playerOne, String playerTwo) {
private void createNewGame(TournamentCallback tournamentCallback, String playerOne, String playerTwo, boolean allowSpectators) {
tournamentCallback.createGame(new LotroGameParticipant(playerOne, _playerDecks.get(playerOne)),
new LotroGameParticipant(playerTwo, _playerDecks.get(playerTwo)));
new LotroGameParticipant(playerTwo, _playerDecks.get(playerTwo)), allowSpectators);
}
private class StartTournament implements TournamentTask {
@@ -253,10 +253,10 @@ public abstract class AbstractTournament implements Tournament {
protected abstract void pairPlayers(TournamentCallback tournamentCallback);
protected void pairNewGame(TournamentCallback tournamentCallback, String playerOne, String playerTwo) {
protected void pairNewGame(TournamentCallback tournamentCallback, String playerOne, String playerTwo, boolean allowSpectators) {
_ongoingGamesCount++;
_tournamentService.addMatch(_tournamentId, _currentRound, playerOne, playerTwo);
createNewGame(tournamentCallback, playerOne, playerTwo);
createNewGame(tournamentCallback, playerOne, playerTwo, allowSpectators);
}
protected void awardNewBye(TournamentCallback tournamentCallback, String player) {
@@ -279,7 +279,7 @@ public abstract class AbstractTournament implements Tournament {
String playerOne = pairings.getKey();
String playerTwo = pairings.getValue();
_ongoingGamesCount++;
createNewGame(tournamentCallback, playerOne, playerTwo);
createNewGame(tournamentCallback, playerOne, playerTwo, false);
}
}

View File

@@ -29,7 +29,7 @@ public class SingleEliminationTournament extends AbstractTournament {
String playerOne = playerIterator.next();
if (playerIterator.hasNext()) {
String playerTwo = playerIterator.next();
pairNewGame(tournamentCallback, playerOne, playerTwo);
pairNewGame(tournamentCallback, playerOne, playerTwo, playersRandomized.size() == 2);
} else {
awardNewBye(tournamentCallback, playerOne);
}

View File

@@ -3,7 +3,7 @@ package com.gempukku.lotro.tournament;
import com.gempukku.lotro.game.LotroGameParticipant;
public interface TournamentCallback {
public void createGame(LotroGameParticipant playerOne, LotroGameParticipant playerTwo);
public void createGame(LotroGameParticipant playerOne, LotroGameParticipant playerTwo, boolean allowSpectators);
public void broadcastMessage(String message);
}

View File

@@ -39,7 +39,7 @@ public class SingleEliminationTournamentTest {
TournamentCallback tournamentCallback = Mockito.mock(TournamentCallback.class);
tournament.advanceTournament(tournamentCallback);
Mockito.verify(tournamentCallback, new Times(1)).createGame(Mockito.<LotroGameParticipant>any(), Mockito.<LotroGameParticipant>any());
Mockito.verify(tournamentCallback, new Times(1)).createGame(Mockito.<LotroGameParticipant>any(), Mockito.<LotroGameParticipant>any(), Mockito.anyBoolean());
assertTrue(tournament.isPlayerInCompetition("p1"));
assertTrue(tournament.isPlayerInCompetition("p2"));
@@ -78,7 +78,7 @@ public class SingleEliminationTournamentTest {
ArgumentCaptor<LotroGameParticipant> playerOne = ArgumentCaptor.forClass(LotroGameParticipant.class);
ArgumentCaptor<LotroGameParticipant> playerTwo = ArgumentCaptor.forClass(LotroGameParticipant.class);
Mockito.verify(tournamentCallback, new Times(2)).createGame(playerOne.capture(), playerTwo.capture());
Mockito.verify(tournamentCallback, new Times(2)).createGame(playerOne.capture(), playerTwo.capture(), Mockito.anyBoolean());
List<LotroGameParticipant> playerOnes = playerOne.getAllValues();
List<LotroGameParticipant> playerTwos = playerTwo.getAllValues();
@@ -118,7 +118,7 @@ public class SingleEliminationTournamentTest {
ArgumentCaptor<LotroGameParticipant> playerOne2 = ArgumentCaptor.forClass(LotroGameParticipant.class);
ArgumentCaptor<LotroGameParticipant> playerTwo2 = ArgumentCaptor.forClass(LotroGameParticipant.class);
Mockito.verify(tournamentCallback, new Times(1)).createGame(playerOne2.capture(), playerTwo2.capture());
Mockito.verify(tournamentCallback, new Times(1)).createGame(playerOne2.capture(), playerTwo2.capture(), Mockito.anyBoolean());
assertTrue(oneNames.contains("p1") || twoNames.contains("p1"));
assertTrue(oneNames.contains(secondWinner) || twoNames.contains(secondWinner));

View File

@@ -39,7 +39,7 @@ public class ChatResource extends AbstractResource {
if (chatRoom == null)
sendError(Response.Status.NOT_FOUND);
List<ChatMessage> chatMessages = chatRoom.joinUser(resourceOwner.getName(), resourceOwner.getType().contains("a"));
List<ChatMessage> chatMessages = chatRoom.joinUser(resourceOwner.getName());
Collection<String> usersInRoom = chatRoom.getUsersInRoom();
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
@@ -73,7 +73,7 @@ public class ChatResource extends AbstractResource {
}
}
List<ChatMessage> chatMessages = chatRoom.getPendingMessages(resourceOwner.getName(), resourceOwner.getType().contains("a"));
List<ChatMessage> chatMessages = chatRoom.getPendingMessages(resourceOwner.getName());
Collection<String> usersInRoom = chatRoom.getUsersInRoom();