Getting information about connected players in Mage Client (without gui part at the moment, only logging to console).

This commit is contained in:
magenoxx 2011-05-13 20:25:46 +04:00
parent f55e3a88dd
commit 54adc043ec
5 changed files with 47 additions and 1 deletions

View file

@ -322,6 +322,18 @@ public class Session {
}
}
public Collection<String> getConnectedPlayers(UUID roomId) throws MageRemoteException {
try {
return server.getConnectedPlayers(roomId);
} catch (RemoteException ex) {
handleRemoteException(ex);
throw new MageRemoteException();
} catch (MageException ex) {
handleMageException(ex);
throw new MageRemoteException();
}
}
public TournamentView getTournament(UUID tournamentId) throws MageRemoteException {
try {
return server.getTournament(tournamentId);

View file

@ -432,6 +432,8 @@ class UpdateTablesTask extends SwingWorker<Void, Collection<TableView>> {
private UUID roomId;
private TablesPanel panel;
private final static Logger logger = Logging.getLogger(TablesPanel.class.getName());
UpdateTablesTask(Session session, UUID roomId, TablesPanel panel) {
this.session = session;
this.roomId = roomId;
@ -442,6 +444,10 @@ class UpdateTablesTask extends SwingWorker<Void, Collection<TableView>> {
protected Void doInBackground() throws Exception {
while (!isCancelled()) {
this.publish(session.getTables(roomId));
logger.info("connected players:");
for (String player : session.getConnectedPlayers(roomId)) {
logger.info(" " + player);
}
Thread.sleep(1000);
}
return null;

View file

@ -68,6 +68,7 @@ public interface Server extends Remote, CallbackServer {
public boolean isTableOwner(UUID sessionId, UUID roomId, UUID tableId) throws RemoteException, MageException;
public TableView getTable(UUID roomId, UUID tableId) throws RemoteException, MageException;
public List<TableView> getTables(UUID roomId) throws RemoteException, MageException;
public List<String> getConnectedPlayers(UUID roomId) throws RemoteException, MageException;
//chat methods
public void sendChatMessage(UUID chatId, String userName, String message) throws RemoteException, MageException;

View file

@ -34,6 +34,7 @@ import java.rmi.registry.Registry;
import java.rmi.server.ExportException;
import java.rmi.server.RemoteServer;
import java.rmi.server.UnicastRemoteObject;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
@ -220,6 +221,22 @@ public class ServerImpl extends RemoteServer implements Server {
return null;
}
@Override
public List<String> getConnectedPlayers(UUID roomId) throws MageException {
try {
List<String> players = new ArrayList<String>();
for (Session session : SessionManager.getInstance().getSessions().values()) {
players.add(session.getUsername());
}
return players;
}
catch (Exception ex) {
handleException(ex);
}
return null;
}
@Override
public TableView getTable(UUID roomId, UUID tableId) throws MageException {
try {

View file

@ -28,6 +28,9 @@
package mage.server;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import mage.interfaces.MageException;
@ -75,4 +78,11 @@ public class SessionManager {
sessions.remove(sessionId);
}
public Map<UUID, Session> getSessions() {
Map<UUID, Session> map = new HashMap<UUID, Session>();
for (Map.Entry<UUID, Session> entry : sessions.entrySet()) {
map.put(entry.getKey(), entry.getValue());
}
return map;
}
}