mirror of
https://github.com/correl/mage.git
synced 2024-12-25 11:11:16 +00:00
Merge branch 'master' of https://github.com/magefree/mage.git
This commit is contained in:
commit
ec546a5ae6
7 changed files with 92 additions and 43 deletions
|
@ -35,6 +35,7 @@ import mage.MageObject;
|
||||||
import mage.ObjectColor;
|
import mage.ObjectColor;
|
||||||
import mage.abilities.Mode;
|
import mage.abilities.Mode;
|
||||||
import mage.cards.Card;
|
import mage.cards.Card;
|
||||||
|
import mage.counters.Counter;
|
||||||
import mage.counters.CounterType;
|
import mage.counters.CounterType;
|
||||||
import mage.game.permanent.Permanent;
|
import mage.game.permanent.Permanent;
|
||||||
import mage.game.permanent.PermanentToken;
|
import mage.game.permanent.PermanentToken;
|
||||||
|
@ -47,8 +48,6 @@ import mage.target.Targets;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import mage.counters.Counter;
|
|
||||||
import mage.counters.Counters;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author BetaSteward_at_googlemail.com
|
* @author BetaSteward_at_googlemail.com
|
||||||
|
@ -100,10 +99,11 @@ public class CardView extends SimpleCardView {
|
||||||
this.name = card.getName();
|
this.name = card.getName();
|
||||||
this.rules = card.getRules();
|
this.rules = card.getRules();
|
||||||
if (card instanceof Permanent) {
|
if (card instanceof Permanent) {
|
||||||
|
Permanent permanent = (Permanent)card;
|
||||||
this.power = Integer.toString(card.getPower().getValue());
|
this.power = Integer.toString(card.getPower().getValue());
|
||||||
this.toughness = Integer.toString(card.getToughness().getValue());
|
this.toughness = Integer.toString(card.getToughness().getValue());
|
||||||
this.loyalty = Integer.toString(((Permanent) card).getCounters().getCount(CounterType.LOYALTY));
|
this.loyalty = Integer.toString(permanent.getCounters().getCount(CounterType.LOYALTY));
|
||||||
this.pairedCard = ((Permanent)card).getPairedCard();
|
this.pairedCard = permanent.getPairedCard();
|
||||||
} else {
|
} else {
|
||||||
this.power = card.getPower().toString();
|
this.power = card.getPower().toString();
|
||||||
this.toughness = card.getToughness().toString();
|
this.toughness = card.getToughness().toString();
|
||||||
|
@ -169,21 +169,13 @@ public class CardView extends SimpleCardView {
|
||||||
this.color = card.getColor();
|
this.color = card.getColor();
|
||||||
this.manaCost = card.getManaCost().getSymbols();
|
this.manaCost = card.getManaCost().getSymbols();
|
||||||
this.convertedManaCost = card.getManaCost().convertedManaCost();
|
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) {
|
if (card instanceof PermanentToken) {
|
||||||
|
PermanentToken permanentToken = (PermanentToken) card;
|
||||||
this.rarity = Rarity.COMMON;
|
this.rarity = Rarity.COMMON;
|
||||||
this.expansionSetCode = ((PermanentToken) card).getExpansionSetCode();
|
this.expansionSetCode = permanentToken.getExpansionSetCode();
|
||||||
this.rules = ((PermanentToken) card).getRules();
|
this.rules = permanentToken.getRules();
|
||||||
this.type = ((PermanentToken)card).getToken().getTokenType();
|
this.type = permanentToken.getToken().getTokenType();
|
||||||
}
|
}
|
||||||
if (this.rarity == null && card instanceof StackAbility) {
|
if (this.rarity == null && card instanceof StackAbility) {
|
||||||
StackAbility stackAbility = (StackAbility)card;
|
StackAbility stackAbility = (StackAbility)card;
|
||||||
|
@ -245,34 +237,21 @@ public class CardView extends SimpleCardView {
|
||||||
this.manaCost = token.getManaCost().getSymbols();
|
this.manaCost = token.getManaCost().getSymbols();
|
||||||
this.rarity = Rarity.NA;
|
this.rarity = Rarity.NA;
|
||||||
this.type = token.getTokenType();
|
this.type = token.getTokenType();
|
||||||
//this.expansionSetCode = "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setTargets(Targets targets) {
|
protected final void setTargets(Targets targets) {
|
||||||
for (Target target : targets) {
|
for (Target target : targets) {
|
||||||
if (target.isChosen()) {
|
if (target.isChosen()) {
|
||||||
for (UUID targetUUID : target.getTargets()) {
|
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);
|
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() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,7 @@ import mage.server.tournament.TournamentFactory;
|
||||||
import mage.server.util.ConfigSettings;
|
import mage.server.util.ConfigSettings;
|
||||||
import mage.server.util.PluginClassLoader;
|
import mage.server.util.PluginClassLoader;
|
||||||
import mage.server.util.ServerMessagesUtil;
|
import mage.server.util.ServerMessagesUtil;
|
||||||
|
import mage.server.util.SystemUtil;
|
||||||
import mage.server.util.config.GamePlugin;
|
import mage.server.util.config.GamePlugin;
|
||||||
import mage.server.util.config.Plugin;
|
import mage.server.util.config.Plugin;
|
||||||
import mage.utils.MageVersion;
|
import mage.utils.MageVersion;
|
||||||
|
@ -106,6 +107,7 @@ public class Main {
|
||||||
}
|
}
|
||||||
else if (arg.startsWith(adminPasswordArg)) {
|
else if (arg.startsWith(adminPasswordArg)) {
|
||||||
adminPassword = arg.replace(adminPasswordArg, "");
|
adminPassword = arg.replace(adminPasswordArg, "");
|
||||||
|
adminPassword = SystemUtil.sanitize(adminPassword);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Connection connection = new Connection();
|
Connection connection = new Connection();
|
||||||
|
|
|
@ -28,9 +28,6 @@
|
||||||
|
|
||||||
package mage.server;
|
package mage.server;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
import mage.MageException;
|
import mage.MageException;
|
||||||
import mage.cards.decks.Deck;
|
import mage.cards.decks.Deck;
|
||||||
import mage.cards.decks.DeckCardLists;
|
import mage.cards.decks.DeckCardLists;
|
||||||
|
@ -43,6 +40,13 @@ import mage.game.tournament.Tournament;
|
||||||
import mage.game.tournament.TournamentOptions;
|
import mage.game.tournament.TournamentOptions;
|
||||||
import mage.players.Player;
|
import mage.players.Player;
|
||||||
import mage.server.game.GamesRoomManager;
|
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 {
|
public class TableManager {
|
||||||
|
|
||||||
|
protected static ScheduledExecutorService expireExecutor = Executors.newSingleThreadScheduledExecutor();
|
||||||
|
|
||||||
private final static TableManager INSTANCE = new TableManager();
|
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, TableController> controllers = new ConcurrentHashMap<UUID, TableController>();
|
||||||
private ConcurrentHashMap<UUID, Table> tables = new ConcurrentHashMap<UUID, Table>();
|
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() {
|
public static TableManager getInstance() {
|
||||||
return INSTANCE;
|
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) {
|
public Table createTable(UUID roomId, UUID userId, MatchOptions options) {
|
||||||
TableController tableController = new TableController(roomId, userId, options);
|
TableController tableController = new TableController(roomId, userId, options);
|
||||||
controllers.put(tableController.getTable().getId(), tableController);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -148,4 +148,20 @@ public class SystemUtil {
|
||||||
}
|
}
|
||||||
return null;
|
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") + "|");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,6 @@ import mage.Constants.Rarity;
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
import mage.abilities.effects.common.FightTargetsEffect;
|
import mage.abilities.effects.common.FightTargetsEffect;
|
||||||
import mage.cards.CardImpl;
|
import mage.cards.CardImpl;
|
||||||
import mage.filter.common.FilterCreaturePermanent;
|
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.target.common.TargetCreaturePermanent;
|
import mage.target.common.TargetCreaturePermanent;
|
||||||
|
|
||||||
|
@ -52,7 +51,7 @@ public class BloodFeud extends CardImpl<BloodFeud> {
|
||||||
// Target creature fights another target creature.
|
// Target creature fights another target creature.
|
||||||
this.getSpellAbility().addEffect(new FightTargetsEffect());
|
this.getSpellAbility().addEffect(new FightTargetsEffect());
|
||||||
this.getSpellAbility().addTarget(new TargetCreaturePermanent(true));
|
this.getSpellAbility().addTarget(new TargetCreaturePermanent(true));
|
||||||
this.getSpellAbility().addTarget(new TargetOtherCreaturePermanent(true));
|
this.getSpellAbility().addTarget(new TargetOtherCreaturePermanent());
|
||||||
}
|
}
|
||||||
|
|
||||||
public BloodFeud(final BloodFeud card) {
|
public BloodFeud(final BloodFeud card) {
|
||||||
|
@ -67,7 +66,7 @@ public class BloodFeud extends CardImpl<BloodFeud> {
|
||||||
|
|
||||||
class TargetOtherCreaturePermanent extends TargetCreaturePermanent {
|
class TargetOtherCreaturePermanent extends TargetCreaturePermanent {
|
||||||
|
|
||||||
public TargetOtherCreaturePermanent(boolean required) {
|
public TargetOtherCreaturePermanent() {
|
||||||
super(true);
|
super(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,8 +36,6 @@ import mage.abilities.Ability;
|
||||||
import mage.abilities.common.SimpleStaticAbility;
|
import mage.abilities.common.SimpleStaticAbility;
|
||||||
import mage.abilities.effects.ContinuousEffectImpl;
|
import mage.abilities.effects.ContinuousEffectImpl;
|
||||||
import mage.cards.CardImpl;
|
import mage.cards.CardImpl;
|
||||||
import mage.cards.Cards;
|
|
||||||
import mage.cards.CardsImpl;
|
|
||||||
import mage.filter.common.FilterCreatureCard;
|
import mage.filter.common.FilterCreatureCard;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.game.permanent.Permanent;
|
import mage.game.permanent.Permanent;
|
||||||
|
|
|
@ -27,7 +27,6 @@
|
||||||
*/
|
*/
|
||||||
package mage.sets.lorwyn;
|
package mage.sets.lorwyn;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import mage.Constants;
|
import mage.Constants;
|
||||||
import mage.Constants.CardType;
|
import mage.Constants.CardType;
|
||||||
|
|
Loading…
Reference in a new issue