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
This commit is contained in:
@@ -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);
|
||||
}
|
||||
@@ -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.
|
||||
}
|
||||
@@ -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.
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user