Started work on the 'crowd' package.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3935 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Ray Greenwell
2006-03-10 03:05:37 +00:00
parent 3f5aed3555
commit ca66f91ac7
31 changed files with 2650 additions and 57 deletions
@@ -0,0 +1,203 @@
//
// $Id: BodyObject.java 3774 2005-12-03 03:05:06Z mdb $
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2004 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.util.Byte;
import com.threerings.util.Name;
import com.threerings.presents.data.ClientObject;
import com.threerings.presents.data.InvocationCodes;
import com.threerings.crowd.chat.data.ChatCodes;
import com.threerings.io.ObjectInputStream;
import com.threerings.io.ObjectOutputStream;
/**
* The basic user object class for Crowd users. Bodies have a username, a
* location and a status.
*/
public class BodyObject extends ClientObject
{
// AUTO-GENERATED: FIELDS START
/** The field name of the <code>username</code> field. */
public static const USERNAME :String = "username";
/** The field name of the <code>location</code> field. */
public static const LOCATION :String = "location";
/** The field name of the <code>status</code> field. */
public static const STATUS :String = "status";
/** The field name of the <code>awayMessage</code> field. */
public static const AWAY_MESSAGE :String = "awayMessage";
// AUTO-GENERATED: FIELDS END
/**
* The username associated with this body object. This should not be used
* directly; in general {@link #getVisibleName} should be used unless you
* specifically know that you want the username.
*/
public var username :Name;
/**
* The oid of the place currently occupied by this body or -1 if they
* currently occupy no place.
*/
public var location :int = -1;
/**
* The user's current status ({@link OccupantInfo#ACTIVE}, etc.).
*/
public var status :int;
/**
* If non-null, this contains a message to be auto-replied whenever
* another user delivers a tell message to this user.
*/
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;
// }
/**
* Returns the name that should be displayed to other users and used for
* the chat system. The default is to use {@link #username}.
*/
public function getVisibleName () :Name
{
return username;
}
public override function writeObject (out :ObjectOutputStream) :void
{
super.writeObject(out);
out.writeObject(username);
out.writeInt(location);
out.writeByte(status);
out.writeField(awayMessage);
}
public override function readObject (ins :ObjectInputStream) :void
{
super.readObject(ins);
username = (ins.readObject() as Name);
location = ins.readInt();
status = ins.readByte();
awayMessage = (ins.readField(String) as String);
}
// AUTO-GENERATED: METHODS START
/**
* Requests that the <code>username</code> field be set to the
* specified value. The local value will be updated immediately and an
* event will be propagated through the system to notify all listeners
* that the attribute did change. Proxied copies of this object (on
* clients) will apply the value change when they received the
* attribute changed notification.
*/
public function setUsername (value :Name) :void
{
Name ovalue = this.username;
requestAttributeChange(
USERNAME, value, ovalue);
this.username = value;
}
/**
* Requests that the <code>location</code> field be set to the
* specified value. The local value will be updated immediately and an
* event will be propagated through the system to notify all listeners
* that the attribute did change. Proxied copies of this object (on
* clients) will apply the value change when they received the
* attribute changed notification.
*/
public function setLocation (value :int) :void
{
int ovalue = this.location;
requestAttributeChange(
LOCATION, value, ovalue);
this.location = value;
}
/**
* Requests that the <code>status</code> field be set to the
* specified value. The local value will be updated immediately and an
* event will be propagated through the system to notify all listeners
* that the attribute did change. Proxied copies of this object (on
* clients) will apply the value change when they received the
* attribute changed notification.
*/
public function setStatus (value :int) :void
{
var ovalue :int = this.status;
requestAttributeChange(
STATUS, new Byte(value), new Byte(ovalue));
this.status = value;
}
/**
* Requests that the <code>awayMessage</code> field be set to the
* specified value. The local value will be updated immediately and an
* event will be propagated through the system to notify all listeners
* that the attribute did change. Proxied copies of this object (on
* clients) will apply the value change when they received the
* attribute changed notification.
*/
public function setAwayMessage (value :String) :void
{
var ovalue :String = this.awayMessage;
requestAttributeChange(
AWAY_MESSAGE, value, ovalue);
this.awayMessage = value;
}
// AUTO-GENERATED: METHODS END
}
}
@@ -0,0 +1,44 @@
//
// $Id: LocationCodes.java 3098 2004-08-27 02:12:55Z mdb $
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2004 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.presents.data.InvocationCodes;
/**
* Contains codes used by the location invocation services.
*/
public class LocationCodes extends InvocationCodes
{
/** An error code indicating that a place identified by a particular
* place id does not exist. Usually generated by a failed moveTo
* request. */
public static const NO_SUCH_PLACE :String = "m.no_such_place";
/** An error code sent when a user requests to move to a new place but
* they are in the middle of moving somewhere already. */
public static const MOVE_IN_PROGRESS :String = "m.move_in_progress";
/** An error code sent when a user requests to move to a place, but
* they are already in the requested place. */
public static const ALREADY_THERE :String = "m.already_there";
}
}
@@ -0,0 +1,102 @@
//
// $Id: OccupantInfo.java 3774 2005-12-03 03:05:06Z mdb $
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2004 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.util.Integer;
import com.threerings.util.Name;
import com.threerings.presents.dobj.DSetEntry;
import com.threerings.crowd.data.BodyObject;
import com.threerings.io.ObjectInputStream;
import com.threerings.io.ObjectOutputStream;
/**
* The occupant info object contains all of the information about an
* occupant of a place that should be shared with other occupants of the
* place. These objects are stored in the place object itself and are
* updated when bodies enter and exit a place.
*
* <p> A system that builds upon the Crowd framework can extend this class to
* include extra information about their occupants. They will need to provide a
* derived {@link BodyObject} that creates and configures their occupant info
* in {@link BodyObject#createOccupantInfo}.
*
* <p> Note also that this class implements {@link Cloneable} which means
* that if derived classes add non-primitive attributes, they are
* responsible for adding the code to clone those attributes when a clone
* is requested.
*/
public class OccupantInfo
implements DSetEntry
{
/** Constant value for {@link #status}. */
public static const ACTIVE :int = 0;
/** Constant value for {@link #status}. */
public static const IDLE :int = 1;
/** Constant value for {@link #status}. */
public static const DISCONNECTED :int = 2;
/** Maps status codes to human readable strings. */
public static const X_STATUS :Array = { "active", "idle", "discon" };
/** The body object id of this occupant (and our entry key). */
public var bodyOid :Integer;
/** The username of this occupant. */
public var username :Name;
/** The status of this occupant. */
public var status :int = ACTIVE;
/** Access to the body object id as an int. */
public function getBodyOid () :int
{
return bodyOid.value;
}
// documentation inherited from interface DSetEntry
public function getKey () :Object
{
return bodyOid;
}
// documentation inherited from superinterface Streamable
public function writeObject (out :ObjectOutputStream) :void
{
out.writeObject(bodyOid);
out.writeObject(username);
out.writeByte(status);
}
// documentation inherited from superinterface Streamable
public function readObject (ins :ObjectInputStream) :void
{
bodyOid = (ins.readObject() as Integer);
username = (ins.readObject() as Name);
status = ins.readByte();
}
}
}
@@ -0,0 +1,64 @@
//
// $Id: PlaceConfig.java 3726 2005-10-11 19:17:43Z ray $
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2004 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.Streamable;
import com.threerings.io.ObjectInputStream;
import com.threerings.io.ObjectOutputStream;
import com.threerings.crowd.client.PlaceController;
/**
* The place config class encapsulates the configuration information for a
* particular type of place. The hierarchy of place config objects mimics
* the hierarchy of place managers and controllers. Both the place manager
* and place controller are provided with the place config object when the
* place is created.
*
* <p> The place config object is also the mechanism used to instantiate
* the appropriate place manager and controller. Every place must have an
* associated place config derived class that overrides {@link
* #getControllerClass} and {@link #getManagerClassName}, returning the
* appropriate place controller and manager class for that place.
*/
public interface PlaceConfig extends Streamable
{
/**
* Returns the class that should be used to create a controller for
* this place. The controller class must derive from {@link
* PlaceController}.
*/
public function getControllerClass () :Class;
/**
* Returns the name of the class that should be used to create a
* manager for this place. The manager class must derive from {@link
* com.threerings.crowd.server.PlaceManager}. <em>Note:</em> this
* method differs from {@link #getControllerClass} because we want to
* avoid compile time linkage of the place config object (which is
* used on the client) to server code. This allows a code optimizer
* (DashO Pro, for example) to remove the server code from the client,
* knowing that it is never used.
*/
// public function getManagerClassName () :String;
}
}
@@ -0,0 +1,179 @@
//
// $Id: PlaceObject.java 3406 2005-03-15 02:12:03Z mdb $
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2004 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.util.Iterator;
import com.threerings.util.Name;
import com.threerings.presents.dobj.DObject;
import com.threerings.presents.dobj.DSet;
import com.threerings.presents.dobj.DSetEntry;
import com.threerings.presents.dobj.OidList;
import com.threerings.crowd.Log;
import com.threerings.crowd.chat.data.SpeakMarshaller;
import com.threerings.crowd.chat.data.SpeakObject;
/**
* A distributed object that contains information on a place that is
* occupied by bodies. This place might be a chat room, a game room, an
* island in a massively multiplayer piratical universe, anything that has
* occupants that might want to chat with one another.
*/
public class PlaceObject extends DObject
{
// AUTO-GENERATED: FIELDS START
/** The field name of the <code>occupants</code> field. */
public static const OCCUPANTS :String = "occupants";
/** The field name of the <code>occupantInfo</code> field. */
public static const OCCUPANT_INFO :String = "occupantInfo";
/** The field name of the <code>speakService</code> field. */
public static const SPEAK_SERVICE :String = "speakService";
// AUTO-GENERATED: FIELDS END
/**
* Tracks the oid of the body objects of all of the occupants of this
* place.
*/
public var occupants :OidList = new OidList();
/**
* Contains an info record (of type {@link OccupantInfo}) for each
* occupant that contains information about that occupant that needs
* to be known by everyone in the place. <em>Note:</em> Don't obtain
* occupant info records directly from this set when on the server,
* use <code>PlaceManager.getOccupantInfo()</code> instead (along with
* <code>PlaceManager.updateOccupantInfo()</code>) because it does
* some special processing to ensure that readers and updaters don't
* step on one another even if they make rapid fire changes to a
* user's occupant info.
*/
public var occupantInfo :DSet = new DSet();
/** Used to generate speak requests on this place object. */
public var speakService :SpeakMarshaller;
/**
* Looks up a user's occupant info by name.
*
* @return the occupant info record for the named user or null if no
* user in the room has that username.
*/
public function getOccupantInfo (username :Name) :OccupantInfo
{
var itr :Iterator = occupantInfo.iterator();
while (itr.hasNext()) {
var info :OccupantInfo = (itr.next() as OccupantInfo);
if (info.username.equals(username)) {
return info;
}
}
return null;
}
// AUTO-GENERATED: METHODS START
/**
* Requests that <code>oid</code> be added to the <code>occupants</code>
* oid list. The list will not change until the event is actually
* propagated through the system.
*/
public function addToOccupants (oid :int) :void
{
requestOidAdd(OCCUPANTS, oid);
}
/**
* Requests that <code>oid</code> be removed from the
* <code>occupants</code> oid list. The list will not change until the
* event is actually propagated through the system.
*/
public function removeFromOccupants (oid :int) :void
{
requestOidRemove(OCCUPANTS, oid);
}
/**
* Requests that the specified entry be added to the
* <code>occupantInfo</code> set. The set will not change until the event is
* actually propagated through the system.
*/
public function addToOccupantInfo (elem :DSetEntry) :void
{
requestEntryAdd(OCCUPANT_INFO, occupantInfo, elem);
}
/**
* Requests that the entry matching the supplied key be removed from
* the <code>occupantInfo</code> set. The set will not change until the
* event is actually propagated through the system.
*/
public function removeFromOccupantInfo (key :Object) :void
{
requestEntryRemove(OCCUPANT_INFO, occupantInfo, key);
}
/**
* Requests that the specified entry be updated in the
* <code>occupantInfo</code> set. The set will not change until the event is
* actually propagated through the system.
*/
public function updateOccupantInfo (elem :DSetEntry) :void
{
requestEntryUpdate(OCCUPANT_INFO, occupantInfo, elem);
}
/**
* Requests that the <code>occupantInfo</code> field be set to the
* specified value. Generally one only adds, updates and removes
* entries of a distributed set, but certain situations call for a
* complete replacement of the set value. The local value will be
* updated immediately and an event will be propagated through the
* system to notify all listeners that the attribute did
* change. Proxied copies of this object (on clients) will apply the
* value change when they received the attribute changed notification.
*/
public function setOccupantInfo (value :DSet) :void
{
requestAttributeChange(OCCUPANT_INFO, value, this.occupantInfo);
this.occupantInfo = (value == null) ? null : (DSet)value.clone();
}
/**
* Requests that the <code>speakService</code> field be set to the
* specified value. The local value will be updated immediately and an
* event will be propagated through the system to notify all listeners
* that the attribute did change. Proxied copies of this object (on
* clients) will apply the value change when they received the
* attribute changed notification.
*/
public function setSpeakService (value :SpeakMarshaller) :void
{
var ovalue :SpeakMarshaller = this.speakService;
requestAttributeChange(
SPEAK_SERVICE, value, ovalue);
this.speakService = value;
}
// AUTO-GENERATED: METHODS END
}
}