soc.server
Class SOCGameList

java.lang.Object
  extended bysoc.server.SOCGameList

public class SOCGameList
extends java.lang.Object

A class for creating and tracking the games

Author:
Robert S. Thomas

Field Summary
static int GAME_EXPIRE_MINUTES
          Number of minutes after which a game (created on the list) is expired.
protected  java.util.Hashtable gameData
          map of game names to SOCGame objects
protected  java.util.Hashtable gameMembers
          map of game names to Vector of game members
protected  java.util.Hashtable gameMutexes
          mutexes to synchronize game state access
protected  boolean inUse
          used with gamelist's monitor
 
Constructor Summary
SOCGameList()
          constructor
 
Method Summary
 void addMember(StringConnection conn, java.lang.String gaName)
          add a member to the game.
 void createGame(java.lang.String gaName)
          create a new game, and add to the list; game will expire in GAME_EXPIRE_MINUTES.
 void deleteGame(java.lang.String gaName)
          remove the game from the list
 SOCGame getGameData(java.lang.String gaName)
           
 java.util.Enumeration getGames()
           
 java.util.Vector getMembers(java.lang.String gaName)
           
 boolean isGame(java.lang.String gaName)
           
 boolean isGameEmpty(java.lang.String gaName)
           
 boolean isMember(StringConnection conn, java.lang.String gaName)
           
 void releaseMonitor()
          release the monitor for this game list
 boolean releaseMonitorForGame(java.lang.String game)
          release the monitor for this game
 void removeMember(StringConnection conn, java.lang.String gaName)
          remove member from the game.
 SOCGameBoardReset resetBoard(java.lang.String gaName)
          Reset the board of this game, create a new game of same name, same players, new layout.
 void takeMonitor()
          take the monitor for this game list
 boolean takeMonitorForGame(java.lang.String game)
          take the monitor for this game
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GAME_EXPIRE_MINUTES

public static int GAME_EXPIRE_MINUTES
Number of minutes after which a game (created on the list) is expired. Default is 90.

See Also:
createGame(String)

gameMutexes

protected java.util.Hashtable gameMutexes
mutexes to synchronize game state access


gameMembers

protected java.util.Hashtable gameMembers
map of game names to Vector of game members


gameData

protected java.util.Hashtable gameData
map of game names to SOCGame objects


inUse

protected boolean inUse
used with gamelist's monitor

Constructor Detail

SOCGameList

public SOCGameList()
constructor

Method Detail

takeMonitor

public void takeMonitor()
take the monitor for this game list


releaseMonitor

public void releaseMonitor()
release the monitor for this game list


takeMonitorForGame

public boolean takeMonitorForGame(java.lang.String game)
take the monitor for this game

Parameters:
game - the name of the game
Returns:
false if the game has no mutex

releaseMonitorForGame

public boolean releaseMonitorForGame(java.lang.String game)
release the monitor for this game

Parameters:
game - the name of the game
Returns:
false if the game has no mutex

getGames

public java.util.Enumeration getGames()
Returns:
an enumeration of game names

isGameEmpty

public boolean isGameEmpty(java.lang.String gaName)
Parameters:
gaName - the name of the game
Returns:
true if the channel exists and has an empty member list

getMembers

public java.util.Vector getMembers(java.lang.String gaName)
Parameters:
gaName - game name
Returns:
list of members: a Vector of StringConnections

getGameData

public SOCGame getGameData(java.lang.String gaName)
Parameters:
gaName - game name
Returns:
the game data

isMember

public boolean isMember(StringConnection conn,
                        java.lang.String gaName)
Parameters:
gaName - the name of the game
conn - the member's connection
Returns:
true if memName is a member of the game

addMember

public void addMember(StringConnection conn,
                      java.lang.String gaName)
add a member to the game. Also checks client's version against game's current range of client versions. Please call takeMonitorForGame(String) before calling this.

Parameters:
gaName - the name of the game
conn - the member's connection; version should already be set

removeMember

public void removeMember(StringConnection conn,
                         java.lang.String gaName)
remove member from the game. Also updates game's version range of remaining connected members. Please call takeMonitorForGame(String) before calling this.

Parameters:
gaName - the name of the game
conn - the member's connection

isGame

public boolean isGame(java.lang.String gaName)
Parameters:
gaName - the name of the game
Returns:
true if the game exists

createGame

public void createGame(java.lang.String gaName)
create a new game, and add to the list; game will expire in GAME_EXPIRE_MINUTES. If a game already exists (per isGame(String)), do nothing.

Parameters:
gaName - the name of the game
See Also:
GAME_EXPIRE_MINUTES

resetBoard

public SOCGameBoardReset resetBoard(java.lang.String gaName)
Reset the board of this game, create a new game of same name, same players, new layout. The new "reset" board takes the place of the old game in the game list. Robots are not copied and must re-join the game. (They're removed from the list of game members.) Takes game monitor. Destroys old game. YOU MUST RELEASE the game monitor after returning.

Parameters:
gaName - Name of game - If not found, do nothing. No monitor is taken.
Returns:
New game if gaName was found and copied; null if no game called gaName
See Also:
SOCGame.resetAsCopy(), releaseMonitorForGame(String)

deleteGame

public void deleteGame(java.lang.String gaName)
remove the game from the list

Parameters:
gaName - the name of the game