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
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user