- Added TokenRing

- Specify override first on overridden methods.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4170 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Ray Greenwell
2006-06-05 21:28:00 +00:00
parent a442646791
commit 251566b321
66 changed files with 301 additions and 193 deletions
+32 -32
View File
@@ -76,36 +76,36 @@ public class BodyObject extends ClientObject
*/
public var awayMessage :String;
// /**
// * Checks whether or not this user has access to the specified
// * feature. Currently used by the chat system to regulate access to
// * chat broadcasts but also forms the basis of an extensible
// * fine-grained permissions system.
// *
// * @return null if the user has access, a fully-qualified translatable
// * message string indicating the reason for denial of access (or just
// * {@link InvocationCodes#ACCESS_DENIED} if you don't want to be
// * specific).
// */
// public String checkAccess (String feature, Object context)
// {
// // our default access control policy; how quaint
// if (ChatCodes.BROADCAST_ACCESS.equals(feature)) {
// return getTokens().isAdmin() ? null : ChatCodes.ACCESS_DENIED;
// } else if (ChatCodes.CHAT_ACCESS.equals(feature)) {
// return null;
// } else {
// return InvocationCodes.ACCESS_DENIED;
// }
// }
//
// /**
// * Returns this user's access control tokens.
// */
// public TokenRing getTokens ()
// {
// return EMPTY_TOKENS;
// }
/**
* Checks whether or not this user has access to the specified
* feature. Currently used by the chat system to regulate access to
* chat broadcasts but also forms the basis of an extensible
* fine-grained permissions system.
*
* @return null if the user has access, a fully-qualified translatable
* message string indicating the reason for denial of access (or just
* {@link InvocationCodes#ACCESS_DENIED} if you don't want to be
* specific).
*/
public function checkAccess (feature :String, context :Object) :String
{
// our default access control policy; how quaint
if (ChatCodes.BROADCAST_ACCESS == feature) {
return getTokens().isAdmin() ? null : InvocationCodes.ACCESS_DENIED;
} else if (ChatCodes.CHAT_ACCESS == feature) {
return null;
} else {
return InvocationCodes.ACCESS_DENIED;
}
}
/**
* Returns this user's access control tokens.
*/
public function getTokens () :TokenRing
{
return new TokenRing();
}
/**
* Returns the name that should be displayed to other users and used for
@@ -116,7 +116,7 @@ public class BodyObject extends ClientObject
return username;
}
public override function writeObject (out :ObjectOutputStream) :void
override public function writeObject (out :ObjectOutputStream) :void
{
super.writeObject(out);
@@ -126,7 +126,7 @@ public class BodyObject extends ClientObject
out.writeField(awayMessage);
}
public override function readObject (ins :ObjectInputStream) :void
override public function readObject (ins :ObjectInputStream) :void
{
super.readObject(ins);
@@ -11,7 +11,7 @@ public class LocationMarshaller_MoveMarshaller extends InvocationMarshaller_List
public static const MOVE_SUCCEEDED :int = 1;
// documentation inherited
public override function dispatchResponse (methodId :int, args :Array) :void
override public function dispatchResponse (methodId :int, args :Array) :void
{
switch (methodId) {
case MOVE_SUCCEEDED:
@@ -179,7 +179,7 @@ public class PlaceObject extends DObject
// AUTO-GENERATED: METHODS END
// documentation inherited
public override function writeObject (out :ObjectOutputStream) :void
override public function writeObject (out :ObjectOutputStream) :void
{
super.writeObject(out);
out.writeObject(occupants);
@@ -188,7 +188,7 @@ public class PlaceObject extends DObject
}
// documentation inherited
public override function readObject (ins :ObjectInputStream) :void
override public function readObject (ins :ObjectInputStream) :void
{
super.readObject(ins);
occupants = (ins.readObject() as OidList);
@@ -0,0 +1,108 @@
//
// $Id$
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2005 Three Rings Design, Inc., All Rights Reserved
// http://www.threerings.net/code/narya/
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.threerings.crowd.data {
import com.threerings.io.ObjectInputStream;
import com.threerings.io.ObjectOutputStream;
import com.threerings.io.Streamable;
/**
* Defines access control tokens that convey certain privileges to users
* (see {@link BodyObject#checkAccess}).
*/
public class TokenRing
implements Streamable
{
/** Indicates that this user is an administrator and can do things
* like broadcast, shutdown the server and whatnot. */
public static const ADMIN :int = (1 << 0);
/**
* Constructs a token ring with the supplied set of tokens.
*/
public function TokenRing (tokens :int = 0)
{
_tokens = tokens;
}
/**
* Returns true if this token ring contains the specified token.
*/
public function holdsToken (token :int) :Boolean
{
return (_tokens & token) != 0;
}
/**
* Convenience function for checking whether this ring holds the
* {@link #ADMIN} token.
*/
public function isAdmin () :Boolean
{
return holdsToken(ADMIN);
}
/**
* Returns the bitmask that stores the various tokens.
*/
public function getTokens () :int
{
return _tokens;
}
/**
* Adds the specified token to this ring.
*/
public function setToken (token :int, setOn :Boolean = true) :void
{
if (setOn) {
_tokens |= token;
} else {
clearToken(token);
}
}
/**
* Clears the specified token from this ring.
*/
public function clearToken (token :int) :void
{
_tokens &= ~token;
}
// documentation inherited from interface Streamable
public function writeObject (out :ObjectOutputStream) :void
{
out.writeInt(_tokens);
}
// documentation inherited from interface Streamable
public function readObject (ins :ObjectInputStream) :void
{
_tokens = ins.readInt();
}
/** The tokens contained in this ring (composed together bitwise). */
protected var _tokens :int;
}
}