mirror of
https://github.com/correl/mage.git
synced 2024-12-25 03:00:15 +00:00
Fixed a bug of handling of tournament sub tables if a user left. Some chnages to match view.
This commit is contained in:
parent
8dbd996646
commit
3699b7ca3d
11 changed files with 57 additions and 32 deletions
|
@ -35,6 +35,7 @@ import java.util.List;
|
|||
import java.util.UUID;
|
||||
import mage.game.Game;
|
||||
import mage.game.GameState;
|
||||
import mage.game.Table;
|
||||
import mage.game.match.Match;
|
||||
import mage.game.match.MatchPlayer;
|
||||
import mage.players.Player;
|
||||
|
@ -57,7 +58,7 @@ public class GameEndView implements Serializable {
|
|||
private int loses;
|
||||
private final int winsNeeded;
|
||||
|
||||
public GameEndView(GameState state, Game game, UUID playerId, Match match) {
|
||||
public GameEndView(GameState state, Game game, UUID playerId, Table table) {
|
||||
startTime = game.getStartTime();
|
||||
endTime = game.getEndTime();
|
||||
|
||||
|
@ -85,8 +86,9 @@ public class GameEndView implements Serializable {
|
|||
gameInfo = new StringBuilder("Game is a draw on Turn ").append(game.getTurnNum()).append(".").toString();
|
||||
}
|
||||
}
|
||||
matchView = new MatchView(match);
|
||||
matchView = new MatchView(table);
|
||||
|
||||
Match match = table.getMatch();
|
||||
MatchPlayer matchWinner = null;
|
||||
winsNeeded = match.getOptions().getWinsNeeded();
|
||||
StringBuilder additonalText = new StringBuilder();
|
||||
|
|
|
@ -45,24 +45,33 @@ import mage.game.tournament.TournamentPlayer;
|
|||
public class MatchView implements Serializable {
|
||||
|
||||
private final UUID tableId;
|
||||
private final UUID matchId;
|
||||
private final String matchName;
|
||||
private UUID matchId;
|
||||
private String matchName;
|
||||
private String gameType;
|
||||
private final String deckType;
|
||||
private String deckType;
|
||||
|
||||
private final List<UUID> games = new ArrayList<>();
|
||||
private final String result;
|
||||
private final String players;
|
||||
private String result;
|
||||
private String players;
|
||||
|
||||
private final Date startTime;
|
||||
private final Date endTime;
|
||||
private final boolean replayAvailable;
|
||||
private Date startTime;
|
||||
private Date endTime;
|
||||
private boolean replayAvailable;
|
||||
private final boolean isTournament;
|
||||
|
||||
public MatchView(Table table) {
|
||||
this.tableId = table.getId();
|
||||
this.isTournament = table.isTournament();
|
||||
if (table.isTournament()) {
|
||||
initTournamentTable(table);
|
||||
} else {
|
||||
initMatchTable(table);
|
||||
}
|
||||
}
|
||||
|
||||
// used for matches
|
||||
public MatchView(Match match) {
|
||||
this.tableId = null;
|
||||
this.isTournament = false;
|
||||
private void initMatchTable(Table table) {
|
||||
Match match = table.getMatch();
|
||||
this.matchId = match.getId();
|
||||
this.matchName = match.getName();
|
||||
this.gameType = match.getOptions().getGameType();
|
||||
|
@ -102,9 +111,7 @@ public class MatchView implements Serializable {
|
|||
}
|
||||
|
||||
// used for tournaments
|
||||
public MatchView(Table table) {
|
||||
this.tableId = table.getId();
|
||||
this.isTournament = true;
|
||||
private void initTournamentTable(Table table) {
|
||||
this.matchId = table.getTournament().getId();
|
||||
this.matchName = table.getName();
|
||||
this.gameType = table.getGameType();
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -50,6 +50,7 @@ public interface Match {
|
|||
UUID getId();
|
||||
String getName();
|
||||
boolean hasEnded();
|
||||
boolean hasStarted();
|
||||
boolean checkIfMatchEnds();
|
||||
List<MatchPlayer> getPlayers();
|
||||
MatchPlayer getPlayer(UUID playerId);
|
||||
|
|
|
@ -63,7 +63,7 @@ public abstract class MatchImpl implements Match {
|
|||
|
||||
public MatchImpl(MatchOptions options) {
|
||||
this.options = options;
|
||||
startTime = new Date();
|
||||
startTime = null;
|
||||
replayAvailable = false;
|
||||
draws = 0;
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ public abstract class MatchImpl implements Match {
|
|||
public boolean leave(UUID playerId) {
|
||||
MatchPlayer mPlayer = getPlayer(playerId);
|
||||
if (mPlayer != null) {
|
||||
if (startedGames == 0) {
|
||||
if (!hasStarted()) {
|
||||
return players.remove(mPlayer);
|
||||
}
|
||||
mPlayer.setQuit(true);
|
||||
|
@ -129,7 +129,12 @@ public abstract class MatchImpl implements Match {
|
|||
@Override
|
||||
public boolean hasEnded() {
|
||||
return endTime != null;
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasStarted() {
|
||||
return startTime != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkIfMatchEnds() {
|
||||
|
|
Loading…
Reference in a new issue