Made the code for updating a player's occupant info more general purpose.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@2793 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: BodyProvider.java,v 1.5 2003/08/09 04:57:41 mdb Exp $
|
// $Id: BodyProvider.java,v 1.6 2003/09/11 03:20:06 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.crowd.server;
|
package com.threerings.crowd.server;
|
||||||
|
|
||||||
@@ -19,6 +19,17 @@ import com.threerings.crowd.data.PlaceObject;
|
|||||||
public class BodyProvider
|
public class BodyProvider
|
||||||
implements InvocationProvider
|
implements InvocationProvider
|
||||||
{
|
{
|
||||||
|
/** Used by {@link #updateOccupantInfo}. */
|
||||||
|
public static interface OccupantInfoOp
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Updates the supplied occupant info record, returning true if
|
||||||
|
* changes were made and thus the object should be published anew
|
||||||
|
* to the place object, false if no publish should be done.
|
||||||
|
*/
|
||||||
|
public boolean update (OccupantInfo oinfo);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs and initializes a body provider instance which will be
|
* Constructs and initializes a body provider instance which will be
|
||||||
* used to handle all body-related invocation service requests.
|
* used to handle all body-related invocation service requests.
|
||||||
@@ -53,12 +64,32 @@ public class BodyProvider
|
|||||||
updateOccupantStatus(bobj, bobj.location, nstatus);
|
updateOccupantStatus(bobj, bobj.location, nstatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Locates the specified body's occupant info in the specified
|
||||||
|
* location, applies the supplied occuapnt info operation to it and
|
||||||
|
* then broadcasts the updated info (assuming the occop returned true
|
||||||
|
* indicating that an update was made).
|
||||||
|
*/
|
||||||
|
public static void updateOccupantInfo (BodyObject body, int locationId,
|
||||||
|
OccupantInfoOp occop)
|
||||||
|
{
|
||||||
|
PlaceManager pmgr = CrowdServer.plreg.getPlaceManager(locationId);
|
||||||
|
if (pmgr == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
OccupantInfo info = pmgr.getOccupantInfo(body.getOid());
|
||||||
|
if (info != null && occop.update(info)) {
|
||||||
|
pmgr.updateOccupantInfo(info);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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.
|
||||||
*/
|
*/
|
||||||
public static void updateOccupantStatus (
|
public static void updateOccupantStatus (
|
||||||
BodyObject body, int locationId, byte status)
|
BodyObject body, int locationId, final byte status)
|
||||||
{
|
{
|
||||||
// no need to NOOP
|
// no need to NOOP
|
||||||
if (body.status != status) {
|
if (body.status != status) {
|
||||||
@@ -67,25 +98,15 @@ public class BodyProvider
|
|||||||
body.statusTime = System.currentTimeMillis();
|
body.statusTime = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the place manager for the specified location
|
updateOccupantInfo(body, locationId, new OccupantInfoOp() {
|
||||||
PlaceManager pmgr = CrowdServer.plreg.getPlaceManager(locationId);
|
public boolean update (OccupantInfo info) {
|
||||||
if (pmgr == null) {
|
if (info.status != status) {
|
||||||
return;
|
info.status = status;
|
||||||
}
|
return true;
|
||||||
|
} else {
|
||||||
// get the place object for the specified location (which is, in
|
return false;
|
||||||
// theory, occupied by this user)
|
}
|
||||||
PlaceObject plobj = pmgr.getPlaceObject();
|
}
|
||||||
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) {
|
|
||||||
info.status = status;
|
|
||||||
pmgr.updateOccupantInfo(info);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user