mirror of
https://github.com/correl/mage.git
synced 2024-12-24 11:50:45 +00:00
* Some chnages to logging, added changes to table health check.
This commit is contained in:
parent
b57dbd4bb3
commit
00801e3ecf
5 changed files with 59 additions and 5 deletions
|
@ -209,7 +209,7 @@ public class TableController {
|
|||
tournamentPlayer.submitDeck(deck);
|
||||
}
|
||||
table.joinTable(player, seat);
|
||||
logger.trace("player " + player.getName() + " joined tableId: " + table.getId());
|
||||
logger.debug("Player " + player.getName() + " id: "+ player.getId() + " joined tableId: " + table.getId());
|
||||
//only inform human players and add them to sessionPlayerMap
|
||||
if (seat.getPlayer().isHuman()) {
|
||||
user.addTable(player.getId(), table);
|
||||
|
@ -866,7 +866,9 @@ public class TableController {
|
|||
if (table.getTournament() != null) {
|
||||
TournamentController tournamentController = TournamentManager.getInstance().getTournamentController(table.getTournament().getId());
|
||||
if (tournamentController != null) {
|
||||
//TODO: Check tournament state
|
||||
return tournamentController.isTournamentStillValid(table.getState());
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -81,7 +81,7 @@ public class TableManager {
|
|||
*
|
||||
* In minutes.
|
||||
*/
|
||||
private static final int EXPIRE_CHECK_PERIOD = 10;
|
||||
private static final int EXPIRE_CHECK_PERIOD = 1;
|
||||
|
||||
public static TableManager getInstance() {
|
||||
return INSTANCE;
|
||||
|
|
|
@ -71,6 +71,7 @@ public class User {
|
|||
private final String host;
|
||||
private final Date connectionTime;
|
||||
private final Map<UUID, Table> tables;
|
||||
private final ArrayList<UUID> tablesToDelete;
|
||||
private final Map<UUID, GameSessionPlayer> gameSessions;
|
||||
private final Map<UUID, DraftSession> draftSessions;
|
||||
private final Map<UUID, UUID> userTournaments; // playerId, tournamentId
|
||||
|
@ -100,7 +101,7 @@ public class User {
|
|||
this.constructing = new ConcurrentHashMap<>();
|
||||
this.sideboarding = new ConcurrentHashMap<>();
|
||||
this.watchedGames = new ArrayList<>();
|
||||
|
||||
this.tablesToDelete = new ArrayList<>();
|
||||
this.sessionId = "";
|
||||
}
|
||||
|
||||
|
@ -435,6 +436,7 @@ public class User {
|
|||
} else {
|
||||
// can happen if tournamet has just ended
|
||||
logger.debug(getName() + " tournament player missing - tableId:" + table.getId(), null);
|
||||
tablesToDelete.add(tableEntry.getKey());
|
||||
}
|
||||
} else {
|
||||
logger.error(getName() + " tournament key missing - tableId: " + table.getId(), null);
|
||||
|
@ -457,6 +459,12 @@ public class User {
|
|||
}
|
||||
}
|
||||
}
|
||||
if (!tablesToDelete.isEmpty()) {
|
||||
for(UUID keyId: tablesToDelete) {
|
||||
removeTable(keyId);
|
||||
}
|
||||
tablesToDelete.clear();
|
||||
}
|
||||
if (waiting > 0) {
|
||||
sb.append("Wait: ").append(waiting).append(" ");
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ public class PlayerFactory {
|
|||
if (playerTypeClass != null) {
|
||||
con = playerTypeClass.getConstructor(new Class[]{String.class, RangeOfInfluence.class, int.class});
|
||||
player = (Player)con.newInstance(new Object[] {name, range, skill});
|
||||
logger.debug("Player created: " + name + " - " + player.getId());
|
||||
logger.trace("Player created: " + name + " - " + player.getId());
|
||||
return player;
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -226,6 +226,7 @@ public class TournamentController {
|
|||
}
|
||||
}
|
||||
started = true;
|
||||
logger.debug("Tournament starts (all players joined): " + tournament.getId() + " - " + tournament.getTournamentType().toString());
|
||||
tournament.nextStep();
|
||||
}
|
||||
|
||||
|
@ -455,4 +456,47 @@ public class TournamentController {
|
|||
public void cleanUpOnRemoveTournament() {
|
||||
ChatManager.getInstance().destroyChatSession(chatId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check tournaments that are not already finished, if they are in a still valid state
|
||||
*
|
||||
* @param tableState state of the tournament table
|
||||
* @return true - if tournament is valid
|
||||
* false - if tournament is not valid and should be removed
|
||||
*/
|
||||
|
||||
public boolean isTournamentStillValid(TableState tableState) {
|
||||
int activePlayers = 0;
|
||||
for (Entry<UUID, UUID> entry: userPlayerMap.entrySet()) {
|
||||
TournamentPlayer tournamentPlayer = tournament.getPlayer(entry.getValue());
|
||||
if (tournamentPlayer != null) {
|
||||
if (!tournamentPlayer.hasQuit()) {
|
||||
if (tournamentPlayer.getPlayer().isHuman()) {
|
||||
User user = UserManager.getInstance().getUser(entry.getKey());
|
||||
if (user == null) {
|
||||
logger.debug("Tournament user is missing but player active -> start quit - tournamentId: " + tournament.getId() + " state: " + tableState.toString());
|
||||
// active tournament player but the user is no longer online
|
||||
quit(entry.getKey());
|
||||
}
|
||||
}
|
||||
activePlayers++;
|
||||
}
|
||||
} else {
|
||||
// tournament player is missing
|
||||
logger.debug("Tournament player is missing - tournamentId: " + tournament.getId() + " state: " + tableState.toString());
|
||||
}
|
||||
}
|
||||
for(TournamentPlayer tournamentPlayer: tournament.getPlayers()) {
|
||||
if (!tournamentPlayer.getPlayer().isHuman()) {
|
||||
if (!tournamentPlayer.hasQuit()) {
|
||||
activePlayers++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (activePlayers < 2 && !tableState.equals(TableState.WAITING)) {
|
||||
logger.debug("Tournament has less than 2 active players - tournamentId: " + tournament.getId() + " state: " + tableState.toString());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue