Fixed - join tournament late

This commit is contained in:
jakub.salavec
2025-04-28 12:05:57 +02:00
parent 6b8271953e
commit ee2fa5e6e6
4 changed files with 37 additions and 4 deletions

View File

@@ -555,10 +555,11 @@ public class HallServer extends AbstractServer {
if (tournament.getInfo().Parameters().requiresDeck) { if (tournament.getInfo().Parameters().requiresDeck) {
lotroDeck = validateUserAndDeck(_formatLibrary.getFormat(tournament.getFormatCode()), player, deckName, tournament.getCollectionType()); lotroDeck = validateUserAndDeck(_formatLibrary.getFormat(tournament.getFormatCode()), player, deckName, tournament.getCollectionType());
} }
if (_tournamentService.joinTournamentLate(tournamentId, player.getName(), lotroDeck)) {
_tournamentService.recordTournamentPlayer(tournamentId, player.getName(), lotroDeck); result = "Joined tournament <b>" + tournament.getTournamentName() + "</b> successfully.";
tournament.issuePlayerMaterial(player.getName()); } else {
result = "Joined tournament <b>" + tournament.getTournamentName() + "</b> successfully."; result = "Joining tournament <b>" + tournament.getTournamentName() + "</b> failed.";
}
hallChanged(); hallChanged();
} }

View File

@@ -536,4 +536,26 @@ public abstract class BaseTournament implements Tournament {
public String getTableDescription() { public String getTableDescription() {
return null; return null;
} }
@Override
public boolean join(String playerName, LotroDeck lotroDeck) {
// Assumes the deck is validated for the tournament or null if the tournament is limited
writeLock.lock();
try {
if (!isJoinable()) {
return false;
}
if (_players.contains(playerName)) {
return false;
}
_tournamentService.recordTournamentPlayer(_tournamentId, playerName, lotroDeck);
issuePlayerMaterial(playerName);
_players.add(playerName);
regeneratePlayerList();
return true;
} finally {
writeLock.unlock();
}
}
} }

View File

@@ -206,6 +206,7 @@ public interface Tournament {
TournamentInfo getInfo(); TournamentInfo getInfo();
boolean isJoinable(); boolean isJoinable();
boolean join(String playerName, LotroDeck lotroDeck);
long getSecondsRemaining() throws IllegalStateException; long getSecondsRemaining() throws IllegalStateException;
String getTableDescription(); String getTableDescription();
} }

View File

@@ -332,6 +332,15 @@ public class TournamentService {
_tournamentPlayerDao.addPlayer(tournamentId, playerName, deck); _tournamentPlayerDao.addPlayer(tournamentId, playerName, deck);
} }
public boolean joinTournamentLate(String tournamentId, String playerName, LotroDeck deck) {
// Assumes the deck is validated for the tournament or null if the tournament is limited
Tournament tournament = getTournamentById(tournamentId);
if (tournament == null) {
return false;
}
return tournament.join(playerName, deck);
}
public void recordPlayerTournamentAbandon(String tournamentId, String playerName) { public void recordPlayerTournamentAbandon(String tournamentId, String playerName) {
_tournamentPlayerDao.dropPlayer(tournamentId, playerName); _tournamentPlayerDao.dropPlayer(tournamentId, playerName);
} }