mirror of
https://github.com/magefree/mage.git
synced 2025-12-20 10:40:06 -08:00
* added bad connection mode to test client works on slow network, use -Dxmage.badconnection; * added bad connection protection in events processing due event type; * split events to different types (can be ignored, must be synced, etc); * removed some unused server events.
This commit is contained in:
parent
fa8e93a29d
commit
342979a55a
10 changed files with 299 additions and 202 deletions
|
|
@ -250,6 +250,11 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
|
||||||
LOGGER.fatal(null, ex);
|
LOGGER.fatal(null, ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// other settings
|
||||||
|
if (ClientCallback.SIMULATE_BAD_CONNECTION) {
|
||||||
|
LOGGER.info("Network: bad connection mode enabled");
|
||||||
|
}
|
||||||
|
|
||||||
// DATA PREPARE
|
// DATA PREPARE
|
||||||
RepositoryUtil.bootstrapLocalDb();
|
RepositoryUtil.bootstrapLocalDb();
|
||||||
// re-create database on empty (e.g. after new build cleaned db on startup)
|
// re-create database on empty (e.g. after new build cleaned db on startup)
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,6 @@ public class FeedbackPanel extends javax.swing.JPanel {
|
||||||
private FeedbackMode mode;
|
private FeedbackMode mode;
|
||||||
private MageDialog connectedDialog;
|
private MageDialog connectedDialog;
|
||||||
private ChatPanelBasic connectedChatPanel;
|
private ChatPanelBasic connectedChatPanel;
|
||||||
private int lastMessageId;
|
|
||||||
private Map<String, Serializable> lastOptions = new HashMap<>();
|
private Map<String, Serializable> lastOptions = new HashMap<>();
|
||||||
|
|
||||||
private static final ScheduledExecutorService WORKER = Executors.newSingleThreadScheduledExecutor();
|
private static final ScheduledExecutorService WORKER = Executors.newSingleThreadScheduledExecutor();
|
||||||
|
|
@ -66,14 +65,8 @@ public class FeedbackPanel extends javax.swing.JPanel {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void prepareFeedback(FeedbackMode mode, String message, boolean special, Map<String, Serializable> options,
|
public void prepareFeedback(FeedbackMode mode, String message, boolean special, Map<String, Serializable> options,
|
||||||
int messageId, boolean gameNeedUserFeedback, TurnPhase gameTurnPhase) {
|
boolean gameNeedUserFeedback, TurnPhase gameTurnPhase) {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if (messageId < this.lastMessageId) {
|
|
||||||
// if too many warning messages here then look at GAME_REDRAW_GUI event logic
|
|
||||||
LOGGER.warn("catch un-synced message from later source (possible reason: connection or performance problems): " + messageId + ", text=" + message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.lastMessageId = messageId;
|
|
||||||
this.lastOptions = options;
|
this.lastOptions = options;
|
||||||
this.mode = mode;
|
this.mode = mode;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -122,8 +122,8 @@ public final class GamePanel extends javax.swing.JPanel {
|
||||||
private JPopupMenu popupMenuTriggerOrder;
|
private JPopupMenu popupMenuTriggerOrder;
|
||||||
|
|
||||||
// keep game data for updates/re-draws
|
// keep game data for updates/re-draws
|
||||||
// warning, it keeps updates from GAME_UPDATE events only and ignore another events with GameView
|
|
||||||
static class LastGameData {
|
static class LastGameData {
|
||||||
|
int messageId;
|
||||||
GameView game;
|
GameView game;
|
||||||
boolean showPlayable;
|
boolean showPlayable;
|
||||||
Map<String, Serializable> options;
|
Map<String, Serializable> options;
|
||||||
|
|
@ -571,7 +571,7 @@ public final class GamePanel extends javax.swing.JPanel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void init(GameView game) {
|
public synchronized void init(int messageId, GameView game) {
|
||||||
addPlayers(game);
|
addPlayers(game);
|
||||||
// default menu states
|
// default menu states
|
||||||
setMenuStates(
|
setMenuStates(
|
||||||
|
|
@ -581,7 +581,7 @@ public final class GamePanel extends javax.swing.JPanel {
|
||||||
holdingPriority
|
holdingPriority
|
||||||
);
|
);
|
||||||
|
|
||||||
updateGame(game);
|
updateGame(messageId, game);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addPlayers(GameView game) {
|
private void addPlayers(GameView game) {
|
||||||
|
|
@ -706,12 +706,12 @@ public final class GamePanel extends javax.swing.JPanel {
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void updateGame(GameView game) {
|
public synchronized void updateGame(int messageId, GameView game) {
|
||||||
updateGame(game, false, null, null);
|
updateGame(messageId, game, false, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void updateGame(GameView game, boolean showPlayable, Map<String, Serializable> options, Set<UUID> targets) {
|
public synchronized void updateGame(int messageId, GameView game, boolean showPlayable, Map<String, Serializable> options, Set<UUID> targets) {
|
||||||
keepLastGameData(game, showPlayable, options, targets);
|
keepLastGameData(messageId, game, showPlayable, options, targets);
|
||||||
prepareSelectableView();
|
prepareSelectableView();
|
||||||
updateGame();
|
updateGame();
|
||||||
}
|
}
|
||||||
|
|
@ -946,6 +946,7 @@ public final class GamePanel extends javax.swing.JPanel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//logger.info("game update, message = " + lastGameData.messageId + ", options = " + lastGameData.options + ", priority = " + lastGameData.game.getPriorityPlayerName());
|
||||||
feedbackPanel.disableUndo();
|
feedbackPanel.disableUndo();
|
||||||
feedbackPanel.updateOptions(lastGameData.options);
|
feedbackPanel.updateOptions(lastGameData.options);
|
||||||
|
|
||||||
|
|
@ -1361,12 +1362,13 @@ public final class GamePanel extends javax.swing.JPanel {
|
||||||
windowMap.entrySet().removeIf(entry -> entry.getValue().isClosed());
|
windowMap.entrySet().removeIf(entry -> entry.getValue().isClosed());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ask(String question, GameView gameView, int messageId, Map<String, Serializable> options) {
|
public void ask(int messageId, GameView gameView, String question, Map<String, Serializable> options) {
|
||||||
updateGame(gameView, false, options, null);
|
updateGame(messageId, gameView, false, options, null);
|
||||||
this.feedbackPanel.prepareFeedback(FeedbackMode.QUESTION, question, false, options, messageId, true, gameView.getPhase());
|
this.feedbackPanel.prepareFeedback(FeedbackMode.QUESTION, question, false, options, true, gameView.getPhase());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void keepLastGameData(GameView game, boolean showPlayable, Map<String, Serializable> options, Set<UUID> targets) {
|
private void keepLastGameData(int messageId, GameView game, boolean showPlayable, Map<String, Serializable> options, Set<UUID> targets) {
|
||||||
|
lastGameData.messageId = messageId;
|
||||||
lastGameData.game = game;
|
lastGameData.game = game;
|
||||||
lastGameData.showPlayable = showPlayable;
|
lastGameData.showPlayable = showPlayable;
|
||||||
lastGameData.options = options;
|
lastGameData.options = options;
|
||||||
|
|
@ -1623,8 +1625,8 @@ public final class GamePanel extends javax.swing.JPanel {
|
||||||
* @param options
|
* @param options
|
||||||
* @param messageId
|
* @param messageId
|
||||||
*/
|
*/
|
||||||
public void pickTarget(GameView gameView, Map<String, Serializable> options, String message, CardsView cardsView, Set<UUID> targets, boolean required, int messageId) {
|
public void pickTarget(int messageId, GameView gameView, Map<String, Serializable> options, String message, CardsView cardsView, Set<UUID> targets, boolean required) {
|
||||||
updateGame(gameView, false, options, targets);
|
updateGame(messageId, gameView, false, options, targets);
|
||||||
hideAll();
|
hideAll();
|
||||||
DialogManager.getManager(gameId).fadeOut();
|
DialogManager.getManager(gameId).fadeOut();
|
||||||
clearPickTargetDialogs();
|
clearPickTargetDialogs();
|
||||||
|
|
@ -1652,28 +1654,28 @@ public final class GamePanel extends javax.swing.JPanel {
|
||||||
dialog = prepareCardsDialog(message, cardsView, required, options0, popupMenuType);
|
dialog = prepareCardsDialog(message, cardsView, required, options0, popupMenuType);
|
||||||
options0.put("dialog", dialog);
|
options0.put("dialog", dialog);
|
||||||
}
|
}
|
||||||
this.feedbackPanel.prepareFeedback(required ? FeedbackMode.INFORM : FeedbackMode.CANCEL, message, gameView.getSpecial(), options0, messageId, true, gameView.getPhase());
|
this.feedbackPanel.prepareFeedback(required ? FeedbackMode.INFORM : FeedbackMode.CANCEL, message, gameView.getSpecial(), options0, true, gameView.getPhase());
|
||||||
if (dialog != null) {
|
if (dialog != null) {
|
||||||
this.pickTarget.add(dialog);
|
this.pickTarget.add(dialog);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void inform(String information, GameView gameView, int messageId) {
|
public void inform(int messageId, GameView gameView, String information) {
|
||||||
updateGame(gameView);
|
updateGame(messageId, gameView);
|
||||||
this.feedbackPanel.prepareFeedback(FeedbackMode.INFORM, information, gameView.getSpecial(), null, messageId, false, gameView.getPhase());
|
this.feedbackPanel.prepareFeedback(FeedbackMode.INFORM, information, gameView.getSpecial(), null, false, gameView.getPhase());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void endMessage(GameView gameView, Map<String, Serializable> options, String message, int messageId) {
|
public void endMessage(int messageId, GameView gameView, Map<String, Serializable> options, String message) {
|
||||||
updateGame(gameView, false, options, null);
|
updateGame(messageId, gameView, false, options, null);
|
||||||
hideAll();
|
hideAll();
|
||||||
DialogManager.getManager(gameId).fadeOut();
|
DialogManager.getManager(gameId).fadeOut();
|
||||||
|
|
||||||
this.feedbackPanel.prepareFeedback(FeedbackMode.END, message, false, null, messageId, true, null);
|
this.feedbackPanel.prepareFeedback(FeedbackMode.END, message, false, null, true, null);
|
||||||
ArrowBuilder.getBuilder().removeAllArrows(gameId);
|
ArrowBuilder.getBuilder().removeAllArrows(gameId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void select(GameView gameView, Map<String, Serializable> options, String message, int messageId) {
|
public void select(int messageId, GameView gameView, Map<String, Serializable> options, String message) {
|
||||||
updateGame(gameView, true, options, null);
|
updateGame(messageId, gameView, true, options, null);
|
||||||
hideAll();
|
hideAll();
|
||||||
DialogManager.getManager(gameId).fadeOut();
|
DialogManager.getManager(gameId).fadeOut();
|
||||||
|
|
||||||
|
|
@ -1716,31 +1718,31 @@ public final class GamePanel extends javax.swing.JPanel {
|
||||||
priorityPlayerText = " / priority " + gameView.getPriorityPlayerName();
|
priorityPlayerText = " / priority " + gameView.getPriorityPlayerName();
|
||||||
}
|
}
|
||||||
String messageToDisplay = message + FeedbackPanel.getSmallText(activePlayerText + " / " + gameView.getStep().toString() + priorityPlayerText);
|
String messageToDisplay = message + FeedbackPanel.getSmallText(activePlayerText + " / " + gameView.getStep().toString() + priorityPlayerText);
|
||||||
this.feedbackPanel.prepareFeedback(FeedbackMode.SELECT, messageToDisplay, gameView.getSpecial(), panelOptions, messageId, true, gameView.getPhase());
|
this.feedbackPanel.prepareFeedback(FeedbackMode.SELECT, messageToDisplay, gameView.getSpecial(), panelOptions, true, gameView.getPhase());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void playMana(GameView gameView, Map<String, Serializable> options, String message, int messageId) {
|
public void playMana(int messageId, GameView gameView, Map<String, Serializable> options, String message) {
|
||||||
updateGame(gameView, true, options, null);
|
updateGame(messageId, gameView, true, options, null);
|
||||||
hideAll();
|
hideAll();
|
||||||
DialogManager.getManager(gameId).fadeOut();
|
DialogManager.getManager(gameId).fadeOut();
|
||||||
|
|
||||||
this.feedbackPanel.prepareFeedback(FeedbackMode.CANCEL, message, gameView.getSpecial(), options, messageId, true, gameView.getPhase());
|
this.feedbackPanel.prepareFeedback(FeedbackMode.CANCEL, message, gameView.getSpecial(), options, true, gameView.getPhase());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void playXMana(GameView gameView, Map<String, Serializable> options, String message, int messageId) {
|
public void playXMana(int messageId, GameView gameView, Map<String, Serializable> options, String message) {
|
||||||
updateGame(gameView, true, options, null);
|
updateGame(messageId, gameView, true, options, null);
|
||||||
hideAll();
|
hideAll();
|
||||||
DialogManager.getManager(gameId).fadeOut();
|
DialogManager.getManager(gameId).fadeOut();
|
||||||
|
|
||||||
this.feedbackPanel.prepareFeedback(FeedbackMode.CONFIRM, message, gameView.getSpecial(), null, messageId, true, gameView.getPhase());
|
this.feedbackPanel.prepareFeedback(FeedbackMode.CONFIRM, message, gameView.getSpecial(), null, true, gameView.getPhase());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void replayMessage(String message) {
|
public void replayMessage(String message) {
|
||||||
//TODO: implement this
|
//TODO: implement this
|
||||||
}
|
}
|
||||||
|
|
||||||
public void pickAbility(GameView gameView, Map<String, Serializable> options, AbilityPickerView choices) {
|
public void pickAbility(int messageId, GameView gameView, Map<String, Serializable> options, AbilityPickerView choices) {
|
||||||
updateGame(gameView, false, options, null);
|
updateGame(messageId, gameView, false, options, null);
|
||||||
hideAll();
|
hideAll();
|
||||||
DialogManager.getManager(gameId).fadeOut();
|
DialogManager.getManager(gameId).fadeOut();
|
||||||
|
|
||||||
|
|
@ -1764,8 +1766,8 @@ public final class GamePanel extends javax.swing.JPanel {
|
||||||
return showCards;
|
return showCards;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getAmount(GameView gameView, Map<String, Serializable> options, int min, int max, String message) {
|
public void getAmount(int messageId, GameView gameView, Map<String, Serializable> options, int min, int max, String message) {
|
||||||
updateGame(gameView, false, options, null);
|
updateGame(messageId, gameView, false, options, null);
|
||||||
hideAll();
|
hideAll();
|
||||||
DialogManager.getManager(gameId).fadeOut();
|
DialogManager.getManager(gameId).fadeOut();
|
||||||
|
|
||||||
|
|
@ -1777,9 +1779,9 @@ public final class GamePanel extends javax.swing.JPanel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getMultiAmount(List<MultiAmountMessage> messages, GameView gameView, Map<String, Serializable> options,
|
public void getMultiAmount(int messageId, GameView gameView, List<MultiAmountMessage> messages, Map<String, Serializable> options,
|
||||||
int min, int max) {
|
int min, int max) {
|
||||||
updateGame(gameView, false, options, null);
|
updateGame(messageId, gameView, false, options, null);
|
||||||
hideAll();
|
hideAll();
|
||||||
DialogManager.getManager(gameId).fadeOut();
|
DialogManager.getManager(gameId).fadeOut();
|
||||||
|
|
||||||
|
|
@ -1787,8 +1789,8 @@ public final class GamePanel extends javax.swing.JPanel {
|
||||||
SessionHandler.sendPlayerString(gameId, pickMultiNumber.getMultiAmount());
|
SessionHandler.sendPlayerString(gameId, pickMultiNumber.getMultiAmount());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getChoice(GameView gameView, Map<String, Serializable> options, Choice choice, UUID objectId) {
|
public void getChoice(int messageId, GameView gameView, Map<String, Serializable> options, Choice choice, UUID objectId) {
|
||||||
updateGame(gameView, false, options, null);
|
updateGame(messageId, gameView, false, options, null);
|
||||||
hideAll();
|
hideAll();
|
||||||
DialogManager.getManager(gameId).fadeOut();
|
DialogManager.getManager(gameId).fadeOut();
|
||||||
|
|
||||||
|
|
@ -1813,8 +1815,8 @@ public final class GamePanel extends javax.swing.JPanel {
|
||||||
pickChoice.removeDialog();
|
pickChoice.removeDialog();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void pickPile(GameView gameView, Map<String, Serializable> options, String message, CardsView pile1, CardsView pile2) {
|
public void pickPile(int messageId, GameView gameView, Map<String, Serializable> options, String message, CardsView pile1, CardsView pile2) {
|
||||||
updateGame(gameView, false, options, null);
|
updateGame(messageId, gameView, false, options, null);
|
||||||
hideAll();
|
hideAll();
|
||||||
DialogManager.getManager(gameId).fadeOut();
|
DialogManager.getManager(gameId).fadeOut();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ import mage.client.util.audio.AudioManager;
|
||||||
import mage.client.util.object.SaveObjectUtil;
|
import mage.client.util.object.SaveObjectUtil;
|
||||||
import mage.interfaces.callback.CallbackClient;
|
import mage.interfaces.callback.CallbackClient;
|
||||||
import mage.interfaces.callback.ClientCallback;
|
import mage.interfaces.callback.ClientCallback;
|
||||||
|
import mage.interfaces.callback.ClientCallbackType;
|
||||||
import mage.remote.ActionData;
|
import mage.remote.ActionData;
|
||||||
import mage.remote.Session;
|
import mage.remote.Session;
|
||||||
import mage.view.*;
|
import mage.view.*;
|
||||||
|
|
@ -24,8 +25,7 @@ import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.event.KeyEvent;
|
import java.awt.event.KeyEvent;
|
||||||
import java.util.List;
|
import java.util.*;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author BetaSteward_at_googlemail.com
|
* @author BetaSteward_at_googlemail.com
|
||||||
|
|
@ -34,38 +34,76 @@ public class CallbackClientImpl implements CallbackClient {
|
||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(CallbackClientImpl.class);
|
private static final Logger logger = Logger.getLogger(CallbackClientImpl.class);
|
||||||
private final MageFrame frame;
|
private final MageFrame frame;
|
||||||
private int messageId = 0;
|
private final Map<ClientCallbackType, Integer> lastMessages;
|
||||||
private int gameInformMessageId = 0;
|
|
||||||
|
|
||||||
public CallbackClientImpl(MageFrame frame) {
|
public CallbackClientImpl(MageFrame frame) {
|
||||||
this.frame = frame;
|
this.frame = frame;
|
||||||
|
this.lastMessages = new HashMap<>();
|
||||||
|
Arrays.stream(ClientCallbackType.values()).forEach(t -> this.lastMessages.put(t, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void processCallback(final ClientCallback callback) {
|
public synchronized void processCallback(final ClientCallback callback) {
|
||||||
callback.decompressData();
|
callback.decompressData();
|
||||||
|
|
||||||
|
// put replay related code here
|
||||||
SaveObjectUtil.saveObject(callback.getData(), callback.getMethod().toString());
|
SaveObjectUtil.saveObject(callback.getData(), callback.getMethod().toString());
|
||||||
|
|
||||||
|
// all GUI related code must be executed in swing thread
|
||||||
SwingUtilities.invokeLater(() -> {
|
SwingUtilities.invokeLater(() -> {
|
||||||
try {
|
try {
|
||||||
logger.debug(callback.getMessageId() + " -- " + callback.getMethod());
|
logger.debug("message " + callback.getMessageId() + " - " + callback.getMethod().getType() + " - " + callback.getMethod());
|
||||||
|
|
||||||
|
// process bad connection (events can income in wrong order, so outdated data must be ignored)
|
||||||
|
// - table/dialog events like game start, game end, choose dialog - must be processed anyway
|
||||||
|
// - messages events like chat, inform, error - must be processed anyway
|
||||||
|
// - update events like opponent priority - can be ignored
|
||||||
|
if (!callback.getMethod().getType().equals(ClientCallbackType.CLIENT_SIDE_EVENT)) {
|
||||||
|
int lastAnyMessageId = this.lastMessages.values().stream().mapToInt(x -> x).max().orElse(0);
|
||||||
|
if (lastAnyMessageId > callback.getMessageId()) {
|
||||||
|
// un-synced message
|
||||||
|
if (callback.getMethod().getType().mustIgnoreOnOutdated()) {
|
||||||
|
// ignore
|
||||||
|
logger.warn(String.format("ignore un-synced message %d - %s - %s, possible reason: slow connection/performance",
|
||||||
|
callback.getMessageId(),
|
||||||
|
callback.getMethod().getType(),
|
||||||
|
callback.getMethod()
|
||||||
|
));
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
// process it anyway
|
||||||
|
logger.debug(String.format("processing un-synced message %d - %s - %s, possible reason: slow connection/performance",
|
||||||
|
callback.getMessageId(),
|
||||||
|
callback.getMethod().getType(),
|
||||||
|
callback.getMethod()
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// keep track of synced messages only
|
||||||
|
if (!callback.getMethod().getType().canProcessInAnyOrder()) {
|
||||||
|
this.lastMessages.put(callback.getMethod().getType(), callback.getMessageId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch (callback.getMethod()) {
|
switch (callback.getMethod()) {
|
||||||
|
|
||||||
case START_GAME: {
|
case START_GAME: {
|
||||||
TableClientMessage message = (TableClientMessage) callback.getData();
|
TableClientMessage message = (TableClientMessage) callback.getData();
|
||||||
GameManager.instance.setCurrentPlayerUUID(message.getPlayerId());
|
GameManager.instance.setCurrentPlayerUUID(message.getPlayerId());
|
||||||
gameStarted(message.getGameId(), message.getPlayerId());
|
gameStarted(callback.getMessageId(), message.getGameId(), message.getPlayerId());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case START_TOURNAMENT: {
|
case START_TOURNAMENT: {
|
||||||
TableClientMessage message = (TableClientMessage) callback.getData();
|
TableClientMessage message = (TableClientMessage) callback.getData();
|
||||||
tournamentStarted(message.getGameId(), message.getPlayerId());
|
tournamentStarted(callback.getMessageId(), message.getGameId(), message.getPlayerId());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case START_DRAFT: {
|
case START_DRAFT: {
|
||||||
TableClientMessage message = (TableClientMessage) callback.getData();
|
TableClientMessage message = (TableClientMessage) callback.getData();
|
||||||
draftStarted(message.getGameId(), message.getPlayerId());
|
draftStarted(callback.getMessageId(), message.getGameId(), message.getPlayerId());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -149,7 +187,7 @@ public class CallbackClientImpl implements CallbackClient {
|
||||||
case REPLAY_INIT: {
|
case REPLAY_INIT: {
|
||||||
GamePanel panel = MageFrame.getGame(callback.getObjectId());
|
GamePanel panel = MageFrame.getGame(callback.getObjectId());
|
||||||
if (panel != null) {
|
if (panel != null) {
|
||||||
panel.init((GameView) callback.getData());
|
panel.init(callback.getMessageId(), (GameView) callback.getData());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -157,7 +195,7 @@ public class CallbackClientImpl implements CallbackClient {
|
||||||
case REPLAY_DONE: {
|
case REPLAY_DONE: {
|
||||||
GamePanel panel = MageFrame.getGame(callback.getObjectId());
|
GamePanel panel = MageFrame.getGame(callback.getObjectId());
|
||||||
if (panel != null) {
|
if (panel != null) {
|
||||||
panel.endMessage(null, null, (String) callback.getData(), callback.getMessageId());
|
panel.endMessage(callback.getMessageId(), null, null, (String) callback.getData());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -165,7 +203,7 @@ public class CallbackClientImpl implements CallbackClient {
|
||||||
case REPLAY_UPDATE: {
|
case REPLAY_UPDATE: {
|
||||||
GamePanel panel = MageFrame.getGame(callback.getObjectId());
|
GamePanel panel = MageFrame.getGame(callback.getObjectId());
|
||||||
if (panel != null) {
|
if (panel != null) {
|
||||||
panel.updateGame((GameView) callback.getData());
|
panel.updateGame(callback.getMessageId(), (GameView) callback.getData());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -174,7 +212,7 @@ public class CallbackClientImpl implements CallbackClient {
|
||||||
GamePanel panel = MageFrame.getGame(callback.getObjectId());
|
GamePanel panel = MageFrame.getGame(callback.getObjectId());
|
||||||
if (panel != null) {
|
if (panel != null) {
|
||||||
appendJsonEvent("GAME_INIT", callback.getObjectId(), callback.getData());
|
appendJsonEvent("GAME_INIT", callback.getObjectId(), callback.getData());
|
||||||
panel.init((GameView) callback.getData());
|
panel.init(callback.getMessageId(), (GameView) callback.getData());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -190,7 +228,7 @@ public class CallbackClientImpl implements CallbackClient {
|
||||||
String logFileName = "game-" + gameId + ".json";
|
String logFileName = "game-" + gameId + ".json";
|
||||||
S3Uploader.upload(logFileName, gameId.toString());
|
S3Uploader.upload(logFileName, gameId.toString());
|
||||||
}
|
}
|
||||||
panel.endMessage(message.getGameView(), message.getOptions(), message.getMessage(), callback.getMessageId());
|
panel.endMessage(callback.getMessageId(), message.getGameView(), message.getOptions(), message.getMessage());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -205,7 +243,7 @@ public class CallbackClientImpl implements CallbackClient {
|
||||||
GamePanel panel = MageFrame.getGame(callback.getObjectId());
|
GamePanel panel = MageFrame.getGame(callback.getObjectId());
|
||||||
if (panel != null) {
|
if (panel != null) {
|
||||||
appendJsonEvent("GAME_ASK", callback.getObjectId(), message);
|
appendJsonEvent("GAME_ASK", callback.getObjectId(), message);
|
||||||
panel.ask(message.getMessage(), message.getGameView(), callback.getMessageId(), message.getOptions());
|
panel.ask(callback.getMessageId(), message.getGameView(), message.getMessage(), message.getOptions());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -216,8 +254,8 @@ public class CallbackClientImpl implements CallbackClient {
|
||||||
GamePanel panel = MageFrame.getGame(callback.getObjectId());
|
GamePanel panel = MageFrame.getGame(callback.getObjectId());
|
||||||
if (panel != null) {
|
if (panel != null) {
|
||||||
appendJsonEvent("GAME_TARGET", callback.getObjectId(), message);
|
appendJsonEvent("GAME_TARGET", callback.getObjectId(), message);
|
||||||
panel.pickTarget(message.getGameView(), message.getOptions(), message.getMessage(),
|
panel.pickTarget(callback.getMessageId(), message.getGameView(), message.getOptions(), message.getMessage(),
|
||||||
message.getCardsView1(), message.getTargets(), message.isFlag(), callback.getMessageId());
|
message.getCardsView1(), message.getTargets(), message.isFlag());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -227,7 +265,7 @@ public class CallbackClientImpl implements CallbackClient {
|
||||||
GamePanel panel = MageFrame.getGame(callback.getObjectId());
|
GamePanel panel = MageFrame.getGame(callback.getObjectId());
|
||||||
if (panel != null) {
|
if (panel != null) {
|
||||||
appendJsonEvent("GAME_SELECT", callback.getObjectId(), message);
|
appendJsonEvent("GAME_SELECT", callback.getObjectId(), message);
|
||||||
panel.select(message.getGameView(), message.getOptions(), message.getMessage(), callback.getMessageId());
|
panel.select(callback.getMessageId(), message.getGameView(), message.getOptions(), message.getMessage());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -237,7 +275,7 @@ public class CallbackClientImpl implements CallbackClient {
|
||||||
GamePanel panel = MageFrame.getGame(callback.getObjectId());
|
GamePanel panel = MageFrame.getGame(callback.getObjectId());
|
||||||
if (panel != null) {
|
if (panel != null) {
|
||||||
appendJsonEvent("GAME_CHOOSE_ABILITY", callback.getObjectId(), callback.getData());
|
appendJsonEvent("GAME_CHOOSE_ABILITY", callback.getObjectId(), callback.getData());
|
||||||
panel.pickAbility(abilityPickerView.getGameView(), null, abilityPickerView);
|
panel.pickAbility(callback.getMessageId(), abilityPickerView.getGameView(), null, abilityPickerView);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -247,7 +285,7 @@ public class CallbackClientImpl implements CallbackClient {
|
||||||
GamePanel panel = MageFrame.getGame(callback.getObjectId());
|
GamePanel panel = MageFrame.getGame(callback.getObjectId());
|
||||||
if (panel != null) {
|
if (panel != null) {
|
||||||
appendJsonEvent("GAME_CHOOSE_PILE", callback.getObjectId(), message);
|
appendJsonEvent("GAME_CHOOSE_PILE", callback.getObjectId(), message);
|
||||||
panel.pickPile(message.getGameView(), message.getOptions(), message.getMessage(), message.getCardsView1(), message.getCardsView2());
|
panel.pickPile(callback.getMessageId(), message.getGameView(), message.getOptions(), message.getMessage(), message.getCardsView1(), message.getCardsView2());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -257,7 +295,7 @@ public class CallbackClientImpl implements CallbackClient {
|
||||||
GamePanel panel = MageFrame.getGame(callback.getObjectId());
|
GamePanel panel = MageFrame.getGame(callback.getObjectId());
|
||||||
if (panel != null) {
|
if (panel != null) {
|
||||||
appendJsonEvent("GAME_CHOOSE_CHOICE", callback.getObjectId(), message);
|
appendJsonEvent("GAME_CHOOSE_CHOICE", callback.getObjectId(), message);
|
||||||
panel.getChoice(message.getGameView(), message.getOptions(), message.getChoice(), callback.getObjectId());
|
panel.getChoice(callback.getMessageId(), message.getGameView(), message.getOptions(), message.getChoice(), callback.getObjectId());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -267,7 +305,7 @@ public class CallbackClientImpl implements CallbackClient {
|
||||||
GamePanel panel = MageFrame.getGame(callback.getObjectId());
|
GamePanel panel = MageFrame.getGame(callback.getObjectId());
|
||||||
if (panel != null) {
|
if (panel != null) {
|
||||||
appendJsonEvent("GAME_PLAY_MANA", callback.getObjectId(), message);
|
appendJsonEvent("GAME_PLAY_MANA", callback.getObjectId(), message);
|
||||||
panel.playMana(message.getGameView(), message.getOptions(), message.getMessage(), callback.getMessageId());
|
panel.playMana(callback.getMessageId(), message.getGameView(), message.getOptions(), message.getMessage());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -277,7 +315,7 @@ public class CallbackClientImpl implements CallbackClient {
|
||||||
GamePanel panel = MageFrame.getGame(callback.getObjectId());
|
GamePanel panel = MageFrame.getGame(callback.getObjectId());
|
||||||
if (panel != null) {
|
if (panel != null) {
|
||||||
appendJsonEvent("GAME_PLAY_XMANA", callback.getObjectId(), message);
|
appendJsonEvent("GAME_PLAY_XMANA", callback.getObjectId(), message);
|
||||||
panel.playXMana(message.getGameView(), message.getOptions(), message.getMessage(), callback.getMessageId());
|
panel.playXMana(callback.getMessageId(), message.getGameView(), message.getOptions(), message.getMessage());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -287,8 +325,7 @@ public class CallbackClientImpl implements CallbackClient {
|
||||||
GamePanel panel = MageFrame.getGame(callback.getObjectId());
|
GamePanel panel = MageFrame.getGame(callback.getObjectId());
|
||||||
if (panel != null) {
|
if (panel != null) {
|
||||||
appendJsonEvent("GAME_GET_AMOUNT", callback.getObjectId(), message);
|
appendJsonEvent("GAME_GET_AMOUNT", callback.getObjectId(), message);
|
||||||
|
panel.getAmount(callback.getMessageId(), message.getGameView(), message.getOptions(), message.getMin(), message.getMax(), message.getMessage());
|
||||||
panel.getAmount(message.getGameView(), message.getOptions(), message.getMin(), message.getMax(), message.getMessage());
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -298,8 +335,7 @@ public class CallbackClientImpl implements CallbackClient {
|
||||||
GamePanel panel = MageFrame.getGame(callback.getObjectId());
|
GamePanel panel = MageFrame.getGame(callback.getObjectId());
|
||||||
if (panel != null) {
|
if (panel != null) {
|
||||||
appendJsonEvent("GAME_GET_MULTI_AMOUNT", callback.getObjectId(), message);
|
appendJsonEvent("GAME_GET_MULTI_AMOUNT", callback.getObjectId(), message);
|
||||||
|
panel.getMultiAmount(callback.getMessageId(), message.getGameView(), message.getMessages(), message.getOptions(), message.getMin(), message.getMax());
|
||||||
panel.getMultiAmount(message.getMessages(), message.getGameView(), message.getOptions(), message.getMin(), message.getMax());
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -308,7 +344,7 @@ public class CallbackClientImpl implements CallbackClient {
|
||||||
GamePanel panel = MageFrame.getGame(callback.getObjectId());
|
GamePanel panel = MageFrame.getGame(callback.getObjectId());
|
||||||
if (panel != null) {
|
if (panel != null) {
|
||||||
appendJsonEvent("GAME_UPDATE", callback.getObjectId(), callback.getData());
|
appendJsonEvent("GAME_UPDATE", callback.getObjectId(), callback.getData());
|
||||||
panel.updateGame((GameView) callback.getData(), true, null, null); // update after undo wtf?!
|
panel.updateGame(callback.getMessageId(), (GameView) callback.getData(), true, null, null); // update after undo wtf?! // TODO: clean dialogs?!
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -337,20 +373,12 @@ public class CallbackClientImpl implements CallbackClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
case GAME_INFORM: {
|
case GAME_INFORM: {
|
||||||
if (callback.getMessageId() > gameInformMessageId) {
|
|
||||||
{
|
|
||||||
GameClientMessage message = (GameClientMessage) callback.getData();
|
GameClientMessage message = (GameClientMessage) callback.getData();
|
||||||
GamePanel panel = MageFrame.getGame(callback.getObjectId());
|
GamePanel panel = MageFrame.getGame(callback.getObjectId());
|
||||||
if (panel != null) {
|
if (panel != null) {
|
||||||
appendJsonEvent("GAME_INFORM", callback.getObjectId(), message);
|
appendJsonEvent("GAME_INFORM", callback.getObjectId(), message);
|
||||||
panel.inform(message.getMessage(), message.getGameView(), callback.getMessageId());
|
panel.inform(callback.getMessageId(), message.getGameView(), message.getMessage());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// no longer needed because phase skip handling on server side now
|
|
||||||
} else {
|
|
||||||
logger.warn(new StringBuilder("message out of sequence - ignoring").append("MessageId = ").append(callback.getMessageId()).append(" method = ").append(callback.getMethod()));
|
|
||||||
}
|
|
||||||
gameInformMessageId = messageId;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -432,14 +460,10 @@ public class CallbackClientImpl implements CallbackClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
default: {
|
default: {
|
||||||
|
// TODO: add exception here and process miss events like TOURNAMENT_UPDATE
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// sync message for server side events only
|
|
||||||
if (!callback.getMethod().isClientSideMessage()) {
|
|
||||||
messageId = callback.getMessageId();
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
handleException(ex);
|
handleException(ex);
|
||||||
}
|
}
|
||||||
|
|
@ -539,7 +563,7 @@ public class CallbackClientImpl implements CallbackClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void gameStarted(final UUID gameId, final UUID playerId) {
|
protected void gameStarted(final int messageId, final UUID gameId, final UUID playerId) {
|
||||||
try {
|
try {
|
||||||
frame.showGame(gameId, playerId);
|
frame.showGame(gameId, playerId);
|
||||||
logger.info("Game " + gameId + " started for player " + playerId);
|
logger.info("Game " + gameId + " started for player " + playerId);
|
||||||
|
|
@ -552,7 +576,7 @@ public class CallbackClientImpl implements CallbackClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void draftStarted(UUID draftId, UUID playerId) {
|
protected void draftStarted(int messageId, UUID draftId, UUID playerId) {
|
||||||
try {
|
try {
|
||||||
frame.showDraft(draftId);
|
frame.showDraft(draftId);
|
||||||
logger.info("Draft " + draftId + " started for player " + playerId);
|
logger.info("Draft " + draftId + " started for player " + playerId);
|
||||||
|
|
@ -561,7 +585,7 @@ public class CallbackClientImpl implements CallbackClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void tournamentStarted(UUID tournamentId, UUID playerId) {
|
protected void tournamentStarted(int messageId, UUID tournamentId, UUID playerId) {
|
||||||
try {
|
try {
|
||||||
frame.showTournament(tournamentId);
|
frame.showTournament(tournamentId);
|
||||||
AudioManager.playTournamentStarted();
|
AudioManager.playTournamentStarted();
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,8 @@ import java.text.SimpleDateFormat;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* TODO: part of replay system? Un-used, can be deleted
|
||||||
|
*
|
||||||
* Utility class to save an object on disk.
|
* Utility class to save an object on disk.
|
||||||
*
|
*
|
||||||
* @author ayrat
|
* @author ayrat
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package mage.interfaces.callback;
|
||||||
|
|
||||||
import mage.remote.traffic.ZippedObject;
|
import mage.remote.traffic.ZippedObject;
|
||||||
import mage.utils.CompressUtil;
|
import mage.utils.CompressUtil;
|
||||||
|
import mage.utils.ThreadUtils;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
@ -11,11 +12,23 @@ import java.util.UUID;
|
||||||
*/
|
*/
|
||||||
public class ClientCallback implements Serializable {
|
public class ClientCallback implements Serializable {
|
||||||
|
|
||||||
|
// for debug only: simulate bad connection on client side, use launcher's client param like -Dxmage.badconnection
|
||||||
|
private static final String SIMULATE_BAD_CONNECTION_PROP = "xmage.badconnection";
|
||||||
|
public static final boolean SIMULATE_BAD_CONNECTION;
|
||||||
|
|
||||||
|
static {
|
||||||
|
SIMULATE_BAD_CONNECTION = System.getProperty(SIMULATE_BAD_CONNECTION_PROP) != null;
|
||||||
|
}
|
||||||
|
|
||||||
private UUID objectId;
|
private UUID objectId;
|
||||||
private Object data;
|
private Object data;
|
||||||
private ClientCallbackMethod method;
|
private ClientCallbackMethod method;
|
||||||
private int messageId;
|
private int messageId;
|
||||||
|
|
||||||
|
public ClientCallback(ClientCallbackMethod method, UUID objectId) {
|
||||||
|
this(method, objectId, null);
|
||||||
|
}
|
||||||
|
|
||||||
public ClientCallback(ClientCallbackMethod method, UUID objectId, Object data) {
|
public ClientCallback(ClientCallbackMethod method, UUID objectId, Object data) {
|
||||||
this(method, objectId, data, true);
|
this(method, objectId, data, true);
|
||||||
}
|
}
|
||||||
|
|
@ -26,8 +39,10 @@ public class ClientCallback implements Serializable {
|
||||||
this.setData(data, useCompress);
|
this.setData(data, useCompress);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ClientCallback(ClientCallbackMethod method, UUID objectId) {
|
private void simulateBadConnection() {
|
||||||
this(method, objectId, null);
|
if (SIMULATE_BAD_CONNECTION) {
|
||||||
|
ThreadUtils.sleep(100);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clear() {
|
public void clear() {
|
||||||
|
|
@ -55,12 +70,14 @@ public class ClientCallback implements Serializable {
|
||||||
this.data = data;
|
this.data = data;
|
||||||
} else {
|
} else {
|
||||||
this.data = CompressUtil.compress(data);
|
this.data = CompressUtil.compress(data);
|
||||||
|
simulateBadConnection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void decompressData() {
|
public void decompressData() {
|
||||||
if (this.data instanceof ZippedObject) {
|
if (this.data instanceof ZippedObject) {
|
||||||
this.data = CompressUtil.decompress(this.data);
|
this.data = CompressUtil.decompress(this.data);
|
||||||
|
simulateBadConnection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,68 +1,86 @@
|
||||||
package mage.interfaces.callback;
|
package mage.interfaces.callback;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by IGOUDT on 4-4-2017.
|
* Server's commands to process on client side. Commands can come in un-synced state due bad/slow network
|
||||||
|
* <p>
|
||||||
|
* Can be:
|
||||||
|
* - critical events (messages, game events, choose dialogs, etc)
|
||||||
|
* - non-critical events (game updates, messages)
|
||||||
*/
|
*/
|
||||||
public enum ClientCallbackMethod {
|
public enum ClientCallbackMethod {
|
||||||
|
|
||||||
CHATMESSAGE("chatMessage"),
|
// TODO: rename events due place/action like GAME_STARTED, GAME_ASK_DIALOG, GAME_TARGET_DIALOG
|
||||||
TOURNAMENT_INIT("tournamentInit"),
|
|
||||||
TOURNAMENT_UPDATE("tournamentUpdate"),
|
|
||||||
TOURNAMENT_OVER("tournamentOver"),
|
|
||||||
JOINED_TABLE("joinedTable"),
|
|
||||||
START_DRAFT("startDraft"),
|
|
||||||
START_TOURNAMENT("startTournament"),
|
|
||||||
SIDEBOARD("sideboard"),
|
|
||||||
VIEW_LIMITED_DECK("viewLimitedDeck"),
|
|
||||||
VIEW_SIDEBOARD("viewSideboard"),
|
|
||||||
CONSTRUCT("construct"),
|
|
||||||
SHOW_USERMESSAGE("showUserMessage"),
|
|
||||||
WATCHGAME("watchGame"),
|
|
||||||
REPLAY_GAME("replayGame"),
|
|
||||||
START_GAME("startGame"),
|
|
||||||
SHOW_TOURNAMENT("showTournament"),
|
|
||||||
SHOW_GAME_END_DIALOG("showGameEndDialog"),
|
|
||||||
SERVER_MESSAGE("serverMessage"),
|
|
||||||
GAME_INIT("gameInit"),
|
|
||||||
GAME_OVER("gameOver"),
|
|
||||||
GAME_INFORM("gameInform"),
|
|
||||||
GAME_INFORM_PERSONAL("gameInformPersonal"),
|
|
||||||
GAME_ERROR("gameError"),
|
|
||||||
GAME_UPDATE("gameUpdate"),
|
|
||||||
GAME_REDRAW_GUI("gameRedrawGUI", true),
|
|
||||||
DRAFT_OVER("draftOver"),
|
|
||||||
REPLAY_DONE("replayDone"),
|
|
||||||
USER_REQUEST_DIALOG("userRequestDialog"),
|
|
||||||
REPLAY_UPDATE("replayUpdate"),
|
|
||||||
REPLAY_INIT("replayInit"),
|
|
||||||
END_GAME_INFO("endGameInfo"),
|
|
||||||
GAME_TARGET("gameTarget"),
|
|
||||||
GAME_CHOOSE_ABILITY("gameChooseAbility"),
|
|
||||||
GAME_CHOOSE_PILE("gameChoosePile"),
|
|
||||||
GAME_CHOOSE_CHOICE("gameChooseChoice"),
|
|
||||||
GAME_ASK("gameAsk"),
|
|
||||||
GAME_SELECT("gameSelect"),
|
|
||||||
GAME_PLAY_MANA("gamePlayMana"),
|
|
||||||
GAME_PLAY_XMANA("gamePlayXMana"),
|
|
||||||
GAME_GET_AMOUNT("gameSelectAmount"),
|
|
||||||
GAME_GET_MULTI_AMOUNT("gameSelectMultiAmount"),
|
|
||||||
DRAFT_INIT("draftInit"),
|
|
||||||
DRAFT_PICK("draftPick"),
|
|
||||||
DRAFT_UPDATE("draftUpdate");
|
|
||||||
|
|
||||||
String code;
|
// messages
|
||||||
boolean isClientSideMessage;
|
CHATMESSAGE(ClientCallbackType.MESSAGE, "chatMessage"),
|
||||||
|
SHOW_USERMESSAGE(ClientCallbackType.MESSAGE, "showUserMessage"),
|
||||||
|
SERVER_MESSAGE(ClientCallbackType.MESSAGE, "serverMessage"),
|
||||||
|
|
||||||
ClientCallbackMethod(String code) {
|
// table
|
||||||
this(code, false);
|
JOINED_TABLE(ClientCallbackType.TABLE_CHANGE, "joinedTable"),
|
||||||
}
|
|
||||||
|
|
||||||
ClientCallbackMethod(String code, boolean isClientSideMessage) {
|
// tournament
|
||||||
|
START_TOURNAMENT(ClientCallbackType.TABLE_CHANGE, "startTournament"),
|
||||||
|
TOURNAMENT_INIT(ClientCallbackType.TABLE_CHANGE, "tournamentInit"), // TODO: unused on client
|
||||||
|
TOURNAMENT_UPDATE(ClientCallbackType.UPDATE, "tournamentUpdate"), // TODO: unused on client
|
||||||
|
TOURNAMENT_OVER(ClientCallbackType.TABLE_CHANGE, "tournamentOver"), // TODO: unused on client
|
||||||
|
|
||||||
|
// draft/sideboard
|
||||||
|
START_DRAFT(ClientCallbackType.TABLE_CHANGE, "startDraft"),
|
||||||
|
SIDEBOARD(ClientCallbackType.TABLE_CHANGE, "sideboard"),
|
||||||
|
CONSTRUCT(ClientCallbackType.TABLE_CHANGE, "construct"),
|
||||||
|
DRAFT_OVER(ClientCallbackType.TABLE_CHANGE, "draftOver"),
|
||||||
|
DRAFT_INIT(ClientCallbackType.TABLE_CHANGE, "draftInit"),
|
||||||
|
DRAFT_PICK(ClientCallbackType.TABLE_CHANGE, "draftPick"),
|
||||||
|
DRAFT_UPDATE(ClientCallbackType.UPDATE, "draftUpdate"),
|
||||||
|
|
||||||
|
// watch
|
||||||
|
SHOW_TOURNAMENT(ClientCallbackType.TABLE_CHANGE, "showTournament"),
|
||||||
|
WATCHGAME(ClientCallbackType.TABLE_CHANGE, "watchGame"),
|
||||||
|
|
||||||
|
// in-game actions
|
||||||
|
VIEW_LIMITED_DECK(ClientCallbackType.MESSAGE, "viewLimitedDeck"),
|
||||||
|
VIEW_SIDEBOARD(ClientCallbackType.MESSAGE, "viewSideboard"),
|
||||||
|
|
||||||
|
// other
|
||||||
|
USER_REQUEST_DIALOG(ClientCallbackType.DIALOG, "userRequestDialog"),
|
||||||
|
GAME_REDRAW_GUI(ClientCallbackType.CLIENT_SIDE_EVENT, "gameRedrawGUI"),
|
||||||
|
|
||||||
|
// game
|
||||||
|
START_GAME(ClientCallbackType.TABLE_CHANGE, "startGame"),
|
||||||
|
GAME_INIT(ClientCallbackType.TABLE_CHANGE, "gameInit"),
|
||||||
|
GAME_INFORM(ClientCallbackType.MESSAGE, "gameInform"),
|
||||||
|
GAME_INFORM_PERSONAL(ClientCallbackType.MESSAGE, "gameInformPersonal"),
|
||||||
|
GAME_ERROR(ClientCallbackType.MESSAGE, "gameError"),
|
||||||
|
GAME_UPDATE(ClientCallbackType.UPDATE, "gameUpdate"),
|
||||||
|
GAME_TARGET(ClientCallbackType.DIALOG, "gameTarget"),
|
||||||
|
GAME_CHOOSE_ABILITY(ClientCallbackType.DIALOG, "gameChooseAbility"),
|
||||||
|
GAME_CHOOSE_PILE(ClientCallbackType.DIALOG, "gameChoosePile"),
|
||||||
|
GAME_CHOOSE_CHOICE(ClientCallbackType.DIALOG, "gameChooseChoice"),
|
||||||
|
GAME_ASK(ClientCallbackType.DIALOG, "gameAsk"),
|
||||||
|
GAME_SELECT(ClientCallbackType.DIALOG, "gameSelect"),
|
||||||
|
GAME_PLAY_MANA(ClientCallbackType.DIALOG, "gamePlayMana"),
|
||||||
|
GAME_PLAY_XMANA(ClientCallbackType.DIALOG, "gamePlayXMana"),
|
||||||
|
GAME_GET_AMOUNT(ClientCallbackType.DIALOG, "gameSelectAmount"),
|
||||||
|
GAME_GET_MULTI_AMOUNT(ClientCallbackType.DIALOG, "gameSelectMultiAmount"),
|
||||||
|
GAME_OVER(ClientCallbackType.TABLE_CHANGE, "gameOver"),
|
||||||
|
END_GAME_INFO(ClientCallbackType.TABLE_CHANGE, "endGameInfo"),
|
||||||
|
|
||||||
|
// replay (unsupported)
|
||||||
|
REPLAY_GAME(ClientCallbackType.TABLE_CHANGE, "replayGame"),
|
||||||
|
REPLAY_INIT(ClientCallbackType.TABLE_CHANGE, "replayInit"),
|
||||||
|
REPLAY_UPDATE(ClientCallbackType.UPDATE, "replayUpdate"),
|
||||||
|
REPLAY_DONE(ClientCallbackType.TABLE_CHANGE, "replayDone");
|
||||||
|
|
||||||
|
final ClientCallbackType type;
|
||||||
|
final String code;
|
||||||
|
|
||||||
|
ClientCallbackMethod(ClientCallbackType type, String code) {
|
||||||
|
this.type = type;
|
||||||
this.code = code;
|
this.code = code;
|
||||||
this.isClientSideMessage = isClientSideMessage;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isClientSideMessage() {
|
public ClientCallbackType getType() {
|
||||||
return this.isClientSideMessage;
|
return this.type;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,35 @@
|
||||||
|
package mage.interfaces.callback;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Server event type for processing on the client
|
||||||
|
*
|
||||||
|
* @author JayDi85
|
||||||
|
*/
|
||||||
|
public enum ClientCallbackType {
|
||||||
|
|
||||||
|
TABLE_CHANGE,
|
||||||
|
UPDATE(true, true),
|
||||||
|
MESSAGE(true, false),
|
||||||
|
DIALOG,
|
||||||
|
CLIENT_SIDE_EVENT(true, true);
|
||||||
|
|
||||||
|
final boolean canProcessInAnyOrder;
|
||||||
|
final boolean mustIgnoreOnOutdated;
|
||||||
|
|
||||||
|
ClientCallbackType() {
|
||||||
|
this(false, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
ClientCallbackType(boolean canProcessInAnyOrder, boolean mustIgnoreOnOutdated) {
|
||||||
|
this.canProcessInAnyOrder = canProcessInAnyOrder;
|
||||||
|
this.mustIgnoreOnOutdated = mustIgnoreOnOutdated;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean canProcessInAnyOrder() {
|
||||||
|
return this.canProcessInAnyOrder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean mustIgnoreOnOutdated() {
|
||||||
|
return this.mustIgnoreOnOutdated;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -271,10 +271,6 @@ public class User {
|
||||||
fireCallback(new ClientCallback(ClientCallbackMethod.SHOW_TOURNAMENT, tournamentId));
|
fireCallback(new ClientCallback(ClientCallbackMethod.SHOW_TOURNAMENT, tournamentId));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ccShowGameEndDialog(final UUID gameId) {
|
|
||||||
fireCallback(new ClientCallback(ClientCallbackMethod.SHOW_GAME_END_DIALOG, gameId));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void showUserMessage(final String titel, String message) {
|
public void showUserMessage(final String titel, String message) {
|
||||||
List<String> messageData = new LinkedList<>();
|
List<String> messageData = new LinkedList<>();
|
||||||
messageData.add(titel);
|
messageData.add(titel);
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import mage.game.draft.Draft;
|
||||||
import mage.game.match.MatchOptions;
|
import mage.game.match.MatchOptions;
|
||||||
import mage.game.tournament.MultiplayerRound;
|
import mage.game.tournament.MultiplayerRound;
|
||||||
import mage.game.tournament.TournamentPairing;
|
import mage.game.tournament.TournamentPairing;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.EventObject;
|
import java.util.EventObject;
|
||||||
|
|
@ -17,11 +18,15 @@ import java.util.UUID;
|
||||||
*/
|
*/
|
||||||
public class TableEvent extends EventObject implements ExternalEvent, Serializable {
|
public class TableEvent extends EventObject implements ExternalEvent, Serializable {
|
||||||
|
|
||||||
|
private static final Logger logger = Logger.getLogger(TableEvent.class);
|
||||||
|
|
||||||
public enum EventType {
|
public enum EventType {
|
||||||
UPDATE, INFO, STATUS, START_DRAFT, START_MATCH, SIDEBOARD, CONSTRUCT, SUBMIT_DECK, END, END_GAME_INFO, ERROR,
|
UPDATE, INFO, STATUS, START_DRAFT, START_MATCH, SIDEBOARD, CONSTRUCT, SUBMIT_DECK, END, END_GAME_INFO, ERROR,
|
||||||
INIT_TIMER, RESUME_TIMER, PAUSE_TIMER, CHECK_STATE_PLAYERS, START_MULTIPLAYER_MATCH
|
INIT_TIMER, RESUME_TIMER, PAUSE_TIMER, CHECK_STATE_PLAYERS, START_MULTIPLAYER_MATCH
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private Game game;
|
private Game game;
|
||||||
private Draft draft;
|
private Draft draft;
|
||||||
private EventType eventType;
|
private EventType eventType;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue