From 14de10fd72f52df1aa2bae9b7143ac2ad005e7b7 Mon Sep 17 00:00:00 2001 From: BetaSteward Date: Sat, 27 Mar 2010 02:19:06 +0000 Subject: [PATCH] ... --- Mage.Client/release/license.txt | 25 +++ Mage.Client/release/readme.txt | 24 ++- Mage.Client/src/mage/client/MageFrame.java | 3 +- Mage.Client/src/mage/client/cards/Card.java | 28 +-- .../src/mage/client/chat/ChatClientImpl.java | 114 ++++++------ .../src/mage/client/chat/ChatPanel.form | 10 +- .../src/mage/client/chat/ChatPanel.java | 20 +-- .../mage/client/deckeditor/CardSelector.java | 9 +- .../client/deckeditor/DeckEditorPanel.java | 24 ++- .../src/mage/client/dialog/AboutDialog.form | 17 +- .../src/mage/client/dialog/AboutDialog.java | 14 +- .../src/mage/client/dialog/ConnectDialog.form | 5 +- .../src/mage/client/dialog/ConnectDialog.java | 39 +++- .../src/mage/client/dialog/MageDialog.java | 2 +- .../src/mage/client/game/AbilityPicker.java | 21 ++- .../src/mage/client/game/FeedbackPanel.java | 2 +- .../src/mage/client/game/GamePanel.java | 22 +-- .../src/mage/client/remote/Client.java | 166 ++++++++++++++++++ .../src/mage/client/remote/ClientImpl.java | 97 ---------- .../mage/client/remote/GameClientImpl.java | 151 ---------------- .../client/remote/GameReplayClientImpl.java | 87 --------- .../src/mage/client/remote/Session.java | 61 +++++-- .../mage/client/util/EDTExceptionHandler.java | 58 ++++++ 23 files changed, 498 insertions(+), 501 deletions(-) create mode 100644 Mage.Client/release/license.txt create mode 100644 Mage.Client/src/mage/client/remote/Client.java delete mode 100644 Mage.Client/src/mage/client/remote/ClientImpl.java delete mode 100644 Mage.Client/src/mage/client/remote/GameClientImpl.java delete mode 100644 Mage.Client/src/mage/client/remote/GameReplayClientImpl.java create mode 100644 Mage.Client/src/mage/client/util/EDTExceptionHandler.java diff --git a/Mage.Client/release/license.txt b/Mage.Client/release/license.txt new file mode 100644 index 00000000000..dc1ab47fb13 --- /dev/null +++ b/Mage.Client/release/license.txt @@ -0,0 +1,25 @@ +Copyright 2010 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. \ No newline at end of file diff --git a/Mage.Client/release/readme.txt b/Mage.Client/release/readme.txt index ab490ee6eff..c7446f67aff 100644 --- a/Mage.Client/release/readme.txt +++ b/Mage.Client/release/readme.txt @@ -8,6 +8,7 @@ You will need to have the Java Runtime Environment Version 6 Update 10 or greate You can download this from: http://java.com/ ----------------------------------------------------------------------------------- +Installing and running MAGE You will need to download both the client and the server applications. These can be obtained from http://code.google.com/p/magic--another-game-engine/downloads/list. @@ -23,17 +24,34 @@ To launch the client run the startClient.bat command. Click on the connect butt the toolbar and enter the server name/IP address and port. Then click on the tables button. This will bring up a list of active and completed games. Click on join to join an existing game that hasn't started yet or you can create a new table by -clicking the new button. +clicking the New button. ----------------------------------------------------------------------------------- +Playing a game -The client useage should be fairly self evident. Click on cards in your hand to +Playing a game should be fairly self evident. Your hand is displayed at the bottom +of the screen. The battlefield is the central area. Click on cards in your hand to play them. Click on cards in the battlefield to activate abilities. A popup menu will be presented if you have more than one choice. To pass priority for the turn hold down the ctrl key while clicking done. You will still receive priority if -your opponent casts a spell or activates an ability. +your opponent casts a spell or activates an ability. Target cards by clicking on +them. To target a player click on the player name. You can see the cards in any +graveyard by clicking on the graveyard count. ----------------------------------------------------------------------------------- +Deck editor + +A simple deck editor is available by clicking on the Deck Editor button on the +toolbar. All the available cards are displayed in the top section. Your deck +and sideboard are displayed at the bottom. To add a card to your deck double +click on the card in the top section. To remove it from your deck double click +on the card in the deck area. The sideboard section is not ready yet (don't +worry it's coming soon). + +You can save or load a deck using the Save or Load buttons. + +----------------------------------------------------------------------------------- +Notes MAGE is still very much in the testing phase so there can be lots of bugs and/or missing functionality. Please be patient. If you notice anything or want to diff --git a/Mage.Client/src/mage/client/MageFrame.java b/Mage.Client/src/mage/client/MageFrame.java index 98acc6fde12..de84b19f80c 100644 --- a/Mage.Client/src/mage/client/MageFrame.java +++ b/Mage.Client/src/mage/client/MageFrame.java @@ -48,6 +48,7 @@ import mage.cards.decks.Deck; import mage.client.dialog.AboutDialog; import mage.client.dialog.ConnectDialog; import mage.client.remote.Session; +import mage.client.util.EDTExceptionHandler; import mage.util.Logging; /** @@ -75,6 +76,7 @@ public class MageFrame extends javax.swing.JFrame { /** Creates new form MageFrame */ public MageFrame() { + EDTExceptionHandler.registerExceptionHandler(); addWindowListener(new WindowAdapter() { @Override @@ -100,7 +102,6 @@ public class MageFrame extends javax.swing.JFrame { } public void showGame(UUID gameId, UUID playerId) { - logger.info("showing game"); this.tablesPane.hideTables(); this.tablesPane.setVisible(false); this.gamePane.setVisible(true); diff --git a/Mage.Client/src/mage/client/cards/Card.java b/Mage.Client/src/mage/client/cards/Card.java index 92b11074e0d..7d8c141dc0b 100644 --- a/Mage.Client/src/mage/client/cards/Card.java +++ b/Mage.Client/src/mage/client/cards/Card.java @@ -166,24 +166,17 @@ public class Card extends javax.swing.JPanel implements MouseMotionListener, Mou private String getText(String cardType) { StringBuilder sb = new StringBuilder(); - sb.append(card.getName()); - sb.append("\n"); + sb.append(card.getName()).append("\n"); if (card.getManaCost().size() > 0) { - sb.append(card.getManaCost()); - sb.append("\n"); + sb.append(card.getManaCost()).append("\n"); } - sb.append(cardType); - sb.append("\n"); - sb.append(card.getColor().toString()); - sb.append("\n"); + sb.append(cardType).append("\n"); + sb.append(card.getColor().toString()).append("\n"); for (String rule: card.getRules()) { - sb.append(rule); - sb.append("\n"); + sb.append(rule).append("\n"); } if (card.getCardTypes().contains(CardType.CREATURE)) { - sb.append(card.getPower()); - sb.append("/"); - sb.append(card.getToughness()); + sb.append(card.getPower()).append("/").append(card.getToughness()); } else if (card.getCardTypes().contains(CardType.PLANESWALKER)) { sb.append(card.getLoyalty()); @@ -209,20 +202,17 @@ public class Card extends javax.swing.JPanel implements MouseMotionListener, Mou StringBuilder sbType = new StringBuilder(); for (String superType: card.getSuperTypes()) { - sbType.append(superType); - sbType.append(" "); + sbType.append(superType).append(" "); } for (mage.Constants.CardType cardType: card.getCardTypes()) { - sbType.append(cardType.toString()); - sbType.append(" "); + sbType.append(cardType.toString()).append(" "); } if (card.getSubTypes().size() > 0) { sbType.append("- "); for (String subType: card.getSubTypes()) { - sbType.append(subType); - sbType.append(" "); + sbType.append(subType).append(" "); } } diff --git a/Mage.Client/src/mage/client/chat/ChatClientImpl.java b/Mage.Client/src/mage/client/chat/ChatClientImpl.java index 3c79aa3b928..eb31f905695 100644 --- a/Mage.Client/src/mage/client/chat/ChatClientImpl.java +++ b/Mage.Client/src/mage/client/chat/ChatClientImpl.java @@ -26,60 +26,60 @@ * or implied, of BetaSteward_at_googlemail.com. */ -package mage.client.chat; - -import java.io.Serializable; -import java.rmi.RemoteException; -import java.rmi.server.UnicastRemoteObject; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.swing.JTextArea; -import mage.interfaces.ChatClient; -import mage.util.Logging; - - -/** - * - * @author BetaSteward_at_googlemail.com - */ -public class ChatClientImpl implements ChatClient, Serializable { - - private final static Logger logger = Logging.getLogger(ChatClientImpl.class.getName()); - - private JTextArea textArea; - private String userName; - private UUID clientId; - - public ChatClientImpl(String userName, JTextArea textArea) { - this.clientId = UUID.randomUUID(); - this.textArea = textArea; - try { - this.userName = userName; - UnicastRemoteObject.exportObject(this, 0); - } catch (RemoteException ex) { - logger.log(Level.SEVERE, null, ex); - } - } - - @Override - public void receiveMessage(String message) throws RemoteException { - this.textArea.append(message + "\n"); - textArea.setCaretPosition(textArea.getText().length() - 1); - } - - @Override - public String getName() throws RemoteException { - return userName; - } - - @Override - public UUID getId() throws RemoteException { - return clientId; - } - - public UUID getIdLocal() { - return clientId; - } - -} \ No newline at end of file +//package mage.client.chat; +// +//import java.io.Serializable; +//import java.rmi.RemoteException; +//import java.rmi.server.UnicastRemoteObject; +//import java.util.UUID; +//import java.util.logging.Level; +//import java.util.logging.Logger; +//import javax.swing.JTextArea; +//import mage.interfaces.ChatClient; +//import mage.util.Logging; +// +// +///** +// * +// * @author BetaSteward_at_googlemail.com +// */ +//public class ChatClientImpl implements ChatClient, Serializable { +// +// private final static Logger logger = Logging.getLogger(ChatClientImpl.class.getName()); +// +// private JTextArea textArea; +// private String userName; +// private UUID clientId; +// +// public ChatClientImpl(String userName, JTextArea textArea) { +// this.clientId = UUID.randomUUID(); +// this.textArea = textArea; +// try { +// this.userName = userName; +// UnicastRemoteObject.exportObject(this, 0); +// } catch (RemoteException ex) { +// logger.log(Level.SEVERE, null, ex); +// } +// } +// +// @Override +// public void receiveMessage(String message) throws RemoteException { +// this.textArea.append(message + "\n"); +// textArea.setCaretPosition(textArea.getText().length() - 1); +// } +// +// @Override +// public String getName() throws RemoteException { +// return userName; +// } +// +// @Override +// public UUID getId() throws RemoteException { +// return clientId; +// } +// +// public UUID getIdLocal() { +// return clientId; +// } +// +//} \ No newline at end of file diff --git a/Mage.Client/src/mage/client/chat/ChatPanel.form b/Mage.Client/src/mage/client/chat/ChatPanel.form index 9a980c0d2c1..83bebbdb942 100644 --- a/Mage.Client/src/mage/client/chat/ChatPanel.form +++ b/Mage.Client/src/mage/client/chat/ChatPanel.form @@ -16,16 +16,16 @@ - + - - - - + + + + diff --git a/Mage.Client/src/mage/client/chat/ChatPanel.java b/Mage.Client/src/mage/client/chat/ChatPanel.java index 4a14495ddbb..c4a400a741b 100644 --- a/Mage.Client/src/mage/client/chat/ChatPanel.java +++ b/Mage.Client/src/mage/client/chat/ChatPanel.java @@ -39,7 +39,6 @@ import java.util.UUID; import java.util.logging.Logger; import mage.client.MageFrame; import mage.client.remote.Session; -import mage.interfaces.ChatClient; import mage.util.Logging; /** * @@ -51,7 +50,6 @@ public class ChatPanel extends javax.swing.JPanel { private UUID chatId; private UUID clientId; - private ChatClient client; private Session session; @@ -63,16 +61,18 @@ public class ChatPanel extends javax.swing.JPanel { public void connect(UUID chatId) { session = MageFrame.getSession(); this.chatId = chatId; - client = new ChatClientImpl(session.getUserName(), this.txtConversation); - clientId = ((ChatClientImpl)client).getIdLocal(); - session.joinChat(chatId, client); + session.joinChat(chatId, this); } public void disconnect() { if (session.isConnected()) - session.leaveChat(chatId, clientId); + session.leaveChat(chatId); } + public void receiveMessage(String message) { + this.txtConversation.append(message + "\n"); + txtConversation.setCaretPosition(txtConversation.getText().length() - 1); + } /** This method is called from within the constructor to * initialize the form. @@ -105,15 +105,15 @@ public class ChatPanel extends javax.swing.JPanel { this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 179, Short.MAX_VALUE) .addComponent(txtMessage, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 179, Short.MAX_VALUE) + .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 179, Short.MAX_VALUE) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 305, Short.MAX_VALUE) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE) .addGap(0, 0, 0) - .addComponent(txtMessage, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addComponent(txtMessage, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)) ); }// //GEN-END:initComponents diff --git a/Mage.Client/src/mage/client/deckeditor/CardSelector.java b/Mage.Client/src/mage/client/deckeditor/CardSelector.java index db01019ff1a..dff0aa23954 100644 --- a/Mage.Client/src/mage/client/deckeditor/CardSelector.java +++ b/Mage.Client/src/mage/client/deckeditor/CardSelector.java @@ -34,6 +34,7 @@ package mage.client.deckeditor; +import java.awt.Cursor; import mage.Constants.Zone; import mage.cards.Cards; import mage.cards.CardsImpl; @@ -91,7 +92,13 @@ public class CardSelector extends javax.swing.JPanel { } private void filterCards() { - this.cardsList1.loadCards(new CardsView(cards.getCards(filter)), bigCard, null); + try { + setCursor(new Cursor(Cursor.WAIT_CURSOR)); + this.cardsList1.loadCards(new CardsView(cards.getCards(filter)), bigCard, null); + } + finally { + setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); + } } public CardsList getCardsList() { diff --git a/Mage.Client/src/mage/client/deckeditor/DeckEditorPanel.java b/Mage.Client/src/mage/client/deckeditor/DeckEditorPanel.java index 8f78b67b81e..8e99072e21a 100644 --- a/Mage.Client/src/mage/client/deckeditor/DeckEditorPanel.java +++ b/Mage.Client/src/mage/client/deckeditor/DeckEditorPanel.java @@ -34,9 +34,8 @@ package mage.client.deckeditor; +import java.awt.Cursor; import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; import java.lang.reflect.Constructor; import java.util.UUID; import java.util.logging.Level; @@ -95,15 +94,20 @@ public class DeckEditorPanel extends javax.swing.JPanel { } } ); - this.setVisible(true); this.repaint(); } private void refreshDeck() { - this.txtDeckName.setText(deck.getName()); - deckArea.getDeckList().loadCards(new CardsView(deck.getCards()), bigCard, null); - deckArea.getSideboardList().loadCards(new CardsView(deck.getSideboard()), bigCard, null); + try { + setCursor(new Cursor(Cursor.WAIT_CURSOR)); + this.txtDeckName.setText(deck.getName()); + deckArea.getDeckList().loadCards(new CardsView(deck.getCards()), bigCard, null); + deckArea.getSideboardList().loadCards(new CardsView(deck.getSideboard()), bigCard, null); + } + finally { + setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); + } } private Card createCard(Class clazz) { @@ -236,10 +240,14 @@ public class DeckEditorPanel extends javax.swing.JPanel { if (ret == JFileChooser.APPROVE_OPTION) { File file = fcSelectDeck.getSelectedFile(); try { + setCursor(new Cursor(Cursor.WAIT_CURSOR)); deck = Deck.load(DeckCardLists.load(file.getPath())); } catch (Exception ex) { Logger.getLogger(DeckEditorPanel.class.getName()).log(Level.SEVERE, null, ex); } + finally { + setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); + } refreshDeck(); } fcSelectDeck.setSelectedFile(null); @@ -251,10 +259,14 @@ public class DeckEditorPanel extends javax.swing.JPanel { if (ret == JFileChooser.APPROVE_OPTION) { File file = fcSelectDeck.getSelectedFile(); try { + setCursor(new Cursor(Cursor.WAIT_CURSOR)); deck.getDeckCardLists().save(file.getPath()); } catch (Exception ex) { Logger.getLogger(DeckEditorPanel.class.getName()).log(Level.SEVERE, null, ex); } + finally { + setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); + } } }//GEN-LAST:event_btnSaveActionPerformed diff --git a/Mage.Client/src/mage/client/dialog/AboutDialog.form b/Mage.Client/src/mage/client/dialog/AboutDialog.form index 44a286f0f37..37ee2566668 100644 --- a/Mage.Client/src/mage/client/dialog/AboutDialog.form +++ b/Mage.Client/src/mage/client/dialog/AboutDialog.form @@ -1,9 +1,6 @@ -
- - - + @@ -23,7 +20,7 @@ - + @@ -32,17 +29,17 @@ - + - + - + @@ -58,7 +55,7 @@ - + @@ -86,7 +83,7 @@ - + diff --git a/Mage.Client/src/mage/client/dialog/AboutDialog.java b/Mage.Client/src/mage/client/dialog/AboutDialog.java index efb969dc64b..c04aee5775a 100644 --- a/Mage.Client/src/mage/client/dialog/AboutDialog.java +++ b/Mage.Client/src/mage/client/dialog/AboutDialog.java @@ -66,8 +66,6 @@ public class AboutDialog extends MageDialog { jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); - setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); - btnOk.setText("OK"); btnOk.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { @@ -79,7 +77,7 @@ public class AboutDialog extends MageDialog { lblVersion.setText("version"); - jLabel2.setText("Courtesy: ForgottenBeta@gmail.com"); + jLabel2.setText("Courtesy: BetaSteward@googlemail.com"); jLabel3.setText("Thanks: KLo, Cosmo & Fritz"); @@ -88,7 +86,7 @@ public class AboutDialog extends MageDialog { layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addContainerGap(154, Short.MAX_VALUE) + .addContainerGap(159, Short.MAX_VALUE) .addComponent(btnOk) .addContainerGap()) .addGroup(layout.createSequentialGroup() @@ -96,15 +94,15 @@ public class AboutDialog extends MageDialog { .addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(lblVersion) - .addContainerGap(104, Short.MAX_VALUE)) + .addContainerGap(109, Short.MAX_VALUE)) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jLabel2) - .addContainerGap(23, Short.MAX_VALUE)) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jLabel3) - .addContainerGap(70, Short.MAX_VALUE)) + .addContainerGap(75, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) @@ -117,7 +115,7 @@ public class AboutDialog extends MageDialog { .addComponent(jLabel2) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel3) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 15, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 19, Short.MAX_VALUE) .addComponent(btnOk) .addContainerGap()) ); diff --git a/Mage.Client/src/mage/client/dialog/ConnectDialog.form b/Mage.Client/src/mage/client/dialog/ConnectDialog.form index c62be0b92ea..7352893398b 100644 --- a/Mage.Client/src/mage/client/dialog/ConnectDialog.form +++ b/Mage.Client/src/mage/client/dialog/ConnectDialog.form @@ -66,7 +66,7 @@ - + @@ -101,9 +101,6 @@ - - - diff --git a/Mage.Client/src/mage/client/dialog/ConnectDialog.java b/Mage.Client/src/mage/client/dialog/ConnectDialog.java index 05ad14da293..ffdb7fc8a1d 100644 --- a/Mage.Client/src/mage/client/dialog/ConnectDialog.java +++ b/Mage.Client/src/mage/client/dialog/ConnectDialog.java @@ -34,10 +34,12 @@ package mage.client.dialog; +import java.awt.Cursor; import java.rmi.NotBoundException; import java.rmi.RemoteException; import java.util.logging.Level; import java.util.logging.Logger; +import java.util.prefs.Preferences; import javax.swing.JOptionPane; import mage.client.remote.Session; import mage.client.util.Config; @@ -51,16 +53,19 @@ public class ConnectDialog extends MageDialog { private final static Logger logger = Logging.getLogger(ConnectDialog.class.getName()); private Session session; + private Preferences prefs; /** Creates new form ConnectDialog */ public ConnectDialog(Session session) { this.session = session; + prefs = Preferences.userNodeForPackage(this.getClass()); initComponents(); } public void showDialog() { - this.txtServer.setText(Config.serverName); - this.txtPort.setText(Integer.toString(Config.port)); + this.txtServer.setText(prefs.get("serverAddress", Config.serverName)); + this.txtPort.setText(prefs.get("serverPort", Integer.toString(Config.port))); + this.txtUserName.setText(prefs.get("userName", "")); this.setModal(true); this.setVisible(true); } @@ -95,8 +100,6 @@ public class ConnectDialog extends MageDialog { } }); - txtUserName.setText("me"); - lblUserName.setLabelFor(txtUserName); lblUserName.setText("User Name:"); @@ -154,7 +157,7 @@ public class ConnectDialog extends MageDialog { .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(txtUserName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(lblUserName)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 35, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 43, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(btnCancel) .addComponent(btnConnect)) @@ -171,15 +174,41 @@ public class ConnectDialog extends MageDialog { private void btnConnectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnConnectActionPerformed try { + if (txtUserName.getText().isEmpty()) { + JOptionPane.showMessageDialog(rootPane, "Please provide a user name"); + return; + } + if (txtServer.getText().isEmpty()) { + JOptionPane.showMessageDialog(rootPane, "Please provide a server address"); + return; + } + if (txtPort.getText().isEmpty()) { + JOptionPane.showMessageDialog(rootPane, "Please provide a port number"); + return; + } + if (Integer.valueOf(txtPort.getText()) < 1 || Integer.valueOf(txtPort.getText()) > 65535 ) { + JOptionPane.showMessageDialog(rootPane, "Invalid port number"); + txtPort.setText(prefs.get("serverPort", Integer.toString(Config.port))); + return; + } + setCursor(new Cursor(Cursor.WAIT_CURSOR)); session.connect(txtUserName.getText(), txtServer.getText(), Integer.valueOf(txtPort.getText())); + prefs.put("serverAddress", txtServer.getText()); + prefs.put("serverPort", txtPort.getText()); + prefs.put("userName", txtUserName.getText()); this.setVisible(false); } catch (RemoteException ex) { + setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); logger.log(Level.SEVERE, "Unable to connect to server", ex); JOptionPane.showMessageDialog(rootPane, "Unable to connect to server"); } catch (NotBoundException ex) { + setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); logger.log(Level.SEVERE, "Unable to connect to server", ex); JOptionPane.showMessageDialog(rootPane, "Unable to connect to server"); } + finally { + setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); + } }//GEN-LAST:event_btnConnectActionPerformed private void keyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_keyTyped diff --git a/Mage.Client/src/mage/client/dialog/MageDialog.java b/Mage.Client/src/mage/client/dialog/MageDialog.java index 801a2836523..4f76ba5ed6f 100644 --- a/Mage.Client/src/mage/client/dialog/MageDialog.java +++ b/Mage.Client/src/mage/client/dialog/MageDialog.java @@ -122,7 +122,7 @@ public class MageDialog extends javax.swing.JInternalFrame { } else if (source instanceof MenuComponent) { ((MenuComponent) source).dispatchEvent(event); } else { - logger.info("Unable to dispatch: " + event); + logger.warning("Unable to dispatch: " + event); } } } diff --git a/Mage.Client/src/mage/client/game/AbilityPicker.java b/Mage.Client/src/mage/client/game/AbilityPicker.java index a4e3617eb60..b19a456cefa 100644 --- a/Mage.Client/src/mage/client/game/AbilityPicker.java +++ b/Mage.Client/src/mage/client/game/AbilityPicker.java @@ -35,6 +35,9 @@ import java.util.UUID; import javax.swing.AbstractAction; import javax.swing.Action; 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.view.AbilityPickerView; @@ -42,12 +45,13 @@ import mage.view.AbilityPickerView; * * @author BetaSteward_at_googlemail.com */ -public class AbilityPicker extends JPopupMenu { +public class AbilityPicker extends JPopupMenu implements PopupMenuListener { private Session session; private UUID gameId; public AbilityPicker() { + this.addPopupMenuListener(this); } public void init(Session session, UUID gameId) { @@ -60,8 +64,19 @@ public class AbilityPicker extends JPopupMenu { for (Entry choice: choices.getChoices().entrySet()) { this.add(new AbilityPickerAction(choice.getKey(), choice.getValue())); } - this.setLocation(p); - this.setVisible(true); +// this.setLocation(p); + this.show(MageFrame.getDesktop(), p.x, p.y); + } + + @Override + public void popupMenuWillBecomeVisible(PopupMenuEvent e) { } + + @Override + public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { } + + @Override + public void popupMenuCanceled(PopupMenuEvent e) { + session.sendPlayerBoolean(gameId, false); } private class AbilityPickerAction extends AbstractAction { diff --git a/Mage.Client/src/mage/client/game/FeedbackPanel.java b/Mage.Client/src/mage/client/game/FeedbackPanel.java index a3d2e5901ca..c96a18aad04 100644 --- a/Mage.Client/src/mage/client/game/FeedbackPanel.java +++ b/Mage.Client/src/mage/client/game/FeedbackPanel.java @@ -145,7 +145,7 @@ public class FeedbackPanel extends javax.swing.JPanel { } else if (source instanceof MenuComponent) { ((MenuComponent) source).dispatchEvent(event); } else { - logger.info("Unable to dispatch: " + event); + logger.warning("Unable to dispatch: " + event); } } } diff --git a/Mage.Client/src/mage/client/game/GamePanel.java b/Mage.Client/src/mage/client/game/GamePanel.java index f1d6d1aea9e..9b93b97248a 100644 --- a/Mage.Client/src/mage/client/game/GamePanel.java +++ b/Mage.Client/src/mage/client/game/GamePanel.java @@ -51,11 +51,7 @@ import mage.client.dialog.PickChoiceDialog; import mage.client.dialog.PickNumberDialog; import mage.client.dialog.ShowCardsDialog; import mage.client.game.FeedbackPanel.FeedbackMode; -import mage.client.remote.GameClientImpl; -import mage.client.remote.GameReplayClientImpl; import mage.client.remote.Session; -import mage.interfaces.GameClient; -import mage.interfaces.GameReplayClient; import mage.util.Logging; import mage.view.AbilityPickerView; import mage.view.CardsView; @@ -74,8 +70,6 @@ public class GamePanel extends javax.swing.JPanel { private Map players = new HashMap(); private Map exiles = new HashMap(); private UUID gameId; - private GameClient gameClient; - private GameReplayClient replayClient; private Session session; private CombatDialog combat = new CombatDialog(); @@ -87,7 +81,7 @@ public class GamePanel extends javax.swing.JPanel { public void showGame(UUID gameId, UUID playerId) { this.gameId = gameId; session = MageFrame.getSession(); - gameClient = new GameClientImpl(this); + session.setGame(this); this.feedbackPanel.init(gameId); this.feedbackPanel.clear(); this.abilityPicker.init(session, gameId); @@ -96,13 +90,14 @@ public class GamePanel extends javax.swing.JPanel { this.btnStopWatching.setVisible(false); this.setVisible(true); this.chatPanel.connect(session.getGameChatId(gameId)); - if (!session.joinGame(gameId, gameClient)) + if (!session.joinGame(gameId)) hideGame(); } public void watchGame(UUID gameId) { this.gameId = gameId; - gameClient = new GameClientImpl(this); + session = MageFrame.getSession(); + session.setGame(this); this.feedbackPanel.init(gameId); this.feedbackPanel.clear(); this.btnConcede.setVisible(false); @@ -110,19 +105,20 @@ public class GamePanel extends javax.swing.JPanel { this.pnlReplay.setVisible(false); this.setVisible(true); this.chatPanel.connect(session.getGameChatId(gameId)); - if (!session.watchGame(gameId, gameClient)) + if (!session.watchGame(gameId)) hideGame(); } public void replayGame(UUID gameId) { this.gameId = gameId; - replayClient = new GameReplayClientImpl(this); + session = MageFrame.getSession(); + session.setGame(this); this.feedbackPanel.clear(); this.btnConcede.setVisible(false); this.btnStopWatching.setVisible(false); this.pnlReplay.setVisible(true); this.setVisible(true); - if (!session.replayGame(gameId, replayClient)) + if (!session.replayGame()) hideGame(); } @@ -537,7 +533,7 @@ public class GamePanel extends javax.swing.JPanel { private void btnStopWatchingActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnStopWatchingActionPerformed if (modalQuestion("Are you sure you want to stop watching?", "Stop watching") == JOptionPane.YES_OPTION) { - session.stopWatching(gameId, ((GameClientImpl)gameClient).getIdLocal()); + session.stopWatching(gameId); } }//GEN-LAST:event_btnStopWatchingActionPerformed diff --git a/Mage.Client/src/mage/client/remote/Client.java b/Mage.Client/src/mage/client/remote/Client.java new file mode 100644 index 00000000000..4346940a285 --- /dev/null +++ b/Mage.Client/src/mage/client/remote/Client.java @@ -0,0 +1,166 @@ +/* +* Copyright 2010 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.client.remote; + +import java.rmi.RemoteException; +import java.util.UUID; +import java.util.logging.Logger; +import mage.client.MageFrame; +import mage.interfaces.callback.CallbackClient; +import mage.interfaces.callback.ClientCallback; +import mage.util.Logging; +import mage.view.AbilityPickerView; +import mage.view.ChatMessage; +import mage.view.GameClientMessage; +import mage.view.GameView; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class Client implements CallbackClient { + + private final static Logger logger = Logging.getLogger(Client.class.getName()); + + private UUID clientId; + private String userName; + private MageFrame frame; + private Session session; + + public Client(Session session, MageFrame frame, String userName) { + + this.clientId = UUID.randomUUID(); + this.userName = userName; + this.frame = frame; + this.session = session; + + } + + @Override + public void processCallback(ClientCallback callback) { + if (callback.getMethod().equals("startGame")) { + UUID[] data = (UUID[]) callback.getData(); + gameStarted(data[0], data[1]); + } + else if (callback.getMethod().equals("replayGame")) { + replayGame((UUID) callback.getData()); + } + else if (callback.getMethod().equals("watchGame")) { + watchGame((UUID) callback.getData()); + } + else if (callback.getMethod().equals("chatMessage")) { + ChatMessage message = (ChatMessage) callback.getData(); + session.getChats().get(message.getChatId()).receiveMessage(message.getMessage()); + } + else if (callback.getMethod().equals("replayInit")) { + session.getGame().init((GameView) callback.getData()); + } + else if (callback.getMethod().equals("replayDone")) { + session.getGame().modalMessage((String) callback.getData()); + session.getGame().hideGame(); + } + else if (callback.getMethod().equals("replayUpdate")) { + session.getGame().updateGame((GameView) callback.getData()); + } + else if (callback.getMethod().equals("gameInit")) { + session.getGame().init((GameView) callback.getData()); + } + else if (callback.getMethod().equals("gameUpdate")) { + session.getGame().updateGame((GameView) callback.getData()); + } + else if (callback.getMethod().equals("gameInform")) { + GameClientMessage message = (GameClientMessage) callback.getData(); + session.getGame().inform(message.getMessage(), null, message.getGameView()); + } + else if (callback.getMethod().equals("gameOver")) { + session.getGame().modalMessage((String) callback.getData()); + session.getGame().hideGame(); + } + else if (callback.getMethod().equals("gameAsk")) { + GameClientMessage message = (GameClientMessage) callback.getData(); + session.getGame().updateGame(message.getGameView()); + session.getGame().ask(message.getMessage()); + } + else if (callback.getMethod().equals("gameTarget")) { + GameClientMessage message = (GameClientMessage) callback.getData(); + if (message.isFlag()) { + session.getGame().inform(message.getMessage(), message.getCardsView(), message.getGameView()); + } else { + session.getGame().cancel(message.getMessage(), message.getCardsView(), message.getGameView()); + } + } + else if (callback.getMethod().equals("gameSelect")) { + GameClientMessage message = (GameClientMessage) callback.getData(); + session.getGame().select(message.getMessage(), message.getGameView()); + } + else if (callback.getMethod().equals("gameChooseAbility")) { + session.getGame().pickAbility((AbilityPickerView) callback.getData()); + } + else if (callback.getMethod().equals("gameChoose")) { + GameClientMessage message = (GameClientMessage) callback.getData(); + session.getGame().getChoice(message.getMessage(), message.getStrings()); + } + else if (callback.getMethod().equals("gamePlayMana")) { + GameClientMessage message = (GameClientMessage) callback.getData(); + session.getGame().playMana(message.getMessage(), message.getGameView()); + } + else if (callback.getMethod().equals("gamePlayXMana")) { + GameClientMessage message = (GameClientMessage) callback.getData(); + session.getGame().playXMana(message.getMessage(), message.getGameView()); + } + else if (callback.getMethod().equals("gameSelectAmount")) { + GameClientMessage message = (GameClientMessage) callback.getData(); + session.getGame().getAmount(message.getMin(), message.getMax()); + } + else if (callback.getMethod().equals("gameReveal")) { + GameClientMessage message = (GameClientMessage) callback.getData(); + session.getGame().revealCards(message.getMessage(), message.getCardsView()); + } + } + + public UUID getId() throws RemoteException { + return clientId; + } + + protected void gameStarted(UUID gameId, UUID playerId) { + frame.showGame(gameId, playerId); + logger.info("Game " + gameId + " started for player " + playerId); + } + + protected void watchGame(UUID gameId) { + frame.watchGame(gameId); + logger.info("Watching game " + gameId); + } + + protected void replayGame(UUID gameId) { + frame.replayGame(gameId); + logger.info("Replaying game " + gameId); + } + +} diff --git a/Mage.Client/src/mage/client/remote/ClientImpl.java b/Mage.Client/src/mage/client/remote/ClientImpl.java deleted file mode 100644 index eb2cd31ef44..00000000000 --- a/Mage.Client/src/mage/client/remote/ClientImpl.java +++ /dev/null @@ -1,97 +0,0 @@ -/* -* Copyright 2010 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.client.remote; - -import java.io.Serializable; -import java.rmi.RemoteException; -import java.rmi.server.UnicastRemoteObject; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import mage.client.MageFrame; -import mage.interfaces.Client; -import mage.util.Logging; - -/** - * - * @author BetaSteward_at_googlemail.com - */ -public class ClientImpl implements Client, Serializable { - - private final static Logger logger = Logging.getLogger(ClientImpl.class.getName()); - - private UUID clientId; - private String userName; - private MageFrame frame; - - public ClientImpl(MageFrame frame, String userName) { - - this.clientId = UUID.randomUUID(); - this.userName = userName; - this.frame = frame; - try { - UnicastRemoteObject.exportObject(this, 0); - } catch (RemoteException ex) { - logger.log(Level.SEVERE, null, ex); - } - - } - - @Override - public UUID getId() throws RemoteException { - return clientId; - } - - @Override - public UUID getPlayerId() throws RemoteException { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public void gameStarted(UUID gameId, UUID playerId) throws RemoteException { - frame.showGame(gameId, playerId); - logger.info("Game client started for player " + playerId); - } - - @Override - public String getUserName() throws RemoteException { - return userName; - } - - @Override - public void watchGame(UUID gameId) throws RemoteException { - frame.watchGame(gameId); - } - - @Override - public void replayGame(UUID gameId) throws RemoteException { - frame.replayGame(gameId); - } - -} diff --git a/Mage.Client/src/mage/client/remote/GameClientImpl.java b/Mage.Client/src/mage/client/remote/GameClientImpl.java deleted file mode 100644 index ea80ecbdd04..00000000000 --- a/Mage.Client/src/mage/client/remote/GameClientImpl.java +++ /dev/null @@ -1,151 +0,0 @@ -/* -* Copyright 2010 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.client.remote; - -import java.rmi.RemoteException; -import java.rmi.server.UnicastRemoteObject; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import mage.client.game.GamePanel; -import mage.interfaces.GameClient; -import mage.interfaces.MageException; -import mage.util.Logging; -import mage.view.AbilityPickerView; -import mage.view.CardsView; -import mage.view.GameView; - -/** - * - * @author BetaSteward_at_googlemail.com - */ -public class GameClientImpl implements GameClient { - - private final static Logger logger = Logging.getLogger(GameClientImpl.class.getName()); - - private UUID gameClientId; - private GamePanel gamePanel; - - public GameClientImpl(GamePanel gamePanel) { - gameClientId = UUID.randomUUID(); - this.gamePanel = gamePanel; - try { - UnicastRemoteObject.exportObject(this, 0); - } catch (RemoteException ex) { - logger.log(Level.SEVERE, null, ex); - } - } - - @Override - public synchronized UUID getId() throws RemoteException { - return gameClientId; - } - - public UUID getIdLocal() { - return gameClientId; - } - - @Override - public synchronized void update(GameView gameView) throws RemoteException { - logger.info("Received update event for game"); - gamePanel.updateGame(gameView); - } - - @Override - public synchronized void init(GameView gameView) throws RemoteException { - gamePanel.init(gameView); - } - - @Override - public synchronized void ask(String question, GameView gameView) throws RemoteException { - gamePanel.updateGame(gameView); - gamePanel.ask(question); - } - - @Override - public synchronized void inform(String message, GameView gameView) throws RemoteException { - gamePanel.inform(message, null, gameView); - } - - @Override - public synchronized void target(String message, CardsView cardView, boolean required, GameView gameView) throws RemoteException { - if (required) { - gamePanel.inform(message, cardView, gameView); - } else { - gamePanel.cancel(message, cardView, gameView); - } - } - - @Override - public synchronized void gameOver(String message) throws RemoteException { - gamePanel.modalMessage(message); - gamePanel.hideGame(); - } - - @Override - public synchronized void select(String message, GameView gameView) throws RemoteException { - gamePanel.select(message, gameView); - } - - @Override - public synchronized void playMana(String message, GameView gameView) throws RemoteException { - gamePanel.playMana(message, gameView); - } - - @Override - public synchronized void playXMana(String message, GameView gameView) throws RemoteException { - gamePanel.playXMana(message, gameView); - } - - @Override - public synchronized void chooseAbility(AbilityPickerView abilities) throws RemoteException { - gamePanel.pickAbility(abilities); - } - - public void handleException(Exception ex) throws MageException { - logger.log(Level.SEVERE, "", ex); - throw new MageException("Server error"); - } - - @Override - public synchronized void revealCards(String name, CardsView cards) throws RemoteException { - gamePanel.revealCards(name, cards); - } - - @Override - public synchronized void getAmount(int min, int max) throws RemoteException { - gamePanel.getAmount(min, max); - } - - @Override - public synchronized void choose(String message, String[] choices) throws RemoteException { - gamePanel.getChoice(message, choices); - } - -} diff --git a/Mage.Client/src/mage/client/remote/GameReplayClientImpl.java b/Mage.Client/src/mage/client/remote/GameReplayClientImpl.java deleted file mode 100644 index 71c18a76832..00000000000 --- a/Mage.Client/src/mage/client/remote/GameReplayClientImpl.java +++ /dev/null @@ -1,87 +0,0 @@ -/* -* Copyright 2010 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.client.remote; - -import java.rmi.RemoteException; -import java.rmi.server.UnicastRemoteObject; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import mage.client.game.GamePanel; -import mage.interfaces.GameReplayClient; -import mage.util.Logging; -import mage.view.GameView; - -/** - * - * @author BetaSteward_at_googlemail.com - */ -public class GameReplayClientImpl implements GameReplayClient { - - private final static Logger logger = Logging.getLogger(GameClientImpl.class.getName()); - - private UUID replayClientId; - private GamePanel gamePanel; - - public GameReplayClientImpl(GamePanel gamePanel) { - replayClientId = UUID.randomUUID(); - this.gamePanel = gamePanel; - try { - UnicastRemoteObject.exportObject(this, 0); - } catch (RemoteException ex) { - logger.log(Level.SEVERE, null, ex); - } - } - - @Override - public UUID getId() throws RemoteException { - return replayClientId; - } - - @Override - public synchronized void update(GameView game) throws RemoteException { - gamePanel.updateGame(game); - } - - @Override - public synchronized void init(GameView gameView) throws RemoteException { - gamePanel.init(gameView); - } - - @Override - public synchronized void gameOver(String message) throws RemoteException { - gamePanel.modalMessage(message); - gamePanel.hideGame(); - } - - public synchronized void message(String message) throws RemoteException { - gamePanel.replayMessage(message); - } - -} diff --git a/Mage.Client/src/mage/client/remote/Session.java b/Mage.Client/src/mage/client/remote/Session.java index d662059bda4..0ddd39baeac 100644 --- a/Mage.Client/src/mage/client/remote/Session.java +++ b/Mage.Client/src/mage/client/remote/Session.java @@ -33,7 +33,9 @@ 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.logging.Level; import java.util.logging.Logger; @@ -41,13 +43,12 @@ import javax.swing.JOptionPane; import mage.Constants; import mage.cards.decks.DeckCardLists; import mage.client.MageFrame; +import mage.client.chat.ChatPanel; +import mage.client.game.GamePanel; import mage.client.util.Config; -import mage.interfaces.ChatClient; -import mage.interfaces.Client; -import mage.interfaces.GameClient; -import mage.interfaces.GameReplayClient; import mage.interfaces.MageException; import mage.interfaces.Server; +import mage.interfaces.callback.CallbackClientDaemon; import mage.util.Logging; import mage.view.TableView; @@ -66,6 +67,9 @@ public class Session { private MageFrame frame; private String[] playerTypes; private String[] gameTypes; + private Map chats = new HashMap(); + private GamePanel game; + private CallbackClientDaemon callbackDaemon; public Session(MageFrame frame) { this.frame = frame; @@ -75,13 +79,14 @@ public class Session { if (isConnected()) { disconnect(); } - this.userName = userName; - this.client = new ClientImpl(frame, userName); System.setSecurityManager(null); Registry reg = LocateRegistry.getRegistry(serverName, port); this.server = (Server) reg.lookup(Config.remoteServer); + this.userName = userName; try { - sessionId = server.registerClient(client); + this.client = new Client(this, frame, userName); + sessionId = server.registerClient(userName, client.getId()); + callbackDaemon = new CallbackClientDaemon(sessionId, client, server); playerTypes = server.getPlayerTypes(); gameTypes = server.getGameTypes(); logger.info("Connected to RMI server at " + serverName + ":" + port); @@ -95,6 +100,10 @@ public class Session { if (isConnected()) { try { + for (UUID chatId: chats.keySet()) { + server.leaveChat(chatId, sessionId); + } + //TODO: stop daemon server.deregisterClient(sessionId); server = null; logger.info("Disconnected ... "); @@ -118,6 +127,18 @@ public class Session { return gameTypes; } + public Map getChats() { + return chats; + } + + public GamePanel getGame() { + return game; + } + + public void setGame(GamePanel gamePanel) { + game = gamePanel; + } + public UUID getMainRoomId() { try { return server.getMainRoomId(); @@ -268,9 +289,10 @@ public class Session { return false; } - public boolean joinChat(UUID chatId, ChatClient client) { + public boolean joinChat(UUID chatId, ChatPanel chat) { try { - server.joinChat(chatId, client); + server.joinChat(chatId, sessionId, userName); + chats.put(chatId, chat); return true; } catch (RemoteException ex) { handleRemoteException(ex); @@ -280,9 +302,10 @@ public class Session { return false; } - public boolean leaveChat(UUID chatId, UUID clientId) { + public boolean leaveChat(UUID chatId) { try { - server.leaveChat(chatId, clientId); + server.leaveChat(chatId, sessionId); + chats.remove(chatId); return true; } catch (RemoteException ex) { handleRemoteException(ex); @@ -304,9 +327,9 @@ public class Session { return false; } - public boolean joinGame(UUID gameId, GameClient gameClient) { + public boolean joinGame(UUID gameId) { try { - server.joinGame(gameId, sessionId, gameClient); + server.joinGame(gameId, sessionId); return true; } catch (RemoteException ex) { handleRemoteException(ex); @@ -316,9 +339,9 @@ public class Session { return false; } - public boolean watchGame(UUID gameId, GameClient gameClient) { + public boolean watchGame(UUID gameId) { try { - server.watchGame(gameId, sessionId, gameClient); + server.watchGame(gameId, sessionId); return true; } catch (RemoteException ex) { handleRemoteException(ex); @@ -328,9 +351,9 @@ public class Session { return false; } - public boolean replayGame(UUID gameId, GameReplayClient replayClient) { + public boolean replayGame() { try { - server.replayGame(gameId, sessionId, replayClient); + server.replayGame(sessionId); return true; } catch (RemoteException ex) { handleRemoteException(ex); @@ -410,9 +433,9 @@ public class Session { return false; } - public boolean stopWatching(UUID gameId, UUID gameClientId) { + public boolean stopWatching(UUID gameId) { try { - server.stopWatching(gameId, gameClientId); + server.stopWatching(gameId, sessionId); return true; } catch (RemoteException ex) { handleRemoteException(ex); diff --git a/Mage.Client/src/mage/client/util/EDTExceptionHandler.java b/Mage.Client/src/mage/client/util/EDTExceptionHandler.java new file mode 100644 index 00000000000..6321af56f60 --- /dev/null +++ b/Mage.Client/src/mage/client/util/EDTExceptionHandler.java @@ -0,0 +1,58 @@ +/* + * Copyright 2010 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.client.util; + +import java.util.logging.Logger; +import mage.util.Logging; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class EDTExceptionHandler implements Thread.UncaughtExceptionHandler { + + private final static Logger logger = Logging.getLogger(EDTExceptionHandler.class.getName()); + + @Override + public void uncaughtException(Thread t, Throwable e) { + handle(e); + } + + public void handle(Throwable throwable) { + try { + logger.severe(throwable.getMessage()); + } catch (Throwable t) {} + } + + public static void registerExceptionHandler() { + Thread.setDefaultUncaughtExceptionHandler(new EDTExceptionHandler()); + System.setProperty("sun.awt.exception.handler", EDTExceptionHandler.class.getName()); + } + +}