mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 04:52:07 -08:00
Added connection speed information per user (milliseconds the ping needs). Some minor changes to server console.
This commit is contained in:
parent
1285df5da3
commit
b98c16f061
20 changed files with 166 additions and 54 deletions
|
|
@ -93,6 +93,12 @@ public class ChatSession {
|
|||
case SessionExpired:
|
||||
message = " session expired";
|
||||
break;
|
||||
case AdminDisconnect:
|
||||
message = " was disconnected by the Admin";
|
||||
break;
|
||||
case ConnectingOtherInstance:
|
||||
message = " reconnected and replaced still active old session";
|
||||
break;
|
||||
case CleaningUp:
|
||||
message = null;
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -330,8 +330,8 @@ public class MageServerImpl implements MageServer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean ping(String sessionId) {
|
||||
return SessionManager.getInstance().extendUserSession(sessionId);
|
||||
public boolean ping(String sessionId, String pingInfo) {
|
||||
return SessionManager.getInstance().extendUserSession(sessionId, pingInfo);
|
||||
}
|
||||
|
||||
// @Override
|
||||
|
|
@ -959,6 +959,13 @@ public class MageServerImpl implements MageServer {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user data for admin console
|
||||
*
|
||||
* @param sessionId
|
||||
* @return
|
||||
* @throws MageException
|
||||
*/
|
||||
@Override
|
||||
public List<UserView> getUsers(String sessionId) throws MageException {
|
||||
return executeWithResult("getUsers", sessionId, new ActionWithNullNegativeResult<List<UserView>>() {
|
||||
|
|
@ -966,7 +973,8 @@ public class MageServerImpl implements MageServer {
|
|||
public List<UserView> execute() throws MageException {
|
||||
List<UserView> users = new ArrayList<>();
|
||||
for (User user : UserManager.getInstance().getUsers()) {
|
||||
users.add(new UserView(user.getName(), user.getHost(), user.getSessionId(), user.getConnectionTime()));
|
||||
|
||||
users.add(new UserView(user.getName(), user.getHost(), user.getSessionId(), user.getConnectionTime(), user.getGameInfo()));
|
||||
}
|
||||
return users;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ public class Session {
|
|||
if (user == null) { // user already exists
|
||||
user = UserManager.getInstance().findUser(userName);
|
||||
if (user.getHost().equals(host)) {
|
||||
user.updateLastActivity(); // minimizes possible expiration
|
||||
user.updateLastActivity(null); // minimizes possible expiration
|
||||
this.userId = user.getId();
|
||||
if (user.getSessionId().isEmpty()) {
|
||||
logger.info("Reconnecting session for " + userName);
|
||||
|
|
|
|||
|
|
@ -152,13 +152,35 @@ public class SessionManager {
|
|||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* Admin requested the disconnect of a user
|
||||
* @param sessionId
|
||||
* @param userSessionId
|
||||
*/
|
||||
public void disconnectUser(String sessionId, String userSessionId) {
|
||||
if (isAdmin(sessionId)) {
|
||||
disconnect(userSessionId, DisconnectReason.AdminDisconnect);
|
||||
LogServiceImpl.instance.log(LogKeys.KEY_SESSION_DISCONNECTED_BY_ADMIN, sessionId, userSessionId);
|
||||
User userAdmin, user;
|
||||
if ((userAdmin = getUserFromSession(sessionId)) != null) {
|
||||
if ((user = getUserFromSession(userSessionId)) != null) {
|
||||
user.showUserMessage("Admin operation","Your session was disconnected by Admin.");
|
||||
userAdmin.showUserMessage("Admin action", "User" + user.getName() + " was disconnected.");
|
||||
disconnect(userSessionId, DisconnectReason.AdminDisconnect);
|
||||
LogServiceImpl.instance.log(LogKeys.KEY_SESSION_DISCONNECTED_BY_ADMIN, sessionId, userSessionId);
|
||||
} else {
|
||||
userAdmin.showUserMessage("Admin operation","User with sessionId " + userSessionId + " could not be found!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private User getUserFromSession(String sessionId) {
|
||||
Session session = getSession(sessionId);
|
||||
if (session == null) {
|
||||
return null;
|
||||
}
|
||||
return UserManager.getInstance().getUser(session.getUserId());
|
||||
}
|
||||
|
||||
public void endUserSession(String sessionId, String userSessionId) {
|
||||
if (isAdmin(sessionId)) {
|
||||
disconnect(userSessionId, DisconnectReason.AdminDisconnect);
|
||||
|
|
@ -186,10 +208,10 @@ public class SessionManager {
|
|||
return null;
|
||||
}
|
||||
|
||||
public boolean extendUserSession(String sessionId) {
|
||||
public boolean extendUserSession(String sessionId, String pingInfo) {
|
||||
Session session = sessions.get(sessionId);
|
||||
if (session != null) {
|
||||
return UserManager.getInstance().extendUserSession(session.getUserId());
|
||||
return UserManager.getInstance().extendUserSession(session.getUserId(), pingInfo);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ import java.util.ArrayList;
|
|||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.Executors;
|
||||
|
|
@ -51,6 +52,7 @@ import mage.game.match.MatchOptions;
|
|||
import mage.game.tournament.Tournament;
|
||||
import mage.game.tournament.TournamentOptions;
|
||||
import mage.players.Player;
|
||||
import mage.server.game.GameController;
|
||||
import mage.server.game.GameManager;
|
||||
import mage.server.game.GamesRoomManager;
|
||||
import org.apache.log4j.Logger;
|
||||
|
|
@ -378,12 +380,18 @@ public class TableManager {
|
|||
logger.debug("------- Tables: " + tables.size() + " --------------------------------------------");
|
||||
for (Table table: tables.values()) {
|
||||
logger.debug(table.getId() + " [" + table.getName()+ "] " + formatter.format(table.getStartTime()) +" (" + table.getState().toString() + ")");
|
||||
}
|
||||
}
|
||||
logger.debug("------- Games: " + GameManager.getInstance().getNumberActiveGames() + " --------------------------------------------");
|
||||
for (Entry<UUID, GameController> entry: GameManager.getInstance().getGameController().entrySet()) {
|
||||
logger.debug(entry.getKey() + entry.getValue().getPlayerNameList());
|
||||
}
|
||||
logger.debug("--- Server state END ------------------------------------------");
|
||||
}
|
||||
|
||||
private void checkExpired() {
|
||||
debugServerState();
|
||||
if (logger.isDebugEnabled()) {
|
||||
debugServerState();
|
||||
}
|
||||
Date now = new Date();
|
||||
List<UUID> toRemove = new ArrayList<>();
|
||||
for (Table table : tables.values()) {
|
||||
|
|
|
|||
|
|
@ -75,7 +75,8 @@ public class User {
|
|||
private final Map<UUID, Deck> sideboarding;
|
||||
private final List<UUID> watchedGames;
|
||||
private String sessionId;
|
||||
private String info;
|
||||
private String info = "";
|
||||
private String pingInfo = "";
|
||||
private Date lastActivity;
|
||||
private UserState userState;
|
||||
private UserData userData;
|
||||
|
|
@ -238,7 +239,10 @@ public class User {
|
|||
GameManager.getInstance().sendPlayerInteger(gameId, userId, data);
|
||||
}
|
||||
|
||||
public void updateLastActivity() {
|
||||
public void updateLastActivity(String pingInfo) {
|
||||
if (pingInfo != null) {
|
||||
this.pingInfo = pingInfo;
|
||||
}
|
||||
lastActivity = new Date();
|
||||
if (userState == UserState.Disconnected) { // this can happen if user reconnects very fast after disconnect
|
||||
userState = UserState.Reconnected;
|
||||
|
|
@ -457,5 +461,9 @@ public class User {
|
|||
public UserState getUserState() {
|
||||
return userState;
|
||||
}
|
||||
|
||||
public String getPingInfo() {
|
||||
return pingInfo;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -145,11 +145,11 @@ public class UserManager {
|
|||
}
|
||||
}
|
||||
|
||||
public boolean extendUserSession(UUID userId) {
|
||||
public boolean extendUserSession(UUID userId, String pingInfo) {
|
||||
if (userId != null) {
|
||||
User user = users.get(userId);
|
||||
if (user != null) {
|
||||
user.updateLastActivity();
|
||||
user.updateLastActivity(pingInfo);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -826,4 +826,17 @@ public class GameController implements GameCallback {
|
|||
}
|
||||
return gameSessions.get(playerId);
|
||||
}
|
||||
|
||||
public String getPlayerNameList() {
|
||||
StringBuilder sb = new StringBuilder(" [");
|
||||
for (UUID playerId: userPlayerMap.values()) {
|
||||
Player player = game.getPlayer(playerId);
|
||||
if (player != null) {
|
||||
sb.append(player.getName()).append("(Left=").append(player.hasLeft() ? "Y":"N").append(") ");
|
||||
} else {
|
||||
sb.append("player missing: ").append(playerId).append(" ");
|
||||
}
|
||||
}
|
||||
return sb.append("]").toString();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,10 +62,6 @@ public class GameManager {
|
|||
}
|
||||
}
|
||||
|
||||
// public void destroyChatSession(UUID gameId) {
|
||||
// gameControllers.remove(gameId);
|
||||
// }
|
||||
|
||||
public UUID getChatId(UUID gameId) {
|
||||
if (gameControllers.containsKey(gameId)) {
|
||||
return gameControllers.get(gameId).getChatId();
|
||||
|
|
@ -213,4 +209,8 @@ public class GameManager {
|
|||
public int getNumberActiveGames() {
|
||||
return gameControllers.size();
|
||||
}
|
||||
|
||||
public ConcurrentHashMap<UUID, GameController> getGameController() {
|
||||
return gameControllers;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -118,10 +118,10 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
|
|||
List<UsersView> users = new ArrayList<>();
|
||||
for (User user : UserManager.getInstance().getUsers()) {
|
||||
try {
|
||||
users.add(new UsersView(user.getName(), user.getInfo(), user.getGameInfo()));
|
||||
users.add(new UsersView(user.getName(), user.getInfo(), user.getGameInfo(), user.getPingInfo()));
|
||||
} catch (Exception ex) {
|
||||
logger.fatal("User update exception: " + user.getName() + " - " + ex.toString(), ex);
|
||||
users.add(new UsersView(user.getName(), user.getInfo(), "[exception]"));
|
||||
users.add(new UsersView(user.getName(), user.getInfo(), "[exception]", user.getPingInfo()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue