com.threerings.parlor.data
Class Table

java.lang.Object
  extended by com.threerings.parlor.data.Table
All Implemented Interfaces:
Streamable, ParlorCodes, InvocationCodes, DSet.Entry

public class Table
extends Object
implements DSet.Entry, ParlorCodes

This class represents a table that is being used to matchmake a game by the Parlor services.


Nested Class Summary
 
Nested classes/interfaces inherited from interface com.threerings.io.Streamable
Streamable.Closure
 
Field Summary
protected  HashSet<Name> _bannedUsers
          On the server, the usernames that have been banned from this table.
protected static int _tableIdCounter
          A counter for assigning table ids.
static int ANY_POSITION
          Used to request any position at a table.
 int[] bodyOids
          The body oids of the players of this table, or null if a party game.
 GameConfig config
          The game config for the game that is being matchmade.
 int gameOid
          The oid of the game that was created from this table or -1 if the table is still in matchmaking mode.
 int lobbyOid
          The object id of the lobby object with which this table is associated.
 Name[] players
          An array of the usernames of the players of this table (some slots may not be filled), or null if a party game.
 int tableId
          The unique identifier for this table.
 TableConfig tconfig
          The table configuration object.
 Name[] watchers
          An array of the usernames of the non-player occupants of this game.
 
Fields inherited from interface com.threerings.parlor.data.ParlorCodes
ALREADY_AT_TABLE, BANNED_FROM_TABLE, GAME_ALREADY_STARTED, INVALID_TABLE_POSITION, INVITATION_ACCEPTED, INVITATION_COUNTERED, INVITATION_REFUSED, INVITEE_NOT_ONLINE, MUST_BE_CREATOR, NO_SELF_BOOT, NO_SUCH_TABLE, NOT_AT_TABLE, PARLOR_GROUP, TABLE_POSITION_OCCUPIED
 
Fields inherited from interface com.threerings.presents.data.InvocationCodes
ACCESS_DENIED, E_ACCESS_DENIED, E_INTERNAL_ERROR, GLOBAL_GROUP, INTERNAL_ERROR
 
Constructor Summary
Table()
          Constructs a blank table instance, suitable for unserialization.
 
Method Summary
 void addBannedUser(Name player)
          Indicate to this table that a user was booted and should be prevented from rejoining.
 boolean clearPlayer(Name username)
          Requests that the specified user be removed from their seat at this table.
 boolean clearPlayerByOid(int bodyOid)
          Requests that the user identified by the specified body object id be removed from their seat at this table.
 void clearPlayerPos(int position)
          Called to clear a player at the specified position.
 boolean containsPlayer(Name player)
          Returns true if this table contains the specified player.
protected  Name[] createPlayerNamesArray(int length)
          Creates a names array of the appropriate type.
 boolean equals(Object other)
           
 Comparable<?> getKey()
           
 int getOccupiedCount()
          Count the number of players currently occupying this table.
 Name[] getPlayers()
          Once a table is ready to play (see mayBeStarted() and shouldBeStarted()), the players array can be fetched using this method.
 int[][] getTeamMemberIndices()
          For a team game, get the team member indices of the compressed players array returned by getPlayers().
 int hashCode()
           
 void init(int lobbyOid, TableConfig tconfig, GameConfig config)
          Initializes a new table instance, and assigns it the next monotonically increasing table id.
 boolean inPlay()
          Returns true if this table is in play, false if it is still being matchmade.
 boolean isEmpty()
          Returns true if there is no one sitting at this table.
 boolean mayBeStarted()
          Returns true if this table has a sufficient number of players that the game can be started.
 String setPlayer(int position, BodyObject player)
          Requests to seat the specified user at the specified position in this table.
 void setPlayerPos(int position, BodyObject player)
          This method is used for party games, it does no bounds checking or verification of the player's ability to join, if you are unsure you should call 'setPlayer'.
 boolean shouldBeStarted()
          Returns true if sufficient seats are occupied that the game should be automatically started.
 String toString()
           
protected  void toString(StringBuilder buf)
          Helper method for toString, ripe for overrideability.
 void updateOccupants(GameObject gameobj)
          Called by the table manager when the game object's players have changed.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ANY_POSITION

