[minor] formatting

This commit is contained in:
LevelX2 2013-03-26 13:43:24 +01:00
parent cb18bf2bd4
commit d8961a7a82
4 changed files with 205 additions and 118 deletions

View file

@ -28,9 +28,7 @@
package mage.client.table; package mage.client.table;
import java.util.UUID; import java.util.UUID;
import javax.swing.JComponent; import javax.swing.JComponent;
import mage.client.MageFrame; import mage.client.MageFrame;
import mage.client.MagePane; import mage.client.MagePane;
import mage.client.plugins.impl.Plugins; import mage.client.plugins.impl.Plugins;

View file

@ -34,6 +34,18 @@
package mage.client.table; package mage.client.table;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.beans.PropertyVetoException;
import java.io.File;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.List;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
import javax.swing.*;
import javax.swing.table.AbstractTableModel;
import mage.Constants.MultiplayerAttackOption; import mage.Constants.MultiplayerAttackOption;
import mage.Constants.RangeOfInfluence; import mage.Constants.RangeOfInfluence;
import mage.cards.decks.importer.DeckImporterUtil; import mage.cards.decks.importer.DeckImporterUtil;
@ -53,18 +65,6 @@ import mage.view.MatchView;
import mage.view.TableView; import mage.view.TableView;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import javax.swing.*;
import javax.swing.table.AbstractTableModel;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.beans.PropertyVetoException;
import java.io.File;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.List;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
/** /**
@ -114,7 +114,8 @@ public class TablesPanel extends javax.swing.JPanel {
jScrollPane1.getViewport().setBackground(new Color(255,255,255,50)); jScrollPane1.getViewport().setBackground(new Color(255,255,255,50));
jScrollPane2.getViewport().setBackground(new Color(255,255,255,50)); jScrollPane2.getViewport().setBackground(new Color(255,255,255,50));
Action joinTable = new AbstractAction() Action joinTable;
joinTable = new AbstractAction()
{ {
@Override @Override
public void actionPerformed(ActionEvent e) public void actionPerformed(ActionEvent e)
@ -239,20 +240,24 @@ public class TablesPanel extends javax.swing.JPanel {
} }
} }
else { else {
if (updateMatchesTask != null) if (updateMatchesTask != null) {
updateMatchesTask.cancel(true); updateMatchesTask.cancel(true);
} }
} }
} }
}
public void stopTasks() { public void stopTasks() {
if (updateTablesTask != null) if (updateTablesTask != null) {
updateTablesTask.cancel(true); updateTablesTask.cancel(true);
if (updatePlayersTask != null) }
if (updatePlayersTask != null) {
updatePlayersTask.cancel(true); updatePlayersTask.cancel(true);
if (updateMatchesTask != null) }
if (updateMatchesTask != null) {
updateMatchesTask.cancel(true); updateMatchesTask.cancel(true);
} }
}
public void showTables(UUID roomId) { public void showTables(UUID roomId) {
this.roomId = roomId; this.roomId = roomId;
@ -319,9 +324,10 @@ public class TablesPanel extends javax.swing.JPanel {
while (c != null && !(c instanceof TablesPane)) { while (c != null && !(c instanceof TablesPane)) {
c = c.getParent(); c = c.getParent();
} }
if (c != null) if (c != null) {
((TablesPane)c).hideFrame(); ((TablesPane)c).hideFrame();
} }
}
/** This method is called from within the constructor to /** This method is called from within the constructor to
* initialize the form. * initialize the form.
@ -658,8 +664,9 @@ class TableTableModel extends AbstractTableModel {
case 7: case 7:
return tables[arg0].isTournament(); return tables[arg0].isTournament();
case 8: case 8:
if (!tables[arg0].getGames().isEmpty()) if (!tables[arg0].getGames().isEmpty()) {
return tables[arg0].getGames().get(0); return tables[arg0].getGames().get(0);
}
return null; return null;
case 9: case 9:
return tables[arg0].getTableId(); return tables[arg0].getTableId();
@ -671,8 +678,9 @@ class TableTableModel extends AbstractTableModel {
public String getColumnName(int columnIndex) { public String getColumnName(int columnIndex) {
String colName = ""; String colName = "";
if (columnIndex <= getColumnCount()) if (columnIndex <= getColumnCount()) {
colName = columnNames[columnIndex]; colName = columnNames[columnIndex];
}
return colName; return colName;
} }
@ -684,8 +692,9 @@ class TableTableModel extends AbstractTableModel {
@Override @Override
public boolean isCellEditable(int rowIndex, int columnIndex) { public boolean isCellEditable(int rowIndex, int columnIndex) {
if (columnIndex != 6) if (columnIndex != 6) {
return false; return false;
}
return true; return true;
} }
@ -711,7 +720,9 @@ class UpdateTablesTask extends SwingWorker<Void, Collection<TableView>> {
protected Void doInBackground() throws Exception { protected Void doInBackground() throws Exception {
while (!isCancelled()) { while (!isCancelled()) {
Collection<TableView> tables = session.getTables(roomId); Collection<TableView> tables = session.getTables(roomId);
if (tables != null) this.publish(tables); if (tables != null) {
this.publish(tables);
}
Thread.sleep(1000); Thread.sleep(1000);
} }
return null; return null;
@ -826,8 +837,9 @@ class MatchesTableModel extends AbstractTableModel {
public String getColumnName(int columnIndex) { public String getColumnName(int columnIndex) {
String colName = ""; String colName = "";
if (columnIndex <= getColumnCount()) if (columnIndex <= getColumnCount()) {
colName = columnNames[columnIndex]; colName = columnNames[columnIndex];
}
return colName; return colName;
} }
@ -839,8 +851,9 @@ class MatchesTableModel extends AbstractTableModel {
@Override @Override
public boolean isCellEditable(int rowIndex, int columnIndex) { public boolean isCellEditable(int rowIndex, int columnIndex) {
if (columnIndex != 5) if (columnIndex != 5) {
return false; return false;
}
return true; return true;
} }
@ -864,7 +877,9 @@ class UpdateMatchesTask extends SwingWorker<Void, Collection<MatchView>> {
protected Void doInBackground() throws Exception { protected Void doInBackground() throws Exception {
while (!isCancelled()) { while (!isCancelled()) {
Collection<MatchView> matches = session.getFinishedMatches(roomId); Collection<MatchView> matches = session.getFinishedMatches(roomId);
if (matches != null) this.publish(matches); if (matches != null) {
this.publish(matches);
}
Thread.sleep(5000); Thread.sleep(5000);
} }
return null; return null;
@ -897,7 +912,9 @@ class GameChooser extends JPopupMenu {
} }
public void show(List<UUID> games, Point p) { public void show(List<UUID> games, Point p) {
if (p == null) return; if (p == null) {
return;
}
this.removeAll(); this.removeAll();
for (UUID gameId: games) { for (UUID gameId: games) {
this.add(new GameChooserAction(gameId, gameId.toString())); this.add(new GameChooserAction(gameId, gameId.toString()));

View file

@ -28,6 +28,8 @@
package mage.remote; package mage.remote;
import java.net.*;
import java.util.*;
import mage.MageException; import mage.MageException;
import mage.cards.decks.DeckCardLists; import mage.cards.decks.DeckCardLists;
import mage.cards.decks.InvalidDeckException; import mage.cards.decks.InvalidDeckException;
@ -51,8 +53,6 @@ import org.jboss.remoting.transport.bisocket.Bisocket;
import org.jboss.remoting.transport.socket.SocketWrapper; import org.jboss.remoting.transport.socket.SocketWrapper;
import org.jboss.remoting.transporter.TransporterClient; import org.jboss.remoting.transporter.TransporterClient;
import java.net.*;
import java.util.*;
/** /**
* *
@ -164,7 +164,7 @@ public class SessionImpl implements Session {
callbackClient.invoke(""); callbackClient.invoke("");
this.sessionId = callbackClient.getSessionId(); this.sessionId = callbackClient.getSessionId();
boolean registerResult = false; boolean registerResult;
if (connection.getPassword() == null) { if (connection.getPassword() == null) {
UserDataView userDataView = new UserDataView(connection.getAvatarId()); UserDataView userDataView = new UserDataView(connection.getAvatarId());
// for backward compatibility. don't remove twice call - first one does nothing but for version checking // for backward compatibility. don't remove twice call - first one does nothing but for version checking
@ -238,10 +238,12 @@ public class SessionImpl implements Session {
@Override @Override
public synchronized void disconnect(boolean showMessage) { public synchronized void disconnect(boolean showMessage) {
if (isConnected()) if (isConnected()) {
sessionState = SessionState.DISCONNECTING; sessionState = SessionState.DISCONNECTING;
if (connection == null) }
if (connection == null) {
return; return;
}
try { try {
callbackClient.disconnect(); callbackClient.disconnect();
TransporterClient.destroyTransporterClient(server); TransporterClient.destroyTransporterClient(server);
@ -253,9 +255,10 @@ public class SessionImpl implements Session {
logger.info("Disconnected ... "); logger.info("Disconnected ... ");
} }
client.disconnected(); client.disconnected();
if (showMessage) if (showMessage) {
client.showError("Network error. You have been disconnected"); client.showError("Network error. You have been disconnected");
} }
}
@Override @Override
public synchronized boolean sendFeedback(String title, String type, String message, String email) { public synchronized boolean sendFeedback(String title, String type, String message, String email) {
@ -288,8 +291,9 @@ public class SessionImpl implements Session {
@Override @Override
public boolean isConnected() { public boolean isConnected() {
if (callbackClient == null) if (callbackClient == null) {
return false; return false;
}
return callbackClient.isConnected(); return callbackClient.isConnected();
} }
@ -315,16 +319,18 @@ public class SessionImpl implements Session {
@Override @Override
public boolean isTestMode() { public boolean isTestMode() {
if (serverState != null) if (serverState != null) {
return serverState.isTestMode(); return serverState.isTestMode();
}
return false; return false;
} }
@Override @Override
public UUID getMainRoomId() { public UUID getMainRoomId() {
try { try {
if (isConnected()) if (isConnected()) {
return server.getMainRoomId(); return server.getMainRoomId();
}
} catch (MageException ex) { } catch (MageException ex) {
handleMageException(ex); handleMageException(ex);
} catch (Throwable t) { } catch (Throwable t) {
@ -336,8 +342,9 @@ public class SessionImpl implements Session {
@Override @Override
public UUID getRoomChatId(UUID roomId) { public UUID getRoomChatId(UUID roomId) {
try { try {
if (isConnected()) if (isConnected()) {
return server.getRoomChatId(roomId); return server.getRoomChatId(roomId);
}
} catch (MageException ex) { } catch (MageException ex) {
handleMageException(ex); handleMageException(ex);
} catch (Throwable t) { } catch (Throwable t) {
@ -349,8 +356,9 @@ public class SessionImpl implements Session {
@Override @Override
public UUID getTableChatId(UUID tableId) { public UUID getTableChatId(UUID tableId) {
try { try {
if (isConnected()) if (isConnected()) {
return server.getTableChatId(tableId); return server.getTableChatId(tableId);
}
} catch (MageException ex) { } catch (MageException ex) {
handleMageException(ex); handleMageException(ex);
} catch (Throwable t) { } catch (Throwable t) {
@ -362,8 +370,9 @@ public class SessionImpl implements Session {
@Override @Override
public UUID getGameChatId(UUID gameId) { public UUID getGameChatId(UUID gameId) {
try { try {
if (isConnected()) if (isConnected()) {
return server.getGameChatId(gameId); return server.getGameChatId(gameId);
}
} catch (MageException ex) { } catch (MageException ex) {
handleMageException(ex); handleMageException(ex);
} catch (Throwable t) { } catch (Throwable t) {
@ -375,8 +384,9 @@ public class SessionImpl implements Session {
@Override @Override
public TableView getTable(UUID roomId, UUID tableId) { public TableView getTable(UUID roomId, UUID tableId) {
try { try {
if (isConnected()) if (isConnected()) {
return server.getTable(roomId, tableId); return server.getTable(roomId, tableId);
}
} catch (MageException ex) { } catch (MageException ex) {
handleMageException(ex); handleMageException(ex);
} catch (Throwable t) { } catch (Throwable t) {
@ -403,8 +413,9 @@ public class SessionImpl implements Session {
@Override @Override
public boolean joinTable(UUID roomId, UUID tableId, String playerName, String playerType, int skill, DeckCardLists deckList) { public boolean joinTable(UUID roomId, UUID tableId, String playerName, String playerType, int skill, DeckCardLists deckList) {
try { try {
if (isConnected()) if (isConnected()) {
return server.joinTable(sessionId, roomId, tableId, playerName, playerType, skill, deckList); return server.joinTable(sessionId, roomId, tableId, playerName, playerType, skill, deckList);
}
} catch (InvalidDeckException iex) { } catch (InvalidDeckException iex) {
handleInvalidDeckException(iex); handleInvalidDeckException(iex);
} catch (GameException ex) { } catch (GameException ex) {
@ -420,8 +431,9 @@ public class SessionImpl implements Session {
@Override @Override
public boolean joinTournamentTable(UUID roomId, UUID tableId, String playerName, String playerType, int skill) { public boolean joinTournamentTable(UUID roomId, UUID tableId, String playerName, String playerType, int skill) {
try { try {
if (isConnected()) if (isConnected()) {
return server.joinTournamentTable(sessionId, roomId, tableId, playerName, playerType, skill); return server.joinTournamentTable(sessionId, roomId, tableId, playerName, playerType, skill);
}
} catch (GameException ex) { } catch (GameException ex) {
handleGameException(ex); handleGameException(ex);
} catch (MageException ex) { } catch (MageException ex) {
@ -435,8 +447,9 @@ public class SessionImpl implements Session {
@Override @Override
public Collection<TableView> getTables(UUID roomId) throws MageRemoteException { public Collection<TableView> getTables(UUID roomId) throws MageRemoteException {
try { try {
if (isConnected()) if (isConnected()) {
return server.getTables(roomId); return server.getTables(roomId);
}
} catch (MageException ex) { } catch (MageException ex) {
handleMageException(ex); handleMageException(ex);
throw new MageRemoteException(); throw new MageRemoteException();
@ -449,8 +462,9 @@ public class SessionImpl implements Session {
@Override @Override
public Collection<MatchView> getFinishedMatches(UUID roomId) throws MageRemoteException { public Collection<MatchView> getFinishedMatches(UUID roomId) throws MageRemoteException {
try { try {
if (isConnected()) if (isConnected()) {
return server.getFinishedMatches(roomId); return server.getFinishedMatches(roomId);
}
} catch (MageException ex) { } catch (MageException ex) {
handleMageException(ex); handleMageException(ex);
throw new MageRemoteException(); throw new MageRemoteException();
@ -463,8 +477,9 @@ public class SessionImpl implements Session {
@Override @Override
public Collection<String> getConnectedPlayers(UUID roomId) throws MageRemoteException { public Collection<String> getConnectedPlayers(UUID roomId) throws MageRemoteException {
try { try {
if (isConnected()) if (isConnected()) {
return server.getConnectedPlayers(roomId); return server.getConnectedPlayers(roomId);
}
} catch (MageException ex) { } catch (MageException ex) {
handleMageException(ex); handleMageException(ex);
throw new MageRemoteException(); throw new MageRemoteException();
@ -477,8 +492,9 @@ public class SessionImpl implements Session {
@Override @Override
public TournamentView getTournament(UUID tournamentId) throws MageRemoteException { public TournamentView getTournament(UUID tournamentId) throws MageRemoteException {
try { try {
if (isConnected()) if (isConnected()) {
return server.getTournament(tournamentId); return server.getTournament(tournamentId);
}
} catch (MageException ex) { } catch (MageException ex) {
handleMageException(ex); handleMageException(ex);
throw new MageRemoteException(); throw new MageRemoteException();
@ -491,8 +507,9 @@ public class SessionImpl implements Session {
@Override @Override
public UUID getTournamentChatId(UUID tournamentId) { public UUID getTournamentChatId(UUID tournamentId) {
try { try {
if (isConnected()) if (isConnected()) {
return server.getTournamentChatId(tournamentId); return server.getTournamentChatId(tournamentId);
}
} catch (MageException ex) { } catch (MageException ex) {
handleMageException(ex); handleMageException(ex);
} catch (Throwable t) { } catch (Throwable t) {
@ -564,8 +581,9 @@ public class SessionImpl implements Session {
@Override @Override
public DraftPickView sendCardPick(UUID draftId, UUID cardId) { public DraftPickView sendCardPick(UUID draftId, UUID cardId) {
try { try {
if (isConnected()) if (isConnected()) {
return server.sendCardPick(draftId, sessionId, cardId); return server.sendCardPick(draftId, sessionId, cardId);
}
} catch (MageException ex) { } catch (MageException ex) {
handleMageException(ex); handleMageException(ex);
} catch (Throwable t) { } catch (Throwable t) {
@ -718,8 +736,9 @@ public class SessionImpl implements Session {
@Override @Override
public TableView createTable(UUID roomId, MatchOptions matchOptions) { public TableView createTable(UUID roomId, MatchOptions matchOptions) {
try { try {
if (isConnected()) if (isConnected()) {
return server.createTable(sessionId, roomId, matchOptions); return server.createTable(sessionId, roomId, matchOptions);
}
} catch (MageException ex) { } catch (MageException ex) {
handleMageException(ex); handleMageException(ex);
} catch (Throwable t) { } catch (Throwable t) {
@ -731,8 +750,9 @@ public class SessionImpl implements Session {
@Override @Override
public TableView createTournamentTable(UUID roomId, TournamentOptions tournamentOptions) { public TableView createTournamentTable(UUID roomId, TournamentOptions tournamentOptions) {
try { try {
if (isConnected()) if (isConnected()) {
return server.createTournamentTable(sessionId, roomId, tournamentOptions); return server.createTournamentTable(sessionId, roomId, tournamentOptions);
}
} catch (MageException ex) { } catch (MageException ex) {
handleMageException(ex); handleMageException(ex);
} catch (Throwable t) { } catch (Throwable t) {
@ -744,8 +764,9 @@ public class SessionImpl implements Session {
@Override @Override
public boolean isTableOwner(UUID roomId, UUID tableId) { public boolean isTableOwner(UUID roomId, UUID tableId) {
try { try {
if (isConnected()) if (isConnected()) {
return server.isTableOwner(sessionId, roomId, tableId); return server.isTableOwner(sessionId, roomId, tableId);
}
} catch (MageException ex) { } catch (MageException ex) {
handleMageException(ex); handleMageException(ex);
} catch (Throwable t) { } catch (Throwable t) {
@ -862,8 +883,9 @@ public class SessionImpl implements Session {
@Override @Override
public boolean submitDeck(UUID tableId, DeckCardLists deck) { public boolean submitDeck(UUID tableId, DeckCardLists deck) {
try { try {
if (isConnected()) if (isConnected()) {
return server.submitDeck(sessionId, tableId, deck); return server.submitDeck(sessionId, tableId, deck);
}
} catch (GameException ex) { } catch (GameException ex) {
handleGameException(ex); handleGameException(ex);
} catch (MageException ex) { } catch (MageException ex) {
@ -1014,8 +1036,9 @@ public class SessionImpl implements Session {
@Override @Override
public List<UserView> getUsers() { public List<UserView> getUsers() {
try { try {
if (isConnected()) if (isConnected()) {
return server.getUsers(sessionId); return server.getUsers(sessionId);
}
} catch (MageException ex) { } catch (MageException ex) {
handleMageException(ex); handleMageException(ex);
} catch (Throwable t) { } catch (Throwable t) {
@ -1027,8 +1050,9 @@ public class SessionImpl implements Session {
@Override @Override
public List<String> getServerMessages() { public List<String> getServerMessages() {
try { try {
if (isConnected()) if (isConnected()) {
return (List<String>) CompressUtil.decompress(server.getServerMessagesCompressed(sessionId)); return (List<String>) CompressUtil.decompress(server.getServerMessagesCompressed(sessionId));
}
} catch (MageException ex) { } catch (MageException ex) {
handleMageException(ex); handleMageException(ex);
} catch (Throwable t) { } catch (Throwable t) {

View file

@ -28,6 +28,10 @@
package mage.server; package mage.server;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import mage.MageException; import mage.MageException;
import mage.cards.decks.DeckCardLists; import mage.cards.decks.DeckCardLists;
import mage.game.GameException; import mage.game.GameException;
@ -53,10 +57,6 @@ import mage.view.*;
import mage.view.ChatMessage.MessageColor; import mage.view.ChatMessage.MessageColor;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
//import mage.interfaces.Server; //import mage.interfaces.Server;
@ -88,8 +88,9 @@ public class MageServerImpl implements MageServer {
} }
return SessionManager.getInstance().registerUser(sessionId, userName); return SessionManager.getInstance().registerUser(sessionId, userName);
} catch (Exception ex) { } catch (Exception ex) {
if (ex instanceof MageVersionException) if (ex instanceof MageVersionException) {
throw (MageVersionException)ex; throw (MageVersionException)ex;
}
handleException(ex); handleException(ex);
} }
return false; return false;
@ -98,6 +99,7 @@ public class MageServerImpl implements MageServer {
@Override @Override
public boolean setUserData(final String userName, final String sessionId, final UserDataView userDataView) throws MageException { public boolean setUserData(final String userName, final String sessionId, final UserDataView userDataView) throws MageException {
return executeWithResult("setUserData", sessionId, new ActionWithBooleanResult() { return executeWithResult("setUserData", sessionId, new ActionWithBooleanResult() {
@Override
public Boolean execute() throws MageException { public Boolean execute() throws MageException {
return SessionManager.getInstance().setUserData(userName, sessionId, userDataView); return SessionManager.getInstance().setUserData(userName, sessionId, userDataView);
} }
@ -107,10 +109,12 @@ public class MageServerImpl implements MageServer {
@Override @Override
public boolean registerAdmin(String password, String sessionId, MageVersion version) throws MageException { public boolean registerAdmin(String password, String sessionId, MageVersion version) throws MageException {
try { try {
if (version.compareTo(Main.getVersion()) != 0) if (version.compareTo(Main.getVersion()) != 0) {
throw new MageException("Wrong client version " + version + ", expecting version " + Main.getVersion()); throw new MageException("Wrong client version " + version + ", expecting version " + Main.getVersion());
if (!password.equals(this.password)) }
if (!password.equals(this.password)) {
throw new MageException("Wrong password"); throw new MageException("Wrong password");
}
return SessionManager.getInstance().registerAdmin(sessionId); return SessionManager.getInstance().registerAdmin(sessionId);
} catch (Exception ex) { } catch (Exception ex) {
handleException(ex); handleException(ex);
@ -121,6 +125,7 @@ public class MageServerImpl implements MageServer {
@Override @Override
public TableView createTable(final String sessionId, final UUID roomId, final MatchOptions options) throws MageException { public TableView createTable(final String sessionId, final UUID roomId, final MatchOptions options) throws MageException {
return executeWithResult("createTable", sessionId, new ActionWithTableViewResult() { return executeWithResult("createTable", sessionId, new ActionWithTableViewResult() {
@Override
public TableView execute() throws MageException { public TableView execute() throws MageException {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId(); UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
TableView table = GamesRoomManager.getInstance().getRoom(roomId).createTable(userId, options); TableView table = GamesRoomManager.getInstance().getRoom(roomId).createTable(userId, options);
@ -134,6 +139,7 @@ public class MageServerImpl implements MageServer {
@Override @Override
public TableView createTournamentTable(final String sessionId, final UUID roomId, final TournamentOptions options) throws MageException { public TableView createTournamentTable(final String sessionId, final UUID roomId, final TournamentOptions options) throws MageException {
return executeWithResult("createTournamentTable", sessionId, new ActionWithTableViewResult() { return executeWithResult("createTournamentTable", sessionId, new ActionWithTableViewResult() {
@Override
public TableView execute() throws MageException { public TableView execute() throws MageException {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId(); UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
TableView table = GamesRoomManager.getInstance().getRoom(roomId).createTournamentTable(userId, options); TableView table = GamesRoomManager.getInstance().getRoom(roomId).createTournamentTable(userId, options);
@ -147,6 +153,7 @@ public class MageServerImpl implements MageServer {
@Override @Override
public void removeTable(final String sessionId, final UUID roomId, final UUID tableId) throws MageException { public void removeTable(final String sessionId, final UUID roomId, final UUID tableId) throws MageException {
execute("removeTable", sessionId, new Action() { execute("removeTable", sessionId, new Action() {
@Override
public void execute() { public void execute() {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId(); UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
TableManager.getInstance().removeTable(userId, tableId); TableManager.getInstance().removeTable(userId, tableId);
@ -157,6 +164,7 @@ public class MageServerImpl implements MageServer {
@Override @Override
public boolean joinTable(final String sessionId, final UUID roomId, final UUID tableId, final String name, final String playerType, final int skill, final DeckCardLists deckList) throws MageException, GameException { public boolean joinTable(final String sessionId, final UUID roomId, final UUID tableId, final String name, final String playerType, final int skill, final DeckCardLists deckList) throws MageException, GameException {
return executeWithResult("joinTable", sessionId, new ActionWithBooleanResult() { return executeWithResult("joinTable", sessionId, new ActionWithBooleanResult() {
@Override
public Boolean execute() throws MageException { public Boolean execute() throws MageException {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId(); UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
boolean ret = GamesRoomManager.getInstance().getRoom(roomId).joinTable(userId, tableId, name, playerType, skill, deckList); boolean ret = GamesRoomManager.getInstance().getRoom(roomId).joinTable(userId, tableId, name, playerType, skill, deckList);
@ -169,6 +177,7 @@ public class MageServerImpl implements MageServer {
@Override @Override
public boolean joinTournamentTable(final String sessionId, final UUID roomId, final UUID tableId, final String name, final String playerType, final int skill) throws MageException, GameException { public boolean joinTournamentTable(final String sessionId, final UUID roomId, final UUID tableId, final String name, final String playerType, final int skill) throws MageException, GameException {
return executeWithResult("joinTournamentTable", sessionId, new ActionWithBooleanResult() { return executeWithResult("joinTournamentTable", sessionId, new ActionWithBooleanResult() {
@Override
public Boolean execute() throws MageException { public Boolean execute() throws MageException {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId(); UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
boolean ret = GamesRoomManager.getInstance().getRoom(roomId).joinTournamentTable(userId, tableId, name, playerType, skill); boolean ret = GamesRoomManager.getInstance().getRoom(roomId).joinTournamentTable(userId, tableId, name, playerType, skill);
@ -181,6 +190,7 @@ public class MageServerImpl implements MageServer {
@Override @Override
public boolean submitDeck(final String sessionId, final UUID tableId, final DeckCardLists deckList) throws MageException, GameException { public boolean submitDeck(final String sessionId, final UUID tableId, final DeckCardLists deckList) throws MageException, GameException {
return executeWithResult("submitDeck", sessionId, new ActionWithBooleanResult() { return executeWithResult("submitDeck", sessionId, new ActionWithBooleanResult() {
@Override
public Boolean execute() throws MageException { public Boolean execute() throws MageException {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId(); UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
boolean ret = TableManager.getInstance().submitDeck(userId, tableId, deckList); boolean ret = TableManager.getInstance().submitDeck(userId, tableId, deckList);
@ -193,6 +203,7 @@ public class MageServerImpl implements MageServer {
@Override @Override
public void updateDeck(final String sessionId, final UUID tableId, final DeckCardLists deckList) throws MageException, GameException { public void updateDeck(final String sessionId, final UUID tableId, final DeckCardLists deckList) throws MageException, GameException {
execute("updateDeck", sessionId, new Action() { execute("updateDeck", sessionId, new Action() {
@Override
public void execute() throws MageException { public void execute() throws MageException {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId(); UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
TableManager.getInstance().updateDeck(userId, tableId, deckList); TableManager.getInstance().updateDeck(userId, tableId, deckList);
@ -257,6 +268,7 @@ public class MageServerImpl implements MageServer {
@Override @Override
public void deregisterClient(final String sessionId) throws MageException { public void deregisterClient(final String sessionId) throws MageException {
execute("deregisterClient", sessionId, new Action() { execute("deregisterClient", sessionId, new Action() {
@Override
public void execute() { public void execute() {
SessionManager.getInstance().disconnect(sessionId, true); SessionManager.getInstance().disconnect(sessionId, true);
logger.info("Client deregistered ..."); logger.info("Client deregistered ...");
@ -267,6 +279,7 @@ public class MageServerImpl implements MageServer {
@Override @Override
public void startMatch(final String sessionId, final UUID roomId, final UUID tableId) throws MageException { public void startMatch(final String sessionId, final UUID roomId, final UUID tableId) throws MageException {
execute("startMatch", sessionId, new Action() { execute("startMatch", sessionId, new Action() {
@Override
public void execute() { public void execute() {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId(); UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
TableManager.getInstance().startMatch(userId, roomId, tableId); TableManager.getInstance().startMatch(userId, roomId, tableId);
@ -277,6 +290,7 @@ public class MageServerImpl implements MageServer {
@Override @Override
public void startChallenge(final String sessionId, final UUID roomId, final UUID tableId, final UUID challengeId) throws MageException { public void startChallenge(final String sessionId, final UUID roomId, final UUID tableId, final UUID challengeId) throws MageException {
execute("startChallenge", sessionId, new Action() { execute("startChallenge", sessionId, new Action() {
@Override
public void execute() { public void execute() {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId(); UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
TableManager.getInstance().startChallenge(userId, roomId, tableId, challengeId); TableManager.getInstance().startChallenge(userId, roomId, tableId, challengeId);
@ -287,6 +301,7 @@ public class MageServerImpl implements MageServer {
@Override @Override
public void startTournament(final String sessionId, final UUID roomId, final UUID tableId) throws MageException { public void startTournament(final String sessionId, final UUID roomId, final UUID tableId) throws MageException {
execute("startTournament", sessionId, new Action() { execute("startTournament", sessionId, new Action() {
@Override
public void execute() { public void execute() {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId(); UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
TableManager.getInstance().startTournament(userId, roomId, tableId); TableManager.getInstance().startTournament(userId, roomId, tableId);
@ -327,6 +342,7 @@ public class MageServerImpl implements MageServer {
@Override @Override
public void joinChat(final UUID chatId, final String sessionId, final String userName) throws MageException { public void joinChat(final UUID chatId, final String sessionId, final String userName) throws MageException {
execute("joinChat", sessionId, new Action() { execute("joinChat", sessionId, new Action() {
@Override
public void execute() { public void execute() {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId(); UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
ChatManager.getInstance().joinChat(chatId, userId); ChatManager.getInstance().joinChat(chatId, userId);
@ -337,6 +353,7 @@ public class MageServerImpl implements MageServer {
@Override @Override
public void leaveChat(final UUID chatId, final String sessionId) throws MageException { public void leaveChat(final UUID chatId, final String sessionId) throws MageException {
execute("leaveChat", sessionId, new Action() { execute("leaveChat", sessionId, new Action() {
@Override
public void execute() { public void execute() {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId(); UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
ChatManager.getInstance().leaveChat(chatId, userId); ChatManager.getInstance().leaveChat(chatId, userId);
@ -371,6 +388,7 @@ public class MageServerImpl implements MageServer {
@Override @Override
public boolean isTableOwner(final String sessionId, UUID roomId, final UUID tableId) throws MageException { public boolean isTableOwner(final String sessionId, UUID roomId, final UUID tableId) throws MageException {
return executeWithResult("isTableOwner", sessionId, new ActionWithBooleanResult() { return executeWithResult("isTableOwner", sessionId, new ActionWithBooleanResult() {
@Override
public Boolean execute() { public Boolean execute() {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId(); UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
return TableManager.getInstance().isTableOwner(tableId, userId); return TableManager.getInstance().isTableOwner(tableId, userId);
@ -381,6 +399,7 @@ public class MageServerImpl implements MageServer {
@Override @Override
public void swapSeats(final String sessionId, final UUID roomId, final UUID tableId, final int seatNum1, final int seatNum2) throws MageException { public void swapSeats(final String sessionId, final UUID roomId, final UUID tableId, final int seatNum1, final int seatNum2) throws MageException {
execute("swapSeats", sessionId, new Action() { execute("swapSeats", sessionId, new Action() {
@Override
public void execute() { public void execute() {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId(); UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
TableManager.getInstance().swapSeats(tableId, userId, seatNum1, seatNum2); TableManager.getInstance().swapSeats(tableId, userId, seatNum1, seatNum2);
@ -391,6 +410,7 @@ public class MageServerImpl implements MageServer {
@Override @Override
public void leaveTable(final String sessionId, final UUID roomId, final UUID tableId) throws MageException { public void leaveTable(final String sessionId, final UUID roomId, final UUID tableId) throws MageException {
execute("leaveTable", sessionId, new Action() { execute("leaveTable", sessionId, new Action() {
@Override
public void execute() { public void execute() {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId(); UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
GamesRoomManager.getInstance().getRoom(roomId).leaveTable(userId, tableId); GamesRoomManager.getInstance().getRoom(roomId).leaveTable(userId, tableId);
@ -413,6 +433,7 @@ public class MageServerImpl implements MageServer {
@Override @Override
public void joinGame(final UUID gameId, final String sessionId) throws MageException { public void joinGame(final UUID gameId, final String sessionId) throws MageException {
execute("joinGame", sessionId, new Action() { execute("joinGame", sessionId, new Action() {
@Override
public void execute() { public void execute() {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId(); UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
GameManager.getInstance().joinGame(gameId, userId); GameManager.getInstance().joinGame(gameId, userId);
@ -423,6 +444,7 @@ public class MageServerImpl implements MageServer {
@Override @Override
public void joinDraft(final UUID draftId, final String sessionId) throws MageException { public void joinDraft(final UUID draftId, final String sessionId) throws MageException {
execute("joinDraft", sessionId, new Action() { execute("joinDraft", sessionId, new Action() {
@Override
public void execute() { public void execute() {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId(); UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
DraftManager.getInstance().joinDraft(draftId, userId); DraftManager.getInstance().joinDraft(draftId, userId);
@ -433,6 +455,7 @@ public class MageServerImpl implements MageServer {
@Override @Override
public void joinTournament(final UUID tournamentId, final String sessionId) throws MageException { public void joinTournament(final UUID tournamentId, final String sessionId) throws MageException {
execute("joinTournament", sessionId, new Action() { execute("joinTournament", sessionId, new Action() {
@Override
public void execute() { public void execute() {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId(); UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
TournamentManager.getInstance().joinTournament(tournamentId, userId); TournamentManager.getInstance().joinTournament(tournamentId, userId);
@ -467,6 +490,7 @@ public class MageServerImpl implements MageServer {
@Override @Override
public void sendPlayerUUID(final UUID gameId, final String sessionId, final UUID data) throws MageException { public void sendPlayerUUID(final UUID gameId, final String sessionId, final UUID data) throws MageException {
execute("sendPlayerUUID", sessionId, new Action() { execute("sendPlayerUUID", sessionId, new Action() {
@Override
public void execute() { public void execute() {
User user = SessionManager.getInstance().getUser(sessionId); User user = SessionManager.getInstance().getUser(sessionId);
if (user != null) { if (user != null) {
@ -481,6 +505,7 @@ public class MageServerImpl implements MageServer {
@Override @Override
public void sendPlayerString(final UUID gameId, final String sessionId, final String data) throws MageException { public void sendPlayerString(final UUID gameId, final String sessionId, final String data) throws MageException {
execute("sendPlayerString", sessionId, new Action() { execute("sendPlayerString", sessionId, new Action() {
@Override
public void execute() { public void execute() {
User user = SessionManager.getInstance().getUser(sessionId); User user = SessionManager.getInstance().getUser(sessionId);
if (user != null) { if (user != null) {
@ -495,6 +520,7 @@ public class MageServerImpl implements MageServer {
@Override @Override
public void sendPlayerBoolean(final UUID gameId, final String sessionId, final Boolean data) throws MageException { public void sendPlayerBoolean(final UUID gameId, final String sessionId, final Boolean data) throws MageException {
execute("sendPlayerBoolean", sessionId, new Action() { execute("sendPlayerBoolean", sessionId, new Action() {
@Override
public void execute() { public void execute() {
User user = SessionManager.getInstance().getUser(sessionId); User user = SessionManager.getInstance().getUser(sessionId);
if (user != null) { if (user != null) {
@ -509,6 +535,7 @@ public class MageServerImpl implements MageServer {
@Override @Override
public void sendPlayerInteger(final UUID gameId, final String sessionId, final Integer data) throws MageException { public void sendPlayerInteger(final UUID gameId, final String sessionId, final Integer data) throws MageException {
execute("sendPlayerInteger", sessionId, new Action() { execute("sendPlayerInteger", sessionId, new Action() {
@Override
public void execute() { public void execute() {
User user = SessionManager.getInstance().getUser(sessionId); User user = SessionManager.getInstance().getUser(sessionId);
if (user != null) { if (user != null) {
@ -523,6 +550,7 @@ public class MageServerImpl implements MageServer {
@Override @Override
public DraftPickView sendCardPick(final UUID draftId, final String sessionId, final UUID cardPick) throws MageException { public DraftPickView sendCardPick(final UUID draftId, final String sessionId, final UUID cardPick) throws MageException {
return executeWithResult("sendCardPick", sessionId, new ActionWithNullNegativeResult<DraftPickView>() { return executeWithResult("sendCardPick", sessionId, new ActionWithNullNegativeResult<DraftPickView>() {
@Override
public DraftPickView execute() { public DraftPickView execute() {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId(); UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
return DraftManager.getInstance().sendCardPick(draftId, userId, cardPick); return DraftManager.getInstance().sendCardPick(draftId, userId, cardPick);
@ -533,6 +561,7 @@ public class MageServerImpl implements MageServer {
@Override @Override
public void concedeGame(final UUID gameId, final String sessionId) throws MageException { public void concedeGame(final UUID gameId, final String sessionId) throws MageException {
execute("concedeGame", sessionId, new Action() { execute("concedeGame", sessionId, new Action() {
@Override
public void execute() { public void execute() {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId(); UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
GameManager.getInstance().concedeGame(gameId, userId); GameManager.getInstance().concedeGame(gameId, userId);
@ -543,6 +572,7 @@ public class MageServerImpl implements MageServer {
@Override @Override
public boolean watchTable(final String sessionId, final UUID roomId, final UUID tableId) throws MageException { public boolean watchTable(final String sessionId, final UUID roomId, final UUID tableId) throws MageException {
return executeWithResult("setUserData", sessionId, new ActionWithBooleanResult() { return executeWithResult("setUserData", sessionId, new ActionWithBooleanResult() {
@Override
public Boolean execute() throws MageException { public Boolean execute() throws MageException {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId(); UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
return GamesRoomManager.getInstance().getRoom(roomId).watchTable(userId, tableId); return GamesRoomManager.getInstance().getRoom(roomId).watchTable(userId, tableId);
@ -553,6 +583,7 @@ public class MageServerImpl implements MageServer {
@Override @Override
public void watchGame(final UUID gameId, final String sessionId) throws MageException { public void watchGame(final UUID gameId, final String sessionId) throws MageException {
execute("watchGame", sessionId, new Action() { execute("watchGame", sessionId, new Action() {
@Override
public void execute() { public void execute() {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId(); UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
GameManager.getInstance().watchGame(gameId, userId); GameManager.getInstance().watchGame(gameId, userId);
@ -563,6 +594,7 @@ public class MageServerImpl implements MageServer {
@Override @Override
public void stopWatching(final UUID gameId, final String sessionId) throws MageException { public void stopWatching(final UUID gameId, final String sessionId) throws MageException {
execute("stopWatching", sessionId, new Action() { execute("stopWatching", sessionId, new Action() {
@Override
public void execute() { public void execute() {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId(); UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
GameManager.getInstance().stopWatching(gameId, userId); GameManager.getInstance().stopWatching(gameId, userId);
@ -573,6 +605,7 @@ public class MageServerImpl implements MageServer {
@Override @Override
public void replayGame(final UUID gameId, final String sessionId) throws MageException { public void replayGame(final UUID gameId, final String sessionId) throws MageException {
execute("replayGame", sessionId, new Action() { execute("replayGame", sessionId, new Action() {
@Override
public void execute() { public void execute() {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId(); UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
ReplayManager.getInstance().replayGame(gameId, userId); ReplayManager.getInstance().replayGame(gameId, userId);
@ -583,6 +616,7 @@ public class MageServerImpl implements MageServer {
@Override @Override
public void startReplay(final UUID gameId, final String sessionId) throws MageException { public void startReplay(final UUID gameId, final String sessionId) throws MageException {
execute("startReplay", sessionId, new Action() { execute("startReplay", sessionId, new Action() {
@Override
public void execute() { public void execute() {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId(); UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
ReplayManager.getInstance().startReplay(gameId, userId); ReplayManager.getInstance().startReplay(gameId, userId);
@ -593,6 +627,7 @@ public class MageServerImpl implements MageServer {
@Override @Override
public void stopReplay(final UUID gameId, final String sessionId) throws MageException { public void stopReplay(final UUID gameId, final String sessionId) throws MageException {
execute("stopReplay", sessionId, new Action() { execute("stopReplay", sessionId, new Action() {
@Override
public void execute() { public void execute() {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId(); UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
ReplayManager.getInstance().stopReplay(gameId, userId); ReplayManager.getInstance().stopReplay(gameId, userId);
@ -603,6 +638,7 @@ public class MageServerImpl implements MageServer {
@Override @Override
public void nextPlay(final UUID gameId, final String sessionId) throws MageException { public void nextPlay(final UUID gameId, final String sessionId) throws MageException {
execute("nextPlay", sessionId, new Action() { execute("nextPlay", sessionId, new Action() {
@Override
public void execute() { public void execute() {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId(); UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
ReplayManager.getInstance().nextPlay(gameId, userId); ReplayManager.getInstance().nextPlay(gameId, userId);
@ -613,6 +649,7 @@ public class MageServerImpl implements MageServer {
@Override @Override
public void previousPlay(final UUID gameId, final String sessionId) throws MageException { public void previousPlay(final UUID gameId, final String sessionId) throws MageException {
execute("previousPlay", sessionId, new Action() { execute("previousPlay", sessionId, new Action() {
@Override
public void execute() { public void execute() {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId(); UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
ReplayManager.getInstance().previousPlay(gameId, userId); ReplayManager.getInstance().previousPlay(gameId, userId);
@ -623,6 +660,7 @@ public class MageServerImpl implements MageServer {
@Override @Override
public void skipForward(final UUID gameId, final String sessionId, final int moves) throws MageException { public void skipForward(final UUID gameId, final String sessionId, final int moves) throws MageException {
execute("skipForward", sessionId, new Action() { execute("skipForward", sessionId, new Action() {
@Override
public void execute() { public void execute() {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId(); UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
ReplayManager.getInstance().skipForward(gameId, userId, moves); ReplayManager.getInstance().skipForward(gameId, userId, moves);
@ -651,6 +689,7 @@ public class MageServerImpl implements MageServer {
@Override @Override
public void cheat(final UUID gameId, final String sessionId, final UUID playerId, final DeckCardLists deckList) throws MageException { public void cheat(final UUID gameId, final String sessionId, final UUID playerId, final DeckCardLists deckList) throws MageException {
execute("cheat", sessionId, new Action() { execute("cheat", sessionId, new Action() {
@Override
public void execute() { public void execute() {
if (testMode) { if (testMode) {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId(); UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
@ -663,6 +702,7 @@ public class MageServerImpl implements MageServer {
@Override @Override
public boolean cheat(final UUID gameId, final String sessionId, final UUID playerId, final String cardName) throws MageException { public boolean cheat(final UUID gameId, final String sessionId, final UUID playerId, final String cardName) throws MageException {
return executeWithResult("cheatOne", sessionId, new ActionWithBooleanResult() { return executeWithResult("cheatOne", sessionId, new ActionWithBooleanResult() {
@Override
public Boolean execute() { public Boolean execute() {
if (testMode) { if (testMode) {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId(); UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
@ -681,6 +721,7 @@ public class MageServerImpl implements MageServer {
@Override @Override
public GameView getGameView(final UUID gameId, final String sessionId, final UUID playerId) throws MageException { public GameView getGameView(final UUID gameId, final String sessionId, final UUID playerId) throws MageException {
return executeWithResult("getGameView", sessionId, new ActionWithNullNegativeResult<GameView>() { return executeWithResult("getGameView", sessionId, new ActionWithNullNegativeResult<GameView>() {
@Override
public GameView execute() throws MageException { public GameView execute() throws MageException {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId(); UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
return GameManager.getInstance().getGameView(gameId, userId, playerId); return GameManager.getInstance().getGameView(gameId, userId, playerId);
@ -691,6 +732,7 @@ public class MageServerImpl implements MageServer {
@Override @Override
public List<UserView> getUsers(String sessionId) throws MageException { public List<UserView> getUsers(String sessionId) throws MageException {
return executeWithResult("getUsers", sessionId, new ActionWithNullNegativeResult<List<UserView>>() { return executeWithResult("getUsers", sessionId, new ActionWithNullNegativeResult<List<UserView>>() {
@Override
public List<UserView> execute() throws MageException { public List<UserView> execute() throws MageException {
List<UserView> users = new ArrayList<UserView>(); List<UserView> users = new ArrayList<UserView>();
for (User user : UserManager.getInstance().getUsers()) { for (User user : UserManager.getInstance().getUsers()) {
@ -704,6 +746,7 @@ public class MageServerImpl implements MageServer {
@Override @Override
public void disconnectUser(final String sessionId, final String userSessionId) throws MageException { public void disconnectUser(final String sessionId, final String userSessionId) throws MageException {
execute("disconnectUser", sessionId, new Action() { execute("disconnectUser", sessionId, new Action() {
@Override
public void execute() { public void execute() {
SessionManager.getInstance().disconnectUser(sessionId, userSessionId); SessionManager.getInstance().disconnectUser(sessionId, userSessionId);
} }
@ -713,6 +756,7 @@ public class MageServerImpl implements MageServer {
@Override @Override
public void removeTable(final String sessionId, final UUID tableId) throws MageException { public void removeTable(final String sessionId, final UUID tableId) throws MageException {
execute("removeTable", sessionId, new Action() { execute("removeTable", sessionId, new Action() {
@Override
public void execute() { public void execute() {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId(); UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
TableManager.getInstance().removeTable(userId, tableId); TableManager.getInstance().removeTable(userId, tableId);
@ -723,6 +767,7 @@ public class MageServerImpl implements MageServer {
@Override @Override
public Object getServerMessagesCompressed(String sessionId) throws MageException { public Object getServerMessagesCompressed(String sessionId) throws MageException {
return executeWithResult("getGameView", sessionId, new ActionWithNullNegativeResult<Object>() { return executeWithResult("getGameView", sessionId, new ActionWithNullNegativeResult<Object>() {
@Override
public Object execute() throws MageException { public Object execute() throws MageException {
return CompressUtil.compress(ServerMessagesUtil.getInstance().getMessages()); return CompressUtil.compress(ServerMessagesUtil.getInstance().getMessages());
} }
@ -733,6 +778,7 @@ public class MageServerImpl implements MageServer {
public void sendFeedbackMessage(final String sessionId, final String username, final String title, final String type, final String message, final String email) throws MageException { public void sendFeedbackMessage(final String sessionId, final String username, final String title, final String type, final String message, final String email) throws MageException {
if (title != null && message != null) { if (title != null && message != null) {
execute("sendFeedbackMessage", sessionId, new Action() { execute("sendFeedbackMessage", sessionId, new Action() {
@Override
public void execute() { public void execute() {
String host = SessionManager.getInstance().getSession(sessionId).getHost(); String host = SessionManager.getInstance().getSession(sessionId).getHost();
FeedbackServiceImpl.instance.feedback(username, title, type, message, email, host); FeedbackServiceImpl.instance.feedback(username, title, type, message, email, host);
@ -742,9 +788,11 @@ public class MageServerImpl implements MageServer {
} }
} }
@Override
public void sendBroadcastMessage(final String sessionId, final String message) throws MageException { public void sendBroadcastMessage(final String sessionId, final String message) throws MageException {
if (message != null) { if (message != null) {
execute("sendBroadcastMessage", sessionId, new Action() { execute("sendBroadcastMessage", sessionId, new Action() {
@Override
public void execute() { public void execute() {
for (User user : UserManager.getInstance().getUsers()) { for (User user : UserManager.getInstance().getUsers()) {
if (message.toLowerCase().startsWith("warn")) { if (message.toLowerCase().startsWith("warn")) {