soc.server
Class SOCGameListAtServer

java.lang.Object
  extended by soc.util.SOCGameList
      extended by soc.server.SOCGameListAtServer

public class SOCGameListAtServer
extends SOCGameList

A class for creating and tracking the games; contains each game's name, game options, SOCGame object, and clients (StringConnections).

In 1.1.07, parent class SOCGameList was refactored, with some methods moved to this new subclass, such as createGame.

Since:
1.1.07
Author:
Jeremy D Monin <jeremy@nand.net>
See Also:
SOCBoardLargeAtServer

Nested Class Summary
protected static class SOCGameListAtServer.GameInfoAtServer
          Game info including server-side information, such as the game type's GameHandler.
 
Nested classes/interfaces inherited from class soc.util.SOCGameList
SOCGameList.GameInfo
 
Field Summary
static int GAME_TIME_EXPIRE_MINUTES
          Number of minutes after which a game (created on the list) is expired.
protected  java.util.Hashtable<java.lang.String,java.util.Vector<StringConnection>> gameMembers
          synchronized map of game names to Vector of game members (StringConnections)
 
Fields inherited from class soc.util.SOCGameList
gameData, gameInfo, inUse
 
Constructor Summary
SOCGameListAtServer()
          constructor
 
Method Summary
 void addMember(StringConnection conn, java.lang.String gaName)
          add a member to the game.
 SOCGame createGame(java.lang.String gaName, java.lang.String gaOwner, java.lang.String gaLocaleStr, java.util.Map<java.lang.String,SOCGameOption> gaOpts, GameHandler handler)
          create a new game, and add to the list; game will expire in GAME_TIME_EXPIRE_MINUTES minutes.
 void deleteGame(java.lang.String gaName)
          remove the game from the list and call SOCGame.destroyGame() via SOCGameList.deleteGame(String).
 GameHandler getGameTypeHandler(java.lang.String gaName)
          Get this game's type handler from its SOCGameListAtServer.GameInfoAtServer.
 java.util.Vector<StringConnection> getMembers(java.lang.String gaName)
          get a game's members (client connections)
 boolean isGameEmpty(java.lang.String gaName)
          does the game have no members?
 boolean isMember(StringConnection conn, java.lang.String gaName)
          is this connection a member of the game?
 java.util.Vector<SOCGame> memberGames(StringConnection c, java.lang.String firstGameName)
          List of games containing this member.
 int playerGamesMinVersion(StringConnection plConn)
          For the games this player is in, what's the minimum required client version? Checks SOCGame.getClientVersionMinRequired().
 void removeMember(StringConnection conn, java.lang.String gaName)
          remove member from the game.
 void replaceMemberAllGames(StringConnection oldConn, StringConnection newConn)
          Replace member from all games, with a new connection with same name (after a network problem).
 SOCGameBoardReset resetBoard(java.lang.String gaName)
          Reset the board of this game, create a new game of same name, same players, new layout.
 
Methods inherited from class soc.util.SOCGameList
addGame, addGame, addGames, addGames, getGameData, getGameNames, getGameOptions, getGameOptionsString, getGamesData, isGame, isUnjoinableGame, parseGameOptions, releaseMonitor, releaseMonitorForGame, size, takeMonitor, takeMonitorForGame
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GAME_TIME_EXPIRE_MINUTES

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

Before v2.0.00 this field was named GAME_EXPIRE_MINUTES.

See Also:
createGame(String, String, String, Map, GameHandler), SOCGame.setExpiration(long), SOCServer.checkForExpiredGames(long)

gameMembers

protected java.util.Hashtable<java.lang.String,java.util.Vector<StringConnection>> gameMembers
synchronized map of game names to Vector of game members (StringConnections)

Constructor Detail

SOCGameListAtServer

public SOCGameListAtServer()
constructor

Method Detail

isGameEmpty

public boolean isGameEmpty(java.lang.String gaName)
does the game have no members?

Parameters:
gaName - the name of the game
Returns:
true if the game exists and has an empty member list

getGameTypeHandler

public GameHandler getGameTypeHandler(java.lang.String gaName)
Get this game's type handler from its SOCGameListAtServer.GameInfoAtServer.

Parameters:
gaName - Game name
Returns:
handler, or null if game unknown or its GameInfo doesn't have a handler
Since:
2.0.00

getMembers

public java.util.Vector<StringConnection> getMembers(java.lang.String gaName)
get a game's members (client connections)

Parameters:
gaName - game name
Returns:
list of members: a Vector of StringConnections

isMember

public boolean isMember(StringConnection conn,
                        java.lang.String gaName)
is this connection a member of the game?

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 SOCGameList.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 client version range, with remaining connected members. Please call SOCGameList.takeMonitorForGame(String) before calling this.

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

replaceMemberAllGames

public void replaceMemberAllGames(StringConnection oldConn,
                                  StringConnection newConn)
                           throws java.lang.IllegalArgumentException
Replace member from all games, with a new connection with same name (after a network problem).

Parameters:
oldConn - the member's old connection
newConn - the member's new connection
Throws:
java.lang.IllegalArgumentException - if oldConn's keyname (via getData()) differs from newConn's keyname
Since:
1.1.08
See Also:
memberGames(StringConnection, String)

createGame

public SOCGame createGame(java.lang.String gaName,
                          java.lang.String gaOwner,
                          java.lang.String gaLocaleStr,
                          java.util.Map<java.lang.String,SOCGameOption> gaOpts,
                          GameHandler handler)
                   throws java.lang.IllegalArgumentException
create a new game, and add to the list; game will expire in GAME_TIME_EXPIRE_MINUTES minutes. If a game already exists (per SOCGameList.isGame(String)), do nothing.

Parameters:
gaName - the name of the game
gaOwner - the game owner/creator's player name, or null (added in 1.1.10)
gaLocaleStr - the game creator's locale, to later set SOCGame.hasMultiLocales if needed (added in 2.0.00)
gaOpts - if game has options, its SOCGameOptions; otherwise null. Should already be validated, by calling SOCGameOption.adjustOptionsToKnown(Map, Map, boolean) with doServerPreadjust true.
handler - Game type handler for this game
Returns:
new game object, or null if it already existed
Throws:
java.lang.IllegalArgumentException - if handler is null

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.) If the game had robots, they must leave the old game before any players can join the new game; the new game's SOCGame.boardResetOngoingInfo field is set to the object returned by this method, and its gameState will be SOCGame.READY_RESET_WAIT_ROBOT_DISMISS instead of SOCGame.NEW.

Locking: Takes game monitor. Copies old game. Adds reset-copy to gamelist. Destroys old game. Releases game monitor.

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, or if a problem occurs during reset
See Also:
SOCGame.resetAsCopy()

deleteGame

public void deleteGame(java.lang.String gaName)
remove the game from the list and call SOCGame.destroyGame() via SOCGameList.deleteGame(String).

Overrides:
deleteGame in class SOCGameList
Parameters:
gaName - the name of the game

playerGamesMinVersion

public int playerGamesMinVersion(StringConnection plConn)
For the games this player is in, what's the minimum required client version? Checks SOCGame.getClientVersionMinRequired().

This method helps determine if a client's connection can be "taken over" after a network problem. It synchronizes on gameData.

Parameters:
plConn - the previous connection of the player, which might be taken over
Returns:
Minimum version, in same format as SOCGame.getClientVersionMinRequired(), or 0 if player isn't in any games.
Since:
1.1.08

memberGames

public java.util.Vector<SOCGame> memberGames(StringConnection c,
                                             java.lang.String firstGameName)
List of games containing this member.

Parameters:
c - Connection
firstGameName - Game name that should be first element of list (if newConn is a member of it), or null.
Returns:
The games, in no particular order (past firstGameName), or a 0-length Vector, if member isn't in any game.
Since:
1.1.08
See Also:
replaceMemberAllGames(StringConnection, StringConnection)