This commit is contained in:
BetaSteward 2010-03-27 02:15:55 +00:00
parent 345d364d76
commit de6a672d24
23 changed files with 492 additions and 383 deletions

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Config.xsd">
<server serverName="mage-server" port="17171" maxGameThreads="10" maxSecondsIdle="600"/>
<server serverAddress="localhost" serverName="mage-server" port="17171" maxGameThreads="10" maxSecondsIdle="600"/>
<playerTypes>
<plugin name="Human" jar="Mage.HumanPlayer.jar" className="mage.human.HumanPlayer"/>
<plugin name="Computer - default" jar="Mage.AI.jar" className="mage.ai.ComputerPlayer"/>

View file

@ -0,0 +1,2 @@
# Default global logging level.
.level=FINE

View file

@ -73,7 +73,7 @@ run-sys-prop.java.endorsed.dirs=${jaxbwiz.endorsed.dirs}
run.classpath=\
${javac.classpath}:\
${build.classes.dir}
run.jvmargs=-server -Djava.security.policy=config/security.policy
run.jvmargs=-server -Djava.security.policy=./config/security.policy -Djava.util.logging.config.file=./config/logging.config
run.test.classpath=\
${javac.test.classpath}:\
${build.test.classes.dir}

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Config.xsd">
<server serverName="mage-server" port="17171" maxGameThreads="10" maxSecondsIdle="600"/>
<server serverAddress="localhost" serverName="mage-server" port="17171" maxGameThreads="10" maxSecondsIdle="600"/>
<playerTypes>
<plugin name="Human" jar="Mage.HumanPlayer.jar" className="mage.human.HumanPlayer"/>
<plugin name="Computer - default" jar="Mage.AI.jar" className="mage.ai.ComputerPlayer"/>

View file

@ -0,0 +1,2 @@
# Default global logging level.
.level=INFO

View file

