From 0699eb3d1ca0685588cbf09d998201965e50c555 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Sun, 30 Apr 2006 19:16:05 +0000 Subject: [PATCH] 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 --- .../crowd/server/CrowdObjectAccess.java | 26 +++++++++++++++++++ .../threerings/crowd/server/PlaceManager.java | 17 ++++++++++-- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/java/com/threerings/crowd/server/CrowdObjectAccess.java b/src/java/com/threerings/crowd/server/CrowdObjectAccess.java index be4ec17ed..cc75d3ac5 100644 --- a/src/java/com/threerings/crowd/server/CrowdObjectAccess.java +++ b/src/java/com/threerings/crowd/server/CrowdObjectAccess.java @@ -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); + } + }; } diff --git a/src/java/com/threerings/crowd/server/PlaceManager.java b/src/java/com/threerings/crowd/server/PlaceManager.java index 6d7346391..c802c5689 100644 --- a/src/java/com/threerings/crowd/server/PlaceManager.java +++ b/src/java/com/threerings/crowd/server/PlaceManager.java @@ -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 * super.didStartup()) 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());