Maintain user's status in their body object; also maintain a timestamp

that indicates the time at which their status became what it is.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1863 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2002-10-30 00:42:37 +00:00
parent 6b651c2f9c
commit 77ae8c7d0f
4 changed files with 83 additions and 21 deletions
@@ -1,5 +1,5 @@
//
// $Id: BodyObject.dobj,v 1.10 2002/08/14 19:07:49 mdb Exp $
// $Id: BodyObject.dobj,v 1.11 2002/10/30 00:42:37 mdb Exp $
package com.threerings.crowd.data;
@@ -18,9 +18,25 @@ public class BodyObject extends ClientObject
*/
public int location = -1;
/**
* The user's current status ({@link OccupantInfo#ACTIVE}, etc.).
*/
public byte status;
/**
* The time at which the {@link #status} field was last updated. This
* is only available on the server.
*/
public transient long statusTime;
// documentation inherited
public String who ()
{
return username + " (" + getOid() + ")";
StringBuffer buf = new StringBuffer(username);
buf.append(" (").append(getOid());
if (status != OccupantInfo.ACTIVE) {
buf.append(" ").append(OccupantInfo.X_STATUS[status]);
}
return buf.append(")").toString();
}
}
@@ -1,5 +1,5 @@
//
// $Id: BodyObject.java,v 1.4 2002/08/14 19:07:49 mdb Exp $
// $Id: BodyObject.java,v 1.5 2002/10/30 00:42:37 mdb Exp $
package com.threerings.crowd.data;
@@ -13,6 +13,9 @@ public class BodyObject extends ClientObject
/** The field name of the <code>location</code> field. */
public static final String LOCATION = "location";
/** The field name of the <code>status</code> field. */
public static final String STATUS = "status";
/**
* The username associated with this body object.
*/
@@ -24,10 +27,26 @@ public class BodyObject extends ClientObject
*/
public int location = -1;
/**
* The user's current status ({@link OccupantInfo#ACTIVE}, etc.).
*/
public byte status;
/**
* The time at which the {@link #status} field was last updated. This
* is only available on the server.
*/
public transient long statusTime;
// documentation inherited
public String who ()
{
return username + " (" + getOid() + ")";
StringBuffer buf = new StringBuffer(username);
buf.append(" (").append(getOid());
if (status != OccupantInfo.ACTIVE) {
buf.append(" ").append(OccupantInfo.X_STATUS[status]);
}
return buf.append(")").toString();
}
/**
@@ -57,4 +76,18 @@ public class BodyObject extends ClientObject
this.location = location;
requestAttributeChange(LOCATION, new Integer(location));
}
/**
* Requests that the <code>status</code> field be set to the specified
* value. The local value will be updated immediately and an event
* will be propagated through the system to notify all listeners that
* the attribute did change. Proxied copies of this object (on
* clients) will apply the value change when they received the
* attribute changed notification.
*/
public void setStatus (byte status)
{
this.status = status;
requestAttributeChange(STATUS, new Byte(status));
}
}
@@ -1,5 +1,5 @@
//
// $Id: OccupantInfo.java,v 1.10 2002/10/26 02:40:30 shaper Exp $
// $Id: OccupantInfo.java,v 1.11 2002/10/30 00:42:37 mdb Exp $
package com.threerings.crowd.data;
@@ -36,6 +36,9 @@ public class OccupantInfo extends SimpleStreamableObject
/** Constant value for {@link #status}. */
public static final byte DISCONNECTED = 2;
/** Maps status codes to human readable strings. */
public static final String[] X_STATUS = { "active", "idle", "discon" };
/** The body object id of this occupant (and our entry key). */
public Integer bodyOid;
@@ -1,5 +1,5 @@
//
// $Id: CrowdClient.java,v 1.12 2002/10/27 02:04:50 shaper Exp $
// $Id: CrowdClient.java,v 1.13 2002/10/30 00:42:37 mdb Exp $
package com.threerings.crowd.server;
@@ -25,8 +25,7 @@ public class CrowdClient extends PresentsClient
if (_clobj != null) {
// note that the user's disconnected
BodyObject bobj = (BodyObject)_clobj;
updateOccupantStatus(
bobj.getOid(), bobj.location, OccupantInfo.DISCONNECTED);
updateOccupantStatus(bobj, OccupantInfo.DISCONNECTED);
}
}
@@ -37,26 +36,37 @@ public class CrowdClient extends PresentsClient
// note that the user's active once more
BodyObject bobj = (BodyObject)_clobj;
updateOccupantStatus(bobj.getOid(), bobj.location, OccupantInfo.ACTIVE);
updateOccupantStatus(bobj, OccupantInfo.ACTIVE);
}
/**
* Updates the connection status for the given body object's occupant
* info in the specified location.
*/
protected void updateOccupantStatus (
int bodyOid, int locationId, byte status)
protected void updateOccupantStatus (BodyObject body, byte status)
{
// get the place object for the specified location
PlaceObject plobj = (PlaceObject)CrowdServer.omgr.getObject(locationId);
if (plobj != null) {
// update the occupant info with the new connection status
OccupantInfo info = (OccupantInfo)plobj.occupantInfo.get(
new Integer(bodyOid));
if (info != null && info.status != status) {
info.status = status;
plobj.updateOccupantInfo(info);
}
// no need to NOOP
if (body.status == status) {
return;
}
// update the status in their body object
body.setStatus(status);
body.statusTime = System.currentTimeMillis();
// get the place object for the location occupied by the user
PlaceObject plobj = (PlaceObject)
CrowdServer.omgr.getObject(body.location);
if (plobj == null) {
return;
}
// update the occupant info with the new connection status
OccupantInfo info = (OccupantInfo)
plobj.occupantInfo.get(new Integer(body.getOid()));
if (info != null) {
info.status = status;
plobj.updateOccupantInfo(info);
}
}
}