From 79259479c666342f9c4409ae8b153d7f160db874 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Thu, 31 Oct 2002 21:03:57 +0000 Subject: [PATCH] Make a note of when we started our session and when we most recently connected or disconnected. Use this to determine if a client has "expired" (meaning they've been disconnected for too long). git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1871 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../presents/server/PresentsClient.java | 46 ++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/src/java/com/threerings/presents/server/PresentsClient.java b/src/java/com/threerings/presents/server/PresentsClient.java index 94f1e651d..276387533 100644 --- a/src/java/com/threerings/presents/server/PresentsClient.java +++ b/src/java/com/threerings/presents/server/PresentsClient.java @@ -1,5 +1,5 @@ // -// $Id: PresentsClient.java,v 1.42 2002/10/26 02:40:30 shaper Exp $ +// $Id: PresentsClient.java,v 1.43 2002/10/31 21:03:57 mdb Exp $ package com.threerings.presents.server; @@ -81,6 +81,33 @@ public class PresentsClient return _creds; } + /** + * Returns true if this client has been disconnected for sufficiently + * long that its session should be forcibly ended. + */ + public boolean checkExpired (long now) + { + return (getConnection() == null && (now - _networkStamp > FLUSH_TIME)); + } + + /** + * Returns the time at which this client started their network + * session. + */ + public long getSessionStamp () + { + return _sessionStamp; + } + + /** + * Returns the time at which this client most recently connected or + * disconnected. + */ + public long getNetworkStamp () + { + return _networkStamp; + } + /** * Returns the username with which this client instance is associated. */ @@ -213,6 +240,9 @@ public class PresentsClient // resolve our client object before we get fully underway cmgr.resolveClientObject(_username, this); + + // make a note of our session start time + _sessionStamp = System.currentTimeMillis(); } /** @@ -527,6 +557,9 @@ public class PresentsClient if (_conn != null) { _conn.setMessageHandler(this); } + + // make a note that our network status changed + _networkStamp = System.currentTimeMillis(); } /** @@ -740,6 +773,17 @@ public class PresentsClient protected static HashMap _disps = new HashMap(); + /** The time at which this client started their session. */ + protected long _sessionStamp; + + /** The time at which this client most recently connected or + * disconnected. */ + protected long _networkStamp; + + /** The amount of time after disconnection a user is allowed before + * their session is forcibly ended. */ + protected static final long FLUSH_TIME = 7 * 60 * 1000L; + // register our message dispatchers static { _disps.put(SubscribeRequest.class, new SubscribeDispatcher());