Created a SpotSceneRegistry, have that implement SpotService instead of using a
concrete provider. Other implicit depends removal and cleanup. git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@641 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
@@ -21,225 +21,38 @@
|
|||||||
|
|
||||||
package com.threerings.whirled.spot.server;
|
package com.threerings.whirled.spot.server;
|
||||||
|
|
||||||
import com.samskivert.util.StringUtil;
|
import com.threerings.presents.client.InvocationService;
|
||||||
import com.threerings.crowd.chat.data.ChatCodes;
|
|
||||||
import com.threerings.crowd.chat.data.UserMessage;
|
|
||||||
import com.threerings.crowd.chat.server.SpeakUtil;
|
|
||||||
import com.threerings.crowd.data.BodyObject;
|
|
||||||
import com.threerings.crowd.server.PlaceRegistry;
|
|
||||||
import com.threerings.presents.data.ClientObject;
|
import com.threerings.presents.data.ClientObject;
|
||||||
import com.threerings.presents.data.InvocationMarshaller;
|
|
||||||
import com.threerings.presents.dobj.RootDObjectManager;
|
|
||||||
import com.threerings.presents.server.InvocationException;
|
import com.threerings.presents.server.InvocationException;
|
||||||
import com.threerings.presents.server.InvocationProvider;
|
import com.threerings.presents.server.InvocationProvider;
|
||||||
import com.threerings.util.MessageManager;
|
import com.threerings.whirled.client.SceneService;
|
||||||
import com.threerings.util.Name;
|
|
||||||
import com.threerings.whirled.client.SceneService.SceneMoveListener;
|
|
||||||
import com.threerings.whirled.data.ScenePlace;
|
|
||||||
import com.threerings.whirled.server.SceneRegistry;
|
|
||||||
import com.threerings.whirled.spot.client.SpotService;
|
|
||||||
import com.threerings.whirled.spot.data.Location;
|
import com.threerings.whirled.spot.data.Location;
|
||||||
import com.threerings.whirled.spot.data.Portal;
|
|
||||||
import com.threerings.whirled.spot.data.SpotCodes;
|
|
||||||
import com.threerings.whirled.spot.data.SpotScene;
|
|
||||||
|
|
||||||
import static com.threerings.whirled.spot.Log.log;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides the server-side implementation of the spot services.
|
* Defines the server-side of the {@link SpotService}.
|
||||||
*/
|
*/
|
||||||
public class SpotProvider
|
public interface SpotProvider extends InvocationProvider
|
||||||
implements SpotCodes, InvocationProvider
|
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Creates a spot provider that can be registered with the invocation manager to handle spot
|
* Handles a {@link SpotService#changeLocation} request.
|
||||||
* services.
|
|
||||||
*/
|
*/
|
||||||
public SpotProvider (RootDObjectManager omgr, PlaceRegistry plreg, SceneRegistry screg)
|
public void changeLocation (ClientObject caller, int arg1, Location arg2, InvocationService.ConfirmListener arg3)
|
||||||
{
|
throws InvocationException;
|
||||||
// we'll need these later
|
|
||||||
_plreg = plreg;
|
|
||||||
_screg = screg;
|
|
||||||
_omgr = omgr;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Processes a {@link SpotService#traversePortal} request.
|
* Handles a {@link SpotService#clusterSpeak} request.
|
||||||
*/
|
*/
|
||||||
public void traversePortal (ClientObject caller, int sceneId, int portalId,
|
public void clusterSpeak (ClientObject caller, String arg1, byte arg2);
|
||||||
int destSceneVer, SceneMoveListener listener)
|
|
||||||
throws InvocationException
|
|
||||||
{
|
|
||||||
// le sanity check
|
|
||||||
BodyObject body = (BodyObject)caller;
|
|
||||||
int cSceneId = ScenePlace.getSceneId(body);
|
|
||||||
if (cSceneId != sceneId) {
|
|
||||||
log.info("Ignoring stale traverse portal request [caller=" + caller.who() +
|
|
||||||
", oSceneId=" + sceneId + ", portalId=" + portalId +
|
|
||||||
", cSceneId=" + cSceneId + "].");
|
|
||||||
InvocationMarshaller.setNoResponse(listener);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// obtain the source scene
|
|
||||||
SpotSceneManager srcmgr = (SpotSceneManager)_screg.getSceneManager(sceneId);
|
|
||||||
if (srcmgr == null) {
|
|
||||||
log.warning("Traverse portal missing source scene " +
|
|
||||||
"[user=" + body.who() + ", sceneId=" + sceneId +
|
|
||||||
", portalId=" + portalId + "].");
|
|
||||||
throw new InvocationException(INTERNAL_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
// obtain the destination scene and location id
|
|
||||||
SpotScene rss = (SpotScene)srcmgr.getScene();
|
|
||||||
Portal dest = rss.getPortal(portalId);
|
|
||||||
|
|
||||||
// give the source scene manager a chance to do access control
|
|
||||||
String errmsg = srcmgr.mayTraversePortal(body, dest);
|
|
||||||
if (errmsg != null) {
|
|
||||||
throw new InvocationException(errmsg);
|
|
||||||
}
|
|
||||||
|
|
||||||
// make sure this portal has valid info
|
|
||||||
if (dest == null || !dest.isValid()) {
|
|
||||||
log.warning("Traverse portal with invalid portal [user=" + body.who() +
|
|
||||||
", scene=" + srcmgr.where() + ", pid=" + portalId + ", portal=" + dest +
|
|
||||||
", portals=" + StringUtil.toString(rss.getPortals()) + "].");
|
|
||||||
throw new InvocationException(NO_SUCH_PORTAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
// resolve their destination scene
|
|
||||||
_screg.resolveScene(dest.targetSceneId,
|
|
||||||
new SpotSceneMoveHandler(srcmgr, body, destSceneVer, dest, listener));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Processes a {@link SpotService#changeLocation} request.
|
* Handles a {@link SpotService#joinCluster} request.
|
||||||
*/
|
*/
|
||||||
public void changeLocation (ClientObject caller, int sceneId, Location loc,
|
public void joinCluster (ClientObject caller, int arg1, InvocationService.ConfirmListener arg2)
|
||||||
SpotService.ConfirmListener listener)
|
throws InvocationException;
|
||||||
throws InvocationException
|
|
||||||
{
|
|
||||||
BodyObject source = (BodyObject)caller;
|
|
||||||
int cSceneId = ScenePlace.getSceneId(source);
|
|
||||||
if (cSceneId != sceneId) {
|
|
||||||
log.info("Rejecting changeLocation for invalid scene [user=" + source.who() +
|
|
||||||
", insid=" + cSceneId + ", wantsid=" + sceneId + ", loc=" + loc + "].");
|
|
||||||
throw new InvocationException(INVALID_LOCATION);
|
|
||||||
}
|
|
||||||
|
|
||||||
// look up the scene manager for the specified scene
|
|
||||||
SpotSceneManager smgr = (SpotSceneManager)_screg.getSceneManager(sceneId);
|
|
||||||
if (smgr == null) {
|
|
||||||
log.warning("User requested to change location from non-existent scene " +
|
|
||||||
"[user=" + source.who() + ", sceneId=" + sceneId + ", loc=" + loc +"].");
|
|
||||||
throw new InvocationException(INTERNAL_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
// pass the buck to yon scene manager
|
|
||||||
smgr.handleChangeLoc(source, loc);
|
|
||||||
|
|
||||||
// if that method finished, we're good to go
|
|
||||||
listener.requestProcessed();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Processes a {@link SpotService#joinCluster} request.
|
* Handles a {@link SpotService#traversePortal} request.
|
||||||
*/
|
*/
|
||||||
public void joinCluster (ClientObject caller, int friendOid,
|
public void traversePortal (ClientObject caller, int arg1, int arg2, int arg3, SceneService.SceneMoveListener arg4)
|
||||||
SpotService.ConfirmListener listener)
|
throws InvocationException;
|
||||||
throws InvocationException
|
|
||||||
{
|
|
||||||
BodyObject source = (BodyObject)caller;
|
|
||||||
int sceneId = ScenePlace.getSceneId(source);
|
|
||||||
|
|
||||||
// look up the scene manager for the specified scene
|
|
||||||
SpotSceneManager smgr = (SpotSceneManager)_screg.getSceneManager(sceneId);
|
|
||||||
if (smgr == null) {
|
|
||||||
log.warning("User requested to join cluster from non-existent scene " +
|
|
||||||
"[user=" + source.who() + ", sceneId=" + sceneId +
|
|
||||||
", foid=" + friendOid +"].");
|
|
||||||
throw new InvocationException(INTERNAL_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
// pass the buck to yon scene manager
|
|
||||||
smgr.handleJoinCluster(source, friendOid);
|
|
||||||
|
|
||||||
// if that method finished, we're good to go
|
|
||||||
listener.requestProcessed();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles request to generate a speak message in the specified cluster.
|
|
||||||
*/
|
|
||||||
public void clusterSpeak (ClientObject caller, String message, byte mode)
|
|
||||||
throws InvocationException
|
|
||||||
{
|
|
||||||
// ensure the caller has normal chat access
|
|
||||||
BodyObject source = (BodyObject)caller;
|
|
||||||
String errmsg = source.checkAccess(ChatCodes.CHAT_ACCESS, null);
|
|
||||||
if (errmsg != null) {
|
|
||||||
SpeakUtil.sendFeedback(source, MessageManager.GLOBAL_BUNDLE, errmsg);
|
|
||||||
} else {
|
|
||||||
sendClusterChatMessage(ScenePlace.getSceneId(source), source.getOid(),
|
|
||||||
source.getVisibleName(), null, message, mode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sends a cluster chat notification to the specified location in the specified place object
|
|
||||||
* originating with the specified speaker (the speaker can be a server entity that wishes to
|
|
||||||
* fake a "speak" message, in which case the bundle argument should be non-null and should
|
|
||||||
* contain the id of the bundle to be used to translate the message text) and with the supplied
|
|
||||||
* message content.
|
|
||||||
*
|
|
||||||
* @param sceneId the scene id in which to deliver the chat message.
|
|
||||||
* @param speakerOid the body object id of the speaker (used to verify that they are in the
|
|
||||||
* cluster in question).
|
|
||||||
* @param speaker the username of the user that generated the message (or some special speaker
|
|
||||||
* name for server messages).
|
|
||||||
* @param bundle the bundle identifier that will be used by the client to translate the message
|
|
||||||
* text (or null if the message originated from a real live human who wrote it in their native
|
|
||||||
* tongue).
|
|
||||||
* @param message the text of the chat message.
|
|
||||||
*/
|
|
||||||
public void sendClusterChatMessage (int sceneId, int speakerOid, Name speaker,
|
|
||||||
String bundle, String message, byte mode)
|
|
||||||
{
|
|
||||||
sendClusterChatMessage(sceneId, speakerOid,
|
|
||||||
new UserMessage(speaker, bundle, message, mode));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sends a cluster chat notification to the specified location in the specified place object
|
|
||||||
* originating with the specified speaker.
|
|
||||||
*
|
|
||||||
* @param sceneId the scene id in which to deliver the chat message.
|
|
||||||
* @param speakerOid the body object id of the speaker (used to verify that they are in the
|
|
||||||
* cluster in question).
|
|
||||||
* @param message the message.
|
|
||||||
*/
|
|
||||||
public void sendClusterChatMessage (int sceneId, int speakerOid, UserMessage message)
|
|
||||||
{
|
|
||||||
// look up the scene manager for the specified scene
|
|
||||||
SpotSceneManager smgr = (SpotSceneManager)_screg.getSceneManager(sceneId);
|
|
||||||
if (smgr == null) {
|
|
||||||
log.warning("User requested cluster chat in non-existent scene " +
|
|
||||||
"[user=" + message.speaker + ", sceneId=" + sceneId +
|
|
||||||
", message=" + message + "].");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// pass this request on to the spot scene manager
|
|
||||||
smgr.handleClusterMessageRequest(speakerOid, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The place registry with which we interoperate. */
|
|
||||||
protected PlaceRegistry _plreg;
|
|
||||||
|
|
||||||
/** The scene registry with which we interoperate. */
|
|
||||||
protected SceneRegistry _screg;
|
|
||||||
|
|
||||||
/** The object manager we use to do dobject stuff. */
|
|
||||||
protected RootDObjectManager _omgr;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,9 +32,9 @@ import com.threerings.presents.server.InvocationException;
|
|||||||
|
|
||||||
import com.threerings.crowd.chat.data.UserMessage;
|
import com.threerings.crowd.chat.data.UserMessage;
|
||||||
import com.threerings.crowd.chat.server.SpeakUtil;
|
import com.threerings.crowd.chat.server.SpeakUtil;
|
||||||
|
import com.threerings.crowd.server.PlaceRegistry;
|
||||||
import com.threerings.crowd.data.BodyObject;
|
import com.threerings.crowd.data.BodyObject;
|
||||||
import com.threerings.crowd.data.OccupantInfo;
|
import com.threerings.crowd.data.OccupantInfo;
|
||||||
import com.threerings.crowd.server.CrowdServer;
|
|
||||||
|
|
||||||
import com.threerings.whirled.server.SceneManager;
|
import com.threerings.whirled.server.SceneManager;
|
||||||
|
|
||||||
@@ -60,10 +60,9 @@ public class SpotSceneManager extends SceneManager
|
|||||||
/**
|
/**
|
||||||
* Move the specified body to the default portal, if possible.
|
* Move the specified body to the default portal, if possible.
|
||||||
*/
|
*/
|
||||||
public static void moveBodyToDefaultPortal (BodyObject body)
|
public static void moveBodyToDefaultPortal (PlaceRegistry plreg, BodyObject body)
|
||||||
{
|
{
|
||||||
SpotSceneManager mgr = (SpotSceneManager)
|
SpotSceneManager mgr = (SpotSceneManager)plreg.getPlaceManager(body.getPlaceOid());
|
||||||
CrowdServer.plreg.getPlaceManager(body.getPlaceOid());
|
|
||||||
if (mgr != null) {
|
if (mgr != null) {
|
||||||
mgr.moveToDefaultPortal(body);
|
mgr.moveToDefaultPortal(body);
|
||||||
}
|
}
|
||||||
@@ -313,7 +312,7 @@ public class SpotSceneManager extends SceneManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
// otherwise see if they sent us the user's oid
|
// otherwise see if they sent us the user's oid
|
||||||
DObject tobj = CrowdServer.omgr.getObject(targetOid);
|
DObject tobj = _omgr.getObject(targetOid);
|
||||||
if (!(tobj instanceof BodyObject)) {
|
if (!(tobj instanceof BodyObject)) {
|
||||||
log.info("Can't join cluster, missing target [creator=" + joiner.who() +
|
log.info("Can't join cluster, missing target [creator=" + joiner.who() +
|
||||||
", targetOid=" + targetOid + "].");
|
", targetOid=" + targetOid + "].");
|
||||||
@@ -385,7 +384,7 @@ public class SpotSceneManager extends SceneManager
|
|||||||
*/
|
*/
|
||||||
protected ClusterRecord getCluster (int bodyOid)
|
protected ClusterRecord getCluster (int bodyOid)
|
||||||
{
|
{
|
||||||
BodyObject bobj = (BodyObject)CrowdServer.omgr.getObject(bodyOid);
|
BodyObject bobj = (BodyObject)_omgr.getObject(bodyOid);
|
||||||
if (bobj instanceof ClusteredBodyObject) {
|
if (bobj instanceof ClusteredBodyObject) {
|
||||||
return _clusters.get(((ClusteredBodyObject)bobj).getClusterOid());
|
return _clusters.get(((ClusteredBodyObject)bobj).getClusterOid());
|
||||||
} else {
|
} else {
|
||||||
@@ -457,7 +456,7 @@ public class SpotSceneManager extends SceneManager
|
|||||||
{
|
{
|
||||||
public ClusterRecord ()
|
public ClusterRecord ()
|
||||||
{
|
{
|
||||||
_clobj = CrowdServer.omgr.registerObject(new ClusterObject());
|
_clobj = _omgr.registerObject(new ClusterObject());
|
||||||
_clusters.put(_clobj.getOid(), this);
|
_clusters.put(_clobj.getOid(), this);
|
||||||
|
|
||||||
// let any mapped users know about our cluster
|
// let any mapped users know about our cluster
|
||||||
@@ -579,7 +578,7 @@ public class SpotSceneManager extends SceneManager
|
|||||||
if (doRemoval) {
|
if (doRemoval) {
|
||||||
_clusters.remove(_clobj.getOid());
|
_clusters.remove(_clobj.getOid());
|
||||||
}
|
}
|
||||||
CrowdServer.omgr.destroyObject(_clobj.getOid());
|
_omgr.destroyObject(_clobj.getOid());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ClusterObject _clobj;
|
protected ClusterObject _clobj;
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ package com.threerings.whirled.spot.server;
|
|||||||
import com.threerings.presents.server.InvocationException;
|
import com.threerings.presents.server.InvocationException;
|
||||||
|
|
||||||
import com.threerings.crowd.data.BodyObject;
|
import com.threerings.crowd.data.BodyObject;
|
||||||
|
import com.threerings.crowd.server.LocationManager;
|
||||||
|
|
||||||
import com.threerings.whirled.client.SceneService;
|
import com.threerings.whirled.client.SceneService;
|
||||||
import com.threerings.whirled.server.SceneManager;
|
import com.threerings.whirled.server.SceneManager;
|
||||||
@@ -36,10 +37,10 @@ import com.threerings.whirled.spot.data.Portal;
|
|||||||
*/
|
*/
|
||||||
public class SpotSceneMoveHandler extends SceneMoveHandler
|
public class SpotSceneMoveHandler extends SceneMoveHandler
|
||||||
{
|
{
|
||||||
public SpotSceneMoveHandler (SpotSceneManager srcmgr, BodyObject body, int sceneVer,
|
public SpotSceneMoveHandler (LocationManager locman, SpotSceneManager srcmgr, BodyObject body,
|
||||||
Portal dest, SceneService.SceneMoveListener listener)
|
int sceneVer, Portal dest, SceneService.SceneMoveListener listener)
|
||||||
{
|
{
|
||||||
super(body, sceneVer, listener);
|
super(locman, body, sceneVer, listener);
|
||||||
_srcmgr = srcmgr;
|
_srcmgr = srcmgr;
|
||||||
_dest = dest;
|
_dest = dest;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,234 @@
|
|||||||
|
//
|
||||||
|
// $Id$
|
||||||
|
//
|
||||||
|
// Vilya library - tools for developing networked games
|
||||||
|
// Copyright (C) 2002-2007 Three Rings Design, Inc., All Rights Reserved
|
||||||
|
// http://www.threerings.net/code/vilya/
|
||||||
|
//
|
||||||
|
// This library is free software; you can redistribute it and/or modify it
|
||||||
|
// under the terms of the GNU Lesser General Public License as published
|
||||||
|
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
// Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public
|
||||||
|
// License along with this library; if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
|
package com.threerings.whirled.spot.server;
|
||||||
|
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
import com.google.inject.Singleton;
|
||||||
|
|
||||||
|
import com.threerings.util.MessageManager;
|
||||||
|
import com.threerings.util.Name;
|
||||||
|
|
||||||
|
import com.threerings.presents.data.ClientObject;
|
||||||
|
import com.threerings.presents.data.InvocationMarshaller;
|
||||||
|
import com.threerings.presents.dobj.RootDObjectManager;
|
||||||
|
import com.threerings.presents.server.InvocationException;
|
||||||
|
import com.threerings.presents.server.InvocationManager;
|
||||||
|
import com.threerings.presents.server.InvocationProvider;
|
||||||
|
|
||||||
|
import com.threerings.crowd.chat.data.ChatCodes;
|
||||||
|
import com.threerings.crowd.chat.data.UserMessage;
|
||||||
|
import com.threerings.crowd.chat.server.SpeakUtil;
|
||||||
|
import com.threerings.crowd.data.BodyObject;
|
||||||
|
import com.threerings.crowd.server.PlaceRegistry;
|
||||||
|
|
||||||
|
import com.threerings.whirled.client.SceneService;
|
||||||
|
import com.threerings.whirled.data.SceneCodes;
|
||||||
|
import com.threerings.whirled.data.ScenePlace;
|
||||||
|
import com.threerings.whirled.server.SceneRegistry;
|
||||||
|
|
||||||
|
import com.threerings.whirled.spot.client.SpotService;
|
||||||
|
import com.threerings.whirled.spot.data.Location;
|
||||||
|
import com.threerings.whirled.spot.data.Portal;
|
||||||
|
import com.threerings.whirled.spot.data.SpotCodes;
|
||||||
|
import com.threerings.whirled.spot.data.SpotScene;
|
||||||
|
import com.threerings.whirled.spot.server.SpotDispatcher;
|
||||||
|
|
||||||
|
import static com.threerings.whirled.spot.Log.log;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extends the {@link SceneRegistry} with spot-related services.
|
||||||
|
*/
|
||||||
|
@Singleton
|
||||||
|
public class SpotSceneRegistry extends SceneRegistry
|
||||||
|
implements SpotProvider
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Constructs a spot scene registry.
|
||||||
|
*/
|
||||||
|
@Inject public SpotSceneRegistry (InvocationManager invmgr)
|
||||||
|
{
|
||||||
|
super(invmgr);
|
||||||
|
invmgr.registerDispatcher(new SpotDispatcher(this), SceneCodes.WHIRLED_GROUP);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends a cluster chat notification to the specified location in the specified place object
|
||||||
|
* originating with the specified speaker (the speaker can be a server entity that wishes to
|
||||||
|
* fake a "speak" message, in which case the bundle argument should be non-null and should
|
||||||
|
* contain the id of the bundle to be used to translate the message text) and with the supplied
|
||||||
|
* message content.
|
||||||
|
*
|
||||||
|
* @param sceneId the scene id in which to deliver the chat message.
|
||||||
|
* @param speakerOid the body object id of the speaker (used to verify that they are in the
|
||||||
|
* cluster in question).
|
||||||
|
* @param speaker the username of the user that generated the message (or some special speaker
|
||||||
|
* name for server messages).
|
||||||
|
* @param bundle the bundle identifier that will be used by the client to translate the message
|
||||||
|
* text (or null if the message originated from a real live human who wrote it in their native
|
||||||
|
* tongue).
|
||||||
|
* @param message the text of the chat message.
|
||||||
|
*/
|
||||||
|
public void sendClusterChatMessage (int sceneId, int speakerOid, Name speaker,
|
||||||
|
String bundle, String message, byte mode)
|
||||||
|
{
|
||||||
|
sendClusterChatMessage(sceneId, speakerOid,
|
||||||
|
new UserMessage(speaker, bundle, message, mode));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends a cluster chat notification to the specified location in the specified place object
|
||||||
|
* originating with the specified speaker.
|
||||||
|
*
|
||||||
|
* @param sceneId the scene id in which to deliver the chat message.
|
||||||
|
* @param speakerOid the body object id of the speaker (used to verify that they are in the
|
||||||
|
* cluster in question).
|
||||||
|
* @param message the message.
|
||||||
|
*/
|
||||||
|
public void sendClusterChatMessage (int sceneId, int speakerOid, UserMessage message)
|
||||||
|
{
|
||||||
|
// look up the scene manager for the specified scene
|
||||||
|
SpotSceneManager smgr = (SpotSceneManager)getSceneManager(sceneId);
|
||||||
|
if (smgr == null) {
|
||||||
|
log.warning("User requested cluster chat in non-existent scene " +
|
||||||
|
"[user=" + message.speaker + ", sceneId=" + sceneId +
|
||||||
|
", message=" + message + "].");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// pass this request on to the spot scene manager
|
||||||
|
smgr.handleClusterMessageRequest(speakerOid, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
// from interface SpotProvider
|
||||||
|
public void traversePortal (ClientObject caller, int sceneId, int portalId,
|
||||||
|
int destSceneVer, SceneService.SceneMoveListener listener)
|
||||||
|
throws InvocationException
|
||||||
|
{
|
||||||
|
// le sanity check
|
||||||
|
BodyObject body = (BodyObject)caller;
|
||||||
|
int cSceneId = ScenePlace.getSceneId(body);
|
||||||
|
if (cSceneId != sceneId) {
|
||||||
|
log.info("Ignoring stale traverse portal request [caller=" + caller.who() +
|
||||||
|
", oSceneId=" + sceneId + ", portalId=" + portalId +
|
||||||
|
", cSceneId=" + cSceneId + "].");
|
||||||
|
InvocationMarshaller.setNoResponse(listener);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// obtain the source scene
|
||||||
|
SpotSceneManager srcmgr = (SpotSceneManager)getSceneManager(sceneId);
|
||||||
|
if (srcmgr == null) {
|
||||||
|
log.warning("Traverse portal missing source scene " +
|
||||||
|
"[user=" + body.who() + ", sceneId=" + sceneId +
|
||||||
|
", portalId=" + portalId + "].");
|
||||||
|
throw new InvocationException(SpotCodes.INTERNAL_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
// obtain the destination scene and location id
|
||||||
|
SpotScene rss = (SpotScene)srcmgr.getScene();
|
||||||
|
Portal dest = rss.getPortal(portalId);
|
||||||
|
|
||||||
|
// give the source scene manager a chance to do access control
|
||||||
|
String errmsg = srcmgr.mayTraversePortal(body, dest);
|
||||||
|
if (errmsg != null) {
|
||||||
|
throw new InvocationException(errmsg);
|
||||||
|
}
|
||||||
|
|
||||||
|
// make sure this portal has valid info
|
||||||
|
if (dest == null || !dest.isValid()) {
|
||||||
|
log.warning("Traverse portal with invalid portal", "user", body.who(),
|
||||||
|
"scene", srcmgr.where(), "pid", portalId, "portal", dest,
|
||||||
|
"portals", rss.getPortals());
|
||||||
|
throw new InvocationException(SpotCodes.NO_SUCH_PORTAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
// resolve their destination scene
|
||||||
|
resolveScene(dest.targetSceneId,
|
||||||
|
new SpotSceneMoveHandler(_locman, srcmgr, body, destSceneVer, dest, listener));
|
||||||
|
}
|
||||||
|
|
||||||
|
// from interface SpotProvider
|
||||||
|
public void changeLocation (ClientObject caller, int sceneId, Location loc,
|
||||||
|
SpotService.ConfirmListener listener)
|
||||||
|
throws InvocationException
|
||||||
|
{
|
||||||
|
BodyObject source = (BodyObject)caller;
|
||||||
|
int cSceneId = ScenePlace.getSceneId(source);
|
||||||
|
if (cSceneId != sceneId) {
|
||||||
|
log.info("Rejecting changeLocation for invalid scene [user=" + source.who() +
|
||||||
|
", insid=" + cSceneId + ", wantsid=" + sceneId + ", loc=" + loc + "].");
|
||||||
|
throw new InvocationException(SpotCodes.INVALID_LOCATION);
|
||||||
|
}
|
||||||
|
|
||||||
|
// look up the scene manager for the specified scene
|
||||||
|
SpotSceneManager smgr = (SpotSceneManager)getSceneManager(sceneId);
|
||||||
|
if (smgr == null) {
|
||||||
|
log.warning("User requested to change location from non-existent scene " +
|
||||||
|
"[user=" + source.who() + ", sceneId=" + sceneId + ", loc=" + loc +"].");
|
||||||
|
throw new InvocationException(SpotCodes.INTERNAL_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
// pass the buck to yon scene manager
|
||||||
|
smgr.handleChangeLoc(source, loc);
|
||||||
|
|
||||||
|
// if that method finished, we're good to go
|
||||||
|
listener.requestProcessed();
|
||||||
|
}
|
||||||
|
|
||||||
|
// from interface SpotProvider
|
||||||
|
public void joinCluster (ClientObject caller, int friendOid,
|
||||||
|
SpotService.ConfirmListener listener)
|
||||||
|
throws InvocationException
|
||||||
|
{
|
||||||
|
BodyObject source = (BodyObject)caller;
|
||||||
|
int sceneId = ScenePlace.getSceneId(source);
|
||||||
|
|
||||||
|
// look up the scene manager for the specified scene
|
||||||
|
SpotSceneManager smgr = (SpotSceneManager)getSceneManager(sceneId);
|
||||||
|
if (smgr == null) {
|
||||||
|
log.warning("User requested to join cluster from non-existent scene " +
|
||||||
|
"[user=" + source.who() + ", sceneId=" + sceneId +
|
||||||
|
", foid=" + friendOid +"].");
|
||||||
|
throw new InvocationException(SpotCodes.INTERNAL_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
// pass the buck to yon scene manager
|
||||||
|
smgr.handleJoinCluster(source, friendOid);
|
||||||
|
|
||||||
|
// if that method finished, we're good to go
|
||||||
|
listener.requestProcessed();
|
||||||
|
}
|
||||||
|
|
||||||
|
// from interface SpotProvider
|
||||||
|
public void clusterSpeak (ClientObject caller, String message, byte mode)
|
||||||
|
{
|
||||||
|
// ensure the caller has normal chat access
|
||||||
|
BodyObject source = (BodyObject)caller;
|
||||||
|
String errmsg = source.checkAccess(ChatCodes.CHAT_ACCESS, null);
|
||||||
|
if (errmsg != null) {
|
||||||
|
SpeakUtil.sendFeedback(source, MessageManager.GLOBAL_BUNDLE, errmsg);
|
||||||
|
} else {
|
||||||
|
sendClusterChatMessage(ScenePlace.getSceneId(source), source.getOid(),
|
||||||
|
source.getVisibleName(), null, message, mode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user