mirror of
https://github.com/correl/mage.git
synced 2024-11-28 19:19:55 +00:00
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:
parent
810d33c8ba
commit
a7a496af0e
23 changed files with 118 additions and 27 deletions
|
@ -12,6 +12,6 @@ hand-scaling-factor=1.3
|
|||
|
||||
# parameters for debugging and testing faster
|
||||
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
|
||||
default-other-player-index=3
|
||||
# 0: Human, 1: Computer - minimax, 2: Computer - mad, 3: Computer - Monte Carlo
|
||||
default-other-player-index=2
|
||||
default-computer-name=computer
|
||||
|
|
28
Mage.Client/config/config.xml
Normal file
28
Mage.Client/config/config.xml
Normal 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>
|
14
Mage.Client/config/log4j.properties
Normal file
14
Mage.Client/config/log4j.properties
Normal 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
|
3
Mage.Client/config/security.policy
Normal file
3
Mage.Client/config/security.policy
Normal file
|
@ -0,0 +1,3 @@
|
|||
grant {
|
||||
permission java.security.AllPermission;
|
||||
};
|
7
Mage.Client/plugins/AIMinimax.properties
Normal file
7
Mage.Client/plugins/AIMinimax.properties
Normal file
|
@ -0,0 +1,7 @@
|
|||
maxDepth=10
|
||||
maxNodes=5000
|
||||
evaluatorLifeFactor=2
|
||||
evaluatorPermanentFactor=1
|
||||
evaluatorCreatureFactor=1
|
||||
evaluatorHandFactor=1
|
||||
maxThinkSeconds=30
|
BIN
Mage.Client/plugins/mage-deck-constructed.jar
Normal file
BIN
Mage.Client/plugins/mage-deck-constructed.jar
Normal file
Binary file not shown.
BIN
Mage.Client/plugins/mage-deck-limited.jar
Normal file
BIN
Mage.Client/plugins/mage-deck-limited.jar
Normal file
Binary file not shown.
BIN
Mage.Client/plugins/mage-draft-8playerbooster.jar
Normal file
BIN
Mage.Client/plugins/mage-draft-8playerbooster.jar
Normal file
Binary file not shown.
BIN
Mage.Client/plugins/mage-game-freeforall.jar
Normal file
BIN
Mage.Client/plugins/mage-game-freeforall.jar
Normal file
Binary file not shown.
BIN
Mage.Client/plugins/mage-game-twoplayerduel.jar
Normal file
BIN
Mage.Client/plugins/mage-game-twoplayerduel.jar
Normal file
Binary file not shown.
BIN
Mage.Client/plugins/mage-player-ai-ma.jar
Normal file
BIN
Mage.Client/plugins/mage-player-ai-ma.jar
Normal file
Binary file not shown.
BIN
Mage.Client/plugins/mage-player-ai.jar
Normal file
BIN
Mage.Client/plugins/mage-player-ai.jar
Normal file
Binary file not shown.
BIN
Mage.Client/plugins/mage-player-aimcts.jar
Normal file
BIN
Mage.Client/plugins/mage-player-aimcts.jar
Normal file
Binary file not shown.
BIN
Mage.Client/plugins/mage-player-aiminimax.jar
Normal file
BIN
Mage.Client/plugins/mage-player-aiminimax.jar
Normal file
Binary file not shown.
BIN
Mage.Client/plugins/mage-player-human.jar
Normal file
BIN
Mage.Client/plugins/mage-player-human.jar
Normal file
Binary file not shown.
BIN
Mage.Client/plugins/mage-tournament-booster-draft.jar
Normal file
BIN
Mage.Client/plugins/mage-tournament-booster-draft.jar
Normal file
Binary file not shown.
BIN
Mage.Client/plugins/mage-tournament-sealed.jar
Normal file
BIN
Mage.Client/plugins/mage-tournament-sealed.jar
Normal file
Binary file not shown.
|
@ -30,6 +30,12 @@
|
|||
<artifactId>mage-sets</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<!-- for running embedded mage server -->
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>mage-server</artifactId>
|
||||
<version>${mage-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.googlecode.jspf</groupId>
|
||||
<artifactId>jspf-core</artifactId>
|
||||
|
|
|
@ -61,12 +61,13 @@ import mage.client.util.SettingsManager;
|
|||
import mage.client.util.gui.ArrowBuilder;
|
||||
import mage.components.ImagePanel;
|
||||
import mage.game.match.MatchOptions;
|
||||
import mage.interfaces.MageClient;
|
||||
import mage.interfaces.*;
|
||||
import mage.interfaces.callback.CallbackClient;
|
||||
import mage.interfaces.callback.ClientCallback;
|
||||
import mage.remote.Connection;
|
||||
import mage.remote.Connection.ProxyType;
|
||||
import mage.remote.Session;
|
||||
import mage.server.Main;
|
||||
import mage.sets.Sets;
|
||||
import mage.utils.MageVersion;
|
||||
import mage.view.TableView;
|
||||
|
@ -180,6 +181,12 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
|
|||
this.setExtendedState(JFrame.MAXIMIZED_BOTH);
|
||||
|
||||
session = new Session(this);
|
||||
session.setEmbeddedMageServerAction(new mage.interfaces.Action() {
|
||||
@Override
|
||||
public void execute() {
|
||||
Main.main(new String[] {});
|
||||
}
|
||||
});
|
||||
callbackClient = new CallbackClientImpl(this);
|
||||
connectDialog = new ConnectDialog();
|
||||
desktopPane.add(connectDialog, JLayeredPane.POPUP_LAYER);
|
||||
|
|
|
@ -71,7 +71,7 @@ public final class Constants {
|
|||
public static final String PLUGINS_DIRECTORY = "plugins/";
|
||||
|
||||
public enum SessionState {
|
||||
DISCONNECTED, CONNECTED, CONNECTING, DISCONNECTING, SERVER_UNAVAILABLE;
|
||||
DISCONNECTED, CONNECTED, CONNECTING, DISCONNECTING, SERVER_UNAVAILABLE, SERVER_STARTING;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
10
Mage.Common/src/mage/interfaces/Action.java
Normal file
10
Mage.Common/src/mage/interfaces/Action.java
Normal file
|
@ -0,0 +1,10 @@
|
|||
package mage.interfaces;
|
||||
|
||||
/**
|
||||
* Action interface
|
||||
*
|
||||
* @author ayratn
|
||||
*/
|
||||
public interface Action {
|
||||
public void execute();
|
||||
}
|
|
@ -28,23 +28,13 @@
|
|||
|
||||
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.cards.decks.DeckCardLists;
|
||||
import mage.constants.Constants.SessionState;
|
||||
import mage.game.GameException;
|
||||
import mage.game.match.MatchOptions;
|
||||
import mage.game.tournament.TournamentOptions;
|
||||
import mage.interfaces.Action;
|
||||
import mage.interfaces.MageClient;
|
||||
import mage.interfaces.MageServer;
|
||||
import mage.interfaces.ServerState;
|
||||
|
@ -52,12 +42,7 @@ import mage.interfaces.callback.ClientCallback;
|
|||
import mage.utils.CompressUtil;
|
||||
import mage.view.*;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.jboss.remoting.CannotConnectException;
|
||||
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.*;
|
||||
import org.jboss.remoting.callback.Callback;
|
||||
import org.jboss.remoting.callback.HandleCallbackException;
|
||||
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.transporter.TransporterClient;
|
||||
|
||||
import java.net.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
|
@ -81,11 +69,18 @@ public class Session {
|
|||
private SessionState sessionState = SessionState.DISCONNECTED;
|
||||
private Connection connection;
|
||||
|
||||
private Action embeddedMageServerAction;
|
||||
|
||||
private static boolean debugMode = false;
|
||||
private static boolean standalone = true;
|
||||
|
||||
private boolean canceled = false;
|
||||
|
||||
static {
|
||||
debugMode = System.getProperty("debug.mage") != null;
|
||||
if (System.getProperty("skip.standalone") != null) {
|
||||
standalone = false;
|
||||
}
|
||||
}
|
||||
|
||||
public Session(MageClient client) {
|
||||
|
@ -107,6 +102,11 @@ public class Session {
|
|||
}
|
||||
|
||||
public boolean connect() {
|
||||
|
||||
if (standalone && connection.getHost().equals("localhost")) {
|
||||
runEmbeddedMageServer();
|
||||
}
|
||||
|
||||
sessionState = SessionState.CONNECTING;
|
||||
try {
|
||||
System.setProperty("http.nonProxyHosts", "code.google.com");
|
||||
|
@ -200,6 +200,12 @@ public class Session {
|
|||
return false;
|
||||
}
|
||||
|
||||
private void runEmbeddedMageServer() {
|
||||
if (embeddedMageServerAction != null) {
|
||||
embeddedMageServerAction.execute();
|
||||
}
|
||||
}
|
||||
|
||||
private void handleCannotConnectException(CannotConnectException ex) {
|
||||
logger.warn("Cannot connect", ex);
|
||||
Throwable t = ex.getCause();
|
||||
|
@ -986,6 +992,9 @@ public class Session {
|
|||
return false;
|
||||
}
|
||||
|
||||
public void setEmbeddedMageServerAction(Action embeddedMageServerAction) {
|
||||
this.embeddedMageServerAction = embeddedMageServerAction;
|
||||
}
|
||||
}
|
||||
|
||||
class MageAuthenticator extends Authenticator {
|
||||
|
|
|
@ -207,8 +207,15 @@ public class Main {
|
|||
@Override
|
||||
public Object invoke(final InvocationRequest invocation) throws Throwable {
|
||||
String sessionId = invocation.getSessionId();
|
||||
Map map = invocation.getRequestPayload();
|
||||
String host;
|
||||
if (map != null) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue