use of mage.remote.Session in project mage by magefree.
the class CallbackClientImpl method appendJsonEvent.
private ActionData appendJsonEvent(String name, UUID gameId, Object value) {
Session session = SessionHandler.getSession();
if (session.isJsonLogActive()) {
ActionData actionData = new ActionData(name, gameId);
actionData.value = value;
session.appendJsonLog(actionData);
return actionData;
}
return null;
}
use of mage.remote.Session in project mage by magefree.
the class CallbackClientImpl method processCallback.
@Override
public synchronized void processCallback(final ClientCallback callback) {
callback.decompressData();
SaveObjectUtil.saveObject(callback.getData(), callback.getMethod().toString());
SwingUtilities.invokeLater(() -> {
try {
logger.debug(callback.getMessageId() + " -- " + callback.getMethod());
switch(callback.getMethod()) {
case START_GAME:
{
TableClientMessage message = (TableClientMessage) callback.getData();
GameManager.instance.setCurrentPlayerUUID(message.getPlayerId());
gameStarted(message.getGameId(), message.getPlayerId());
break;
}
case START_TOURNAMENT:
{
TableClientMessage message = (TableClientMessage) callback.getData();
tournamentStarted(message.getGameId(), message.getPlayerId());
break;
}
case START_DRAFT:
{
TableClientMessage message = (TableClientMessage) callback.getData();
draftStarted(message.getGameId(), message.getPlayerId());
break;
}
case REPLAY_GAME:
{
replayGame(callback.getObjectId());
break;
}
case SHOW_TOURNAMENT:
{
showTournament(callback.getObjectId());
break;
}
case WATCHGAME:
{
watchGame(callback.getObjectId());
break;
}
case CHATMESSAGE:
{
ChatMessage message = (ChatMessage) callback.getData();
// Drop messages from ignored users
if (message.getUsername() != null && IgnoreList.IGNORED_MESSAGE_TYPES.contains(message.getMessageType())) {
final String serverAddress = SessionHandler.getSession().getServerHostname().orElse("");
if (IgnoreList.userIsIgnored(serverAddress, message.getUsername())) {
break;
}
}
ChatPanelBasic panel = MageFrame.getChat(callback.getObjectId());
if (panel != null) {
// play the sound related to the message
if (message.getSoundToPlay() != null) {
switch(message.getSoundToPlay()) {
case PlayerLeft:
AudioManager.playPlayerLeft();
break;
case PlayerQuitTournament:
AudioManager.playPlayerQuitTournament();
break;
case PlayerSubmittedDeck:
AudioManager.playPlayerSubmittedDeck();
break;
case PlayerWhispered:
AudioManager.playPlayerWhispered();
break;
}
}
// send start message to chat if not done yet
if (!panel.isStartMessageDone()) {
createChatStartMessage(panel);
}
// send the message to subchat if exists and it's not a game message
if (message.getMessageType() != MessageType.GAME && panel.getConnectedChat() != null) {
panel.getConnectedChat().receiveMessage(message.getUsername(), message.getMessage(), message.getTime(), message.getTurnInfo(), message.getMessageType(), ChatMessage.MessageColor.BLACK);
} else {
panel.receiveMessage(message.getUsername(), message.getMessage(), message.getTime(), message.getTurnInfo(), message.getMessageType(), message.getColor());
}
}
break;
}
case SERVER_MESSAGE:
{
if (callback.getData() != null) {
ChatMessage message = (ChatMessage) callback.getData();
if (message.getColor() == ChatMessage.MessageColor.RED) {
JOptionPane.showMessageDialog(null, message.getMessage(), "Server message", JOptionPane.WARNING_MESSAGE);
} else {
JOptionPane.showMessageDialog(null, message.getMessage(), "Server message", JOptionPane.INFORMATION_MESSAGE);
}
}
break;
}
case JOINED_TABLE:
{
TableClientMessage message = (TableClientMessage) callback.getData();
joinedTable(message.getRoomId(), message.getTableId(), message.getFlag());
break;
}
case REPLAY_INIT:
{
GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) {
panel.init((GameView) callback.getData());
}
break;
}
case REPLAY_DONE:
{
GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) {
panel.endMessage(null, null, (String) callback.getData(), callback.getMessageId());
}
break;
}
case REPLAY_UPDATE:
{
GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) {
panel.updateGame((GameView) callback.getData());
}
break;
}
case GAME_INIT:
{
GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) {
appendJsonEvent("GAME_INIT", callback.getObjectId(), callback.getData());
panel.init((GameView) callback.getData());
}
break;
}
case GAME_OVER:
{
GameClientMessage message = (GameClientMessage) callback.getData();
GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) {
Session session = SessionHandler.getSession();
if (session.isJsonLogActive()) {
UUID gameId = callback.getObjectId();
appendJsonEvent("GAME_OVER", callback.getObjectId(), message);
String logFileName = "game-" + gameId + ".json";
S3Uploader.upload(logFileName, gameId.toString());
}
panel.endMessage(message.getGameView(), message.getOptions(), message.getMessage(), callback.getMessageId());
}
break;
}
case GAME_ERROR:
{
frame.showErrorDialog("Game Error", (String) callback.getData());
break;
}
case GAME_ASK:
{
GameClientMessage message = (GameClientMessage) callback.getData();
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());
}
break;
}
case GAME_TARGET:
{
// e.g. Pick triggered ability
GameClientMessage message = (GameClientMessage) callback.getData();
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());
}
break;
}
case GAME_SELECT:
{
GameClientMessage message = (GameClientMessage) callback.getData();
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());
}
break;
}
case GAME_CHOOSE_ABILITY:
{
AbilityPickerView abilityPickerView = (AbilityPickerView) callback.getData();
GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) {
appendJsonEvent("GAME_CHOOSE_ABILITY", callback.getObjectId(), callback.getData());
panel.pickAbility(abilityPickerView.getGameView(), null, abilityPickerView);
}
break;
}
case GAME_CHOOSE_PILE:
{
GameClientMessage message = (GameClientMessage) callback.getData();
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());
}
break;
}
case GAME_CHOOSE_CHOICE:
{
GameClientMessage message = (GameClientMessage) callback.getData();
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());
}
break;
}
case GAME_PLAY_MANA:
{
GameClientMessage message = (GameClientMessage) callback.getData();
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());
}
break;
}
case GAME_PLAY_XMANA:
{
GameClientMessage message = (GameClientMessage) callback.getData();
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());
}
break;
}
case GAME_GET_AMOUNT:
{
GameClientMessage message = (GameClientMessage) callback.getData();
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());
}
break;
}
case GAME_GET_MULTI_AMOUNT:
{
GameClientMessage message = (GameClientMessage) callback.getData();
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());
}
break;
}
case GAME_UPDATE:
{
GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) {
appendJsonEvent("GAME_UPDATE", callback.getObjectId(), callback.getData());
// update after undo wtf?!
panel.updateGame((GameView) callback.getData(), true, null, null);
}
break;
}
case GAME_REDRAW_GUI:
{
// re-draw game's gui elements like attack arrows
// uses for client side only (example: update after scrollbars support)
GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) {
panel.updateGame();
}
break;
}
case END_GAME_INFO:
{
MageFrame.getInstance().showGameEndDialog((GameEndView) callback.getData());
break;
}
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 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()));
}
gameInformMessageId = messageId;
break;
}
case GAME_INFORM_PERSONAL:
{
GameClientMessage message = (GameClientMessage) callback.getData();
GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) {
JOptionPane.showMessageDialog(panel, message.getMessage(), "Game message", JOptionPane.INFORMATION_MESSAGE);
}
break;
}
case SIDEBOARD:
{
TableClientMessage message = (TableClientMessage) callback.getData();
DeckView deckView = message.getDeck();
Deck deck = DeckUtil.construct(deckView);
if (message.getFlag()) {
construct(deck, message.getTableId(), message.getTime());
} else {
sideboard(deck, message.getTableId(), message.getTime());
}
break;
}
case VIEW_LIMITED_DECK:
{
TableClientMessage message = (TableClientMessage) callback.getData();
DeckView deckView = message.getDeck();
Deck deck = DeckUtil.construct(deckView);
viewLimitedDeck(deck, message.getTableId(), message.getTime());
break;
}
case VIEW_SIDEBOARD:
{
TableClientMessage message = (TableClientMessage) callback.getData();
viewSideboard(message.getGameId(), message.getPlayerId());
break;
}
case CONSTRUCT:
{
TableClientMessage message = (TableClientMessage) callback.getData();
DeckView deckView = message.getDeck();
Deck deck = DeckUtil.construct(deckView);
construct(deck, message.getTableId(), message.getTime());
break;
}
case DRAFT_OVER:
{
MageFrame.removeDraft(callback.getObjectId());
break;
}
case DRAFT_INIT:
case DRAFT_PICK:
{
DraftClientMessage message = (DraftClientMessage) callback.getData();
DraftPanel panel = MageFrame.getDraft(callback.getObjectId());
if (panel != null) {
panel.loadBooster(message.getDraftPickView());
}
break;
}
case DRAFT_UPDATE:
{
DraftPanel panel = MageFrame.getDraft(callback.getObjectId());
DraftClientMessage message = (DraftClientMessage) callback.getData();
if (panel != null) {
panel.updateDraft(message.getDraftView());
}
break;
}
case TOURNAMENT_INIT:
{
break;
}
case USER_REQUEST_DIALOG:
{
frame.showUserRequestDialog((UserRequestMessage) callback.getData());
break;
}
default:
{
break;
}
}
// sync message for server side events only
if (!callback.getMethod().isClientSideMessage()) {
messageId = callback.getMessageId();
}
} catch (Exception ex) {
handleException(ex);
}
});
}
use of mage.remote.Session in project mage by magefree.
the class JoinTableDialog method btnOKActionPerformed.
// GEN-LAST:event_btnCancelActionPerformed
private void btnOKActionPerformed(java.awt.event.ActionEvent evt) {
// GEN-FIRST:event_btnOKActionPerformed
Session session = SessionHandler.getSession();
try {
PreferencesDialog.saveValue(PreferencesDialog.KEY_NEW_TABLE_PASSWORD_JOIN, txtPassword.getText());
if (isTournament) {
joined = session.joinTournamentTable(roomId, tableId, this.newPlayerPanel.getPlayerName(), PlayerType.HUMAN, 1, DeckImporter.importDeckFromFile(this.newPlayerPanel.getDeckFile(), true), this.txtPassword.getText());
} else {
joined = session.joinTable(roomId, tableId, this.newPlayerPanel.getPlayerName(), PlayerType.HUMAN, 1, DeckImporter.importDeckFromFile(this.newPlayerPanel.getDeckFile(), true), this.txtPassword.getText());
}
} catch (Exception ex) {
handleError(ex);
}
this.hideDialog();
}
Aggregations