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:
@@ -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;
|
package com.threerings.crowd.data;
|
||||||
|
|
||||||
@@ -18,9 +18,25 @@ public class BodyObject extends ClientObject
|
|||||||
*/
|
*/
|
||||||
public int location = -1;
|
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
|
// documentation inherited
|
||||||
public String who ()
|
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;
|
package com.threerings.crowd.data;
|
||||||
|
|
||||||
@@ -13,6 +13,9 @@ public class BodyObject extends ClientObject
|
|||||||
/** The field name of the <code>location</code> field. */
|
/** The field name of the <code>location</code> field. */
|
||||||
public static final String LOCATION = "location";
|
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.
|
* The username associated with this body object.
|
||||||
*/
|
*/
|
||||||
@@ -24,10 +27,26 @@ public class BodyObject extends ClientObject
|
|||||||
*/
|
*/
|
||||||
public int location = -1;
|
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
|
// documentation inherited
|
||||||
public String who ()
|
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;
|
this.location = location;
|
||||||
requestAttributeChange(LOCATION, new Integer(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;
|
package com.threerings.crowd.data;
|
||||||
|
|
||||||
@@ -36,6 +36,9 @@ public class OccupantInfo extends SimpleStreamableObject
|
|||||||
/** Constant value for {@link #status}. */
|
/** Constant value for {@link #status}. */
|
||||||
public static final byte DISCONNECTED = 2;
|
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). */
|
/** The body object id of this occupant (and our entry key). */
|
||||||
public Integer bodyOid;
|
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;
|
package com.threerings.crowd.server;
|
||||||
|
|
||||||
@@ -25,8 +25,7 @@ public class CrowdClient extends PresentsClient
|
|||||||
if (_clobj != null) {
|
if (_clobj != null) {
|
||||||
// note that the user's disconnected
|
// note that the user's disconnected
|
||||||
BodyObject bobj = (BodyObject)_clobj;
|
BodyObject bobj = (BodyObject)_clobj;
|
||||||
updateOccupantStatus(
|
updateOccupantStatus(bobj, OccupantInfo.DISCONNECTED);
|
||||||
bobj.getOid(), bobj.location, OccupantInfo.DISCONNECTED);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,26 +36,37 @@ public class CrowdClient extends PresentsClient
|
|||||||
|
|
||||||
// note that the user's active once more
|
// note that the user's active once more
|
||||||
BodyObject bobj = (BodyObject)_clobj;
|
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
|
* Updates the connection status for the given body object's occupant
|
||||||
* info in the specified location.
|
* info in the specified location.
|
||||||
*/
|
*/
|
||||||
protected void updateOccupantStatus (
|
protected void updateOccupantStatus (BodyObject body, byte status)
|
||||||
int bodyOid, int locationId, byte status)
|
|
||||||
{
|
{
|
||||||
// get the place object for the specified location
|
// no need to NOOP
|
||||||
PlaceObject plobj = (PlaceObject)CrowdServer.omgr.getObject(locationId);
|
if (body.status == status) {
|
||||||
if (plobj != null) {
|
return;
|
||||||
// update the occupant info with the new connection status
|
}
|
||||||
OccupantInfo info = (OccupantInfo)plobj.occupantInfo.get(
|
|
||||||
new Integer(bodyOid));
|
// update the status in their body object
|
||||||
if (info != null && info.status != status) {
|
body.setStatus(status);
|
||||||
info.status = status;
|
body.statusTime = System.currentTimeMillis();
|
||||||
plobj.updateOccupantInfo(info);
|
|
||||||
}
|
// 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user