mirror of
https://github.com/correl/mage.git
synced 2024-11-14 19:19:32 +00:00
clientcallbacks to enums
This commit is contained in:
parent
0e7604a0cc
commit
ff6d1541c3
14 changed files with 210 additions and 165 deletions
|
@ -4,6 +4,7 @@ import mage.client.MageFrame;
|
|||
import mage.client.SessionHandler;
|
||||
import mage.client.util.IgnoreList;
|
||||
import mage.interfaces.callback.ClientCallback;
|
||||
import mage.interfaces.callback.ClientCallbackMethod;
|
||||
import mage.view.ChatMessage;
|
||||
|
||||
import java.text.DateFormat;
|
||||
|
@ -58,7 +59,7 @@ public final class LocalCommands {
|
|||
|
||||
private static void displayLocalCommandResponse(UUID chatId, String response) {
|
||||
final String text = new StringBuilder().append("<font color=yellow>").append(response).append("</font>").toString();
|
||||
ClientCallback chatMessage = new ClientCallback("chatMessage", chatId,
|
||||
ClientCallback chatMessage = new ClientCallback(ClientCallbackMethod.CHATMESSAGE, chatId,
|
||||
new ChatMessage("", text, timeFormatter.format(new Date()), ChatMessage.MessageColor.BLUE));
|
||||
MageFrame.getInstance().processCallback(chatMessage);
|
||||
}
|
||||
|
|
|
@ -27,11 +27,6 @@
|
|||
*/
|
||||
package mage.client.remote;
|
||||
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.SwingUtilities;
|
||||
import mage.cards.decks.Deck;
|
||||
import mage.client.MageFrame;
|
||||
import mage.client.SessionHandler;
|
||||
|
@ -49,19 +44,15 @@ import mage.client.util.object.SaveObjectUtil;
|
|||
import mage.interfaces.callback.CallbackClient;
|
||||
import mage.interfaces.callback.ClientCallback;
|
||||
import mage.utils.CompressUtil;
|
||||
import mage.view.AbilityPickerView;
|
||||
import mage.view.ChatMessage;
|
||||
import mage.view.*;
|
||||
import mage.view.ChatMessage.MessageType;
|
||||
import mage.view.DeckView;
|
||||
import mage.view.DraftClientMessage;
|
||||
import mage.view.DraftView;
|
||||
import mage.view.GameClientMessage;
|
||||
import mage.view.GameEndView;
|
||||
import mage.view.GameView;
|
||||
import mage.view.TableClientMessage;
|
||||
import mage.view.UserRequestMessage;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
|
@ -79,38 +70,38 @@ public class CallbackClientImpl implements CallbackClient {
|
|||
|
||||
@Override
|
||||
public synchronized void processCallback(final ClientCallback callback) {
|
||||
SaveObjectUtil.saveObject(callback.getData(), callback.getMethod());
|
||||
SaveObjectUtil.saveObject(callback.getData(), callback.getMethod().toString());
|
||||
callback.setData(CompressUtil.decompress(callback.getData()));
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
try {
|
||||
logger.debug(callback.getMessageId() + " -- " + callback.getMethod());
|
||||
switch (callback.getMethod()) {
|
||||
case "startGame": {
|
||||
case START_GAME: {
|
||||
TableClientMessage message = (TableClientMessage) callback.getData();
|
||||
GameManager.instance.setCurrentPlayerUUID(message.getPlayerId());
|
||||
gameStarted(message.getGameId(), message.getPlayerId());
|
||||
break;
|
||||
}
|
||||
case "startTournament": {
|
||||
case START_TOURNAMENT: {
|
||||
TableClientMessage message = (TableClientMessage) callback.getData();
|
||||
tournamentStarted(message.getGameId(), message.getPlayerId());
|
||||
break;
|
||||
}
|
||||
case "startDraft": {
|
||||
case START_DRAFT: {
|
||||
TableClientMessage message = (TableClientMessage) callback.getData();
|
||||
draftStarted(message.getGameId(), message.getPlayerId());
|
||||
break;
|
||||
}
|
||||
case "replayGame":
|
||||
case REPLAY_GAME:
|
||||
replayGame(callback.getObjectId());
|
||||
break;
|
||||
case "showTournament":
|
||||
case SHOW_TOURNAMENT:
|
||||
showTournament(callback.getObjectId());
|
||||
break;
|
||||
case "watchGame":
|
||||
case WATCHGAME:
|
||||
watchGame(callback.getObjectId());
|
||||
break;
|
||||
case "chatMessage": {
|
||||
case CHATMESSAGE: {
|
||||
ChatMessage message = (ChatMessage) callback.getData();
|
||||
|
||||
// Drop messages from ignored users
|
||||
|
@ -154,7 +145,7 @@ public class CallbackClientImpl implements CallbackClient {
|
|||
}
|
||||
break;
|
||||
}
|
||||
case "serverMessage":
|
||||
case SERVER_MESSAGE:
|
||||
if (callback.getData() != null) {
|
||||
ChatMessage message = (ChatMessage) callback.getData();
|
||||
if (message.getColor() == ChatMessage.MessageColor.RED) {
|
||||
|
@ -164,50 +155,50 @@ public class CallbackClientImpl implements CallbackClient {
|
|||
}
|
||||
}
|
||||
break;
|
||||
case "joinedTable": {
|
||||
case JOINED_TABLE: {
|
||||
TableClientMessage message = (TableClientMessage) callback.getData();
|
||||
joinedTable(message.getRoomId(), message.getTableId(), message.getFlag());
|
||||
break;
|
||||
}
|
||||
case "replayInit": {
|
||||
case REPLAY_INIT: {
|
||||
GamePanel panel = MageFrame.getGame(callback.getObjectId());
|
||||
if (panel != null) {
|
||||
panel.init((GameView) callback.getData());
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "replayDone": {
|
||||
case REPLAY_DONE: {
|
||||
GamePanel panel = MageFrame.getGame(callback.getObjectId());
|
||||
if (panel != null) {
|
||||
panel.endMessage((String) callback.getData(), callback.getMessageId());
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "replayUpdate": {
|
||||
case REPLAY_UPDATE: {
|
||||
GamePanel panel = MageFrame.getGame(callback.getObjectId());
|
||||
if (panel != null) {
|
||||
panel.updateGame((GameView) callback.getData());
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "gameInit": {
|
||||
case GAME_INIT: {
|
||||
GamePanel panel = MageFrame.getGame(callback.getObjectId());
|
||||
if (panel != null) {
|
||||
panel.init((GameView) callback.getData());
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "gameOver": {
|
||||
case GAME_OVER: {
|
||||
GamePanel panel = MageFrame.getGame(callback.getObjectId());
|
||||
if (panel != null) {
|
||||
panel.endMessage((String) callback.getData(), callback.getMessageId());
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "gameError":
|
||||
case GAME_ERROR:
|
||||
frame.showErrorDialog("Game Error", (String) callback.getData());
|
||||
break;
|
||||
case "gameAsk": {
|
||||
case GAME_ASK: {
|
||||
GameClientMessage message = (GameClientMessage) callback.getData();
|
||||
GamePanel panel = MageFrame.getGame(callback.getObjectId());
|
||||
if (panel != null) {
|
||||
|
@ -215,7 +206,7 @@ public class CallbackClientImpl implements CallbackClient {
|
|||
}
|
||||
break;
|
||||
}
|
||||
case "gameTarget": // e.g. Pick triggered ability
|
||||
case GAME_TARGET: // e.g. Pick triggered ability
|
||||
{
|
||||
GameClientMessage message = (GameClientMessage) callback.getData();
|
||||
GamePanel panel = MageFrame.getGame(callback.getObjectId());
|
||||
|
@ -225,7 +216,7 @@ public class CallbackClientImpl implements CallbackClient {
|
|||
}
|
||||
break;
|
||||
}
|
||||
case "gameSelect": {
|
||||
case GAME_SELECT: {
|
||||
GameClientMessage message = (GameClientMessage) callback.getData();
|
||||
GamePanel panel = MageFrame.getGame(callback.getObjectId());
|
||||
if (panel != null) {
|
||||
|
@ -233,14 +224,14 @@ public class CallbackClientImpl implements CallbackClient {
|
|||
}
|
||||
break;
|
||||
}
|
||||
case "gameChooseAbility": {
|
||||
case GAME_CHOOSE_ABILITY: {
|
||||
GamePanel panel = MageFrame.getGame(callback.getObjectId());
|
||||
if (panel != null) {
|
||||
panel.pickAbility((AbilityPickerView) callback.getData());
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "gameChoosePile": {
|
||||
case GAME_CHOOSE_PILE: {
|
||||
GameClientMessage message = (GameClientMessage) callback.getData();
|
||||
GamePanel panel = MageFrame.getGame(callback.getObjectId());
|
||||
if (panel != null) {
|
||||
|
@ -248,7 +239,7 @@ public class CallbackClientImpl implements CallbackClient {
|
|||
}
|
||||
break;
|
||||
}
|
||||
case "gameChooseChoice": {
|
||||
case GAME_CHOOSE_CHOICE: {
|
||||
GameClientMessage message = (GameClientMessage) callback.getData();
|
||||
GamePanel panel = MageFrame.getGame(callback.getObjectId());
|
||||
|
||||
|
@ -257,7 +248,7 @@ public class CallbackClientImpl implements CallbackClient {
|
|||
}
|
||||
break;
|
||||
}
|
||||
case "gamePlayMana": {
|
||||
case GAME_PLAY_MANA: {
|
||||
GameClientMessage message = (GameClientMessage) callback.getData();
|
||||
GamePanel panel = MageFrame.getGame(callback.getObjectId());
|
||||
if (panel != null) {
|
||||
|
@ -265,7 +256,7 @@ public class CallbackClientImpl implements CallbackClient {
|
|||
}
|
||||
break;
|
||||
}
|
||||
case "gamePlayXMana": {
|
||||
case GAME_PLAY_XMANA: {
|
||||
GameClientMessage message = (GameClientMessage) callback.getData();
|
||||
GamePanel panel = MageFrame.getGame(callback.getObjectId());
|
||||
if (panel != null) {
|
||||
|
@ -273,7 +264,7 @@ public class CallbackClientImpl implements CallbackClient {
|
|||
}
|
||||
break;
|
||||
}
|
||||
case "gameSelectAmount": {
|
||||
case GAME_GET_AMOUNT: {
|
||||
GameClientMessage message = (GameClientMessage) callback.getData();
|
||||
GamePanel panel = MageFrame.getGame(callback.getObjectId());
|
||||
if (panel != null) {
|
||||
|
@ -281,23 +272,23 @@ public class CallbackClientImpl implements CallbackClient {
|
|||
}
|
||||
break;
|
||||
}
|
||||
case "gameUpdate": {
|
||||
case GAME_UPDATE: {
|
||||
GamePanel panel = MageFrame.getGame(callback.getObjectId());
|
||||
if (panel != null) {
|
||||
panel.updateGame((GameView) callback.getData());
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "endGameInfo":
|
||||
case END_GAME_INFO:
|
||||
MageFrame.getInstance().showGameEndDialog((GameEndView) callback.getData());
|
||||
break;
|
||||
case "showUserMessage":
|
||||
case SHOW_USERMESSAGE:
|
||||
List<String> messageData = (List<String>) callback.getData();
|
||||
if (messageData.size() == 2) {
|
||||
JOptionPane.showMessageDialog(null, messageData.get(1), messageData.get(0), JOptionPane.WARNING_MESSAGE);
|
||||
}
|
||||
break;
|
||||
case "gameInform":
|
||||
case GAME_INFORM:
|
||||
if (callback.getMessageId() > gameInformMessageId) {
|
||||
{
|
||||
GameClientMessage message = (GameClientMessage) callback.getData();
|
||||
|
@ -313,7 +304,7 @@ public class CallbackClientImpl implements CallbackClient {
|
|||
}
|
||||
gameInformMessageId = messageId;
|
||||
break;
|
||||
case "gameInformPersonal": {
|
||||
case GAME_INFORM_PERSONAL: {
|
||||
GameClientMessage message = (GameClientMessage) callback.getData();
|
||||
GamePanel panel = MageFrame.getGame(callback.getObjectId());
|
||||
if (panel != null) {
|
||||
|
@ -322,7 +313,7 @@ public class CallbackClientImpl implements CallbackClient {
|
|||
}
|
||||
break;
|
||||
}
|
||||
case "sideboard": {
|
||||
case SIDEBOARD: {
|
||||
TableClientMessage message = (TableClientMessage) callback.getData();
|
||||
DeckView deckView = message.getDeck();
|
||||
Deck deck = DeckUtil.construct(deckView);
|
||||
|
@ -333,17 +324,17 @@ public class CallbackClientImpl implements CallbackClient {
|
|||
}
|
||||
break;
|
||||
}
|
||||
case "construct": {
|
||||
case CONSTRUCT: {
|
||||
TableClientMessage message = (TableClientMessage) callback.getData();
|
||||
DeckView deckView = message.getDeck();
|
||||
Deck deck = DeckUtil.construct(deckView);
|
||||
construct(deck, message.getTableId(), message.getTime());
|
||||
break;
|
||||
}
|
||||
case "draftOver":
|
||||
case DRAFT_OVER:
|
||||
MageFrame.removeDraft(callback.getObjectId());
|
||||
break;
|
||||
case "draftPick": {
|
||||
case DRAFT_PICK: {
|
||||
DraftClientMessage message = (DraftClientMessage) callback.getData();
|
||||
DraftPanel panel = MageFrame.getDraft(callback.getObjectId());
|
||||
if (panel != null) {
|
||||
|
@ -351,14 +342,14 @@ public class CallbackClientImpl implements CallbackClient {
|
|||
}
|
||||
break;
|
||||
}
|
||||
case "draftUpdate": {
|
||||
case DRAFT_UPDATE: {
|
||||
DraftPanel panel = MageFrame.getDraft(callback.getObjectId());
|
||||
if (panel != null) {
|
||||
panel.updateDraft((DraftView) callback.getData());
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "draftInform": // if (callback.getMessageId() > messageId) {
|
||||
case DRAFT_INFORM: // if (callback.getMessageId() > messageId) {
|
||||
{
|
||||
DraftClientMessage message = (DraftClientMessage) callback.getData();
|
||||
}
|
||||
|
@ -366,7 +357,7 @@ public class CallbackClientImpl implements CallbackClient {
|
|||
// logger.warn("message out of sequence - ignoring");
|
||||
// }
|
||||
break;
|
||||
case "draftInit": {
|
||||
case DRAFT_INIT: {
|
||||
DraftClientMessage message = (DraftClientMessage) callback.getData();
|
||||
DraftPanel panel = MageFrame.getDraft(callback.getObjectId());
|
||||
if (panel != null) {
|
||||
|
@ -374,9 +365,9 @@ public class CallbackClientImpl implements CallbackClient {
|
|||
}
|
||||
break;
|
||||
}
|
||||
case "tournamentInit":
|
||||
case TOURNAMENT_INIT:
|
||||
break;
|
||||
case "userRequestDialog":
|
||||
case USER_REQUEST_DIALOG:
|
||||
frame.showUserRequestDialog((UserRequestMessage) callback.getData());
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -39,18 +39,18 @@ public class ClientCallback implements Serializable {
|
|||
|
||||
private UUID objectId;
|
||||
private Object data;
|
||||
private String method;
|
||||
private ClientCallbackMethod method;
|
||||
private int messageId;
|
||||
|
||||
public ClientCallback() {}
|
||||
|
||||
public ClientCallback(String method, UUID objectId, Object data) {
|
||||
public ClientCallback(ClientCallbackMethod method, UUID objectId, Object data) {
|
||||
this.method = method;
|
||||
this.objectId = objectId;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public ClientCallback(String method, UUID objectId) {
|
||||
public ClientCallback(ClientCallbackMethod method, UUID objectId) {
|
||||
this(method, objectId, null);
|
||||
}
|
||||
|
||||
|
@ -75,11 +75,11 @@ public class ClientCallback implements Serializable {
|
|||
this.data = data;
|
||||
}
|
||||
|
||||
public String getMethod() {
|
||||
public ClientCallbackMethod getMethod() {
|
||||
return method;
|
||||
}
|
||||
|
||||
public void setMethod(String method) {
|
||||
public void setMethod(ClientCallbackMethod method) {
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
package mage.interfaces.callback;
|
||||
|
||||
/**
|
||||
* Created by IGOUDT on 4-4-2017.
|
||||
*/
|
||||
public enum ClientCallbackMethod {
|
||||
|
||||
CHATMESSAGE("chatMessage"),
|
||||
TOURNAMENT_INIT("tournamentInit"),
|
||||
TOURNAMENT_UPDATE("tournamentUpdate"),
|
||||
TOURNAMENT_OVER("tournamentOver"),
|
||||
JOINED_TABLE("joinedTable"),
|
||||
START_DRAFT("startDraft"),
|
||||
START_TOURNAMENT("startTournament"),
|
||||
SIDEBOARD("sideboard"),
|
||||
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"),
|
||||
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"), DRAFT_INIT("draftInit"), DRAFT_INFORM("draftInform"), DRAFT_PICK("draftPick"), DRAFT_UPDATE("draftUpdate");
|
||||
|
||||
String value;
|
||||
|
||||
ClientCallbackMethod(String value){
|
||||
this.value = value;
|
||||
}
|
||||
}
|
|
@ -28,6 +28,7 @@
|
|||
package mage.server;
|
||||
|
||||
import mage.interfaces.callback.ClientCallback;
|
||||
import mage.interfaces.callback.ClientCallbackMethod;
|
||||
import mage.view.ChatMessage;
|
||||
import mage.view.ChatMessage.MessageColor;
|
||||
import mage.view.ChatMessage.MessageType;
|
||||
|
@ -118,7 +119,7 @@ public class ChatSession {
|
|||
|
||||
public boolean broadcastInfoToUser(User toUser, String message) {
|
||||
if (clients.containsKey(toUser.getId())) {
|
||||
toUser.fireCallback(new ClientCallback("chatMessage", chatId, new ChatMessage(null, message, timeFormatter.format(new Date()), MessageColor.BLUE, MessageType.USER_INFO, null)));
|
||||
toUser.fireCallback(new ClientCallback(ClientCallbackMethod.CHATMESSAGE, chatId, new ChatMessage(null, message, timeFormatter.format(new Date()), MessageColor.BLUE, MessageType.USER_INFO, null)));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -126,10 +127,10 @@ public class ChatSession {
|
|||
|
||||
public boolean broadcastWhisperToUser(User fromUser, User toUser, String message) {
|
||||
if (clients.containsKey(toUser.getId())) {
|
||||
toUser.fireCallback(new ClientCallback("chatMessage", chatId,
|
||||
toUser.fireCallback(new ClientCallback(ClientCallbackMethod.CHATMESSAGE, chatId,
|
||||
new ChatMessage(fromUser.getName(), message, timeFormatter.format(new Date()), MessageColor.YELLOW, MessageType.WHISPER_FROM, SoundToPlay.PlayerWhispered)));
|
||||
if (clients.containsKey(fromUser.getId())) {
|
||||
fromUser.fireCallback(new ClientCallback("chatMessage", chatId,
|
||||
fromUser.fireCallback(new ClientCallback(ClientCallbackMethod.CHATMESSAGE, chatId,
|
||||
new ChatMessage(toUser.getName(), message, timeFormatter.format(new Date()), MessageColor.YELLOW, MessageType.WHISPER_TO, null)));
|
||||
return true;
|
||||
}
|
||||
|
@ -140,7 +141,7 @@ public class ChatSession {
|
|||
public void broadcast(String userName, String message, MessageColor color, boolean withTime, MessageType messageType, SoundToPlay soundToPlay) {
|
||||
if (!message.isEmpty()) {
|
||||
HashSet<UUID> clientsToRemove = new HashSet<>();
|
||||
ClientCallback clientCallback = new ClientCallback("chatMessage", chatId, new ChatMessage(userName, message, (withTime ? timeFormatter.format(new Date()) : ""), color, messageType, soundToPlay));
|
||||
ClientCallback clientCallback = new ClientCallback(ClientCallbackMethod.CHATMESSAGE, chatId, new ChatMessage(userName, message, (withTime ? timeFormatter.format(new Date()) : ""), color, messageType, soundToPlay));
|
||||
for (UUID userId : clients.keySet()) {
|
||||
Optional<User> user = UserManager.instance.getUser(userId);
|
||||
if (user.isPresent()) {
|
||||
|
|
|
@ -45,6 +45,7 @@ import mage.interfaces.ActionWithResult;
|
|||
import mage.interfaces.MageServer;
|
||||
import mage.interfaces.ServerState;
|
||||
import mage.interfaces.callback.ClientCallback;
|
||||
import mage.interfaces.callback.ClientCallbackMethod;
|
||||
import mage.players.PlayerType;
|
||||
import mage.players.net.UserData;
|
||||
import mage.remote.MageVersionException;
|
||||
|
@ -1172,9 +1173,9 @@ public class MageServerImpl implements MageServer {
|
|||
execute("sendBroadcastMessage", sessionId, () -> {
|
||||
for (User user : UserManager.instance.getUsers()) {
|
||||
if (message.toLowerCase(Locale.ENGLISH).startsWith("warn")) {
|
||||
user.fireCallback(new ClientCallback("serverMessage", null, new ChatMessage("SERVER", message, null, MessageColor.RED)));
|
||||
user.fireCallback(new ClientCallback(ClientCallbackMethod.SERVER_MESSAGE, null, new ChatMessage("SERVER", message, null, MessageColor.RED)));
|
||||
} else {
|
||||
user.fireCallback(new ClientCallback("serverMessage", null, new ChatMessage("SERVER", message, null, MessageColor.BLUE)));
|
||||
user.fireCallback(new ClientCallback(ClientCallbackMethod.SERVER_MESSAGE, null, new ChatMessage("SERVER", message, null, MessageColor.BLUE)));
|
||||
}
|
||||
}
|
||||
}, true);
|
||||
|
|
|
@ -30,6 +30,7 @@ package mage.server;
|
|||
import mage.MageException;
|
||||
import mage.constants.Constants;
|
||||
import mage.interfaces.callback.ClientCallback;
|
||||
import mage.interfaces.callback.ClientCallbackMethod;
|
||||
import mage.players.net.UserData;
|
||||
import mage.players.net.UserGroup;
|
||||
import mage.server.game.GamesRoom;
|
||||
|
@ -423,14 +424,14 @@ public class Session {
|
|||
List<String> messageData = new LinkedList<>();
|
||||
messageData.add("Error while connecting to server");
|
||||
messageData.add(message);
|
||||
fireCallback(new ClientCallback("showUserMessage", null, messageData));
|
||||
fireCallback(new ClientCallback(ClientCallbackMethod.SHOW_USERMESSAGE, null, messageData));
|
||||
}
|
||||
|
||||
public void sendInfoMessageToClient(String message) {
|
||||
List<String> messageData = new LinkedList<>();
|
||||
messageData.add("Information about connecting to the server");
|
||||
messageData.add(message);
|
||||
fireCallback(new ClientCallback("showUserMessage", null, messageData));
|
||||
fireCallback(new ClientCallback(ClientCallbackMethod.SHOW_USERMESSAGE, null, messageData));
|
||||
}
|
||||
|
||||
public static Throwable getBasicCause(Throwable cause) {
|
||||
|
|
|
@ -27,10 +27,6 @@
|
|||
*/
|
||||
package mage.server;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import mage.cards.decks.Deck;
|
||||
import mage.constants.ManaType;
|
||||
import mage.constants.TableState;
|
||||
|
@ -38,6 +34,7 @@ import mage.game.Table;
|
|||
import mage.game.result.ResultProtos;
|
||||
import mage.game.tournament.TournamentPlayer;
|
||||
import mage.interfaces.callback.ClientCallback;
|
||||
import mage.interfaces.callback.ClientCallbackMethod;
|
||||
import mage.players.net.UserData;
|
||||
import mage.server.draft.DraftSession;
|
||||
import mage.server.game.GameManager;
|
||||
|
@ -54,6 +51,11 @@ import mage.server.util.SystemUtil;
|
|||
import mage.view.TableClientMessage;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
|
@ -247,52 +249,52 @@ public class User {
|
|||
}
|
||||
|
||||
public void ccJoinedTable(final UUID roomId, final UUID tableId, boolean isTournament) {
|
||||
fireCallback(new ClientCallback("joinedTable", tableId, new TableClientMessage(roomId, tableId, isTournament)));
|
||||
fireCallback(new ClientCallback(ClientCallbackMethod.JOINED_TABLE, tableId, new TableClientMessage(roomId, tableId, isTournament)));
|
||||
}
|
||||
|
||||
public void ccGameStarted(final UUID gameId, final UUID playerId) {
|
||||
fireCallback(new ClientCallback("startGame", gameId, new TableClientMessage(gameId, playerId)));
|
||||
fireCallback(new ClientCallback(ClientCallbackMethod.START_GAME, gameId, new TableClientMessage(gameId, playerId)));
|
||||
}
|
||||
|
||||
public void ccDraftStarted(final UUID draftId, final UUID playerId) {
|
||||
fireCallback(new ClientCallback("startDraft", draftId, new TableClientMessage(draftId, playerId)));
|
||||
fireCallback(new ClientCallback(ClientCallbackMethod.START_DRAFT, draftId, new TableClientMessage(draftId, playerId)));
|
||||
}
|
||||
|
||||
public void ccTournamentStarted(final UUID tournamentId, final UUID playerId) {
|
||||
fireCallback(new ClientCallback("startTournament", tournamentId, new TableClientMessage(tournamentId, playerId)));
|
||||
fireCallback(new ClientCallback(ClientCallbackMethod.START_TOURNAMENT, tournamentId, new TableClientMessage(tournamentId, playerId)));
|
||||
}
|
||||
|
||||
public void ccSideboard(final Deck deck, final UUID tableId, final int time, boolean limited) {
|
||||
fireCallback(new ClientCallback("sideboard", tableId, new TableClientMessage(deck, tableId, time, limited)));
|
||||
fireCallback(new ClientCallback(ClientCallbackMethod.SIDEBOARD, tableId, new TableClientMessage(deck, tableId, time, limited)));
|
||||
sideboarding.put(tableId, deck);
|
||||
}
|
||||
|
||||
public void ccConstruct(final Deck deck, final UUID tableId, final int time) {
|
||||
fireCallback(new ClientCallback("construct", tableId, new TableClientMessage(deck, tableId, time)));
|
||||
fireCallback(new ClientCallback(ClientCallbackMethod.CONSTRUCT, tableId, new TableClientMessage(deck, tableId, time)));
|
||||
}
|
||||
|
||||
public void ccShowTournament(final UUID tournamentId) {
|
||||
fireCallback(new ClientCallback("showTournament", tournamentId));
|
||||
fireCallback(new ClientCallback(ClientCallbackMethod.SHOW_TOURNAMENT, tournamentId));
|
||||
}
|
||||
|
||||
public void ccShowGameEndDialog(final UUID gameId) {
|
||||
fireCallback(new ClientCallback("showGameEndDialog", gameId));
|
||||
fireCallback(new ClientCallback(ClientCallbackMethod.SHOW_GAME_END_DIALOG, gameId));
|
||||
}
|
||||
|
||||
public void showUserMessage(final String titel, String message) {
|
||||
List<String> messageData = new LinkedList<>();
|
||||
messageData.add(titel);
|
||||
messageData.add(message);
|
||||
fireCallback(new ClientCallback("showUserMessage", null, messageData));
|
||||
fireCallback(new ClientCallback(ClientCallbackMethod.SHOW_USERMESSAGE, null, messageData));
|
||||
}
|
||||
|
||||
public boolean ccWatchGame(final UUID gameId) {
|
||||
fireCallback(new ClientCallback("watchGame", gameId));
|
||||
fireCallback(new ClientCallback(ClientCallbackMethod.WATCHGAME, gameId));
|
||||
return true;
|
||||
}
|
||||
|
||||
public void ccReplayGame(final UUID gameId) {
|
||||
fireCallback(new ClientCallback("replayGame", gameId));
|
||||
fireCallback(new ClientCallback(ClientCallbackMethod.REPLAY_GAME, gameId));
|
||||
}
|
||||
|
||||
public void sendPlayerUUID(final UUID gameId, final UUID data) {
|
||||
|
|
|
@ -30,6 +30,7 @@ package mage.server.draft;
|
|||
|
||||
import mage.game.draft.Draft;
|
||||
import mage.interfaces.callback.ClientCallback;
|
||||
import mage.interfaces.callback.ClientCallbackMethod;
|
||||
import mage.server.User;
|
||||
import mage.server.UserManager;
|
||||
import mage.server.util.ThreadExecutor;
|
||||
|
@ -75,7 +76,7 @@ public class DraftSession {
|
|||
if (user.isPresent()) {
|
||||
if (futureTimeout != null && !futureTimeout.isDone()) {
|
||||
int remaining = (int) futureTimeout.getDelay(TimeUnit.SECONDS);
|
||||
user.get().fireCallback(new ClientCallback("draftInit", draft.getId(), new DraftClientMessage(getDraftPickView(remaining))));
|
||||
user.get().fireCallback(new ClientCallback(ClientCallbackMethod.DRAFT_INIT, draft.getId(), new DraftClientMessage(getDraftPickView(remaining))));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -88,7 +89,7 @@ public class DraftSession {
|
|||
UserManager.instance
|
||||
.getUser(userId).
|
||||
ifPresent(user -> user.fireCallback(
|
||||
new ClientCallback("draftUpdate", draft.getId(), getDraftView())));
|
||||
new ClientCallback(ClientCallbackMethod.DRAFT_UPDATE, draft.getId(), getDraftView())));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -98,7 +99,7 @@ public class DraftSession {
|
|||
if (!killed) {
|
||||
UserManager.instance
|
||||
.getUser(userId)
|
||||
.ifPresent(user -> user.fireCallback(new ClientCallback("draftInform", draft.getId(), new DraftClientMessage(getDraftView(), message))));
|
||||
.ifPresent(user -> user.fireCallback(new ClientCallback(ClientCallbackMethod.DRAFT_INFORM, draft.getId(), new DraftClientMessage(getDraftView(), message))));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -107,7 +108,7 @@ public class DraftSession {
|
|||
if (!killed) {
|
||||
UserManager.instance
|
||||
.getUser(userId)
|
||||
.ifPresent(user -> user.fireCallback(new ClientCallback("draftOver", draft.getId())));
|
||||
.ifPresent(user -> user.fireCallback(new ClientCallback(ClientCallbackMethod.DRAFT_OVER, draft.getId())));
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -117,7 +118,7 @@ public class DraftSession {
|
|||
setupTimeout(timeout);
|
||||
UserManager.instance
|
||||
.getUser(userId)
|
||||
.ifPresent(user -> user.fireCallback(new ClientCallback("draftPick", draft.getId(), new DraftClientMessage(getDraftPickView(timeout)))));
|
||||
.ifPresent(user -> user.fireCallback(new ClientCallback(ClientCallbackMethod.DRAFT_PICK, draft.getId(), new DraftClientMessage(getDraftPickView(timeout)))));
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@ import mage.constants.PlayerAction;
|
|||
import mage.game.Game;
|
||||
import mage.game.Table;
|
||||
import mage.interfaces.callback.ClientCallback;
|
||||
import mage.interfaces.callback.ClientCallbackMethod;
|
||||
import mage.players.Player;
|
||||
import mage.server.User;
|
||||
import mage.server.UserManager;
|
||||
|
@ -69,7 +70,7 @@ public class GameSessionPlayer extends GameSessionWatcher {
|
|||
|
||||
public void ask(final String question, final Map<String, Serializable> options) {
|
||||
if (!killed) {
|
||||
UserManager.instance.getUser(userId).ifPresent(user -> user.fireCallback(new ClientCallback("gameAsk", game.getId(), new GameClientMessage(getGameView(), question, options)))
|
||||
UserManager.instance.getUser(userId).ifPresent(user -> user.fireCallback(new ClientCallback(ClientCallbackMethod.GAME_TARGET, game.getId(), new GameClientMessage(getGameView(), question, options)))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -77,7 +78,7 @@ public class GameSessionPlayer extends GameSessionWatcher {
|
|||
public void target(final String question, final CardsView cardView, final Set<UUID> targets, final boolean required, final Map<String, Serializable> options) {
|
||||
if (!killed) {
|
||||
UserManager.instance.getUser(userId).ifPresent(user -> {
|
||||
user.fireCallback(new ClientCallback("gameTarget", game.getId(), new GameClientMessage(getGameView(), question, cardView, targets, required, options)));
|
||||
user.fireCallback(new ClientCallback(ClientCallbackMethod.GAME_TARGET, game.getId(), new GameClientMessage(getGameView(), question, cardView, targets, required, options)));
|
||||
});
|
||||
|
||||
}
|
||||
|
@ -85,14 +86,14 @@ public class GameSessionPlayer extends GameSessionWatcher {
|
|||
|
||||
public void select(final String message, final Map<String, Serializable> options) {
|
||||
if (!killed) {
|
||||
UserManager.instance.getUser(userId).ifPresent(user -> user.fireCallback(new ClientCallback("gameSelect", game.getId(), new GameClientMessage(getGameView(), message, options))));
|
||||
UserManager.instance.getUser(userId).ifPresent(user -> user.fireCallback(new ClientCallback(ClientCallbackMethod.GAME_SELECT, game.getId(), new GameClientMessage(getGameView(), message, options))));
|
||||
}
|
||||
}
|
||||
|
||||
public void chooseAbility(final AbilityPickerView abilities) {
|
||||
if (!killed) {
|
||||
UserManager.instance.getUser(userId).ifPresent(user
|
||||
-> user.fireCallback(new ClientCallback("gameChooseAbility", game.getId(), abilities)));
|
||||
-> user.fireCallback(new ClientCallback(ClientCallbackMethod.GAME_CHOOSE_ABILITY, game.getId(), abilities)));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -100,7 +101,7 @@ public class GameSessionPlayer extends GameSessionWatcher {
|
|||
public void choosePile(final String message, final CardsView pile1, final CardsView pile2) {
|
||||
if (!killed) {
|
||||
UserManager.instance.getUser(userId).ifPresent(user
|
||||
-> user.fireCallback(new ClientCallback("gameChoosePile", game.getId(), new GameClientMessage(message, pile1, pile2))));
|
||||
-> user.fireCallback(new ClientCallback(ClientCallbackMethod.GAME_CHOOSE_PILE, game.getId(), new GameClientMessage(message, pile1, pile2))));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -108,7 +109,7 @@ public class GameSessionPlayer extends GameSessionWatcher {
|
|||
public void chooseChoice(final Choice choice) {
|
||||
if (!killed) {
|
||||
UserManager.instance.getUser(userId).ifPresent(user
|
||||
-> user.fireCallback(new ClientCallback("gameChooseChoice", game.getId(), new GameClientMessage(choice))));
|
||||
-> user.fireCallback(new ClientCallback(ClientCallbackMethod.GAME_CHOOSE_CHOICE, game.getId(), new GameClientMessage(choice))));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -116,14 +117,14 @@ public class GameSessionPlayer extends GameSessionWatcher {
|
|||
public void playMana(final String message, final Map<String, Serializable> options) {
|
||||
if (!killed) {
|
||||
UserManager.instance.getUser(userId).ifPresent(user
|
||||
-> user.fireCallback(new ClientCallback("gamePlayMana", game.getId(), new GameClientMessage(getGameView(), message, options))));
|
||||
-> user.fireCallback(new ClientCallback(ClientCallbackMethod.GAME_PLAY_MANA, game.getId(), new GameClientMessage(getGameView(), message, options))));
|
||||
}
|
||||
}
|
||||
|
||||
public void playXMana(final String message) {
|
||||
if (!killed) {
|
||||
UserManager.instance.getUser(userId).ifPresent(user
|
||||
-> user.fireCallback(new ClientCallback("gamePlayXMana", game.getId(), new GameClientMessage(getGameView(), message))));
|
||||
-> user.fireCallback(new ClientCallback(ClientCallbackMethod.GAME_PLAY_XMANA, game.getId(), new GameClientMessage(getGameView(), message))));
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -131,14 +132,14 @@ public class GameSessionPlayer extends GameSessionWatcher {
|
|||
public void getAmount(final String message, final int min, final int max) {
|
||||
if (!killed) {
|
||||
UserManager.instance.getUser(userId).ifPresent(user -> {
|
||||
user.fireCallback(new ClientCallback("gameSelectAmount", game.getId(), new GameClientMessage(message, min, max)));
|
||||
user.fireCallback(new ClientCallback(ClientCallbackMethod.GAME_GET_AMOUNT, game.getId(), new GameClientMessage(message, min, max)));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void endGameInfo(Table table) {
|
||||
if (!killed) {
|
||||
UserManager.instance.getUser(userId).ifPresent(user -> user.fireCallback(new ClientCallback("endGameInfo", game.getId(), getGameEndView(playerId, table))));
|
||||
UserManager.instance.getUser(userId).ifPresent(user -> user.fireCallback(new ClientCallback(ClientCallbackMethod.END_GAME_INFO, game.getId(), getGameEndView(playerId, table))));
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -165,7 +166,7 @@ public class GameSessionPlayer extends GameSessionWatcher {
|
|||
userRequestMessage.setGameId(game.getId());
|
||||
userRequestMessage.setButton1("Accept", PlayerAction.ADD_PERMISSION_TO_ROLLBACK_TURN);
|
||||
userRequestMessage.setButton2("Deny", PlayerAction.DENY_PERMISSON_TO_ROLLBACK_TURN);
|
||||
requestedUser.get().fireCallback(new ClientCallback("userRequestDialog", game.getId(), userRequestMessage));
|
||||
requestedUser.get().fireCallback(new ClientCallback(ClientCallbackMethod.USER_REQUEST_DIALOG, game.getId(), userRequestMessage));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -183,7 +184,7 @@ public class GameSessionPlayer extends GameSessionWatcher {
|
|||
userRequestMessage.setGameId(game.getId());
|
||||
userRequestMessage.setButton1("Accept", PlayerAction.ADD_PERMISSION_TO_SEE_HAND_CARDS);
|
||||
userRequestMessage.setButton2("Reject", null);
|
||||
user.get().fireCallback(new ClientCallback("userRequestDialog", game.getId(), userRequestMessage));
|
||||
user.get().fireCallback(new ClientCallback(ClientCallbackMethod.USER_REQUEST_DIALOG, game.getId(), userRequestMessage));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,14 +28,10 @@
|
|||
|
||||
package mage.server.game;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import mage.game.Game;
|
||||
import mage.game.Table;
|
||||
import mage.interfaces.callback.ClientCallback;
|
||||
import mage.interfaces.callback.ClientCallbackMethod;
|
||||
import mage.players.Player;
|
||||
import mage.server.User;
|
||||
import mage.server.UserManager;
|
||||
|
@ -45,6 +41,11 @@ import mage.view.GameView;
|
|||
import mage.view.SimpleCardsView;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
|
@ -67,7 +68,7 @@ public class GameSessionWatcher {
|
|||
if (!killed) {
|
||||
Optional<User> user = UserManager.instance.getUser(userId);
|
||||
if (user.isPresent()) {
|
||||
user.get().fireCallback(new ClientCallback("gameInit", game.getId(), getGameView()));
|
||||
user.get().fireCallback(new ClientCallback(ClientCallbackMethod.GAME_INIT, game.getId(), getGameView()));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -76,21 +77,21 @@ public class GameSessionWatcher {
|
|||
|
||||
public void update() {
|
||||
if (!killed) {
|
||||
UserManager.instance.getUser(userId).ifPresent(user -> user.fireCallback(new ClientCallback("gameUpdate", game.getId(), getGameView())));
|
||||
UserManager.instance.getUser(userId).ifPresent(user -> user.fireCallback(new ClientCallback(ClientCallbackMethod.GAME_UPDATE, game.getId(), getGameView())));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void inform(final String message) {
|
||||
if (!killed) {
|
||||
UserManager.instance.getUser(userId).ifPresent(user -> user.fireCallback(new ClientCallback("gameInform", game.getId(), new GameClientMessage(getGameView(), message))));
|
||||
UserManager.instance.getUser(userId).ifPresent(user -> user.fireCallback(new ClientCallback(ClientCallbackMethod.GAME_INFORM, game.getId(), new GameClientMessage(getGameView(), message))));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void informPersonal(final String message) {
|
||||
if (!killed) {
|
||||
UserManager.instance.getUser(userId).ifPresent(user -> user.fireCallback(new ClientCallback("gameInformPersonal", game.getId(), new GameClientMessage(getGameView(), message))));
|
||||
UserManager.instance.getUser(userId).ifPresent(user -> user.fireCallback(new ClientCallback(ClientCallbackMethod.GAME_INFORM_PERSONAL, game.getId(), new GameClientMessage(getGameView(), message))));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -99,7 +100,7 @@ public class GameSessionWatcher {
|
|||
if (!killed) {
|
||||
UserManager.instance.getUser(userId).ifPresent(user -> {
|
||||
user.removeGameWatchInfo(game.getId());
|
||||
user.fireCallback(new ClientCallback("gameOver", game.getId(), message));
|
||||
user.fireCallback(new ClientCallback(ClientCallbackMethod.GAME_OVER, game.getId(), message));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -113,7 +114,7 @@ public class GameSessionWatcher {
|
|||
|
||||
public void gameError(final String message) {
|
||||
if (!killed) {
|
||||
UserManager.instance.getUser(userId).ifPresent(user -> user.fireCallback(new ClientCallback("gameError", game.getId(), message)));
|
||||
UserManager.instance.getUser(userId).ifPresent(user -> user.fireCallback(new ClientCallback(ClientCallbackMethod.GAME_ERROR, game.getId(), message)));
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ import java.util.UUID;
|
|||
import mage.game.Game;
|
||||
import mage.game.GameState;
|
||||
import mage.interfaces.callback.ClientCallback;
|
||||
import mage.interfaces.callback.ClientCallbackMethod;
|
||||
import mage.server.UserManager;
|
||||
import mage.view.GameView;
|
||||
|
||||
|
@ -52,7 +53,7 @@ public class ReplaySession implements GameCallback {
|
|||
public void replay() {
|
||||
replay.start();
|
||||
UserManager.instance.getUser(userId).ifPresent(user ->
|
||||
user.fireCallback(new ClientCallback("replayInit", replay.getGame().getId(), new GameView(replay.next(), replay.getGame(), null, null))));
|
||||
user.fireCallback(new ClientCallback(ClientCallbackMethod.REPLAY_INIT, replay.getGame().getId(), new GameView(replay.next(), replay.getGame(), null, null))));
|
||||
|
||||
}
|
||||
|
||||
|
@ -78,7 +79,7 @@ public class ReplaySession implements GameCallback {
|
|||
@Override
|
||||
public void gameResult(final String result) {
|
||||
UserManager.instance.getUser(userId).ifPresent(user ->
|
||||
user.fireCallback(new ClientCallback("replayDone", replay.getGame().getId(), result)));
|
||||
user.fireCallback(new ClientCallback(ClientCallbackMethod.REPLAY_DONE, replay.getGame().getId(), result)));
|
||||
|
||||
ReplayManager.instance.endReplay(replay.getGame().getId(), userId);
|
||||
}
|
||||
|
@ -88,7 +89,7 @@ public class ReplaySession implements GameCallback {
|
|||
gameResult("game ended");
|
||||
} else {
|
||||
UserManager.instance.getUser(userId).ifPresent(user ->
|
||||
user.fireCallback(new ClientCallback("replayUpdate", replay.getGame().getId(), new GameView(state, game, null, null))));
|
||||
user.fireCallback(new ClientCallback(ClientCallbackMethod.REPLAY_UPDATE, replay.getGame().getId(), new GameView(state, game, null, null))));
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ package mage.server.tournament;
|
|||
import mage.cards.decks.Deck;
|
||||
import mage.game.tournament.Tournament;
|
||||
import mage.interfaces.callback.ClientCallback;
|
||||
import mage.interfaces.callback.ClientCallbackMethod;
|
||||
import mage.server.User;
|
||||
import mage.server.UserManager;
|
||||
import mage.server.util.ThreadExecutor;
|
||||
|
@ -69,7 +70,7 @@ public class TournamentSession {
|
|||
if (!killed) {
|
||||
Optional<User> user = UserManager.instance.getUser(userId);
|
||||
if (user.isPresent()) {
|
||||
user.get().fireCallback(new ClientCallback("tournamentInit", tournament.getId(), getTournamentView()));
|
||||
user.get().fireCallback(new ClientCallback(ClientCallbackMethod.TOURNAMENT_INIT, tournament.getId(), getTournamentView()));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -79,7 +80,7 @@ public class TournamentSession {
|
|||
public void update() {
|
||||
if (!killed) {
|
||||
UserManager.instance.getUser(userId).ifPresent(user ->
|
||||
user.fireCallback(new ClientCallback("tournamentUpdate", tournament.getId(), getTournamentView())));
|
||||
user.fireCallback(new ClientCallback(ClientCallbackMethod.TOURNAMENT_UPDATE, tournament.getId(), getTournamentView())));
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -87,7 +88,7 @@ public class TournamentSession {
|
|||
public void gameOver(final String message) {
|
||||
if (!killed) {
|
||||
UserManager.instance.getUser(userId).ifPresent(user ->
|
||||
user.fireCallback(new ClientCallback("tournamentOver", tournament.getId(), message)));
|
||||
user.fireCallback(new ClientCallback(ClientCallbackMethod.TOURNAMENT_OVER, tournament.getId(), message)));
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,58 +35,55 @@ public class LoadCallbackClient implements CallbackClient {
|
|||
log.info(callback.getMethod());
|
||||
callback.setData(CompressUtil.decompress(callback.getData()));
|
||||
switch (callback.getMethod()) {
|
||||
case "startGame":
|
||||
{
|
||||
TableClientMessage message = (TableClientMessage) callback.getData();
|
||||
gameId = message.getGameId();
|
||||
playerId = message.getPlayerId();
|
||||
session.joinGame(message.getGameId());
|
||||
startControlThread();
|
||||
break;
|
||||
}
|
||||
case "gameInform":
|
||||
{
|
||||
GameClientMessage message = (GameClientMessage) callback.getData();
|
||||
log.info("Inform: " + message.getMessage());
|
||||
gameView = message.getGameView();
|
||||
break;
|
||||
}
|
||||
case "gameInit":
|
||||
case START_GAME: {
|
||||
TableClientMessage message = (TableClientMessage) callback.getData();
|
||||
gameId = message.getGameId();
|
||||
playerId = message.getPlayerId();
|
||||
session.joinGame(message.getGameId());
|
||||
startControlThread();
|
||||
break;
|
||||
case "gameTarget":
|
||||
{
|
||||
GameClientMessage message = (GameClientMessage) callback.getData();
|
||||
log.info("Target: " + message.getMessage());
|
||||
switch (message.getMessage()) {
|
||||
case "Select a starting player":
|
||||
session.sendPlayerUUID(gameId, playerId);
|
||||
break;
|
||||
case "Select a card to discard":
|
||||
log.info("hand size: " + gameView.getHand().size());
|
||||
SimpleCardView card = gameView.getHand().values().iterator().next();
|
||||
session.sendPlayerUUID(gameId, card.getId());
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case GAME_INFORM: {
|
||||
GameClientMessage message = (GameClientMessage) callback.getData();
|
||||
log.info("Inform: " + message.getMessage());
|
||||
gameView = message.getGameView();
|
||||
break;
|
||||
}
|
||||
case GAME_INIT:
|
||||
break;
|
||||
case GAME_TARGET: {
|
||||
GameClientMessage message = (GameClientMessage) callback.getData();
|
||||
log.info("Target: " + message.getMessage());
|
||||
switch (message.getMessage()) {
|
||||
case "Select a starting player":
|
||||
session.sendPlayerUUID(gameId, playerId);
|
||||
break;
|
||||
case "Select a card to discard":
|
||||
log.info("hand size: " + gameView.getHand().size());
|
||||
SimpleCardView card = gameView.getHand().values().iterator().next();
|
||||
session.sendPlayerUUID(gameId, card.getId());
|
||||
break;
|
||||
}
|
||||
case "gameAsk":
|
||||
{
|
||||
GameClientMessage message = (GameClientMessage) callback.getData();
|
||||
log.info("Ask: " + message.getMessage());
|
||||
if (message.getMessage().equals("Do you want to take a mulligan?")) {
|
||||
session.sendPlayerBoolean(gameId, false);
|
||||
} break;
|
||||
break;
|
||||
}
|
||||
case GAME_ASK: {
|
||||
GameClientMessage message = (GameClientMessage) callback.getData();
|
||||
log.info("Ask: " + message.getMessage());
|
||||
if (message.getMessage().equals("Do you want to take a mulligan?")) {
|
||||
session.sendPlayerBoolean(gameId, false);
|
||||
}
|
||||
case "gameSelect":
|
||||
{
|
||||
GameClientMessage message = (GameClientMessage) callback.getData();
|
||||
log.info("Select: " + message.getMessage());
|
||||
if (LoadPhaseManager.getInstance().isSkip(message.getGameView(), message.getMessage(), playerId)) {
|
||||
log.info("Skipped: " + message.getMessage());
|
||||
session.sendPlayerBoolean(gameId, false);
|
||||
} break;
|
||||
break;
|
||||
}
|
||||
case GAME_SELECT: {
|
||||
GameClientMessage message = (GameClientMessage) callback.getData();
|
||||
log.info("Select: " + message.getMessage());
|
||||
if (LoadPhaseManager.getInstance().isSkip(message.getGameView(), message.getMessage(), playerId)) {
|
||||
log.info("Skipped: " + message.getMessage());
|
||||
session.sendPlayerBoolean(gameId, false);
|
||||
}
|
||||
case "gameOver":
|
||||
break;
|
||||
}
|
||||
case GAME_OVER:
|
||||
log.info("Game over");
|
||||
gameOver = true;
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue