diff --git a/Mage.Server/src/main/java/mage/server/TableController.java b/Mage.Server/src/main/java/mage/server/TableController.java index edf40e765d..e5278b1779 100644 --- a/Mage.Server/src/main/java/mage/server/TableController.java +++ b/Mage.Server/src/main/java/mage/server/TableController.java @@ -281,7 +281,18 @@ public class TableController { public synchronized void leaveTable(UUID userId) { if (table.getState() == TableState.WAITING || table.getState() == TableState.STARTING) { - table.leaveTable(userPlayerMap.get(userId)); + UUID playerId = userPlayerMap.get(userId); + if (playerId != null) { + table.leaveTable(playerId); + if (table.isTournament()) { + tournament.leave(playerId); + } else { + match.leave(playerId); + } + User user = UserManager.getInstance().getUser(userId); + user.removeTable(playerId); + userPlayerMap.remove(userId); + } } } diff --git a/Mage/src/mage/game/match/Match.java b/Mage/src/mage/game/match/Match.java index 502a39f660..f2f9b2df50 100644 --- a/Mage/src/mage/game/match/Match.java +++ b/Mage/src/mage/game/match/Match.java @@ -50,7 +50,10 @@ public interface Match { boolean isMatchOver(); List getPlayers(); MatchPlayer getPlayer(UUID playerId); + void addPlayer(Player player, Deck deck); + boolean leave(UUID playerId); + void submitDeck(UUID playerId, Deck deck); void updateDeck(UUID playerId, Deck deck); void startMatch() throws GameException; diff --git a/Mage/src/mage/game/match/MatchImpl.java b/Mage/src/mage/game/match/MatchImpl.java index e1be582d74..526c5b982a 100644 --- a/Mage/src/mage/game/match/MatchImpl.java +++ b/Mage/src/mage/game/match/MatchImpl.java @@ -77,6 +77,15 @@ public abstract class MatchImpl implements Match { players.add(mPlayer); } + @Override + public boolean leave(UUID playerId) { + MatchPlayer mPlayer = getPlayer(playerId); + if (mPlayer != null) { + return players.remove(mPlayer); + } + return false; + } + @Override public void startMatch() throws GameException { diff --git a/Mage/src/mage/game/tournament/TournamentImpl.java b/Mage/src/mage/game/tournament/TournamentImpl.java index bb35d9e44e..7d80ebecab 100644 --- a/Mage/src/mage/game/tournament/TournamentImpl.java +++ b/Mage/src/mage/game/tournament/TournamentImpl.java @@ -102,7 +102,9 @@ public abstract class TournamentImpl implements Tournament { @Override public void leave(UUID playerId) { - //TODO: implement this + if (players.containsKey(playerId)) { + players.remove(playerId); + } } @Override