Clearing queues, when server goes down.
This commit is contained in:
@@ -226,6 +226,10 @@ public class CollectionsManager {
|
||||
}
|
||||
}
|
||||
|
||||
public void addCurrencyToPlayerCollection(String player, CollectionType collectionType, int currency) {
|
||||
addCurrencyToPlayerCollection(_playerDAO.getPlayer(player), collectionType, currency);
|
||||
}
|
||||
|
||||
public void addCurrencyToPlayerCollection(Player player, CollectionType collectionType, int currency) {
|
||||
_readWriteLock.writeLock().lock();
|
||||
try {
|
||||
|
||||
@@ -106,7 +106,8 @@ public class HallServer extends AbstractServer {
|
||||
}
|
||||
|
||||
private void cancelTournamentQueues() {
|
||||
|
||||
for (TournamentQueue tournamentQueue : _tournamentQueues.values())
|
||||
tournamentQueue.leaveAllPlayers(_collectionsManager);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -160,6 +161,9 @@ public class HallServer extends AbstractServer {
|
||||
}
|
||||
|
||||
public boolean joinQueue(String queueId, Player player, String deckName) throws HallException {
|
||||
if (_shutdown)
|
||||
throw new HallException("Server is in shutdown mode. Server will be restarted after all running games are finished.");
|
||||
|
||||
_hallDataAccessLock.writeLock().lock();
|
||||
try {
|
||||
if (isPlayerBusy(player.getName()))
|
||||
@@ -185,6 +189,9 @@ public class HallServer extends AbstractServer {
|
||||
* @return If table joined, otherwise <code>false</code> (if the user already is sitting at a table or playing).
|
||||
*/
|
||||
public boolean joinTableAsPlayer(String tableId, Player player, String deckName) throws HallException {
|
||||
if (_shutdown)
|
||||
throw new HallException("Server is in shutdown mode. Server will be restarted after all running games are finished.");
|
||||
|
||||
_hallDataAccessLock.writeLock().lock();
|
||||
try {
|
||||
if (isPlayerBusy(player.getName()))
|
||||
|
||||
@@ -94,6 +94,15 @@ public class SingleEliminationRecurringQueue implements TournamentQueue {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void leaveAllPlayers(CollectionsManager collectionsManager) {
|
||||
if (_cost > 0) {
|
||||
for (String player : _playerDecks.keySet())
|
||||
collectionsManager.addCurrencyToPlayerCollection(player, _currencyCollection, _cost);
|
||||
}
|
||||
_playerDecks.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean isPlayerSignedUp(String player) {
|
||||
return _playerDecks.containsKey(player);
|
||||
|
||||
@@ -19,6 +19,8 @@ public interface TournamentQueue {
|
||||
|
||||
public void leavePlayer(CollectionsManager collectionsManager, Player player);
|
||||
|
||||
public void leaveAllPlayers(CollectionsManager collectionsManager);
|
||||
|
||||
public int getPlayerCount();
|
||||
|
||||
public boolean isPlayerSignedUp(String player);
|
||||
|
||||
Reference in New Issue
Block a user