mirror of
https://github.com/correl/mage.git
synced 2025-01-13 11:01:58 +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 java.util.UUID;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.game.GameState;
|
import mage.game.GameState;
|
||||||
|
import mage.game.Table;
|
||||||
import mage.game.match.Match;
|
import mage.game.match.Match;
|
||||||
import mage.game.match.MatchPlayer;
|
import mage.game.match.MatchPlayer;
|
||||||
import mage.players.Player;
|
import mage.players.Player;
|
||||||
|
@ -57,7 +58,7 @@ public class GameEndView implements Serializable {
|
||||||
private int loses;
|
private int loses;
|
||||||
private final int winsNeeded;
|
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();
|
startTime = game.getStartTime();
|
||||||
endTime = game.getEndTime();
|
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();
|
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;
|
MatchPlayer matchWinner = null;
|
||||||
winsNeeded = match.getOptions().getWinsNeeded();
|
winsNeeded = match.getOptions().getWinsNeeded();
|
||||||
StringBuilder additonalText = new StringBuilder();
|
StringBuilder additonalText = new StringBuilder();
|
||||||
|
|
|
@ -45,24 +45,33 @@ import mage.game.tournament.TournamentPlayer;
|
||||||
public class MatchView implements Serializable {
|
public class MatchView implements Serializable {
|
||||||
|
|
||||||
private final UUID tableId;
|
private final UUID tableId;
|
||||||
private final UUID matchId;
|
private UUID matchId;
|
||||||
private final String matchName;
|
private String matchName;
|
||||||
private String gameType;
|
private String gameType;
|
||||||
private final String deckType;
|
private String deckType;
|
||||||
|
|
||||||
private final List<UUID> games = new ArrayList<>();
|
private final List<UUID> games = new ArrayList<>();
|
||||||
private final String result;
|
private String result;
|
||||||
private final String players;
|
private String players;
|
||||||
|
|
||||||
private final Date startTime;
|
private Date startTime;
|
||||||
private final Date endTime;
|
private Date endTime;
|
||||||
private final boolean replayAvailable;
|
private boolean replayAvailable;
|
||||||
private final boolean isTournament;
|
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
|
// used for matches
|
||||||
public MatchView(Match match) {
|
private void initMatchTable(Table table) {
|
||||||
this.tableId = null;
|
Match match = table.getMatch();
|
||||||
this.isTournament = false;
|
|
||||||
this.matchId = match.getId();
|
this.matchId = match.getId();
|
||||||
this.matchName = match.getName();
|
this.matchName = match.getName();
|
||||||
this.gameType = match.getOptions().getGameType();
|
this.gameType = match.getOptions().getGameType();
|
||||||
|
@ -102,9 +111,7 @@ public class MatchView implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
// used for tournaments
|
// used for tournaments
|
||||||
public MatchView(Table table) {
|
private void initTournamentTable(Table table) {
|
||||||
this.tableId = table.getId();
|
|
||||||
this.isTournament = true;
|
|
||||||
this.matchId = table.getTournament().getId();
|
this.matchId = table.getTournament().getId();
|
||||||
this.matchName = table.getName();
|
this.matchName = table.getName();
|
||||||
this.gameType = table.getGameType();
|
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) {
|
public synchronized boolean replaceDraftPlayer(Player oldPlayer, String name, String playerType, int skill) {
|
||||||
Player newPlayer = createPlayer(name, playerType, skill);
|
Player newPlayer = createPlayer(name, playerType, skill);
|
||||||
if (newPlayer == null || table.getState() != TableState.DRAFTING) {
|
if (newPlayer == null || table.getState() != TableState.DRAFTING) {
|
||||||
|
@ -404,7 +408,7 @@ public class TableController {
|
||||||
} else if (!table.getState().equals(TableState.FINISHED)) {
|
} else if (!table.getState().equals(TableState.FINISHED)) {
|
||||||
if (table.isTournament()) {
|
if (table.isTournament()) {
|
||||||
logger.debug("Quit tournament sub tables for userId: " + userId);
|
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());
|
logger.debug("Quit tournament Id: " + table.getTournament().getId());
|
||||||
TournamentManager.getInstance().quit(tournament.getId(), userId);
|
TournamentManager.getInstance().quit(tournament.getId(), userId);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -181,15 +181,17 @@ public class TableManager {
|
||||||
public void userQuitTournamentSubTables(UUID tournamentId, UUID userId) {
|
public void userQuitTournamentSubTables(UUID tournamentId, UUID userId) {
|
||||||
for (TableController controller: controllers.values()) {
|
for (TableController controller: controllers.values()) {
|
||||||
if (controller.getTable().isTournamentSubTable() && controller.getTable().getTournament().getId().equals(tournamentId)) {
|
if (controller.getTable().isTournamentSubTable() && controller.getTable().getTournament().getId().equals(tournamentId)) {
|
||||||
|
if (controller.isPlayer(userId)) {
|
||||||
Match match = controller.getTable().getMatch();
|
Match match = controller.getTable().getMatch();
|
||||||
if (match != null) {
|
if (match != null) {
|
||||||
if (match.getGame() != null) {
|
if (!match.hasEnded() && match.getGame() != null) {
|
||||||
GameManager.getInstance().quitMatch(match.getGame().getId(), userId);
|
GameManager.getInstance().quitMatch(match.getGame().getId(), userId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isTableOwner(UUID tableId, UUID userId) {
|
public boolean isTableOwner(UUID tableId, UUID userId) {
|
||||||
if (controllers.containsKey(tableId)) {
|
if (controllers.containsKey(tableId)) {
|
||||||
|
|
|
@ -193,7 +193,10 @@ public class UserManager {
|
||||||
|
|
||||||
public void handleException(Exception ex) {
|
public void handleException(Exception ex) {
|
||||||
if (ex != null) {
|
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();
|
ex.printStackTrace();
|
||||||
}else {
|
}else {
|
||||||
logger.fatal("User manager exception - null");
|
logger.fatal("User manager exception - null");
|
||||||
|
|
|
@ -536,7 +536,7 @@ public class GameController implements GameCallback {
|
||||||
if (table != null) {
|
if (table != null) {
|
||||||
if (table.getMatch() != null) {
|
if (table.getMatch() != null) {
|
||||||
for (final GameSession gameSession: gameSessions.values()) {
|
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.ScheduledExecutorService;
|
||||||
import java.util.concurrent.ScheduledFuture;
|
import java.util.concurrent.ScheduledFuture;
|
||||||
import java.util.concurrent.TimeUnit;
|
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) {
|
if (!killed) {
|
||||||
User user = UserManager.getInstance().getUser(userId);
|
User user = UserManager.getInstance().getUser(userId);
|
||||||
if (user != null) {
|
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 java.util.UUID;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.game.match.Match;
|
import mage.game.Table;
|
||||||
import mage.interfaces.callback.ClientCallback;
|
import mage.interfaces.callback.ClientCallback;
|
||||||
import mage.server.User;
|
import mage.server.User;
|
||||||
import mage.server.UserManager;
|
import mage.server.UserManager;
|
||||||
|
@ -123,8 +123,8 @@ public class GameWatcher {
|
||||||
return new GameView(game.getState(), game, null);
|
return new GameView(game.getState(), game, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GameEndView getGameEndView(UUID playerId, Match match) {
|
public GameEndView getGameEndView(UUID playerId, Table table) {
|
||||||
return new GameEndView(game.getState(), game, playerId, match);
|
return new GameEndView(game.getState(), game, playerId, table);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPlayer() {
|
public boolean isPlayer() {
|
||||||
|
|
|
@ -103,7 +103,7 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
|
||||||
if (table.isTournament()) {
|
if (table.isTournament()) {
|
||||||
matchList.add(new MatchView(table));
|
matchList.add(new MatchView(table));
|
||||||
} else {
|
} else {
|
||||||
matchList.add(new MatchView(table.getMatch()));
|
matchList.add(new MatchView(table));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// more since 50 matches finished since this match so remove it
|
// more since 50 matches finished since this match so remove it
|
||||||
|
|
|
@ -50,6 +50,7 @@ public interface Match {
|
||||||
UUID getId();
|
UUID getId();
|
||||||
String getName();
|
String getName();
|
||||||
boolean hasEnded();
|
boolean hasEnded();
|
||||||
|
boolean hasStarted();
|
||||||
boolean checkIfMatchEnds();
|
boolean checkIfMatchEnds();
|
||||||
List<MatchPlayer> getPlayers();
|
List<MatchPlayer> getPlayers();
|
||||||
MatchPlayer getPlayer(UUID playerId);
|
MatchPlayer getPlayer(UUID playerId);
|
||||||
|
|
|
@ -63,7 +63,7 @@ public abstract class MatchImpl implements Match {
|
||||||
|
|
||||||
public MatchImpl(MatchOptions options) {
|
public MatchImpl(MatchOptions options) {
|
||||||
this.options = options;
|
this.options = options;
|
||||||
startTime = new Date();
|
startTime = null;
|
||||||
replayAvailable = false;
|
replayAvailable = false;
|
||||||
draws = 0;
|
draws = 0;
|
||||||
}
|
}
|
||||||
|
@ -93,7 +93,7 @@ public abstract class MatchImpl implements Match {
|
||||||
public boolean leave(UUID playerId) {
|
public boolean leave(UUID playerId) {
|
||||||
MatchPlayer mPlayer = getPlayer(playerId);
|
MatchPlayer mPlayer = getPlayer(playerId);
|
||||||
if (mPlayer != null) {
|
if (mPlayer != null) {
|
||||||
if (startedGames == 0) {
|
if (!hasStarted()) {
|
||||||
return players.remove(mPlayer);
|
return players.remove(mPlayer);
|
||||||
}
|
}
|
||||||
mPlayer.setQuit(true);
|
mPlayer.setQuit(true);
|
||||||
|
@ -129,7 +129,12 @@ public abstract class MatchImpl implements Match {
|
||||||
@Override
|
@Override
|
||||||
public boolean hasEnded() {
|
public boolean hasEnded() {
|
||||||
return endTime != null;
|
return endTime != null;
|
||||||
};
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasStarted() {
|
||||||
|
return startTime != null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean checkIfMatchEnds() {
|
public boolean checkIfMatchEnds() {
|
||||||
|
|
Loading…
Reference in a new issue