This commit is contained in:
LevelX2 2013-03-10 13:46:02 +01:00
commit ec546a5ae6
7 changed files with 92 additions and 43 deletions

View file

@ -35,6 +35,7 @@ import mage.MageObject;
import mage.ObjectColor;
import mage.abilities.Mode;
import mage.cards.Card;
import mage.counters.Counter;
import mage.counters.CounterType;
import mage.game.permanent.Permanent;
import mage.game.permanent.PermanentToken;
@ -47,8 +48,6 @@ import mage.target.Targets;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import mage.counters.Counter;
import mage.counters.Counters;
/**
* @author BetaSteward_at_googlemail.com
@ -100,10 +99,11 @@ public class CardView extends SimpleCardView {
this.name = card.getName();
this.rules = card.getRules();
if (card instanceof Permanent) {
Permanent permanent = (Permanent)card;
this.power = Integer.toString(card.getPower().getValue());
this.toughness = Integer.toString(card.getToughness().getValue());
this.loyalty = Integer.toString(((Permanent) card).getCounters().getCount(CounterType.LOYALTY));
this.pairedCard = ((Permanent)card).getPairedCard();
this.loyalty = Integer.toString(permanent.getCounters().getCount(CounterType.LOYALTY));
this.pairedCard = permanent.getPairedCard();
} else {
this.power = card.getPower().toString();
this.toughness = card.getToughness().toString();
@ -169,21 +169,13 @@ public class CardView extends SimpleCardView {
this.color = card.getColor();
this.manaCost = card.getManaCost().getSymbols();
this.convertedManaCost = card.getManaCost().convertedManaCost();
// if (card instanceof Card) {
// Counters cardCounters = ((Card) card).getCounters();
// if (cardCounters != null && !cardCounters.isEmpty()) {
// counters = new ArrayList<CounterView>();
// for (Counter counter: cardCounters.values()) {
// counters.add(new CounterView(counter));
// }
// }
// }
if (card instanceof PermanentToken) {
PermanentToken permanentToken = (PermanentToken) card;
this.rarity = Rarity.COMMON;
this.expansionSetCode = ((PermanentToken) card).getExpansionSetCode();
this.rules = ((PermanentToken) card).getRules();
this.type = ((PermanentToken)card).getToken().getTokenType();
this.expansionSetCode = permanentToken.getExpansionSetCode();
this.rules = permanentToken.getRules();
this.type = permanentToken.getToken().getTokenType();
}
if (this.rarity == null && card instanceof StackAbility) {
StackAbility stackAbility = (StackAbility)card;
@ -245,34 +237,21 @@ public class CardView extends SimpleCardView {
this.manaCost = token.getManaCost().getSymbols();
this.rarity = Rarity.NA;
this.type = token.getTokenType();
//this.expansionSetCode = "";
}
protected void setTargets(Targets targets) {
protected final void setTargets(Targets targets) {
for (Target target : targets) {
if (target.isChosen()) {
for (UUID targetUUID : target.getTargets()) {
if (this.targets == null) this.targets = new ArrayList<UUID>();
if (this.targets == null) {
this.targets = new ArrayList<UUID>();
}
this.targets.add(targetUUID);
}
}
}
}
// protected List<String> formatRules(List<String> rules) {
// List<String> newRules = new ArrayList<String>();
// for (String rule: rules) {
// newRules.add(formatRule(rule));
// }
// return newRules;
// }
//
// protected String formatRule(String rule) {
// String replace = rule.replace("{this}", this.name);
// replace = replace.replace("{source}", this.name);
// return replace;
// }
public String getName() {
return name;
}

View file

@ -40,6 +40,7 @@ import mage.server.tournament.TournamentFactory;
import mage.server.util.ConfigSettings;
import mage.server.util.PluginClassLoader;
import mage.server.util.ServerMessagesUtil;
import mage.server.util.SystemUtil;
import mage.server.util.config.GamePlugin;
import mage.server.util.config.Plugin;
import mage.utils.MageVersion;
@ -106,6 +107,7 @@ public class Main {
}
else if (arg.startsWith(adminPasswordArg)) {
adminPassword = arg.replace(adminPasswordArg, "");
adminPassword = SystemUtil.sanitize(adminPassword);
}
}
Connection connection = new Connection();

View file

@ -28,9 +28,6 @@
package mage.server;
import java.util.Collection;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import mage.MageException;
import mage.cards.decks.Deck;
import mage.cards.decks.DeckCardLists;
@ -43,6 +40,13 @@ import mage.game.tournament.Tournament;
import mage.game.tournament.TournamentOptions;
import mage.players.Player;
import mage.server.game.GamesRoomManager;
import org.apache.log4j.Logger;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
/**
*
@ -50,16 +54,48 @@ import mage.server.game.GamesRoomManager;
*/
public class TableManager {
protected static ScheduledExecutorService expireExecutor = Executors.newSingleThreadScheduledExecutor();
private final static TableManager INSTANCE = new TableManager();
//private final static Logger logger = Logger.getLogger(TableManager.class);
private final static Logger logger = Logger.getLogger(TableManager.class);
private ConcurrentHashMap<UUID, TableController> controllers = new ConcurrentHashMap<UUID, TableController>();
private ConcurrentHashMap<UUID, Table> tables = new ConcurrentHashMap<UUID, Table>();
/**
* Defines how often checking process should be run on server.
*
* In minutes.
*/
private static final int EXPIRE_CHECK_PERIOD = 10;
/**
* This parameters defines when table can be counted as expired.
* Uses EXPIRE_TIME_UNIT_VALUE as unit of measurement.
*
* The time pass is calculated as (table_created_at - now) / EXPIRE_TIME_UNIT_VALUE.
* Then this values is compared to EXPIRE_TIME.
*/
private static final int EXPIRE_TIME = 3;
/**
* Defines unit of measurement for expiration time of tables created.
*/
private static final int EXPIRE_TIME_UNIT_VALUE = 1000 * 60 * 60; // 1 hour
public static TableManager getInstance() {
return INSTANCE;
}
private TableManager() {
expireExecutor.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
checkExpired();
}
}, EXPIRE_CHECK_PERIOD, EXPIRE_CHECK_PERIOD, TimeUnit.MINUTES);
}
public Table createTable(UUID roomId, UUID userId, MatchOptions options) {
TableController tableController = new TableController(roomId, userId, options);
controllers.put(tableController.getTable().getId(), tableController);
@ -232,4 +268,24 @@ public class TableManager {
}
}
private void checkExpired() {
logger.info("Table expire checking...");
Date now = new Date();
List<UUID> toRemove = new ArrayList<UUID>();
for (Table table : tables.values()) {
long diff = (now.getTime() - table.getCreateTime().getTime()) / EXPIRE_TIME_UNIT_VALUE;
if (diff >= EXPIRE_TIME) {
logger.info("Table expired: id = " + table.getId() + ", created_by=" + table.getControllerName() + ". Removing...");
toRemove.add(table.getId());
}
}
for (UUID tableId : toRemove) {
try {
removeTable(tableId);
} catch (Exception e) {
logger.error(e);
}
}
}
}

