1
0
Fork 0
mirror of https://github.com/correl/mage.git synced 2025-04-03 01:08:59 -09:00

client + server improvements

This commit is contained in:
BetaSteward 2011-05-17 21:55:20 -04:00
parent f37f2d8b63
commit 94c5a0cdfb
20 changed files with 594 additions and 321 deletions

View file

@ -746,6 +746,16 @@ public class MageFrame extends javax.swing.JFrame {
this.tablesPane.hideTables();
}
public void hideGames() {
JInternalFrame[] windows = desktopPane.getAllFramesInLayer(javax.swing.JLayeredPane.DEFAULT_LAYER);
for (JInternalFrame window: windows) {
if (window instanceof GamePane) {
GamePane gamePane = (GamePane) window;
gamePane.hideGame();
}
}
}
public void showDeckEditor(DeckEditorMode mode, Deck deck, UUID tableId, int time) {
try {
DeckEditorPane deckEditorPane = new DeckEditorPane();
@ -826,6 +836,7 @@ public class MageFrame extends javax.swing.JFrame {
public void setStatusText(String status) {
this.lblStatus.setText(status);
}
}
class MagePaneMenuItem extends JCheckBoxMenuItem {

View file

@ -78,7 +78,7 @@ public class ConnectDialog extends MageDialog {
this.chkAutoConnect.setSelected(Boolean.parseBoolean(MageFrame.getPreferences().get("autoConnect", "false")));
this.txtProxyServer.setText(MageFrame.getPreferences().get("proxyAddress", Config.serverName));
this.txtProxyPort.setText(MageFrame.getPreferences().get("proxyPort", Integer.toString(Config.port)));
this.cbProxyType.setSelectedItem(MageFrame.getPreferences().get("proxyType", Connection.ProxyType.NONE.toString()));
this.cbProxyType.setSelectedItem(Connection.ProxyType.valueOf(MageFrame.getPreferences().get("proxyType", "NONE").toUpperCase()));
this.showProxySettings();
this.setModal(true);
this.setLocation(50, 50);

View file

@ -318,6 +318,10 @@ public class NewTableDialog extends MageDialog {
options.setRange((RangeOfInfluence) this.cbRange.getSelectedItem());
options.setWinsNeeded((Integer)this.spnNumWins.getValue());
table = session.createTable(roomId, options);
if (table == null) {
JOptionPane.showMessageDialog(MageFrame.getDesktop(), "Error creating table.", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
try {
if (session.joinTable(roomId, table.getTableId(), this.player1Panel.getPlayerName(), "Human", 1, Sets.loadDeck(this.player1Panel.getDeckFile()))) {
for (TablePlayerPanel player: players) {

View file

@ -308,6 +308,10 @@ public class NewTournamentDialog extends MageDialog {
tOptions.getMatchOptions().setAttackOption(MultiplayerAttackOption.LEFT);
tOptions.getMatchOptions().setRange(RangeOfInfluence.ALL);
table = session.createTournamentTable(roomId, tOptions);
if (table == null) {
JOptionPane.showMessageDialog(MageFrame.getDesktop(), "Error creating table.", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
if (session.joinTournamentTable(roomId, table.getTableId(), this.txtPlayer1Name.getText(), "Human", 1)) {
for (TournamentPlayerPanel player: players) {
if (!player.getPlayerType().equals("Human")) {

View file

@ -83,6 +83,10 @@ public class GamePane extends MagePane {
this.toFront();
}
public void hideGame() {
gamePanel.hideGame();
}
public void watchGame(UUID gameId) {
this.setTitle("Watching " + gameId);
gamePanel.watchGame(gameId);

View file

@ -100,6 +100,8 @@ public class Session {
}
try {
System.setSecurityManager(null);
System.setProperty("http.nonProxyHosts", "code.google.com");
System.setProperty("socksNonProxyHosts", "code.google.com");
switch (connection.getProxyType()) {
case SOCKS:
System.setProperty("socksProxyHost", connection.getProxyHost());
@ -157,7 +159,8 @@ public class Session {
}
try {
//TODO: stop daemon
server.deregisterClient(sessionId);
if (server != null)
server.deregisterClient(sessionId);
} catch (RemoteException ex) {
logger.fatal("Error disconnecting ...", ex);
} catch (MageException ex) {
@ -171,6 +174,7 @@ public class Session {
if (future != null && !future.isDone())
future.cancel(true);
server = null;
frame.hideGames();
frame.hideTables();
frame.setStatusText("Not connected");
frame.disableButtons();

View file

@ -122,5 +122,7 @@ public interface Server extends Remote, CallbackServer {
//admin methods
public List<UserView> getUsers(UUID sessionId) throws RemoteException, MageException;
public void disconnectUser(UUID sessionId, UUID userSessionId) throws RemoteException, MageException;
public void removeTable(UUID sessionId, UUID tableId) throws RemoteException, MageException;
}

View file

@ -46,6 +46,7 @@ public class UserView implements Serializable {
this.userName = userName;
this.host = host;
this.sessionId = sessionId;
this.timeConnected = timeConnected;
}
public String getUserName() {

View file

@ -34,12 +34,10 @@
package mage.server.console;
import java.util.logging.Level;
import java.util.prefs.Preferences;
import javax.swing.Box;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import mage.server.console.remote.Session;
import mage.utils.MageVersion;
import org.apache.log4j.Logger;

View file

@ -120,6 +120,9 @@
<Properties>
<Property name="text" type="java.lang.String" value="Disconnect"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnDisconnectActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Container>
@ -208,6 +211,9 @@
<Properties>
<Property name="text" type="java.lang.String" value="Remove"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnDeleteActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Container>

View file

@ -134,6 +134,11 @@ public class ConsolePanel extends javax.swing.JPanel {
jPanel4.setVerifyInputWhenFocusTarget(false);
btnDisconnect.setText("Disconnect");
btnDisconnect.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnDisconnectActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
jPanel4.setLayout(jPanel4Layout);
@ -182,6 +187,11 @@ public class ConsolePanel extends javax.swing.JPanel {
);
btnDelete.setText("Remove");
btnDelete.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnDeleteActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
jPanel6.setLayout(jPanel6Layout);
@ -226,6 +236,17 @@ public class ConsolePanel extends javax.swing.JPanel {
.addComponent(jSplitPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 395, Short.MAX_VALUE)
);
}// </editor-fold>//GEN-END:initComponents
private void btnDisconnectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDisconnectActionPerformed
int row = this.tblUsers.getSelectedRow();
ConsoleFrame.getSession().disconnectUser((UUID)tableUserModel.getValueAt(row, 3));
}//GEN-LAST:event_btnDisconnectActionPerformed
private void btnDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeleteActionPerformed
int row = this.tblTables.getSelectedRow();
ConsoleFrame.getSession().removeTable((UUID)tableTableModel.getValueAt(row, 7));
}//GEN-LAST:event_btnDeleteActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnDelete;
private javax.swing.JButton btnDisconnect;

View file

@ -492,9 +492,9 @@ public class Session {
return false;
}
public boolean removeTable(UUID roomId, UUID tableId) {
public boolean removeTable(UUID tableId) {
try {
server.removeTable(sessionId, roomId, tableId);
server.removeTable(sessionId, tableId);
return true;
} catch (RemoteException ex) {
handleRemoteException(ex);
@ -672,6 +672,18 @@ public class Session {
return null;
}
public boolean disconnectUser(UUID userSessionId) {
try {
server.disconnectUser(sessionId, userSessionId);
return true;
} catch (RemoteException ex) {
handleRemoteException(ex);
} catch (MageException ex) {
handleMageException(ex);
}
return false;
}
private void handleRemoteException(RemoteException ex) {
logger.fatal("Communication error", ex);
if (ex instanceof java.rmi.ConnectException) {

View file

@ -154,9 +154,11 @@ public class ServerImpl extends RemoteServer implements Server {
@Override
public TableView createTable(UUID sessionId, UUID roomId, MatchOptions options) throws MageException {
try {
TableView table = GamesRoomManager.getInstance().getRoom(roomId).createTable(sessionId, options);
logger.info("Table " + table.getTableId() + " created");
return table;
if (SessionManager.getInstance().isValidSession(sessionId)) {
TableView table = GamesRoomManager.getInstance().getRoom(roomId).createTable(sessionId, options);
logger.info("Table " + table.getTableId() + " created");
return table;
}
}
catch (Exception ex) {
handleException(ex);
@ -167,9 +169,11 @@ public class ServerImpl extends RemoteServer implements Server {
@Override
public TableView createTournamentTable(UUID sessionId, UUID roomId, TournamentOptions options) throws MageException {
try {
TableView table = GamesRoomManager.getInstance().getRoom(roomId).createTournamentTable(sessionId, options);
logger.info("Tournament table " + table.getTableId() + " created");
return table;
if (SessionManager.getInstance().isValidSession(sessionId)) {
TableView table = GamesRoomManager.getInstance().getRoom(roomId).createTournamentTable(sessionId, options);
logger.info("Tournament table " + table.getTableId() + " created");
return table;
}
}
catch (Exception ex) {
handleException(ex);
@ -179,27 +183,31 @@ public class ServerImpl extends RemoteServer implements Server {
@Override
public void removeTable(final UUID sessionId, final UUID roomId, final UUID tableId) throws MageException {
try {
rmiExecutor.execute(
new Runnable() {
@Override
public void run() {
GamesRoomManager.getInstance().getRoom(roomId).removeTable(sessionId, tableId);
if (SessionManager.getInstance().isValidSession(sessionId)) {
try {
rmiExecutor.execute(
new Runnable() {
@Override
public void run() {
TableManager.getInstance().removeTable(sessionId, tableId);
}
}
}
);
}
catch (Exception ex) {
handleException(ex);
);
}
catch (Exception ex) {
handleException(ex);
}
}
}
@Override
public boolean joinTable(UUID sessionId, UUID roomId, UUID tableId, String name, String playerType, int skill, DeckCardLists deckList) throws MageException, GameException {
try {
boolean ret = GamesRoomManager.getInstance().getRoom(roomId).joinTable(sessionId, tableId, name, playerType, skill, deckList);
logger.info("Session " + sessionId + " joined table " + tableId);
return ret;
if (SessionManager.getInstance().isValidSession(sessionId)) {
boolean ret = GamesRoomManager.getInstance().getRoom(roomId).joinTable(sessionId, tableId, name, playerType, skill, deckList);
logger.info("Session " + sessionId + " joined table " + tableId);
return ret;
}
}
catch (Exception ex) {
if (ex instanceof GameException)
@ -212,9 +220,11 @@ public class ServerImpl extends RemoteServer implements Server {
@Override
public boolean joinTournamentTable(UUID sessionId, UUID roomId, UUID tableId, String name, String playerType, int skill) throws MageException, GameException {
try {
boolean ret = GamesRoomManager.getInstance().getRoom(roomId).joinTournamentTable(sessionId, tableId, name, playerType, skill);
logger.info("Session " + sessionId + " joined table " + tableId);
return ret;
if (SessionManager.getInstance().isValidSession(sessionId)) {
boolean ret = GamesRoomManager.getInstance().getRoom(roomId).joinTournamentTable(sessionId, tableId, name, playerType, skill);
logger.info("Session " + sessionId + " joined table " + tableId);
return ret;
}
}
catch (Exception ex) {
if (ex instanceof GameException)
@ -227,9 +237,11 @@ public class ServerImpl extends RemoteServer implements Server {
@Override
public boolean submitDeck(UUID sessionId, UUID tableId, DeckCardLists deckList) throws MageException, GameException {
try {
boolean ret = TableManager.getInstance().submitDeck(sessionId, tableId, deckList);
logger.info("Session " + sessionId + " submitted deck");
return ret;
if (SessionManager.getInstance().isValidSession(sessionId)) {
boolean ret = TableManager.getInstance().submitDeck(sessionId, tableId, deckList);
logger.info("Session " + sessionId + " submitted deck");
return ret;
}
}
catch (Exception ex) {
if (ex instanceof GameException)
@ -299,52 +311,58 @@ public class ServerImpl extends RemoteServer implements Server {
@Override
public void startMatch(final UUID sessionId, final UUID roomId, final UUID tableId) throws MageException {
try {
rmiExecutor.execute(
new Runnable() {
@Override
public void run() {
TableManager.getInstance().startMatch(sessionId, roomId, tableId);
if (SessionManager.getInstance().isValidSession(sessionId)) {
try {
rmiExecutor.execute(
new Runnable() {
@Override
public void run() {
TableManager.getInstance().startMatch(sessionId, roomId, tableId);
}
}
}
);
}
catch (Exception ex) {
handleException(ex);
);
}
catch (Exception ex) {
handleException(ex);
}
}
}
@Override
public void startChallenge(final UUID sessionId, final UUID roomId, final UUID tableId, final UUID challengeId) throws RemoteException, MageException {
try {
rmiExecutor.execute(
new Runnable() {
@Override
public void run() {
TableManager.getInstance().startChallenge(sessionId, roomId, tableId, challengeId);
if (SessionManager.getInstance().isValidSession(sessionId)) {
try {
rmiExecutor.execute(
new Runnable() {
@Override
public void run() {
TableManager.getInstance().startChallenge(sessionId, roomId, tableId, challengeId);
}
}
}
);
}
catch (Exception ex) {
handleException(ex);
);
}
catch (Exception ex) {
handleException(ex);
}
}
}
@Override
public void startTournament(final UUID sessionId, final UUID roomId, final UUID tableId) throws MageException {
try {
rmiExecutor.execute(
new Runnable() {
@Override
public void run() {
TableManager.getInstance().startTournament(sessionId, roomId, tableId);
if (SessionManager.getInstance().isValidSession(sessionId)) {
try {
rmiExecutor.execute(
new Runnable() {
@Override
public void run() {
TableManager.getInstance().startTournament(sessionId, roomId, tableId);
}
}
}
);
}
catch (Exception ex) {
handleException(ex);
);
}
catch (Exception ex) {
handleException(ex);
}
}
}
@ -445,35 +463,39 @@ public class ServerImpl extends RemoteServer implements Server {
@Override
public void swapSeats(final UUID sessionId, final UUID roomId, final UUID tableId, final int seatNum1, final int seatNum2) throws RemoteException, MageException {
try {
rmiExecutor.execute(
new Runnable() {
@Override
public void run() {
TableManager.getInstance().swapSeats(tableId, sessionId, seatNum1, seatNum2);
if (SessionManager.getInstance().isValidSession(sessionId)) {
try {
rmiExecutor.execute(
new Runnable() {
@Override
public void run() {
TableManager.getInstance().swapSeats(tableId, sessionId, seatNum1, seatNum2);
}
}
}
);
}
catch (Exception ex) {
handleException(ex);
);
}
catch (Exception ex) {
handleException(ex);
}
}
}
@Override
public void leaveTable(final UUID sessionId, final UUID roomId, final UUID tableId) throws MageException {
try {
rmiExecutor.execute(
new Runnable() {
@Override
public void run() {
GamesRoomManager.getInstance().getRoom(roomId).leaveTable(sessionId, tableId);
if (SessionManager.getInstance().isValidSession(sessionId)) {
try {
rmiExecutor.execute(
new Runnable() {
@Override
public void run() {
GamesRoomManager.getInstance().getRoom(roomId).leaveTable(sessionId, tableId);
}
}
}
);
}
catch (Exception ex) {
handleException(ex);
);
}
catch (Exception ex) {
handleException(ex);
}
}
}
@ -490,52 +512,58 @@ public class ServerImpl extends RemoteServer implements Server {
@Override
public void joinGame(final UUID gameId, final UUID sessionId) throws MageException {
try {
rmiExecutor.execute(
new Runnable() {
@Override
public void run() {
GameManager.getInstance().joinGame(gameId, sessionId);
if (SessionManager.getInstance().isValidSession(sessionId)) {
try {
rmiExecutor.execute(
new Runnable() {
@Override
public void run() {
GameManager.getInstance().joinGame(gameId, sessionId);
}
}
}
);
}
catch (Exception ex) {
handleException(ex);
);
}
catch (Exception ex) {
handleException(ex);
}
}
}
@Override
public void joinDraft(final UUID draftId, final UUID sessionId) throws MageException {
try {
rmiExecutor.execute(
new Runnable() {
@Override
public void run() {
DraftManager.getInstance().joinDraft(draftId, sessionId);
if (SessionManager.getInstance().isValidSession(sessionId)) {
try {
rmiExecutor.execute(
new Runnable() {
@Override
public void run() {
DraftManager.getInstance().joinDraft(draftId, sessionId);
}
}
}
);
}
catch (Exception ex) {
handleException(ex);
);
}
catch (Exception ex) {
handleException(ex);
}
}
}
@Override
public void joinTournament(final UUID tournamentId, final UUID sessionId) throws MageException {
try {
rmiExecutor.execute(
new Runnable() {
@Override
public void run() {
TournamentManager.getInstance().joinTournament(tournamentId, sessionId);
if (SessionManager.getInstance().isValidSession(sessionId)) {
try {
rmiExecutor.execute(
new Runnable() {
@Override
public void run() {
TournamentManager.getInstance().joinTournament(tournamentId, sessionId);
}
}
}
);
}
catch (Exception ex) {
handleException(ex);
);
}
catch (Exception ex) {
handleException(ex);
}
}
}
@ -563,76 +591,86 @@ public class ServerImpl extends RemoteServer implements Server {
@Override
public void sendPlayerUUID(final UUID gameId, final UUID sessionId, final UUID data) throws MageException {
try {
rmiExecutor.execute(
new Runnable() {
@Override
public void run() {
GameManager.getInstance().sendPlayerUUID(gameId, sessionId, data);
if (SessionManager.getInstance().isValidSession(sessionId)) {
try {
rmiExecutor.execute(
new Runnable() {
@Override
public void run() {
GameManager.getInstance().sendPlayerUUID(gameId, sessionId, data);
}
}
}
);
}
catch (Exception ex) {
handleException(ex);
);
}
catch (Exception ex) {
handleException(ex);
}
}
}
@Override
public void sendPlayerString(final UUID gameId, final UUID sessionId, final String data) throws MageException {
try {
rmiExecutor.execute(
new Runnable() {
@Override
public void run() {
GameManager.getInstance().sendPlayerString(gameId, sessionId, data);
if (SessionManager.getInstance().isValidSession(sessionId)) {
try {
rmiExecutor.execute(
new Runnable() {
@Override
public void run() {
GameManager.getInstance().sendPlayerString(gameId, sessionId, data);
}
}
}
);
}
catch (Exception ex) {
handleException(ex);
);
}
catch (Exception ex) {
handleException(ex);
}
}
}
@Override
public void sendPlayerBoolean(final UUID gameId, final UUID sessionId, final Boolean data) throws MageException {
try {
rmiExecutor.execute(
new Runnable() {
@Override
public void run() {
GameManager.getInstance().sendPlayerBoolean(gameId, sessionId, data);
if (SessionManager.getInstance().isValidSession(sessionId)) {
try {
rmiExecutor.execute(
new Runnable() {
@Override
public void run() {
GameManager.getInstance().sendPlayerBoolean(gameId, sessionId, data);
}
}
}
);
}
catch (Exception ex) {
handleException(ex);
);
}
catch (Exception ex) {
handleException(ex);
}
}
}
@Override
public void sendPlayerInteger(final UUID gameId, final UUID sessionId, final Integer data) throws RemoteException, MageException {
try {
rmiExecutor.execute(
new Runnable() {
@Override
public void run() {
GameManager.getInstance().sendPlayerInteger(gameId, sessionId, data);
if (SessionManager.getInstance().isValidSession(sessionId)) {
try {
rmiExecutor.execute(
new Runnable() {
@Override
public void run() {
GameManager.getInstance().sendPlayerInteger(gameId, sessionId, data);
}
}
}
);
}
catch (Exception ex) {
handleException(ex);
);
}
catch (Exception ex) {
handleException(ex);
}
}
}
@Override
public DraftPickView sendCardPick(final UUID draftId, final UUID sessionId, final UUID cardPick) throws MageException {
try {
return DraftManager.getInstance().sendCardPick(draftId, sessionId, cardPick);
if (SessionManager.getInstance().isValidSession(sessionId)) {
return DraftManager.getInstance().sendCardPick(draftId, sessionId, cardPick);
}
}
catch (Exception ex) {
handleException(ex);
@ -642,25 +680,29 @@ public class ServerImpl extends RemoteServer implements Server {
@Override
public void concedeGame(final UUID gameId, final UUID sessionId) throws MageException {
try {
rmiExecutor.execute(
new Runnable() {
@Override
public void run() {
GameManager.getInstance().concedeGame(gameId, sessionId);
if (SessionManager.getInstance().isValidSession(sessionId)) {
try {
rmiExecutor.execute(
new Runnable() {
@Override
public void run() {
GameManager.getInstance().concedeGame(gameId, sessionId);
}
}
}
);
}
catch (Exception ex) {
handleException(ex);
);
}
catch (Exception ex) {
handleException(ex);
}
}
}
@Override
public boolean watchTable(UUID sessionId, UUID roomId, UUID tableId) throws MageException {
try {
return GamesRoomManager.getInstance().getRoom(roomId).watchTable(sessionId, tableId);
if (SessionManager.getInstance().isValidSession(sessionId)) {
return GamesRoomManager.getInstance().getRoom(roomId).watchTable(sessionId, tableId);
}
}
catch (Exception ex) {
handleException(ex);
@ -670,120 +712,134 @@ public class ServerImpl extends RemoteServer implements Server {
@Override
public void watchGame(final UUID gameId, final UUID sessionId) throws MageException {
try {
rmiExecutor.execute(
new Runnable() {
@Override
public void run() {
GameManager.getInstance().watchGame(gameId, sessionId);
if (SessionManager.getInstance().isValidSession(sessionId)) {
try {
rmiExecutor.execute(
new Runnable() {
@Override
public void run() {
GameManager.getInstance().watchGame(gameId, sessionId);
}
}
}
);
}
catch (Exception ex) {
handleException(ex);
);
}
catch (Exception ex) {
handleException(ex);
}
}
}
@Override
public void stopWatching(final UUID gameId, final UUID sessionId) throws MageException {
try {
rmiExecutor.execute(
new Runnable() {
@Override
public void run() {
GameManager.getInstance().stopWatching(gameId, sessionId);
if (SessionManager.getInstance().isValidSession(sessionId)) {
try {
rmiExecutor.execute(
new Runnable() {
@Override
public void run() {
GameManager.getInstance().stopWatching(gameId, sessionId);
}
}
}
);
}
catch (Exception ex) {
handleException(ex);
);
}
catch (Exception ex) {
handleException(ex);
}
}
}
@Override
public void replayGame(final UUID gameId, final UUID sessionId) throws MageException {
try {
rmiExecutor.execute(
new Runnable() {
@Override
public void run() {
ReplayManager.getInstance().replayGame(gameId, sessionId);
if (SessionManager.getInstance().isValidSession(sessionId)) {
try {
rmiExecutor.execute(
new Runnable() {
@Override
public void run() {
ReplayManager.getInstance().replayGame(gameId, sessionId);
}
}
}
);
}
catch (Exception ex) {
handleException(ex);
);
}
catch (Exception ex) {
handleException(ex);
}
}
}
@Override
public void startReplay(final UUID gameId, final UUID sessionId) throws MageException {
try {
rmiExecutor.execute(
new Runnable() {
@Override
public void run() {
ReplayManager.getInstance().startReplay(gameId, sessionId);
if (SessionManager.getInstance().isValidSession(sessionId)) {
try {
rmiExecutor.execute(
new Runnable() {
@Override
public void run() {
ReplayManager.getInstance().startReplay(gameId, sessionId);
}
}
}
);
}
catch (Exception ex) {
handleException(ex);
);
}
catch (Exception ex) {
handleException(ex);
}
}
}
@Override
public void stopReplay(final UUID gameId, final UUID sessionId) throws MageException {
try {
rmiExecutor.execute(
new Runnable() {
@Override
public void run() {
ReplayManager.getInstance().stopReplay(gameId, sessionId);
if (SessionManager.getInstance().isValidSession(sessionId)) {
try {
rmiExecutor.execute(
new Runnable() {
@Override
public void run() {
ReplayManager.getInstance().stopReplay(gameId, sessionId);
}
}
}
);
}
catch (Exception ex) {
handleException(ex);
);
}
catch (Exception ex) {
handleException(ex);
}
}
}
@Override
public void nextPlay(final UUID gameId, final UUID sessionId) throws MageException {
try {
rmiExecutor.execute(
new Runnable() {
@Override
public void run() {
ReplayManager.getInstance().nextPlay(gameId, sessionId);
if (SessionManager.getInstance().isValidSession(sessionId)) {
try {
rmiExecutor.execute(
new Runnable() {
@Override
public void run() {
ReplayManager.getInstance().nextPlay(gameId, sessionId);
}
}
}
);
}
catch (Exception ex) {
handleException(ex);
);
}
catch (Exception ex) {
handleException(ex);
}
}
}
@Override
public void previousPlay(final UUID gameId, final UUID sessionId) throws MageException {
try {
rmiExecutor.execute(
new Runnable() {
@Override
public void run() {
ReplayManager.getInstance().previousPlay(gameId, sessionId);
if (SessionManager.getInstance().isValidSession(sessionId)) {
try {
rmiExecutor.execute(
new Runnable() {
@Override
public void run() {
ReplayManager.getInstance().previousPlay(gameId, sessionId);
}
}
}
);
}
catch (Exception ex) {
handleException(ex);
);
}
catch (Exception ex) {
handleException(ex);
}
}
}
@ -806,43 +862,90 @@ public class ServerImpl extends RemoteServer implements Server {
@Override
public void cheat(final UUID gameId, final UUID sessionId, final UUID playerId, final DeckCardLists deckList) throws MageException {
try {
rmiExecutor.execute(
new Runnable() {
@Override
public void run() {
if (testMode)
GameManager.getInstance().cheat(gameId, sessionId, playerId, deckList);
if (SessionManager.getInstance().isValidSession(sessionId)) {
try {
rmiExecutor.execute(
new Runnable() {
@Override
public void run() {
if (testMode)
GameManager.getInstance().cheat(gameId, sessionId, playerId, deckList);
}
}
}
);
}
catch (Exception ex) {
handleException(ex);
);
}
catch (Exception ex) {
handleException(ex);
}
}
}
@Override
public boolean cheat(final UUID gameId, final UUID sessionId, final UUID playerId, final String cardName) throws MageException {
if (testMode) {
return GameManager.getInstance().cheat(gameId, sessionId, playerId, cardName);
} else {
return false;
if (SessionManager.getInstance().isValidSession(sessionId)) {
return GameManager.getInstance().cheat(gameId, sessionId, playerId, cardName);
}
}
}
return false;
}
public void handleException(Exception ex) throws MageException {
logger.fatal("", ex);
throw new MageException("Server error: " + ex.getMessage());
}
@Override
public GameView getGameView(final UUID gameId, final UUID sessionId, final UUID playerId) {
return GameManager.getInstance().getGameView(gameId, sessionId, playerId);
if (SessionManager.getInstance().isValidSession(sessionId)) {
return GameManager.getInstance().getGameView(gameId, sessionId, playerId);
}
return null;
}
@Override
public List<UserView> getUsers(UUID sessionId) throws RemoteException, MageException {
return SessionManager.getInstance().getUsers(sessionId);
if (SessionManager.getInstance().isValidSession(sessionId)) {
return SessionManager.getInstance().getUsers(sessionId);
}
return null;
}
@Override
public void disconnectUser(final UUID sessionId, final UUID userSessionId) throws RemoteException, MageException {
if (SessionManager.getInstance().isValidSession(sessionId)) {
try {
rmiExecutor.execute(
new Runnable() {
@Override
public void run() {
SessionManager.getInstance().disconnectUser(sessionId, userSessionId);
}
}
);
}
catch (Exception ex) {
handleException(ex);
}
}
}
@Override
public void removeTable(final UUID sessionId, final UUID tableId) throws RemoteException, MageException {
if (SessionManager.getInstance().isValidSession(sessionId)) {
try {
rmiExecutor.execute(
new Runnable() {
@Override
public void run() {
TableManager.getInstance().removeTable(sessionId, tableId);
}
}
);
}
catch (Exception ex) {
handleException(ex);
}
}
}
}

View file

@ -124,6 +124,29 @@ public class SessionManager {
return users;
}
public void disconnectUser(UUID sessionId, UUID userSessionId) {
if (isAdmin(sessionId)) {
Session session = sessions.get(userSessionId);
if (session != null) {
session.kill();
}
}
}
public boolean isAdmin(UUID sessionId) {
Session admin = sessions.get(sessionId);
if (admin != null) {
return admin.isAdmin();
}
return false;
}
public boolean isValidSession(UUID sessionId) {
if (sessions.containsKey(sessionId))
return true;
return false;
}
class SessionChecker implements Runnable {
@Override

View file

@ -279,18 +279,35 @@ public class TableController {
match.startMatch();
startGame(null);
} catch (GameException ex) {
logger.fatal(null, ex);
logger.fatal("Error starting match ", ex);
match.endGame();
}
}
}
private void startGame(UUID choosingPlayerId) throws GameException {
match.startGame();
table.initGame();
GameManager.getInstance().createGameSession(match.getGame(), sessionPlayerMap, table.getId(), choosingPlayerId);
SessionManager sessionManager = SessionManager.getInstance();
for (Entry<UUID, UUID> entry: sessionPlayerMap.entrySet()) {
sessionManager.getSession(entry.getKey()).gameStarted(match.getGame().getId(), entry.getValue());
try {
match.startGame();
table.initGame();
GameManager.getInstance().createGameSession(match.getGame(), sessionPlayerMap, table.getId(), choosingPlayerId);
SessionManager sessionManager = SessionManager.getInstance();
for (Entry<UUID, UUID> entry: sessionPlayerMap.entrySet()) {
Session session = sessionManager.getSession(entry.getKey());
if (session != null) {
session.gameStarted(match.getGame().getId(), entry.getValue());
}
else {
TableManager.getInstance().removeTable(table.getId());
GameManager.getInstance().removeGame(match.getGame().getId());
logger.warn("Unable to find player " + entry.getKey());
break;
}
}
}
catch (Exception ex) {
logger.fatal("Error starting game", ex);
TableManager.getInstance().removeTable(table.getId());
GameManager.getInstance().removeGame(match.getGame().getId());
}
}
@ -341,7 +358,7 @@ public class TableController {
startGame(choosingPlayerId);
}
else {
GamesRoomManager.getInstance().getRoom(table.getRoomId()).removeTable(sessionId, table.getId());
GamesRoomManager.getInstance().removeTable(table.getId());
}
} catch (GameException ex) {
logger.fatal(null, ex);

View file

@ -40,6 +40,7 @@ import mage.game.match.Match;
import mage.game.match.MatchOptions;
import mage.game.tournament.TournamentOptions;
import mage.players.Player;
import mage.server.game.GamesRoomManager;
import org.apache.log4j.Logger;
/**
@ -84,7 +85,9 @@ public class TableManager {
}
public Match getMatch(UUID tableId) {
return controllers.get(tableId).getMatch();
if (controllers.containsKey(tableId))
return controllers.get(tableId).getMatch();
return null;
}
public Collection<Table> getTables() {
@ -92,15 +95,21 @@ public class TableManager {
}
public boolean joinTable(UUID sessionId, UUID tableId, String name, String playerType, int skill, DeckCardLists deckList) throws GameException {
return controllers.get(tableId).joinTable(sessionId, name, playerType, skill, deckList);
if (controllers.containsKey(tableId))
return controllers.get(tableId).joinTable(sessionId, name, playerType, skill, deckList);
return false;
}
public boolean joinTournament(UUID sessionId, UUID tableId, String name, String playerType, int skill) throws GameException {
return controllers.get(tableId).joinTournament(sessionId, name, playerType, skill);
if (controllers.containsKey(tableId))
return controllers.get(tableId).joinTournament(sessionId, name, playerType, skill);
return false;
}
public boolean submitDeck(UUID sessionId, UUID tableId, DeckCardLists deckList) throws GameException {
return controllers.get(tableId).submitDeck(sessionId, deckList);
if (controllers.containsKey(tableId))
return controllers.get(tableId).submitDeck(sessionId, deckList);
return false;
}
public void removeSession(UUID sessionId) {
@ -108,74 +117,101 @@ public class TableManager {
}
public boolean isTableOwner(UUID tableId, UUID sessionId) {
return controllers.get(tableId).isOwner(sessionId);
if (controllers.containsKey(tableId))
return controllers.get(tableId).isOwner(sessionId);
return false;
}
public boolean removeTable(UUID sessionId, UUID tableId) {
if (isTableOwner(tableId, sessionId)) {
controllers.remove(tableId);
tables.remove(tableId);
if (isTableOwner(tableId, sessionId) || SessionManager.getInstance().isAdmin(sessionId)) {
removeTable(tableId);
return true;
}
return false;
}
public void leaveTable(UUID sessionId, UUID tableId) {
controllers.get(tableId).leaveTable(sessionId);
if (controllers.containsKey(tableId))
controllers.get(tableId).leaveTable(sessionId);
}
public UUID getChatId(UUID tableId) {
return controllers.get(tableId).getChatId();
if (controllers.containsKey(tableId))
return controllers.get(tableId).getChatId();
return null;
}
public void startMatch(UUID sessionId, UUID roomId, UUID tableId) {
controllers.get(tableId).startMatch(sessionId);
if (controllers.containsKey(tableId))
controllers.get(tableId).startMatch(sessionId);
}
public void startMatch(UUID roomId, UUID tableId) {
controllers.get(tableId).startMatch();
if (controllers.containsKey(tableId))
controllers.get(tableId).startMatch();
}
public void startChallenge(UUID sessionId, UUID roomId, UUID tableId, UUID challengeId) {
controllers.get(tableId).startChallenge(sessionId, challengeId);
if (controllers.containsKey(tableId))
controllers.get(tableId).startChallenge(sessionId, challengeId);
}
public void startTournament(UUID sessionId, UUID roomId, UUID tableId) {
controllers.get(tableId).startTournament(sessionId);
if (controllers.containsKey(tableId))
controllers.get(tableId).startTournament(sessionId);
}
public void startDraft(UUID tableId, Draft draft) {
controllers.get(tableId).startDraft(draft);
if (controllers.containsKey(tableId))
controllers.get(tableId).startDraft(draft);
}
public boolean watchTable(UUID sessionId, UUID tableId) {
return controllers.get(tableId).watchTable(sessionId);
if (controllers.containsKey(tableId))
return controllers.get(tableId).watchTable(sessionId);
return false;
}
public boolean replayTable(UUID sessionId, UUID tableId) {
return controllers.get(tableId).replayTable(sessionId);
if (controllers.containsKey(tableId))
return controllers.get(tableId).replayTable(sessionId);
return false;
}
public void endGame(UUID tableId) {
controllers.get(tableId).endGame();
if (controllers.containsKey(tableId))
controllers.get(tableId).endGame();
}
public void endDraft(UUID tableId, Draft draft) {
controllers.get(tableId).endDraft(draft);
if (controllers.containsKey(tableId))
controllers.get(tableId).endDraft(draft);
}
public void swapSeats(UUID tableId, UUID sessionId, int seatNum1, int seatNum2) {
if (isTableOwner(tableId, sessionId)) {
if (controllers.containsKey(tableId) && isTableOwner(tableId, sessionId)) {
controllers.get(tableId).swapSeats(seatNum1, seatNum2);
}
}
public void construct(UUID tableId) {
controllers.get(tableId).construct();
if (controllers.containsKey(tableId))
controllers.get(tableId).construct();
}
public void addPlayer(UUID sessionId, UUID tableId, Player player, String playerType, Deck deck) throws GameException {
controllers.get(tableId).addPlayer(sessionId, player, playerType, deck);
if (controllers.containsKey(tableId))
controllers.get(tableId).addPlayer(sessionId, player, playerType, deck);
}
public void removeTable(UUID tableId) {
if (tables.containsKey(tableId)) {
Table table = tables.get(tableId);
table.getMatch().getGame().end();
}
controllers.remove(tableId);
tables.remove(tableId);
GamesRoomManager.getInstance().removeTable(tableId);
}
}

View file

@ -56,7 +56,8 @@ public class GameManager {
}
public void joinGame(UUID gameId, UUID sessionId) {
gameControllers.get(gameId).join(sessionId);
if (gameControllers.containsKey(gameId))
gameControllers.get(gameId).join(sessionId);
}
public void destroyChatSession(UUID gameId) {
@ -70,31 +71,38 @@ public class GameManager {
}
public void sendPlayerUUID(UUID gameId, UUID sessionId, UUID data) {
gameControllers.get(gameId).sendPlayerUUID(sessionId, data);
if (gameControllers.containsKey(gameId))
gameControllers.get(gameId).sendPlayerUUID(sessionId, data);
}
public void sendPlayerString(UUID gameId, UUID sessionId, String data) {
gameControllers.get(gameId).sendPlayerString(sessionId, data);
if (gameControllers.containsKey(gameId))
gameControllers.get(gameId).sendPlayerString(sessionId, data);
}
public void sendPlayerBoolean(UUID gameId, UUID sessionId, Boolean data) {
gameControllers.get(gameId).sendPlayerBoolean(sessionId, data);
if (gameControllers.containsKey(gameId))
gameControllers.get(gameId).sendPlayerBoolean(sessionId, data);
}
public void sendPlayerInteger(UUID gameId, UUID sessionId, Integer data) {
gameControllers.get(gameId).sendPlayerInteger(sessionId, data);
if (gameControllers.containsKey(gameId))
gameControllers.get(gameId).sendPlayerInteger(sessionId, data);
}
public void concedeGame(UUID gameId, UUID sessionId) {
gameControllers.get(gameId).concede(sessionId);
if (gameControllers.containsKey(gameId))
gameControllers.get(gameId).concede(sessionId);
}
public void watchGame(UUID gameId, UUID sessionId) {
gameControllers.get(gameId).watch(sessionId);
if (gameControllers.containsKey(gameId))
gameControllers.get(gameId).watch(sessionId);
}
public void stopWatching(UUID gameId, UUID sessionId) {
gameControllers.get(gameId).stopWatching(sessionId);
if (gameControllers.containsKey(gameId))
gameControllers.get(gameId).stopWatching(sessionId);
}
public void removeSession(UUID sessionId) {
@ -104,19 +112,24 @@ public class GameManager {
}
public void kill(UUID gameId, UUID sessionId) {
gameControllers.get(gameId).kill(sessionId);
if (gameControllers.containsKey(gameId))
gameControllers.get(gameId).kill(sessionId);
}
public void cheat(UUID gameId, UUID sessionId, UUID playerId, DeckCardLists deckList) {
gameControllers.get(gameId).cheat(sessionId, playerId, deckList);
if (gameControllers.containsKey(gameId))
gameControllers.get(gameId).cheat(sessionId, playerId, deckList);
}
public boolean cheat(UUID gameId, UUID sessionId, UUID playerId, String cardName) {
return gameControllers.get(gameId).cheat(sessionId, playerId, cardName);
if (gameControllers.containsKey(gameId))
return gameControllers.get(gameId).cheat(sessionId, playerId, cardName);
return false;
}
public void timeout(UUID gameId, UUID sessionId) {
gameControllers.get(gameId).timeout(sessionId);
if (gameControllers.containsKey(gameId))
gameControllers.get(gameId).timeout(sessionId);
}
public void removeGame(UUID gameId) {
@ -124,11 +137,14 @@ public class GameManager {
}
public void saveGame(UUID gameId) {
gameControllers.get(gameId).saveGame();
if (gameControllers.containsKey(gameId))
gameControllers.get(gameId).saveGame();
}
public GameView getGameView(UUID gameId, UUID sessionId, UUID playerId) {
return gameControllers.get(gameId).getGameView(playerId);
if (gameControllers.containsKey(gameId))
return gameControllers.get(gameId).getGameView(playerId);
return null;
}
}

View file

@ -49,9 +49,9 @@ public interface GamesRoom extends Room {
public TableView createTable(UUID sessionId, MatchOptions options);
public TableView createTournamentTable(UUID sessionId, TournamentOptions options);
public void removeTable(UUID sessionId, UUID tableId);
public void removeTable(UUID tableId);
public TableView getTable(UUID tableId);
public void leaveTable(UUID sessionId, UUID tableId);
public boolean watchTable(UUID sessionId, UUID tableId);
}

View file

@ -49,7 +49,7 @@ import org.apache.log4j.Logger;
*/
public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
// private final static Logger logger = Logger.getLogger(GamesRoomImpl.class);
private final static Logger logger = Logger.getLogger(GamesRoomImpl.class);
private ConcurrentHashMap<UUID, Table> tables = new ConcurrentHashMap<UUID, Table>();
@ -103,9 +103,14 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
@Override
public void removeTable(UUID sessionId, UUID tableId) {
if (TableManager.getInstance().removeTable(sessionId, tableId)) {
tables.remove(tableId);
}
tables.remove(tableId);
}
@Override
public void removeTable(UUID tableId) {
tables.remove(tableId);
if (logger.isDebugEnabled())
logger.debug("Table removed: " + tableId);
}
@Override

View file

@ -67,5 +67,11 @@ public class GamesRoomManager {
public GamesRoom getRoom(UUID roomId) {
return rooms.get(roomId);
}
public void removeTable(UUID tableId) {
for (GamesRoom room: rooms.values()) {
room.removeTable(tableId);
}
}
}