* Tournaments - Added handling for constructed formats and password protection.

This commit is contained in:
LevelX2 2014-10-12 04:19:28 +02:00
parent 8459e8d1f9
commit 5ccc1c91ae
32 changed files with 666 additions and 267 deletions

View file

@ -236,7 +236,7 @@ public class MageServerImpl implements MageServer {
}
@Override
public boolean joinTournamentTable(final String sessionId, final UUID roomId, final UUID tableId, final String name, final String playerType, final int skill) throws MageException, GameException {
public boolean joinTournamentTable(final String sessionId, final UUID roomId, final UUID tableId, final String name, final String playerType, final int skill, final DeckCardLists deckList, final String password) throws MageException, GameException {
return executeWithResult("joinTournamentTable", sessionId, new ActionWithBooleanResult() {
@Override
public Boolean execute() throws MageException {
@ -251,7 +251,7 @@ public class MageServerImpl implements MageServer {
logger.fatal("Got no userId from sessionId" + sessionId + " tableId" + tableId);
return false;
}
boolean ret = GamesRoomManager.getInstance().getRoom(roomId).joinTournamentTable(userId, tableId, name, playerType, skill);
boolean ret = GamesRoomManager.getInstance().getRoom(roomId).joinTournamentTable(userId, tableId, name, playerType, skill, deckList, password);
return ret;
}
});

View file

@ -149,10 +149,11 @@ public class TableController {
);
}
public synchronized boolean joinTournament(UUID userId, String name, String playerType, int skill) throws GameException {
public synchronized boolean joinTournament(UUID userId, String name, String playerType, int skill, DeckCardLists deckList, String password) throws GameException {
if (table.getState() != TableState.WAITING) {
return false;
}
Seat seat = table.getNextAvailableSeat(playerType);
if (seat == null) {
throw new GameException("No available seats.");
@ -162,10 +163,36 @@ public class TableController {
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 (deckList != null) {
deck = Deck.load(deckList, false, 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)) {
@ -173,6 +200,10 @@ public class TableController {
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

View file

@ -148,9 +148,9 @@ public class TableManager {
return false;
}
public boolean joinTournament(UUID userId, UUID tableId, String name, String playerType, int skill) throws GameException {
public boolean joinTournament(UUID userId, UUID tableId, String name, String playerType, int skill, DeckCardLists deckList, String password) throws GameException {
if (controllers.containsKey(tableId)) {
return controllers.get(tableId).joinTournament(userId, name, playerType, skill);
return controllers.get(tableId).joinTournament(userId, name, playerType, skill, deckList, password);
}
return false;
}

View file

@ -32,7 +32,7 @@ import java.lang.reflect.Constructor;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import mage.cards.decks.*;
import mage.cards.decks.DeckValidator;
import org.apache.log4j.Logger;
/**
@ -44,7 +44,7 @@ public class DeckValidatorFactory {
private static final DeckValidatorFactory INSTANCE = new DeckValidatorFactory();
private static final Logger logger = Logger.getLogger(DeckValidatorFactory.class);
private Map<String, Class> deckTypes = new LinkedHashMap<String, Class>();
private final Map<String, Class> deckTypes = new LinkedHashMap<>();
public static DeckValidatorFactory getInstance() {
return INSTANCE;

View file

@ -39,7 +39,6 @@ import mage.server.Room;
import mage.view.MatchView;
import mage.view.RoomUsersView;
import mage.view.TableView;
import mage.view.UsersView;
/**
*
@ -51,7 +50,7 @@ public interface GamesRoom extends Room {
List<MatchView> getFinished();
List<RoomUsersView> getRoomUsersInfo();
boolean joinTable(UUID userId, UUID tableId, String name, String playerType, int skill, DeckCardLists deckList, String password) throws MageException;
boolean joinTournamentTable(UUID userId, UUID tableId, String name, String playerType, int skill) throws GameException;
boolean joinTournamentTable(UUID userId, UUID tableId, String name, String playerType, int skill, DeckCardLists deckList, String password) throws GameException;
TableView createTable(UUID userId, MatchOptions options);
TableView createTournamentTable(UUID userId, TournamentOptions options);
void removeTable(UUID userId, UUID tableId);

View file

@ -155,9 +155,9 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
}
@Override
public boolean joinTournamentTable(UUID userId, UUID tableId, String name, String playerType, int skill) throws GameException {
public boolean joinTournamentTable(UUID userId, UUID tableId, String name, String playerType, int skill, DeckCardLists deckList, String password) throws GameException {
if (tables.containsKey(tableId)) {
return TableManager.getInstance().joinTournament(userId, tableId, name, playerType, skill);
return TableManager.getInstance().joinTournament(userId, tableId, name, playerType, skill, deckList, password);
} else {
return false;
}

View file

@ -69,13 +69,13 @@ public class TournamentFactory {
tournament = con.newInstance(new Object[] {options});
// transfer set information, create short info string for included sets
tournament.setTournamentType(tournamentTypes.get(tournamentType));
Map<String,Integer> setInfo = new LinkedHashMap<>();
for (String setCode: options.getLimitedOptions().getSetCodes()) {
tournament.getSets().add(Sets.findSet(setCode));
int count = setInfo.containsKey(setCode) ? setInfo.get(setCode) : 0;
setInfo.put(setCode, count + 1);
}
if (tournament.getTournamentType().isLimited()) {
Map<String,Integer> setInfo = new LinkedHashMap<>();
for (String setCode: options.getLimitedOptions().getSetCodes()) {
tournament.getSets().add(Sets.findSet(setCode));
int count = setInfo.containsKey(setCode) ? setInfo.get(setCode) : 0;
setInfo.put(setCode, count + 1);
}
tournament.getOptions().getLimitedOptions().setNumberBoosters(tournament.getTournamentType().getNumBoosters());
if (tournament.getTournamentType().isCubeBooster()) {
tournament.getOptions().getLimitedOptions().setDraftCube(CubeFactory.getInstance().createDraftCube(tournament.getOptions().getLimitedOptions().getDraftCubeName()));
@ -87,14 +87,15 @@ public class TournamentFactory {
}
tournament.setBoosterInfo(sb.toString());
}
} else {
tournament.setBoosterInfo("");
}
} catch (Exception ex) {
logger.fatal("TournamentFactory error ", ex);
return null;
}
logger.debug("Tournament created: " + tournamentType); // + game.getId().toString());
logger.debug("Tournament created: " + tournamentType + " " + tournament.getId());
return tournament;
}