Server side of occupant management stuff.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@269 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2001-08-16 04:28:36 +00:00
parent eac3e9aa94
commit 2f7f106271
5 changed files with 202 additions and 15 deletions
@@ -1,15 +1,15 @@
//
// $Id: LocationProvider.java,v 1.5 2001/08/11 02:07:20 mdb Exp $
// $Id: LocationProvider.java,v 1.6 2001/08/16 04:28:36 mdb Exp $
package com.threerings.cocktail.party.server;
import com.threerings.cocktail.cher.dobj.DObject;
import com.threerings.cocktail.cher.server.CherServer;
import com.threerings.cocktail.cher.server.InvocationProvider;
import com.threerings.cocktail.cher.util.Codes;
import com.threerings.cocktail.party.Log;
import com.threerings.cocktail.party.data.*;
import com.threerings.cocktail.party.server.PartyServer;
/**
* This class provides the server end of the location services.
@@ -43,8 +43,8 @@ public class LocationProvider extends InvocationProvider
public static String moveTo (BodyObject source, int placeId)
{
// make sure the place in question actually exists
DObject pobj = CherServer.omgr.getObject(placeId);
if (pobj == null || !(pobj instanceof PlaceObject)) {
PlaceManager pmgr = PartyServer.plreg.getPlaceManager(placeId);
if (pmgr == null) {
Log.info("Requested to move to non-existent place " +
"[source=" + source + ", place=" + placeId + "].");
return "m.no_such_place";
@@ -69,8 +69,18 @@ public class LocationProvider extends InvocationProvider
// remove them from the occupant list of the previous location
try {
PlaceObject pold = (PlaceObject)
CherServer.omgr.getObject(source.location);
pold.removeFromOccupants(source.getOid());
PartyServer.omgr.getObject(source.location);
if (pold != null) {
pold.removeFromOccupants(source.getOid());
// also remove their occupant info (which is keyed on
// username)
pold.removeFromOccupantInfo(source.username);
} else {
Log.info("Body's prior location no longer around? " +
"[boid=" + source.getOid() +
", poid=" + source.location + "].");
}
} catch (ClassCastException cce) {
Log.warning("Body claims to be at location which " +
@@ -80,13 +90,20 @@ public class LocationProvider extends InvocationProvider
}
}
// add the body object id to the place object's occupant list
PlaceObject place = (PlaceObject)pobj;
place.addToOccupants(source.getOid());
// set their new location
// set the body's new location
PlaceObject place = pmgr.getPlaceObject();
source.setLocation(place.getOid());
// generate a new occupant info record and add it to the target
// location
OccupantInfo info = pmgr.buildOccupantInfo(source);
if (info != null) {
place.addToOccupantInfo(info);
}
// add the body object id to the place object's occupant list
place.addToOccupants(source.getOid());
// and finally queue up a lock release event to release the lock
// once all these events are processed
source.releaseLock("moveToLock");
@@ -1,5 +1,5 @@
//
// $Id: PlaceManager.java,v 1.7 2001/08/04 01:13:36 mdb Exp $
// $Id: PlaceManager.java,v 1.8 2001/08/16 04:28:36 mdb Exp $
package com.threerings.cocktail.party.server;
@@ -9,7 +9,7 @@ import java.util.Properties;
import com.threerings.cocktail.cher.dobj.*;
import com.threerings.cocktail.party.Log;
import com.threerings.cocktail.party.data.PlaceObject;
import com.threerings.cocktail.party.data.*;
/**
* The place manager is the server-side entity that handles all
@@ -58,6 +58,9 @@ public class PlaceManager implements Subscriber
// keep track of this
_plobj = plobj;
// configure the occupant info set
plobj.occupantInfo.setElementType(getOccupantInfoClass());
// we'll want to be included among the place object's subscribers;
// we know that we can call addSubscriber() directly because the
// place manager is doing all of our initialization on the dobjmgr
@@ -78,6 +81,54 @@ public class PlaceManager implements Subscriber
{
}
/**
* When the manager starts up, it configures its place object occupant
* info set by setting the type of occupant info objects it will
* contain. Managers that wish to use derived occupant info classes
* should override this function and return a reference to their
* derived class.
*/
protected Class getOccupantInfoClass ()
{
return OccupantInfo.class;
}
/**
* Builds an occupant info record for the specified body object. This
* is called by the location services when a body enters a place. It
* should not be overridden by derived classes, they should override
* {@link #populateOccupantInfo}, which is set up for that sort of
* thing.
*/
public OccupantInfo buildOccupantInfo (BodyObject body)
{
// create a new occupant info instance
try {
OccupantInfo info = (OccupantInfo)
getOccupantInfoClass().newInstance();
populateOccupantInfo(info, body);
return info;
} catch (Exception e) {
Log.warning("Failure building occupant info " +
"[body=" + body + "].");
Log.logStackTrace(e);
return null;
}
}
/**
* Derived classes should override this method if they are making use
* of a derived occupant info class. They should call the super
* implementation and then populate the occupant info fields in their
* extended object.
*/
protected void populateOccupantInfo (OccupantInfo info, BodyObject body)
{
// the base occupant info is only their username
info.username = body.username;
}
/**
* Called when a body object enters this place.
*/
@@ -1,5 +1,5 @@
//
// $Id: PlaceRegistry.java,v 1.6 2001/08/11 04:03:25 mdb Exp $
// $Id: PlaceRegistry.java,v 1.7 2001/08/16 04:28:36 mdb Exp $
package com.threerings.cocktail.party.server;
@@ -114,6 +114,15 @@ public class PlaceRegistry implements Subscriber
}
}
/**
* Returns the place manager associated with the specified place
* object id or null if no such place exists.
*/
public PlaceManager getPlaceManager (int placeOid)
{
return (PlaceManager)_pmgrs.get(placeOid);
}
/**
* Returns an enumeration of all of the registered place objects. This
* should only be accessed on the dobjmgr thread and shouldn't be kept