mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 04:52:07 -08:00
added pingInfo to user info
This commit is contained in:
parent
bc51a8fc79
commit
481e177d71
13 changed files with 159 additions and 24 deletions
|
|
@ -491,6 +491,16 @@ public class Main implements MageServer {
|
|||
// public boolean ping(String sessionId, String pingInfo) {
|
||||
// return SessionManager.getInstance().extendUserSession(sessionId, pingInfo);
|
||||
// }
|
||||
|
||||
public void pingClient(String sessionId) {
|
||||
server.pingClient(sessionId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pingTime(long milliSeconds, String sessionId) {
|
||||
SessionManager.getInstance().recordPingTime(sessionId, milliSeconds);
|
||||
}
|
||||
|
||||
//
|
||||
// @Override
|
||||
// public void deregisterClient(final String sessionId) throws MageException {
|
||||
|
|
|
|||
|
|
@ -33,6 +33,8 @@ import java.util.Date;
|
|||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.regex.Matcher;
|
||||
|
|
@ -57,6 +59,7 @@ import org.jboss.remoting.callback.InvokerCallbackHandler;
|
|||
public class Session {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(Session.class);
|
||||
private static final ScheduledExecutorService pingTaskExecutor = Executors.newScheduledThreadPool(10);
|
||||
|
||||
private final String sessionId;
|
||||
private UUID userId;
|
||||
|
|
@ -64,6 +67,10 @@ public class Session {
|
|||
private int messageId = 0;
|
||||
private final Date timeConnected;
|
||||
private boolean isAdmin = false;
|
||||
private final static int PING_CYCLES = 10;
|
||||
private final LinkedList<Long> pingTime = new LinkedList<>();
|
||||
private String pingInfo = "";
|
||||
|
||||
// private final AsynchInvokerCallbackHandler callbackHandler;
|
||||
|
||||
private final ReentrantLock lock;
|
||||
|
|
@ -82,6 +89,12 @@ public class Session {
|
|||
// sendErrorMessageToClient(returnMessage);
|
||||
// }
|
||||
// return returnMessage;
|
||||
pingTaskExecutor.scheduleAtFixedRate(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Main.getInstance().pingClient(sessionId);
|
||||
}
|
||||
}, 10, 60, TimeUnit.SECONDS);
|
||||
return registerUserHandling(userName);
|
||||
}
|
||||
|
||||
|
|
@ -260,6 +273,7 @@ public class Session {
|
|||
logger.error("SESSION LOCK - kill: userId " + userId);
|
||||
}
|
||||
UserManager.getInstance().removeUser(userId, reason);
|
||||
pingTime.clear();
|
||||
} catch (InterruptedException ex) {
|
||||
logger.error("SESSION LOCK - kill: userId " + userId, ex);
|
||||
}
|
||||
|
|
@ -324,4 +338,21 @@ public class Session {
|
|||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
public void recordPingTime(long milliSeconds) {
|
||||
pingTime.add(milliSeconds);
|
||||
String lastPing = milliSeconds > 0 ? milliSeconds+"ms" : "<1ms";
|
||||
if (pingTime.size() > PING_CYCLES) {
|
||||
pingTime.poll();
|
||||
}
|
||||
long sum = 0;
|
||||
for (Long time :pingTime) {
|
||||
sum += time;
|
||||
}
|
||||
pingInfo = lastPing + " (Av: " + (milliSeconds > 0 ? milliSeconds + "ms":"<1ms")+")";
|
||||
}
|
||||
|
||||
public String getPingInfo() {
|
||||
return pingInfo;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -223,4 +223,11 @@ public class SessionManager {
|
|||
// }
|
||||
// return false;
|
||||
// }
|
||||
|
||||
void recordPingTime(String sessionId, long milliSeconds) {
|
||||
Session session = sessions.get(sessionId);
|
||||
if (session != null) {
|
||||
session.recordPingTime(milliSeconds);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -375,7 +375,7 @@ public class TableManager {
|
|||
logger.debug(user.getId()
|
||||
+ " | " + formatter.format(user.getConnectionTime())
|
||||
+ " | " + sessionState
|
||||
+ " | " + user.getName() +" (" +user.getUserState().toString() + " - " + user.getPingInfo() + ")");
|
||||
+ " | " + user.getName() +" (" +user.getUserState().toString() + " - " + session.getPingInfo() + ")");
|
||||
}
|
||||
ArrayList<ChatSession> chatSessions = ChatManager.getInstance().getChatSessions();
|
||||
logger.debug("------- ChatSessions: " + chatSessions.size() + " ----------------------------------");
|
||||
|
|
|
|||
|
|
@ -512,12 +512,12 @@ public class User {
|
|||
return userState;
|
||||
}
|
||||
|
||||
public String getPingInfo() {
|
||||
if (isConnected()) {
|
||||
return pingInfo;
|
||||
} else {
|
||||
return " (discon. "+ getDisconnectDuration() + ")";
|
||||
}
|
||||
}
|
||||
// public String getPingInfo() {
|
||||
// if (isConnected()) {
|
||||
// return pingInfo;
|
||||
// } else {
|
||||
// return " (discon. "+ getDisconnectDuration() + ")";
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -197,4 +197,8 @@ public class UserManager {
|
|||
logger.fatal("User manager exception - null");
|
||||
}
|
||||
}
|
||||
|
||||
void recordPingTime(UUID userId, long milliSeconds) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,6 +73,8 @@ import mage.interfaces.Action;
|
|||
import mage.players.Player;
|
||||
import mage.server.ChatManager;
|
||||
import mage.server.Main;
|
||||
import mage.server.Session;
|
||||
import mage.server.SessionManager;
|
||||
import mage.server.TableManager;
|
||||
import mage.server.User;
|
||||
import mage.server.UserManager;
|
||||
|
|
@ -363,7 +365,8 @@ public class GameController implements GameCallback {
|
|||
GameManager.getInstance().joinGame(game.getId(), user.getId());
|
||||
logger.debug("Player " + player.getLogName() + " (disconnected) has joined gameId: " +game.getId());
|
||||
}
|
||||
ChatManager.getInstance().broadcast(chatId, user, user.getPingInfo() + " is pending to join the game", MessageColor.BLUE, true, ChatMessage.MessageType.STATUS);
|
||||
Session session = SessionManager.getInstance().getSession(user.getSessionId());
|
||||
ChatManager.getInstance().broadcast(chatId, user, session.getPingInfo() + " is pending to join the game", MessageColor.BLUE, true, ChatMessage.MessageType.STATUS);
|
||||
if (user.getSecondsDisconnected() > 240) {
|
||||
// Cancel player join possibility lately after 4 minutes
|
||||
logger.debug("Player " + player.getLogName() + " - canceled game (after 240 seconds) gameId: " +game.getId());
|
||||
|
|
|
|||
|
|
@ -46,6 +46,8 @@ import mage.game.Table;
|
|||
import mage.game.match.MatchOptions;
|
||||
import mage.game.tournament.TournamentOptions;
|
||||
import mage.server.RoomImpl;
|
||||
import mage.server.Session;
|
||||
import mage.server.SessionManager;
|
||||
import mage.server.TableManager;
|
||||
import mage.server.User;
|
||||
import mage.server.UserManager;
|
||||
|
|
@ -119,11 +121,12 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
|
|||
matchView = matchList;
|
||||
List<UsersView> users = new ArrayList<>();
|
||||
for (User user : UserManager.getInstance().getUsers()) {
|
||||
Session session = SessionManager.getInstance().getSession(user.getSessionId());
|
||||
try {
|
||||
users.add(new UsersView(user.getName(), user.getInfo(), user.getGameInfo(), user.getPingInfo()));
|
||||
users.add(new UsersView(user.getName(), user.getInfo(), user.getGameInfo(), session.getPingInfo()));
|
||||
} catch (Exception ex) {
|
||||
logger.fatal("User update exception: " + user.getName() + " - " + ex.toString(), ex);
|
||||
users.add(new UsersView(user.getName(), user.getInfo(), "[exception]", user.getPingInfo()));
|
||||
users.add(new UsersView(user.getName(), user.getInfo(), "[exception]", session.getPingInfo()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue