Separated the code that does the moveTo from the code that processes the

invocation request. This will allow more complicated services to be built
atop the same location management system provided by the Party services.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@220 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2001-08-11 00:22:55 +00:00
parent 8ba65f8304
commit a5ef549091
@@ -1,11 +1,12 @@
//
// $Id: LocationProvider.java,v 1.3 2001/08/11 00:05:58 mdb Exp $
// $Id: LocationProvider.java,v 1.4 2001/08/11 00:22:55 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.*;
@@ -20,14 +21,33 @@ public class LocationProvider extends InvocationProvider
*/
public void handleMoveToRequest (BodyObject source, int invid,
int placeId)
{
// try to do the actual move
String rcode = moveTo(source, placeId);
// send the response
if (rcode.equals(Codes.SUCCESS)) {
sendResponse(source, invid, "MoveSucceeded");
} else {
sendResponse(source, invid, "MoveFailed", rcode);
}
}
/**
* Moves the specified body from whatever location they currently
* occupy to the location identified by the supplied place id.
*
* @return the string <code>Codes.SUCCESS</code> if the move was
* successful or a reason code for failure if not.
*/
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)) {
Log.info("Requested to move to non-existent place " +
"[source=" + source + ", place=" + placeId + "].");
sendResponse(source, invid, "MoveFailed", "m.no_such_place");
return;
return "m.no_such_place";
}
// acquire a lock on the body object to ensure that rapid fire
@@ -35,8 +55,7 @@ public class LocationProvider extends InvocationProvider
if (!source.acquireLock("moveToLock")) {
// if we're still locked, a previous moveTo request hasn't
// been fully processed
sendResponse(source, invid, "MoveFailed", "m.move_in_progress");
return;
return "m.move_in_progress";
}
// find out if they were previously in some other location
@@ -66,7 +85,6 @@ public class LocationProvider extends InvocationProvider
// once all these events are processed
source.releaseLock("moveToLock");
// send the response
sendResponse(source, invid, "MoveSucceeded");
return Codes.SUCCESS;
}
}