network: reworked client-server events (related to triggers dialog problem from #11173) (#11189)

* 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:
Oleg Agafonov 2023-09-21 18:40:52 +04:00 committed by GitHub
parent fa8e93a29d
commit 342979a55a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 299 additions and 202 deletions

View file

@ -250,6 +250,11 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
LOGGER.fatal(null, ex);
}
// other settings
if (ClientCallback.SIMULATE_BAD_CONNECTION) {
LOGGER.info("Network: bad connection mode enabled");
}
// DATA PREPARE
RepositoryUtil.bootstrapLocalDb();
// re-create database on empty (e.g. after new build cleaned db on startup)

View file

@ -38,7 +38,6 @@ public class FeedbackPanel extends javax.swing.JPanel {
private FeedbackMode mode;
private MageDialog connectedDialog;
private ChatPanelBasic connectedChatPanel;
private int lastMessageId;
private Map<String, Serializable> lastOptions = new HashMap<>();
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,
int messageId, boolean gameNeedUserFeedback, TurnPhase gameTurnPhase) {
boolean gameNeedUserFeedback, TurnPhase gameTurnPhase) {
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.mode = mode;
}

View file

@ -122,8 +122,8 @@ public final class GamePanel extends javax.swing.JPanel {
private JPopupMenu popupMenuTriggerOrder;
// 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 {
int messageId;
GameView game;
boolean showPlayable;
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);
// default menu states
setMenuStates(
@ -581,7 +581,7 @@ public final class GamePanel extends javax.swing.JPanel {
holdingPriority
);
updateGame(game);
updateGame(messageId, game);
}
private void addPlayers(GameView game) {
@ -706,12 +706,12 @@ public final class GamePanel extends javax.swing.JPanel {
*/
}
public synchronized void updateGame(GameView game) {
updateGame(game, false, null, null);
public synchronized void updateGame(int messageId, GameView game) {
updateGame(messageId, game, false, null, null);
}
public synchronized void updateGame(GameView game, boolean showPlayable, Map<String, Serializable> options, Set<UUID> targets) {
keepLastGameData(game, showPlayable, options, targets);
public synchronized void updateGame(int messageId, GameView game, boolean showPlayable, Map<String, Serializable> options, Set<UUID> targets) {
keepLastGameData(messageId, game, showPlayable, options, targets);
prepareSelectableView();
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.updateOptions(lastGameData.options);
@ -1361,12 +1362,13 @@ public final class GamePanel extends javax.swing.JPanel {
windowMap.entrySet().removeIf(entry -> entry.getValue().isClosed());
}
public void ask(String question, GameView gameView, int messageId, Map<String, Serializable> options) {
updateGame(gameView, false, options, null);
this.feedbackPanel.prepareFeedback(FeedbackMode.QUESTION, question, false, options, messageId, true, gameView.getPhase());
public void ask(int messageId, GameView gameView, String question, Map<String, Serializable> options) {
updateGame(messageId, gameView, false, options, null);
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.showPlayable = showPlayable;
lastGameData.options = options;
@ -1623,8 +1625,8 @@ public final class GamePanel extends javax.swing.JPanel {
* @param options
* @param messageId
*/
public void pickTarget(GameView gameView, Map<String, Serializable> options, String message, CardsView cardsView, Set<UUID> targets, boolean required, int messageId) {
updateGame(gameView, false, options, targets);
public void pickTarget(int messageId, GameView gameView, Map<String, Serializable> options, String message, CardsView cardsView, Set<UUID> targets, boolean required) {
updateGame(messageId, gameView, false, options, targets);
hideAll();
DialogManager.getManager(gameId).fadeOut();
clearPickTargetDialogs();
@ -1652,28 +1654,28 @@ public final class GamePanel extends javax.swing.JPanel {
dialog = prepareCardsDialog(message, cardsView, required, options0, popupMenuType);
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) {
this.pickTarget.add(dialog);
}
}
public void inform(String information, GameView gameView, int messageId) {
updateGame(gameView);
this.feedbackPanel.prepareFeedback(FeedbackMode.INFORM, information, gameView.getSpecial(), null, messageId, false, gameView.getPhase());
public void inform(int messageId, GameView gameView, String information) {
updateGame(messageId, gameView);
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) {
updateGame(gameView, false, options, null);
public void endMessage(int messageId, GameView gameView, Map<String, Serializable> options, String message) {
updateGame(messageId, gameView, false, options, null);
hideAll();
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);
}
public void select(GameView gameView, Map<String, Serializable> options, String message, int messageId) {
updateGame(gameView, true, options, null);
public void select(int messageId, GameView gameView, Map<String, Serializable> options, String message) {
updateGame(messageId, gameView, true, options, null);
hideAll();
DialogManager.getManager(gameId).fadeOut();
@ -1716,31 +1718,31 @@ public final class GamePanel extends javax.swing.JPanel {
priorityPlayerText = " / priority " + gameView.getPriorityPlayerName();
}
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) {
updateGame(gameView, true, options, null);
public void playMana(int messageId, GameView gameView, Map<String, Serializable> options, String message) {
updateGame(messageId, gameView, true, options, null);
hideAll();
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) {
updateGame(gameView, true, options, null);
public void playXMana(int messageId, GameView gameView, Map<String, Serializable> options, String message) {
updateGame(messageId, gameView, true, options, null);
hideAll();
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) {
//TODO: implement this
}
public void pickAbility(GameView gameView, Map<String, Serializable> options, AbilityPickerView choices) {
updateGame(gameView, false, options, null);
public void pickAbility(int messageId, GameView gameView, Map<String, Serializable> options, AbilityPickerView choices) {
updateGame(messageId, gameView, false, options, null);
hideAll();
DialogManager.getManager(gameId).fadeOut();
@ -1764,8 +1766,8 @@ public final class GamePanel extends javax.swing.JPanel {
return showCards;
}
public void getAmount(GameView gameView, Map<String, Serializable> options, int min, int max, String message) {
updateGame(gameView, false, options, null);
public void getAmount(int messageId, GameView gameView, Map<String, Serializable> options, int min, int max, String message) {
updateGame(messageId, gameView, false, options, null);
hideAll();
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) {
updateGame(gameView, false, options, null);
updateGame(messageId, gameView, false, options, null);
hideAll();
DialogManager.getManager(gameId).fadeOut();
@ -1787,8 +1789,8 @@ public final class GamePanel extends javax.swing.JPanel {
SessionHandler.sendPlayerString(gameId, pickMultiNumber.getMultiAmount());
}
public void getChoice(GameView gameView, Map<String, Serializable> options, Choice choice, UUID objectId) {
updateGame(gameView, false, options, null);
public void getChoice(int messageId, GameView gameView, Map<String, Serializable> options, Choice choice, UUID objectId) {
updateGame(messageId, gameView, false, options, null);
hideAll();
DialogManager.getManager(gameId).fadeOut();
@ -1813,8 +1815,8 @@ public final class GamePanel extends javax.swing.JPanel {
pickChoice.removeDialog();
}
public void pickPile(GameView gameView, Map<String, Serializable> options, String message, CardsView pile1, CardsView pile2) {
updateGame(gameView, false, options, null);
public void pickPile(int messageId, GameView gameView, Map<String, Serializable> options, String message, CardsView pile1, CardsView pile2) {
updateGame(messageId, gameView, false, options, null);
hideAll();
DialogManager.getManager(gameId).fadeOut();

View file

@ -16,6 +16,7 @@ import mage.client.util.audio.AudioManager;
import mage.client.util.object.SaveObjectUtil;
import mage.interfaces.callback.CallbackClient;
import mage.interfaces.callback.ClientCallback;
import mage.interfaces.callback.ClientCallbackType;
import mage.remote.ActionData;
import mage.remote.Session;
import mage.view.*;
@ -24,8 +25,7 @@ import org.apache.log4j.Logger;
import javax.swing.*;
import java.awt.event.KeyEvent;
import java.util.List;
import java.util.UUID;
import java.util.*;
/**
* @author BetaSteward_at_googlemail.com
@ -34,38 +34,76 @@ public class CallbackClientImpl implements CallbackClient {
private static final Logger logger = Logger.getLogger(CallbackClientImpl.class);
private final MageFrame frame;
private int messageId = 0;
private int gameInformMessageId = 0;
private final Map<ClientCallbackType, Integer> lastMessages;
public CallbackClientImpl(MageFrame frame) {
this.frame = frame;
this.lastMessages = new HashMap<>();
Arrays.stream(ClientCallbackType.values()).forEach(t -> this.lastMessages.put(t, 0));
}
@Override
public synchronized void processCallback(final ClientCallback callback) {
callback.decompressData();
// put replay related code here
SaveObjectUtil.saveObject(callback.getData(), callback.getMethod().toString());
// all GUI related code must be executed in swing thread
SwingUtilities.invokeLater(() -> {
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()) {
case START_GAME: {
TableClientMessage message = (TableClientMessage) callback.getData();
GameManager.instance.setCurrentPlayerUUID(message.getPlayerId());
gameStarted(message.getGameId(), message.getPlayerId());
gameStarted(callback.getMessageId(), message.getGameId(), message.getPlayerId());
break;
}
case START_TOURNAMENT: {
TableClientMessage message = (TableClientMessage) callback.getData();
tournamentStarted(message.getGameId(), message.getPlayerId());
tournamentStarted(callback.getMessageId(), message.getGameId(), message.getPlayerId());
break;
}
case START_DRAFT: {
TableClientMessage message = (TableClientMessage) callback.getData();
draftStarted(message.getGameId(), message.getPlayerId());
draftStarted(callback.getMessageId(), message.getGameId(), message.getPlayerId());
break;
}
@ -149,7 +187,7 @@ public class CallbackClientImpl implements CallbackClient {
case REPLAY_INIT: {
GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) {
panel.init((GameView) callback.getData());
panel.init(callback.getMessageId(), (GameView) callback.getData());
}
break;
}
@ -157,7 +195,7 @@ public class CallbackClientImpl implements CallbackClient {
case REPLAY_DONE: {
GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) {
panel.endMessage(null, null, (String) callback.getData(), callback.getMessageId());
panel.endMessage(callback.getMessageId(), null, null, (String) callback.getData());
}
break;
}
@ -165,7 +203,7 @@ public class CallbackClientImpl implements CallbackClient {
case REPLAY_UPDATE: {
GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) {
panel.updateGame((GameView) callback.getData());
panel.updateGame(callback.getMessageId(), (GameView) callback.getData());
}
break;
}
@ -174,7 +212,7 @@ public class CallbackClientImpl implements CallbackClient {
GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) {
appendJsonEvent("GAME_INIT", callback.getObjectId(), callback.getData());
panel.init((GameView) callback.getData());
panel.init(callback.getMessageId(), (GameView) callback.getData());
}
break;
}
@ -190,7 +228,7 @@ public class CallbackClientImpl implements CallbackClient {
String logFileName = "game-" + gameId + ".json";
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;
}
@ -205,7 +243,7 @@ public class CallbackClientImpl implements CallbackClient {
GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) {
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;
}
@ -216,8 +254,8 @@ public class CallbackClientImpl implements CallbackClient {
GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) {
appendJsonEvent("GAME_TARGET", callback.getObjectId(), message);
panel.pickTarget(message.getGameView(), message.getOptions(), message.getMessage(),
message.getCardsView1(), message.getTargets(), message.isFlag(), callback.getMessageId());
panel.pickTarget(callback.getMessageId(), message.getGameView(), message.getOptions(), message.getMessage(),
message.getCardsView1(), message.getTargets(), message.isFlag());
}
break;
}
@ -227,7 +265,7 @@ public class CallbackClientImpl implements CallbackClient {
GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) {
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;
}
@ -237,7 +275,7 @@ public class CallbackClientImpl implements CallbackClient {
GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) {
appendJsonEvent("GAME_CHOOSE_ABILITY", callback.getObjectId(), callback.getData());
panel.pickAbility(abilityPickerView.getGameView(), null, abilityPickerView);
panel.pickAbility(callback.getMessageId(), abilityPickerView.getGameView(), null, abilityPickerView);
}
break;
}
@ -247,7 +285,7 @@ public class CallbackClientImpl implements CallbackClient {
GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) {
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;
}
@ -257,7 +295,7 @@ public class CallbackClientImpl implements CallbackClient {
GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) {
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;
}
@ -267,7 +305,7 @@ public class CallbackClientImpl implements CallbackClient {
GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) {
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;
}
@ -277,7 +315,7 @@ public class CallbackClientImpl implements CallbackClient {
GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) {
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;
}
@ -287,8 +325,7 @@ public class CallbackClientImpl implements CallbackClient {
GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) {
appendJsonEvent("GAME_GET_AMOUNT", callback.getObjectId(), message);
panel.getAmount(message.getGameView(), message.getOptions(), message.getMin(), message.getMax(), message.getMessage());
panel.getAmount(callback.getMessageId(), message.getGameView(), message.getOptions(), message.getMin(), message.getMax(), message.getMessage());
}
break;
}
@ -298,8 +335,7 @@ public class CallbackClientImpl implements CallbackClient {
GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) {
appendJsonEvent("GAME_GET_MULTI_AMOUNT", callback.getObjectId(), message);
panel.getMultiAmount(message.getMessages(), message.getGameView(), message.getOptions(), message.getMin(), message.getMax());
panel.getMultiAmount(callback.getMessageId(), message.getGameView(), message.getMessages(), message.getOptions(), message.getMin(), message.getMax());
}
break;
}
@ -308,7 +344,7 @@ public class CallbackClientImpl implements CallbackClient {
GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) {
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;
}
@ -337,20 +373,12 @@ public class CallbackClientImpl implements CallbackClient {
}
case GAME_INFORM: {
if (callback.getMessageId() > gameInformMessageId) {
{
GameClientMessage message = (GameClientMessage) callback.getData();
GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) {
appendJsonEvent("GAME_INFORM", callback.getObjectId(), message);
panel.inform(message.getMessage(), message.getGameView(), callback.getMessageId());
}
}
// 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()));
GameClientMessage message = (GameClientMessage) callback.getData();
GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) {
appendJsonEvent("GAME_INFORM", callback.getObjectId(), message);
panel.inform(callback.getMessageId(), message.getGameView(), message.getMessage());
}
gameInformMessageId = messageId;
break;
}
@ -432,14 +460,10 @@ public class CallbackClientImpl implements CallbackClient {
}
default: {
// TODO: add exception here and process miss events like TOURNAMENT_UPDATE
break;
}
}
// sync message for server side events only
if (!callback.getMethod().isClientSideMessage()) {
messageId = callback.getMessageId();
}
} catch (Exception ex) {
handleException(ex);
}
@ -466,50 +490,50 @@ public class CallbackClientImpl implements CallbackClient {
switch (usedPanel.getChatType()) {
case GAME:
usedPanel.receiveMessage("", new StringBuilder()
.append("HOTKEYS:")
.append("<br/>Turn mousewheel up (ALT-e) - enlarge image of card the mousepointer hovers over")
.append("<br/>Turn mousewheel down (ALT-s) - enlarge original/alternate image of card the mousepointer hovers over")
.append("<br/><b>")
.append(KeyEvent.getKeyText(PreferencesDialog.getCurrentControlKey(PreferencesDialog.KEY_CONTROL_CONFIRM)))
.append("</b> - Confirm \"Ok\", \"Yes\" or \"Done\" button")
.append("<br/><b>")
.append(KeyEvent.getKeyText(PreferencesDialog.getCurrentControlKey(PreferencesDialog.KEY_CONTROL_NEXT_TURN)))
.append("</b> - Skip current turn but stop on declare attackers/blockers and something on the stack")
.append("<br/><b>")
.append(KeyEvent.getKeyText(PreferencesDialog.getCurrentControlKey(PreferencesDialog.KEY_CONTROL_END_STEP)))
.append("</b> - Skip to next end step but stop on declare attackers/blockers and something on the stack")
.append("<br/><b>")
.append(KeyEvent.getKeyText(PreferencesDialog.getCurrentControlKey(PreferencesDialog.KEY_CONTROL_SKIP_STEP)))
.append("</b> - Skip current turn but stop on declare attackers/blockers")
.append("<br/><b>")
.append(KeyEvent.getKeyText(PreferencesDialog.getCurrentControlKey(PreferencesDialog.KEY_CONTROL_MAIN_STEP)))
.append("</b> - Skip to next main phase but stop on declare attackers/blockers and something on the stack")
.append("<br/><b>")
.append(KeyEvent.getKeyText(PreferencesDialog.getCurrentControlKey(PreferencesDialog.KEY_CONTROL_YOUR_TURN)))
.append("</b> - Skip everything until your next turn")
.append("<br/><b>")
.append(KeyEvent.getKeyText(PreferencesDialog.getCurrentControlKey(PreferencesDialog.KEY_CONTROL_PRIOR_END)))
.append("</b> - Skip everything until the end step just prior to your turn")
.append("<br/><b>")
.append(KeyEvent.getKeyText(PreferencesDialog.getCurrentControlKey(PreferencesDialog.KEY_CONTROL_CANCEL_SKIP)))
.append("</b> - Undo F4/F5/F7/F9/F11")
.append("<br/><b>")
.append(KeyEvent.getKeyText(PreferencesDialog.getCurrentControlKey(PreferencesDialog.KEY_CONTROL_SWITCH_CHAT)))
.append("</b> - Switch in/out to chat text field")
/*
.append("HOTKEYS:")
.append("<br/>Turn mousewheel up (ALT-e) - enlarge image of card the mousepointer hovers over")
.append("<br/>Turn mousewheel down (ALT-s) - enlarge original/alternate image of card the mousepointer hovers over")
.append("<br/><b>")
.append(KeyEvent.getKeyText(PreferencesDialog.getCurrentControlKey(PreferencesDialog.KEY_CONTROL_TOGGLE_MACRO)))
.append("</b> - Toggle recording a sequence of actions to repeat. Will not pause if interrupted and can fail if a selected card changes such as when scrying top card to bottom.")
.append("<br/><b>").append(System.getProperty("os.name").contains("Mac OS X") ? "Cmd" : "Ctrl").append(" + click</b> - Hold priority while casting a spell or activating an ability")
*/
.append("<br/>")
.append("<br/>")
.append("CHAT COMMANDS:")
.append("<br/>").append("<b>/h username </b> - show player's stats (history)")
.append("<br/>").append("<b>/w username message</b> - send private message to player (whisper)")
.append("<br/>").append("<b>/pings</b> - show players and watchers ping")
.append("<br/>").append("<b>/fix</b> - fix frozen game")
.toString(),
.append(KeyEvent.getKeyText(PreferencesDialog.getCurrentControlKey(PreferencesDialog.KEY_CONTROL_CONFIRM)))
.append("</b> - Confirm \"Ok\", \"Yes\" or \"Done\" button")
.append("<br/><b>")
.append(KeyEvent.getKeyText(PreferencesDialog.getCurrentControlKey(PreferencesDialog.KEY_CONTROL_NEXT_TURN)))
.append("</b> - Skip current turn but stop on declare attackers/blockers and something on the stack")
.append("<br/><b>")
.append(KeyEvent.getKeyText(PreferencesDialog.getCurrentControlKey(PreferencesDialog.KEY_CONTROL_END_STEP)))
.append("</b> - Skip to next end step but stop on declare attackers/blockers and something on the stack")
.append("<br/><b>")
.append(KeyEvent.getKeyText(PreferencesDialog.getCurrentControlKey(PreferencesDialog.KEY_CONTROL_SKIP_STEP)))
.append("</b> - Skip current turn but stop on declare attackers/blockers")
.append("<br/><b>")
.append(KeyEvent.getKeyText(PreferencesDialog.getCurrentControlKey(PreferencesDialog.KEY_CONTROL_MAIN_STEP)))
.append("</b> - Skip to next main phase but stop on declare attackers/blockers and something on the stack")
.append("<br/><b>")
.append(KeyEvent.getKeyText(PreferencesDialog.getCurrentControlKey(PreferencesDialog.KEY_CONTROL_YOUR_TURN)))
.append("</b> - Skip everything until your next turn")
.append("<br/><b>")
.append(KeyEvent.getKeyText(PreferencesDialog.getCurrentControlKey(PreferencesDialog.KEY_CONTROL_PRIOR_END)))
.append("</b> - Skip everything until the end step just prior to your turn")
.append("<br/><b>")
.append(KeyEvent.getKeyText(PreferencesDialog.getCurrentControlKey(PreferencesDialog.KEY_CONTROL_CANCEL_SKIP)))
.append("</b> - Undo F4/F5/F7/F9/F11")
.append("<br/><b>")
.append(KeyEvent.getKeyText(PreferencesDialog.getCurrentControlKey(PreferencesDialog.KEY_CONTROL_SWITCH_CHAT)))
.append("</b> - Switch in/out to chat text field")
/*
.append("<br/><b>")
.append(KeyEvent.getKeyText(PreferencesDialog.getCurrentControlKey(PreferencesDialog.KEY_CONTROL_TOGGLE_MACRO)))
.append("</b> - Toggle recording a sequence of actions to repeat. Will not pause if interrupted and can fail if a selected card changes such as when scrying top card to bottom.")
.append("<br/><b>").append(System.getProperty("os.name").contains("Mac OS X") ? "Cmd" : "Ctrl").append(" + click</b> - Hold priority while casting a spell or activating an ability")
*/
.append("<br/>")
.append("<br/>")
.append("CHAT COMMANDS:")
.append("<br/>").append("<b>/h username </b> - show player's stats (history)")
.append("<br/>").append("<b>/w username message</b> - send private message to player (whisper)")
.append("<br/>").append("<b>/pings</b> - show players and watchers ping")
.append("<br/>").append("<b>/fix</b> - fix frozen game")
.toString(),
null, null, MessageType.USER_INFO, ChatMessage.MessageColor.BLUE);
break;
case TOURNAMENT:
@ -519,10 +543,10 @@ public class CallbackClientImpl implements CallbackClient {
case TABLES:
String serverAddress = SessionHandler.getSession().getServerHostname().orElse("");
usedPanel.receiveMessage("", new StringBuilder("Download card images by using the \"Images\" main menu.")
.append("<br/>Download icons and symbols by using the \"Symbols\" main menu.")
.append("<br/>\\list - show a list of available chat commands.")
.append("<br/>").append(IgnoreList.usage(serverAddress))
.append("<br/>Type <font color=green>\\w yourUserName profanity 0 (or 1 or 2)</font> to turn off/on the profanity filter").toString(),
.append("<br/>Download icons and symbols by using the \"Symbols\" main menu.")
.append("<br/>\\list - show a list of available chat commands.")
.append("<br/>").append(IgnoreList.usage(serverAddress))
.append("<br/>Type <font color=green>\\w yourUserName profanity 0 (or 1 or 2)</font> to turn off/on the profanity filter").toString(),
null, null, MessageType.USER_INFO, ChatMessage.MessageColor.BLUE);
break;
default:
@ -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 {
frame.showGame(gameId, 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 {
frame.showDraft(draftId);
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 {
frame.showTournament(tournamentId);
AudioManager.playTournamentStarted();

View file

@ -9,6 +9,8 @@ import java.text.SimpleDateFormat;
import java.util.Calendar;
/**
* TODO: part of replay system? Un-used, can be deleted
*
* Utility class to save an object on disk.
*
* @author ayrat