Beginnings of table matchmaking services.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@503 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2001-10-19 02:04:29 +00:00
parent 7844e4db85
commit 8c1d9e9a3d
6 changed files with 278 additions and 3 deletions
@@ -0,0 +1,75 @@
//
// $Id: Table.java,v 1.1 2001/10/19 02:04:29 mdb Exp $
package com.threerings.parlor.data;
import java.io.IOException;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import com.samskivert.util.StringUtil;
import com.threerings.presents.dobj.DSet;
import com.threerings.presents.dobj.io.ValueMarshaller;
import com.threerings.parlor.game.GameConfig;
/**
* This class represents a table that is being used to matchmake a game by
* the Parlor services.
*/
public class Table implements DSet.Element
{
/** The unique identifier for this table. */
public Integer tableId;
/** An array of the usernames of the occupants of this table (some
* slots may not be filled. */
public String[] occupants;
/** The game config for the game that is being matchmade. This config
* instance will also implement {@link TableConfig}. */
public GameConfig config;
/**
* A convenience function for accessing the table id as an int.
*/
public int getTableId ()
{
return tableId.intValue();
}
// documentation inherited
public Object getKey ()
{
return tableId;
}
// documentation inherited
public void writeTo (DataOutputStream out)
throws IOException
{
out.writeInt(getTableId());
ValueMarshaller.writeTo(out, occupants);
ValueMarshaller.writeTo(out, config);
}
// documentation inherited
public void readFrom (DataInputStream in)
throws IOException
{
tableId = new Integer(in.readInt());
occupants = (String[])ValueMarshaller.readFrom(in);
config = (GameConfig)ValueMarshaller.readFrom(in);
}
/**
* Generates a string representation of this table instance.
*/
public String toString ()
{
return "[tableId=" + tableId +
", occupants=" + StringUtil.toString(occupants) +
", config=" + config + "]";
}
}
@@ -0,0 +1,30 @@
//
// $Id: TableConfig.java,v 1.1 2001/10/19 02:04:29 mdb Exp $
package com.threerings.parlor.data;
/**
* A game config object that is to be matchmade using the table services
* should implement this interface so that the table services can extract
* the necessary table-generic information.
*/
public interface TableConfig
{
/**
* Returns the minimum number of players needed to start the game.
*/
public int getMinimumPlayers ();
/**
* Returns the maximum number of players that can play in the game.
*/
public int getMaximumPlayers ();
/**
* Returns the number of players desired for this game, or -1 if the
* table services should allow up to the maximum number of players to
* join the table, but also allow the game to be started by the table
* creator any time after the minimum number of players has arrived.
*/
public int getDesiredPlayers ();
}
@@ -0,0 +1,38 @@
//
// $Id: TableLobbyObject.java,v 1.1 2001/10/19 02:04:29 mdb Exp $
package com.threerings.parlor.data;
import com.threerings.presents.dobj.DSet;
/**
* This interface must be implemented by the place object used by a lobby
* that wishes to make use of the table services.
*/
public interface TableLobbyObject
{
/**
* Returns a reference to the distributed set instance that will be
* holding the tables.
*/
public DSet getTables ();
/**
* Adds the supplied table instance to the tables set (using the
* appropriate distributed object mechanisms).
*/
public void addToTables (Table table);
/**
* Updates the value of the specified table instance in the tables
* distributed set (using the appropriate distributed object
* mechanisms).
*/
public void updateTables (Table table);
/**
* Removes the table instance that matches the specified key from the
* tables set (using the appropriate distributed object mechanisms).
*/
public void removeFromTables (Object key);
}