[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;
import java.util.UUID;
import javax.swing.JComponent;
import mage.client.MageFrame;
import mage.client.MagePane;
import mage.client.plugins.impl.Plugins;

View file

@ -34,6 +34,18 @@
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.RangeOfInfluence;
import mage.cards.decks.importer.DeckImporterUtil;
@ -53,18 +65,6 @@ import mage.view.MatchView;
import mage.view.TableView;
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,62 +114,63 @@ public class TablesPanel extends javax.swing.JPanel {
jScrollPane1.getViewport().setBackground(new Color(255,255,255,50));
jScrollPane2.getViewport().setBackground(new Color(255,255,255,50));
Action joinTable = new AbstractAction()
{
@Override
public void actionPerformed(ActionEvent e)
{
int modelRow = Integer.valueOf( e.getActionCommand() );
UUID tableId = (UUID)tableModel.getValueAt(modelRow, 9);
UUID gameId = (UUID)tableModel.getValueAt(modelRow, 8);
String state = (String)tableModel.getValueAt(modelRow, 6);
boolean isTournament = (Boolean)tableModel.getValueAt(modelRow, 7);
String owner = (String)tableModel.getValueAt(modelRow, 1);
Action joinTable;
joinTable = new AbstractAction()
{
@Override
public void actionPerformed(ActionEvent e)
{
int modelRow = Integer.valueOf( e.getActionCommand() );
UUID tableId = (UUID)tableModel.getValueAt(modelRow, 9);
UUID gameId = (UUID)tableModel.getValueAt(modelRow, 8);
String state = (String)tableModel.getValueAt(modelRow, 6);
boolean isTournament = (Boolean)tableModel.getValueAt(modelRow, 7);
String owner = (String)tableModel.getValueAt(modelRow, 1);
if (state.equals("Join")) {
if (owner.equals(session.getUserName())) {
try {
JDesktopPane desktopPane = (JDesktopPane)MageFrame.getUI().getComponent(MageComponents.DESKTOP_PANE);
JInternalFrame[] windows = desktopPane.getAllFramesInLayer(javax.swing.JLayeredPane.DEFAULT_LAYER);
for (JInternalFrame frame : windows) {
if (frame.getTitle().equals("Waiting for players")) {
frame.toFront();
frame.setVisible(true);
try {
frame.setSelected(true);
} catch (PropertyVetoException ve) {
ve.printStackTrace();
logger.error(ve);
}
}
if (state.equals("Join")) {
if (owner.equals(session.getUserName())) {
try {
JDesktopPane desktopPane = (JDesktopPane)MageFrame.getUI().getComponent(MageComponents.DESKTOP_PANE);
JInternalFrame[] windows = desktopPane.getAllFramesInLayer(javax.swing.JLayeredPane.DEFAULT_LAYER);
for (JInternalFrame frame : windows) {
if (frame.getTitle().equals("Waiting for players")) {
frame.toFront();
frame.setVisible(true);
try {
frame.setSelected(true);
} catch (PropertyVetoException ve) {
ve.printStackTrace();
logger.error(ve);
}
}
}
} catch (Exception ex) {
logger.error(ex);
}
return;
}
if (isTournament) {
logger.info("Joining tournament " + tableId);
session.joinTournamentTable(roomId, tableId, session.getUserName(), "Human", 1);
}
else {
logger.info("Joining table " + tableId);
joinTableDialog.showDialog(roomId, tableId);
}
} else if (state.equals("Remove")) {
if (JOptionPane.showConfirmDialog(null, "Are you sure you want to remove table?", "Removing table", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
session.removeTable(roomId, tableId);
}
} else if (state.equals("Watch")) {
logger.info("Watching table " + tableId);
session.watchTable(roomId, tableId);
} else if (state.equals("Replay")) {
logger.info("Replaying game " + gameId);
session.replayGame(gameId);
}
}
};
}
} catch (Exception ex) {
logger.error(ex);
}
return;
}
if (isTournament) {
logger.info("Joining tournament " + tableId);
session.joinTournamentTable(roomId, tableId, session.getUserName(), "Human", 1);
}
else {
logger.info("Joining table " + tableId);
joinTableDialog.showDialog(roomId, tableId);
}
} else if (state.equals("Remove")) {
if (JOptionPane.showConfirmDialog(null, "Are you sure you want to remove table?", "Removing table", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
session.removeTable(roomId, tableId);
}
} else if (state.equals("Watch")) {
logger.info("Watching table " + tableId);
session.watchTable(roomId, tableId);
} else if (state.equals("Replay")) {
logger.info("Replaying game " + gameId);
session.replayGame(gameId);
}
}
};
Action replayMatch = new AbstractAction()
{
@ -239,19 +240,23 @@ public class TablesPanel extends javax.swing.JPanel {
}
}
else {
if (updateMatchesTask != null)
updateMatchesTask.cancel(true);
if (updateMatchesTask != null) {
updateMatchesTask.cancel(true);
}
}
}
}
public void stopTasks() {
if (updateTablesTask != null)
if (updateTablesTask != null) {
updateTablesTask.cancel(true);
if (updatePlayersTask != null)
}
if (updatePlayersTask != null) {
updatePlayersTask.cancel(true);
if (updateMatchesTask != null)
}
if (updateMatchesTask != null) {
updateMatchesTask.cancel(true);
}
}
public void showTables(UUID roomId) {
@ -319,8 +324,9 @@ public class TablesPanel extends javax.swing.JPanel {
while (c != null && !(c instanceof TablesPane)) {
c = c.getParent();
}
if (c != null)
if (c != null) {
((TablesPane)c).hideFrame();
}
}
/** This method is called from within the constructor to
@ -658,8 +664,9 @@ class TableTableModel extends AbstractTableModel {
case 7:
return tables[arg0].isTournament();
case 8:
if (!tables[arg0].getGames().isEmpty())
if (!tables[arg0].getGames().isEmpty()) {
return tables[arg0].getGames().get(0);
}
return null;
case 9:
return tables[arg0].getTableId();
@ -671,8 +678,9 @@ class TableTableModel extends AbstractTableModel {
public String getColumnName(int columnIndex) {
String colName = "";
if (columnIndex <= getColumnCount())
if (columnIndex <= getColumnCount()) {
colName = columnNames[columnIndex];
}
return colName;
}
@ -684,8 +692,9 @@ class TableTableModel extends AbstractTableModel {
@Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
if (columnIndex != 6)
if (columnIndex != 6) {
return false;
}
return true;
}
@ -711,7 +720,9 @@ class UpdateTablesTask extends SwingWorker<Void, Collection<TableView>> {
protected Void doInBackground() throws Exception {
while (!isCancelled()) {
Collection<TableView> tables = session.getTables(roomId);
if (tables != null) this.publish(tables);
if (tables != null) {
this.publish(tables);
}
Thread.sleep(1000);
}
return null;
@ -826,8 +837,9 @@ class MatchesTableModel extends AbstractTableModel {
public String getColumnName(int columnIndex) {
String colName = "";
if (columnIndex <= getColumnCount())
if (columnIndex <= getColumnCount()) {
colName = columnNames[columnIndex];
}
return colName;
}
@ -839,8 +851,9 @@ class MatchesTableModel extends AbstractTableModel {
@Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
if (columnIndex != 5)
if (columnIndex != 5) {
return false;
}
return true;
}
@ -864,7 +877,9 @@ class UpdateMatchesTask extends SwingWorker<Void, Collection<MatchView>> {
protected Void doInBackground() throws Exception {
while (!isCancelled()) {
Collection<MatchView> matches = session.getFinishedMatches(roomId);
if (matches != null) this.publish(matches);
if (matches != null) {
this.publish(matches);
}
Thread.sleep(5000);
}
return null;
@ -897,7 +912,9 @@ class GameChooser extends JPopupMenu {
}
public void show(List<UUID> games, Point p) {
if (p == null) return;
if (p == null) {
return;
}
this.removeAll();
for (UUID gameId: games) {
this.add(new GameChooserAction(gameId, gameId.toString()));

View file

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

View file

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