Server side of occupant management stuff.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@269 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
//
|
||||
// $Id: OccupantInfo.java,v 1.1 2001/08/16 04:28:36 mdb Exp $
|
||||
|
||||
package com.threerings.cocktail.party.data;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
|
||||
import com.threerings.cocktail.cher.dobj.DSet;
|
||||
|
||||
/**
|
||||
* 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. A system that builds upon
|
||||
* the Party framework can extend this class to include extra information
|
||||
* about their occupants. They will need to be sure to return the proper
|
||||
* class from {@link
|
||||
* com.threerings.cocktail.party.server.PlaceManager#getOccupantInfoClass}
|
||||
* and populate their occupant info in {@link
|
||||
* com.threerings.cocktail.party.server.PlaceManager#populateOccupantInfo}.
|
||||
*/
|
||||
public class OccupantInfo implements DSet.Element
|
||||
{
|
||||
/** The username of this occupant. */
|
||||
public String username;
|
||||
|
||||
// documentation inherited
|
||||
public Object getKey ()
|
||||
{
|
||||
return username;
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public void writeTo (DataOutputStream out)
|
||||
throws IOException
|
||||
{
|
||||
out.writeUTF(username);
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public void readFrom (DataInputStream in)
|
||||
throws IOException
|
||||
{
|
||||
username = in.readUTF();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called to generate a string representation of this occupant info
|
||||
* object. This calls the overridable {@link #toString(StringBuffer)}
|
||||
* to generate that representation in a derived class friendly manner.
|
||||
*/
|
||||
public String toString ()
|
||||
{
|
||||
StringBuffer buf = new StringBuffer();
|
||||
buf.append("[");
|
||||
toString(buf);
|
||||
buf.append("]");
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Derived classes should override this and append their extra
|
||||
* occupant info to the buffer. They should of course not to forget to
|
||||
* call super.
|
||||
*/
|
||||
protected void toString (StringBuffer buf)
|
||||
{
|
||||
buf.append("username=").append(username);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: PlaceObject.dobj,v 1.4 2001/08/02 06:01:13 mdb Exp $
|
||||
// $Id: PlaceObject.dobj,v 1.5 2001/08/16 04:28:36 mdb Exp $
|
||||
|
||||
package com.threerings.cocktail.party.data;
|
||||
|
||||
@@ -10,12 +10,22 @@ public class PlaceObject extends DObject
|
||||
/** The field name of the <code>occupants</code> field. */
|
||||
public static final String OCCUPANTS = "occupants";
|
||||
|
||||
/** The field name of the <code>occupantInfo</code> field. */
|
||||
public static final String OCCUPANT_INFO = "occupantInfo";
|
||||
|
||||
/**
|
||||
* Tracks the oid of the body objects of all of the occupants of this
|
||||
* place.
|
||||
*/
|
||||
public OidList occupants = 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.
|
||||
*/
|
||||
public DSet occupantInfo = new DSet();
|
||||
|
||||
/**
|
||||
* Requests that the specified oid be added to the
|
||||
* <code>occupants</code> oid list.
|
||||
@@ -34,9 +44,37 @@ public class PlaceObject extends DObject
|
||||
requestOidRemove(OCCUPANTS, oid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests that the specified element be added to the
|
||||
* <code>occupantInfo</code> set.
|
||||
*/
|
||||
public void addToOccupantInfo (DSet.Element elem)
|
||||
{
|
||||
requestElementAdd(OCCUPANT_INFO, elem);
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests that the element matching the supplied key be removed from
|
||||
* the <code>occupantInfo</code> set.
|
||||
*/
|
||||
public void removeFromOccupantInfo (Object key)
|
||||
{
|
||||
requestElementRemove(OCCUPANT_INFO, key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests that the specified element be updated in the
|
||||
* <code>occupantInfo</code> set.
|
||||
*/
|
||||
public void updateOccupantInfo (DSet.Element elem)
|
||||
{
|
||||
requestElementUpdate(OCCUPANT_INFO, elem);
|
||||
}
|
||||
|
||||
protected void toString (StringBuffer buf)
|
||||
{
|
||||
super.toString(buf);
|
||||
buf.append(", occupants=").append(occupants);
|
||||
buf.append(", occupantInfo=").append(occupantInfo);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user