Added a standard mechanism for customizing the AccessController on a

PlaceObject. Created a default AccessController that is slightly more strict
than the CrowdServer-wide default in that it only allows place occupants to
subscribe to a PlaceObject (a motivated and resourceful player could otherwise
listen in on place chat everywhere in the game if they so desired; with a
custom client, of course).


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4079 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2006-04-30 19:16:05 +00:00
parent 2df0c56f2a
commit 0699eb3d1c
2 changed files with 41 additions and 2 deletions
@@ -21,6 +21,7 @@
package com.threerings.crowd.server;
import com.threerings.presents.data.ClientObject;
import com.threerings.presents.dobj.AccessController;
import com.threerings.presents.dobj.DEvent;
import com.threerings.presents.dobj.DObject;
@@ -31,6 +32,7 @@ import com.threerings.presents.dobj.Subscriber;
import com.threerings.crowd.Log;
import com.threerings.crowd.data.BodyObject;
import com.threerings.crowd.data.PlaceObject;
/**
* Defines the various object access controllers used by the Crowd server.
@@ -103,4 +105,28 @@ public class CrowdObjectAccess
}
}
};
/**
* Provides access control for place objects. The default behavior is to
* allow place occupants to subscribe to the place object and to use the
* {@link #DEFAULT} modification policy.
*/
public static AccessController PLACE = new AccessController()
{
// documentation inherited from interface
public boolean allowSubscribe (DObject object, Subscriber sub)
{
if (sub instanceof CrowdClient) {
ClientObject co = ((CrowdClient)sub).getClientObject();
return ((PlaceObject)object).occupants.contains(co.getOid());
}
return true;
}
// documentation inherited from interface
public boolean allowDispatch (DObject object, DEvent event)
{
return DEFAULT.allowDispatch(object, event);
}
};
}
@@ -33,6 +33,7 @@ import com.threerings.presents.data.ClientObject;
import com.threerings.presents.server.InvocationManager;
import com.threerings.presents.server.PresentsDObjectMgr;
import com.threerings.presents.dobj.AccessController;
import com.threerings.presents.dobj.DObject;
import com.threerings.presents.dobj.DObjectManager;
import com.threerings.presents.dobj.EntryAddedEvent;
@@ -265,6 +266,9 @@ public class PlaceManager
// we'll need to hear about place object events
plobj.addListener(this);
// configure this place's access controller
plobj.setAccessController(getAccessController());
// let our derived classes do their thang
didStartup();
@@ -281,6 +285,15 @@ public class PlaceManager
return true;
}
/**
* Creates an access controller for this place's distributed object, which
* by default is {@link CrowdObjectAccess#PLACE}.
*/
protected AccessController getAccessController ()
{
return CrowdObjectAccess.PLACE;
}
/**
* Derived classes should override this (and be sure to call
* <code>super.didStartup()</code>) to perform any startup time
@@ -619,8 +632,8 @@ 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());