If we're going to do this, I guess we're going to do it properly. Nixed the
notion of a global group (though we implicitly define one in InvocationCodes) added a mechanism for directors (which generally handle the client side of invocation services) to register their interest in bootstrap service groups so that the whole goddamned complex business can happen magically behind the scenes. If you instantiate a director, it will automatically register interest in the service group it needs and everything will work. If you don't use the director code, you don't get the services and you can safely exclude all of that code from your client even though the services are still in use on the server (and presumably used by some other types of clients). This is going to break all the builds, which I'll soon fix. Then I'll go write all this in ActionScript. Yay! git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4552 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -52,6 +52,7 @@ import com.threerings.util.TimeUtil;
|
||||
import com.threerings.crowd.Log;
|
||||
import com.threerings.crowd.client.LocationObserver;
|
||||
import com.threerings.crowd.data.BodyObject;
|
||||
import com.threerings.crowd.data.CrowdCodes;
|
||||
import com.threerings.crowd.data.PlaceObject;
|
||||
import com.threerings.crowd.util.CrowdContext;
|
||||
|
||||
@@ -1002,7 +1003,13 @@ public class ChatDirector extends BasicDirector
|
||||
return (type == null) ? PLACE_CHAT_TYPE : type;
|
||||
}
|
||||
|
||||
// documentation inherited from interface
|
||||
@Override // from BasicDirector
|
||||
protected void registerServices (Client client)
|
||||
{
|
||||
client.addServiceGroup(CrowdCodes.CROWD_GROUP);
|
||||
}
|
||||
|
||||
@Override // from BasicDirector
|
||||
protected void fetchServices (Client client)
|
||||
{
|
||||
// get a handle on our chat service
|
||||
|
||||
@@ -33,19 +33,19 @@ import com.threerings.crowd.chat.client.SpeakService;
|
||||
*/
|
||||
public interface ChatCodes extends InvocationCodes
|
||||
{
|
||||
/** A return value used by the ChatDirector and possibly other entities
|
||||
* to indicate successful processing of chat. */
|
||||
/** A return value used by the ChatDirector and possibly other entities to indicate successful
|
||||
* processing of chat. */
|
||||
public static final String SUCCESS = "success";
|
||||
|
||||
/** The message identifier for a chat notification message. */
|
||||
public static final String CHAT_NOTIFICATION = "chat";
|
||||
|
||||
/** The access control identifier for normal chat privileges. See
|
||||
* {@link BodyObject#checkAccess}. */
|
||||
/** The access control identifier for normal chat privileges. See {@link
|
||||
* BodyObject#checkAccess}. */
|
||||
public static final String CHAT_ACCESS = "crowd.chat.chat";
|
||||
|
||||
/** The access control identifier for broadcast chat privileges. See
|
||||
* {@link BodyObject#checkAccess}. */
|
||||
/** The access control identifier for broadcast chat privileges. See {@link
|
||||
* BodyObject#checkAccess}. */
|
||||
public static final String BROADCAST_ACCESS = "crowd.chat.broadcast";
|
||||
|
||||
/** The configuration key for idle time. */
|
||||
@@ -54,10 +54,9 @@ public interface ChatCodes extends InvocationCodes
|
||||
/** The default time after which a player is assumed idle. */
|
||||
public static final long DEFAULT_IDLE_TIME = 3 * 60 * 1000L;
|
||||
|
||||
/** The chat localtype code for chat messages delivered on the place
|
||||
* object currently occupied by the client. This is the only type of
|
||||
* chat message that will be delivered unless the chat director is
|
||||
* explicitly provided with other chat message sources via {@link
|
||||
/** The chat localtype code for chat messages delivered on the place object currently occupied
|
||||
* by the client. This is the only type of chat message that will be delivered unless the chat
|
||||
* director is explicitly provided with other chat message sources via {@link
|
||||
* ChatDirector#addAuxiliarySource}. */
|
||||
public static final String PLACE_CHAT_TYPE = "placeChat";
|
||||
|
||||
@@ -67,21 +66,18 @@ public interface ChatCodes extends InvocationCodes
|
||||
/** The default mode used by {@link SpeakService#speak} requests. */
|
||||
public static final byte DEFAULT_MODE = 0;
|
||||
|
||||
/** A {@link SpeakService#speak} mode to indicate that the user is
|
||||
* thinking what they're saying, or is it that they're saying what
|
||||
* they're thinking? */
|
||||
/** A {@link SpeakService#speak} mode to indicate that the user is thinking what they're
|
||||
* saying, or is it that they're saying what they're thinking? */
|
||||
public static final byte THINK_MODE = 1;
|
||||
|
||||
/** A {@link SpeakService#speak} mode to indicate that a speak is
|
||||
* actually an emote. */
|
||||
/** A {@link SpeakService#speak} mode to indicate that a speak is actually an emote. */
|
||||
public static final byte EMOTE_MODE = 2;
|
||||
|
||||
/** A {@link SpeakService#speak} mode to indicate that a speak is
|
||||
* actually a shout. */
|
||||
/** A {@link SpeakService#speak} mode to indicate that a speak is actually a shout. */
|
||||
public static final byte SHOUT_MODE = 3;
|
||||
|
||||
/** A {@link SpeakService#speak} mode to indicate that a speak is
|
||||
* actually a server-wide broadcast. */
|
||||
/** A {@link SpeakService#speak} mode to indicate that a speak is actually a server-wide
|
||||
* broadcast. */
|
||||
public static final byte BROADCAST_MODE = 4;
|
||||
|
||||
/** String translations for the various chat modes. */
|
||||
@@ -89,11 +85,9 @@ public interface ChatCodes extends InvocationCodes
|
||||
"default", "think", "emote", "shout", "broadcast"
|
||||
};
|
||||
|
||||
/** An error code delivered when the user targeted for a tell
|
||||
* notification is not online. */
|
||||
/** An error code delivered when the user targeted for a tell notification is not online. */
|
||||
public static final String USER_NOT_ONLINE = "m.user_not_online";
|
||||
|
||||
/** An error code delivered when the user targeted for a tell
|
||||
* notification is disconnected. */
|
||||
/** An error code delivered when the user targeted for a tell notification is disconnected. */
|
||||
public static final String USER_DISCONNECTED = "m.user_disconnected";
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ import com.threerings.presents.server.InvocationManager;
|
||||
import com.threerings.presents.server.InvocationProvider;
|
||||
|
||||
import com.threerings.crowd.data.BodyObject;
|
||||
import com.threerings.crowd.data.CrowdCodes;
|
||||
import com.threerings.crowd.data.OccupantInfo;
|
||||
import com.threerings.crowd.data.PlaceObject;
|
||||
import com.threerings.crowd.server.CrowdServer;
|
||||
@@ -58,32 +59,29 @@ public class ChatProvider
|
||||
public static interface TellAutoResponder
|
||||
{
|
||||
/**
|
||||
* Called following the delivery of <code>message</code> from
|
||||
* <code>teller</code> to <code>tellee</code>.
|
||||
* Called following the delivery of <code>message</code> from <code>teller</code> to
|
||||
* <code>tellee</code>.
|
||||
*/
|
||||
public void sentTell (BodyObject teller, BodyObject tellee,
|
||||
String message);
|
||||
public void sentTell (BodyObject teller, BodyObject tellee, String message);
|
||||
}
|
||||
|
||||
/** Used to forward tells between servers in a multi-server setup. */
|
||||
public static interface TellForwarder
|
||||
{
|
||||
/**
|
||||
* Requests that the supplied tell message be delivered to the
|
||||
* appropriate destination.
|
||||
* Requests that the supplied tell message be delivered to the appropriate destination.
|
||||
*
|
||||
* @return true if the tell was delivered, false otherwise.
|
||||
*/
|
||||
public boolean forwardTell (UserMessage message, Name target,
|
||||
TellListener listener);
|
||||
public boolean forwardTell (UserMessage message, Name target, TellListener listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an object to which all broadcasts should be sent, rather
|
||||
* than iterating over the place objects and sending to each of them.
|
||||
* Set an object to which all broadcasts should be sent, rather than iterating over the place
|
||||
* objects and sending to each of them.
|
||||
*
|
||||
* @param object an object to send all broadcasts, or null to send to
|
||||
* each place object instead.
|
||||
* @param object an object to send all broadcasts, or null to send to each place object
|
||||
* instead.
|
||||
*/
|
||||
public void setAlternateBroadcastObject (DObject object)
|
||||
{
|
||||
@@ -91,11 +89,10 @@ public class ChatProvider
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the auto tell responder for the chat provider. Only one auto
|
||||
* responder is allowed. <em>Note:</em> this only works for same-server
|
||||
* tells. If the tell is forwarded to another server, no auto-response
|
||||
* opportunity is provided (because we never have both body objects in the
|
||||
* same place).
|
||||
* Set the auto tell responder for the chat provider. Only one auto responder is allowed.
|
||||
* <em>Note:</em> this only works for same-server tells. If the tell is forwarded to another
|
||||
* server, no auto-response opportunity is provided (because we never have both body objects in
|
||||
* the same place).
|
||||
*/
|
||||
public void setTellAutoResponder (TellAutoResponder autoRespond)
|
||||
{
|
||||
@@ -103,9 +100,8 @@ public class ChatProvider
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the tell forwarded for the chat provider. This is used by the
|
||||
* Crowd peer services to forward tells between servers in a multi-server
|
||||
* cluster.
|
||||
* Configures the tell forwarded for the chat provider. This is used by the Crowd peer services
|
||||
* to forward tells between servers in a multi-server cluster.
|
||||
*/
|
||||
public void setTellForwarder (TellForwarder forwarder)
|
||||
{
|
||||
@@ -113,21 +109,18 @@ public class ChatProvider
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the chat services and registers a chat provider with
|
||||
* the invocation manager.
|
||||
* Initializes the chat services and registers a chat provider with the invocation manager.
|
||||
*/
|
||||
public void init (InvocationManager invmgr, DObjectManager omgr)
|
||||
{
|
||||
// register a chat provider with the invocation manager
|
||||
invmgr.registerDispatcher(new ChatDispatcher(this), true);
|
||||
invmgr.registerDispatcher(new ChatDispatcher(this), CrowdCodes.CROWD_GROUP);
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes a request from a client to deliver a tell message to
|
||||
* another client.
|
||||
* Processes a request from a client to deliver a tell message to another client.
|
||||
*/
|
||||
public void tell (ClientObject caller, Name target, String message,
|
||||
TellListener listener)
|
||||
public void tell (ClientObject caller, Name target, String message, TellListener listener)
|
||||
throws InvocationException
|
||||
{
|
||||
// ensure that the caller has normal chat privileges
|
||||
@@ -142,8 +135,7 @@ public class ChatProvider
|
||||
|
||||
// inform the auto-responder if needed
|
||||
BodyObject targobj;
|
||||
if (_autoRespond != null &&
|
||||
(targobj = CrowdServer.lookupBody(target)) != null) {
|
||||
if (_autoRespond != null && (targobj = CrowdServer.lookupBody(target)) != null) {
|
||||
_autoRespond.sentTell(source, targobj, message);
|
||||
}
|
||||
}
|
||||
@@ -151,8 +143,7 @@ public class ChatProvider
|
||||
/**
|
||||
* Processes a {@link ChatService#broadcast} request.
|
||||
*/
|
||||
public void broadcast (ClientObject caller, String message,
|
||||
InvocationListener listener)
|
||||
public void broadcast (ClientObject caller, String message, InvocationListener listener)
|
||||
throws InvocationException
|
||||
{
|
||||
// make sure the requesting user has broadcast privileges
|
||||
@@ -170,20 +161,19 @@ public class ChatProvider
|
||||
public void away (ClientObject caller, String message)
|
||||
{
|
||||
BodyObject body = (BodyObject)caller;
|
||||
// we modify this field via an invocation service request because
|
||||
// a body object is not modifiable by the client
|
||||
// we modify this field via an invocation service request because a body object is not
|
||||
// modifiable by the client
|
||||
body.setAwayMessage(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Broadcast the specified message to all places in the game.
|
||||
*
|
||||
* @param from the user the broadcast is from, or null to send the message
|
||||
* as a system message.
|
||||
* @param from the user the broadcast is from, or null to send the message as a system message.
|
||||
* @param bundle the bundle, or null if the message needs no translation.
|
||||
* @param msg the content of the message to broadcast.
|
||||
* @param attention if true, the message is sent as ATTENTION level,
|
||||
* otherwise as INFO. Ignored if from is non-null.
|
||||
* @param attention if true, the message is sent as ATTENTION level, otherwise as INFO. Ignored
|
||||
* if from is non-null.
|
||||
*/
|
||||
public void broadcast (Name from, String bundle, String msg,
|
||||
boolean attention)
|
||||
@@ -203,12 +193,10 @@ public class ChatProvider
|
||||
}
|
||||
|
||||
/**
|
||||
* Delivers a tell message to the specified target and notifies the
|
||||
* supplied listener of the result. It is assumed that the teller has
|
||||
* already been permissions checked.
|
||||
* Delivers a tell message to the specified target and notifies the supplied listener of the
|
||||
* result. It is assumed that the teller has already been permissions checked.
|
||||
*/
|
||||
public void deliverTell (UserMessage message, Name target,
|
||||
TellListener listener)
|
||||
public void deliverTell (UserMessage message, Name target, TellListener listener)
|
||||
throws InvocationException
|
||||
{
|
||||
// make sure the target user is online
|
||||
@@ -225,8 +213,7 @@ public class ChatProvider
|
||||
if (tobj.status == OccupantInfo.DISCONNECTED) {
|
||||
String errmsg = MessageBundle.compose(
|
||||
USER_DISCONNECTED, TimeUtil.getTimeOrderString(
|
||||
System.currentTimeMillis() - tobj.statusTime,
|
||||
TimeUtil.SECOND));
|
||||
System.currentTimeMillis() - tobj.statusTime, TimeUtil.SECOND));
|
||||
throw new InvocationException(errmsg);
|
||||
}
|
||||
|
||||
@@ -246,9 +233,9 @@ public class ChatProvider
|
||||
}
|
||||
|
||||
/**
|
||||
* Delivers a tell notification to the specified target player. It is
|
||||
* assumed that the message is coming from some server entity and need not
|
||||
* be permissions checked or notified of the result.
|
||||
* Delivers a tell notification to the specified target player. It is assumed that the message
|
||||
* is coming from some server entity and need not be permissions checked or notified of the
|
||||
* result.
|
||||
*/
|
||||
public void deliverTell (BodyObject target, UserMessage message)
|
||||
{
|
||||
@@ -269,8 +256,8 @@ public class ChatProvider
|
||||
/**
|
||||
* Direct a broadcast to the specified object.
|
||||
*/
|
||||
protected void broadcastTo (DObject object, Name from, String bundle,
|
||||
String msg, boolean attention)
|
||||
protected void broadcastTo (DObject object, Name from, String bundle, String msg,
|
||||
boolean attention)
|
||||
{
|
||||
if (from == null) {
|
||||
if (attention) {
|
||||
@@ -280,8 +267,7 @@ public class ChatProvider
|
||||
}
|
||||
|
||||
} else {
|
||||
SpeakProvider.sendSpeak(object, from, bundle, msg,
|
||||
BROADCAST_MODE);
|
||||
SpeakProvider.sendSpeak(object, from, bundle, msg, BROADCAST_MODE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ import com.threerings.presents.dobj.Subscriber;
|
||||
|
||||
import com.threerings.crowd.Log;
|
||||
import com.threerings.crowd.data.BodyObject;
|
||||
import com.threerings.crowd.data.CrowdCodes;
|
||||
import com.threerings.crowd.data.LocationCodes;
|
||||
import com.threerings.crowd.data.PlaceConfig;
|
||||
import com.threerings.crowd.data.PlaceObject;
|
||||
@@ -416,12 +417,17 @@ public class LocationDirector extends BasicDirector
|
||||
_lservice = null;
|
||||
}
|
||||
|
||||
@Override // from BasicDirector
|
||||
protected void registerServices (Client client)
|
||||
{
|
||||
client.addServiceGroup(CrowdCodes.CROWD_GROUP);
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
protected void fetchServices (Client client)
|
||||
{
|
||||
// obtain our service handle
|
||||
_lservice = (LocationService)
|
||||
client.requireService(LocationService.class);
|
||||
_lservice = (LocationService)client.requireService(LocationService.class);
|
||||
}
|
||||
|
||||
protected void gotBodyObject (BodyObject clobj)
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2006 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://www.threerings.net/code/narya/
|
||||
//
|
||||
// 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.crowd.data;
|
||||
|
||||
import com.threerings.presents.data.InvocationCodes;
|
||||
|
||||
/**
|
||||
* Codes and constants global to the Crowd services.
|
||||
*/
|
||||
public interface CrowdCodes extends InvocationCodes
|
||||
{
|
||||
/** Defines our invocation services group. */
|
||||
public static final String CROWD_GROUP = "crowd";
|
||||
}
|
||||
@@ -99,8 +99,7 @@ public class CrowdPeerManager extends PeerManager
|
||||
|
||||
// unregister our invocation service
|
||||
if (_nodeobj != null) {
|
||||
CrowdServer.invmgr.clearDispatcher(
|
||||
((CrowdNodeObject)_nodeobj).crowdPeerService);
|
||||
CrowdServer.invmgr.clearDispatcher(((CrowdNodeObject)_nodeobj).crowdPeerService);
|
||||
}
|
||||
|
||||
// clear our tell forwarder registration
|
||||
@@ -136,7 +135,7 @@ public class CrowdPeerManager extends PeerManager
|
||||
CrowdNodeObject cnobj = (CrowdNodeObject)_nodeobj;
|
||||
cnobj.setCrowdPeerService(
|
||||
(CrowdPeerMarshaller)CrowdServer.invmgr.registerDispatcher(
|
||||
new CrowdPeerDispatcher(this), false));
|
||||
new CrowdPeerDispatcher(this)));
|
||||
|
||||
// register ourselves as a tell forwarder
|
||||
CrowdServer.chatprov.setTellForwarder(this);
|
||||
|
||||
@@ -28,6 +28,7 @@ import com.threerings.presents.server.InvocationProvider;
|
||||
|
||||
import com.threerings.crowd.Log;
|
||||
import com.threerings.crowd.data.BodyObject;
|
||||
import com.threerings.crowd.data.CrowdCodes;
|
||||
import com.threerings.crowd.data.OccupantInfo;
|
||||
|
||||
/**
|
||||
@@ -54,7 +55,7 @@ public class BodyProvider
|
||||
public static void init (InvocationManager invmgr)
|
||||
{
|
||||
// register a provider instance
|
||||
invmgr.registerDispatcher(new BodyDispatcher(new BodyProvider()), true);
|
||||
invmgr.registerDispatcher(new BodyDispatcher(new BodyProvider()), CrowdCodes.CROWD_GROUP);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -59,35 +59,28 @@ import com.threerings.crowd.chat.server.SpeakDispatcher;
|
||||
import com.threerings.crowd.chat.server.SpeakProvider;
|
||||
|
||||
/**
|
||||
* The place manager is the server-side entity that handles all
|
||||
* place-related interaction. It subscribes to the place object and reacts
|
||||
* to message and other events. Behavior specific to a place (or class of
|
||||
* places) should live in the place manager. An intelligently constructed
|
||||
* hierarchy of place manager classes working in concert with invocation
|
||||
* services should provide the majority of the server-side functionality
|
||||
* of an application built on the Presents platform.
|
||||
* The place manager is the server-side entity that handles all place-related interaction. It
|
||||
* subscribes to the place object and reacts to message and other events. Behavior specific to a
|
||||
* place (or class of places) should live in the place manager. An intelligently constructed
|
||||
* hierarchy of place manager classes working in concert with invocation services should provide
|
||||
* the majority of the server-side functionality of an application built on the Presents platform.
|
||||
*
|
||||
* <p> The base place manager class takes care of the necessary
|
||||
* interactions with the place registry to manage place registration. It
|
||||
* handles the place-related component of chatting. It also provides the
|
||||
* basis for place-based access control.
|
||||
* <p> The base place manager class takes care of the necessary interactions with the place
|
||||
* registry to manage place registration. It handles the place-related component of chatting. It
|
||||
* also provides the basis for place-based access control.
|
||||
*
|
||||
* <p> A derived class is expected to handle initialization, cleanup and
|
||||
* operational functionality via the calldown functions {@link #didInit},
|
||||
* {@link #didStartup}, and {@link #didShutdown} as well as through event
|
||||
* listeners.
|
||||
* <p> A derived class is expected to handle initialization, cleanup and operational functionality
|
||||
* via the calldown functions {@link #didInit}, {@link #didStartup}, and {@link #didShutdown} as
|
||||
* well as through event listeners.
|
||||
*/
|
||||
public class PlaceManager
|
||||
implements MessageListener, OidListListener, ObjectDeathListener,
|
||||
SpeakProvider.SpeakerValidator
|
||||
implements MessageListener, OidListListener, ObjectDeathListener, SpeakProvider.SpeakerValidator
|
||||
{
|
||||
/**
|
||||
* An interface used to allow the registration of standard message handlers
|
||||
* to be invoked by the place manager when particular types of message
|
||||
* events are received.
|
||||
* An interface used to allow the registration of standard message handlers to be invoked by
|
||||
* the place manager when particular types of message events are received.
|
||||
*
|
||||
* @deprecated Use dynamically bound methods instead. See {@link
|
||||
* DynamicListener}.
|
||||
* @deprecated Use dynamically bound methods instead. See {@link DynamicListener}.
|
||||
*/
|
||||
@Deprecated
|
||||
public static interface MessageHandler
|
||||
@@ -96,8 +89,7 @@ public class PlaceManager
|
||||
* Invokes this message handler on the supplied event.
|
||||
*
|
||||
* @param event the message event received.
|
||||
* @param pmgr the place manager for which the message is being
|
||||
* handled.
|
||||
* @param pmgr the place manager for which the message is being handled.
|
||||
*/
|
||||
public void handleEvent (MessageEvent event, PlaceManager pmgr);
|
||||
}
|
||||
@@ -119,9 +111,8 @@ public class PlaceManager
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the occupant info record for the user with the specified
|
||||
* body oid, if they are an occupant of this room. Returns null
|
||||
* otherwise.
|
||||
* Returns the occupant info record for the user with the specified body oid, if they are an
|
||||
* occupant of this room. Returns null otherwise.
|
||||
*/
|
||||
public OccupantInfo getOccupantInfo (int bodyOid)
|
||||
{
|
||||
@@ -129,8 +120,7 @@ public class PlaceManager
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the supplied occupant operation to each occupant currently
|
||||
* present in this place.
|
||||
* Applies the supplied occupant operation to each occupant currently present in this place.
|
||||
*/
|
||||
public void applyToOccupants (OccupantOp op)
|
||||
{
|
||||
@@ -143,11 +133,10 @@ public class PlaceManager
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the occupant info for this room occupant. <em>Note:</em>
|
||||
* This must be used rather than setting the occupant info directly to
|
||||
* avoid possible complications due to rapid fire changes to a user's
|
||||
* occupant info. The occupant info record supplied to this method
|
||||
* must be one returned from {@link #getOccupantInfo}. For example:
|
||||
* Updates the occupant info for this room occupant. <em>Note:</em> This must be used rather
|
||||
* than setting the occupant info directly to avoid possible complications due to rapid fire
|
||||
* changes to a user's occupant info. The occupant info record supplied to this method must be
|
||||
* one returned from {@link #getOccupantInfo}. For example:
|
||||
*
|
||||
* <pre>
|
||||
* OccupantInfo info = _plmgr.getOccupantInfo(bodyOid);
|
||||
@@ -159,17 +148,16 @@ public class PlaceManager
|
||||
{
|
||||
// update the canonical copy
|
||||
_occInfo.put(occInfo.getBodyOid(), occInfo);
|
||||
// clone the canonical copy and send out an event updating the
|
||||
// distributed set with that clone
|
||||
// clone the canonical copy and send out an event updating the distributed set with that
|
||||
// clone
|
||||
_plobj.updateOccupantInfo((OccupantInfo)occInfo.clone());
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the place registry after creating this place manager.
|
||||
*/
|
||||
public void init (
|
||||
PlaceRegistry registry, InvocationManager invmgr,
|
||||
DObjectManager omgr, PlaceConfig config)
|
||||
public void init (PlaceRegistry registry, InvocationManager invmgr,
|
||||
DObjectManager omgr, PlaceConfig config)
|
||||
{
|
||||
_registry = registry;
|
||||
_invmgr = invmgr;
|
||||
@@ -181,11 +169,10 @@ public class PlaceManager
|
||||
}
|
||||
|
||||
/**
|
||||
* Called after this place manager has been initialized with its
|
||||
* configuration information but before it has been started up with
|
||||
* its place object reference. Derived classes can override this
|
||||
* function and perform any basic initialization that they desire.
|
||||
* They should of course be sure to call <code>super.didInit()</code>.
|
||||
* Called after this place manager has been initialized with its configuration information but
|
||||
* before it has been started up with its place object reference. Derived classes can override
|
||||
* this function and perform any basic initialization that they desire. They should of course
|
||||
* be sure to call <code>super.didInit()</code>.
|
||||
*/
|
||||
protected void didInit ()
|
||||
{
|
||||
@@ -209,14 +196,12 @@ public class PlaceManager
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides an opportunity for place managers to ratify the creation
|
||||
* of a place based on whatever criterion they may require (based on
|
||||
* information available to the manager at this post-init() but
|
||||
* pre-startup() phase of initialization).
|
||||
* Provides an opportunity for place managers to ratify the creation of a place based on
|
||||
* whatever criterion they may require (based on information available to the manager at this
|
||||
* post-init() but pre-startup() phase of initialization).
|
||||
*
|
||||
* @return If a permissions check is to fail, the manager should
|
||||
* return a translatable string explaining the failure.
|
||||
* <code>null</code> should be returned if initialization is to be
|
||||
* @return If a permissions check is to fail, the manager should return a translatable string
|
||||
* explaining the failure. <code>null</code> should be returned if initialization is to be
|
||||
* allowed to proceed.
|
||||
*/
|
||||
public String checkPermissions ()
|
||||
@@ -225,19 +210,18 @@ public class PlaceManager
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the place manager after the place object has been
|
||||
* successfully created.
|
||||
* Called by the place manager after the place object has been successfully created.
|
||||
*/
|
||||
public void startup (PlaceObject plobj)
|
||||
{
|
||||
// keep track of this
|
||||
_plobj = plobj;
|
||||
|
||||
// we usually want to create and register a speaker service instance
|
||||
// that clients can use to speak in this place
|
||||
// we usually want to create and register a speaker service instance that clients can use
|
||||
// to speak in this place
|
||||
if (shouldCreateSpeakService()) {
|
||||
plobj.setSpeakService((SpeakMarshaller) _invmgr.registerDispatcher(
|
||||
new SpeakDispatcher(new SpeakProvider(plobj, this)), false));
|
||||
plobj.setSpeakService((SpeakMarshaller)_invmgr.registerDispatcher(
|
||||
new SpeakDispatcher(new SpeakProvider(plobj, this))));
|
||||
}
|
||||
|
||||
// we'll need to hear about place object events
|
||||
@@ -255,8 +239,8 @@ public class PlaceManager
|
||||
}
|
||||
|
||||
/**
|
||||
* Causes the place object being managed by this place manager to be
|
||||
* destroyed and the place manager to shut down.
|
||||
* Causes the place object being managed by this place manager to be destroyed and the place
|
||||
* manager to shut down.
|
||||
*/
|
||||
public void shutdown ()
|
||||
{
|
||||
@@ -273,12 +257,10 @@ public class PlaceManager
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides an opportunity for the place manager to prevent bodies from
|
||||
* entering.
|
||||
* Provides an opportunity for the place manager to prevent bodies from entering.
|
||||
*
|
||||
* @return <code>null</code> if the body can enter, otherwise a
|
||||
* translatable message explaining the reason the body is blocked
|
||||
* from entering
|
||||
* @return <code>null</code> if the body can enter, otherwise a translatable message explaining
|
||||
* the reason the body is blocked from entering
|
||||
*/
|
||||
public String ratifyBodyEntry (BodyObject body)
|
||||
{
|
||||
@@ -286,12 +268,11 @@ public class PlaceManager
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds an {@link OccupantInfo} record for the specified body object and
|
||||
* inserts it into our place object. This is called by the location
|
||||
* services when a body enters a place. If a derived class wishes to
|
||||
* perform custom actions when an occupant is being inserted into a room,
|
||||
* they should override {@link #insertOccupantInfo}, if they want to react
|
||||
* to a body having entered, they should override {@link #bodyEntered}.
|
||||
* Builds an {@link OccupantInfo} record for the specified body object and inserts it into our
|
||||
* place object. This is called by the location services when a body enters a place. If a
|
||||
* derived class wishes to perform custom actions when an occupant is being inserted into a
|
||||
* room, they should override {@link #insertOccupantInfo}, if they want to react to a body
|
||||
* having entered, they should override {@link #bodyEntered}.
|
||||
*/
|
||||
public OccupantInfo buildOccupantInfo (BodyObject body)
|
||||
{
|
||||
@@ -299,8 +280,8 @@ public class PlaceManager
|
||||
// create a new occupant info instance
|
||||
OccupantInfo info = body.createOccupantInfo(_plobj);
|
||||
|
||||
// insert the occupant info into our canonical table; this is done
|
||||
// in a method so that derived classes
|
||||
// insert the occupant info into our canonical table; this is done in a method so that
|
||||
// derived classes
|
||||
insertOccupantInfo(info, body);
|
||||
|
||||
// clone the canonical copy and insert it into the DSet
|
||||
@@ -309,23 +290,21 @@ public class PlaceManager
|
||||
return info;
|
||||
|
||||
} catch (Exception e) {
|
||||
Log.warning("Failure building occupant info " +
|
||||
"[where=" + where() + ", body=" + body + "].");
|
||||
Log.warning("Failure building occupant info [where=" + where() +
|
||||
", body=" + body + "].");
|
||||
Log.logStackTrace(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a particular message handler instance to be used when
|
||||
* processing message events with the specified name.
|
||||
* Registers a particular message handler instance to be used when processing message events
|
||||
* with the specified name.
|
||||
*
|
||||
* @param name the message name of the message events that should be
|
||||
* handled by this handler.
|
||||
* @param name the message name of the message events that should be handled by this handler.
|
||||
* @param handler the handler to be registered.
|
||||
*
|
||||
* @deprecated Use dynamically bound methods instead. See {@link
|
||||
* DynamicListener}.
|
||||
* @deprecated Use dynamically bound methods instead. See {@link DynamicListener}.
|
||||
*/
|
||||
@Deprecated
|
||||
public void registerMessageHandler (String name, MessageHandler handler)
|
||||
@@ -348,11 +327,10 @@ public class PlaceManager
|
||||
handler.handleEvent(event, this);
|
||||
}
|
||||
|
||||
// the first argument should be the client object of the caller or null
|
||||
// if it is a server originated event
|
||||
// the first argument should be the client object of the caller or null if it is a server
|
||||
// originated event
|
||||
int srcoid = event.getSourceOid();
|
||||
DObject source = (srcoid <= 0) ?
|
||||
null : CrowdServer.omgr.getObject(srcoid);
|
||||
DObject source = (srcoid <= 0) ? null : CrowdServer.omgr.getObject(srcoid);
|
||||
Object[] args = event.getArgs(), nargs;
|
||||
if (args == null) {
|
||||
nargs = new Object[] { source };
|
||||
@@ -391,30 +369,26 @@ public class PlaceManager
|
||||
}
|
||||
|
||||
// documentation inherited from interface
|
||||
public boolean isValidSpeaker (
|
||||
DObject speakObj, ClientObject speaker, byte mode)
|
||||
public boolean isValidSpeaker (DObject speakObj, ClientObject speaker, byte mode)
|
||||
{
|
||||
// only allow people in the room to speak
|
||||
return _plobj.occupants.contains(speaker.getOid());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string that can be used in log messages to identify the
|
||||
* place as sensibly as possible to the developer who has to puzzle
|
||||
* over log output trying to figure out what's going on. Derived place
|
||||
* managers can override this and augment the default value (which is
|
||||
* Returns a string that can be used in log messages to identify the place as sensibly as
|
||||
* possible to the developer who has to puzzle over log output trying to figure out what's
|
||||
* going on. Derived place managers can override this and augment the default value (which is
|
||||
* simply the place object id) with useful identifying information.
|
||||
*/
|
||||
public String where ()
|
||||
{
|
||||
return (_plobj == null) ?
|
||||
StringUtil.shortClassName(this) + ":-1" : _plobj.which();
|
||||
return (_plobj == null) ? StringUtil.shortClassName(this) + ":-1" : _plobj.which();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a string representation of this manager. Does so in a way
|
||||
* that makes it easier for derived classes to add to the string
|
||||
* representation.
|
||||
* Generates a string representation of this manager. Does so in a way that makes it easier for
|
||||
* derived classes to add to the string representation.
|
||||
*
|
||||
* @see #toString(StringBuilder)
|
||||
*/
|
||||
@@ -428,8 +402,8 @@ public class PlaceManager
|
||||
}
|
||||
|
||||
/**
|
||||
* Derived classes will generally override this method to create a custom
|
||||
* {@link PlaceObject} derivation that contains extra information.
|
||||
* Derived classes will generally override this method to create a custom {@link PlaceObject}
|
||||
* derivation that contains extra information.
|
||||
*/
|
||||
protected PlaceObject createPlaceObject ()
|
||||
{
|
||||
@@ -450,17 +424,16 @@ public class PlaceManager
|
||||
}
|
||||
|
||||
/**
|
||||
* Called if the permissions check failed, to give place managers a
|
||||
* chance to do any cleanup that might be necessary due to their early
|
||||
* initialization or permissions checking code.
|
||||
* Called if the permissions check failed, to give place managers a chance to do any cleanup
|
||||
* that might be necessary due to their early initialization or permissions checking code.
|
||||
*/
|
||||
protected void permissionsFailed ()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if we should create a speaker service for our place object
|
||||
* so that clients can use it to speak in this place.
|
||||
* @return true if we should create a speaker service for our place object so that clients can
|
||||
* use it to speak in this place.
|
||||
*/
|
||||
protected boolean shouldCreateSpeakService ()
|
||||
{
|
||||
@@ -468,8 +441,8 @@ public class PlaceManager
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an access controller for this place's distributed object, which
|
||||
* by default is {@link CrowdObjectAccess#PLACE}.
|
||||
* Creates an access controller for this place's distributed object, which by default is {@link
|
||||
* CrowdObjectAccess#PLACE}.
|
||||
*/
|
||||
protected AccessController getAccessController ()
|
||||
{
|
||||
@@ -477,10 +450,9 @@ public class PlaceManager
|
||||
}
|
||||
|
||||
/**
|
||||
* Derived classes should override this (and be sure to call
|
||||
* <code>super.didStartup()</code>) to perform any startup time
|
||||
* initialization. The place object will be available by the time this
|
||||
* method is executed.
|
||||
* Derived classes should override this (and be sure to call <code>super.didStartup()</code>)
|
||||
* to perform any startup time initialization. The place object will be available by the time
|
||||
* this method is executed.
|
||||
*/
|
||||
protected void didStartup ()
|
||||
{
|
||||
@@ -493,10 +465,9 @@ public class PlaceManager
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when this place has been destroyed and the place manager has
|
||||
* shut down (via a call to {@link #shutdown}). Derived classes can
|
||||
* override this method and perform any necessary shutdown time
|
||||
* processing.
|
||||
* Called when this place has been destroyed and the place manager has shut down (via a call to
|
||||
* {@link #shutdown}). Derived classes can override this method and perform any necessary
|
||||
* shutdown time processing.
|
||||
*/
|
||||
protected void didShutdown ()
|
||||
{
|
||||
@@ -509,10 +480,9 @@ public class PlaceManager
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when an occupant is being added to this place. This will be
|
||||
* before the call to {@link #bodyEntered} and gives the derived class a
|
||||
* chance to set up additional information about the occupant that might
|
||||
* not be tracked in the occupant info.
|
||||
* Called when an occupant is being added to this place. This will be before the call to {@link
|
||||
* #bodyEntered} and gives the derived class a chance to set up additional information about
|
||||
* the occupant that might not be tracked in the occupant info.
|
||||
*/
|
||||
protected void insertOccupantInfo (OccupantInfo info, BodyObject body)
|
||||
{
|
||||
@@ -525,8 +495,7 @@ public class PlaceManager
|
||||
protected void bodyEntered (final int bodyOid)
|
||||
{
|
||||
if (Log.log.getLevel() == Level.FINE) {
|
||||
Log.debug("Body entered [where=" + where() +
|
||||
", oid=" + bodyOid + "].");
|
||||
Log.debug("Body entered [where=" + where() + ", oid=" + bodyOid + "].");
|
||||
}
|
||||
|
||||
// let our delegates know what's up
|
||||
@@ -546,13 +515,11 @@ public class PlaceManager
|
||||
protected void bodyLeft (final int bodyOid)
|
||||
{
|
||||
if (Log.log.getLevel() == Level.FINE) {
|
||||
Log.debug("Body left [where=" + where() +
|
||||
", oid=" + bodyOid + "].");
|
||||
Log.debug("Body left [where=" + where() + ", oid=" + bodyOid + "].");
|
||||
}
|
||||
|
||||
// if their occupant info hasn't been removed (which may be the
|
||||
// case if they logged off rather than left via a MoveTo request),
|
||||
// we need to get it on out of here
|
||||
// if their occupant info hasn't been removed (which may be the case if they logged off
|
||||
// rather than left via a MoveTo request), we need to get it on out of here
|
||||
Integer key = Integer.valueOf(bodyOid);
|
||||
if (_plobj.occupantInfo.containsKey(key)) {
|
||||
_plobj.removeFromOccupantInfo(key);
|
||||
@@ -575,8 +542,7 @@ public class PlaceManager
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the location should be marked as empty and potentially
|
||||
* shutdown.
|
||||
* Returns whether the location should be marked as empty and potentially shutdown.
|
||||
*/
|
||||
protected boolean shouldDeclareEmpty (OccupantInfo leaver)
|
||||
{
|
||||
@@ -597,10 +563,9 @@ public class PlaceManager
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when we transition from having bodies in the place to not
|
||||
* having any bodies in the place. Some places may take this as a sign
|
||||
* to pack it in, others may wish to stick around. In any case, they
|
||||
* can override this method to do their thing.
|
||||
* Called when we transition from having bodies in the place to not having any bodies in the
|
||||
* place. Some places may take this as a sign to pack it in, others may wish to stick
|
||||
* around. In any case, they can override this method to do their thing.
|
||||
*/
|
||||
protected void placeBecameEmpty ()
|
||||
{
|
||||
@@ -646,9 +611,9 @@ public class PlaceManager
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the period (in milliseconds) of emptiness after which this
|
||||
* place manager will unload itself and shutdown. Returning
|
||||
* <code>0</code> indicates that the place should never be shutdown.
|
||||
* Returns the period (in milliseconds) of emptiness after which this place manager will unload
|
||||
* itself and shutdown. Returning <code>0</code> indicates that the place should never be
|
||||
* shutdown.
|
||||
*/
|
||||
protected long idleUnloadPeriod ()
|
||||
{
|
||||
@@ -656,9 +621,8 @@ public class PlaceManager
|
||||
}
|
||||
|
||||
/**
|
||||
* An extensible way to add to the string representation of this
|
||||
* class. Override this (being sure to call super) and append your
|
||||
* info to the buffer.
|
||||
* An extensible way to add to the string representation of this class. Override this (being
|
||||
* sure to call super) and append your info to the buffer.
|
||||
*/
|
||||
protected void toString (StringBuilder buf)
|
||||
{
|
||||
@@ -699,8 +663,7 @@ public class PlaceManager
|
||||
/** A reference to the place registry with which we're registered. */
|
||||
protected PlaceRegistry _registry;
|
||||
|
||||
/** The invocation manager with whom we register our game invocation
|
||||
* services. */
|
||||
/** The invocation manager with whom we register our game invocation services. */
|
||||
protected InvocationManager _invmgr;
|
||||
|
||||
/** A distributed object manager for doing dobj stuff. */
|
||||
@@ -719,12 +682,10 @@ public class PlaceManager
|
||||
protected ArrayList<PlaceManagerDelegate> _delegates;
|
||||
|
||||
/** Used to keep a canonical copy of the occupant info records. */
|
||||
protected HashIntMap<OccupantInfo> _occInfo =
|
||||
new HashIntMap<OccupantInfo>();
|
||||
protected HashIntMap<OccupantInfo> _occInfo = new HashIntMap<OccupantInfo>();
|
||||
|
||||
/** The interval currently registered to shut this place
|
||||
* down after a certain period of idility, or null if no
|
||||
* interval is currently registered. */
|
||||
/** The interval currently registered to shut this place down after a certain period of
|
||||
* idility, or null if no interval is currently registered. */
|
||||
protected Interval _shutdownInterval;
|
||||
|
||||
/** Used to do method lookup magic when we receive message events. */
|
||||
|
||||
@@ -30,6 +30,7 @@ import com.threerings.presents.server.InvocationException;
|
||||
import com.threerings.presents.server.InvocationManager;
|
||||
|
||||
import com.threerings.crowd.Log;
|
||||
import com.threerings.crowd.data.CrowdCodes;
|
||||
import com.threerings.crowd.data.PlaceConfig;
|
||||
import com.threerings.crowd.data.PlaceObject;
|
||||
|
||||
@@ -59,7 +60,7 @@ public class PlaceRegistry
|
||||
{
|
||||
// create and register our location provider
|
||||
locprov = new LocationProvider(invmgr, omgr, this);
|
||||
invmgr.registerDispatcher(new LocationDispatcher(locprov), true);
|
||||
invmgr.registerDispatcher(new LocationDispatcher(locprov), CrowdCodes.CROWD_GROUP);
|
||||
|
||||
// we'll need these later
|
||||
_omgr = omgr;
|
||||
|
||||
Reference in New Issue
Block a user