From f25c028cca05b7af57874daf36b7f9f31154666a Mon Sep 17 00:00:00 2001 From: Walter Korman Date: Fri, 1 Nov 2002 00:39:18 +0000 Subject: [PATCH] Initial work on a body service to allow setting a user's idled state. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1877 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../threerings/crowd/client/BodyService.java | 19 ++++ .../threerings/crowd/data/BodyMarshaller.java | 33 +++++++ .../crowd/server/BodyDispatcher.java | 53 +++++++++++ .../threerings/crowd/server/BodyProvider.java | 95 +++++++++++++++++++ .../threerings/crowd/server/CrowdClient.java | 41 +------- .../threerings/crowd/server/CrowdServer.java | 5 +- 6 files changed, 208 insertions(+), 38 deletions(-) create mode 100644 src/java/com/threerings/crowd/client/BodyService.java create mode 100644 src/java/com/threerings/crowd/data/BodyMarshaller.java create mode 100644 src/java/com/threerings/crowd/server/BodyDispatcher.java create mode 100644 src/java/com/threerings/crowd/server/BodyProvider.java diff --git a/src/java/com/threerings/crowd/client/BodyService.java b/src/java/com/threerings/crowd/client/BodyService.java new file mode 100644 index 000000000..769f07cfc --- /dev/null +++ b/src/java/com/threerings/crowd/client/BodyService.java @@ -0,0 +1,19 @@ +// +// $Id: BodyService.java,v 1.1 2002/11/01 00:39:18 shaper Exp $ + +package com.threerings.crowd.client; + +import com.threerings.presents.client.Client; +import com.threerings.presents.client.InvocationService; + +/** + * The client side of the body-related invocation services. + */ +public interface BodyService extends InvocationService +{ + /** + * Requests to set the idle state of the client to the specified + * value. + */ + public void setIdle (Client client, boolean idle); +} diff --git a/src/java/com/threerings/crowd/data/BodyMarshaller.java b/src/java/com/threerings/crowd/data/BodyMarshaller.java new file mode 100644 index 000000000..b1b87236e --- /dev/null +++ b/src/java/com/threerings/crowd/data/BodyMarshaller.java @@ -0,0 +1,33 @@ +// +// $Id: BodyMarshaller.java,v 1.1 2002/11/01 00:39:18 shaper Exp $ + +package com.threerings.crowd.data; + +import com.threerings.crowd.client.BodyService; +import com.threerings.presents.client.Client; +import com.threerings.presents.data.InvocationMarshaller; +import com.threerings.presents.dobj.InvocationResponseEvent; + +/** + * Provides the implementation of the {@link BodyService} interface + * that marshalls the arguments and delivers the request to the provider + * on the server. Also provides an implementation of the response listener + * interfaces that marshall the response arguments and deliver them back + * to the requesting client. + */ +public class BodyMarshaller extends InvocationMarshaller + implements BodyService +{ + /** The method id used to dispatch {@link #setIdle} requests. */ + public static final int SET_IDLE = 1; + + // documentation inherited from interface + public void setIdle (Client arg1, boolean arg2) + { + sendRequest(arg1, SET_IDLE, new Object[] { + new Boolean(arg2) + }); + } + + // Generated on 15:58:33 10/31/02. +} diff --git a/src/java/com/threerings/crowd/server/BodyDispatcher.java b/src/java/com/threerings/crowd/server/BodyDispatcher.java new file mode 100644 index 000000000..ef33d721f --- /dev/null +++ b/src/java/com/threerings/crowd/server/BodyDispatcher.java @@ -0,0 +1,53 @@ +// +// $Id: BodyDispatcher.java,v 1.1 2002/11/01 00:39:18 shaper Exp $ + +package com.threerings.crowd.server; + +import com.threerings.crowd.client.BodyService; +import com.threerings.crowd.data.BodyMarshaller; +import com.threerings.presents.client.Client; +import com.threerings.presents.data.ClientObject; +import com.threerings.presents.data.InvocationMarshaller; +import com.threerings.presents.server.InvocationDispatcher; +import com.threerings.presents.server.InvocationException; + +/** + * Dispatches requests to the {@link BodyProvider}. + */ +public class BodyDispatcher extends InvocationDispatcher +{ + /** + * Creates a dispatcher that may be registered to dispatch invocation + * service requests for the specified provider. + */ + public BodyDispatcher (BodyProvider provider) + { + this.provider = provider; + } + + // documentation inherited + public InvocationMarshaller createMarshaller () + { + return new BodyMarshaller(); + } + + // documentation inherited + public void dispatchRequest ( + ClientObject source, int methodId, Object[] args) + throws InvocationException + { + switch (methodId) { + case BodyMarshaller.SET_IDLE: + ((BodyProvider)provider).setIdle( + source, + ((Boolean)args[0]).booleanValue() + ); + return; + + default: + super.dispatchRequest(source, methodId, args); + } + } + + // Generated on 15:58:33 10/31/02. +} diff --git a/src/java/com/threerings/crowd/server/BodyProvider.java b/src/java/com/threerings/crowd/server/BodyProvider.java new file mode 100644 index 000000000..ffaf4014f --- /dev/null +++ b/src/java/com/threerings/crowd/server/BodyProvider.java @@ -0,0 +1,95 @@ +// +// $Id: BodyProvider.java,v 1.1 2002/11/01 00:39:18 shaper Exp $ + +package com.threerings.crowd.server; + +import com.threerings.presents.dobj.DObjectManager; + +import com.threerings.presents.data.ClientObject; +import com.threerings.presents.server.InvocationException; +import com.threerings.presents.server.InvocationManager; +import com.threerings.presents.server.InvocationProvider; + +import com.threerings.crowd.Log; +import com.threerings.crowd.data.BodyObject; +import com.threerings.crowd.data.OccupantInfo; +import com.threerings.crowd.data.PlaceObject; + +/** + * Provides the server-side side of the body-related invocation services. + */ +public class BodyProvider + implements InvocationProvider +{ + /** + * Constructs and initializes a body provider instance which will be + * used to handle all body-related invocation service requests. + */ + public static void init (InvocationManager invmgr, DObjectManager omgr) + { + _omgr = omgr; + + // register a provider instance + invmgr.registerDispatcher(new BodyDispatcher(new BodyProvider()), true); + } + + /** + * Handles a request to set the idle state of a client to the + * specified value. + */ + public void setIdle (ClientObject caller, boolean idle) + throws InvocationException + { + BodyObject bobj = (BodyObject)caller; + + // determine the body's proposed new status + byte nstatus = (idle) ? OccupantInfo.IDLE : OccupantInfo.ACTIVE; + + // report NOOP attempts + if (bobj.status == nstatus) { + throw new InvocationException( + (idle) ? "m.already_idle" : "m.already_active"); + } + + // update their status! + Log.info("setIdle [user=" + bobj.username + + ", status=" + nstatus + "]."); + updateOccupantStatus(bobj, bobj.location, nstatus); + } + + /** + * Updates the connection status for the given body object's occupant + * info in the specified location. + */ + public static void updateOccupantStatus ( + BodyObject body, int locationId, byte status) + { + // no need to NOOP + if (body.status == status) { + return; + } + + // update the status in their body object + body.setStatus(status); + body.statusTime = System.currentTimeMillis(); + + // get the place object for the specified location (which is, in + // theory, occupied by this user) + PlaceObject plobj = (PlaceObject) + CrowdServer.omgr.getObject(locationId); + if (plobj == null) { + return; + } + + // update the occupant info with the new connection status + OccupantInfo info = (OccupantInfo) + plobj.occupantInfo.get(new Integer(body.getOid())); + if (info != null) { + info.status = status; + plobj.updateOccupantInfo(info); + } + } + + /** The distributed object manager used by the chat services. */ + protected static DObjectManager _omgr; +} diff --git a/src/java/com/threerings/crowd/server/CrowdClient.java b/src/java/com/threerings/crowd/server/CrowdClient.java index 4623bb914..b0c471f0f 100644 --- a/src/java/com/threerings/crowd/server/CrowdClient.java +++ b/src/java/com/threerings/crowd/server/CrowdClient.java @@ -1,5 +1,5 @@ // -// $Id: CrowdClient.java,v 1.14 2002/10/30 00:47:19 mdb Exp $ +// $Id: CrowdClient.java,v 1.15 2002/11/01 00:39:18 shaper Exp $ package com.threerings.crowd.server; @@ -9,7 +9,6 @@ import com.threerings.crowd.Log; import com.threerings.crowd.data.BodyObject; import com.threerings.crowd.data.OccupantInfo; import com.threerings.crowd.data.PlaceObject; -import com.threerings.crowd.server.CrowdServer; /** * The crowd client extends the presents client with crowd-specific client @@ -25,7 +24,7 @@ public class CrowdClient extends PresentsClient if (_clobj != null) { // note that the user's disconnected BodyObject bobj = (BodyObject)_clobj; - updateOccupantStatus( + BodyProvider.updateOccupantStatus( bobj, bobj.location, OccupantInfo.DISCONNECTED); } } @@ -37,39 +36,7 @@ public class CrowdClient extends PresentsClient // note that the user's active once more BodyObject bobj = (BodyObject)_clobj; - updateOccupantStatus(bobj, bobj.location, OccupantInfo.ACTIVE); - } - - /** - * Updates the connection status for the given body object's occupant - * info in the specified location. - */ - protected void updateOccupantStatus ( - BodyObject body, int locationId, byte status) - { - // no need to NOOP - if (body.status == status) { - return; - } - - // update the status in their body object - body.setStatus(status); - body.statusTime = System.currentTimeMillis(); - - // get the place object for the specified location (which is, in - // theory, occupied by this user) - PlaceObject plobj = (PlaceObject) - CrowdServer.omgr.getObject(locationId); - if (plobj == null) { - return; - } - - // update the occupant info with the new connection status - OccupantInfo info = (OccupantInfo) - plobj.occupantInfo.get(new Integer(body.getOid())); - if (info != null) { - info.status = status; - plobj.updateOccupantInfo(info); - } + BodyProvider.updateOccupantStatus( + bobj, bobj.location, OccupantInfo.ACTIVE); } } diff --git a/src/java/com/threerings/crowd/server/CrowdServer.java b/src/java/com/threerings/crowd/server/CrowdServer.java index e2a1bc2f3..fc641fc7a 100644 --- a/src/java/com/threerings/crowd/server/CrowdServer.java +++ b/src/java/com/threerings/crowd/server/CrowdServer.java @@ -1,5 +1,5 @@ // -// $Id: CrowdServer.java,v 1.15 2002/10/31 21:32:39 mdb Exp $ +// $Id: CrowdServer.java,v 1.16 2002/11/01 00:39:18 shaper Exp $ package com.threerings.crowd.server; @@ -47,6 +47,9 @@ public class CrowdServer extends PresentsServer // create our access control implementation actrl = createAccessControl(); + // initialize the body services + BodyProvider.init(invmgr, omgr); + // initialize the chat services ChatProvider.init(invmgr, omgr);