@ -8,6 +8,7 @@ You will need to have the Java Runtime Environment Version 6 Update 10 or greate
You can download this from: http://java.com/
-----------------------------------------------------------------------------------
Installing and running MAGE
You will need to download both the client and the server applications. These can be
obtained from http://code.google.com/p/magic--another-game-engine/downloads/list.
@ -23,17 +24,34 @@ To launch the client run the startClient.bat command. Click on the connect butt
the toolbar and enter the server name/IP address and port. Then click on the tables
button. This will bring up a list of active and completed games. Click on join to
join an existing game that hasn't started yet or you can create a new table by
clicking the new button.
clicking the New button.
-----------------------------------------------------------------------------------
Playing a game
The client useage should be fairly self evident. Click on cards in your hand to
Playing a game should be fairly self evident. Your hand is displayed at the bottom
of the screen. The battlefield is the central area. Click on cards in your hand to
play them. Click on cards in the battlefield to activate abilities. A popup menu
will be presented if you have more than one choice. To pass priority for the turn
hold down the ctrl key while clicking done. You will still receive priority if
your opponent casts a spell or activates an ability.
your opponent casts a spell or activates an ability. Target cards by clicking on
them. To target a player click on the player name. You can see the cards in any
graveyard by clicking on the graveyard count.
-----------------------------------------------------------------------------------
Deck editor
A simple deck editor is available by clicking on the Deck Editor button on the
toolbar. All the available cards are displayed in the top section. Your deck
and sideboard are displayed at the bottom. To add a card to your deck double
click on the card in the top section. To remove it from your deck double click
on the card in the deck area. The sideboard section is not ready yet (don't
worry it's coming soon).
You can save or load a deck using the Save or Load buttons.
-----------------------------------------------------------------------------------
Notes
MAGE is still very much in the testing phase so there can be lots of bugs and/or
missing functionality. Please be patient. If you notice anything or want to

View file

@ -1 +1 @@
start java -jar .\MageServer.jar
start java -server -Djava.security.policy=./config/security.policy -Djava.util.logging.config.file=./config/logging.config -jar ./MageServer.jar

View file

@ -30,7 +30,6 @@ package mage.server;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import mage.interfaces.ChatClient;
/**
*
@ -54,12 +53,12 @@ public class ChatManager {
return chatSession.getChatId();
}
public void joinChat(UUID chatId, ChatClient client) {
chatSessions.get(chatId).join(client);
public void joinChat(UUID chatId, UUID sessionId, String userName) {
chatSessions.get(chatId).join(userName, sessionId);
}
public void leaveChat(UUID chatId, UUID clientId) {
chatSessions.get(chatId).leave(clientId);
public void leaveChat(UUID chatId, UUID sessionId) {
chatSessions.get(chatId).kill(sessionId);
}
public void destroyChatSession(UUID chatId) {
@ -69,4 +68,10 @@ public class ChatManager {
public void broadcast(UUID chatId, String userName, String message) {
chatSessions.get(chatId).broadcast(userName, message);
}
void removeSession(UUID sessionId) {
for (ChatSession chat: chatSessions.values()) {
chat.kill(sessionId);
}
}
}

View file

@ -28,20 +28,17 @@
package mage.server;
import mage.server.util.ThreadExecutor;
import java.rmi.RemoteException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Map.Entry;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.logging.Level;
import java.util.logging.Logger;
import mage.interfaces.ChatClient;
import mage.interfaces.callback.ClientCallback;
import mage.util.Logging;
import mage.view.ChatMessage;
/**
*
@ -49,9 +46,8 @@ import mage.util.Logging;
*/
public class ChatSession {
private static ExecutorService executor = ThreadExecutor.getInstance().getRMIExecutor();
private final static Logger logger = Logging.getLogger(ChatSession.class.getName());
private ConcurrentHashMap<UUID, ChatClient> clients = new ConcurrentHashMap<UUID, ChatClient>();
private ConcurrentHashMap<UUID, String> clients = new ConcurrentHashMap<UUID, String>();
private UUID chatId;
private DateFormat timeFormatter = SimpleDateFormat.getTimeInstance(SimpleDateFormat.SHORT);
@ -61,51 +57,30 @@ public class ChatSession {
chatId = UUID.randomUUID();
}
public void join(ChatClient client) {
try {
logger.log(Level.INFO, "joining chat " + chatId);
clients.put(client.getId(), client);
broadcast(client.getName(), " has joined");
} catch (RemoteException ex) {
logger.log(Level.SEVERE, null, ex);
public void join(String userName, UUID sessionId) {
clients.put(sessionId, userName);
broadcast(userName, " has joined");
logger.info(userName + " joined chat " + chatId);
}
public void kill(UUID sessionId) {
if (clients.containsKey(sessionId)) {
String userName = clients.get(sessionId);
clients.remove(sessionId);
broadcast(userName, " has left");
logger.info(userName + " has left chat " + chatId);
}
}
public void leave(UUID clientId) {
if (clients.contains(clientId)) {
String clientName = "";
try {
clientName = clients.get(clientId).getName();
} catch (RemoteException ex) {
logger.log(Level.SEVERE, null, ex);
}
kill(clientId);
broadcast(clientName, " has left");
}
}
public void kill(UUID clientId) {
if (clients.contains(clientId))
clients.remove(clientId);
}
public void broadcast(final String userName, final String message) {
public void broadcast(String userName, String message) {
Calendar cal = new GregorianCalendar();
final String msg = timeFormatter.format(cal.getTime()) + " " + userName + ":" + message;
for (final Entry<UUID, ChatClient> entry: clients.entrySet()) {
executor.submit(
new Runnable() {
public void run() {
try {
entry.getValue().receiveMessage(msg);
}
catch (RemoteException ex) {
logger.log(Level.WARNING, ex.getMessage());
kill(entry.getKey());
}
}
}
);
for (UUID sessionId: clients.keySet()) {
Session session = SessionManager.getInstance().getSession(sessionId);
if (session != null)
session.fireCallback(new ClientCallback("chatMessage", new ChatMessage(chatId, msg)));
else
kill(sessionId);
}
}

View file

@ -50,6 +50,8 @@ public class Main {
private final static String testModeArg = "-testMode=";
private static Server server;
/**
* @param args the command line arguments
*/
@ -69,8 +71,9 @@ public class Main {
testMode = Boolean.valueOf(arg.replace(testModeArg, ""));
}
}
Server server = new ServerImpl(config.getPort(), config.getServerName(), testMode);
System.setProperty("java.rmi.server.hostname", config.getServerAddress());
server = new ServerImpl(config.getPort(), config.getServerName(), testMode);
}
private static Class<?> loadPlugin(Plugin plugin) {

View file

@ -31,6 +31,7 @@ package mage.server;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.RemoteServer;
import java.rmi.server.UnicastRemoteObject;
import java.util.Collection;
import java.util.List;
@ -38,13 +39,10 @@ import java.util.UUID;
import java.util.logging.Level;
import java.util.logging.Logger;
import mage.Constants.DeckType;
import mage.interfaces.ChatClient;
import mage.interfaces.Client;
import mage.cards.decks.DeckCardLists;
import mage.interfaces.GameClient;
import mage.interfaces.GameReplayClient;
import mage.interfaces.MageException;
import mage.interfaces.Server;
import mage.interfaces.callback.ClientCallback;
import mage.server.game.GameFactory;
import mage.server.game.GameManager;
import mage.server.game.GamesRoomManager;
@ -58,7 +56,7 @@ import mage.view.TableView;
*
* @author BetaSteward_at_googlemail.com
*/
public class ServerImpl implements Server {
public class ServerImpl extends RemoteServer implements Server {
private final static Logger logger = Logging.getLogger("Mage Server");
@ -68,8 +66,8 @@ public class ServerImpl implements Server {
try {
System.setSecurityManager(null);
Registry reg = LocateRegistry.createRegistry(port);
Server server = (Server) UnicastRemoteObject.exportObject(this, 0);
reg.rebind(name, server);
Server stub = (Server) UnicastRemoteObject.exportObject(this, port);
reg.rebind(name, stub);
this.testMode = testMode;
logger.info("Started MAGE server - listening on port " + port);
logger.info("MAGE server running in test mode");
@ -80,10 +78,29 @@ public class ServerImpl implements Server {
}
@Override
public UUID registerClient(Client c) throws RemoteException {
public ClientCallback callback(UUID sessionId) {
return SessionManager.getInstance().getSession(sessionId).callback();
}
UUID sessionId = SessionManager.getInstance().createSession(c);
logger.info("Session " + sessionId + " created for client " + c.getId());
// @Override
// public String getClientIp() throws RemoteException, MageException {
// try {
// return getClientHost();
// } catch (Exception ex) {
// handleException(ex);
// }
// return null;
// }
@Override
public UUID registerClient(String userName, UUID clientId) throws MageException, RemoteException {
UUID sessionId = SessionManager.getInstance().createSession(userName, clientId);
try {
logger.info("Session " + sessionId + " created for user " + userName + " at " + getClientHost());
} catch (Exception ex) {
handleException(ex);
}
return sessionId;
}
@ -178,9 +195,9 @@ public class ServerImpl implements Server {
}
@Override
public void joinChat(UUID chatId, ChatClient chatClient) throws MageException {
public void joinChat(UUID chatId, UUID sessionId, String userName) throws MageException {
try {
ChatManager.getInstance().joinChat(chatId, chatClient);
ChatManager.getInstance().joinChat(chatId, sessionId, userName);
}
catch (Exception ex) {
handleException(ex);
@ -188,9 +205,9 @@ public class ServerImpl implements Server {
}
@Override
public void leaveChat(UUID chatId, UUID clientId) throws MageException {
public void leaveChat(UUID chatId, UUID sessionId) throws MageException {
try {
ChatManager.getInstance().leaveChat(chatId, clientId);
ChatManager.getInstance().leaveChat(chatId, sessionId);
}
catch (Exception ex) {
handleException(ex);
@ -252,9 +269,9 @@ public class ServerImpl implements Server {
}
@Override
public void joinGame(UUID gameId, UUID sessionId, GameClient gameClient) throws MageException {
public void joinGame(UUID gameId, UUID sessionId) throws MageException {
try {
GameManager.getInstance().joinGame(gameId, sessionId, gameClient);
GameManager.getInstance().joinGame(gameId, sessionId);
}
catch (Exception ex) {
handleException(ex);
@ -334,9 +351,9 @@ public class ServerImpl implements Server {
}
@Override
public void watchGame(UUID gameId, UUID sessionId, GameClient gameClient) throws MageException {
public void watchGame(UUID gameId, UUID sessionId) throws MageException {
try {
GameManager.getInstance().watchGame(gameId, sessionId, gameClient);
GameManager.getInstance().watchGame(gameId, sessionId);
}
catch (Exception ex) {
handleException(ex);
@ -344,9 +361,9 @@ public class ServerImpl implements Server {
}
@Override
public void stopWatching(UUID gameId, UUID clientId) throws MageException {
public void stopWatching(UUID gameId, UUID sessionId) throws MageException {
try {
GameManager.getInstance().stopWatching(gameId, clientId);
GameManager.getInstance().stopWatching(gameId, sessionId);
}
catch (Exception ex) {
handleException(ex);
@ -354,9 +371,9 @@ public class ServerImpl implements Server {
}
@Override
public void replayGame(UUID gameId, UUID sessionId, GameReplayClient replayClient) throws MageException {
public void replayGame(UUID sessionId) throws MageException {
try {
ReplayManager.getInstance().startReplay(sessionId, replayClient);
ReplayManager.getInstance().startReplay(sessionId);
}
catch (Exception ex) {
handleException(ex);

View file

@ -28,13 +28,14 @@
package mage.server;
import java.util.logging.Level;
import mage.server.util.ThreadExecutor;
import java.rmi.RemoteException;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.logging.Level;
import java.util.logging.Logger;
import mage.interfaces.Client;
import mage.interfaces.callback.CallbackServer;
import mage.interfaces.callback.CallbackServerSession;
import mage.interfaces.callback.ClientCallback;
import mage.server.game.GameManager;
import mage.server.game.TableManager;
import mage.util.Logging;
@ -49,17 +50,14 @@ public class Session {
private final static Logger logger = Logging.getLogger(Session.class.getName());
private UUID sessionId;
private UUID clientId;
private String username;
private Client client;
private final CallbackServerSession callback = new CallbackServerSession();
public Session(Client client) {
public Session(String userName, UUID clientId) {
sessionId = UUID.randomUUID();
try {
username = client.getUserName();
} catch (RemoteException ex) {
logger.log(Level.SEVERE, null, ex);
}
this.client = client;
this.username = userName;
this.clientId = clientId;
}
public UUID getId() {
@ -70,59 +68,79 @@ public class Session {
SessionManager.getInstance().removeSession(sessionId);
TableManager.getInstance().removeSession(sessionId);
GameManager.getInstance().removeSession(sessionId);
ChatManager.getInstance().removeSession(sessionId);
}
public ClientCallback callback() {
try {
return callback.callback();
} catch (InterruptedException ex) {
logger.log(Level.SEVERE, null, ex);
}
return null;
}
public void fireCallback(ClientCallback call) {
try {
callback.setCallback(call);
} catch (InterruptedException ex) {
logger.log(Level.SEVERE, null, ex);
}
}
public void gameStarted(final UUID gameId, final UUID playerId) {
executor.submit(
new Runnable() {
@Override
public void run() {
try {
client.gameStarted(gameId, playerId);
logger.info("game started for player " + playerId);
}
catch (RemoteException ex) {
logger.log(Level.WARNING, ex.getMessage());
kill();
}
}
}
);
fireCallback(new ClientCallback("startGame", new UUID[] {gameId, playerId}));
// executor.submit(
// new Runnable() {
// @Override
// public void run() {
// try {
// client.gameStarted(gameId, playerId);
// logger.info("game started for player " + playerId);
// }
// catch (RemoteException ex) {
// logger.log(Level.WARNING, ex.getMessage());
// kill();
// }
// }
// }
// );
}
public void watchGame(final UUID gameId) {
executor.submit(
new Runnable() {
@Override
public void run() {
try {
client.watchGame(gameId);
}
catch (RemoteException ex) {
logger.log(Level.WARNING, ex.getMessage());
kill();
}
}
}
);
fireCallback(new ClientCallback("watchGame", gameId));
// executor.submit(
// new Runnable() {
// @Override
// public void run() {
// try {
// client.watchGame(gameId);
// }
// catch (RemoteException ex) {
// logger.log(Level.WARNING, ex.getMessage());
// kill();
// }
// }
// }
// );
}
public void replayGame(final UUID gameId) {
executor.submit(
new Runnable() {
@Override
public void run() {
try {
client.replayGame(gameId);
}
catch (RemoteException ex) {
logger.log(Level.WARNING, ex.getMessage());
kill();
}
}
}
);
fireCallback(new ClientCallback("replayGame", gameId));
// executor.submit(
// new Runnable() {
// @Override
// public void run() {
// try {
// client.replayGame(gameId);
// }
// catch (RemoteException ex) {
// logger.log(Level.WARNING, ex.getMessage());
// kill();
// }
// }
// }
// );
}
public String getUsername() {

View file

@ -30,7 +30,6 @@ package mage.server;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import mage.interfaces.Client;
/**
*
@ -50,8 +49,8 @@ public class SessionManager {
return sessions.get(sessionId);
}
public UUID createSession(Client c) {
Session session = new Session(c);
public UUID createSession(String userName, UUID clientId) {
Session session = new Session(userName, clientId);
sessions.put(session.getId(), session);
return session.getId();
}

View file

@ -44,7 +44,6 @@ import mage.cards.decks.DeckCardLists;
import mage.game.Game;
import mage.game.GameReplay;
import mage.game.events.TableEvent;
import mage.interfaces.GameClient;
import mage.server.ChatManager;
import mage.server.util.ThreadExecutor;
import mage.game.events.Listener;
@ -95,7 +94,7 @@ public class GameController implements GameCallback {
break;
case INFO:
ChatManager.getInstance().broadcast(chatId, "", event.getMessage());
logger.info(game.getId() + " " + event.getMessage());
logger.fine(game.getId() + " " + event.getMessage());
break;
}
}
@ -140,11 +139,11 @@ public class GameController implements GameCallback {
return sessionPlayerMap.get(sessionId);
}
public void join(UUID sessionId, GameClient client) {
public void join(UUID sessionId) {
UUID playerId = sessionPlayerMap.get(sessionId);
GameSession gameSession = new GameSession(client, game, sessionId, playerId);
GameSession gameSession = new GameSession(game, sessionId, playerId);
gameSessions.put(playerId, gameSession);
logger.log(Level.INFO, "player " + playerId + " has joined game " + game.getId());
logger.info("player " + playerId + " has joined game " + game.getId());
gameSession.init(getGameView(playerId));
ChatManager.getInstance().broadcast(chatId, "", game.getPlayer(playerId).getName() + " has joined the game");
if (allJoined()) {
@ -168,8 +167,8 @@ public class GameController implements GameCallback {
return true;
}
public void watch(UUID sessionId, GameClient client) {
GameWatcher gameWatcher = new GameWatcher(client, sessionId, game.getId());
public void watch(UUID sessionId) {
GameWatcher gameWatcher = new GameWatcher(sessionId, game.getId());
watchers.put(sessionId, gameWatcher);
gameWatcher.init(getGameView());
ChatManager.getInstance().broadcast(chatId, "", " has started watching");

View file

@ -33,7 +33,6 @@ import java.util.concurrent.ConcurrentHashMap;
import mage.cards.decks.DeckCardLists;
import mage.game.Game;
import mage.game.GameReplay;
import mage.interfaces.GameClient;
/**
*
@ -56,8 +55,8 @@ public class GameManager {
return gameController.getSessionId();
}
public void joinGame(UUID gameId, UUID sessionId, GameClient client) {
gameControllers.get(gameId).join(sessionId, client);
public void joinGame(UUID gameId, UUID sessionId) {
gameControllers.get(gameId).join(sessionId);
}
// public void leaveGame(UUID gameId, UUID clientId) {
@ -92,12 +91,12 @@ public class GameManager {
gameControllers.get(gameId).concede(sessionId);
}
public void watchGame(UUID gameId, UUID sessionId, GameClient client) {
gameControllers.get(gameId).watch(sessionId, client);
public void watchGame(UUID gameId, UUID sessionId) {
gameControllers.get(gameId).watch(sessionId);
}
public void stopWatching(UUID gameId, UUID clientId) {
gameControllers.get(gameId).stopWatching(clientId);
public void stopWatching(UUID gameId, UUID sessionId) {
gameControllers.get(gameId).stopWatching(sessionId);
}
public void removeSession(UUID sessionId) {

View file

@ -28,17 +28,19 @@
package mage.server.game;
import java.rmi.RemoteException;
import java.util.UUID;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import mage.game.Game;
import mage.interfaces.GameClient;
import mage.interfaces.callback.ClientCallback;
import mage.server.Session;
import mage.server.SessionManager;
import mage.server.util.ConfigSettings;
import mage.server.util.ThreadExecutor;
import mage.view.AbilityPickerView;
import mage.view.CardsView;
import mage.view.GameClientMessage;
import mage.view.GameView;
/**
@ -53,171 +55,215 @@ public class GameSession extends GameWatcher {
private ScheduledFuture<?> futureTimeout;
protected static ScheduledExecutorService timeoutExecutor = ThreadExecutor.getInstance().getTimeoutExecutor();
public GameSession(GameClient client, Game game, UUID sessionId, UUID playerId) {
super(client, sessionId, game.getId());
public GameSession(Game game, UUID sessionId, UUID playerId) {
super(sessionId, game.getId());
this.game = game;
this.playerId = playerId;
}
public void ask(final String question, final GameView gameView) {
if (!killed) {
setupTimeout();
rmiExecutor.submit(
new Runnable() {
@Override
public void run() {
try {
client.ask(question, gameView);
} catch (RemoteException ex) {
handleRemoteException(ex);
}
}
}
);
Session session = SessionManager.getInstance().getSession(sessionId);
if (session != null)
session.fireCallback(new ClientCallback("gameAsk", new GameClientMessage(gameView, question)));
}
// setupTimeout();
// rmiExecutor.submit(
// new Runnable() {
// @Override
// public void run() {
// try {
// client.ask(question, gameView);
// } catch (RemoteException ex) {
// handleRemoteException(ex);
// }
// }
// }
// );
// }
}
public void target(final String question, final CardsView cardView, final boolean required, final GameView gameView) {
if (!killed) {
setupTimeout();
rmiExecutor.submit(
new Runnable() {
@Override
public void run() {
try {
client.target(question, cardView, required, gameView);
} catch (RemoteException ex) {
handleRemoteException(ex);
}
}
}
);
Session session = SessionManager.getInstance().getSession(sessionId);
if (session != null)
session.fireCallback(new ClientCallback("gameTarget", new GameClientMessage(gameView, question, cardView, required)));
}
// if (!killed) {
// setupTimeout();
// rmiExecutor.submit(
// new Runnable() {
// @Override
// public void run() {
// try {
// client.target(question, cardView, required, gameView);
// } catch (RemoteException ex) {
// handleRemoteException(ex);
// }
// }
// }
// );
// }
}
public void select(final String message, final GameView gameView) {
if (!killed) {
setupTimeout();
rmiExecutor.submit(
new Runnable() {
@Override
public void run() {
try {
client.select(message, gameView);
} catch (RemoteException ex) {
handleRemoteException(ex);
}
}
}
);
Session session = SessionManager.getInstance().getSession(sessionId);
if (session != null)
session.fireCallback(new ClientCallback("gameSelect", new GameClientMessage(gameView, message)));
}
// if (!killed) {
// setupTimeout();
// rmiExecutor.submit(
// new Runnable() {
// @Override
// public void run() {
// try {
// client.select(message, gameView);
// } catch (RemoteException ex) {
// handleRemoteException(ex);
// }
// }
// }
// );
// }
}
public void chooseAbility(final AbilityPickerView abilities) {
if (!killed) {
setupTimeout();
rmiExecutor.submit(
new Runnable() {
@Override
public void run() {
try {
client.chooseAbility(abilities);
} catch (RemoteException ex) {
handleRemoteException(ex);
}
}
}
);
Session session = SessionManager.getInstance().getSession(sessionId);
if (session != null)
session.fireCallback(new ClientCallback("gameChooseAbility", abilities));
}
// if (!killed) {
// setupTimeout();
// rmiExecutor.submit(
// new Runnable() {
// @Override
// public void run() {
// try {
// client.chooseAbility(abilities);
// } catch (RemoteException ex) {
// handleRemoteException(ex);
// }
// }
// }
// );
// }
}
public void choose(final String message, final String[] choices) {
if (!killed) {
setupTimeout();
rmiExecutor.submit(
new Runnable() {
@Override
public void run() {
try {
client.choose(message, choices);
} catch (RemoteException ex) {
handleRemoteException(ex);
}
}
}
);
Session session = SessionManager.getInstance().getSession(sessionId);
if (session != null)
session.fireCallback(new ClientCallback("gameChoose", new GameClientMessage(choices, message)));
}
// if (!killed) {
// setupTimeout();
// rmiExecutor.submit(
// new Runnable() {
// @Override
// public void run() {
// try {
// client.choose(message, choices);
// } catch (RemoteException ex) {
// handleRemoteException(ex);
// }
// }
// }
// );
// }
}
public void playMana(final String message, final GameView gameView) {
if (!killed) {
setupTimeout();
rmiExecutor.submit(
new Runnable() {
@Override
public void run() {
try {
client.playMana(message, gameView);
} catch (RemoteException ex) {
handleRemoteException(ex);
}
}
}
);
Session session = SessionManager.getInstance().getSession(sessionId);
if (session != null)
session.fireCallback(new ClientCallback("gamePlayMana", new GameClientMessage(gameView, message)));
}
// if (!killed) {
// setupTimeout();
// rmiExecutor.submit(
// new Runnable() {
// @Override
// public void run() {
// try {
// client.playMana(message, gameView);
// } catch (RemoteException ex) {
// handleRemoteException(ex);
// }
// }
// }
// );
// }
}
public void playXMana(final String message, final GameView gameView) {
if (!killed) {
setupTimeout();
rmiExecutor.submit(
new Runnable() {
@Override
public void run() {
try {
client.playXMana(message, gameView);
} catch (RemoteException ex) {
handleRemoteException(ex);
}
}
}
);
Session session = SessionManager.getInstance().getSession(sessionId);
if (session != null)
session.fireCallback(new ClientCallback("gamePlayXMana", new GameClientMessage(gameView, message)));
}
// if (!killed) {
// setupTimeout();
// rmiExecutor.submit(
// new Runnable() {
// @Override
// public void run() {
// try {
// client.playXMana(message, gameView);
// } catch (RemoteException ex) {
// handleRemoteException(ex);
// }
// }
// }
// );
// }
}
public void getAmount(final String message, final int min, final int max) {
if (!killed) {
setupTimeout();
rmiExecutor.submit(
new Runnable() {
@Override
public void run() {
try {
client.getAmount(min, max);
} catch (RemoteException ex) {
handleRemoteException(ex);
}
}
}
);
Session session = SessionManager.getInstance().getSession(sessionId);
if (session != null)
session.fireCallback(new ClientCallback("gameSelectAmount", new GameClientMessage(message, min, max)));
}
// if (!killed) {
// setupTimeout();
// rmiExecutor.submit(
// new Runnable() {
// @Override
// public void run() {
// try {
// client.getAmount(min, max);
// } catch (RemoteException ex) {
// handleRemoteException(ex);
// }
// }
// }
// );
// }
}
public void revealCards(final String name, final CardsView cardView) {
if (!killed) {
rmiExecutor.submit(
new Runnable() {
@Override
public void run() {
try {
client.revealCards(name, cardView);
} catch (RemoteException ex) {
handleRemoteException(ex);
}
}
}
);
Session session = SessionManager.getInstance().getSession(sessionId);
if (session != null)
session.fireCallback(new ClientCallback("gameReveal", new GameClientMessage(cardView, name)));
}
// if (!killed) {
// rmiExecutor.submit(
// new Runnable() {
// @Override
// public void run() {
// try {
// client.revealCards(name, cardView);
// } catch (RemoteException ex) {
// handleRemoteException(ex);
// }
// }
// }
// );
// }
}

View file

@ -30,12 +30,13 @@ package mage.server.game;
import java.rmi.RemoteException;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.logging.Level;
import java.util.logging.Logger;
import mage.interfaces.GameClient;
import mage.server.util.ThreadExecutor;
import mage.interfaces.callback.ClientCallback;
import mage.server.Session;
import mage.server.SessionManager;
import mage.util.Logging;
import mage.view.GameClientMessage;
import mage.view.GameView;
/**
@ -44,83 +45,96 @@ import mage.view.GameView;
*/
public class GameWatcher {
protected static ExecutorService rmiExecutor = ThreadExecutor.getInstance().getRMIExecutor();
// protected static ExecutorService rmiExecutor = ThreadExecutor.getInstance().getRMIExecutor();
protected final static Logger logger = Logging.getLogger(GameWatcher.class.getName());
protected GameClient client;
protected UUID sessionId;
protected UUID gameId;
protected boolean killed = false;
public GameWatcher(GameClient client, UUID sessionId, UUID gameId) {
this.client = client;
public GameWatcher(UUID sessionId, UUID gameId) {
this.sessionId = sessionId;
this.gameId = gameId;
}
public void init(final GameView gameView) {
if (!killed)
rmiExecutor.submit(
new Runnable() {
@Override
public void run() {
try {
client.init(gameView);
} catch (RemoteException ex) {
handleRemoteException(ex);
}
}
}
);
if (!killed) {
Session session = SessionManager.getInstance().getSession(sessionId);
if (session != null)
session.fireCallback(new ClientCallback("gameInit", gameView));
}
// rmiExecutor.submit(
// new Runnable() {
// @Override
// public void run() {
// try {
// client.init(gameView);
// } catch (RemoteException ex) {
// handleRemoteException(ex);
// }
// }
// }
// );
}
public void update(final GameView gameView) {
if (!killed)
rmiExecutor.submit(
new Runnable() {
@Override
public void run() {
try {
client.update(gameView);
} catch (RemoteException ex) {
handleRemoteException(ex);
}
}
}
);
if (!killed) {
Session session = SessionManager.getInstance().getSession(sessionId);
if (session != null)
session.fireCallback(new ClientCallback("gameUpdate", gameView));
}
// rmiExecutor.submit(
// new Runnable() {
// @Override
// public void run() {
// try {
// client.update(gameView);
// } catch (RemoteException ex) {
// handleRemoteException(ex);
// }
// }
// }
// );
}
public void inform(final String message, final GameView gameView) {
if (!killed)
rmiExecutor.submit(
new Runnable() {
@Override
public void run() {
try {
client.inform(message, gameView);
} catch (RemoteException ex) {
handleRemoteException(ex);
}
}
}
);
if (!killed) {
Session session = SessionManager.getInstance().getSession(sessionId);
if (session != null)
session.fireCallback(new ClientCallback("gameInform", new GameClientMessage(gameView, message)));
}
// rmiExecutor.submit(
// new Runnable() {
// @Override
// public void run() {
// try {
// client.inform(message, gameView);
// } catch (RemoteException ex) {
// handleRemoteException(ex);
// }
// }
// }
// );
}
public void gameOver(final String message) {
if (!killed)
rmiExecutor.submit(
new Runnable() {
@Override
public void run() {
try {
client.gameOver(message);
} catch (RemoteException ex) {
handleRemoteException(ex);
}
}
}
);
if (!killed) {
Session session = SessionManager.getInstance().getSession(sessionId);
if (session != null)
session.fireCallback(new ClientCallback("gameOver", message));
}
// rmiExecutor.submit(
// new Runnable() {
// @Override
// public void run() {
// try {
// client.gameOver(message);
// } catch (RemoteException ex) {
// handleRemoteException(ex);
// }
// }
// }
// );
}
protected void handleRemoteException(RemoteException ex) {

View file

@ -64,7 +64,7 @@ public class PlayerFactory {
logger.log(Level.SEVERE, null, ex);
return null;
}
logger.info("Player created: " + player.getId().toString());
logger.info("Player created: " + name + "-" + player.getId().toString());
return player;
}

View file

@ -30,7 +30,6 @@ package mage.server.game;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import mage.interfaces.GameReplayClient;
import mage.server.SessionManager;
/**
@ -49,13 +48,13 @@ public class ReplayManager {
private ConcurrentHashMap<UUID, ReplaySession> replaySessions = new ConcurrentHashMap<UUID, ReplaySession>();
public void replayGame(UUID sessionId, UUID gameId) {
ReplaySession replaySession = new ReplaySession(gameId);
ReplaySession replaySession = new ReplaySession(gameId, sessionId);
replaySessions.put(sessionId, replaySession);
SessionManager.getInstance().getSession(sessionId).replayGame(gameId);
}
public void startReplay(UUID sessionId, GameReplayClient replayClient) {
replaySessions.get(sessionId).replay(replayClient);
public void startReplay(UUID sessionId) {
replaySessions.get(sessionId).replay();
}
public void stopReplay(UUID sessionId) {

View file

@ -28,15 +28,13 @@
package mage.server.game;
import java.rmi.RemoteException;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.logging.Level;
import java.util.logging.Logger;
import mage.game.GameReplay;
import mage.game.GameState;
import mage.interfaces.GameReplayClient;
import mage.server.util.ThreadExecutor;
import mage.interfaces.callback.ClientCallback;
import mage.server.Session;
import mage.server.SessionManager;
import mage.util.Logging;
import mage.view.GameView;
@ -46,30 +44,33 @@ import mage.view.GameView;
*/
public class ReplaySession implements GameCallback {
protected static ExecutorService rmiExecutor = ThreadExecutor.getInstance().getRMIExecutor();
// protected static ExecutorService rmiExecutor = ThreadExecutor.getInstance().getRMIExecutor();
private final static Logger logger = Logging.getLogger(ReplaySession.class.getName());
private GameReplay game;
private GameReplayClient client;
protected UUID sessionId;
ReplaySession(UUID gameId) {
ReplaySession(UUID gameId, UUID sessionId) {
this.game = GameManager.getInstance().createReplay(gameId);
this.sessionId = sessionId;
}
public void replay(GameReplayClient replayClient) {
this.client = replayClient;
public void replay() {
game.start();
rmiExecutor.submit(
new Runnable() {
public void run() {
try {
client.init(new GameView(game.next()));
} catch (RemoteException ex) {
logger.log(Level.SEVERE, null, ex);
}
}
}
);
Session session = SessionManager.getInstance().getSession(sessionId);
if (session != null)
session.fireCallback(new ClientCallback("replayInit", new GameView(game.next())));
// rmiExecutor.submit(
// new Runnable() {
// public void run() {
// try {
// client.init(new GameView(game.next()));
// } catch (RemoteException ex) {
// logger.log(Level.SEVERE, null, ex);
// }
// }
// }
// );
}
public void stop() {
@ -84,32 +85,39 @@ public class ReplaySession implements GameCallback {
updateGame(game.previous());
}
@Override
public void gameResult(final String result) {
rmiExecutor.submit(
new Runnable() {
public void run() {
try {
client.gameOver(result);
} catch (RemoteException ex) {
logger.log(Level.SEVERE, null, ex);
}
}
}
);
Session session = SessionManager.getInstance().getSession(sessionId);
if (session != null)
session.fireCallback(new ClientCallback("replayDone", result));
// rmiExecutor.submit(
// new Runnable() {
// public void run() {
// try {
// client.gameOver(result);
// } catch (RemoteException ex) {
// logger.log(Level.SEVERE, null, ex);
// }
// }
// }
// );
}
private void updateGame(final GameState state) {
rmiExecutor.submit(
new Runnable() {
public void run() {
try {
client.update(new GameView(state));
} catch (RemoteException ex) {
logger.log(Level.SEVERE, null, ex);
}
}
}
);
Session session = SessionManager.getInstance().getSession(sessionId);
if (session != null)
session.fireCallback(new ClientCallback("replayUpdate", new GameView(state)));
// rmiExecutor.submit(
// new Runnable() {
// public void run() {
// try {
// client.update(new GameView(state));
// } catch (RemoteException ex) {
// logger.log(Level.SEVERE, null, ex);
// }
// }
// }
// );
}
}

View file

@ -90,7 +90,7 @@ public class TableController {
}
} catch (GameException ex) {
logger.log(Level.WARNING, ex.getMessage());
logger.warning(ex.getMessage());
return false;
}
return true;

View file

@ -63,6 +63,10 @@ public class ConfigSettings {
}
}
public String getServerAddress() {
return config.getServer().getServerAddress();
}
public String getServerName() {
return config.getServer().getServerName();
}

View file

@ -14,6 +14,7 @@
<xs:element name="server">
<xs:complexType>
<xs:attribute name="serverAddress" type="xs:string" use="required"/>
<xs:attribute name="serverName" type="xs:string" use="required"/>
<xs:attribute name="port" type="xs:positiveInteger" use="required"/>
<xs:attribute name="maxGameThreads" type="xs:positiveInteger" use="required"/>