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:
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: ChatDirector.java,v 1.21 2002/05/22 21:44:54 shaper Exp $
|
||||
// $Id: ChatDirector.java,v 1.22 2002/05/26 02:24:45 mdb Exp $
|
||||
|
||||
package com.threerings.crowd.chat;
|
||||
|
||||
@@ -34,15 +34,9 @@ public class ChatDirector
|
||||
// keep the context around
|
||||
_ctx = ctx;
|
||||
|
||||
// register a client observer that will register us as the chat
|
||||
// receiver when we log on
|
||||
_ctx.getClient().addClientObserver(new ClientAdapter() {
|
||||
public void clientDidLogon (Client client)
|
||||
{
|
||||
client.getInvocationDirector().registerReceiver(
|
||||
MODULE_NAME, ChatDirector.this);
|
||||
}
|
||||
});
|
||||
// register for chat notifications
|
||||
_ctx.getClient().getInvocationDirector().registerReceiver(
|
||||
MODULE_NAME, this);
|
||||
|
||||
// register ourselves as a location observer
|
||||
_ctx.getLocationDirector().addLocationObserver(this);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: LocationDirector.java,v 1.19 2002/05/22 21:46:53 shaper Exp $
|
||||
// $Id: LocationDirector.java,v 1.20 2002/05/26 02:24:46 mdb Exp $
|
||||
|
||||
package com.threerings.crowd.client;
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.samskivert.util.ObserverList;
|
||||
import com.samskivert.util.ObserverList.ObserverOp;
|
||||
|
||||
import com.threerings.presents.client.Client;
|
||||
import com.threerings.presents.client.InvocationReceiver;
|
||||
import com.threerings.presents.client.SessionObserver;
|
||||
import com.threerings.presents.dobj.DObject;
|
||||
import com.threerings.presents.dobj.DObjectManager;
|
||||
@@ -18,6 +19,7 @@ import com.threerings.presents.dobj.Subscriber;
|
||||
|
||||
import com.threerings.crowd.Log;
|
||||
import com.threerings.crowd.data.BodyObject;
|
||||
import com.threerings.crowd.data.LocationCodes;
|
||||
import com.threerings.crowd.data.PlaceConfig;
|
||||
import com.threerings.crowd.data.PlaceObject;
|
||||
import com.threerings.crowd.util.CrowdContext;
|
||||
@@ -30,7 +32,7 @@ import com.threerings.crowd.util.CrowdContext;
|
||||
* before actually issuing the request.
|
||||
*/
|
||||
public class LocationDirector
|
||||
implements SessionObserver, Subscriber
|
||||
implements LocationCodes, SessionObserver, Subscriber, InvocationReceiver
|
||||
{
|
||||
/**
|
||||
* Used to recover from a moveTo request that was accepted but
|
||||
@@ -57,6 +59,10 @@ public class LocationDirector
|
||||
|
||||
// register ourselves as a client observer
|
||||
ctx.getClient().addClientObserver(this);
|
||||
|
||||
// register for location notifications
|
||||
_ctx.getClient().getInvocationDirector().registerReceiver(
|
||||
MODULE_NAME, this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -174,11 +180,13 @@ public class LocationDirector
|
||||
*/
|
||||
public void didMoveTo (int placeId, PlaceConfig config)
|
||||
{
|
||||
// keep track of our previous place id
|
||||
_previousPlaceId = _placeId;
|
||||
|
||||
// do some cleaning up in case we were previously in a place
|
||||
didLeavePlace();
|
||||
|
||||
// make a note that we're now mostly in the new location
|
||||
_previousPlaceId = _placeId;
|
||||
_placeId = placeId;
|
||||
|
||||
Class cclass = config.getControllerClass();
|
||||
@@ -199,12 +207,12 @@ public class LocationDirector
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when we're leaving our current location. Informs the
|
||||
* Called when we're leaving our current location. Informs the
|
||||
* location's controller that we're departing, unsubscribes from the
|
||||
* location's place object, and clears out our internal place
|
||||
* information.
|
||||
*/
|
||||
protected void didLeavePlace ()
|
||||
public void didLeavePlace ()
|
||||
{
|
||||
if (_plobj != null) {
|
||||
// let the old controller know that things are going away
|
||||
@@ -244,6 +252,7 @@ public class LocationDirector
|
||||
notifyFailure(placeId, reason);
|
||||
}
|
||||
|
||||
// documentation inherited from interface
|
||||
public void clientDidLogon (Client client)
|
||||
{
|
||||
// get a copy of our body object
|
||||
@@ -270,6 +279,7 @@ public class LocationDirector
|
||||
// we'll want to be going there straight away
|
||||
}
|
||||
|
||||
// documentation inherited from interface
|
||||
public void clientDidLogoff (Client client)
|
||||
{
|
||||
// clear ourselves out and inform observers of our departure
|
||||
@@ -307,6 +317,23 @@ public class LocationDirector
|
||||
notifyFailure(placeId, reason);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the server has decided to forcibly move us to another
|
||||
* room. The server first ejects us from our previous room and then
|
||||
* sends us a notification with our new location. We then turn around
|
||||
* and issue a standard moveTo request.
|
||||
*/
|
||||
public void handleMoveNotification (int placeId)
|
||||
{
|
||||
Log.info("Moving at request of server [placeId=" + placeId + "].");
|
||||
|
||||
// clear out our old place information
|
||||
didLeavePlace();
|
||||
|
||||
// move to the new place
|
||||
moveTo(placeId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when we receive the place object to which we subscribed
|
||||
* after a successful moveTo request.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: LocationCodes.java,v 1.2 2002/04/15 18:06:19 mdb Exp $
|
||||
// $Id: LocationCodes.java,v 1.3 2002/05/26 02:24:46 mdb Exp $
|
||||
|
||||
package com.threerings.crowd.data;
|
||||
|
||||
@@ -27,6 +27,9 @@ public interface LocationCodes extends InvocationCodes
|
||||
* LocationDirector#handleMoveFailed}. */
|
||||
public static final String MOVE_FAILED_RESPONSE = "MoveFailed";
|
||||
|
||||
/** The message identifier for a move notification. */
|
||||
public static final String MOVE_NOTIFICATION = "Move";
|
||||
|
||||
/** An error code indicating that a place identified by a particular
|
||||
* place id does not exist. Usually generated by a failed moveTo
|
||||
* request. */
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user