forked from External/mage
fixed client/server ping + added server console
This commit is contained in:
parent
0b1527a206
commit
473f6bcad9
38 changed files with 2657 additions and 63 deletions
|
|
@ -62,6 +62,7 @@ import mage.view.DraftPickView;
|
|||
import mage.view.GameView;
|
||||
import mage.view.TableView;
|
||||
import mage.view.TournamentView;
|
||||
import mage.view.UserView;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
|
|
@ -74,14 +75,16 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
private static ExecutorService rmiExecutor = ThreadExecutor.getInstance().getRMIExecutor();
|
||||
|
||||
private boolean testMode;
|
||||
private String password;
|
||||
|
||||
public ServerImpl(int port, String name, boolean testMode) {
|
||||
public ServerImpl(int port, String name, boolean testMode, String password) {
|
||||
try {
|
||||
System.setSecurityManager(null);
|
||||
Registry reg = LocateRegistry.createRegistry(port);
|
||||
Server stub = (Server) UnicastRemoteObject.exportObject(this, port);
|
||||
reg.rebind(name, stub);
|
||||
this.testMode = testMode;
|
||||
this.password = password;
|
||||
logger.info("Started MAGE server - listening on port " + port);
|
||||
if (testMode)
|
||||
logger.info("MAGE server running in test mode");
|
||||
|
|
@ -106,6 +109,16 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
SessionManager.getInstance().getSession(sessionId).ack(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean ping(UUID sessionId) {
|
||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
||||
if (session != null) {
|
||||
session.ping();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID registerClient(String userName, UUID clientId, MageVersion version) throws MageException, RemoteException {
|
||||
|
||||
|
|
@ -113,7 +126,7 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
try {
|
||||
if (version.compareTo(Main.getVersion()) != 0)
|
||||
throw new MageException("Wrong client version " + version + ", expecting version " + Main.getVersion());
|
||||
sessionId = SessionManager.getInstance().createSession(userName, clientId);
|
||||
sessionId = SessionManager.getInstance().createSession(userName, getClientHost(), clientId);
|
||||
logger.info("User " + userName + " connected from " + getClientHost());
|
||||
} catch (Exception ex) {
|
||||
handleException(ex);
|
||||
|
|
@ -121,6 +134,22 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
return sessionId;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID registerAdmin(String password, MageVersion version) throws RemoteException, MageException {
|
||||
UUID sessionId = null;
|
||||
try {
|
||||
if (version.compareTo(Main.getVersion()) != 0)
|
||||
throw new MageException("Wrong client version " + version + ", expecting version " + Main.getVersion());
|
||||
if (!password.equals(this.password))
|
||||
throw new MageException("Wrong password");
|
||||
sessionId = SessionManager.getInstance().createSession(getClientHost());
|
||||
logger.info("Admin connected from " + getClientHost());
|
||||
} catch (Exception ex) {
|
||||
handleException(ex);
|
||||
}
|
||||
return sessionId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableView createTable(UUID sessionId, UUID roomId, MatchOptions options) throws MageException {
|
||||
|
|
@ -236,7 +265,6 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public TableView getTable(UUID roomId, UUID tableId) throws MageException {
|
||||
try {
|
||||
|
|
@ -258,8 +286,8 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
Session session = SessionManager.getInstance().getSession(sessionId);
|
||||
if (session != null) {
|
||||
session.kill();
|
||||
logger.info("Client deregistered ...");
|
||||
}
|
||||
logger.info("Client deregistered ...");
|
||||
}
|
||||
}
|
||||
);
|
||||
|
|
@ -812,4 +840,9 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
return GameManager.getInstance().getGameView(gameId, sessionId, playerId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserView> getUsers(UUID sessionId) throws RemoteException, MageException {
|
||||
return SessionManager.getInstance().getUsers(sessionId);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue