Got cluster chat support working. Made it an invocation service rather

than a place service (which may be changed back when place services
improve or I may change the main chat stuff to be an invocation service).


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@803 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2001-12-16 21:02:18 +00:00
parent 4f716cd540
commit 1c02c2d6f4
6 changed files with 151 additions and 68 deletions
@@ -1,5 +1,5 @@
//
// $Id: SpotCodes.java,v 1.2 2001/12/14 23:12:39 mdb Exp $
// $Id: SpotCodes.java,v 1.3 2001/12/16 21:02:18 mdb Exp $
package com.threerings.whirled.spot.client;
@@ -41,6 +41,6 @@ public interface SpotCodes extends ChatCodes, SceneCodes
* generated by a failed changeLoc request. */
public static final String LOCATION_OCCUPIED = "m.location_occupied";
/** The message identifier for a cluster speak request message. */
public static final String CLUSTER_SPEAK_REQUEST = "cspkreq";
/** The message identifier for a cluster speak request. */
public static final String CLUSTER_SPEAK_REQUEST = "ClusterSpeak";
}
@@ -1,11 +1,18 @@
//
// $Id: SpotSceneDirector.java,v 1.4 2001/12/16 05:18:20 mdb Exp $
// $Id: SpotSceneDirector.java,v 1.5 2001/12/16 21:02:18 mdb Exp $
package com.threerings.whirled.spot.client;
import java.util.Iterator;
import com.samskivert.util.StringUtil;
import com.threerings.presents.dobj.DObject;
import com.threerings.presents.dobj.DObjectManager;
import com.threerings.presents.dobj.ObjectAccessException;
import com.threerings.presents.dobj.Subscriber;
import com.threerings.crowd.chat.ChatDirector;
import com.threerings.whirled.client.SceneDirector;
import com.threerings.whirled.data.SceneModel;
import com.threerings.whirled.util.WhirledContext;
@@ -19,7 +26,7 @@ import com.threerings.whirled.spot.data.Portal;
* locations within a scene.
*/
public class SpotSceneDirector
implements SpotCodes
implements SpotCodes, Subscriber
{
/**
* This is used to communicate back to the caller of {@link
@@ -52,6 +59,15 @@ public class SpotSceneDirector
_scdir = scdir;
}
/**
* Configures this spot scene director with a chat director, with
* which it will coordinate to implement cluster chatting.
*/
public void setChatDirector (ChatDirector chatdir)
{
_chatdir = chatdir;
}
/**
* Requests that this client move to the location specified by the
* supplied portal id. A request will be made and when the response is
@@ -157,21 +173,64 @@ public class SpotSceneDirector
locationId, this);
}
/**
* Sends a chat message to the other users in the cluster to which the
* location that we currently occupy belongs.
*/
public void requestClusterSpeak (String message)
{
// make sure we're currently in a scene
DisplaySpotScene scene = (DisplaySpotScene)_scdir.getScene();
if (scene == null) {
Log.warning("Requested to speak to cluster, but we're not " +
"currently in any scene [message=" + message + "].");
return;
}
// make sure we're in a location
if (_locationId > 0) {
SpotService.clusterSpeak(
_ctx.getClient(), scene.getId(), _locationId, message, this);
} else {
Log.info("Ignoring cluster speak as we're not in a location.");
}
}
/**
* Called in response to a successful <code>changeLoc</code> request.
*/
public void handleChangeLocSucceeded (int invid)
public void handleChangeLocSucceeded (int invid, int clusterOid)
{
ChangeObserver obs = _changeObserver;
int locId = _pendingLocId;
_locationId = _pendingLocId;
// clear out our pending location info
_pendingLocId = -1;
_changeObserver = null;
// determine if our cluster oid changed (which we only care about
// if we're doing cluster chat)
if (_chatdir != null) {
int oldOid = (_clobj == null) ? -1 : _clobj.getOid();
if (clusterOid != oldOid) {
DObjectManager omgr = _ctx.getDObjectManager();
// remove our old subscription if necessary
if (_clobj != null) {
_chatdir.removeAuxilliarySource(_clobj);
// unsubscribe from our old object
omgr.unsubscribeFromObject(_clobj.getOid(), this);
_clobj = null;
}
// create a new subscription (we'll wire it up to the chat
// director when the subscription completes
omgr.subscribeToObject(clusterOid, this);
}
}
// if we had an observer, let them know things went well
if (obs != null) {
obs.locationChangeSucceeded(locId);
obs.locationChangeSucceeded(_locationId);
}
}
@@ -193,16 +252,43 @@ public class SpotSceneDirector
}
}
// documentation inherited
public void objectAvailable (DObject object)
{
// we've got our cluster chat object, configure the chat director
// with it and keep a reference ourselves
if (_chatdir != null) {
_chatdir.addAuxilliarySource(object);
_clobj = object;
}
}
// documentation inherited
public void requestFailed (int oid, ObjectAccessException cause)
{
Log.warning("Unable to subscribe to cluster chat object " +
"[oid=" + oid + ",, cause=" + cause + "].");
}
/** The active client context. */
protected WhirledContext _ctx;
/** The scene director with which we are cooperating. */
protected SceneDirector _scdir;
/** A reference to the chat director with which we coordinate. */
protected ChatDirector _chatdir;
/** The location id of the location we currently occupy. */
protected int _locationId = -1;
/** The location id on which we have an outstanding change location
* request. */
protected int _pendingLocId = -1;
/** The cluster chat object for the cluster we currently occupy. */
protected DObject _clobj;
/** An entity that wants to know if a requested location change
* succeded or failed. */
protected ChangeObserver _changeObserver;
@@ -1,5 +1,5 @@
//
// $Id: SpotService.java,v 1.3 2001/12/16 05:18:20 mdb Exp $
// $Id: SpotService.java,v 1.4 2001/12/16 21:02:18 mdb Exp $
package com.threerings.whirled.spot.client;
@@ -48,4 +48,20 @@ public class SpotService implements SpotCodes
Log.info("Sent changeLoc request [sceneId=" + sceneId +
", locId=" + locationId + "].");
}
/**
* Requests that the supplied message be delivered to listeners in the
* cluster to which the specified location belongs.
*/
public static void clusterSpeak (
Client client, int sceneId, int locationId, String message,
SpotSceneDirector rsptarget)
{
InvocationDirector invdir = client.getInvocationDirector();
Object[] args = new Object[] {
new Integer(sceneId), new Integer(locationId), message };
invdir.invoke(MODULE_NAME, CLUSTER_SPEAK_REQUEST, args, rsptarget);
Log.info("Sent clusterSpeak request [sceneId=" + sceneId +
", locId=" + locationId + ", message=" + message + "].");
}
}