Fixed a bug of handling of tournament sub tables if a user left. Some chnages to match view.

This commit is contained in:
LevelX2 2014-09-04 18:20:40 +02:00
parent 8dbd996646
commit 3699b7ca3d
11 changed files with 57 additions and 32 deletions

View file

@ -188,6 +188,10 @@ public class TableController {
}
}
public boolean isPlayer(UUID userId) {
return userPlayerMap.containsKey(userId);
}
public synchronized boolean replaceDraftPlayer(Player oldPlayer, String name, String playerType, int skill) {
Player newPlayer = createPlayer(name, playerType, skill);
if (newPlayer == null || table.getState() != TableState.DRAFTING) {
@ -404,7 +408,7 @@ public class TableController {
} else if (!table.getState().equals(TableState.FINISHED)) {
if (table.isTournament()) {
logger.debug("Quit tournament sub tables for userId: " + userId);
TableManager.getInstance().userQuitTournamentSubTables(userId);
TableManager.getInstance().userQuitTournamentSubTables(tournament.getId(), userId);
logger.debug("Quit tournament Id: " + table.getTournament().getId());
TournamentManager.getInstance().quit(tournament.getId(), userId);
} else {

View file

@ -181,10 +181,12 @@ public class TableManager {
public void userQuitTournamentSubTables(UUID tournamentId, UUID userId) {
for (TableController controller: controllers.values()) {
if (controller.getTable().isTournamentSubTable() && controller.getTable().getTournament().getId().equals(tournamentId)) {
Match match = controller.getTable().getMatch();
if (match != null) {
if (match.getGame() != null) {
GameManager.getInstance().quitMatch(match.getGame().getId(), userId);
if (controller.isPlayer(userId)) {
Match match = controller.getTable().getMatch();
if (match != null) {
if (!match.hasEnded() && match.getGame() != null) {
GameManager.getInstance().quitMatch(match.getGame().getId(), userId);
}
}
}
}

View file

@ -193,7 +193,10 @@ public class UserManager {
public void handleException(Exception ex) {
if (ex != null) {
logger.fatal("User manager exception");
logger.fatal("User manager exception" + (ex.getMessage() == null ? "null":ex.getMessage()));
if (ex.getCause() != null) {
logger.debug("- Cause: " + (ex.getCause().getMessage() == null ? "null":ex.getCause().getMessage()));
}
ex.printStackTrace();
}else {
logger.fatal("User manager exception - null");

View file

@ -536,7 +536,7 @@ public class GameController implements GameCallback {
if (table != null) {
if (table.getMatch() != null) {
for (final GameSession gameSession: gameSessions.values()) {
gameSession.endGameInfo(table.getMatch());
gameSession.endGameInfo(table);
}
}
}

View file

@ -48,6 +48,7 @@ import java.util.Map.Entry;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import mage.game.Table;
/**
*
@ -161,11 +162,11 @@ public class GameSession extends GameWatcher {
}
}
public void endGameInfo(Match match) {
public void endGameInfo(Table table) {
if (!killed) {
User user = UserManager.getInstance().getUser(userId);
if (user != null) {
user.fireCallback(new ClientCallback("endGameInfo", game.getId(), getGameEndView(playerId, match)));
user.fireCallback(new ClientCallback("endGameInfo", game.getId(), getGameEndView(playerId, table)));
}
}
}

View file

@ -30,7 +30,7 @@ package mage.server.game;
import java.util.UUID;
import mage.game.Game;
import mage.game.match.Match;
import mage.game.Table;
import mage.interfaces.callback.ClientCallback;
import mage.server.User;
import mage.server.UserManager;
@ -123,8 +123,8 @@ public class GameWatcher {
return new GameView(game.getState(), game, null);
}
public GameEndView getGameEndView(UUID playerId, Match match) {
return new GameEndView(game.getState(), game, playerId, match);
public GameEndView getGameEndView(UUID playerId, Table table) {
return new GameEndView(game.getState(), game, playerId, table);
}
public boolean isPlayer() {

View file

@ -103,7 +103,7 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
if (table.isTournament()) {
matchList.add(new MatchView(table));
} else {
matchList.add(new MatchView(table.getMatch()));
matchList.add(new MatchView(table));
}
} else {
// more since 50 matches finished since this match so remove it