mirror of
https://github.com/correl/mage.git
synced 2025-04-08 01:01:04 -09:00
moved Session to Mage.Common
This commit is contained in:
parent
bbb9e575eb
commit
c4a3a496aa
26 changed files with 268 additions and 202 deletions
Mage.Client/src/main/java/mage/client
Mage.Common/src/mage
Mage.Server/plugins
|
@ -71,37 +71,50 @@ import java.util.List;
|
|||
import java.util.prefs.Preferences;
|
||||
import javax.swing.event.PopupMenuEvent;
|
||||
import javax.swing.event.PopupMenuListener;
|
||||
import mage.client.chat.ChatPanel;
|
||||
import mage.client.components.MageUI;
|
||||
import mage.client.deckeditor.DeckEditorPane;
|
||||
import mage.client.draft.DraftPane;
|
||||
import mage.client.draft.DraftPanel;
|
||||
import mage.client.game.GamePane;
|
||||
import mage.client.remote.Session;
|
||||
import mage.client.game.GamePanel;
|
||||
import mage.client.remote.CallbackClientImpl;
|
||||
import mage.client.table.TablesPane;
|
||||
import mage.client.tournament.TournamentPane;
|
||||
import mage.client.tournament.TournamentPanel;
|
||||
import mage.game.match.MatchOptions;
|
||||
import mage.interfaces.MageClient;
|
||||
import mage.interfaces.callback.CallbackClient;
|
||||
import mage.interfaces.callback.ClientCallback;
|
||||
import mage.remote.Connection;
|
||||
import mage.remote.Connection.ProxyType;
|
||||
import mage.remote.Session;
|
||||
import mage.utils.MageVersion;
|
||||
import mage.sets.Sets;
|
||||
import mage.utils.Connection;
|
||||
import mage.utils.Connection.ProxyType;
|
||||
import mage.view.TableView;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class MageFrame extends javax.swing.JFrame {
|
||||
public class MageFrame extends javax.swing.JFrame implements MageClient {
|
||||
|
||||
private final static Logger logger = Logger.getLogger(MageFrame.class);
|
||||
|
||||
private static Session session;
|
||||
private ConnectDialog connectDialog;
|
||||
private static CallbackClient callbackClient;
|
||||
private static Preferences prefs = Preferences.userNodeForPackage(MageFrame.class);
|
||||
private JLabel title;
|
||||
private Rectangle titleRectangle;
|
||||
private final static MageVersion version = new MageVersion(0, 7, 4, "beta");
|
||||
private UUID clientId;
|
||||
private static MagePane activeFrame;
|
||||
|
||||
|
||||
private static Map<UUID, ChatPanel> chats = new HashMap<UUID, ChatPanel>();
|
||||
private static Map<UUID, GamePanel> games = new HashMap<UUID, GamePanel>();
|
||||
private static Map<UUID, DraftPanel> drafts = new HashMap<UUID, DraftPanel>();
|
||||
private static Map<UUID, TournamentPanel> tournaments = new HashMap<UUID, TournamentPanel>();
|
||||
private static MageUI ui = new MageUI();
|
||||
|
||||
/**
|
||||
|
@ -119,6 +132,7 @@ public class MageFrame extends javax.swing.JFrame {
|
|||
return prefs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MageVersion getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
@ -156,6 +170,7 @@ public class MageFrame extends javax.swing.JFrame {
|
|||
this.setExtendedState(JFrame.MAXIMIZED_BOTH);
|
||||
|
||||
session = new Session(this);
|
||||
callbackClient = new CallbackClientImpl(this);
|
||||
connectDialog = new ConnectDialog();
|
||||
desktopPane.add(connectDialog, JLayeredPane.POPUP_LAYER);
|
||||
ui.addComponent(MageComponents.DESKTOP_PANE, desktopPane);
|
||||
|
@ -739,7 +754,7 @@ public class MageFrame extends javax.swing.JFrame {
|
|||
private void btnConnectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnConnectActionPerformed
|
||||
if (session.isConnected()) {
|
||||
if (JOptionPane.showConfirmDialog(this, "Are you sure you want to disconnect?", "Confirm disconnect", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
|
||||
session.disconnect();
|
||||
session.disconnect(false);
|
||||
showMessage("You have disconnected");
|
||||
}
|
||||
} else {
|
||||
|
@ -754,7 +769,7 @@ public class MageFrame extends javax.swing.JFrame {
|
|||
}//GEN-LAST:event_btnAboutActionPerformed
|
||||
|
||||
public void exitApp() {
|
||||
session.disconnect();
|
||||
session.disconnect(false);
|
||||
Plugins.getInstance().shutdown();
|
||||
dispose();
|
||||
System.exit(0);
|
||||
|
@ -873,10 +888,40 @@ public class MageFrame extends javax.swing.JFrame {
|
|||
return ui;
|
||||
}
|
||||
|
||||
public static ChatPanel getChat(UUID chatId) {
|
||||
return chats.get(chatId);
|
||||
}
|
||||
|
||||
public static void addChat(UUID chatId, ChatPanel chatPanel) {
|
||||
chats.put(chatId, chatPanel);
|
||||
}
|
||||
|
||||
public static GamePanel getGame(UUID gameId) {
|
||||
return games.get(gameId);
|
||||
}
|
||||
|
||||
public static void addGame(UUID gameId, GamePanel gamePanel) {
|
||||
games.put(gameId, gamePanel);
|
||||
}
|
||||
|
||||
public static DraftPanel getDraft(UUID draftId) {
|
||||
return drafts.get(draftId);
|
||||
}
|
||||
|
||||
public static void addDraft(UUID draftId, DraftPanel draftPanel) {
|
||||
drafts.put(draftId, draftPanel);
|
||||
}
|
||||
|
||||
public static void addTournament(UUID tournamentId, TournamentPanel tournament) {
|
||||
tournaments.put(tournamentId, tournament);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getId() {
|
||||
return clientId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connected(final String message) {
|
||||
if (SwingUtilities.isEventDispatchThread()) {
|
||||
setStatusText(message);
|
||||
|
@ -893,6 +938,7 @@ public class MageFrame extends javax.swing.JFrame {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnected() {
|
||||
if (SwingUtilities.isEventDispatchThread()) {
|
||||
setStatusText("Not connected");
|
||||
|
@ -913,6 +959,7 @@ public class MageFrame extends javax.swing.JFrame {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showMessage(final String message) {
|
||||
if (SwingUtilities.isEventDispatchThread()) {
|
||||
JOptionPane.showMessageDialog(desktopPane, message);
|
||||
|
@ -927,6 +974,7 @@ public class MageFrame extends javax.swing.JFrame {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showError(final String message) {
|
||||
if (SwingUtilities.isEventDispatchThread()) {
|
||||
JOptionPane.showMessageDialog(desktopPane, message, "Error", JOptionPane.ERROR_MESSAGE);
|
||||
|
@ -940,6 +988,11 @@ public class MageFrame extends javax.swing.JFrame {
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processCallback(ClientCallback callback) {
|
||||
callbackClient.processCallback(callback);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -80,7 +80,7 @@ import mage.cards.MagePermanent;
|
|||
import mage.cards.TextPopup;
|
||||
import mage.client.MageFrame;
|
||||
import mage.client.game.PlayAreaPanel;
|
||||
import mage.client.remote.Session;
|
||||
import mage.remote.Session;
|
||||
import mage.client.util.Config;
|
||||
import mage.client.util.DefaultActionCallback;
|
||||
import mage.client.util.ImageHelper;
|
||||
|
@ -382,13 +382,13 @@ public class Card extends MagePermanent implements MouseMotionListener, MouseLis
|
|||
List<UUID> targets = card.getTargets();
|
||||
if (targets != null) {
|
||||
for (UUID uuid : targets) {
|
||||
PlayAreaPanel p = MageFrame.getSession().getGame(gameId).getPlayers().get(uuid);
|
||||
PlayAreaPanel p = MageFrame.getGame(gameId).getPlayers().get(uuid);
|
||||
if (p != null) {
|
||||
Point target = p.getLocationOnScreen();
|
||||
Point me = this.getLocationOnScreen();
|
||||
ArrowBuilder.addArrow((int)me.getX() + 35, (int)me.getY(), (int)target.getX() + 40, (int)target.getY() - 40, Color.red);
|
||||
} else {
|
||||
for (PlayAreaPanel pa : MageFrame.getSession().getGame(gameId).getPlayers().values()) {
|
||||
for (PlayAreaPanel pa : MageFrame.getGame(gameId).getPlayers().values()) {
|
||||
MagePermanent permanent = pa.getBattlefieldPanel().getPermanents().get(uuid);
|
||||
if (permanent != null) {
|
||||
Point target = permanent.getLocationOnScreen();
|
||||
|
|
|
@ -40,7 +40,7 @@ import java.util.*;
|
|||
import java.util.List;
|
||||
import mage.client.MageFrame;
|
||||
import mage.client.components.ColorPane;
|
||||
import mage.client.remote.Session;
|
||||
import mage.remote.Session;
|
||||
import mage.view.ChatMessage.MessageColor;
|
||||
|
||||
import javax.swing.border.EmptyBorder;
|
||||
|
@ -130,7 +130,9 @@ public class ChatPanel extends javax.swing.JPanel {
|
|||
public void connect(UUID chatId) {
|
||||
session = MageFrame.getSession();
|
||||
this.chatId = chatId;
|
||||
session.joinChat(chatId, this);
|
||||
if (session.joinChat(chatId)) {
|
||||
MageFrame.addChat(chatId, this);
|
||||
}
|
||||
}
|
||||
|
||||
public void disconnect() {
|
||||
|
|
|
@ -50,8 +50,8 @@ import javax.swing.SwingWorker;
|
|||
|
||||
import mage.client.MageFrame;
|
||||
import mage.client.util.Config;
|
||||
import mage.utils.Connection;
|
||||
import mage.utils.Connection.ProxyType;
|
||||
import mage.remote.Connection;
|
||||
import mage.remote.Connection.ProxyType;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ package mage.client.dialog;
|
|||
import mage.client.*;
|
||||
import java.util.UUID;
|
||||
import javax.swing.JOptionPane;
|
||||
import mage.client.remote.Session;
|
||||
import mage.remote.Session;
|
||||
import mage.sets.Sets;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ import javax.swing.SpinnerNumberModel;
|
|||
import mage.Constants.MultiplayerAttackOption;
|
||||
import mage.Constants.RangeOfInfluence;
|
||||
import mage.client.components.MageComponents;
|
||||
import mage.client.remote.Session;
|
||||
import mage.remote.Session;
|
||||
import mage.client.table.TablePlayerPanel;
|
||||
import mage.client.util.Event;
|
||||
import mage.client.util.Listener;
|
||||
|
|
|
@ -42,7 +42,7 @@ import java.util.concurrent.ExecutionException;
|
|||
import javax.swing.SwingWorker;
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
import mage.client.components.MageComponents;
|
||||
import mage.client.remote.Session;
|
||||
import mage.remote.Session;
|
||||
import mage.view.SeatView;
|
||||
import mage.view.TableView;
|
||||
import org.apache.log4j.Logger;
|
||||
|
|
|
@ -41,7 +41,7 @@ import java.util.UUID;
|
|||
import javax.swing.Timer;
|
||||
import mage.client.MageFrame;
|
||||
import mage.client.constants.Constants.SortBy;
|
||||
import mage.client.remote.Session;
|
||||
import mage.remote.Session;
|
||||
import mage.client.util.Event;
|
||||
import mage.client.util.Listener;
|
||||
import mage.view.DraftPickView;
|
||||
|
@ -81,7 +81,7 @@ public class DraftPanel extends javax.swing.JPanel {
|
|||
public synchronized void showDraft(UUID draftId) {
|
||||
this.draftId = draftId;
|
||||
session = MageFrame.getSession();
|
||||
session.addDraft(draftId, this);
|
||||
MageFrame.addDraft(draftId, this);
|
||||
if (!session.joinDraft(draftId))
|
||||
hideDraft();
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ import javax.swing.JPopupMenu;
|
|||
import javax.swing.event.PopupMenuEvent;
|
||||
import javax.swing.event.PopupMenuListener;
|
||||
import mage.client.MageFrame;
|
||||
import mage.client.remote.Session;
|
||||
import mage.remote.Session;
|
||||
import mage.client.util.gui.GuiDisplayUtil;
|
||||
import mage.view.AbilityPickerView;
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ import javax.swing.*;
|
|||
import mage.client.MageFrame;
|
||||
import mage.client.components.MageTextArea;
|
||||
import mage.client.components.arcane.GlowText;
|
||||
import mage.client.remote.Session;
|
||||
import mage.remote.Session;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ import mage.client.dialog.PickNumberDialog;
|
|||
import mage.client.dialog.ShowCardsDialog;
|
||||
import mage.client.game.FeedbackPanel.FeedbackMode;
|
||||
import mage.client.plugins.impl.Plugins;
|
||||
import mage.client.remote.Session;
|
||||
import mage.remote.Session;
|
||||
import mage.client.util.Config;
|
||||
import mage.client.util.GameManager;
|
||||
import mage.client.util.PhaseManager;
|
||||
|
@ -161,7 +161,7 @@ public class GamePanel extends javax.swing.JPanel {
|
|||
this.gameId = gameId;
|
||||
this.playerId = playerId;
|
||||
session = MageFrame.getSession();
|
||||
session.addGame(gameId, this);
|
||||
MageFrame.addGame(gameId, this);
|
||||
this.feedbackPanel.init(gameId);
|
||||
this.feedbackPanel.clear();
|
||||
this.abilityPicker.init(session, gameId);
|
||||
|
@ -178,7 +178,7 @@ public class GamePanel extends javax.swing.JPanel {
|
|||
this.gameId = gameId;
|
||||
this.playerId = null;
|
||||
session = MageFrame.getSession();
|
||||
session.addGame(gameId, this);
|
||||
MageFrame.addGame(gameId, this);
|
||||
this.feedbackPanel.init(gameId);
|
||||
this.feedbackPanel.clear();
|
||||
this.btnConcede.setVisible(false);
|
||||
|
@ -194,7 +194,7 @@ public class GamePanel extends javax.swing.JPanel {
|
|||
this.gameId = gameId;
|
||||
this.playerId = null;
|
||||
session = MageFrame.getSession();
|
||||
session.addGame(gameId, this);
|
||||
MageFrame.addGame(gameId, this);
|
||||
this.feedbackPanel.clear();
|
||||
this.btnConcede.setVisible(false);
|
||||
this.btnStopWatching.setVisible(false);
|
||||
|
|
|
@ -39,7 +39,7 @@ import java.util.UUID;
|
|||
import mage.client.MageFrame;
|
||||
import mage.client.cards.BigCard;
|
||||
import mage.client.dialog.ShowCardsDialog;
|
||||
import mage.client.remote.Session;
|
||||
import mage.remote.Session;
|
||||
import mage.client.util.Config;
|
||||
import mage.view.PlayerView;
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ import mage.client.components.HoverButton;
|
|||
import mage.client.components.MageRoundPane;
|
||||
import mage.client.components.arcane.ManaSymbols;
|
||||
import mage.client.dialog.ShowCardsDialog;
|
||||
import mage.client.remote.Session;
|
||||
import mage.remote.Session;
|
||||
import mage.client.util.Command;
|
||||
import mage.client.util.Config;
|
||||
import mage.client.util.ImageHelper;
|
||||
|
|
|
@ -18,7 +18,7 @@ import mage.client.cards.BigCard;
|
|||
import mage.client.components.MageComponents;
|
||||
import mage.client.game.PlayAreaPanel;
|
||||
import mage.client.plugins.impl.Plugins;
|
||||
import mage.client.remote.Session;
|
||||
import mage.remote.Session;
|
||||
import mage.client.util.DefaultActionCallback;
|
||||
import mage.client.util.ImageHelper;
|
||||
import mage.client.util.gui.ArrowBuilder;
|
||||
|
@ -82,13 +82,13 @@ public class MageActionCallback implements ActionCallback {
|
|||
for (UUID uuid : targets) {
|
||||
//System.out.println("Getting play area panel for uuid: " + uuid);
|
||||
|
||||
PlayAreaPanel p = session.getGame(data.gameId).getPlayers().get(uuid);
|
||||
PlayAreaPanel p = MageFrame.getGame(data.gameId).getPlayers().get(uuid);
|
||||
if (p != null) {
|
||||
Point target = p.getLocationOnScreen();
|
||||
target.translate(-parentPoint.x, -parentPoint.y);
|
||||
ArrowBuilder.addArrow((int) me.getX() + 35, (int) me.getY(), (int) target.getX() + 40, (int) target.getY() - 40, Color.red);
|
||||
} else {
|
||||
for (PlayAreaPanel pa : session.getGame(data.gameId).getPlayers().values()) {
|
||||
for (PlayAreaPanel pa : MageFrame.getGame(data.gameId).getPlayers().values()) {
|
||||
MagePermanent permanent = pa.getBattlefieldPanel().getPermanents().get(uuid);
|
||||
if (permanent != null) {
|
||||
Point target = permanent.getLocationOnScreen();
|
||||
|
@ -105,7 +105,7 @@ public class MageActionCallback implements ActionCallback {
|
|||
Point me = new Point(data.locationOnScreen);
|
||||
me.translate(-parentPoint.x, -parentPoint.y);
|
||||
UUID uuid = data.card.getParentId();
|
||||
for (PlayAreaPanel pa : session.getGame(data.gameId).getPlayers().values()) {
|
||||
for (PlayAreaPanel pa : MageFrame.getGame(data.gameId).getPlayers().values()) {
|
||||
MagePermanent permanent = pa.getBattlefieldPanel().getPermanents().get(uuid);
|
||||
if (permanent != null) {
|
||||
Point source = permanent.getLocationOnScreen();
|
||||
|
|
|
@ -28,9 +28,7 @@
|
|||
|
||||
package mage.client.remote;
|
||||
|
||||
import java.rmi.RemoteException;
|
||||
import java.util.UUID;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.SwingUtilities;
|
||||
import mage.cards.decks.Deck;
|
||||
import mage.client.MageFrame;
|
||||
|
@ -40,8 +38,10 @@ import mage.client.draft.DraftPanel;
|
|||
import mage.client.game.GamePanel;
|
||||
import mage.client.plugins.impl.Plugins;
|
||||
import mage.client.util.GameManager;
|
||||
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.DraftClientMessage;
|
||||
|
@ -55,26 +55,26 @@ import org.apache.log4j.Logger;
|
|||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class Client implements CallbackClient {
|
||||
public class CallbackClientImpl implements CallbackClient {
|
||||
|
||||
private final static Logger logger = Logger.getLogger(Client.class);
|
||||
private final static Logger logger = Logger.getLogger(CallbackClientImpl.class);
|
||||
|
||||
private UUID clientId;
|
||||
private MageFrame frame;
|
||||
private Session session;
|
||||
private int messageId = 0;
|
||||
|
||||
public Client(Session session, MageFrame frame) {
|
||||
public CallbackClientImpl(MageFrame frame) {
|
||||
|
||||
this.clientId = UUID.randomUUID();
|
||||
this.frame = frame;
|
||||
this.session = session;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void processCallback(final ClientCallback callback) {
|
||||
logger.info(callback.getMessageId() + " - " + callback.getMethod());
|
||||
SaveObjectUtil.saveObject(callback.getData(), callback.getMethod());
|
||||
callback.setData(CompressUtil.decompress(callback.getData()));
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
@ -101,7 +101,7 @@ public class Client implements CallbackClient {
|
|||
}
|
||||
else if (callback.getMethod().equals("chatMessage")) {
|
||||
ChatMessage message = (ChatMessage) callback.getData();
|
||||
ChatPanel panel = session.getChat(callback.getObjectId());
|
||||
ChatPanel panel = frame.getChat(callback.getObjectId());
|
||||
if (panel != null) {
|
||||
if (message.isUserMessage() && panel.getConnectedChat() != null) {
|
||||
panel.getConnectedChat().receiveMessage(message.getUsername(), message.getMessage(), message.getTime(), ChatMessage.MessageColor.BLACK);
|
||||
|
@ -111,31 +111,31 @@ public class Client implements CallbackClient {
|
|||
}
|
||||
}
|
||||
else if (callback.getMethod().equals("replayInit")) {
|
||||
GamePanel panel = session.getGame(callback.getObjectId());
|
||||
GamePanel panel = frame.getGame(callback.getObjectId());
|
||||
if (panel != null)
|
||||
panel.init((GameView) callback.getData());
|
||||
}
|
||||
else if (callback.getMethod().equals("replayDone")) {
|
||||
GamePanel panel = session.getGame(callback.getObjectId());
|
||||
GamePanel panel = frame.getGame(callback.getObjectId());
|
||||
if (panel != null) {
|
||||
panel.modalMessage((String) callback.getData());
|
||||
panel.hideGame();
|
||||
}
|
||||
}
|
||||
else if (callback.getMethod().equals("replayUpdate")) {
|
||||
GamePanel panel = session.getGame(callback.getObjectId());
|
||||
GamePanel panel = frame.getGame(callback.getObjectId());
|
||||
if (panel != null)
|
||||
panel.updateGame((GameView) callback.getData());
|
||||
}
|
||||
else if (callback.getMethod().equals("gameInit")) {
|
||||
GamePanel panel = session.getGame(callback.getObjectId());
|
||||
GamePanel panel = frame.getGame(callback.getObjectId());
|
||||
if (panel != null) {
|
||||
panel.init((GameView) callback.getData());
|
||||
session.ack("gameInit");
|
||||
|
||||
}
|
||||
}
|
||||
else if (callback.getMethod().equals("gameOver")) {
|
||||
GamePanel panel = session.getGame(callback.getObjectId());
|
||||
GamePanel panel = frame.getGame(callback.getObjectId());
|
||||
if (panel != null) {
|
||||
panel.modalMessage((String) callback.getData());
|
||||
panel.hideGame();
|
||||
|
@ -143,53 +143,53 @@ public class Client implements CallbackClient {
|
|||
}
|
||||
else if (callback.getMethod().equals("gameAsk")) {
|
||||
GameClientMessage message = (GameClientMessage) callback.getData();
|
||||
GamePanel panel = session.getGame(callback.getObjectId());
|
||||
GamePanel panel = frame.getGame(callback.getObjectId());
|
||||
if (panel != null)
|
||||
panel.ask(message.getMessage(), message.getGameView());
|
||||
}
|
||||
else if (callback.getMethod().equals("gameTarget")) {
|
||||
GameClientMessage message = (GameClientMessage) callback.getData();
|
||||
GamePanel panel = session.getGame(callback.getObjectId());
|
||||
GamePanel panel = frame.getGame(callback.getObjectId());
|
||||
if (panel != null)
|
||||
panel.pickTarget(message.getMessage(), message.getCardsView(), message.getGameView(), message.getTargets(), message.isFlag(), message.getOptions());
|
||||
}
|
||||
else if (callback.getMethod().equals("gameSelect")) {
|
||||
GameClientMessage message = (GameClientMessage) callback.getData();
|
||||
GamePanel panel = session.getGame(callback.getObjectId());
|
||||
GamePanel panel = frame.getGame(callback.getObjectId());
|
||||
if (panel != null)
|
||||
panel.select(message.getMessage(), message.getGameView());
|
||||
}
|
||||
else if (callback.getMethod().equals("gameChooseAbility")) {
|
||||
GamePanel panel = session.getGame(callback.getObjectId());
|
||||
GamePanel panel = frame.getGame(callback.getObjectId());
|
||||
if (panel != null)
|
||||
panel.pickAbility((AbilityPickerView) callback.getData());
|
||||
}
|
||||
else if (callback.getMethod().equals("gameChoose")) {
|
||||
GameClientMessage message = (GameClientMessage) callback.getData();
|
||||
GamePanel panel = session.getGame(callback.getObjectId());
|
||||
GamePanel panel = frame.getGame(callback.getObjectId());
|
||||
if (panel != null)
|
||||
panel.getChoice(message.getMessage(), message.getStrings());
|
||||
}
|
||||
else if (callback.getMethod().equals("gamePlayMana")) {
|
||||
GameClientMessage message = (GameClientMessage) callback.getData();
|
||||
GamePanel panel = session.getGame(callback.getObjectId());
|
||||
GamePanel panel = frame.getGame(callback.getObjectId());
|
||||
if (panel != null)
|
||||
panel.playMana(message.getMessage(), message.getGameView());
|
||||
}
|
||||
else if (callback.getMethod().equals("gamePlayXMana")) {
|
||||
GameClientMessage message = (GameClientMessage) callback.getData();
|
||||
GamePanel panel = session.getGame(callback.getObjectId());
|
||||
GamePanel panel = frame.getGame(callback.getObjectId());
|
||||
if (panel != null)
|
||||
panel.playXMana(message.getMessage(), message.getGameView());
|
||||
}
|
||||
else if (callback.getMethod().equals("gameSelectAmount")) {
|
||||
GameClientMessage message = (GameClientMessage) callback.getData();
|
||||
GamePanel panel = session.getGame(callback.getObjectId());
|
||||
GamePanel panel = frame.getGame(callback.getObjectId());
|
||||
if (panel != null)
|
||||
panel.getAmount(message.getMin(), message.getMax(), message.getMessage());
|
||||
}
|
||||
else if (callback.getMethod().equals("gameUpdate")) {
|
||||
GamePanel panel = session.getGame(callback.getObjectId());
|
||||
GamePanel panel = frame.getGame(callback.getObjectId());
|
||||
if (panel != null)
|
||||
panel.updateGame((GameView) callback.getData());
|
||||
}
|
||||
|
@ -197,7 +197,7 @@ public class Client implements CallbackClient {
|
|||
|
||||
if (callback.getMessageId() > messageId) {
|
||||
GameClientMessage message = (GameClientMessage) callback.getData();
|
||||
GamePanel panel = session.getGame(callback.getObjectId());
|
||||
GamePanel panel = frame.getGame(callback.getObjectId());
|
||||
if (panel != null)
|
||||
panel.inform(message.getMessage(), message.getGameView());
|
||||
}
|
||||
|
@ -214,18 +214,18 @@ public class Client implements CallbackClient {
|
|||
construct(message.getDeck(), message.getTableId(), message.getTime());
|
||||
}
|
||||
else if (callback.getMethod().equals("draftOver")) {
|
||||
DraftPanel panel = session.getDraft(callback.getObjectId());
|
||||
DraftPanel panel = frame.getDraft(callback.getObjectId());
|
||||
if (panel != null)
|
||||
panel.hideDraft();
|
||||
}
|
||||
else if (callback.getMethod().equals("draftPick")) {
|
||||
DraftClientMessage message = (DraftClientMessage) callback.getData();
|
||||
DraftPanel panel = session.getDraft(callback.getObjectId());
|
||||
DraftPanel panel = frame.getDraft(callback.getObjectId());
|
||||
if (panel != null)
|
||||
panel.loadBooster(message.getDraftPickView());
|
||||
}
|
||||
else if (callback.getMethod().equals("draftUpdate")) {
|
||||
DraftPanel panel = session.getDraft(callback.getObjectId());
|
||||
DraftPanel panel = frame.getDraft(callback.getObjectId());
|
||||
if (panel != null)
|
||||
panel.updateDraft((DraftView) callback.getData());
|
||||
}
|
||||
|
@ -238,10 +238,10 @@ public class Client implements CallbackClient {
|
|||
}
|
||||
}
|
||||
else if (callback.getMethod().equals("draftInit")) {
|
||||
session.ack("draftInit");
|
||||
|
||||
}
|
||||
else if (callback.getMethod().equals("tournamentInit")) {
|
||||
session.ack("tournamentInit");
|
||||
|
||||
}
|
||||
messageId = callback.getMessageId();
|
||||
}
|
||||
|
@ -252,7 +252,7 @@ public class Client implements CallbackClient {
|
|||
});
|
||||
}
|
||||
|
||||
public UUID getId() throws RemoteException {
|
||||
public UUID getId() {
|
||||
return clientId;
|
||||
}
|
||||
|
||||
|
@ -320,9 +320,7 @@ public class Client implements CallbackClient {
|
|||
|
||||
private void handleException(Exception ex) {
|
||||
logger.fatal("Client error\n", ex);
|
||||
JOptionPane.showMessageDialog(MageFrame.getDesktop(), "Unrecoverable client error. Disconnecting", "Error", JOptionPane.ERROR_MESSAGE);
|
||||
session.disconnect();
|
||||
frame.disableButtons();
|
||||
frame.showError("Error: " + ex.getMessage());
|
||||
}
|
||||
|
||||
}
|
|
@ -41,7 +41,7 @@ import java.util.UUID;
|
|||
import javax.swing.DefaultComboBoxModel;
|
||||
|
||||
import mage.client.MageFrame;
|
||||
import mage.client.remote.Session;
|
||||
import mage.remote.Session;
|
||||
import mage.client.util.Config;
|
||||
import mage.client.util.Event;
|
||||
import mage.client.util.Listener;
|
||||
|
|
|
@ -43,8 +43,8 @@ import mage.client.dialog.JoinTableDialog;
|
|||
import mage.client.dialog.NewTableDialog;
|
||||
import mage.client.dialog.NewTournamentDialog;
|
||||
import mage.client.dialog.TableWaitingDialog;
|
||||
import mage.client.remote.MageRemoteException;
|
||||
import mage.client.remote.Session;
|
||||
import mage.remote.MageRemoteException;
|
||||
import mage.remote.Session;
|
||||
import mage.client.util.ButtonColumn;
|
||||
import mage.game.match.MatchOptions;
|
||||
import mage.sets.Sets;
|
||||
|
|
|
@ -38,7 +38,7 @@ import java.util.UUID;
|
|||
import javax.swing.DefaultComboBoxModel;
|
||||
import javax.swing.JComboBox;
|
||||
import mage.client.MageFrame;
|
||||
import mage.client.remote.Session;
|
||||
import mage.remote.Session;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
|
@ -36,20 +36,15 @@ package mage.client.tournament;
|
|||
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Observable;
|
||||
import java.util.Observer;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CancellationException;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import javax.swing.*;
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
import mage.client.MageFrame;
|
||||
import mage.client.remote.MageRemoteException;
|
||||
import mage.client.remote.Session;
|
||||
import mage.remote.Session;
|
||||
import mage.client.util.ButtonColumn;
|
||||
import mage.view.RoundView;
|
||||
import mage.view.TournamentGameView;
|
||||
|
@ -104,7 +99,7 @@ public class TournamentPanel extends javax.swing.JPanel {
|
|||
public synchronized void showTournament(UUID tournamentId) {
|
||||
this.tournamentId = tournamentId;
|
||||
session = MageFrame.getSession();
|
||||
session.addTournament(tournamentId, this);
|
||||
MageFrame.addTournament(tournamentId, this);
|
||||
UUID chatRoomId = session.getTournamentChatId(tournamentId);
|
||||
if (session.joinTournament(tournamentId) && chatRoomId != null) {
|
||||
this.chatPanel1.connect(chatRoomId);
|
||||
|
|
|
@ -3,7 +3,7 @@ package mage.client.util;
|
|||
import java.awt.event.MouseEvent;
|
||||
import java.util.UUID;
|
||||
|
||||
import mage.client.remote.Session;
|
||||
import mage.remote.Session;
|
||||
import mage.view.CardView;
|
||||
|
||||
|
||||
|
|
48
Mage.Common/src/mage/interfaces/MageClient.java
Normal file
48
Mage.Common/src/mage/interfaces/MageClient.java
Normal file
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.interfaces;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.interfaces.callback.CallbackClient;
|
||||
import mage.utils.MageVersion;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public interface MageClient extends CallbackClient {
|
||||
|
||||
public UUID getId();
|
||||
public MageVersion getVersion();
|
||||
public void connected(String message);
|
||||
public void disconnected();
|
||||
public void showMessage(String message);
|
||||
public void showError(String message);
|
||||
|
||||
}
|
|
@ -26,7 +26,11 @@
|
|||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.utils;
|
||||
package mage.remote;
|
||||
|
||||
import java.rmi.registry.LocateRegistry;
|
||||
import java.rmi.registry.Registry;
|
||||
import mage.interfaces.Server;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -44,6 +48,39 @@ public class Connection {
|
|||
private String proxyUsername;
|
||||
private String proxyPassword;
|
||||
|
||||
// protected Server getServer() {
|
||||
// Server server = null;
|
||||
// try {
|
||||
// Registry reg = LocateRegistry.getRegistry(host, port);
|
||||
// server = (Server) reg.lookup("mage-server");
|
||||
// }
|
||||
// catch (Exception ignored) {}
|
||||
// return server;
|
||||
// }
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return (host + Integer.toString(port) + proxyType.toString()).hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
if (! (object instanceof Connection)) {
|
||||
return false;
|
||||
}
|
||||
Connection otherConnection = (Connection) object;
|
||||
return hashCode() == otherConnection.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return host + ":" + Integer.toString(port);
|
||||
}
|
||||
|
||||
public String getURI() {
|
||||
return "bisocket://" + host + ":" + port;
|
||||
}
|
||||
|
||||
public ProxyType getProxyType() {
|
||||
return proxyType;
|
||||
}
|
|
@ -26,7 +26,7 @@
|
|||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.client.remote;
|
||||
package mage.remote;
|
||||
|
||||
/**
|
||||
*
|
|
@ -26,7 +26,7 @@
|
|||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.client.remote;
|
||||
package mage.remote;
|
||||
|
||||
import java.net.Authenticator;
|
||||
import java.net.PasswordAuthentication;
|
||||
|
@ -35,32 +35,23 @@ import java.rmi.RemoteException;
|
|||
import java.rmi.registry.LocateRegistry;
|
||||
import java.rmi.registry.Registry;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
import javax.swing.JOptionPane;
|
||||
import mage.cards.decks.DeckCardLists;
|
||||
import mage.client.MageFrame;
|
||||
import mage.client.chat.ChatPanel;
|
||||
import mage.client.components.MageUI;
|
||||
import mage.client.draft.DraftPanel;
|
||||
import mage.client.game.GamePanel;
|
||||
import mage.client.tournament.TournamentPanel;
|
||||
import mage.client.util.Config;
|
||||
import mage.game.GameException;
|
||||
import mage.MageException;
|
||||
import mage.constants.Constants.SessionState;
|
||||
import mage.game.match.MatchOptions;
|
||||
import mage.game.tournament.TournamentOptions;
|
||||
import mage.interfaces.MageClient;
|
||||
import mage.interfaces.Server;
|
||||
import mage.interfaces.ServerState;
|
||||
import mage.interfaces.callback.CallbackClientDaemon;
|
||||
import mage.utils.Connection;
|
||||
import mage.view.DraftPickView;
|
||||
import mage.view.GameTypeView;
|
||||
import mage.view.TableView;
|
||||
|
@ -79,17 +70,15 @@ public class Session {
|
|||
|
||||
private UUID sessionId;
|
||||
private Server server;
|
||||
private Client client;
|
||||
private MageClient client;
|
||||
private String userName;
|
||||
private MageFrame frame;
|
||||
private ServerState serverState;
|
||||
private Map<UUID, ChatPanel> chats = new HashMap<UUID, ChatPanel>();
|
||||
private Map<UUID, GamePanel> games = new HashMap<UUID, GamePanel>();
|
||||
private Map<UUID, DraftPanel> drafts = new HashMap<UUID, DraftPanel>();
|
||||
private Map<UUID, TournamentPanel> tournaments = new HashMap<UUID, TournamentPanel>();
|
||||
private SessionState sessionState = SessionState.DISCONNECTED;
|
||||
private CallbackClientDaemon callbackDaemon;
|
||||
private ScheduledFuture<?> future;
|
||||
private MageUI ui = new MageUI();
|
||||
private Connection connection;
|
||||
private boolean reconnecting = false;
|
||||
private boolean connecting = false;
|
||||
|
||||
/**
|
||||
* For locking session object.
|
||||
|
@ -97,17 +86,23 @@ public class Session {
|
|||
* there shouldn't be any penalty for synchronization.
|
||||
*
|
||||
* @author nantuko
|
||||
*/
|
||||
*/
|
||||
private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
|
||||
|
||||
public Session(MageFrame frame) {
|
||||
this.frame = frame;
|
||||
public Session(MageClient client) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
public boolean connect(Connection connection) {
|
||||
public synchronized boolean connect(Connection connection) {
|
||||
this.connecting = true;
|
||||
if (isConnected()) {
|
||||
disconnect();
|
||||
disconnect(true);
|
||||
}
|
||||
this.connection = connection;
|
||||
return connect();
|
||||
}
|
||||
|
||||
public boolean connect() {
|
||||
try {
|
||||
System.setSecurityManager(null);
|
||||
System.setProperty("http.nonProxyHosts", "code.google.com");
|
||||
|
@ -131,80 +126,54 @@ public class Session {
|
|||
break;
|
||||
}
|
||||
Registry reg = LocateRegistry.getRegistry(connection.getHost(), connection.getPort());
|
||||
this.server = (Server) reg.lookup(Config.remoteServer);
|
||||
this.server = (Server) reg.lookup("mage-server");
|
||||
this.userName = connection.getUsername();
|
||||
if (client == null)
|
||||
client = new Client(this, frame);
|
||||
sessionId = server.registerClient(userName, client.getId(), frame.getVersion());
|
||||
sessionId = server.registerClient(userName, client.getId(), client.getVersion());
|
||||
callbackDaemon = new CallbackClientDaemon(sessionId, client, server);
|
||||
serverState = server.getServerState();
|
||||
future = sessionExecutor.scheduleWithFixedDelay(new ServerPinger(), 5, 5, TimeUnit.SECONDS);
|
||||
logger.info("Connected to RMI server at " + connection.getHost() + ":" + connection.getPort());
|
||||
frame.setStatusText("Connected to " + connection.getHost() + ":" + connection.getPort() + " ");
|
||||
frame.enableButtons();
|
||||
client.connected("Connected to " + connection.getHost() + ":" + connection.getPort() + " ");
|
||||
reconnecting = false;
|
||||
connecting = false;
|
||||
return true;
|
||||
} catch (MageException ex) {
|
||||
logger.fatal("", ex);
|
||||
disconnect();
|
||||
JOptionPane.showMessageDialog(frame, "Unable to connect to server. " + ex.getMessage());
|
||||
if (!reconnecting) {
|
||||
disconnect(false);
|
||||
client.showMessage("Unable to connect to server. " + ex.getMessage());
|
||||
}
|
||||
} catch (RemoteException ex) {
|
||||
logger.fatal("Unable to connect to server - ", ex);
|
||||
disconnect();
|
||||
JOptionPane.showMessageDialog(frame, "Unable to connect to server. " + ex.getMessage());
|
||||
if (!reconnecting) {
|
||||
disconnect(false);
|
||||
client.showMessage("Unable to connect to server. " + ex.getMessage());
|
||||
}
|
||||
} catch (NotBoundException ex) {
|
||||
logger.fatal("Unable to connect to server - ", ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void disconnect() {
|
||||
|
||||
if (isConnected()) {
|
||||
try {
|
||||
for (UUID chatId: chats.keySet()) {
|
||||
server.leaveChat(chatId, sessionId);
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
//swallow all exceptions at this point
|
||||
}
|
||||
try {
|
||||
//TODO: stop daemon
|
||||
if (server != null)
|
||||
server.deregisterClient(sessionId);
|
||||
} catch (RemoteException ex) {
|
||||
logger.fatal("Error disconnecting ...", ex);
|
||||
} catch (MageException ex) {
|
||||
logger.fatal("Error disconnecting ...", ex);
|
||||
}
|
||||
removeServer();
|
||||
}
|
||||
}
|
||||
|
||||
private void removeServer() {
|
||||
if (future != null && !future.isDone())
|
||||
future.cancel(true);
|
||||
lock.writeLock().lock();
|
||||
try {
|
||||
server = null;
|
||||
} finally {
|
||||
lock.writeLock().unlock();
|
||||
}
|
||||
frame.hideGames();
|
||||
frame.hideTables();
|
||||
frame.setStatusText("Not connected");
|
||||
frame.disableButtons();
|
||||
logger.info("Disconnected ... ");
|
||||
JOptionPane.showMessageDialog(MageFrame.getDesktop(), "Disconnected.", "Disconnected", JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
|
||||
public void ack(String message) {
|
||||
try {
|
||||
server.ack(message, sessionId);
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
public synchronized void disconnect(boolean showMessage) {
|
||||
if (sessionState == SessionState.CONNECTED)
|
||||
sessionState = SessionState.DISCONNECTING;
|
||||
if (connection == null)
|
||||
return;
|
||||
if (sessionState == SessionState.CONNECTED) {
|
||||
try {
|
||||
server.deregisterClient(sessionId);
|
||||
} catch (Exception ex) {
|
||||
logger.fatal("Error disconnecting ...", ex);
|
||||
}
|
||||
}
|
||||
client.disconnected();
|
||||
logger.info("Disconnected ... ");
|
||||
if (sessionState == SessionState.SERVER_UNAVAILABLE && showMessage) {
|
||||
client.showError("Server error. You have been disconnected");
|
||||
}
|
||||
else {
|
||||
sessionState = SessionState.DISCONNECTED;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -220,7 +189,7 @@ public class Session {
|
|||
}
|
||||
|
||||
public boolean isConnected() {
|
||||
return server != null;
|
||||
return sessionState == SessionState.CONNECTED;
|
||||
}
|
||||
|
||||
public String[] getPlayerTypes() {
|
||||
|
@ -245,30 +214,6 @@ public class Session {
|
|||
return false;
|
||||
}
|
||||
|
||||
public ChatPanel getChat(UUID chatId) {
|
||||
return chats.get(chatId);
|
||||
}
|
||||
|
||||
public GamePanel getGame(UUID gameId) {
|
||||
return games.get(gameId);
|
||||
}
|
||||
|
||||
public void addGame(UUID gameId, GamePanel gamePanel) {
|
||||
games.put(gameId, gamePanel);
|
||||
}
|
||||
|
||||
public DraftPanel getDraft(UUID draftId) {
|
||||
return drafts.get(draftId);
|
||||
}
|
||||
|
||||
public void addDraft(UUID draftId, DraftPanel draftPanel) {
|
||||
drafts.put(draftId, draftPanel);
|
||||
}
|
||||
|
||||
public void addTournament(UUID tournamentId, TournamentPanel tournament) {
|
||||
tournaments.put(tournamentId, tournament);
|
||||
}
|
||||
|
||||
public UUID getMainRoomId() {
|
||||
try {
|
||||
return server.getMainRoomId();
|
||||
|
@ -475,10 +420,9 @@ public class Session {
|
|||
return null;
|
||||
}
|
||||
|
||||
public boolean joinChat(UUID chatId, ChatPanel chat) {
|
||||
public boolean joinChat(UUID chatId) {
|
||||
try {
|
||||
server.joinChat(chatId, sessionId, userName);
|
||||
chats.put(chatId, chat);
|
||||
return true;
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
|
@ -493,7 +437,6 @@ public class Session {
|
|||
try {
|
||||
if (server == null) return false;
|
||||
server.leaveChat(chatId, sessionId);
|
||||
chats.remove(chatId);
|
||||
return true;
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
|
@ -785,19 +728,17 @@ public class Session {
|
|||
|
||||
private void handleRemoteException(RemoteException ex) {
|
||||
logger.fatal("Communication error", ex);
|
||||
JOptionPane.showMessageDialog(MageFrame.getDesktop(), "Critical server error. Disconnecting", "Error", JOptionPane.ERROR_MESSAGE);
|
||||
disconnect();
|
||||
disconnect(false);
|
||||
}
|
||||
|
||||
private void handleMageException(MageException ex) {
|
||||
logger.fatal("Server error", ex);
|
||||
JOptionPane.showMessageDialog(MageFrame.getDesktop(), "Critical server error. Disconnecting", "Error", JOptionPane.ERROR_MESSAGE);
|
||||
disconnect();
|
||||
disconnect(false);
|
||||
}
|
||||
|
||||
private void handleGameException(GameException ex) {
|
||||
logger.warn(ex.getMessage());
|
||||
JOptionPane.showMessageDialog(MageFrame.getDesktop(), ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
|
||||
client.showError(ex.getMessage());
|
||||
}
|
||||
|
||||
|
||||
|
@ -805,14 +746,6 @@ public class Session {
|
|||
return userName;
|
||||
}
|
||||
|
||||
public MageUI getUI() {
|
||||
return ui;
|
||||
}
|
||||
|
||||
public Server getServerRef() {
|
||||
return server;
|
||||
}
|
||||
|
||||
class ServerPinger implements Runnable {
|
||||
|
||||
private int missed = 0;
|
||||
|
@ -823,7 +756,7 @@ public class Session {
|
|||
missed++;
|
||||
if (missed > 10) {
|
||||
logger.info("Connection to server timed out");
|
||||
removeServer();
|
||||
disconnect(true);
|
||||
}
|
||||
}
|
||||
else {
|
Binary file not shown.
Binary file not shown.
Loading…
Add table
Reference in a new issue