From 77ae8c7d0f23a3dd58fd43ee31ed33cb9537ee81 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Wed, 30 Oct 2002 00:42:37 +0000 Subject: [PATCH] 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 --- .../com/threerings/crowd/data/BodyObject.dobj | 20 ++++++++- .../com/threerings/crowd/data/BodyObject.java | 37 +++++++++++++++- .../threerings/crowd/data/OccupantInfo.java | 5 ++- .../threerings/crowd/server/CrowdClient.java | 42 ++++++++++++------- 4 files changed, 83 insertions(+), 21 deletions(-) diff --git a/src/java/com/threerings/crowd/data/BodyObject.dobj b/src/java/com/threerings/crowd/data/BodyObject.dobj index 0a325e367..de7aab4c6 100644 --- a/src/java/com/threerings/crowd/data/BodyObject.dobj +++ b/src/java/com/threerings/crowd/data/BodyObject.dobj @@ -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(); } } diff --git a/src/java/com/threerings/crowd/data/BodyObject.java b/src/java/com/threerings/crowd/data/BodyObject.java index c9f121c24..6f19f4a3e 100644 --- a/src/java/com/threerings/crowd/data/BodyObject.java +++ b/src/java/com/threerings/crowd/data/BodyObject.java @@ -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 location field. */ public static final String LOCATION = "location"; + /** The field name of the status 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 status 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)); + } } diff --git a/src/java/com/threerings/crowd/data/OccupantInfo.java b/src/java/com/threerings/crowd/data/OccupantInfo.java index 1045cfe72..c1fa155a4 100644 --- a/src/java/com/threerings/crowd/data/OccupantInfo.java +++ b/src/java/com/threerings/crowd/data/OccupantInfo.java @@ -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; diff --git a/src/java/com/threerings/crowd/server/CrowdClient.java b/src/java/com/threerings/crowd/server/CrowdClient.java index 1dc3b231b..6f2529f8b 100644 --- a/src/java/com/threerings/crowd/server/CrowdClient.java +++ b/src/java/com/threerings/crowd/server/CrowdClient.java @@ -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); } } }