diff --git a/Mage.Server/src/mage/server/Session.java b/Mage.Server/src/mage/server/Session.java index 96707ff627..dc6265704a 100644 --- a/Mage.Server/src/mage/server/Session.java +++ b/Mage.Server/src/mage/server/Session.java @@ -48,6 +48,7 @@ public class Session { private UUID sessionId; private UUID clientId; private String username; + private int messageId = 0; private final CallbackServerSession callback = new CallbackServerSession(); public Session(String userName, UUID clientId) { @@ -78,6 +79,8 @@ public class Session { public void fireCallback(ClientCallback call) { try { + call.setMessageId(messageId++); + logger.info(sessionId + " - " + call.getMessageId() + " - " + call.getMethod()); callback.setCallback(call); } catch (InterruptedException ex) { logger.log(Level.SEVERE, null, ex); diff --git a/Mage.Server/src/mage/server/game/GameController.java b/Mage.Server/src/mage/server/game/GameController.java index 1437c5ea31..916aa2698b 100644 --- a/Mage.Server/src/mage/server/game/GameController.java +++ b/Mage.Server/src/mage/server/game/GameController.java @@ -104,6 +104,7 @@ public class GameController implements GameCallback { new Listener () { @Override public void event(PlayerQueryEvent event) { +// logger.info(event.getPlayerId() + "--" + event.getQueryType() + "--" + event.getMessage()); switch (event.getQueryType()) { case ASK: ask(event.getPlayerId(), event.getMessage()); @@ -132,6 +133,9 @@ public class GameController implements GameCallback { case AMOUNT: amount(event.getPlayerId(), event.getMessage(), event.getMin(), event.getMax()); break; + case LOOK: + lookAtCards(event.getPlayerId(), event.getMessage(), event.getCards()); + break; } } } @@ -257,7 +261,7 @@ public class GameController implements GameCallback { gameSessions.get(sessionPlayerMap.get(sessionId)).sendPlayerInteger(data); } - private void updateGame() { + private synchronized void updateGame() { for (final Entry entry: gameSessions.entrySet()) { entry.getValue().update(getGameView(entry.getKey())); @@ -267,57 +271,71 @@ public class GameController implements GameCallback { } } - private void ask(UUID playerId, String question) { + private synchronized void ask(UUID playerId, String question) { informOthers(playerId); - gameSessions.get(playerId).ask(question, getGameView(playerId)); + if (gameSessions.containsKey(playerId)) + gameSessions.get(playerId).ask(question, getGameView(playerId)); } - private void chooseAbility(UUID playerId, Collection choices) { + private synchronized void chooseAbility(UUID playerId, Collection choices) { informOthers(playerId); - gameSessions.get(playerId).chooseAbility(new AbilityPickerView(choices)); + if (gameSessions.containsKey(playerId)) + gameSessions.get(playerId).chooseAbility(new AbilityPickerView(choices)); } - private void choose(UUID playerId, String message, String[] choices) { + private synchronized void choose(UUID playerId, String message, String[] choices) { informOthers(playerId); - gameSessions.get(playerId).choose(message, choices); + if (gameSessions.containsKey(playerId)) + gameSessions.get(playerId).choose(message, choices); } - private void target(UUID playerId, String question, Cards cards, boolean required) { + private synchronized void target(UUID playerId, String question, Cards cards, boolean required) { informOthers(playerId); - gameSessions.get(playerId).target(question, new CardsView(cards), required, getGameView(playerId)); + if (gameSessions.containsKey(playerId)) + gameSessions.get(playerId).target(question, new CardsView(cards), required, getGameView(playerId)); } - private void target(UUID playerId, String question, Collection abilities, boolean required) { + private synchronized void target(UUID playerId, String question, Collection abilities, boolean required) { informOthers(playerId); - gameSessions.get(playerId).target(question, new CardsView(abilities, game), required, getGameView(playerId)); + if (gameSessions.containsKey(playerId)) + gameSessions.get(playerId).target(question, new CardsView(abilities, game), required, getGameView(playerId)); } - private void select(UUID playerId, String message) { + private synchronized void select(UUID playerId, String message) { informOthers(playerId); - gameSessions.get(playerId).select(message, getGameView(playerId)); + if (gameSessions.containsKey(playerId)) + gameSessions.get(playerId).select(message, getGameView(playerId)); } - private void playMana(UUID playerId, String message) { + private synchronized void playMana(UUID playerId, String message) { informOthers(playerId); - gameSessions.get(playerId).playMana(message, getGameView(playerId)); + if (gameSessions.containsKey(playerId)) + gameSessions.get(playerId).playMana(message, getGameView(playerId)); } - private void playXMana(UUID playerId, String message) { + private synchronized void playXMana(UUID playerId, String message) { informOthers(playerId); - gameSessions.get(playerId).playXMana(message, getGameView(playerId)); + if (gameSessions.containsKey(playerId)) + gameSessions.get(playerId).playXMana(message, getGameView(playerId)); } - private void amount(UUID playerId, String message, int min, int max) { + private synchronized void amount(UUID playerId, String message, int min, int max) { informOthers(playerId); - gameSessions.get(playerId).getAmount(message, min, max); + if (gameSessions.containsKey(playerId)) + gameSessions.get(playerId).getAmount(message, min, max); } - private void revealCards(String name, Cards cards) { + private synchronized void revealCards(String name, Cards cards) { for (GameSession session: gameSessions.values()) { session.revealCards(name, new CardsView(cards)); } } + private synchronized void lookAtCards(UUID playerId, String name, Cards cards) { + if (gameSessions.containsKey(playerId)) + gameSessions.get(playerId).revealCards(name, new CardsView(cards)); + } + private void informOthers(UUID playerId) { final String message = "Waiting for " + game.getPlayer(playerId).getName(); for (final Entry entry: gameSessions.entrySet()) { diff --git a/Mage.Server/src/mage/server/util/PluginClassLoader.java b/Mage.Server/src/mage/server/util/PluginClassLoader.java index 4d58e989be..75123cc606 100644 --- a/Mage.Server/src/mage/server/util/PluginClassLoader.java +++ b/Mage.Server/src/mage/server/util/PluginClassLoader.java @@ -34,6 +34,9 @@ import java.net.URLClassLoader; /** * * @author BetaSteward_at_googlemail.com + * + * some code courtesy of http://tech.puredanger.com/2006/11/09/classloader/ + * */ public class PluginClassLoader extends URLClassLoader {