* Some rework of User/Tournament/Quit handling.

This commit is contained in:
LevelX2 2014-12-20 17:54:02 +01:00
parent 9ea54b38c2
commit 0ef340d108
10 changed files with 130 additions and 113 deletions

View file

@ -213,7 +213,7 @@ public class TableController {
//only inform human players and add them to sessionPlayerMap //only inform human players and add them to sessionPlayerMap
if (seat.getPlayer().isHuman()) { if (seat.getPlayer().isHuman()) {
user.addTable(player.getId(), table); user.addTable(player.getId(), table);
user.joinedTable(table.getRoomId(), table.getId(), true); user.ccJoinedTable(table.getRoomId(), table.getId(), true);
userPlayerMap.put(userId, player.getId()); userPlayerMap.put(userId, player.getId());
} }
@ -301,7 +301,7 @@ public class TableController {
//only inform human players and add them to sessionPlayerMap //only inform human players and add them to sessionPlayerMap
if (seat.getPlayer().isHuman()) { if (seat.getPlayer().isHuman()) {
user.addTable(player.getId(), table); user.addTable(player.getId(), table);
user.joinedTable(table.getRoomId(), table.getId(), false); user.ccJoinedTable(table.getRoomId(), table.getId(), false);
userPlayerMap.put(userId, player.getId()); userPlayerMap.put(userId, player.getId());
} }
return true; return true;
@ -392,7 +392,7 @@ public class TableController {
public boolean watchTable(UUID userId) { public boolean watchTable(UUID userId) {
if (table.isTournament()) { if (table.isTournament()) {
UserManager.getInstance().getUser(userId).showTournament(table.getTournament().getId()); UserManager.getInstance().getUser(userId).ccShowTournament(table.getTournament().getId());
return true; return true;
} else { } else {
if (table.isTournamentSubTable() && !table.getTournament().getOptions().isWatchingAllowed()) { if (table.isTournamentSubTable() && !table.getTournament().getOptions().isWatchingAllowed()) {
@ -405,7 +405,7 @@ public class TableController {
if (userPlayerMap.get(userId) != null) { if (userPlayerMap.get(userId) != null) {
return false; return false;
} }
return UserManager.getInstance().getUser(userId).watchGame(match.getGame().getId()); return UserManager.getInstance().getUser(userId).ccWatchGame(match.getGame().getId());
} }
} }
@ -550,7 +550,7 @@ public class TableController {
// activePlayers++; // activePlayers++;
Player player = match.getPlayer(entry.getValue()).getPlayer(); Player player = match.getPlayer(entry.getValue()).getPlayer();
player.setRequestToShowHandCardsAllowed(user.getUserData().allowRequestShowHandCards()); player.setRequestToShowHandCardsAllowed(user.getUserData().allowRequestShowHandCards());
user.gameStarted(match.getGame().getId(), entry.getValue()); user.ccGameStarted(match.getGame().getId(), entry.getValue());
if (creator == null) { if (creator == null) {
creator = user.getName(); creator = user.getName();
@ -618,7 +618,7 @@ public class TableController {
User user = UserManager.getInstance().getUser(entry.getKey()); User user = UserManager.getInstance().getUser(entry.getKey());
if (user != null) { if (user != null) {
logger.info(new StringBuilder("User ").append(user.getName()).append(" tournament started: ").append(tournament.getId()).append(" userId: ").append(user.getId())); logger.info(new StringBuilder("User ").append(user.getName()).append(" tournament started: ").append(tournament.getId()).append(" userId: ").append(user.getId()));
user.tournamentStarted(tournament.getId(), entry.getValue()); user.ccTournamentStarted(tournament.getId(), entry.getValue());
} }
} }
ServerMessagesUtil.getInstance().incTournamentsStarted(); ServerMessagesUtil.getInstance().incTournamentsStarted();
@ -627,7 +627,7 @@ public class TableController {
catch (Exception ex) { catch (Exception ex) {
logger.fatal("Error starting tournament", ex); logger.fatal("Error starting tournament", ex);
TableManager.getInstance().removeTable(table.getId()); TableManager.getInstance().removeTable(table.getId());
TournamentManager.getInstance().kill(tournament.getId(), userId); TournamentManager.getInstance().quit(tournament.getId(), userId);
} }
} }
@ -638,7 +638,7 @@ public class TableController {
User user = UserManager.getInstance().getUser(entry.getKey()); User user = UserManager.getInstance().getUser(entry.getKey());
if (user != null) { if (user != null) {
logger.info(new StringBuilder("User ").append(user.getName()).append(" draft started: ").append(draft.getId()).append(" userId: ").append(user.getId())); logger.info(new StringBuilder("User ").append(user.getName()).append(" draft started: ").append(draft.getId()).append(" userId: ").append(user.getId()));
user.draftStarted(draft.getId(), entry.getValue()); user.ccDraftStarted(draft.getId(), entry.getValue());
} else { } else {
logger.fatal(new StringBuilder("Start draft user not found userId: ").append(entry.getKey())); logger.fatal(new StringBuilder("Start draft user not found userId: ").append(entry.getKey()));
} }
@ -651,7 +651,7 @@ public class TableController {
User user = UserManager.getInstance().getUser(entry.getKey()); User user = UserManager.getInstance().getUser(entry.getKey());
int remaining = (int) futureTimeout.getDelay(TimeUnit.SECONDS); int remaining = (int) futureTimeout.getDelay(TimeUnit.SECONDS);
if (user != null) { if (user != null) {
user.sideboard(deck, table.getId(), remaining, options.isLimited()); user.ccSideboard(deck, table.getId(), remaining, options.isLimited());
} }
break; break;
} }

View file

@ -73,7 +73,7 @@ public class User {
private final Map<UUID, Table> tables; private final Map<UUID, Table> tables;
private final Map<UUID, GameSessionPlayer> gameSessions; private final Map<UUID, GameSessionPlayer> gameSessions;
private final Map<UUID, DraftSession> draftSessions; private final Map<UUID, DraftSession> draftSessions;
private final Map<UUID, TournamentSession> tournamentSessions; private final Map<UUID, UUID> userTournaments; // playerId, tournamentId
private final Map<UUID, TournamentSession> constructing; private final Map<UUID, TournamentSession> constructing;
private final Map<UUID, Deck> sideboarding; private final Map<UUID, Deck> sideboarding;
private final List<UUID> watchedGames; private final List<UUID> watchedGames;
@ -96,7 +96,7 @@ public class User {
this.tables = new ConcurrentHashMap<>(); this.tables = new ConcurrentHashMap<>();
this.gameSessions = new ConcurrentHashMap<>(); this.gameSessions = new ConcurrentHashMap<>();
this.draftSessions = new ConcurrentHashMap<>(); this.draftSessions = new ConcurrentHashMap<>();
this.tournamentSessions = new ConcurrentHashMap<>(); this.userTournaments = new ConcurrentHashMap<>();
this.constructing = new ConcurrentHashMap<>(); this.constructing = new ConcurrentHashMap<>();
this.sideboarding = new ConcurrentHashMap<>(); this.sideboarding = new ConcurrentHashMap<>();
this.watchedGames = new ArrayList<>(); this.watchedGames = new ArrayList<>();
@ -183,36 +183,36 @@ public class User {
} }
} }
public void joinedTable(final UUID roomId, final UUID tableId, boolean isTournament) { public void ccJoinedTable(final UUID roomId, final UUID tableId, boolean isTournament) {
fireCallback(new ClientCallback("joinedTable", tableId, new TableClientMessage(roomId, tableId, isTournament))); fireCallback(new ClientCallback("joinedTable", tableId, new TableClientMessage(roomId, tableId, isTournament)));
} }
public void gameStarted(final UUID gameId, final UUID playerId) { public void ccGameStarted(final UUID gameId, final UUID playerId) {
fireCallback(new ClientCallback("startGame", gameId, new TableClientMessage(gameId, playerId))); fireCallback(new ClientCallback("startGame", gameId, new TableClientMessage(gameId, playerId)));
} }
public void draftStarted(final UUID draftId, final UUID playerId) { public void ccDraftStarted(final UUID draftId, final UUID playerId) {
fireCallback(new ClientCallback("startDraft", draftId, new TableClientMessage(draftId, playerId))); fireCallback(new ClientCallback("startDraft", draftId, new TableClientMessage(draftId, playerId)));
} }
public void tournamentStarted(final UUID tournamentId, final UUID playerId) { public void ccTournamentStarted(final UUID tournamentId, final UUID playerId) {
fireCallback(new ClientCallback("startTournament", tournamentId, new TableClientMessage(tournamentId, playerId))); fireCallback(new ClientCallback("startTournament", tournamentId, new TableClientMessage(tournamentId, playerId)));
} }
public void sideboard(final Deck deck, final UUID tableId, final int time, boolean limited) { public void ccSideboard(final Deck deck, final UUID tableId, final int time, boolean limited) {
fireCallback(new ClientCallback("sideboard", tableId, new TableClientMessage(deck, tableId, time, limited))); fireCallback(new ClientCallback("sideboard", tableId, new TableClientMessage(deck, tableId, time, limited)));
sideboarding.put(tableId, deck); sideboarding.put(tableId, deck);
} }
public void construct(final Deck deck, final UUID tableId, final int time) { public void ccConstruct(final Deck deck, final UUID tableId, final int time) {
fireCallback(new ClientCallback("construct", tableId, new TableClientMessage(deck, tableId, time))); fireCallback(new ClientCallback("construct", tableId, new TableClientMessage(deck, tableId, time)));
} }
public void showTournament(final UUID tournamentId) { public void ccShowTournament(final UUID tournamentId) {
fireCallback(new ClientCallback("showTournament", tournamentId)); fireCallback(new ClientCallback("showTournament", tournamentId));
} }
public void showGameEndDialog(final UUID gameId) { public void ccShowGameEndDialog(final UUID gameId) {
fireCallback(new ClientCallback("showGameEndDialog", gameId)); fireCallback(new ClientCallback("showGameEndDialog", gameId));
} }
@ -223,12 +223,12 @@ public class User {
fireCallback(new ClientCallback("showUserMessage", null, messageData )); fireCallback(new ClientCallback("showUserMessage", null, messageData ));
} }
public boolean watchGame(final UUID gameId) { public boolean ccWatchGame(final UUID gameId) {
fireCallback(new ClientCallback("watchGame", gameId)); fireCallback(new ClientCallback("watchGame", gameId));
return true; return true;
} }
public void replayGame(final UUID gameId) { public void ccReplayGame(final UUID gameId) {
fireCallback(new ClientCallback("replayGame", gameId)); fireCallback(new ClientCallback("replayGame", gameId));
} }
@ -279,22 +279,24 @@ public class User {
private void reconnect() { private void reconnect() {
for (Entry<UUID, Table> entry: tables.entrySet()) { for (Entry<UUID, Table> entry: tables.entrySet()) {
joinedTable(entry.getValue().getRoomId(), entry.getValue().getId(), entry.getValue().isTournament()); ccJoinedTable(entry.getValue().getRoomId(), entry.getValue().getId(), entry.getValue().isTournament());
}
for (Entry<UUID, UUID> entry: userTournaments.entrySet()) {
TournamentController tournamentController = TournamentManager.getInstance().getTournamentController(entry.getValue());
if (tournamentController != null) {
ccTournamentStarted(entry.getValue(), entry.getKey());
tournamentController.rejoin(entry.getKey());
} }
for (Entry<UUID, TournamentSession> entry: tournamentSessions.entrySet()) {
tournamentStarted(entry.getValue().getTournamentId(), entry.getKey());
entry.getValue().init();
entry.getValue().update();
} }
for (Entry<UUID, GameSessionPlayer> entry: gameSessions.entrySet()) { for (Entry<UUID, GameSessionPlayer> entry: gameSessions.entrySet()) {
gameStarted(entry.getValue().getGameId(), entry.getKey()); ccGameStarted(entry.getValue().getGameId(), entry.getKey());
entry.getValue().init(); entry.getValue().init();
GameManager.getInstance().sendPlayerString(entry.getValue().getGameId(), userId, ""); GameManager.getInstance().sendPlayerString(entry.getValue().getGameId(), userId, "");
} }
for (Entry<UUID, DraftSession> entry: draftSessions.entrySet()) { for (Entry<UUID, DraftSession> entry: draftSessions.entrySet()) {
draftStarted(entry.getValue().getDraftId(), entry.getKey()); ccDraftStarted(entry.getValue().getDraftId(), entry.getKey());
entry.getValue().init(); entry.getValue().init();
entry.getValue().update(); entry.getValue().update();
} }
@ -304,7 +306,7 @@ public class User {
} }
for (Entry<UUID, Deck> entry: sideboarding.entrySet()) { for (Entry<UUID, Deck> entry: sideboarding.entrySet()) {
TableController controller = TableManager.getInstance().getController(entry.getKey()); TableController controller = TableManager.getInstance().getController(entry.getKey());
sideboard(entry.getValue(), entry.getKey(), controller.getRemainingTime(), controller.getOptions().isLimited()); ccSideboard(entry.getValue(), entry.getKey(), controller.getRemainingTime(), controller.getOptions().isLimited());
} }
} }
@ -324,12 +326,12 @@ public class User {
draftSessions.remove(playerId); draftSessions.remove(playerId);
} }
public void addTournament(UUID playerId, TournamentSession tournamentSession) { public void addTournament(UUID playerId, UUID tournamentId) {
tournamentSessions.put(playerId, tournamentSession); userTournaments.put(playerId, tournamentId);
} }
public void removeTournament(UUID playerId) { public void removeTournament(UUID playerId) {
tournamentSessions.remove(playerId); userTournaments.remove(playerId);
} }
public void addTable(UUID playerId, Table table) { public void addTable(UUID playerId, Table table) {
@ -353,32 +355,29 @@ public class User {
} }
public void remove(DisconnectReason reason) { public void remove(DisconnectReason reason) {
logger.trace("REMOVE " + getName() + " Game sessions: " + gameSessions.size() );
for (GameSessionPlayer gameSession: gameSessions.values()) {
logger.debug("-- kill game session of gameId: " + gameSession.getGameId() );
gameSession.quitGame();
}
gameSessions.clear();
logger.trace("REMOVE " + getName() + " Draft sessions " + draftSessions.size()); logger.trace("REMOVE " + getName() + " Draft sessions " + draftSessions.size());
for (DraftSession draftSession: draftSessions.values()) { for (DraftSession draftSession: draftSessions.values()) {
draftSession.setKilled(); draftSession.setKilled();
} }
draftSessions.clear(); draftSessions.clear();
logger.trace("REMOVE " + getName() + " Tournament sessions " + tournamentSessions.size()); logger.trace("REMOVE " + getName() + " Tournament sessions " + userTournaments.size());
for (TournamentSession tournamentSession: tournamentSessions.values()) { for (UUID tournamentId: userTournaments.values()) {
TournamentController tournamentController = TournamentManager.getInstance().getTournamentController(tournamentSession.getTournamentId()); TournamentManager.getInstance().quit(tournamentId, getId());
if (tournamentController != null) {
tournamentController.quit(userId);
} }
tournamentSession.setKilled(); userTournaments.clear();
}
tournamentSessions.clear();
logger.trace("REMOVE " + getName() + " Tables " + tables.size()); logger.trace("REMOVE " + getName() + " Tables " + tables.size());
for (Entry<UUID, Table> entry: tables.entrySet()) { for (Entry<UUID, Table> entry: tables.entrySet()) {
logger.debug("-- leave tableId: " + entry.getValue().getId()); logger.debug("-- leave tableId: " + entry.getValue().getId());
TableManager.getInstance().leaveTable(userId, entry.getValue().getId()); TableManager.getInstance().leaveTable(userId, entry.getValue().getId());
} }
tables.clear(); tables.clear();
logger.trace("REMOVE " + getName() + " Game sessions: " + gameSessions.size() );
for (GameSessionPlayer gameSessionPlayer: gameSessions.values()) {
logger.debug("-- kill game session of gameId: " + gameSessionPlayer.getGameId() );
GameManager.getInstance().quitMatch(gameSessionPlayer.getGameId(), userId);
gameSessionPlayer.quitGame();
}
gameSessions.clear();
logger.trace("REMOVE " + getName() + " watched Games " + watchedGames.size()); logger.trace("REMOVE " + getName() + " watched Games " + watchedGames.size());
for (UUID gameId: watchedGames) { for (UUID gameId: watchedGames) {
GameManager.getInstance().stopWatching(gameId, userId); GameManager.getInstance().stopWatching(gameId, userId);

View file

@ -442,9 +442,9 @@ public class GameController implements GameCallback {
UUID playerId = getPlayerId(userId); UUID playerId = getPlayerId(userId);
if (playerId != null) { if (playerId != null) {
if (allJoined()) { if (allJoined()) {
GameSessionPlayer gameSession = gameSessions.get(playerId); GameSessionPlayer gameSessionPlayer = gameSessions.get(playerId);
if (gameSession != null) { if (gameSessionPlayer != null) {
gameSession.quitGame(); gameSessionPlayer.quitGame();
} }
} else { } else {
// The player did never join the game but the game controller was started because the player was still connected as the // The player did never join the game but the game controller was started because the player was still connected as the

View file

@ -50,7 +50,7 @@ public class ReplayManager {
public void replayGame(UUID gameId, UUID userId) { public void replayGame(UUID gameId, UUID userId) {
ReplaySession replaySession = new ReplaySession(gameId, userId); ReplaySession replaySession = new ReplaySession(gameId, userId);
replaySessions.put(gameId.toString() + userId.toString(), replaySession); replaySessions.put(gameId.toString() + userId.toString(), replaySession);
UserManager.getInstance().getUser(userId).replayGame(gameId); UserManager.getInstance().getUser(userId).ccReplayGame(gameId);
} }
public void startReplay(UUID gameId, UUID userId) { public void startReplay(UUID gameId, UUID userId) {

View file

@ -169,7 +169,7 @@ public class TournamentController {
tournamentSessions.put(playerId, tournamentSession); tournamentSessions.put(playerId, tournamentSession);
User user = UserManager.getInstance().getUser(userId); User user = UserManager.getInstance().getUser(userId);
if (user != null) { if (user != null) {
user.addTournament(playerId, tournamentSession); user.addTournament(playerId, tournament.getId());
TournamentPlayer player = tournament.getPlayer(playerId); TournamentPlayer player = tournament.getPlayer(playerId);
player.setJoined(); player.setJoined();
logger.debug("player " +player.getPlayer().getName() + " - client has joined tournament " + tournament.getId()); logger.debug("player " +player.getPlayer().getName() + " - client has joined tournament " + tournament.getId());
@ -180,6 +180,19 @@ public class TournamentController {
} }
} }
public void rejoin(UUID playerId) {
TournamentSession tournamentSession = tournamentSessions.get(playerId);
if (tournamentSession == null) {
logger.fatal("Tournament session not found - playerId:" + playerId + " tournamentId " + tournament.getId());
return;
}
if (!tournamentSession.init()) {
logger.fatal("Unable to initialize client userId: " + tournamentSession.userId + " tournamentId " + tournament.getId());
return;
}
tournamentSession.update();
}
private void checkStart() { private void checkStart() {
if (!started && allJoined()) { if (!started && allJoined()) {
ThreadExecutor.getInstance().getCallExecutor().execute( ThreadExecutor.getInstance().getCallExecutor().execute(
@ -318,20 +331,35 @@ public class TournamentController {
public void quit(UUID userId) { public void quit(UUID userId) {
UUID playerId = userPlayerMap.get(userId); UUID playerId = userPlayerMap.get(userId);
if (playerId != null) { if (playerId == null) {
TournamentPlayer tPlayer = tournament.getPlayer(playerId); logger.debug("Player not found userId:" + userId + " tournId: " + tournament.getId());
if (tPlayer != null) { return;
if (started) { }
if (tPlayer.isInTournament()) { TournamentPlayer tournamentPlayer = tournament.getPlayer(playerId);
if (tournamentPlayer == null) {
logger.debug("TournamentPlayer not found userId: " + userId + " tournId: " + tournament.getId());
return;
}
if (!started) {
tournament.leave(playerId);
return;
}
TournamentSession tournamentSession = tournamentSessions.get(playerId);
if (tournamentSession == null) {
logger.debug("TournamentSession not found userId: " + userId + " tournId: " + tournament.getId());
return;
}
tournamentSession.setKilled();
if (tournamentPlayer.isInTournament()) {
String info; String info;
if (tournament.isDoneConstructing()) { if (tournament.isDoneConstructing()) {
info = new StringBuilder("during round ").append(tournament.getRounds().size()).toString(); info = new StringBuilder("during round ").append(tournament.getRounds().size()).toString();
// quit active matches of that tournament // quit active matches of that tournament
TableManager.getInstance().userQuitTournamentSubTables(tournament.getId(), userId); TableManager.getInstance().userQuitTournamentSubTables(tournament.getId(), userId);
} else { } else {
if (tPlayer.getState().equals(TournamentPlayerState.DRAFTING)) { if (tournamentPlayer.getState().equals(TournamentPlayerState.DRAFTING)) {
info = "during Draft phase"; info = "during Draft phase";
if (!checkToReplaceDraftPlayerByAi(userId, tPlayer)) { if (!checkToReplaceDraftPlayerByAi(userId, tournamentPlayer)) {
this.abortDraftTournament(); this.abortDraftTournament();
} else { } else {
DraftController draftController = DraftManager.getInstance().getController(tableId); DraftController draftController = DraftManager.getInstance().getController(tableId);
@ -342,25 +370,16 @@ public class TournamentController {
} }
} }
} }
} else if (tPlayer.getState().equals(TournamentPlayerState.CONSTRUCTING)) { } else if (tournamentPlayer.getState().equals(TournamentPlayerState.CONSTRUCTING)) {
info = "during Construction phase"; info = "during Construction phase";
} else { } else {
info = ""; info = "";
} }
} }
tPlayer.setQuit(info); tournamentPlayer.setQuit(info);
tournament.quit(playerId); tournament.quit(playerId);
if (tournamentSessions.containsKey(playerId)) { tournamentSession.quit();
tournamentSessions.get(tPlayer.getPlayer().getId()).quit(); ChatManager.getInstance().broadcast(chatId, "", tournamentPlayer.getPlayer().getName() + " has quit the tournament", MessageColor.BLACK, true, MessageType.STATUS, SoundToPlay.PlayerQuitTournament);
}
ChatManager.getInstance().broadcast(chatId, "", tPlayer.getPlayer().getName() + " has quit the tournament", MessageColor.BLACK, true, MessageType.STATUS, SoundToPlay.PlayerQuitTournament);
}
} else {
tournament.leave(playerId);
}
}
} else {
logger.debug("UserId not found " + userId + " tournId: " + tournament.getId());
} }
} }

View file

@ -71,11 +71,6 @@ public class TournamentManager {
} }
} }
public void kill(UUID tournamentId, UUID userId) {
controllers.get(tournamentId).quit(userId);
}
public void timeout(UUID tournamentId, UUID userId) { public void timeout(UUID tournamentId, UUID userId) {
controllers.get(tournamentId).timeout(userId); controllers.get(tournamentId).timeout(userId);
} }

View file

@ -101,7 +101,7 @@ public class TournamentSession {
User user = UserManager.getInstance().getUser(userId); User user = UserManager.getInstance().getUser(userId);
if (user != null) { if (user != null) {
int remaining = (int) futureTimeout.getDelay(TimeUnit.SECONDS); int remaining = (int) futureTimeout.getDelay(TimeUnit.SECONDS);
user.construct(tournament.getPlayer(playerId).getDeck(), tableId, remaining); user.ccConstruct(tournament.getPlayer(playerId).getDeck(), tableId, remaining);
} }
} }
} }
@ -115,11 +115,6 @@ public class TournamentSession {
tournament.updateDeck(playerId, deck); tournament.updateDeck(playerId, deck);
} }
protected void handleRemoteException(RemoteException ex) {
logger.fatal("TournamentSession error - userId " + userId + " tId " + tournament.getId(), ex);
TournamentManager.getInstance().kill(tournament.getId(), userId);
}
public void setKilled() { public void setKilled() {
killed = true; killed = true;
} }

View file

@ -40,6 +40,7 @@ import java.util.UUID;
import mage.constants.Zone; import mage.constants.Zone;
import mage.filter.FilterCard; import mage.filter.FilterCard;
import mage.game.Game; import mage.game.Game;
import org.apache.log4j.Logger;
/** /**
@ -48,6 +49,8 @@ import mage.game.Game;
*/ */
public class CardsImpl extends LinkedHashSet<UUID> implements Cards, Serializable { public class CardsImpl extends LinkedHashSet<UUID> implements Cards, Serializable {
private static final Logger logger = Logger.getLogger(CardsImpl.class);
private static Random rnd = new Random(); private static Random rnd = new Random();
private UUID ownerId; private UUID ownerId;
private Zone zone; private Zone zone;
@ -62,7 +65,7 @@ public class CardsImpl extends LinkedHashSet<UUID> implements Cards, Serializabl
this.zone = zone; this.zone = zone;
} }
public CardsImpl(Zone zone, List<Card> cards) { public CardsImpl(Zone zone, Collection<Card> cards) {
this(zone); this(zone);
for (Card card: cards) { for (Card card: cards) {
this.add(card.getId()); this.add(card.getId());
@ -181,8 +184,14 @@ public class CardsImpl extends LinkedHashSet<UUID> implements Cards, Serializabl
@Override @Override
public Set<Card> getCards(Game game) { public Set<Card> getCards(Game game) {
Set<Card> cards = new LinkedHashSet<>(); Set<Card> cards = new LinkedHashSet<>();
for (UUID card: this) { for (UUID cardId: this) {
cards.add(game.getCard(card)); Card card = game.getCard(cardId);
if (card != null) {
cards.add(card);
} else {
// this bug seems to happen, if cause is removed, this check can also be removed
logger.error("Card not found cardId: " + cardId + " gameId: " + game.getId() );
}
} }
return cards; return cards;
} }

View file

@ -222,7 +222,7 @@ public interface Game extends MageItem, Serializable {
int mulliganDownTo(UUID playerId); int mulliganDownTo(UUID playerId);
void mulligan(UUID playerId); void mulligan(UUID playerId);
void endMulligan(UUID playerId); void endMulligan(UUID playerId);
void quit(UUID playerId); // void quit(UUID playerId);
void timerTimeout(UUID playerId); void timerTimeout(UUID playerId);
void idleTimeout(UUID playerId); void idleTimeout(UUID playerId);
void concede(UUID playerId); void concede(UUID playerId);

View file

@ -1036,15 +1036,15 @@ public abstract class GameImpl implements Game, Serializable {
player.drawCards(numCards - deduction, this); player.drawCards(numCards - deduction, this);
} }
@Override // @Override
public void quit(UUID playerId) { // public void quit(UUID playerId) {
if (state != null) { // if (state != null) {
Player player = state.getPlayer(playerId); // Player player = state.getPlayer(playerId);
if (player != null && player.isInGame()) { // if (player != null && player.isInGame()) {
player.quit(this); // player.quit(this);
} // }
} // }
} // }
@Override @Override
public synchronized void timerTimeout(UUID playerId) { public synchronized void timerTimeout(UUID playerId) {