//
// $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;
}

@@ -26,17 +26,17 @@
 ava,v 1.
-1
+2
  2002/11
@@ -43,16 +43,16 @@
 /01 
-00:39:18
+21:33:21
  sha
@@ -104,61 +104,8 @@
 r;%0A%0A
-import com.threerings.presents.dobj.DObjectManager;%0A%0A
 impo
@@ -855,59 +855,15 @@
 vmgr
-, DObjectManager omgr)%0A    %7B%0A        _omgr = omgr;%0A
+)%0A    %7B
 %0A   
@@ -1606,22 +1606,38 @@
 g.info(%22
-setIdl
+Setting user idle stat
 e %5Buser=
@@ -2238,16 +2238,210 @@
 lis();%0A%0A
+        // get the place manager for the specified location%0A        PlaceManager pmgr = CrowdServer.plreg.getPlaceManager(locationId);%0A        if (pmgr == null) %7B%0A            return;%0A        %7D%0A%0A
         
@@ -2579,71 +2579,28 @@
 j = 
-(PlaceObject)%0A            CrowdServer.o
+p
 mgr.get
+Place
 Object(
-locationId
 );%0A 
@@ -2907,20 +2907,19 @@
        p
-lobj
+mgr
 .updateO
@@ -2956,120 +2956,7 @@
    %7D
-%0A%0A    /** The distributed object manager used by the chat services. */%0A    protected static DObjectManager _omgr;
 %0A%7D%0A

Update a user's status in their occupant info via the place manager as required, rather than directly in the place object. Don't need dobjmgr in constructor.