From 2c17f3612eaf95fa81949cf3a4a538397fcc85c3 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Fri, 24 Jun 2005 22:10:19 +0000 Subject: [PATCH] Track the number of seconds for which the client is connected at the presents level as it is of interest in pretty much any system. This allows us to do away with one of the time stamps as well. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3624 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../presents/server/PresentsClient.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/java/com/threerings/presents/server/PresentsClient.java b/src/java/com/threerings/presents/server/PresentsClient.java index adf43934f..773197c60 100644 --- a/src/java/com/threerings/presents/server/PresentsClient.java +++ b/src/java/com/threerings/presents/server/PresentsClient.java @@ -463,7 +463,13 @@ public class PresentsClient */ public void shutdown () { - // nothing to do by default + // if the client is connected, we need to fake the computation of + // their final connect time because we won't be closing their + // socket normally + if (getConnection() != null) { + long now = System.currentTimeMillis(); + _connectTime += ((now - _networkStamp) / 1000); + } } /** @@ -663,6 +669,13 @@ public class PresentsClient */ protected synchronized void setConnection (Connection conn) { + // if our connection is being cleared out, record the amount of + // time we were connected to our total connected time + long now = System.currentTimeMillis(); + if (_conn != null && conn == null) { + _connectTime += ((now - _networkStamp) / 1000); + } + // keep a handle to the new connection _conn = conn; @@ -678,7 +691,7 @@ public class PresentsClient } // make a note that our network status changed - _networkStamp = System.currentTimeMillis(); + _networkStamp = now; } /** @@ -933,6 +946,10 @@ public class PresentsClient * disconnected. */ protected long _networkStamp; + /** The total number of seconds for which the user was connected to + * the server in this session. */ + protected int _connectTime; + /** Prevent the client from sending too many messages too frequently. * 100 messages in 10 seconds and you're audi. */ protected Throttle _throttle = new Throttle(100, 10 * 1000L);