Now client can start embedded Mage Server (player's feature request).

Works only for "localhost". Still can be used with external server but in such case server should be started first.
This commit is contained in:
magenoxx 2011-12-23 13:14:32 +04:00
parent 810d33c8ba
commit a7a496af0e
23 changed files with 118 additions and 27 deletions

View file

@ -12,6 +12,6 @@ hand-scaling-factor=1.3
# parameters for debugging and testing faster # parameters for debugging and testing faster
default-deck-path=C:\\Users\\836D~1\\AppData\\Local\\Temp\\tempDeck1577fd51-f098-420e-8794-c22d2c0602d99142449166006085381.dck default-deck-path=C:\\Users\\836D~1\\AppData\\Local\\Temp\\tempDeck1577fd51-f098-420e-8794-c22d2c0602d99142449166006085381.dck
# 0: Human, 1: Computer - default, 2: Computer - minimax, 3: Computer - minimax hybrid # 0: Human, 1: Computer - minimax, 2: Computer - mad, 3: Computer - Monte Carlo
default-other-player-index=3 default-other-player-index=2
default-computer-name=computer default-computer-name=computer

View file

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Config.xsd">
<server serverAddress="localhost" serverName="mage-server" port="17171" maxGameThreads="10" maxSecondsIdle="600"/>
<playerTypes>
<playerType name="Human" jar="mage-player-human.jar" className="mage.player.human.HumanPlayer"/>
<playerType name="Computer - minimax" jar="mage-player-aiminimax.jar" className="mage.player.ai.ComputerPlayer3"/>
<playerType name="Computer - mad" jar="mage-player-ai-ma.jar" className="mage.player.ai.ComputerPlayer6"/>
<playerType name="Computer - monte carlo" jar="mage-player-aimcts.jar" className="mage.player.ai.ComputerPlayerMCTS"/>
</playerTypes>
<gameTypes>
<gameType name="Two Player Duel" jar="mage-game-twoplayerduel.jar" className="mage.game.TwoPlayerMatch" typeName="mage.game.TwoPlayerDuelType"/>
<gameType name="Free For All" jar="mage-game-freeforall.jar" className="mage.game.FreeForAllMatch" typeName="mage.game.FreeForAllType"/>
</gameTypes>
<tournamentTypes>
<tournamentType name="Elimination Booster Draft" jar="mage-tournament-booster-draft.jar" className="mage.tournament.BoosterDraftEliminationTournament" typeName="mage.tournament.BoosterDraftEliminationTournamentType"/>
<tournamentType name="Sealed Elimination" jar="mage-tournament-sealed.jar" className="mage.tournament.SealedEliminationTournament" typeName="mage.tournament.SealedEliminationTournamentType"/>
</tournamentTypes>
<deckTypes>
<deckType name="Constructed - Vintage" jar="mage-deck-constructed.jar" className="mage.deck.Vintage"/>
<deckType name="Constructed - Extended" jar="mage-deck-constructed.jar" className="mage.deck.Extended"/>
<deckType name="Constructed - Standard" jar="mage-deck-constructed.jar" className="mage.deck.Standard"/>
<deckType name="Constructed - Shards of Alara Block" jar="mage-deck-constructed.jar" className="mage.deck.ShardsOfAlaraBlock"/>
<deckType name="Constructed - Zendikar Block" jar="mage-deck-constructed.jar" className="mage.deck.ZendikarBlock"/>
<deckType name="Constructed - Scars of Mirrodin Block" jar="mage-deck-constructed.jar" className="mage.deck.ScarsOfMirrodinBlock"/>
<deckType name="Limited" jar="mage-deck-limited.jar" className="mage.deck.Limited"/>
</deckTypes>
</config>

View file

@ -0,0 +1,14 @@
#default levels
log4j.rootLogger=debug, console, logfile
#console log
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%-5p [%d{yyyy-MM-dd HH:mm [ss:SSS]}] %C{1}[%t]: %m%n
log4j.appender.console.Threshold=info
#file log
log4j.appender.logfile=org.apache.log4j.FileAppender
log4j.appender.logfile.File=mageserver.log
log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
log4j.appender.logfile.layout.ConversionPattern=%-5p [%d{yyyy-MM-dd HH:mm [ss:SSS]}] %C{1}[%t]: %m%n

View file

@ -0,0 +1,3 @@
grant {
permission java.security.AllPermission;
};

View file

@ -0,0 +1,7 @@
maxDepth=10
maxNodes=5000
evaluatorLifeFactor=2
evaluatorPermanentFactor=1
evaluatorCreatureFactor=1
evaluatorHandFactor=1
maxThinkSeconds=30

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -30,6 +30,12 @@
<artifactId>mage-sets</artifactId> <artifactId>mage-sets</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<!-- for running embedded mage server -->
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>mage-server</artifactId>
<version>${mage-version}</version>
</dependency>
<dependency> <dependency>
<groupId>com.googlecode.jspf</groupId> <groupId>com.googlecode.jspf</groupId>
<artifactId>jspf-core</artifactId> <artifactId>jspf-core</artifactId>

View file

@ -61,12 +61,13 @@ import mage.client.util.SettingsManager;
import mage.client.util.gui.ArrowBuilder; import mage.client.util.gui.ArrowBuilder;
import mage.components.ImagePanel; import mage.components.ImagePanel;
import mage.game.match.MatchOptions; import mage.game.match.MatchOptions;
import mage.interfaces.MageClient; import mage.interfaces.*;
import mage.interfaces.callback.CallbackClient; import mage.interfaces.callback.CallbackClient;
import mage.interfaces.callback.ClientCallback; import mage.interfaces.callback.ClientCallback;
import mage.remote.Connection; import mage.remote.Connection;
import mage.remote.Connection.ProxyType; import mage.remote.Connection.ProxyType;
import mage.remote.Session; import mage.remote.Session;
import mage.server.Main;
import mage.sets.Sets; import mage.sets.Sets;
import mage.utils.MageVersion; import mage.utils.MageVersion;
import mage.view.TableView; import mage.view.TableView;
@ -180,6 +181,12 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
this.setExtendedState(JFrame.MAXIMIZED_BOTH); this.setExtendedState(JFrame.MAXIMIZED_BOTH);
session = new Session(this); session = new Session(this);
session.setEmbeddedMageServerAction(new mage.interfaces.Action() {
@Override
public void execute() {
Main.main(new String[] {});
}
});
callbackClient = new CallbackClientImpl(this); callbackClient = new CallbackClientImpl(this);
connectDialog = new ConnectDialog(); connectDialog = new ConnectDialog();
desktopPane.add(connectDialog, JLayeredPane.POPUP_LAYER); desktopPane.add(connectDialog, JLayeredPane.POPUP_LAYER);

View file

@ -71,7 +71,7 @@ public final class Constants {
public static final String PLUGINS_DIRECTORY = "plugins/"; public static final String PLUGINS_DIRECTORY = "plugins/";
public enum SessionState { public enum SessionState {
DISCONNECTED, CONNECTED, CONNECTING, DISCONNECTING, SERVER_UNAVAILABLE; DISCONNECTED, CONNECTED, CONNECTING, DISCONNECTING, SERVER_UNAVAILABLE, SERVER_STARTING;
} }
} }

