moved sessionstate enum to sessionImpl

This commit is contained in:
ingmargoudt 2017-03-07 22:15:58 +01:00
parent daed944eb6
commit 0a77c186be
2 changed files with 32 additions and 34 deletions

View file

@ -76,10 +76,7 @@ public final class Constants {
*/ */
public static final int PRIORITY_TIME_SEC = 1200; public static final int PRIORITY_TIME_SEC = 1200;
public enum SessionState {
DISCONNECTED, CONNECTED, CONNECTING, DISCONNECTING, SERVER_STARTING
}
public enum Option { public enum Option {

View file

@ -33,6 +33,7 @@ import java.net.*;
import java.util.*; import java.util.*;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import mage.MageException; import mage.MageException;
import mage.cards.decks.DeckCardLists; import mage.cards.decks.DeckCardLists;
import mage.cards.decks.InvalidDeckException; import mage.cards.decks.InvalidDeckException;
@ -40,7 +41,6 @@ import mage.cards.repository.CardInfo;
import mage.cards.repository.CardRepository; import mage.cards.repository.CardRepository;
import mage.cards.repository.ExpansionInfo; import mage.cards.repository.ExpansionInfo;
import mage.cards.repository.ExpansionRepository; import mage.cards.repository.ExpansionRepository;
import mage.constants.Constants.SessionState;
import mage.constants.ManaType; import mage.constants.ManaType;
import mage.constants.PlayerAction; import mage.constants.PlayerAction;
import mage.game.GameException; import mage.game.GameException;
@ -63,11 +63,14 @@ import org.jboss.remoting.transport.socket.SocketWrapper;
import org.jboss.remoting.transporter.TransporterClient; import org.jboss.remoting.transporter.TransporterClient;
/** /**
*
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
*/ */
public class SessionImpl implements Session { public class SessionImpl implements Session {
private enum SessionState {
DISCONNECTED, CONNECTED, CONNECTING, DISCONNECTING, SERVER_STARTING
}
private static final Logger logger = Logger.getLogger(SessionImpl.class); private static final Logger logger = Logger.getLogger(SessionImpl.class);
private final MageClient client; private final MageClient client;
@ -216,32 +219,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;
}
});
} }
public Optional<String> getServerHostname() { public Optional<String> getServerHostname() {
@ -468,9 +471,8 @@ 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) {
@ -965,7 +967,6 @@ public class SessionImpl implements Session {
} }
@Override @Override
public boolean joinGame(UUID gameId) { public boolean joinGame(UUID gameId) {
try { try {
@ -1175,7 +1176,7 @@ public class SessionImpl implements Session {
return false; return false;
} }
// @Override // @Override
// public boolean startChallenge(UUID roomId, UUID tableId, UUID challengeId) { // public boolean startChallenge(UUID roomId, UUID tableId, UUID challengeId) {
// try { // try {
// if (isConnected()) { // if (isConnected()) {