View file

@ -148,4 +148,20 @@ public class SystemUtil {
}
return null;
}
public static String sanitize(String input) {
//Pattern pattern = Pattern.compile("[^0-9a-zA-Z]");
//Matcher matcher = pattern.matcher(input);
//return matcher.replaceAll("");
return input.replaceAll("[^a-zA-Z0-9]", "");
}
public static void main(String... args) {
System.out.println(sanitize("123"));
System.out.println(sanitize("AaAaD_123"));
System.out.println(sanitize("--sas-"));
System.out.println(sanitize("anPlsdf123_") + "|");
System.out.println(sanitize("anPlsdf123 ") + "|");
System.out.println(sanitize("anPlsdf123\r\n") + "|");
}
}

View file

@ -33,7 +33,6 @@ import mage.Constants.Rarity;
import mage.abilities.Ability;
import mage.abilities.effects.common.FightTargetsEffect;
import mage.cards.CardImpl;
import mage.filter.common.FilterCreaturePermanent;
import mage.game.Game;
import mage.target.common.TargetCreaturePermanent;
@ -52,7 +51,7 @@ public class BloodFeud extends CardImpl<BloodFeud> {
// Target creature fights another target creature.
this.getSpellAbility().addEffect(new FightTargetsEffect());
this.getSpellAbility().addTarget(new TargetCreaturePermanent(true));
this.getSpellAbility().addTarget(new TargetOtherCreaturePermanent(true));
this.getSpellAbility().addTarget(new TargetOtherCreaturePermanent());
}
public BloodFeud(final BloodFeud card) {
@ -67,7 +66,7 @@ public class BloodFeud extends CardImpl<BloodFeud> {
class TargetOtherCreaturePermanent extends TargetCreaturePermanent {
public TargetOtherCreaturePermanent(boolean required) {
public TargetOtherCreaturePermanent() {
super(true);
}

View file

@ -36,8 +36,6 @@ import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.ContinuousEffectImpl;
import mage.cards.CardImpl;
import mage.cards.Cards;
import mage.cards.CardsImpl;
import mage.filter.common.FilterCreatureCard;
import mage.game.Game;
import mage.game.permanent.Permanent;

View file

@ -27,7 +27,6 @@
*/
package mage.sets.lorwyn;
import java.util.List;
import java.util.UUID;
import mage.Constants;
import mage.Constants.CardType;