* Sideboarding: fixed that it possible to auto-submit 40 cards deck instead 60 in constructed formats (#5579);

Sideboarding: fixed that cheated deck with sideboard can be used instead lose the game;
This commit is contained in:
Oleg Agafonov 2019-04-01 07:34:46 +04:00
parent 3dd6836559
commit de4befb9c2
22 changed files with 204 additions and 124 deletions

View file

@ -2,6 +2,7 @@ package mage.server;
import mage.MageException;
import mage.cards.decks.DeckCardLists;
import mage.cards.decks.DeckValidatorFactory;
import mage.cards.repository.CardInfo;
import mage.cards.repository.CardRepository;
import mage.cards.repository.ExpansionInfo;
@ -142,7 +143,7 @@ public class MageServerImpl implements MageServer {
return SessionManager.instance.connectUser(sessionId, userName, password, userIdStr);
} catch (MageException ex) {
if (ex instanceof MageVersionException) {
throw (MageVersionException) ex;
throw ex;
}
handleException(ex);
}
@ -268,7 +269,7 @@ public class MageServerImpl implements MageServer {
}
@Override
public boolean joinTable(final String sessionId, final UUID roomId, final UUID tableId, final String name, final PlayerType playerType, final int skill, final DeckCardLists deckList, final String password) throws MageException, GameException {
public boolean joinTable(final String sessionId, final UUID roomId, final UUID tableId, final String name, final PlayerType playerType, final int skill, final DeckCardLists deckList, final String password) throws MageException {
return executeWithResult("joinTable", sessionId, new ActionWithBooleanResult() {
@Override
public Boolean execute() throws MageException {
@ -293,7 +294,7 @@ public class MageServerImpl implements MageServer {
}
@Override
public boolean joinTournamentTable(final String sessionId, final UUID roomId, final UUID tableId, final String name, final PlayerType playerType, final int skill, final DeckCardLists deckList, final String password) throws MageException, GameException {
public boolean joinTournamentTable(final String sessionId, final UUID roomId, final UUID tableId, final String name, final PlayerType playerType, final int skill, final DeckCardLists deckList, final String password) throws MageException {
return executeWithResult("joinTournamentTable", sessionId, new ActionWithBooleanResult() {
@Override
public Boolean execute() throws MageException {
@ -321,7 +322,7 @@ public class MageServerImpl implements MageServer {
}
@Override
public boolean submitDeck(final String sessionId, final UUID tableId, final DeckCardLists deckList) throws MageException, GameException {
public boolean submitDeck(final String sessionId, final UUID tableId, final DeckCardLists deckList) throws MageException {
return executeWithResult("submitDeck", sessionId, new ActionWithBooleanResult() {
@Override
public Boolean execute() throws MageException {
@ -339,7 +340,7 @@ public class MageServerImpl implements MageServer {
}
@Override
public void updateDeck(final String sessionId, final UUID tableId, final DeckCardLists deckList) throws MageException, GameException {
public void updateDeck(final String sessionId, final UUID tableId, final DeckCardLists deckList) throws MageException {
execute("updateDeck", sessionId, () -> {
Optional<Session> session = SessionManager.instance.getSession(sessionId);
if (!session.isPresent()) {

View file

@ -2,6 +2,7 @@ package mage.server;
import mage.cards.ExpansionSet;
import mage.cards.Sets;
import mage.cards.decks.DeckValidatorFactory;
import mage.cards.repository.CardScanner;
import mage.cards.repository.PluginClassloaderRegistery;
import mage.cards.repository.RepositoryUtil;
@ -11,7 +12,6 @@ import mage.game.tournament.TournamentType;
import mage.interfaces.MageServer;
import mage.remote.Connection;
import mage.server.draft.CubeFactory;
import mage.server.game.DeckValidatorFactory;
import mage.server.game.GameFactory;
import mage.server.game.PlayerFactory;
import mage.server.record.UserStatsRepository;

View file

@ -1,17 +1,9 @@
package mage.server;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import mage.MageException;
import mage.cards.decks.Deck;
import mage.cards.decks.DeckCardLists;
import mage.cards.decks.DeckValidatorFactory;
import mage.constants.RangeOfInfluence;
import mage.constants.TableState;
import mage.game.*;
@ -28,12 +20,10 @@ import mage.game.tournament.TournamentPlayer;
import mage.players.Player;
import mage.players.PlayerType;
import mage.server.draft.DraftManager;
import mage.server.game.DeckValidatorFactory;
import mage.server.game.GameFactory;
import mage.server.game.GameManager;
import mage.server.game.PlayerFactory;
import mage.server.record.TableRecorderImpl;
import mage.server.tournament.TournamentController;
import mage.server.tournament.TournamentFactory;
import mage.server.tournament.TournamentManager;
import mage.server.util.ConfigSettings;
@ -42,6 +32,16 @@ import mage.server.util.ThreadExecutor;
import mage.view.ChatMessage;
import org.apache.log4j.Logger;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
/**
* @author BetaSteward_at_googlemail.com
*/
@ -876,7 +876,7 @@ public class TableController {
private void autoSideboard() {
for (MatchPlayer player : match.getPlayers()) {
if (!player.isDoneSideboarding()) {
match.submitDeck(player.getPlayer().getId(), player.generateDeck());
match.submitDeck(player.getPlayer().getId(), player.generateDeck(table.getValidator()));
}
}
}
@ -927,9 +927,9 @@ public class TableController {
public boolean isTournamentStillValid() {
if (table.getTournament() != null) {
if (table.getState() != TableState.WAITING && table.getState() != TableState.READY_TO_START && table.getState() != TableState.STARTING) {
return TournamentManager.instance.getTournamentController(table.getTournament().getId())
.map(tc -> tc.isTournamentStillValid(table.getState()))
.orElse(false);
return TournamentManager.instance.getTournamentController(table.getTournament().getId())
.map(tc -> tc.isTournamentStillValid(table.getState()))
.orElse(false);
} else {
// check if table creator is still a valid user, if not removeUserFromAllTablesAndChat table

View file

@ -1,53 +0,0 @@
package mage.server.game;
import mage.cards.decks.DeckValidator;
import org.apache.log4j.Logger;
import java.lang.reflect.Constructor;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public enum DeckValidatorFactory {
instance;
private static final Logger logger = Logger.getLogger(DeckValidatorFactory.class);
private final Map<String, Class> deckTypes = new LinkedHashMap<>();
private DeckValidatorFactory() {}
public DeckValidator createDeckValidator(String deckType) {
DeckValidator validator;
try {
Constructor<?> con = deckTypes.get(deckType).getConstructor();
validator = (DeckValidator)con.newInstance();
} catch (Exception ex) {
logger.fatal("DeckValidatorFactory error", ex);
return null;
}
logger.debug("Deck validator created: " + validator.getName());
return validator;
}
public Set<String> getDeckTypes() {
return deckTypes.keySet();
}
public void addDeckType(String name, Class deckType) {
if (deckType != null) {
this.deckTypes.put(name, deckType);
}
}
}