return false;
}
Seat seat = table.getNextAvailableSeat(playerType);
if (seat == null) {
throw new GameException("No available seats.");
}
User user = UserManager.getInstance().getUser(userId);
if (user == null) {
logger.fatal(new StringBuilder("couldn't get user ").append(name).append(" for join tournament userId = ").append(userId).toString());
return false;
}
// check password
if (!table.getTournament().getOptions().getPassword().isEmpty() && playerType.equals("Human")) {
if (!table.getTournament().getOptions().getPassword().equals(password)) {
user.showUserMessage("Join Table", "Wrong password.");
return false;
}
}
if (userPlayerMap.containsKey(userId) && playerType.equals("Human")){
user.showUserMessage("Join Table", new StringBuilder("You can join a table only one time.").toString());
return false;
}
Deck deck = null;
if (!table.getTournament().getTournamentType().isLimited()) {
if (deckList != null) {
deck = Deck.load(deckList, false, false);
} else {
user.showUserMessage("Join Table", "No valid deck selected!");
return false;
}
if (!Main.isTestMode() && !table.getValidator().validate(deck)) {
StringBuilder sb = new StringBuilder("You (").append(name).append(") have an invalid deck for the selected ").append(table.getValidator().getName()).append(" Format. \n\n");
for (Map.Entry<String, String> entry : table.getValidator().getInvalid().entrySet()) {
sb.append(entry.getKey()).append(": ").append(entry.getValue()).append("\n");
}
sb.append("\n\nSelect a deck that is appropriate for the selected format and try again!");
user.showUserMessage("Join Table", sb.toString());
if (isOwner(userId)) {
logger.debug("New table removed because owner submitted invalid deck tableId " + table.getId());
TableManager.getInstance().removeTable(table.getId());
}
return false;
}
}
Player player = createPlayer(name, seat.getPlayerType(), skill);
if (player != null) {
if (!player.canJoinTable(table)) {
user.showUserMessage("Join Table", new StringBuilder("A ").append(seat.getPlayerType()).append(" player can't join this table.").toString());
return false;
}
tournament.addPlayer(player, seat.getPlayerType());
TournamentPlayer tournamentPlayer = tournament.getPlayer(player.getId());
if (deck != null && tournamentPlayer != null) {
tournamentPlayer.submitDeck(deck);
}
table.joinTable(player, seat);
logger.trace("player " + player.getName() + " joined tableId: " + table.getId());
//only inform human players and add them to sessionPlayerMap
if (seat.getPlayer().isHuman()) {
user.addTable(player.getId(), table);
user.joinedTable(table.getRoomId(), table.getId(), true);
userPlayerMap.put(userId, player.getId());
}
return true;
} else {
throw new GameException("Playertype " + seat.getPlayerType() + " could not be created.");
}
}