Further implementation of body/place/chat stuff. Mostly location related.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@109 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,13 +1,113 @@
|
||||
//
|
||||
// $Id: LocationDirector.java,v 1.2 2001/07/20 23:23:50 mdb Exp $
|
||||
// $Id: LocationDirector.java,v 1.3 2001/07/23 21:14:27 mdb Exp $
|
||||
|
||||
package com.threerings.cocktail.party.client;
|
||||
|
||||
import com.threerings.cocktail.cher.client.Client;
|
||||
import com.threerings.cocktail.cher.client.*;
|
||||
import com.threerings.cocktail.cher.dobj.*;
|
||||
|
||||
import com.threerings.cocktail.party.Log;
|
||||
import com.threerings.cocktail.party.data.BodyObject;
|
||||
import com.threerings.cocktail.party.util.PartyContext;
|
||||
|
||||
/**
|
||||
* The location manager provides a means by which entities on the client
|
||||
* can request to move from place to place and can be notified if other
|
||||
* entities have caused the client to move to a new place. It also
|
||||
* provides a mechanism for ratifying a request to move to a new place
|
||||
* before actually issuing the request.
|
||||
*/
|
||||
public class LocationManager
|
||||
implements ClientObserver
|
||||
{
|
||||
public LocationManager (Client client)
|
||||
public LocationManager (PartyContext ctx)
|
||||
{
|
||||
// keep this around for later
|
||||
_ctx = ctx;
|
||||
|
||||
// register ourselves as a client observer
|
||||
ctx.getClient().addObserver(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests that this client be moved to the specified place. A
|
||||
* request will be made and when the response is received, the
|
||||
* location observers will be notified of success or failure.
|
||||
*/
|
||||
public void moveTo (int placeId)
|
||||
{
|
||||
// issue a moveTo request
|
||||
LocationService.moveTo(_ctx.getClient(), placeId, this);
|
||||
}
|
||||
|
||||
public void clientDidLogon (Client client)
|
||||
{
|
||||
// get a copy of our body object
|
||||
Subscriber sub = new Subscriber() {
|
||||
public void objectAvailable (DObject object)
|
||||
{
|
||||
gotBodyObject((BodyObject)object);
|
||||
}
|
||||
|
||||
public void requestFailed (int oid, ObjectAccessException cause)
|
||||
{
|
||||
Log.warning("Location manager unable to fetch body " +
|
||||
"object; all has gone horribly wrong" +
|
||||
"[cause=" + cause + "].");
|
||||
}
|
||||
|
||||
public boolean handleEvent (DEvent event, DObject target)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
};
|
||||
int cloid = client.getClientOid();
|
||||
client.getDObjectManager().subscribeToObject(cloid, sub);
|
||||
}
|
||||
|
||||
protected void gotBodyObject (BodyObject clobj)
|
||||
{
|
||||
// check to see if we are already in a location, in which case
|
||||
// we'll want to be going there straight away
|
||||
}
|
||||
|
||||
public void clientFailedToLogon (Client client, Exception cause)
|
||||
{
|
||||
// we're fair weather observers. we do nothing until logon
|
||||
// succeeds
|
||||
}
|
||||
|
||||
public void clientConnectionFailed (Client client, Exception cause)
|
||||
{
|
||||
// nothing doing
|
||||
}
|
||||
|
||||
public boolean clientWillLogoff (Client client)
|
||||
{
|
||||
// we have no objections
|
||||
return true;
|
||||
}
|
||||
|
||||
public void clientDidLogoff (Client client)
|
||||
{
|
||||
// nothing doing
|
||||
}
|
||||
|
||||
/**
|
||||
* Called in response to a successful <code>moveTo</code> request.
|
||||
*/
|
||||
public void handleMoveSucceeded ()
|
||||
{
|
||||
Log.info("Move succeeded.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Called in response to a failed <code>moveTo</code> request.
|
||||
*/
|
||||
public void handleMoveFailed (String reason)
|
||||
{
|
||||
Log.info("Move failed [reason=" + reason + "].");
|
||||
}
|
||||
|
||||
protected PartyContext _ctx;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
//
|
||||
// $Id: LocationService.java,v 1.1 2001/07/23 21:14:27 mdb Exp $
|
||||
|
||||
package com.threerings.cocktail.party.client;
|
||||
|
||||
import com.threerings.cocktail.cher.client.Client;
|
||||
import com.threerings.cocktail.cher.client.InvocationManager;
|
||||
import com.threerings.cocktail.party.Log;
|
||||
|
||||
/**
|
||||
* The location services provide a mechanism by which the client can
|
||||
* request to move from place to place in the server. These services
|
||||
* should not be used directly, but instead should be accessed via the
|
||||
* location manager.
|
||||
*
|
||||
* @see LocationManager
|
||||
*/
|
||||
public class LocationService
|
||||
{
|
||||
/** The module name for the location services. */
|
||||
public static final String MODULE = "location";
|
||||
|
||||
/**
|
||||
* Requests that that this client's body be moved to the specified
|
||||
* location.
|
||||
*/
|
||||
public static void moveTo (Client client, int placeId,
|
||||
LocationManager rsptarget)
|
||||
{
|
||||
InvocationManager invmgr = client.getInvocationManager();
|
||||
Object[] args = new Object[] { new Integer(placeId) };
|
||||
invmgr.invoke(MODULE, "MoveTo", args, rsptarget);
|
||||
Log.info("Sent moveTo request [place=" + placeId + "].");
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,36 @@
|
||||
//
|
||||
// $Id: PlaceObject.dobj,v 1.1 2001/07/20 20:07:37 mdb Exp $
|
||||
// $Id: PlaceObject.dobj,v 1.2 2001/07/23 21:14:27 mdb Exp $
|
||||
|
||||
package com.threerings.cocktail.party.place;
|
||||
package com.threerings.cocktail.party.data;
|
||||
|
||||
import com.threerings.cocktail.cher.dobj.DObject;
|
||||
import com.threerings.cocktail.cher.dobj.*;
|
||||
|
||||
public class PlaceObject extends DObject
|
||||
{
|
||||
/** The field name of the <code>occupants</code> field. */
|
||||
public static final String OCCUPANTS = "occupants";
|
||||
|
||||
/**
|
||||
* Tracks the oid of the body objects of all of the occupants of this
|
||||
* place.
|
||||
*/
|
||||
public OidList occupants;
|
||||
|
||||
/**
|
||||
* Requests that the specified oid be added to the
|
||||
* <code>occupants</code> oid list.
|
||||
*/
|
||||
public void addToOccupants (int oid)
|
||||
{
|
||||
requestOidAdd(OCCUPANTS, oid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests that the specified oid be removed from the
|
||||
* <code>occupants</code> oid list.
|
||||
*/
|
||||
public void removeFromOccupants (int oid)
|
||||
{
|
||||
requestOidRemove(OCCUPANTS, oid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
//
|
||||
// $Id: CrowdServer.java,v 1.1 2001/07/23 21:14:27 mdb Exp $
|
||||
|
||||
package com.threerings.cocktail.party.server;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.threerings.cocktail.cher.server.CherServer;
|
||||
|
||||
import com.threerings.cocktail.party.Log;
|
||||
import com.threerings.cocktail.party.data.BodyObject;
|
||||
|
||||
/**
|
||||
* The party server extends the cher server by configuring it to use the
|
||||
* extensions provided by the party layer to support party services.
|
||||
*/
|
||||
public class PartyServer extends CherServer
|
||||
{
|
||||
/** The namespace used for server config properties. */
|
||||
public static final String CONFIG_KEY = "party";
|
||||
|
||||
/**
|
||||
* Initializes all of the server services and prepares for operation.
|
||||
*/
|
||||
public void init ()
|
||||
throws IOException
|
||||
{
|
||||
// do the cher server initialization
|
||||
super.init();
|
||||
|
||||
// bind the party server config into the namespace
|
||||
config.bindProperties(CONFIG_KEY, CONFIG_PATH);
|
||||
|
||||
// configure the client to use the body object
|
||||
clmgr.setClientObjectClass(BodyObject.class);
|
||||
|
||||
// register our invocation service providers
|
||||
registerProviders(config.getValue(PROVIDERS_KEY, (String[])null));
|
||||
|
||||
Log.info("Party server initialized.");
|
||||
}
|
||||
|
||||
public static void main (String[] args)
|
||||
{
|
||||
PartyServer server = new PartyServer();
|
||||
try {
|
||||
server.init();
|
||||
server.run();
|
||||
} catch (Exception e) {
|
||||
Log.warning("Unable to initialize server.");
|
||||
Log.logStackTrace(e);
|
||||
}
|
||||
}
|
||||
|
||||
// the path to the config file
|
||||
protected final static String CONFIG_PATH =
|
||||
"rsrc/config/cocktail/party/server";
|
||||
|
||||
// the config key for our list of invocation provider mappings
|
||||
protected final static String PROVIDERS_KEY = CONFIG_KEY + ".providers";
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
//
|
||||
// $Id: LocationProvider.java,v 1.1 2001/07/23 21:14:27 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.party.Log;
|
||||
import com.threerings.cocktail.party.data.*;
|
||||
|
||||
/**
|
||||
* This class provides the server end of the location services.
|
||||
*/
|
||||
public class LocationProvider extends InvocationProvider
|
||||
{
|
||||
/**
|
||||
* Processes a request from a client to move to a new place.
|
||||
*/
|
||||
public Object[] handleMoveToRequest (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 + "].");
|
||||
return createResponse("MoveFailed", "m.no_such_place");
|
||||
}
|
||||
|
||||
// add the body object id to the place object's occupant list
|
||||
PlaceObject place = (PlaceObject)pobj;
|
||||
place.addToOccupants(source.getOid());
|
||||
return createResponse("MoveSucceeded");
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// $Id: PlaceManager.java,v 1.1 2001/07/20 20:07:37 mdb Exp $
|
||||
// $Id: PlaceManager.java,v 1.2 2001/07/23 21:14:27 mdb Exp $
|
||||
|
||||
package com.threerings.cocktail.party.place;
|
||||
package com.threerings.cocktail.party.server;
|
||||
|
||||
public class PlaceManager
|
||||
{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: TestClient.java,v 1.1 2001/07/20 23:23:50 mdb Exp $
|
||||
// $Id: TestClient.java,v 1.2 2001/07/23 21:14:27 mdb Exp $
|
||||
|
||||
package com.threerings.cocktail.party.client.test;
|
||||
|
||||
@@ -19,13 +19,13 @@ public class TestClient
|
||||
{
|
||||
public TestClient (Credentials creds)
|
||||
{
|
||||
// create our context
|
||||
_ctx = new PartyContextImpl();
|
||||
|
||||
// create the handles on our various services
|
||||
_config = new Config();
|
||||
_client = new Client(creds, this);
|
||||
_locmgr = new LocationManager(_client);
|
||||
|
||||
// create our context
|
||||
_ctx = new PartyContextImpl();
|
||||
_locmgr = new LocationManager(_ctx);
|
||||
|
||||
// we want to know about logon/logoff
|
||||
_client.addObserver(this);
|
||||
@@ -55,6 +55,9 @@ public class TestClient
|
||||
public void clientDidLogon (Client client)
|
||||
{
|
||||
Log.info("Client did logon [client=" + client + "].");
|
||||
|
||||
// request to move to a place
|
||||
_ctx.getLocationManager().moveTo(15);
|
||||
}
|
||||
|
||||
public void clientFailedToLogon (Client client, Exception cause)
|
||||
|
||||
Reference in New Issue
Block a user