diff --git a/Mage.Common/src/main/java/mage/remote/SessionImpl.java b/Mage.Common/src/main/java/mage/remote/SessionImpl.java index 6f46e4bd8c..20918b9b91 100644 --- a/Mage.Common/src/main/java/mage/remote/SessionImpl.java +++ b/Mage.Common/src/main/java/mage/remote/SessionImpl.java @@ -1,5 +1,12 @@ package mage.remote; +import java.io.*; +import java.lang.reflect.UndeclaredThrowableException; +import java.net.*; +import java.util.*; +import java.util.concurrent.CancellationException; +import java.util.concurrent.TimeUnit; +import javax.swing.*; import mage.MageException; import mage.cards.decks.DeckCardLists; import mage.cards.repository.CardInfo; @@ -28,14 +35,6 @@ import org.jboss.remoting.transport.bisocket.Bisocket; import org.jboss.remoting.transport.socket.SocketWrapper; import org.jboss.remoting.transporter.TransporterClient; -import javax.swing.*; -import java.io.*; -import java.lang.reflect.UndeclaredThrowableException; -import java.net.*; -import java.util.*; -import java.util.concurrent.CancellationException; -import java.util.concurrent.TimeUnit; - /** * @author BetaSteward_at_googlemail.com, JayDi85 */ @@ -502,7 +501,7 @@ public class SessionImpl implements Session { /** * @param askForReconnect - true = connection was lost because of error and - * ask the user if they want to try to reconnect + * ask the user if they want to try to reconnect */ @Override public synchronized void disconnect(boolean askForReconnect) { @@ -557,8 +556,21 @@ public class SessionImpl implements Session { @Override public void handleCallback(Callback callback) throws HandleCallbackException { - //logger.info("callback handler"); - client.processCallback((ClientCallback) callback.getCallbackObject()); + try { +// Object object = callback.getCallbackObject(); +// if (((ClientCallback) object).getMethod().equals(ClientCallbackMethod.GAME_TARGET)) { +// Object data = ((ClientCallback) object).getData(); +// if (data instanceof GameClientMessage) { +// GameClientMessage message = (GameClientMessage) ((ClientCallback) object).getData(); +// logger.info("Client Session Event->" + ((ClientCallback) object).getMethod() + " (id:" + ((ClientCallback) object).getMessageId() + ") " + message.getMessage() +// ); +// } +// } + client.processCallback((ClientCallback) callback.getCallbackObject()); + } catch (Exception ex) { + logger.error("handleCallback error", ex); + } + } } diff --git a/Mage.Server/src/main/java/mage/server/Session.java b/Mage.Server/src/main/java/mage/server/Session.java index be7d035750..83b8ec85e8 100644 --- a/Mage.Server/src/main/java/mage/server/Session.java +++ b/Mage.Server/src/main/java/mage/server/Session.java @@ -1,4 +1,3 @@ - package mage.server; import java.util.*; @@ -352,7 +351,16 @@ public class Session { if (valid && callBackLock.tryLock(50, TimeUnit.MILLISECONDS)) { call.setMessageId(messageId++); lockSet = true; - callbackHandler.handleCallbackOneway(new Callback(call)); + Callback callback = new Callback(call); +// if (call.getMethod().equals(ClientCallbackMethod.GAME_TARGET)) { +// Object object = call.getData(); +// if (object instanceof GameClientMessage) { +// String message = ((GameClientMessage) object).getMessage(); +// logger.info("Server Session Event->" + call.getMethod() + " (id:" + call.getMessageId() + ") " + message); +// logger.info(callback.toString()); +// } +// } + callbackHandler.handleCallbackOneway(callback); } } catch (InterruptedException ex) { logger.warn("SESSION LOCK - fireCallback - userId: " + userId + " messageId: " + call.getMessageId(), ex); @@ -364,6 +372,8 @@ public class Session { logger.trace("Stack trace:", ex); SessionManager.instance.disconnect(sessionId, LostConnection); }); + } catch (Exception ex) { + logger.warn("Unspecific exception:", ex); } finally { if (lockSet) { callBackLock.unlock(); diff --git a/Mage.Sets/src/mage/cards/e/Expropriate.java b/Mage.Sets/src/mage/cards/e/Expropriate.java index e7a8f86539..2229dfaaa9 100644 --- a/Mage.Sets/src/mage/cards/e/Expropriate.java +++ b/Mage.Sets/src/mage/cards/e/Expropriate.java @@ -47,6 +47,8 @@ public final class Expropriate extends CardImpl { class ExpropriateDilemmaEffect extends CouncilsDilemmaVoteEffect { + private ArrayList choiceTwoVoters = new ArrayList<>(); + public ExpropriateDilemmaEffect() { super(Outcome.Benefit); this.staticText = "Council's dilemma — Starting with you, each player votes for time or money. For each time vote, take an extra turn after this one. For each money vote, choose a permanent owned by the voter and gain control of it"; @@ -56,10 +58,6 @@ class ExpropriateDilemmaEffect extends CouncilsDilemmaVoteEffect { super(effect); } - public ExpropriateDilemmaEffect(Outcome outcome) { - super(outcome); - } - @Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); @@ -99,7 +97,7 @@ class ExpropriateDilemmaEffect extends CouncilsDilemmaVoteEffect { private void controlForMoneyVote(Player controller, Game game, Ability source) { List chosenCards = new ArrayList<>(); - for (UUID playerId : choiceTwoVoters.keySet()) { + for (UUID playerId : choiceTwoVoters) { FilterPermanent filter = new FilterPermanent("permanent owned by " + game.getPlayer(playerId).getName()); filter.add(new OwnerIdPredicate(playerId)); @@ -125,6 +123,25 @@ class ExpropriateDilemmaEffect extends CouncilsDilemmaVoteEffect { } } + @Override + protected void vote(String choiceOne, String choiceTwo, Player controller, Game game, Ability source) { + for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { + Player player = game.getPlayer(playerId); + if (player != null) { + if (player.chooseUse(Outcome.Vote, + "Choose " + choiceOne + " or " + choiceTwo + "?", + source.getRule(), choiceOne, choiceTwo, source, game)) { + voteOneCount++; + game.informPlayers(player.getName() + " has voted for " + choiceOne); + } else { + voteTwoCount++; + game.informPlayers(player.getName() + " has voted for " + choiceTwo); + choiceTwoVoters.add(player.getId()); + } + } + } + } + @Override public ExpropriateDilemmaEffect copy() { return new ExpropriateDilemmaEffect(this); @@ -154,8 +171,11 @@ class ExpropriateControlEffect extends ContinuousEffectImpl { @Override public boolean apply(Game game, Ability source) { Permanent permanent = game.getPermanent(targetPointer.getFirst(game, source)); - return permanent != null - && controllerId != null - && permanent.changeControllerId(controllerId, game); + if (permanent == null || controllerId == null) { + this.discard(); + } else { + permanent.changeControllerId(controllerId, game); + } + return true; } } diff --git a/Mage/src/main/java/mage/abilities/effects/common/CouncilsDilemmaVoteEffect.java b/Mage/src/main/java/mage/abilities/effects/common/CouncilsDilemmaVoteEffect.java index e163072017..87ab736ab1 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/CouncilsDilemmaVoteEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/CouncilsDilemmaVoteEffect.java @@ -6,7 +6,6 @@ import mage.abilities.effects.OneShotEffect; import mage.constants.Outcome; import mage.game.Game; import mage.players.Player; -import mage.players.Players; /** * @author JRHerlehy @@ -14,8 +13,6 @@ import mage.players.Players; public abstract class CouncilsDilemmaVoteEffect extends OneShotEffect { protected int voteOneCount = 0, voteTwoCount = 0; - protected final Players choiceOneVoters = new Players(); - protected final Players choiceTwoVoters = new Players(); public CouncilsDilemmaVoteEffect(Outcome outcome) { super(outcome); @@ -33,11 +30,9 @@ public abstract class CouncilsDilemmaVoteEffect extends OneShotEffect { "Choose " + choiceOne + " or " + choiceTwo + "?", source.getRule(), choiceOne, choiceTwo, source, game)) { voteOneCount++; - choiceOneVoters.addPlayer(player); game.informPlayers(player.getName() + " has voted for " + choiceOne); } else { voteTwoCount++; - choiceTwoVoters.addPlayer(player); game.informPlayers(player.getName() + " has voted for " + choiceTwo); } } diff --git a/Mage/src/main/java/mage/game/events/EventDispatcher.java b/Mage/src/main/java/mage/game/events/EventDispatcher.java index 51b96d5c81..0e89cb46ba 100644 --- a/Mage/src/main/java/mage/game/events/EventDispatcher.java +++ b/Mage/src/main/java/mage/game/events/EventDispatcher.java @@ -1,5 +1,3 @@ - - package mage.game.events; import java.io.Serializable; @@ -30,7 +28,7 @@ public abstract class EventDispatcher implements Serial listener.event(event); } } - + public void removeAllListener() { listeners.clear(); }