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) {
lotroDeck = validateUserAndDeck(_formatLibrary.getFormat(tournament.getFormatCode()), player, deckName, tournament.getCollectionType());
}
_tournamentService.recordTournamentPlayer(tournamentId, player.getName(), lotroDeck);
tournament.issuePlayerMaterial(player.getName());
if (_tournamentService.joinTournamentLate(tournamentId, player.getName(), lotroDeck)) {
result = "Joined tournament <b>" + tournament.getTournamentName() + "</b> successfully.";
} else {
result = "Joining tournament <b>" + tournament.getTournamentName() + "</b> failed.";
}
hallChanged();
}

View File

@@ -536,4 +536,26 @@ public abstract class BaseTournament implements Tournament {
public String getTableDescription() {
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();
boolean isJoinable();
boolean join(String playerName, LotroDeck lotroDeck);
long getSecondsRemaining() throws IllegalStateException;
String getTableDescription();
}

View File

@@ -332,6 +332,15 @@ public class TournamentService {
_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) {
_tournamentPlayerDao.dropPlayer(tournamentId, playerName);
}