1
0
Fork 0
mirror of https://github.com/correl/mage.git synced 2025-04-12 17:00:08 -09:00

fixed issue 103 - this should catch most card logic errors, log the error on the server and trigger a message on the client

This commit is contained in:
BetaSteward 2011-06-17 22:42:04 -04:00
parent 29865e79af
commit 82654f10d5
7 changed files with 44 additions and 5 deletions
Mage.Client/src/main/java/mage/client/remote
Mage.Server/src/main/java/mage/server/game
Mage/src/mage/game

View file

@ -141,6 +141,12 @@ public class CallbackClientImpl implements CallbackClient {
panel.hideGame();
}
}
else if (callback.getMethod().equals("gameError")) {
GamePanel panel = frame.getGame(callback.getObjectId());
if (panel != null) {
panel.modalMessage((String) callback.getData());
}
}
else if (callback.getMethod().equals("gameAsk")) {
GameClientMessage message = (GameClientMessage) callback.getData();
GamePanel panel = frame.getGame(callback.getObjectId());

View file

@ -117,6 +117,9 @@ public class GameController implements GameCallback {
case REVEAL:
revealCards(event.getMessage(), event.getCards());
break;
case ERROR:
error(event.getMessage());
break;
}
} catch (MageException ex) {
logger.fatal("Table event listener error ", ex);
@ -416,6 +419,12 @@ public class GameController implements GameCallback {
}
}
private void error(String message) {
for (final Entry<UUID, GameSession> entry: gameSessions.entrySet()) {
entry.getValue().gameError(message);
}
}
private GameView getGameView() {
return new GameView(game.getState(), game);
}

View file

@ -95,6 +95,15 @@ public class GameWatcher {
}
}
public void gameError(final String message) {
if (!killed) {
Session session = SessionManager.getInstance().getSession(sessionId);
if (session != null) {
session.fireCallback(new ClientCallback("gameError", gameId, message));
}
}
}
protected void handleRemoteException(RemoteException ex) {
logger.fatal("GameWatcher error", ex);
GameManager.getInstance().kill(gameId, sessionId);

View file

@ -131,7 +131,8 @@ public interface Game extends MageItem, Serializable {
public void fireInformEvent(String message);
public void fireUpdatePlayersEvent();
public void informPlayers(String message);
public void fireErrorEvent(String message);
//game event methods
public void fireEvent(GameEvent event);
public boolean replaceEvent(GameEvent event);

View file

@ -519,6 +519,9 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
state.getPlayerList().getNext();
}
}
} catch (Exception ex) {
logger.fatal("Game exception ", ex);
this.fireErrorEvent("Game exception occurred: " + ex.getMessage() + " - " + ex.getStackTrace()[0]);
} finally {
resetLKI();
}
@ -833,6 +836,11 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
tableEventSource.fireTableEvent(EventType.UPDATE, null, this);
}
@Override
public void fireErrorEvent(String message) {
tableEventSource.fireTableEvent(EventType.ERROR, message, this);
}
@Override
public Players getPlayers() {
return state.getPlayers();

View file

@ -45,7 +45,8 @@ import mage.game.tournament.TournamentPairing;
public class TableEvent extends EventObject implements ExternalEvent, Serializable {
public enum EventType {
UPDATE, INFO, REVEAL, LOOK, START_DRAFT, START_MATCH, SIDEBOARD, CONSTRUCT, SUBMIT_DECK, END}
UPDATE, INFO, REVEAL, LOOK, START_DRAFT, START_MATCH, SIDEBOARD, CONSTRUCT, SUBMIT_DECK, END, ERROR
}
private Game game;
private Draft draft;

View file

@ -58,9 +58,14 @@ public class SpellStack extends Stack<StackObject> {
//resolve top StackObject
public void resolve(Game game) {
StackObject top = this.peek();
top.resolve(game);
this.remove(top);
StackObject top = null;
try {
top = this.peek();
top.resolve(game);
} finally {
if (top != null)
this.remove(top);
}
}
public void checkTriggers(GameEvent event, Game game) {