Server: improved ping info (added last activity time)

This commit is contained in:
Oleg Agafonov 2020-02-01 10:49:00 +04:00
parent 2079065af3
commit f4a0c70cf3
3 changed files with 22 additions and 16 deletions

View file

@ -1,12 +1,5 @@
package mage.remote; package mage.remote;
import java.io.*;
import java.lang.reflect.UndeclaredThrowableException;
import java.net.*;
import java.util.*;
import java.util.concurrent.CancellationException;
import java.util.concurrent.TimeUnit;
import javax.swing.*;
import mage.MageException; import mage.MageException;
import mage.cards.decks.DeckCardLists; import mage.cards.decks.DeckCardLists;
import mage.cards.repository.CardInfo; import mage.cards.repository.CardInfo;
@ -35,6 +28,14 @@ import org.jboss.remoting.transport.bisocket.Bisocket;
import org.jboss.remoting.transport.socket.SocketWrapper; import org.jboss.remoting.transport.socket.SocketWrapper;
import org.jboss.remoting.transporter.TransporterClient; import org.jboss.remoting.transporter.TransporterClient;
import javax.swing.*;
import java.io.*;
import java.lang.reflect.UndeclaredThrowableException;
import java.net.*;
import java.util.*;
import java.util.concurrent.CancellationException;
import java.util.concurrent.TimeUnit;
/** /**
* @author BetaSteward_at_googlemail.com, JayDi85 * @author BetaSteward_at_googlemail.com, JayDi85
*/ */
@ -501,7 +502,7 @@ 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 they want to try to reconnect * ask the user if they want to try to reconnect
*/ */
@Override @Override
public synchronized void disconnect(boolean askForReconnect) { public synchronized void disconnect(boolean askForReconnect) {
@ -1676,7 +1677,7 @@ public class SessionImpl implements Session {
sum += time; sum += time;
} }
milliSeconds = TimeUnit.MILLISECONDS.convert(sum / pingTime.size(), TimeUnit.NANOSECONDS); milliSeconds = TimeUnit.MILLISECONDS.convert(sum / pingTime.size(), TimeUnit.NANOSECONDS);
pingInfo = lastPing + " (Av: " + (milliSeconds > 0 ? milliSeconds + "ms" : "<1ms") + ')'; pingInfo = lastPing + " (avg: " + (milliSeconds > 0 ? milliSeconds + "ms" : "<1ms") + ')';
} }
return true; return true;
} catch (MageException ex) { } catch (MageException ex) {

View file

@ -193,10 +193,11 @@ public class User {
} }
public String getDisconnectDuration() { public String getDisconnectDuration() {
long secondsDisconnected = getSecondsDisconnected(); //long secondsDisconnected = getSecondsDisconnected();
int minutes = (int) secondsDisconnected / 60; //int minutes = (int) secondsDisconnected / 60;
int seconds = (int) secondsDisconnected % 60; //int seconds = (int) secondsDisconnected % 60;
return Integer.toString(minutes) + ':' + (seconds > 9 ? seconds : '0' + Integer.toString(seconds)); //return Integer.toString(minutes) + ':' + (seconds > 9 ? seconds : '0' + Integer.toString(seconds));
return getSecondsDisconnected() + " secs";
} }
public long getSecondsDisconnected() { public long getSecondsDisconnected() {
@ -218,7 +219,11 @@ public class User {
hours = minutes / 60; hours = minutes / 60;
minutes = minutes - (hours * 60); minutes = minutes - (hours * 60);
} }
return hours + ":" + (minutes > 9 ? Integer.toString(minutes) : '0' + Integer.toString(minutes)); String connTime = hours + ":" + (minutes > 9 ? Integer.toString(minutes) : '0' + Integer.toString(minutes));
int lastSecs = (int) SystemUtil.getDateDiff(lastActivity, new Date(), TimeUnit.SECONDS);
return " (online: " + connTime + "; seen: " + lastSecs + " sec ago)";
} }
public void fireCallback(final ClientCallback call) { public void fireCallback(final ClientCallback call) {

View file

@ -1192,7 +1192,7 @@ public class GameController implements GameCallback {
List<String> usersInfo = new ArrayList<>(); List<String> usersInfo = new ArrayList<>();
for (Map.Entry<UUID, UUID> entry : userPlayerMap.entrySet()) { for (Map.Entry<UUID, UUID> entry : userPlayerMap.entrySet()) {
Optional<User> user = UserManager.instance.getUser(entry.getKey()); Optional<User> user = UserManager.instance.getUser(entry.getKey());
user.ifPresent(u -> usersInfo.add(u.getName() + ": " + u.getPingInfo())); user.ifPresent(u -> usersInfo.add("* " + u.getName() + ": " + u.getPingInfo()));
} }
Collections.sort(usersInfo); Collections.sort(usersInfo);
usersInfo.add(0, "Players ping:"); usersInfo.add(0, "Players ping:");
@ -1200,7 +1200,7 @@ public class GameController implements GameCallback {
List<String> watchersinfo = new ArrayList<>(); List<String> watchersinfo = new ArrayList<>();
for (Map.Entry<UUID, GameSessionWatcher> entry : watchers.entrySet()) { for (Map.Entry<UUID, GameSessionWatcher> entry : watchers.entrySet()) {
Optional<User> user = UserManager.instance.getUser(entry.getValue().userId); Optional<User> user = UserManager.instance.getUser(entry.getValue().userId);
user.ifPresent(u -> watchersinfo.add(u.getName() + ": " + u.getPingInfo())); user.ifPresent(u -> watchersinfo.add("* " + u.getName() + ": " + u.getPingInfo()));
} }
Collections.sort(watchersinfo); Collections.sort(watchersinfo);
if (watchersinfo.size() > 0) { if (watchersinfo.size() > 0) {