mirror of
https://github.com/magefree/mage.git
synced 2025-12-20 02:30:08 -08:00
...
This commit is contained in:
parent
345d364d76
commit
de6a672d24
23 changed files with 492 additions and 383 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Config.xsd">
|
<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>
|
<playerTypes>
|
||||||
<plugin name="Human" jar="Mage.HumanPlayer.jar" className="mage.human.HumanPlayer"/>
|
<plugin name="Human" jar="Mage.HumanPlayer.jar" className="mage.human.HumanPlayer"/>
|
||||||
<plugin name="Computer - default" jar="Mage.AI.jar" className="mage.ai.ComputerPlayer"/>
|
<plugin name="Computer - default" jar="Mage.AI.jar" className="mage.ai.ComputerPlayer"/>
|
||||||
|
|
|
||||||
2
Mage.Server/config/logging.config
Normal file
2
Mage.Server/config/logging.config
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
# Default global logging level.
|
||||||
|
.level=FINE
|
||||||
|
|
@ -73,7 +73,7 @@ run-sys-prop.java.endorsed.dirs=${jaxbwiz.endorsed.dirs}
|
||||||
run.classpath=\
|
run.classpath=\
|
||||||
${javac.classpath}:\
|
${javac.classpath}:\
|
||||||
${build.classes.dir}
|
${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=\
|
run.test.classpath=\
|
||||||
${javac.test.classpath}:\
|
${javac.test.classpath}:\
|
||||||
${build.test.classes.dir}
|
${build.test.classes.dir}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Config.xsd">
|
<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>
|
<playerTypes>
|
||||||
<plugin name="Human" jar="Mage.HumanPlayer.jar" className="mage.human.HumanPlayer"/>
|
<plugin name="Human" jar="Mage.HumanPlayer.jar" className="mage.human.HumanPlayer"/>
|
||||||
<plugin name="Computer - default" jar="Mage.AI.jar" className="mage.ai.ComputerPlayer"/>
|
<plugin name="Computer - default" jar="Mage.AI.jar" className="mage.ai.ComputerPlayer"/>
|
||||||
|
|
|
||||||
2
Mage.Server/release/config/logging.config
Normal file
2
Mage.Server/release/config/logging.config
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
# Default global logging level.
|
||||||
|
.level=INFO
|
||||||
|
|
@ -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/
|
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
|
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.
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
missing functionality. Please be patient. If you notice anything or want to
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
@ -30,7 +30,6 @@ package mage.server;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import mage.interfaces.ChatClient;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|
@ -54,12 +53,12 @@ public class ChatManager {
|
||||||
return chatSession.getChatId();
|
return chatSession.getChatId();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void joinChat(UUID chatId, ChatClient client) {
|
public void joinChat(UUID chatId, UUID sessionId, String userName) {
|
||||||
chatSessions.get(chatId).join(client);
|
chatSessions.get(chatId).join(userName, sessionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void leaveChat(UUID chatId, UUID clientId) {
|
public void leaveChat(UUID chatId, UUID sessionId) {
|
||||||
chatSessions.get(chatId).leave(clientId);
|
chatSessions.get(chatId).kill(sessionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void destroyChatSession(UUID chatId) {
|
public void destroyChatSession(UUID chatId) {
|
||||||
|
|
@ -69,4 +68,10 @@ public class ChatManager {
|
||||||
public void broadcast(UUID chatId, String userName, String message) {
|
public void broadcast(UUID chatId, String userName, String message) {
|
||||||
chatSessions.get(chatId).broadcast(userName, message);
|
chatSessions.get(chatId).broadcast(userName, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void removeSession(UUID sessionId) {
|
||||||
|
for (ChatSession chat: chatSessions.values()) {
|
||||||
|
chat.kill(sessionId);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,20 +28,17 @@
|
||||||
|
|
||||||
package mage.server;
|
package mage.server;
|
||||||
|
|
||||||
import mage.server.util.ThreadExecutor;
|
|
||||||
import java.rmi.RemoteException;
|
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
import java.util.Map.Entry;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ExecutorService;
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import mage.interfaces.ChatClient;
|
import mage.interfaces.callback.ClientCallback;
|
||||||
import mage.util.Logging;
|
import mage.util.Logging;
|
||||||
|
import mage.view.ChatMessage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|
@ -49,9 +46,8 @@ import mage.util.Logging;
|
||||||
*/
|
*/
|
||||||
public class ChatSession {
|
public class ChatSession {
|
||||||
|
|
||||||
private static ExecutorService executor = ThreadExecutor.getInstance().getRMIExecutor();
|
|
||||||
private final static Logger logger = Logging.getLogger(ChatSession.class.getName());
|
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 UUID chatId;
|
||||||
private DateFormat timeFormatter = SimpleDateFormat.getTimeInstance(SimpleDateFormat.SHORT);
|
private DateFormat timeFormatter = SimpleDateFormat.getTimeInstance(SimpleDateFormat.SHORT);
|
||||||
|
|
||||||
|
|
@ -61,51 +57,30 @@ public class ChatSession {
|
||||||
chatId = UUID.randomUUID();
|
chatId = UUID.randomUUID();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void join(ChatClient client) {
|
public void join(String userName, UUID sessionId) {
|
||||||
try {
|
clients.put(sessionId, userName);
|
||||||
logger.log(Level.INFO, "joining chat " + chatId);
|
broadcast(userName, " has joined");
|
||||||
clients.put(client.getId(), client);
|
logger.info(userName + " joined chat " + chatId);
|
||||||
broadcast(client.getName(), " has joined");
|
}
|
||||||
} catch (RemoteException ex) {
|
|
||||||
logger.log(Level.SEVERE, null, ex);
|
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) {
|
public void broadcast(String userName, String message) {
|
||||||
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) {
|
|
||||||
Calendar cal = new GregorianCalendar();
|
Calendar cal = new GregorianCalendar();
|
||||||
final String msg = timeFormatter.format(cal.getTime()) + " " + userName + ":" + message;
|
final String msg = timeFormatter.format(cal.getTime()) + " " + userName + ":" + message;
|
||||||
for (final Entry<UUID, ChatClient> entry: clients.entrySet()) {
|
for (UUID sessionId: clients.keySet()) {
|
||||||
executor.submit(
|
Session session = SessionManager.getInstance().getSession(sessionId);
|
||||||
new Runnable() {
|
if (session != null)
|
||||||
public void run() {
|
session.fireCallback(new ClientCallback("chatMessage", new ChatMessage(chatId, msg)));
|
||||||
try {
|
else
|
||||||
entry.getValue().receiveMessage(msg);
|
kill(sessionId);
|
||||||
}
|
|
||||||
catch (RemoteException ex) {
|
|
||||||
logger.log(Level.WARNING, ex.getMessage());
|
|
||||||
kill(entry.getKey());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,8 @@ public class Main {
|
||||||
|
|
||||||
private final static String testModeArg = "-testMode=";
|
private final static String testModeArg = "-testMode=";
|
||||||
|
|
||||||
|
private static Server server;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param args the command line arguments
|
* @param args the command line arguments
|
||||||
*/
|
*/
|
||||||
|
|
@ -69,8 +71,9 @@ public class Main {
|
||||||
testMode = Boolean.valueOf(arg.replace(testModeArg, ""));
|
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) {
|
private static Class<?> loadPlugin(Plugin plugin) {
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ package mage.server;
|
||||||
import java.rmi.RemoteException;
|
import java.rmi.RemoteException;
|
||||||
import java.rmi.registry.LocateRegistry;
|
import java.rmi.registry.LocateRegistry;
|
||||||
import java.rmi.registry.Registry;
|
import java.rmi.registry.Registry;
|
||||||
|
import java.rmi.server.RemoteServer;
|
||||||
import java.rmi.server.UnicastRemoteObject;
|
import java.rmi.server.UnicastRemoteObject;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -38,13 +39,10 @@ import java.util.UUID;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import mage.Constants.DeckType;
|
import mage.Constants.DeckType;
|
||||||
import mage.interfaces.ChatClient;
|
|
||||||
import mage.interfaces.Client;
|
|
||||||
import mage.cards.decks.DeckCardLists;
|
import mage.cards.decks.DeckCardLists;
|
||||||
import mage.interfaces.GameClient;
|
|
||||||
import mage.interfaces.GameReplayClient;
|
|
||||||
import mage.interfaces.MageException;
|
import mage.interfaces.MageException;
|
||||||
import mage.interfaces.Server;
|
import mage.interfaces.Server;
|
||||||
|
import mage.interfaces.callback.ClientCallback;
|
||||||
import mage.server.game.GameFactory;
|
import mage.server.game.GameFactory;
|
||||||
import mage.server.game.GameManager;
|
import mage.server.game.GameManager;
|
||||||
import mage.server.game.GamesRoomManager;
|
import mage.server.game.GamesRoomManager;
|
||||||
|
|
@ -58,7 +56,7 @@ import mage.view.TableView;
|
||||||
*
|
*
|
||||||
* @author BetaSteward_at_googlemail.com
|
* @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");
|
private final static Logger logger = Logging.getLogger("Mage Server");
|
||||||
|
|
||||||
|
|
@ -68,8 +66,8 @@ public class ServerImpl implements Server {
|
||||||
try {
|
try {
|
||||||
System.setSecurityManager(null);
|
System.setSecurityManager(null);
|
||||||
Registry reg = LocateRegistry.createRegistry(port);
|
Registry reg = LocateRegistry.createRegistry(port);
|
||||||
Server server = (Server) UnicastRemoteObject.exportObject(this, 0);
|
Server stub = (Server) UnicastRemoteObject.exportObject(this, port);
|
||||||
reg.rebind(name, server);
|
reg.rebind(name, stub);
|
||||||
this.testMode = testMode;
|
this.testMode = testMode;
|
||||||
logger.info("Started MAGE server - listening on port " + port);
|
logger.info("Started MAGE server - listening on port " + port);
|
||||||
logger.info("MAGE server running in test mode");
|
logger.info("MAGE server running in test mode");
|
||||||
|
|
@ -80,10 +78,29 @@ public class ServerImpl implements Server {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
// @Override
|
||||||
logger.info("Session " + sessionId + " created for client " + c.getId());
|
// 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;
|
return sessionId;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -178,9 +195,9 @@ public class ServerImpl implements Server {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void joinChat(UUID chatId, ChatClient chatClient) throws MageException {
|
public void joinChat(UUID chatId, UUID sessionId, String userName) throws MageException {
|
||||||
try {
|
try {
|
||||||
ChatManager.getInstance().joinChat(chatId, chatClient);
|
ChatManager.getInstance().joinChat(chatId, sessionId, userName);
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
handleException(ex);
|
handleException(ex);
|
||||||
|
|
@ -188,9 +205,9 @@ public class ServerImpl implements Server {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void leaveChat(UUID chatId, UUID clientId) throws MageException {
|
public void leaveChat(UUID chatId, UUID sessionId) throws MageException {
|
||||||
try {
|
try {
|
||||||
ChatManager.getInstance().leaveChat(chatId, clientId);
|
ChatManager.getInstance().leaveChat(chatId, sessionId);
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
handleException(ex);
|
handleException(ex);
|
||||||
|
|
@ -252,9 +269,9 @@ public class ServerImpl implements Server {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void joinGame(UUID gameId, UUID sessionId, GameClient gameClient) throws MageException {
|
public void joinGame(UUID gameId, UUID sessionId) throws MageException {
|
||||||
try {
|
try {
|
||||||
GameManager.getInstance().joinGame(gameId, sessionId, gameClient);
|
GameManager.getInstance().joinGame(gameId, sessionId);
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
handleException(ex);
|
handleException(ex);
|
||||||
|
|
@ -334,9 +351,9 @@ public class ServerImpl implements Server {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void watchGame(UUID gameId, UUID sessionId, GameClient gameClient) throws MageException {
|
public void watchGame(UUID gameId, UUID sessionId) throws MageException {
|
||||||
try {
|
try {
|
||||||
GameManager.getInstance().watchGame(gameId, sessionId, gameClient);
|
GameManager.getInstance().watchGame(gameId, sessionId);
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
handleException(ex);
|
handleException(ex);
|
||||||
|
|
@ -344,9 +361,9 @@ public class ServerImpl implements Server {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stopWatching(UUID gameId, UUID clientId) throws MageException {
|
public void stopWatching(UUID gameId, UUID sessionId) throws MageException {
|
||||||
try {
|
try {
|
||||||
GameManager.getInstance().stopWatching(gameId, clientId);
|
GameManager.getInstance().stopWatching(gameId, sessionId);
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
handleException(ex);
|
handleException(ex);
|
||||||
|
|
@ -354,9 +371,9 @@ public class ServerImpl implements Server {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void replayGame(UUID gameId, UUID sessionId, GameReplayClient replayClient) throws MageException {
|
public void replayGame(UUID sessionId) throws MageException {
|
||||||
try {
|
try {
|
||||||
ReplayManager.getInstance().startReplay(sessionId, replayClient);
|
ReplayManager.getInstance().startReplay(sessionId);
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
handleException(ex);
|
handleException(ex);
|
||||||
|
|
|
||||||
|
|
@ -28,13 +28,14 @@
|
||||||
|
|
||||||
package mage.server;
|
package mage.server;
|
||||||
|
|
||||||
|
import java.util.logging.Level;
|
||||||
import mage.server.util.ThreadExecutor;
|
import mage.server.util.ThreadExecutor;
|
||||||
import java.rmi.RemoteException;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
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.GameManager;
|
||||||
import mage.server.game.TableManager;
|
import mage.server.game.TableManager;
|
||||||
import mage.util.Logging;
|
import mage.util.Logging;
|
||||||
|
|
@ -49,17 +50,14 @@ public class Session {
|
||||||
private final static Logger logger = Logging.getLogger(Session.class.getName());
|
private final static Logger logger = Logging.getLogger(Session.class.getName());
|
||||||
|
|
||||||
private UUID sessionId;
|
private UUID sessionId;
|
||||||
|
private UUID clientId;
|
||||||
private String username;
|
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();
|
sessionId = UUID.randomUUID();
|
||||||
try {
|
this.username = userName;
|
||||||
username = client.getUserName();
|
this.clientId = clientId;
|
||||||
} catch (RemoteException ex) {
|
|
||||||
logger.log(Level.SEVERE, null, ex);
|
|
||||||
}
|
|
||||||
this.client = client;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public UUID getId() {
|
public UUID getId() {
|
||||||
|
|
@ -70,59 +68,79 @@ public class Session {
|
||||||
SessionManager.getInstance().removeSession(sessionId);
|
SessionManager.getInstance().removeSession(sessionId);
|
||||||
TableManager.getInstance().removeSession(sessionId);
|
TableManager.getInstance().removeSession(sessionId);
|
||||||
GameManager.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) {
|
public void gameStarted(final UUID gameId, final UUID playerId) {
|
||||||
executor.submit(
|
fireCallback(new ClientCallback("startGame", new UUID[] {gameId, playerId}));
|
||||||
new Runnable() {
|
// executor.submit(
|
||||||
@Override
|
// new Runnable() {
|
||||||
public void run() {
|
// @Override
|
||||||
try {
|
// public void run() {
|
||||||
client.gameStarted(gameId, playerId);
|
// try {
|
||||||
logger.info("game started for player " + playerId);
|
// client.gameStarted(gameId, playerId);
|
||||||
}
|
// logger.info("game started for player " + playerId);
|
||||||
catch (RemoteException ex) {
|
// }
|
||||||
logger.log(Level.WARNING, ex.getMessage());
|
// catch (RemoteException ex) {
|
||||||
kill();
|
// logger.log(Level.WARNING, ex.getMessage());
|
||||||
}
|
// kill();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
);
|
// }
|
||||||
|
// );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void watchGame(final UUID gameId) {
|
public void watchGame(final UUID gameId) {
|
||||||
executor.submit(
|
fireCallback(new ClientCallback("watchGame", gameId));
|
||||||
new Runnable() {
|
// executor.submit(
|
||||||
@Override
|
// new Runnable() {
|
||||||
public void run() {
|
// @Override
|
||||||
try {
|
// public void run() {
|
||||||
client.watchGame(gameId);
|
// try {
|
||||||
}
|
// client.watchGame(gameId);
|
||||||
catch (RemoteException ex) {
|
// }
|
||||||
logger.log(Level.WARNING, ex.getMessage());
|
// catch (RemoteException ex) {
|
||||||
kill();
|
// logger.log(Level.WARNING, ex.getMessage());
|
||||||
}
|
// kill();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
);
|
// }
|
||||||
|
// );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void replayGame(final UUID gameId) {
|
public void replayGame(final UUID gameId) {
|
||||||
executor.submit(
|
fireCallback(new ClientCallback("replayGame", gameId));
|
||||||
new Runnable() {
|
// executor.submit(
|
||||||
@Override
|
// new Runnable() {
|
||||||
public void run() {
|
// @Override
|
||||||
try {
|
// public void run() {
|
||||||
client.replayGame(gameId);
|
// try {
|
||||||
}
|
// client.replayGame(gameId);
|
||||||
catch (RemoteException ex) {
|
// }
|
||||||
logger.log(Level.WARNING, ex.getMessage());
|
// catch (RemoteException ex) {
|
||||||
kill();
|
// logger.log(Level.WARNING, ex.getMessage());
|
||||||
}
|
// kill();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
);
|
// }
|
||||||
|
// );
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUsername() {
|
public String getUsername() {
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,6 @@ package mage.server;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import mage.interfaces.Client;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|
@ -50,8 +49,8 @@ public class SessionManager {
|
||||||
return sessions.get(sessionId);
|
return sessions.get(sessionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public UUID createSession(Client c) {
|
public UUID createSession(String userName, UUID clientId) {
|
||||||
Session session = new Session(c);
|
Session session = new Session(userName, clientId);
|
||||||
sessions.put(session.getId(), session);
|
sessions.put(session.getId(), session);
|
||||||
return session.getId();
|
return session.getId();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,6 @@ import mage.cards.decks.DeckCardLists;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.game.GameReplay;
|
import mage.game.GameReplay;
|
||||||
import mage.game.events.TableEvent;
|
import mage.game.events.TableEvent;
|
||||||
import mage.interfaces.GameClient;
|
|
||||||
import mage.server.ChatManager;
|
import mage.server.ChatManager;
|
||||||
import mage.server.util.ThreadExecutor;
|
import mage.server.util.ThreadExecutor;
|
||||||
import mage.game.events.Listener;
|
import mage.game.events.Listener;
|
||||||
|
|
@ -95,7 +94,7 @@ public class GameController implements GameCallback {
|
||||||
break;
|
break;
|
||||||
case INFO:
|
case INFO:
|
||||||
ChatManager.getInstance().broadcast(chatId, "", event.getMessage());
|
ChatManager.getInstance().broadcast(chatId, "", event.getMessage());
|
||||||
logger.info(game.getId() + " " + event.getMessage());
|
logger.fine(game.getId() + " " + event.getMessage());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -140,11 +139,11 @@ public class GameController implements GameCallback {
|
||||||
return sessionPlayerMap.get(sessionId);
|
return sessionPlayerMap.get(sessionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void join(UUID sessionId, GameClient client) {
|
public void join(UUID sessionId) {
|
||||||
UUID playerId = sessionPlayerMap.get(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);
|
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));
|
gameSession.init(getGameView(playerId));
|
||||||
ChatManager.getInstance().broadcast(chatId, "", game.getPlayer(playerId).getName() + " has joined the game");
|
ChatManager.getInstance().broadcast(chatId, "", game.getPlayer(playerId).getName() + " has joined the game");
|
||||||
if (allJoined()) {
|
if (allJoined()) {
|
||||||
|
|
@ -168,8 +167,8 @@ public class GameController implements GameCallback {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void watch(UUID sessionId, GameClient client) {
|
public void watch(UUID sessionId) {
|
||||||
GameWatcher gameWatcher = new GameWatcher(client, sessionId, game.getId());
|
GameWatcher gameWatcher = new GameWatcher(sessionId, game.getId());
|
||||||
watchers.put(sessionId, gameWatcher);
|
watchers.put(sessionId, gameWatcher);
|
||||||
gameWatcher.init(getGameView());
|
gameWatcher.init(getGameView());
|
||||||
ChatManager.getInstance().broadcast(chatId, "", " has started watching");
|
ChatManager.getInstance().broadcast(chatId, "", " has started watching");
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,6 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||||
import mage.cards.decks.DeckCardLists;
|
import mage.cards.decks.DeckCardLists;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.game.GameReplay;
|
import mage.game.GameReplay;
|
||||||
import mage.interfaces.GameClient;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|
@ -56,8 +55,8 @@ public class GameManager {
|
||||||
return gameController.getSessionId();
|
return gameController.getSessionId();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void joinGame(UUID gameId, UUID sessionId, GameClient client) {
|
public void joinGame(UUID gameId, UUID sessionId) {
|
||||||
gameControllers.get(gameId).join(sessionId, client);
|
gameControllers.get(gameId).join(sessionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// public void leaveGame(UUID gameId, UUID clientId) {
|
// public void leaveGame(UUID gameId, UUID clientId) {
|
||||||
|
|
@ -92,12 +91,12 @@ public class GameManager {
|
||||||
gameControllers.get(gameId).concede(sessionId);
|
gameControllers.get(gameId).concede(sessionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void watchGame(UUID gameId, UUID sessionId, GameClient client) {
|
public void watchGame(UUID gameId, UUID sessionId) {
|
||||||
gameControllers.get(gameId).watch(sessionId, client);
|
gameControllers.get(gameId).watch(sessionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stopWatching(UUID gameId, UUID clientId) {
|
public void stopWatching(UUID gameId, UUID sessionId) {
|
||||||
gameControllers.get(gameId).stopWatching(clientId);
|
gameControllers.get(gameId).stopWatching(sessionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeSession(UUID sessionId) {
|
public void removeSession(UUID sessionId) {
|
||||||
|
|
|
||||||
|
|
@ -28,17 +28,19 @@
|
||||||
|
|
||||||
package mage.server.game;
|
package mage.server.game;
|
||||||
|
|
||||||
import java.rmi.RemoteException;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.concurrent.ScheduledFuture;
|
import java.util.concurrent.ScheduledFuture;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import mage.game.Game;
|
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.ConfigSettings;
|
||||||
import mage.server.util.ThreadExecutor;
|
import mage.server.util.ThreadExecutor;
|
||||||
import mage.view.AbilityPickerView;
|
import mage.view.AbilityPickerView;
|
||||||
import mage.view.CardsView;
|
import mage.view.CardsView;
|
||||||
|
import mage.view.GameClientMessage;
|
||||||
import mage.view.GameView;
|
import mage.view.GameView;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -53,171 +55,215 @@ public class GameSession extends GameWatcher {
|
||||||
private ScheduledFuture<?> futureTimeout;
|
private ScheduledFuture<?> futureTimeout;
|
||||||
protected static ScheduledExecutorService timeoutExecutor = ThreadExecutor.getInstance().getTimeoutExecutor();
|
protected static ScheduledExecutorService timeoutExecutor = ThreadExecutor.getInstance().getTimeoutExecutor();
|
||||||
|
|
||||||
public GameSession(GameClient client, Game game, UUID sessionId, UUID playerId) {
|
public GameSession(Game game, UUID sessionId, UUID playerId) {
|
||||||
super(client, sessionId, game.getId());
|
super(sessionId, game.getId());
|
||||||
this.game = game;
|
this.game = game;
|
||||||
this.playerId = playerId;
|
this.playerId = playerId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ask(final String question, final GameView gameView) {
|
public void ask(final String question, final GameView gameView) {
|
||||||
if (!killed) {
|
if (!killed) {
|
||||||
setupTimeout();
|
Session session = SessionManager.getInstance().getSession(sessionId);
|
||||||
rmiExecutor.submit(
|
if (session != null)
|
||||||
new Runnable() {
|
session.fireCallback(new ClientCallback("gameAsk", new GameClientMessage(gameView, question)));
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
client.ask(question, gameView);
|
|
||||||
} catch (RemoteException ex) {
|
|
||||||
handleRemoteException(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
// 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) {
|
public void target(final String question, final CardsView cardView, final boolean required, final GameView gameView) {
|
||||||
if (!killed) {
|
if (!killed) {
|
||||||
setupTimeout();
|
Session session = SessionManager.getInstance().getSession(sessionId);
|
||||||
rmiExecutor.submit(
|
if (session != null)
|
||||||
new Runnable() {
|
session.fireCallback(new ClientCallback("gameTarget", new GameClientMessage(gameView, question, cardView, required)));
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
client.target(question, cardView, required, gameView);
|
|
||||||
} catch (RemoteException ex) {
|
|
||||||
handleRemoteException(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
// 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) {
|
public void select(final String message, final GameView gameView) {
|
||||||
if (!killed) {
|
if (!killed) {
|
||||||
setupTimeout();
|
Session session = SessionManager.getInstance().getSession(sessionId);
|
||||||
rmiExecutor.submit(
|
if (session != null)
|
||||||
new Runnable() {
|
session.fireCallback(new ClientCallback("gameSelect", new GameClientMessage(gameView, message)));
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
client.select(message, gameView);
|
|
||||||
} catch (RemoteException ex) {
|
|
||||||
handleRemoteException(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
// 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) {
|
public void chooseAbility(final AbilityPickerView abilities) {
|
||||||
if (!killed) {
|
if (!killed) {
|
||||||
setupTimeout();
|
Session session = SessionManager.getInstance().getSession(sessionId);
|
||||||
rmiExecutor.submit(
|
if (session != null)
|
||||||
new Runnable() {
|
session.fireCallback(new ClientCallback("gameChooseAbility", abilities));
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
client.chooseAbility(abilities);
|
|
||||||
} catch (RemoteException ex) {
|
|
||||||
handleRemoteException(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
// 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) {
|
public void choose(final String message, final String[] choices) {
|
||||||
if (!killed) {
|
if (!killed) {
|
||||||
setupTimeout();
|
Session session = SessionManager.getInstance().getSession(sessionId);
|
||||||
rmiExecutor.submit(
|
if (session != null)
|
||||||
new Runnable() {
|
session.fireCallback(new ClientCallback("gameChoose", new GameClientMessage(choices, message)));
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
client.choose(message, choices);
|
|
||||||
} catch (RemoteException ex) {
|
|
||||||
handleRemoteException(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
// 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) {
|
public void playMana(final String message, final GameView gameView) {
|
||||||
if (!killed) {
|
if (!killed) {
|
||||||
setupTimeout();
|
Session session = SessionManager.getInstance().getSession(sessionId);
|
||||||
rmiExecutor.submit(
|
if (session != null)
|
||||||
new Runnable() {
|
session.fireCallback(new ClientCallback("gamePlayMana", new GameClientMessage(gameView, message)));
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
client.playMana(message, gameView);
|
|
||||||
} catch (RemoteException ex) {
|
|
||||||
handleRemoteException(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
// 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) {
|
public void playXMana(final String message, final GameView gameView) {
|
||||||
if (!killed) {
|
if (!killed) {
|
||||||
setupTimeout();
|
Session session = SessionManager.getInstance().getSession(sessionId);
|
||||||
rmiExecutor.submit(
|
if (session != null)
|
||||||
new Runnable() {
|
session.fireCallback(new ClientCallback("gamePlayXMana", new GameClientMessage(gameView, message)));
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
client.playXMana(message, gameView);
|
|
||||||
} catch (RemoteException ex) {
|
|
||||||
handleRemoteException(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
// 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) {
|
public void getAmount(final String message, final int min, final int max) {
|
||||||
if (!killed) {
|
if (!killed) {
|
||||||
setupTimeout();
|
Session session = SessionManager.getInstance().getSession(sessionId);
|
||||||
rmiExecutor.submit(
|
if (session != null)
|
||||||
new Runnable() {
|
session.fireCallback(new ClientCallback("gameSelectAmount", new GameClientMessage(message, min, max)));
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
client.getAmount(min, max);
|
|
||||||
} catch (RemoteException ex) {
|
|
||||||
handleRemoteException(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
// 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) {
|
public void revealCards(final String name, final CardsView cardView) {
|
||||||
if (!killed) {
|
if (!killed) {
|
||||||
rmiExecutor.submit(
|
Session session = SessionManager.getInstance().getSession(sessionId);
|
||||||
new Runnable() {
|
if (session != null)
|
||||||
@Override
|
session.fireCallback(new ClientCallback("gameReveal", new GameClientMessage(cardView, name)));
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
client.revealCards(name, cardView);
|
|
||||||
} catch (RemoteException ex) {
|
|
||||||
handleRemoteException(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
// if (!killed) {
|
||||||
|
// rmiExecutor.submit(
|
||||||
|
// new Runnable() {
|
||||||
|
// @Override
|
||||||
|
// public void run() {
|
||||||
|
// try {
|
||||||
|
// client.revealCards(name, cardView);
|
||||||
|
// } catch (RemoteException ex) {
|
||||||
|
// handleRemoteException(ex);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// );
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,12 +30,13 @@ package mage.server.game;
|
||||||
|
|
||||||
import java.rmi.RemoteException;
|
import java.rmi.RemoteException;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ExecutorService;
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import mage.interfaces.GameClient;
|
import mage.interfaces.callback.ClientCallback;
|
||||||
import mage.server.util.ThreadExecutor;
|
import mage.server.Session;
|
||||||
|
import mage.server.SessionManager;
|
||||||
import mage.util.Logging;
|
import mage.util.Logging;
|
||||||
|
import mage.view.GameClientMessage;
|
||||||
import mage.view.GameView;
|
import mage.view.GameView;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -44,83 +45,96 @@ import mage.view.GameView;
|
||||||
*/
|
*/
|
||||||
public class GameWatcher {
|
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 final static Logger logger = Logging.getLogger(GameWatcher.class.getName());
|
||||||
|
|
||||||
protected GameClient client;
|
|
||||||
|
|
||||||
protected UUID sessionId;
|
protected UUID sessionId;
|
||||||
protected UUID gameId;
|
protected UUID gameId;
|
||||||
protected boolean killed = false;
|
protected boolean killed = false;
|
||||||
|
|
||||||
public GameWatcher(GameClient client, UUID sessionId, UUID gameId) {
|
public GameWatcher(UUID sessionId, UUID gameId) {
|
||||||
this.client = client;
|
|
||||||
this.sessionId = sessionId;
|
this.sessionId = sessionId;
|
||||||
this.gameId = gameId;
|
this.gameId = gameId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init(final GameView gameView) {
|
public void init(final GameView gameView) {
|
||||||
if (!killed)
|
if (!killed) {
|
||||||
rmiExecutor.submit(
|
Session session = SessionManager.getInstance().getSession(sessionId);
|
||||||
new Runnable() {
|
if (session != null)
|
||||||
@Override
|
session.fireCallback(new ClientCallback("gameInit", gameView));
|
||||||
public void run() {
|
}
|
||||||
try {
|
// rmiExecutor.submit(
|
||||||
client.init(gameView);
|
// new Runnable() {
|
||||||
} catch (RemoteException ex) {
|
// @Override
|
||||||
handleRemoteException(ex);
|
// public void run() {
|
||||||
}
|
// try {
|
||||||
}
|
// client.init(gameView);
|
||||||
}
|
// } catch (RemoteException ex) {
|
||||||
);
|
// handleRemoteException(ex);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update(final GameView gameView) {
|
public void update(final GameView gameView) {
|
||||||
if (!killed)
|
if (!killed) {
|
||||||
rmiExecutor.submit(
|
Session session = SessionManager.getInstance().getSession(sessionId);
|
||||||
new Runnable() {
|
if (session != null)
|
||||||
@Override
|
session.fireCallback(new ClientCallback("gameUpdate", gameView));
|
||||||
public void run() {
|
}
|
||||||
try {
|
// rmiExecutor.submit(
|
||||||
client.update(gameView);
|
// new Runnable() {
|
||||||
} catch (RemoteException ex) {
|
// @Override
|
||||||
handleRemoteException(ex);
|
// public void run() {
|
||||||
}
|
// try {
|
||||||
}
|
// client.update(gameView);
|
||||||
}
|
// } catch (RemoteException ex) {
|
||||||
);
|
// handleRemoteException(ex);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void inform(final String message, final GameView gameView) {
|
public void inform(final String message, final GameView gameView) {
|
||||||
if (!killed)
|
if (!killed) {
|
||||||
rmiExecutor.submit(
|
Session session = SessionManager.getInstance().getSession(sessionId);
|
||||||
new Runnable() {
|
if (session != null)
|
||||||
@Override
|
session.fireCallback(new ClientCallback("gameInform", new GameClientMessage(gameView, message)));
|
||||||
public void run() {
|
}
|
||||||
try {
|
// rmiExecutor.submit(
|
||||||
client.inform(message, gameView);
|
// new Runnable() {
|
||||||
} catch (RemoteException ex) {
|
// @Override
|
||||||
handleRemoteException(ex);
|
// public void run() {
|
||||||
}
|
// try {
|
||||||
}
|
// client.inform(message, gameView);
|
||||||
}
|
// } catch (RemoteException ex) {
|
||||||
);
|
// handleRemoteException(ex);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void gameOver(final String message) {
|
public void gameOver(final String message) {
|
||||||
if (!killed)
|
if (!killed) {
|
||||||
rmiExecutor.submit(
|
Session session = SessionManager.getInstance().getSession(sessionId);
|
||||||
new Runnable() {
|
if (session != null)
|
||||||
@Override
|
session.fireCallback(new ClientCallback("gameOver", message));
|
||||||
public void run() {
|
}
|
||||||
try {
|
// rmiExecutor.submit(
|
||||||
client.gameOver(message);
|
// new Runnable() {
|
||||||
} catch (RemoteException ex) {
|
// @Override
|
||||||
handleRemoteException(ex);
|
// public void run() {
|
||||||
}
|
// try {
|
||||||
}
|
// client.gameOver(message);
|
||||||
}
|
// } catch (RemoteException ex) {
|
||||||
);
|
// handleRemoteException(ex);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void handleRemoteException(RemoteException ex) {
|
protected void handleRemoteException(RemoteException ex) {
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ public class PlayerFactory {
|
||||||
logger.log(Level.SEVERE, null, ex);
|
logger.log(Level.SEVERE, null, ex);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
logger.info("Player created: " + player.getId().toString());
|
logger.info("Player created: " + name + "-" + player.getId().toString());
|
||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,6 @@ package mage.server.game;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import mage.interfaces.GameReplayClient;
|
|
||||||
import mage.server.SessionManager;
|
import mage.server.SessionManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -49,13 +48,13 @@ public class ReplayManager {
|
||||||
private ConcurrentHashMap<UUID, ReplaySession> replaySessions = new ConcurrentHashMap<UUID, ReplaySession>();
|
private ConcurrentHashMap<UUID, ReplaySession> replaySessions = new ConcurrentHashMap<UUID, ReplaySession>();
|
||||||
|
|
||||||
public void replayGame(UUID sessionId, UUID gameId) {
|
public void replayGame(UUID sessionId, UUID gameId) {
|
||||||
ReplaySession replaySession = new ReplaySession(gameId);
|
ReplaySession replaySession = new ReplaySession(gameId, sessionId);
|
||||||
replaySessions.put(sessionId, replaySession);
|
replaySessions.put(sessionId, replaySession);
|
||||||
SessionManager.getInstance().getSession(sessionId).replayGame(gameId);
|
SessionManager.getInstance().getSession(sessionId).replayGame(gameId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startReplay(UUID sessionId, GameReplayClient replayClient) {
|
public void startReplay(UUID sessionId) {
|
||||||
replaySessions.get(sessionId).replay(replayClient);
|
replaySessions.get(sessionId).replay();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stopReplay(UUID sessionId) {
|
public void stopReplay(UUID sessionId) {
|
||||||
|
|
|
||||||
|
|
@ -28,15 +28,13 @@
|
||||||
|
|
||||||
package mage.server.game;
|
package mage.server.game;
|
||||||
|
|
||||||
import java.rmi.RemoteException;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ExecutorService;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import mage.game.GameReplay;
|
import mage.game.GameReplay;
|
||||||
import mage.game.GameState;
|
import mage.game.GameState;
|
||||||
import mage.interfaces.GameReplayClient;
|
import mage.interfaces.callback.ClientCallback;
|
||||||
import mage.server.util.ThreadExecutor;
|
import mage.server.Session;
|
||||||
|
import mage.server.SessionManager;
|
||||||
import mage.util.Logging;
|
import mage.util.Logging;
|
||||||
import mage.view.GameView;
|
import mage.view.GameView;
|
||||||
|
|
||||||
|
|
@ -46,30 +44,33 @@ import mage.view.GameView;
|
||||||
*/
|
*/
|
||||||
public class ReplaySession implements GameCallback {
|
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 final static Logger logger = Logging.getLogger(ReplaySession.class.getName());
|
||||||
|
|
||||||
private GameReplay game;
|
private GameReplay game;
|
||||||
private GameReplayClient client;
|
protected UUID sessionId;
|
||||||
|
|
||||||
ReplaySession(UUID gameId) {
|
ReplaySession(UUID gameId, UUID sessionId) {
|
||||||
this.game = GameManager.getInstance().createReplay(gameId);
|
this.game = GameManager.getInstance().createReplay(gameId);
|
||||||
|
this.sessionId = sessionId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void replay(GameReplayClient replayClient) {
|
public void replay() {
|
||||||
this.client = replayClient;
|
|
||||||
game.start();
|
game.start();
|
||||||
rmiExecutor.submit(
|
Session session = SessionManager.getInstance().getSession(sessionId);
|
||||||
new Runnable() {
|
if (session != null)
|
||||||
public void run() {
|
session.fireCallback(new ClientCallback("replayInit", new GameView(game.next())));
|
||||||
try {
|
// rmiExecutor.submit(
|
||||||
client.init(new GameView(game.next()));
|
// new Runnable() {
|
||||||
} catch (RemoteException ex) {
|
// public void run() {
|
||||||
logger.log(Level.SEVERE, null, ex);
|
// try {
|
||||||
}
|
// client.init(new GameView(game.next()));
|
||||||
}
|
// } catch (RemoteException ex) {
|
||||||
}
|
// logger.log(Level.SEVERE, null, ex);
|
||||||
);
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop() {
|
public void stop() {
|
||||||
|
|
@ -84,32 +85,39 @@ public class ReplaySession implements GameCallback {
|
||||||
updateGame(game.previous());
|
updateGame(game.previous());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void gameResult(final String result) {
|
public void gameResult(final String result) {
|
||||||
rmiExecutor.submit(
|
Session session = SessionManager.getInstance().getSession(sessionId);
|
||||||
new Runnable() {
|
if (session != null)
|
||||||
public void run() {
|
session.fireCallback(new ClientCallback("replayDone", result));
|
||||||
try {
|
// rmiExecutor.submit(
|
||||||
client.gameOver(result);
|
// new Runnable() {
|
||||||
} catch (RemoteException ex) {
|
// public void run() {
|
||||||
logger.log(Level.SEVERE, null, ex);
|
// try {
|
||||||
}
|
// client.gameOver(result);
|
||||||
}
|
// } catch (RemoteException ex) {
|
||||||
}
|
// logger.log(Level.SEVERE, null, ex);
|
||||||
);
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateGame(final GameState state) {
|
private void updateGame(final GameState state) {
|
||||||
rmiExecutor.submit(
|
Session session = SessionManager.getInstance().getSession(sessionId);
|
||||||
new Runnable() {
|
if (session != null)
|
||||||
public void run() {
|
session.fireCallback(new ClientCallback("replayUpdate", new GameView(state)));
|
||||||
try {
|
// rmiExecutor.submit(
|
||||||
client.update(new GameView(state));
|
// new Runnable() {
|
||||||
} catch (RemoteException ex) {
|
// public void run() {
|
||||||
logger.log(Level.SEVERE, null, ex);
|
// try {
|
||||||
}
|
// client.update(new GameView(state));
|
||||||
}
|
// } catch (RemoteException ex) {
|
||||||
}
|
// logger.log(Level.SEVERE, null, ex);
|
||||||
);
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -90,7 +90,7 @@ public class TableController {
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (GameException ex) {
|
} catch (GameException ex) {
|
||||||
logger.log(Level.WARNING, ex.getMessage());
|
logger.warning(ex.getMessage());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,10 @@ public class ConfigSettings {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getServerAddress() {
|
||||||
|
return config.getServer().getServerAddress();
|
||||||
|
}
|
||||||
|
|
||||||
public String getServerName() {
|
public String getServerName() {
|
||||||
return config.getServer().getServerName();
|
return config.getServer().getServerName();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@
|
||||||
|
|
||||||
<xs:element name="server">
|
<xs:element name="server">
|
||||||
<xs:complexType>
|
<xs:complexType>
|
||||||
|
<xs:attribute name="serverAddress" type="xs:string" use="required"/>
|
||||||
<xs:attribute name="serverName" 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="port" type="xs:positiveInteger" use="required"/>
|
||||||
<xs:attribute name="maxGameThreads" type="xs:positiveInteger" use="required"/>
|
<xs:attribute name="maxGameThreads" type="xs:positiveInteger" use="required"/>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue