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
@@ -1,5 +1,5 @@
//
// $Id: ParlorCodes.java,v 1.5 2001/10/11 04:07:51 mdb Exp $
// $Id: ParlorCodes.java,v 1.6 2001/10/19 02:04:29 mdb Exp $
package com.threerings.parlor.client;
@@ -58,4 +58,30 @@ public interface ParlorCodes extends InvocationCodes
* the invited user was not online at the time the invitation was
* received. */
public static final String INVITEE_NOT_ONLINE = "m.invitee_not_online";
/** The message identifier for a create table request. */
public static final String CREATE_TABLE_REQUEST = "CreateTable";
/** The response identifier for a table created response. This is
* mapped by the invocation services to a call to {@link
* ParlorDirector#handleTableCreated}. */
public static final String TABLE_CREATED_RESPONSE = "TableCreated";
/** The response identifier for a create failed response. This is
* mapped by the invocation services to a call to {@link
* ParlorDirector#handleCreateFailed}. */
public static final String CREATE_FAILED_RESPONSE = "CreateFailed";
/** The message identifier for a join table request. */
public static final String JOIN_TABLE_REQUEST = "JoinTable";
/** The response identifier for a table joined response. This is
* mapped by the invocation services to a call to {@link
* ParlorDirector#handleTableJoined}. */
public static final String TABLE_JOINED_RESPONSE = "TableJoined";
/** The response identifier for a join failed response. This is mapped
* by the invocation services to a call to {@link
* ParlorDirector#handleJoinFailed}. */
public static final String JOIN_FAILED_RESPONSE = "JoinFailed";
}
@@ -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);
}
@@ -1,5 +1,5 @@
//
// $Id: ParlorManager.java,v 1.10 2001/10/17 02:49:17 mdb Exp $
// $Id: ParlorManager.java,v 1.11 2001/10/19 02:04:29 mdb Exp $
package com.threerings.parlor.server;
@@ -14,6 +14,8 @@ import com.threerings.crowd.server.CrowdServer;
import com.threerings.parlor.Log;
import com.threerings.parlor.client.ParlorCodes;
import com.threerings.parlor.data.TableConfig;
import com.threerings.parlor.data.TableLobbyObject;
import com.threerings.parlor.game.GameConfig;
import com.threerings.parlor.game.GameManager;
@@ -191,6 +193,58 @@ public class ParlorManager
}
}
/**
* Requests that a new table be created to matchmake the game
* described by the supplied game config instance. The config instance
* provided must implement the {@link TableConfig} interface so that
* the parlor services can determine how to configure the table that
* will be created.
*
* @param creator the body object that will own the new table.
* @param placeOid the place object id of the place (lobby) in which
* this table should be created. The place object specified must
* implement the {@link TableLobbyObject} interface.
* @param config the configuration of the game to be created.
*
* @return the id of the newly created table.
*
* @exception ServiceFailedException thrown if the table creation was
* not able processed for some reason. The explanation will be
* provided in the message data of the exception.
*/
public int createTable (BodyObject creator, int placeOid,
GameConfig config)
throws ServiceFailedException
{
return -1;
}
/**
* Requests that the specified user be added to the specified table at
* the specified position. If the user successfully joins the table,
* the function will return normally. If they are not able to join for
* some reason (the slot is already full, etc.), a {@link
* ServiceFailedException} will be thrown with a message code that
* describes the reason for failure. If the user does successfully
* join, they will be added to the table entry in the tables set in
* the place object that is hosting the table.
*
* @param joiner the body object of the user that wishes to join the
* table.
* @param tableId the id of the table to be joined.
* @param position the position at which to join the table.
*
* @return the id of the newly created table.
*
* @exception ServiceFailedException thrown if the table creation was
* not able processed for some reason. The explanation will be
* provided in the message data of the exception.
*/
public void joinTable (BodyObject joiner, int tableId, int position)
throws ServiceFailedException
{
}
/**
* The invitation record is used by the parlor manager to keep track
* of pending invitations.
@@ -1,5 +1,5 @@
//
// $Id: ParlorProvider.java,v 1.7 2001/10/11 21:08:22 mdb Exp $
// $Id: ParlorProvider.java,v 1.8 2001/10/19 02:04:29 mdb Exp $
package com.threerings.parlor.server;
@@ -89,6 +89,58 @@ public class ParlorProvider
_pmgr.cancelInvite(source, inviteId);
}
/**
* Processes a request from the client to create a new table.
*/
public void handleCreateTableRequest (
BodyObject source, int invid, int placeOid, GameConfig config)
{
Log.info("Handling create table request [source=" + source +
", invid=" + invid + ", placeOid=" + placeOid +
", config=" + config + "].");
String rsp = null;
try {
// pass the creation request on to the table manager
int tableId = _pmgr.createTable(source, placeOid, config);
sendResponse(source, invid, TABLE_CREATED_RESPONSE,
new Integer(tableId));
} catch (ServiceFailedException sfe) {
// the exception message is the code indicating the reason for
// the creation rejection
sendResponse(source, invid, CREATE_FAILED_RESPONSE,
sfe.getMessage());
}
}
/**
* Processes a request from the client to join an existing table.
*/
public void handleJoinTableRequest (
BodyObject source, int invid, int tableId, int position)
{
Log.info("Handling join table request [source=" + source +
", invid=" + invid + ", tableId=" + tableId +
", position=" + position + "].");
String rsp = null;
try {
// pass the creation request on to the table manager
_pmgr.joinTable(source, tableId, position);
// there is normally no response. the client will see
// themselves show up in the table that they joined
} catch (ServiceFailedException sfe) {
// the exception message is the code indicating the reason for
// the creation rejection
sendResponse(source, invid, JOIN_FAILED_RESPONSE,
sfe.getMessage());
}
}
/** A reference to the parlor manager we're working with. */
protected ParlorManager _pmgr;
}