View file

@ -0,0 +1,10 @@
package mage.interfaces;
/**
* Action interface
*
* @author ayratn
*/
public interface Action {
public void execute();
}

View file

@ -28,23 +28,13 @@
package mage.remote; package mage.remote;
import java.net.Authenticator;
import java.net.ConnectException;
import java.net.MalformedURLException;
import java.net.PasswordAuthentication;
import java.net.SocketException;
import java.net.SocketTimeoutException;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import mage.cards.decks.DeckCardLists;
import mage.game.GameException;
import mage.MageException; import mage.MageException;
import mage.cards.decks.DeckCardLists;
import mage.constants.Constants.SessionState; import mage.constants.Constants.SessionState;
import mage.game.GameException;
import mage.game.match.MatchOptions; import mage.game.match.MatchOptions;
import mage.game.tournament.TournamentOptions; import mage.game.tournament.TournamentOptions;
import mage.interfaces.Action;
import mage.interfaces.MageClient; import mage.interfaces.MageClient;
import mage.interfaces.MageServer; import mage.interfaces.MageServer;
import mage.interfaces.ServerState; import mage.interfaces.ServerState;
@ -52,12 +42,7 @@ import mage.interfaces.callback.ClientCallback;
import mage.utils.CompressUtil; import mage.utils.CompressUtil;
import mage.view.*; import mage.view.*;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.jboss.remoting.CannotConnectException; import org.jboss.remoting.*;
import org.jboss.remoting.Client;
import org.jboss.remoting.ConnectionListener;
import org.jboss.remoting.ConnectionValidator;
import org.jboss.remoting.InvokerLocator;
import org.jboss.remoting.Remoting;
import org.jboss.remoting.callback.Callback; import org.jboss.remoting.callback.Callback;
import org.jboss.remoting.callback.HandleCallbackException; import org.jboss.remoting.callback.HandleCallbackException;
import org.jboss.remoting.callback.InvokerCallbackHandler; import org.jboss.remoting.callback.InvokerCallbackHandler;
@ -65,6 +50,9 @@ import org.jboss.remoting.transport.bisocket.Bisocket;
import org.jboss.remoting.transport.socket.SocketWrapper; import org.jboss.remoting.transport.socket.SocketWrapper;
import org.jboss.remoting.transporter.TransporterClient; import org.jboss.remoting.transporter.TransporterClient;
import java.net.*;
import java.util.*;
/** /**
* *
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
@ -81,11 +69,18 @@ public class Session {
private SessionState sessionState = SessionState.DISCONNECTED; private SessionState sessionState = SessionState.DISCONNECTED;
private Connection connection; private Connection connection;
private Action embeddedMageServerAction;
private static boolean debugMode = false; private static boolean debugMode = false;
private static boolean standalone = true;
private boolean canceled = false; private boolean canceled = false;
static { static {
debugMode = System.getProperty("debug.mage") != null; debugMode = System.getProperty("debug.mage") != null;
if (System.getProperty("skip.standalone") != null) {
standalone = false;
}
} }
public Session(MageClient client) { public Session(MageClient client) {
@ -107,6 +102,11 @@ public class Session {
} }
public boolean connect() { public boolean connect() {
if (standalone && connection.getHost().equals("localhost")) {
runEmbeddedMageServer();
}
sessionState = SessionState.CONNECTING; sessionState = SessionState.CONNECTING;
try { try {
System.setProperty("http.nonProxyHosts", "code.google.com"); System.setProperty("http.nonProxyHosts", "code.google.com");
@ -200,6 +200,12 @@ public class Session {
return false; return false;
} }
private void runEmbeddedMageServer() {
if (embeddedMageServerAction != null) {
embeddedMageServerAction.execute();
}
}
private void handleCannotConnectException(CannotConnectException ex) { private void handleCannotConnectException(CannotConnectException ex) {
logger.warn("Cannot connect", ex); logger.warn("Cannot connect", ex);
Throwable t = ex.getCause(); Throwable t = ex.getCause();
@ -986,6 +992,9 @@ public class Session {
return false; return false;
} }
public void setEmbeddedMageServerAction(Action embeddedMageServerAction) {
this.embeddedMageServerAction = embeddedMageServerAction;
}
} }
class MageAuthenticator extends Authenticator { class MageAuthenticator extends Authenticator {

View file

@ -207,8 +207,15 @@ public class Main {
@Override @Override
public Object invoke(final InvocationRequest invocation) throws Throwable { public Object invoke(final InvocationRequest invocation) throws Throwable {
String sessionId = invocation.getSessionId(); String sessionId = invocation.getSessionId();
Map map = invocation.getRequestPayload();
String host;
if (map != null) {
InetAddress clientAddress = (InetAddress) invocation.getRequestPayload().get(Remoting.CLIENT_ADDRESS); InetAddress clientAddress = (InetAddress) invocation.getRequestPayload().get(Remoting.CLIENT_ADDRESS);
SessionManager.getInstance().getSession(sessionId).setHost(clientAddress.getHostAddress()); host = clientAddress.getHostAddress();
} else {
host = "localhost";
}
SessionManager.getInstance().getSession(sessionId).setHost(host);
return null; return null;
} }