Added build time to version info, cleanup manifest files;

This commit is contained in:
Oleg Agafonov 2018-12-15 18:29:10 +04:00
parent 498edb4138
commit 0a2f312da7
19 changed files with 243 additions and 205 deletions

View file

@ -1,3 +0,0 @@
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build
SplashScreen-Image: splash.jpg

View file

@ -194,11 +194,13 @@
<artifactId>maven-jar-plugin</artifactId> <artifactId>maven-jar-plugin</artifactId>
<configuration> <configuration>
<archive> <archive>
<manifestFile>${manifest.file}</manifestFile>
<manifest> <manifest>
<addClasspath>true</addClasspath> <addClasspath>true</addClasspath>
<mainClass>mage.client.MageFrame</mainClass> <mainClass>mage.client.MageFrame</mainClass>
</manifest> </manifest>
<manifestEntries>
<SplashScreen-Image>splash.jpg</SplashScreen-Image>
</manifestEntries>
</archive> </archive>
</configuration> </configuration>
</plugin> </plugin>

View file

@ -1,21 +1,5 @@
package mage.client; package mage.client;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import java.net.SocketException;
import java.util.*;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.prefs.Preferences;
import javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.event.PopupMenuEvent;
import javax.swing.event.PopupMenuListener;
import mage.cards.action.ActionCallback; import mage.cards.action.ActionCallback;
import mage.cards.decks.Deck; import mage.cards.decks.Deck;
import mage.cards.repository.CardRepository; import mage.cards.repository.CardRepository;
@ -67,6 +51,22 @@ import org.mage.plugins.card.images.DownloadPictures;
import org.mage.plugins.card.info.CardInfoPaneImpl; import org.mage.plugins.card.info.CardInfoPaneImpl;
import org.mage.plugins.card.utils.impl.ImageManagerImpl; import org.mage.plugins.card.utils.impl.ImageManagerImpl;
import javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.event.PopupMenuEvent;
import javax.swing.event.PopupMenuListener;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import java.net.SocketException;
import java.util.*;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.prefs.Preferences;
/** /**
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
*/ */
@ -93,7 +93,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
private static final Preferences PREFS = Preferences.userNodeForPackage(MageFrame.class); private static final Preferences PREFS = Preferences.userNodeForPackage(MageFrame.class);
private JLabel title; private JLabel title;
private Rectangle titleRectangle; private Rectangle titleRectangle;
private static final MageVersion VERSION = new MageVersion(MageVersion.MAGE_VERSION_MAJOR, MageVersion.MAGE_VERSION_MINOR, MageVersion.MAGE_VERSION_PATCH, MageVersion.MAGE_VERSION_MINOR_PATCH, MageVersion.MAGE_VERSION_INFO); private static final MageVersion VERSION = new MageVersion(MageFrame.class);
private Connection currentConnection; private Connection currentConnection;
private static MagePane activeFrame; private static MagePane activeFrame;
private static boolean liteMode = false; private static boolean liteMode = false;
@ -136,7 +136,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
public static boolean isGray() { public static boolean isGray() {
return grayMode; return grayMode;
} }
public static boolean isSkipSmallSymbolGenerationForExisting() { public static boolean isSkipSmallSymbolGenerationForExisting() {
return skipSmallSymbolGenerationForExisting; return skipSmallSymbolGenerationForExisting;
} }
@ -760,7 +760,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
prepareAndShowTablesPane(); prepareAndShowTablesPane();
return true; return true;
} else { } else {
showMessage("Unable to connect to server"); showMessage("Unable connect to server");
} }
} finally { } finally {
setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
@ -934,16 +934,16 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout); getContentPane().setLayout(layout);
layout.setHorizontalGroup( layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(desktopPane, javax.swing.GroupLayout.DEFAULT_SIZE, 769, Short.MAX_VALUE) .addComponent(desktopPane, javax.swing.GroupLayout.DEFAULT_SIZE, 769, Short.MAX_VALUE)
.addComponent(mageToolbar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(mageToolbar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
); );
layout.setVerticalGroup( layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup() .addGroup(layout.createSequentialGroup()
.addComponent(mageToolbar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(mageToolbar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(2, 2, 2) .addGap(2, 2, 2)
.addComponent(desktopPane, javax.swing.GroupLayout.DEFAULT_SIZE, 145, Short.MAX_VALUE)) .addComponent(desktopPane, javax.swing.GroupLayout.DEFAULT_SIZE, 145, Short.MAX_VALUE))
); );
pack(); pack();
@ -1168,7 +1168,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
startTime = System.currentTimeMillis(); startTime = System.currentTimeMillis();
Thread.setDefaultUncaughtExceptionHandler((t, e) -> LOGGER.fatal(null, e)); Thread.setDefaultUncaughtExceptionHandler((t, e) -> LOGGER.fatal(null, e));
SwingUtilities.invokeLater(() -> { SwingUtilities.invokeLater(() -> {
for (int i = 0; i < args.length; i++) { for (int i = 0; i < args.length; i++) {
String arg = args[i]; String arg = args[i];
@ -1184,20 +1184,20 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
if (arg.startsWith(SKIP_DONE_SYMBOLS)) { if (arg.startsWith(SKIP_DONE_SYMBOLS)) {
skipSmallSymbolGenerationForExisting = true; skipSmallSymbolGenerationForExisting = true;
} }
if (arg.startsWith(USER_ARG)){ if (arg.startsWith(USER_ARG)) {
startUser = args[i+1]; startUser = args[i + 1];
i++; i++;
} }
if (arg.startsWith(PASSWORD_ARG)){ if (arg.startsWith(PASSWORD_ARG)) {
startPassword = args[i+1]; startPassword = args[i + 1];
i++; i++;
} }
if (arg.startsWith(SERVER_ARG)){ if (arg.startsWith(SERVER_ARG)) {
startServer = args[i+1]; startServer = args[i + 1];
i++; i++;
} }
if (arg.startsWith(PORT_ARG)){ if (arg.startsWith(PORT_ARG)) {
startPort = Integer.valueOf(args[i+1]); startPort = Integer.valueOf(args[i + 1]);
i++; i++;
} }
} }
@ -1212,14 +1212,14 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
} }
} }
instance = new MageFrame(); instance = new MageFrame();
if( startUser != null){ if (startUser != null) {
instance.currentConnection = new Connection(); instance.currentConnection = new Connection();
instance.currentConnection.setUsername(startUser); instance.currentConnection.setUsername(startUser);
instance.currentConnection.setHost(startServer); instance.currentConnection.setHost(startServer);
if (startPort > 0){ if (startPort > 0) {
instance.currentConnection.setPort(startPort); instance.currentConnection.setPort(startPort);
}else { } else {
instance.currentConnection.setPort(MagePreferences.getServerPortWithDefault(Config.port)); instance.currentConnection.setPort(MagePreferences.getServerPortWithDefault(Config.port));
} }
PreferencesDialog.setProxyInformation(instance.currentConnection); PreferencesDialog.setProxyInformation(instance.currentConnection);
@ -1339,18 +1339,18 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
} else { } else {
LOGGER.info("DISCONNECTED (NO Event Dispatch Thread)"); LOGGER.info("DISCONNECTED (NO Event Dispatch Thread)");
SwingUtilities.invokeLater(() -> { SwingUtilities.invokeLater(() -> {
setConnectButtonText(NOT_CONNECTED_TEXT); setConnectButtonText(NOT_CONNECTED_TEXT);
disableButtons(); disableButtons();
hideGames(); hideGames();
hideTables(); hideTables();
SessionHandler.disconnect(false); SessionHandler.disconnect(false);
if (errorCall) { if (errorCall) {
UserRequestMessage message = new UserRequestMessage("Connection lost", "The connection to server was lost. Reconnect?"); UserRequestMessage message = new UserRequestMessage("Connection lost", "The connection to server was lost. Reconnect?");
message.setButton1("No", null); message.setButton1("No", null);
message.setButton2("Yes", PlayerAction.CLIENT_RECONNECT); message.setButton2("Yes", PlayerAction.CLIENT_RECONNECT);
showUserRequestDialog(message); showUserRequestDialog(message);
} }
} }
); );
} }
} }

