Added support for initiating a place/scene/zone transition from the

server; chat director no longer needs to wait until we're logged on to
register itself with the invocation director.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1393 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2002-05-26 02:24:46 +00:00
parent 8a7a046df8
commit 97197d49cc
10 changed files with 251 additions and 73 deletions
@@ -1,5 +1,5 @@
//
// $Id: LocationProvider.java,v 1.13 2002/05/02 21:19:28 mdb Exp $
// $Id: LocationProvider.java,v 1.14 2002/05/26 02:24:46 mdb Exp $
package com.threerings.crowd.server;
@@ -20,8 +20,8 @@ import com.threerings.crowd.data.PlaceObject;
/**
* This class provides the server end of the location services.
*/
public class LocationProvider
extends InvocationProvider implements LocationCodes
public class LocationProvider extends InvocationProvider
implements LocationCodes
{
/**
* Constructs a location provider and registers it with the invocation
@@ -32,6 +32,7 @@ public class LocationProvider
InvocationManager invmgr, RootDObjectManager omgr, PlaceRegistry plreg)
{
// we'll need these later
_invmgr = invmgr;
_omgr = omgr;
_plreg = plreg;
@@ -42,8 +43,8 @@ public class LocationProvider
/**
* Processes a request from a client to move to a new place.
*/
public void handleMoveToRequest (BodyObject source, int invid,
int placeId)
public void handleMoveToRequest (
BodyObject source, int invid, int placeId)
{
try {
// do the move
@@ -90,62 +91,124 @@ public class LocationProvider
return pmgr.getConfig();
}
// acquire a lock on the body object to ensure that rapid fire
// moveto requests don't break things
if (!source.acquireLock("moveToLock")) {
// if we're still locked, a previous moveTo request hasn't
// been fully processed
throw new ServiceFailedException(MOVE_IN_PROGRESS);
try {
// acquire a lock on the body object to ensure that rapid fire
// moveTo requests don't break things
if (!source.acquireLock("moveToLock")) {
// if we're still locked, a previous moveTo request hasn't
// been fully processed
throw new ServiceFailedException(MOVE_IN_PROGRESS);
}
PlaceObject place = pmgr.getPlaceObject();
try {
source.startTransaction();
// remove them from any previous location
leaveOccupiedPlace(source);
// set the body's new location
source.setLocation(place.getOid());
} finally {
source.commitTransaction();
}
try {
place.startTransaction();
// 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 oid to the place object's occupant list
place.addToOccupants(bodoid);
} finally {
place.commitTransaction();
}
} finally {
// and finally queue up a lock release event to release the
// lock once all these events are processed
source.releaseLock("moveToLock");
}
// find out if they were previously in some other location
if (source.location != -1) {
// remove them from the occupant list of the previous location
try {
PlaceObject pold = (PlaceObject)
_omgr.getObject(source.location);
if (pold != null) {
Object key = new Integer(bodoid);
return pmgr.getConfig();
}
/**
* Removes the specified body from the place object they currently
* occupy. Does nothing if the body is not currently in a place.
*/
public static void leaveOccupiedPlace (BodyObject source)
{
int oldloc = source.location;
int bodoid = source.getOid();
// nothing to do if they weren't previously in some location
if (oldloc == -1) {
return;
}
// remove them from the occupant list
try {
PlaceObject pold = (PlaceObject)_omgr.getObject(oldloc);
if (pold != null) {
Object key = new Integer(bodoid);
try {
pold.startTransaction();
// remove their occupant info (which is keyed on oid)
pold.removeFromOccupantInfo(key);
// and remove them from the occupant list
pold.removeFromOccupants(bodoid);
} else {
Log.info("Body's prior location no longer around? " +
"[boid=" + bodoid +
", poid=" + source.location + "].");
} finally {
pold.commitTransaction();
}
} catch (ClassCastException cce) {
Log.warning("Body claims to be at location which " +
"references non-PlaceObject!? " +
"[boid=" + bodoid +
", poid=" + source.location + "].");
} else {
Log.info("Body's prior location no longer around? " +
"[boid=" + bodoid + ", poid=" + oldloc + "].");
}
} catch (ClassCastException cce) {
Log.warning("Body claims to occupy non-PlaceObject!? " +
"[boid=" + bodoid + ", poid=" + oldloc +
", error=" + cce + "].");
}
// 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(bodoid);
// and finally queue up a lock release event to release the lock
// once all these events are processed
source.releaseLock("moveToLock");
return pmgr.getConfig();
// clear out their location oid
source.setLocation(-1);
}
/**
* Forcibly moves the specified body object to the new place. This is
* accomplished by first removing the client from their old location
* and then sending the client a notification, instructing it to move
* to the new location (which it does using the normal moveTo
* service). This has the benefit that the client is removed from
* their old place regardless of whether or not they are cooperating.
* If they choose to ignore the forced move request, they will remain
* in limbo, unable to do much of anything.
*/
public void moveBody (BodyObject source, int placeId)
{
// first remove them from their old place
leaveOccupiedPlace(source);
// then send a move notification
_invmgr.sendNotification(
source.getOid(), MODULE_NAME, MOVE_NOTIFICATION,
new Object[] { new Integer(placeId) });
}
/** The invocation manager with which we interoperate. */
protected static InvocationManager _invmgr;
/** The distributed object manager with which we interoperate. */
protected static RootDObjectManager _omgr;