public static final int ANY_POSITION
Used to request any position at a table.

See Also:
Constant Field Values

tableId

public int tableId
The unique identifier for this table.


lobbyOid

public int lobbyOid
The object id of the lobby object with which this table is associated.


gameOid

public int gameOid
The oid of the game that was created from this table or -1 if the table is still in matchmaking mode.


players

public Name[] players
An array of the usernames of the players of this table (some slots may not be filled), or null if a party game.


watchers

public Name[] watchers
An array of the usernames of the non-player occupants of this game. For FFA party games this is all of a room's occupants and they are in fact players.


bodyOids

public transient int[] bodyOids
The body oids of the players of this table, or null if a party game. (This is not propagated to remote instances.)


config

public GameConfig config
The game config for the game that is being matchmade.


tconfig

public TableConfig tconfig
The table configuration object.


_tableIdCounter

protected static int _tableIdCounter
A counter for assigning table ids.


_bannedUsers

protected transient HashSet<Name> _bannedUsers
On the server, the usernames that have been banned from this table.

Constructor Detail

Table

public Table()
Constructs a blank table instance, suitable for unserialization.

Method Detail

init

public void init(int lobbyOid,
                 TableConfig tconfig,
                 GameConfig config)
Initializes a new table instance, and assigns it the next monotonically increasing table id.

Parameters:
lobbyOid - the object id of the lobby in which this table is to live.
tconfig - the table configuration for this table.
config - the configuration of the game being matchmade by this table.

isEmpty

public boolean isEmpty()
Returns true if there is no one sitting at this table.


getOccupiedCount

public int getOccupiedCount()
Count the number of players currently occupying this table.


getPlayers

public Name[] getPlayers()
Once a table is ready to play (see mayBeStarted() and shouldBeStarted()), the players array can be fetched using this method. It will return an array containing the usernames of all of the players in the game, sized properly and with each player in the appropriate position.


getTeamMemberIndices

public int[][] getTeamMemberIndices()
For a team game, get the team member indices of the compressed players array returned by getPlayers().


setPlayer

public String setPlayer(int position,
                        BodyObject player)
Requests to seat the specified user at the specified position in this table.

Parameters:
position - the position in which to seat the user.
player - the player to set.
Returns:
null if the user was successfully seated, a string error code explaining the failure if the user was not able to be seated at that position.

setPlayerPos

public void setPlayerPos(int position,
                         BodyObject player)
This method is used for party games, it does no bounds checking or verification of the player's ability to join, if you are unsure you should call 'setPlayer'.


addBannedUser

public void addBannedUser(Name player)
Indicate to this table that a user was booted and should be prevented from rejoining.


clearPlayer

public boolean clearPlayer(Name username)
Requests that the specified user be removed from their seat at this table.

Returns:
true if the user was seated at the table and has now been removed, false if the user was never seated at the table in the first place.

clearPlayerByOid

public boolean clearPlayerByOid(int bodyOid)
Requests that the user identified by the specified body object id be removed from their seat at this table.

Returns:
true if the user was seated at the table and has now been removed, false if the user was never seated at the table in the first place.

clearPlayerPos

public void clearPlayerPos(int position)
Called to clear a player at the specified position. Only call this method if you know what you're doing.


containsPlayer

public boolean containsPlayer(Name player)
Returns true if this table contains the specified player.


updateOccupants

public void updateOccupants(GameObject gameobj)
Called by the table manager when the game object's players have changed. Regenerates the watchers array.


mayBeStarted

public boolean mayBeStarted()
Returns true if this table has a sufficient number of players that the game can be started.


shouldBeStarted

public boolean shouldBeStarted()
Returns true if sufficient seats are occupied that the game should be automatically started.


inPlay

public boolean inPlay()
Returns true if this table is in play, false if it is still being matchmade.


getKey

public Comparable<?> getKey()
Specified by:
getKey in interface DSet.Entry

equals

public boolean equals(Object other)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object

toString

protected void toString(StringBuilder buf)
Helper method for toString, ripe for overrideability.


createPlayerNamesArray

protected Name[] createPlayerNamesArray(int length)
Creates a names array of the appropriate type.