View file

@ -1,3 +0,0 @@
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build
SplashScreen-Image: splash.jpg

View file

@ -1,8 +1,5 @@
package mage.client.game; package mage.client.game;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import javax.swing.*;
import mage.client.components.MageUI; import mage.client.components.MageUI;
import mage.interfaces.MageClient; import mage.interfaces.MageClient;
import mage.interfaces.callback.ClientCallback; import mage.interfaces.callback.ClientCallback;
@ -13,6 +10,10 @@ import mage.utils.MageVersion;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.junit.Ignore; import org.junit.Ignore;
import javax.swing.*;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
/** /**
* Test for emulating the connection from multi mage clients. * Test for emulating the connection from multi mage clients.
* *
@ -30,7 +31,7 @@ public class MultiConnectTest {
private static final CountDownLatch latch = new CountDownLatch(USER_CONNECT_COUNT); private static final CountDownLatch latch = new CountDownLatch(USER_CONNECT_COUNT);
private static final MageVersion version = new MageVersion(MageVersion.MAGE_VERSION_MAJOR, MageVersion.MAGE_VERSION_MINOR, MageVersion.MAGE_VERSION_PATCH, MageVersion.MAGE_VERSION_MINOR_PATCH, MageVersion.MAGE_VERSION_INFO); private static final MageVersion version = new MageVersion(MultiConnectTest.class);
private static volatile int connected; private static volatile int connected;

View file

@ -1,15 +1,5 @@
package mage.remote; package mage.remote;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.UndeclaredThrowableException;
import java.net.*;
import java.util.*;
import java.util.concurrent.TimeUnit;
import mage.MageException; import mage.MageException;
import mage.cards.decks.DeckCardLists; import mage.cards.decks.DeckCardLists;
import mage.cards.repository.CardInfo; import mage.cards.repository.CardInfo;
@ -38,6 +28,12 @@ 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.io.*;
import java.lang.reflect.UndeclaredThrowableException;
import java.net.*;
import java.util.*;
import java.util.concurrent.TimeUnit;
/** /**
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
*/ */
@ -94,37 +90,38 @@ public class SessionImpl implements Session {
return remoting.run(); return remoting.run();
} catch (MalformedURLException ex) { } catch (MalformedURLException ex) {
logger.fatal("", ex); logger.fatal("", ex);
client.showMessage("Unable to connect to server. " + ex.getMessage()); client.showMessage("Unable connect to server. " + ex.getMessage());
} catch (UndeclaredThrowableException ex) { } catch (UndeclaredThrowableException ex) {
String addMessage = ""; String addMessage = "";
Throwable cause = ex.getCause(); Throwable cause = ex.getCause();
if (cause instanceof InvocationFailureException) { if (cause instanceof InvocationFailureException) {
InvocationFailureException exep = (InvocationFailureException) cause; InvocationFailureException exep = (InvocationFailureException) cause;
if (exep.getCause() instanceof IOException) { if (exep.getCause() instanceof IOException) {
if (exep.getCause().getMessage().startsWith("Field hash null is not available on current")) { if (exep.getCause().getMessage().startsWith("Field hash null is not available on current")
addMessage = "Probabaly the server version is not compatible to the client. "; || exep.getCause().getMessage().endsWith("end of file")) {
addMessage = "Probably the server version is not compatible with the client. ";
} }
} }
} else if (cause instanceof NoSuchMethodException) { } else if (cause instanceof NoSuchMethodException) {
// NoSuchMethodException is thrown on an invocation of an unknow JBoss remoting // NoSuchMethodException is thrown on an invocation of an unknow JBoss remoting
// method, so it's likely to be because of a version incompatibility. // method, so it's likely to be because of a version incompatibility.
addMessage = "The following method is not available in the server, probably the " addMessage = "The following method is not available in the server, probably the "
+ "server version is not compatible to the client: " + cause.getMessage(); + "server version is not compatible with the client: " + cause.getMessage();
} }
if (addMessage.isEmpty()) { if (addMessage.isEmpty()) {
logger.fatal("", ex); logger.fatal("", ex);
} }
client.showMessage("Unable to connect to server. " + addMessage + (ex.getMessage() != null ? ex.getMessage() : "")); client.showMessage("Unable connect to server. " + addMessage + (ex.getMessage() != null ? ex.getMessage() : ""));
} catch (IOException ex) { } catch (IOException ex) {
logger.fatal("", ex); logger.fatal("", ex);
String addMessage = ""; String addMessage = "";
if (ex.getMessage() != null && ex.getMessage().startsWith("Unable to perform invocation")) { if (ex.getMessage() != null && ex.getMessage().startsWith("Unable to perform invocation")) {
addMessage = "Maybe the server version is not compatible. "; addMessage = "Maybe the server version is not compatible. ";
} }
client.showMessage("Unable to connect to server. " + addMessage + ex.getMessage() != null ? ex.getMessage() : ""); client.showMessage("Unable connect to server. " + addMessage + ex.getMessage() != null ? ex.getMessage() : "");
} catch (MageVersionException ex) { } catch (MageVersionException ex) {
if (!canceled) { if (!canceled) {
client.showMessage("Unable to connect to server. " + ex.getMessage()); client.showMessage("Unable connect to server. " + ex.getMessage());
} }
disconnect(false); disconnect(false);
} catch (CannotConnectException ex) { } catch (CannotConnectException ex) {
@ -132,11 +129,11 @@ public class SessionImpl implements Session {
handleCannotConnectException(ex); handleCannotConnectException(ex);
} }
} catch (Throwable t) { } catch (Throwable t) {
logger.fatal("Unable to connect to server - ", t); logger.fatal("Unable connect to server - ", t);
if (!canceled) { if (!canceled) {
disconnect(false); disconnect(false);
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("Unable to connect to server.\n"); sb.append("Unable connect to server.\n");
for (StackTraceElement element : t.getStackTrace()) { for (StackTraceElement element : t.getStackTrace()) {
sb.append(element.toString()).append('\n'); sb.append(element.toString()).append('\n');
} }
@ -196,32 +193,32 @@ public class SessionImpl implements Session {
public synchronized boolean connect(final Connection connection) { public synchronized boolean connect(final Connection connection) {
return establishJBossRemotingConnection(connection) return establishJBossRemotingConnection(connection)
&& handleRemotingTaskExceptions(new RemotingTask() { && handleRemotingTaskExceptions(new RemotingTask() {
@Override @Override
public boolean run() throws Throwable { public boolean run() throws Throwable {
logger.info("Trying to log-in as " + getUserName() + " to XMAGE server at " + connection.getHost() + ':' + connection.getPort()); logger.info("Trying to log-in as " + getUserName() + " to XMAGE server at " + connection.getHost() + ':' + connection.getPort());
boolean registerResult; boolean registerResult;
if (connection.getAdminPassword() == null) { if (connection.getAdminPassword() == null) {
// for backward compatibility. don't remove twice call - first one does nothing but for version checking // for backward compatibility. don't remove twice call - first one does nothing but for version checking
registerResult = server.connectUser(connection.getUsername(), connection.getPassword(), sessionId, client.getVersion(), connection.getUserIdStr()); registerResult = server.connectUser(connection.getUsername(), connection.getPassword(), sessionId, client.getVersion(), connection.getUserIdStr());
if (registerResult) { if (registerResult) {
server.setUserData(connection.getUsername(), sessionId, connection.getUserData(), client.getVersion().toString(), connection.getUserIdStr()); server.setUserData(connection.getUsername(), sessionId, connection.getUserData(), client.getVersion().toString(), connection.getUserIdStr());
}
} else {
registerResult = server.connectAdmin(connection.getAdminPassword(), sessionId, client.getVersion());
}
if (registerResult) {
serverState = server.getServerState();
if (!connection.getUsername().equals("Admin")) {
updateDatabase(connection.isForceDBComparison(), serverState);
}
logger.info("Logged-in as " + getUserName() + " to MAGE server at " + connection.getHost() + ':' + connection.getPort());
client.connected(getUserName() + '@' + connection.getHost() + ':' + connection.getPort() + ' ');
return true;
}
disconnect(false);
return false;
} }
}); } else {
registerResult = server.connectAdmin(connection.getAdminPassword(), sessionId, client.getVersion());
}
if (registerResult) {
serverState = server.getServerState();
if (!connection.getUsername().equals("Admin")) {
updateDatabase(connection.isForceDBComparison(), serverState);
}
logger.info("Logged-in as " + getUserName() + " to MAGE server at " + connection.getHost() + ':' + connection.getPort());
client.connected(getUserName() + '@' + connection.getHost() + ':' + connection.getPort() + ' ');
return true;
}
disconnect(false);
return false;
}
});
} }
@Override @Override
@ -442,7 +439,7 @@ public class SessionImpl implements Session {
t = t.getCause(); t = t.getCause();
} }
client.showMessage("Unable to connect to server. " + message); client.showMessage("Unable connect to server. " + message);
if (logger.isTraceEnabled()) { if (logger.isTraceEnabled()) {
logger.trace("StackTrace", t); logger.trace("StackTrace", t);
} }
@ -450,7 +447,7 @@ public class SessionImpl implements Session {
/** /**
* @param askForReconnect - true = connection was lost because of error and * @param askForReconnect - true = connection was lost because of error and
* ask the user if he want to try to reconnect * ask the user if he want to try to reconnect
*/ */
@Override @Override
public synchronized void disconnect(boolean askForReconnect) { public synchronized void disconnect(boolean askForReconnect) {

View file

@ -0,0 +1,50 @@
package mage.utils;
import org.apache.log4j.Logger;
import java.net.URL;
import java.time.Instant;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.jar.Attributes;
import java.util.jar.Manifest;
/**
* @author JayDi85
*/
public class JarVersion {
private static final Logger logger = Logger.getLogger(JarVersion.class);
private static final String JAR_BUILD_TIME_FROM_CLASSES = "runtime";
private static final String JAR_BUILD_TIME_ERROR = "n/a";
public static String getBuildTime(Class clazz) {
// build time info inserted by maven on jar build phase (see root pom.xml)
String className = clazz.getSimpleName() + ".class";
String classPath = clazz.getResource(className).toString();
// https://stackoverflow.com/a/1273432/1276632
String manifestPath;
if (classPath.startsWith("jar")) {
// jar source
manifestPath = classPath.substring(0, classPath.lastIndexOf("!") + 1) + "/META-INF/MANIFEST.MF";
} else {
// dir source (e.g. IDE's debug)
// it's can be generated by runtime, but need extra code and performance: https://stackoverflow.com/questions/34674073/how-to-generate-manifest-mf-file-during-compile-phase
// manifestPath = classPath.substring(0, classPath.lastIndexOf("/" + className)) + "/META-INF/MANIFEST.MF";
return JAR_BUILD_TIME_FROM_CLASSES;
}
try {
Manifest manifest = new Manifest(new URL(manifestPath).openStream());
Attributes attr = manifest.getMainAttributes();
String buildTime = attr.getValue("Build-Time");
Instant instant = Instant.parse(buildTime);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm").withZone(ZoneOffset.UTC);
return formatter.format(instant);
} catch (Throwable e) {
logger.error("Can't read build time in jar manifest for class " + clazz.getName() + " and path " + manifestPath, e);
return JAR_BUILD_TIME_ERROR;
}
}
}

View file

@ -3,7 +3,6 @@ package mage.utils;
import java.io.Serializable; import java.io.Serializable;
/** /**
*
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
*/ */
public class MageVersion implements Serializable, Comparable<MageVersion> { public class MageVersion implements Serializable, Comparable<MageVersion> {
@ -14,22 +13,30 @@ public class MageVersion implements Serializable, Comparable<MageVersion> {
public final static int MAGE_VERSION_MAJOR = 1; public final static int MAGE_VERSION_MAJOR = 1;
public final static int MAGE_VERSION_MINOR = 4; public final static int MAGE_VERSION_MINOR = 4;
public final static int MAGE_VERSION_PATCH = 32; public final static int MAGE_VERSION_PATCH = 32;
public final static String MAGE_EDITION_INFO = ""; // set "-beta" for 1.4.32-betaV0
public final static String MAGE_VERSION_MINOR_PATCH = "V0"; public final static String MAGE_VERSION_MINOR_PATCH = "V0";
public final static String MAGE_VERSION_INFO = "";
private final int major; private final int major;
private final int minor; private final int minor;
private final int patch; private final int patch;
private final String minorPatch; // doesn't matter for compatibility private final String minorPatch; // doesn't matter for compatibility
private final String buildTime;
private String editionInfo;
private final boolean showBuildTime = true;
private String info = ""; public MageVersion(Class sourceClass) {
this(MAGE_VERSION_MAJOR, MAGE_VERSION_MINOR, MAGE_VERSION_PATCH, MAGE_VERSION_MINOR_PATCH, MAGE_EDITION_INFO, sourceClass);
}
public MageVersion(int major, int minor, int patch, String minorPatch, String info) { public MageVersion(int major, int minor, int patch, String minorPatch, String editionInfo, Class sourceClass) {
this.major = major; this.major = major;
this.minor = minor; this.minor = minor;
this.patch = patch; this.patch = patch;
this.minorPatch = minorPatch; this.minorPatch = minorPatch;
this.info = info; this.editionInfo = editionInfo;
// build time
this.buildTime = showBuildTime ? JarVersion.getBuildTime(sourceClass) : "";
} }
public int getMajor() { public int getMajor() {
@ -50,7 +57,8 @@ public class MageVersion implements Serializable, Comparable<MageVersion> {
@Override @Override
public String toString() { public String toString() {
return major + "." + minor + '.' + patch + info + minorPatch; // 1.4.32-betaV0 (build: time)
return major + "." + minor + '.' + patch + editionInfo + minorPatch + (!this.buildTime.isEmpty() ? " (build: " + this.buildTime + ")" : "");
} }
@Override @Override
@ -64,7 +72,7 @@ public class MageVersion implements Serializable, Comparable<MageVersion> {
if (patch != o.patch) { if (patch != o.patch) {
return patch - o.patch; return patch - o.patch;
} }
return info.compareTo(o.info); return editionInfo.compareTo(o.editionInfo);
} }
} }

View file

@ -53,7 +53,6 @@
<artifactId>maven-jar-plugin</artifactId> <artifactId>maven-jar-plugin</artifactId>
<configuration> <configuration>
<archive> <archive>
<manifestFile>${manifest.file}</manifestFile>
<manifest> <manifest>
<addClasspath>true</addClasspath> <addClasspath>true</addClasspath>
<mainClass>mage.server.console.ConsoleFrame</mainClass> <mainClass>mage.server.console.ConsoleFrame</mainClass>

View file

@ -1,11 +1,3 @@
/*
* ConsoleFrame.java
*
* Created on May 13, 2011, 2:39:10 PM
*/
package mage.server.console; package mage.server.console;
import mage.interfaces.MageClient; import mage.interfaces.MageClient;
@ -25,7 +17,6 @@ import java.util.concurrent.TimeUnit;
import java.util.prefs.Preferences; import java.util.prefs.Preferences;
/** /**
*
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
*/ */
public class ConsoleFrame extends javax.swing.JFrame implements MageClient { public class ConsoleFrame extends javax.swing.JFrame implements MageClient {
@ -35,9 +26,10 @@ public class ConsoleFrame extends javax.swing.JFrame implements MageClient {
private static Session session; private static Session session;
private ConnectDialog connectDialog; private ConnectDialog connectDialog;
private static final Preferences prefs = Preferences.userNodeForPackage(ConsoleFrame.class); private static final Preferences prefs = Preferences.userNodeForPackage(ConsoleFrame.class);
private static final MageVersion version = new MageVersion(MageVersion.MAGE_VERSION_MAJOR, MageVersion.MAGE_VERSION_MINOR, MageVersion.MAGE_VERSION_PATCH, MageVersion.MAGE_VERSION_MINOR_PATCH, MageVersion.MAGE_VERSION_INFO); private static final MageVersion version = new MageVersion(ConsoleFrame.class);
private static final ScheduledExecutorService pingTaskExecutor = Executors.newSingleThreadScheduledExecutor(); private static final ScheduledExecutorService pingTaskExecutor = Executors.newSingleThreadScheduledExecutor();
/** /**
* @return the session * @return the session
*/ */
@ -54,7 +46,9 @@ public class ConsoleFrame extends javax.swing.JFrame implements MageClient {
return version; return version;
} }
/** Creates new form ConsoleFrame */ /**
* Creates new form ConsoleFrame
*/
public ConsoleFrame() { public ConsoleFrame() {
addWindowListener(new WindowAdapter() { addWindowListener(new WindowAdapter() {
@ -72,11 +66,11 @@ public class ConsoleFrame extends javax.swing.JFrame implements MageClient {
} catch (Exception ex) { } catch (Exception ex) {
logger.fatal("", ex); logger.fatal("", ex);
} }
pingTaskExecutor.scheduleAtFixedRate(() -> session.ping(), 60, 60, TimeUnit.SECONDS); pingTaskExecutor.scheduleAtFixedRate(() -> session.ping(), 60, 60, TimeUnit.SECONDS);
} }
public boolean connect(Connection connection) { public boolean connect(Connection connection) {
if (session.connect(connection)) { if (session.connect(connection)) {
this.consolePanel1.start(); this.consolePanel1.start();
return true; return true;
@ -100,7 +94,8 @@ public class ConsoleFrame extends javax.swing.JFrame implements MageClient {
btnSendMessage.setEnabled(false); btnSendMessage.setEnabled(false);
} }
/** This method is called from within the constructor to /**
* This method is called from within the constructor to
* initialize the form. * initialize the form.
* WARNING: Do NOT modify this code. The content of this method is * WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor. * always regenerated by the Form Editor.
@ -143,16 +138,16 @@ public class ConsoleFrame extends javax.swing.JFrame implements MageClient {
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout); getContentPane().setLayout(layout);
layout.setHorizontalGroup( layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 933, Short.MAX_VALUE) .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 933, Short.MAX_VALUE)
.addComponent(consolePanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 933, Short.MAX_VALUE) .addComponent(consolePanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 933, Short.MAX_VALUE)
); );
layout.setVerticalGroup( layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup() .addGroup(layout.createSequentialGroup()
.addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, 0) .addGap(0, 0, 0)
.addComponent(consolePanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 432, Short.MAX_VALUE)) .addComponent(consolePanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 432, Short.MAX_VALUE))
); );
pack(); pack();
@ -177,8 +172,8 @@ public class ConsoleFrame extends javax.swing.JFrame implements MageClient {
}//GEN-LAST:event_btnSendMessageActionPerformed }//GEN-LAST:event_btnSendMessageActionPerformed
/** /**
* @param args the command line arguments * @param args the command line arguments
*/ */
public static void main(String args[]) { public static void main(String args[]) {
logger.info("Starting MAGE server console version " + version); logger.info("Starting MAGE server console version " + version);
logger.info("Logging level: " + logger.getEffectiveLevel()); logger.info("Logging level: " + logger.getEffectiveLevel());
@ -205,9 +200,8 @@ public class ConsoleFrame extends javax.swing.JFrame implements MageClient {
public void connected(final String message) { public void connected(final String message) {
if (SwingUtilities.isEventDispatchThread()) { if (SwingUtilities.isEventDispatchThread()) {
setStatusText(message); setStatusText(message);
enableButtons(); enableButtons();
} } else {
else {
SwingUtilities.invokeLater(() -> { SwingUtilities.invokeLater(() -> {
setStatusText(message); setStatusText(message);
enableButtons(); enableButtons();
@ -221,8 +215,7 @@ public class ConsoleFrame extends javax.swing.JFrame implements MageClient {
consolePanel1.stop(); consolePanel1.stop();
setStatusText("Not connected"); setStatusText("Not connected");
disableButtons(); disableButtons();
} } else {
else {
SwingUtilities.invokeLater(() -> { SwingUtilities.invokeLater(() -> {
consolePanel1.stop(); consolePanel1.stop();
setStatusText("Not connected"); setStatusText("Not connected");
@ -235,8 +228,7 @@ public class ConsoleFrame extends javax.swing.JFrame implements MageClient {
public void showMessage(final String message) { public void showMessage(final String message) {
if (SwingUtilities.isEventDispatchThread()) { if (SwingUtilities.isEventDispatchThread()) {
JOptionPane.showMessageDialog(this, message); JOptionPane.showMessageDialog(this, message);
} } else {
else {
SwingUtilities.invokeLater(() -> JOptionPane.showMessageDialog(getFrame(), message)); SwingUtilities.invokeLater(() -> JOptionPane.showMessageDialog(getFrame(), message));
} }
} }
@ -245,8 +237,7 @@ public class ConsoleFrame extends javax.swing.JFrame implements MageClient {
public void showError(final String message) { public void showError(final String message) {
if (SwingUtilities.isEventDispatchThread()) { if (SwingUtilities.isEventDispatchThread()) {
JOptionPane.showMessageDialog(this, message, "Error", JOptionPane.ERROR_MESSAGE); JOptionPane.showMessageDialog(this, message, "Error", JOptionPane.ERROR_MESSAGE);
} } else {
else {
SwingUtilities.invokeLater(() -> JOptionPane.showMessageDialog(getFrame(), message, "Error", JOptionPane.ERROR_MESSAGE)); SwingUtilities.invokeLater(() -> JOptionPane.showMessageDialog(getFrame(), message, "Error", JOptionPane.ERROR_MESSAGE));
} }
} }

View file

@ -1,3 +0,0 @@
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build

View file

@ -258,7 +258,6 @@
<configuration> <configuration>
<generatePackage>mage.server.util.config</generatePackage> <generatePackage>mage.server.util.config</generatePackage>
<schemaDirectory>./src/main/xml-resources/jaxb/Config/</schemaDirectory> <schemaDirectory>./src/main/xml-resources/jaxb/Config/</schemaDirectory>
<arguments>-Xcommons-lang</arguments>
</configuration> </configuration>
<executions> <executions>
<execution> <execution>

View file

@ -1,10 +1,5 @@
package mage.server; package mage.server;
import java.security.SecureRandom;
import java.util.*;
import java.util.concurrent.ExecutorService;
import javax.management.timer.Timer;
import mage.MageException; import mage.MageException;
import mage.cards.decks.DeckCardLists; import mage.cards.decks.DeckCardLists;
import mage.cards.repository.CardInfo; import mage.cards.repository.CardInfo;
@ -43,6 +38,11 @@ import mage.view.ChatMessage.MessageColor;
import org.apache.commons.lang3.StringEscapeUtils; import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import javax.management.timer.Timer;
import java.security.SecureRandom;
import java.util.*;
import java.util.concurrent.ExecutorService;
/** /**
* @author BetaSteward_at_googlemail.com, noxx * @author BetaSteward_at_googlemail.com, noxx
*/ */
@ -827,27 +827,27 @@ public class MageServerImpl implements MageServer {
public void quitDraft(final UUID draftId, final String sessionId) throws MageException { public void quitDraft(final UUID draftId, final String sessionId) throws MageException {
execute("quitDraft", sessionId, () -> { execute("quitDraft", sessionId, () -> {
try { try {
callExecutor.execute( callExecutor.execute(
() -> { () -> {
Optional<Session> session = SessionManager.instance.getSession(sessionId); Optional<Session> session = SessionManager.instance.getSession(sessionId);
if (!session.isPresent()) { if (!session.isPresent()) {
logger.error("Session not found : " + sessionId); logger.error("Session not found : " + sessionId);
} else { } else {
UUID userId = session.get().getUserId(); UUID userId = session.get().getUserId();
UUID tableId = DraftManager.instance.getControllerByDraftId(draftId).getTableId(); UUID tableId = DraftManager.instance.getControllerByDraftId(draftId).getTableId();
Table table = TableManager.instance.getTable(tableId); Table table = TableManager.instance.getTable(tableId);
if (table.isTournament()) { if (table.isTournament()) {
UUID tournamentId = table.getTournament().getId(); UUID tournamentId = table.getTournament().getId();
TournamentManager.instance.quit(tournamentId, userId); TournamentManager.instance.quit(tournamentId, userId);
}
}
} }
} );
} } catch (Exception ex) {
); handleException(ex);
} catch (Exception ex) { }
handleException(ex); }
}
}
); );
} }
@ -1141,12 +1141,12 @@ public class MageServerImpl implements MageServer {
public void toggleActivation(final String sessionId, final String userName) throws MageException { public void toggleActivation(final String sessionId, final String userName) throws MageException {
execute("toggleActivation", sessionId, () execute("toggleActivation", sessionId, ()
-> UserManager.instance.getUserByName(userName).ifPresent(user -> UserManager.instance.getUserByName(userName).ifPresent(user
-> { -> {
user.setActive(!user.isActive()); user.setActive(!user.isActive());
if (!user.isActive() && user.isConnected()) { if (!user.isActive() && user.isConnected()) {
SessionManager.instance.disconnectUser(sessionId, user.getSessionId()); SessionManager.instance.disconnectUser(sessionId, user.getSessionId());
} }
})); }));
} }
@Override @Override
@ -1181,8 +1181,8 @@ public class MageServerImpl implements MageServer {
if (title != null && message != null) { if (title != null && message != null) {
execute("sendFeedbackMessage", sessionId, () execute("sendFeedbackMessage", sessionId, ()
-> SessionManager.instance.getSession(sessionId).ifPresent( -> SessionManager.instance.getSession(sessionId).ifPresent(
session -> FeedbackServiceImpl.instance.feedback(username, title, type, message, email, session.getHost()) session -> FeedbackServiceImpl.instance.feedback(username, title, type, message, email, session.getHost())
)); ));
} }
} }
@ -1307,8 +1307,8 @@ public class MageServerImpl implements MageServer {
logger.error("Session not found : " + sessionId); logger.error("Session not found : " + sessionId);
return null; return null;
} else { } else {
UUID userId = session.get().getUserId(); //UUID userId = session.get().getUserId();
return GameManager.instance.getGameView(gameId, userId, playerId); return GameManager.instance.getGameView(gameId, playerId);
} }
} }
} }

View file

@ -1,12 +1,5 @@
package mage.server; package mage.server;
import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.util.*;
import javax.management.MBeanServer;
import mage.cards.ExpansionSet; import mage.cards.ExpansionSet;
import mage.cards.Sets; import mage.cards.Sets;
import mage.cards.repository.CardScanner; import mage.cards.repository.CardScanner;
@ -39,13 +32,20 @@ import org.jboss.remoting.transporter.TransporterClient;
import org.jboss.remoting.transporter.TransporterServer; import org.jboss.remoting.transporter.TransporterServer;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import javax.management.MBeanServer;
import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.util.*;
/** /**
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
*/ */
public final class Main { public final class Main {
private static final Logger logger = Logger.getLogger(Main.class); private static final Logger logger = Logger.getLogger(Main.class);
private static final MageVersion version = new MageVersion(MageVersion.MAGE_VERSION_MAJOR, MageVersion.MAGE_VERSION_MINOR, MageVersion.MAGE_VERSION_PATCH, MageVersion.MAGE_VERSION_MINOR_PATCH, MageVersion.MAGE_VERSION_INFO); private static final MageVersion version = new MageVersion(Main.class);
private static final String testModeArg = "-testMode="; private static final String testModeArg = "-testMode=";
private static final String fastDBModeArg = "-fastDbMode="; private static final String fastDBModeArg = "-fastDbMode=";

View file

@ -9,7 +9,6 @@
<version>1.4.32</version> <version>1.4.32</version>
</parent> </parent>
<groupId>org.mage</groupId>
<artifactId>mage-stats</artifactId> <artifactId>mage-stats</artifactId>
<packaging>war</packaging> <packaging>war</packaging>
<name>XMage Stats Web Service</name> <name>XMage Stats Web Service</name>

View file

@ -189,9 +189,9 @@ public class MageBase {
} catch (MageException ex) { } catch (MageException ex) {
logger.log(Level.SEVERE, null, ex); logger.log(Level.SEVERE, null, ex);
} catch (RemoteException ex) { } catch (RemoteException ex) {
logger.log(Level.SEVERE, "Unable to connect to server - ", ex); logger.log(Level.SEVERE, "Unable connect to server - ", ex);
} catch (NotBoundException ex) { } catch (NotBoundException ex) {
logger.log(Level.SEVERE, "Unable to connect to server - ", ex); logger.log(Level.SEVERE, "Unable connect to server - ", ex);
} }
} }

View file

@ -16,7 +16,7 @@ import org.apache.log4j.Logger;
public class SimpleMageClient implements MageClient { public class SimpleMageClient implements MageClient {
private final UUID clientId; private final UUID clientId;
private static final MageVersion version = new MageVersion(MageVersion.MAGE_VERSION_MAJOR, MageVersion.MAGE_VERSION_MINOR, MageVersion.MAGE_VERSION_PATCH, MageVersion.MAGE_VERSION_MINOR_PATCH, MageVersion.MAGE_VERSION_INFO); private static final MageVersion version = new MageVersion(MageClient.class);
private static final Logger log = Logger.getLogger(SimpleMageClient.class); private static final Logger log = Logger.getLogger(SimpleMageClient.class);

View file

@ -1,3 +0,0 @@
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build

View file

@ -29,6 +29,7 @@
<!-- <compilerArgument>-Xlint:all</compilerArgument> --> <!-- <compilerArgument>-Xlint:all</compilerArgument> -->
</configuration> </configuration>
</plugin> </plugin>
<plugin> <plugin>
<artifactId>maven-resources-plugin</artifactId> <artifactId>maven-resources-plugin</artifactId>
<version>2.7</version> <version>2.7</version>
@ -36,6 +37,8 @@
<encoding>UTF-8</encoding> <encoding>UTF-8</encoding>
</configuration> </configuration>
</plugin> </plugin>
<!-- default manifest settings (parent) -->
<plugin> <plugin>
<artifactId>maven-jar-plugin</artifactId> <artifactId>maven-jar-plugin</artifactId>
<version>2.5</version> <version>2.5</version>
@ -43,6 +46,7 @@
<archive> <archive>
<manifestEntries> <manifestEntries>
<Built-By>MageTeam</Built-By> <Built-By>MageTeam</Built-By>
<Build-Time>${maven.build.timestamp}</Build-Time>
</manifestEntries> </manifestEntries>
</archive> </archive>
</configuration> </configuration>