soc.server
Class SOCServer

java.lang.Object
  extended by java.lang.Thread
      extended by soc.server.genericServer.Server
          extended by soc.server.SOCServer
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Runnable

public class SOCServer
extends Server

A server for Settlers of Catan

Author:
Robert S. Thomas Note: This is an attempt at being more modular. 5/13/99 RST Note: Hopefully fixed all of the deadlock problems. 12/27/01 RST

For server command line options, use the --help option.

If the database is used (see SOCDBHelper), users can be set up with a username & password in that database to log in and play. Users without accounts can connect by leaving the password blank, as long as they aren't using a nickname which has a password in the database. There's a database setup script parameter SOCDBHelper.PROP_JSETTLERS_DB_SCRIPT_SETUP. If the setup script is ran, the server exits afterward, so that the script won't be part of the command line for normal server operation.

Network traffic: The first message over the connection is the client's version and the second is the server's response: Either SOCRejectConnection, or the lists of channels and games (SOCChannels, SOCGames).

The server supports several debug commands when enabled, and when sent as chat messages by a user named "debug". (Or, by the only user in a practice game.) See processDebugCommand(StringConnection, String, String, String) and handleGAMETEXTMSG(StringConnection, SOCGameTextMsg) for details.

The version check timer is set in SOCClientData.setVersionTimer(SOCServer, StringConnection). Before 1.1.06, the server's response was first message, and client version was then sent in reply to server's version.

Java properties (starting with "jsettlers.") were added in 1.1.09, with constant names starting with PROP_JSETTLERS_, and listed in PROPS_LIST.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class soc.server.genericServer.Server
Server.ConnExcepDelayedPrintTask, Server.NetStringServerSocket
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
private  boolean acctsNotOpenRegButNoUsers
          Server internal flag to indicate that user accounts are active, and authentication is required to create accounts, and there aren't any accounts in the database yet.
private static java.lang.String ADMIN_COMMANDS_HEADING
          Heading to show above any admin commands the user is authorized to run.
static java.lang.String[] ADMIN_USER_COMMANDS_HELP
          List and description of user-admin commands.
private  boolean allowDebugUser
          Is a debug user allowed to run commands listed in DEBUG_COMMANDS_HELP? Default is false.
private static int AUTH_OR_REJECT__FAILED
          authOrRejectClientUser(....) result: Failed authentication, failed name validation, or name is already logged in and that connection hasn't timed out yet
private static int AUTH_OR_REJECT__OK
          authOrRejectClientUser(....) result: Authentication succeeded
private static int AUTH_OR_REJECT__TAKING_OVER
          authOrRejectClientUser(....) result: Authentication succeeded, is taking over another connection
protected  SOCChannelList channelList
          list of chat channels
static int CLI_VERSION_ASSUMED_GUESS
          If client never tells us their version, assume they are version 1.0.0 (1000).
static int CLI_VERSION_MIN
          Minimum required client version, to connect and play a game.
static java.lang.String CLI_VERSION_MIN_DISPLAY
          Minimum required client version, in "display" form, like "1.0.00".
static int CLI_VERSION_TIMER_FIRE_MS
          Client version is guessed after this many milliseconds (1200) if the client hasn't yet sent it to us.
static int CLIENT_MAX_CREATE_CHANNELS
          Maximum number of chat channels that a client can create at the same time (default 2).
static int CLIENT_MAX_CREATE_GAMES
          Maximum number of games that a client can create at the same time (default 5).
protected  java.util.HashMap<java.lang.Integer,java.lang.Integer> clientPastVersionStats
          Client version count stats since startup (includes bots).
private  java.lang.Object countFieldSync
          Synchronization for numberOfGamesFinished writes.
(package private)  java.lang.String databasePassword
           
private  java.util.Set<java.lang.String> databaseUserAdmins
          User admins whitelist, from PROP_JSETTLERS_ACCOUNTS_ADMINS, or null if disabled.
(package private)  java.lang.String databaseUserName
           
static java.lang.String[] DEBUG_COMMANDS_HELP
          List and description of debug/admin commands.
private  SOCServerFeatures features
          Active optional server features, if any; see SOCServerFeatures constants for currently defined features.
static int GAME_NAME_MAX_LENGTH
          Maximum permitted game name length, default 30 characters.
static int GAME_TIME_EXPIRE_ADDTIME_MINUTES
          Amount of time to add (30 minutes) when the *ADDTIME* command is used by a player.
static int GAME_TIME_EXPIRE_CHECK_MINUTES
          Sleep time (minutes) between checks for expired games in SOCGameTimeoutChecker.run().
static int GAME_TIME_EXPIRE_WARN_MINUTES
          If game will expire in this or fewer minutes, warn the players.
protected  SOCGameListAtServer gameList
          list of soc games
(package private)  SOCGameTimeoutChecker gameTimeoutChecker
          game timeout checker
static java.lang.String[] GENERAL_COMMANDS_HELP
          List and description of general commands that any game member can run.
private static char[] GENERATEROBOTCOOKIE_HEX
          The 16 hex characters to use in generateRobotCookie().
private  SOCGameHandler handler
          Game type handler, currently shared by all game instances.
static boolean hasSetGameOptions
          Did the properties or command line include --option / -o to set game option values? Checked in constructors for possible stderr option-values printout.
private static boolean hasStartupPrintAndExit
          Did the command line include an option that prints some information (like --help or --version) and should exit, instead of starting the server? Set in parseCmdline_DashedArgs(String[]).
private  boolean hasUtilityModeProp
          True if props contains a property which is used to run the server in Utility Mode instead of Server Mode.
private static java.lang.String i18n_gameopt_PL_desc
          Description string for SOCGameOption "PL" hardcoded into the SOCGameOption class, from SOCGameOption.getOption("PL", false).
(package private) static java.lang.String i18n_scenario_SC_WOND_desc
          Short description string for SOCScenario "SC_WOND" hardcoded into the SOCScenario class.
protected  int maxConnections
          Maximum number of connections allowed.
static java.lang.String MSG_NICKNAME_ALREADY_IN_USE
          Status Message to send, nickname already logged into the system
static java.lang.String MSG_NICKNAME_ALREADY_IN_USE_NEWER_VERSION_P1
          Part 1 of Status Message to send, nickname already logged into the system with a newer client version.
static java.lang.String MSG_NICKNAME_ALREADY_IN_USE_NEWER_VERSION_P2
          Part 2 of Status Message to send, nickname already logged into the system with a newer client version.
static java.lang.String MSG_NICKNAME_ALREADY_IN_USE_WAIT_TRY_AGAIN
          Status Message to send, nickname already logged into the system.
static int NICKNAME_TAKEOVER_SECONDS_DIFFERENT_IP
          Number of seconds before a connection is considered disconnected, and its nickname can be "taken over" by a new connection from a different IP.
static int NICKNAME_TAKEOVER_SECONDS_SAME_IP
          Number of seconds before a connection is considered disconnected, and its nickname can be "taken over" by a new connection from the same IP.
static int NICKNAME_TAKEOVER_SECONDS_SAME_PASSWORD
          Number of seconds before a connection is considered disconnected, and its nickname can be "taken over" by a new connection with the right password.
protected  int numberOfGamesFinished
          The total number of games finished: Game state became SOCGame.OVER or higher from an earlier/lower state.
protected  int numberOfGamesStarted
          The total number of games that have been started: GameHandler.startGame(SOCGame) has been called and game play has begun.
protected  int numberOfUsers
          total number of users
private  int numRobotOnlyGamesRemaining
          Number of robot-only games not yet started (optional feature).
static int PLAYER_NAME_MAX_LENGTH
          Maximum permitted player name length, default 20 characters.
static java.lang.String PRACTICE_STRINGPORT
          For local practice games (pipes, not TCP), the name of the pipe.
static boolean printedUsageAlready
          Track whether we've already called printUsage(boolean).
static java.lang.String PROP_JSETTLERS_ACCOUNTS_ADMINS
          Property jsettlers.accounts.admins to restrict which usernames can create accounts.
static java.lang.String PROP_JSETTLERS_ACCOUNTS_OPEN
          Boolean property jsettlers.accounts.open to permit open registration.
static java.lang.String PROP_JSETTLERS_ACCOUNTS_REQUIRED
          Boolean property jsettlers.accounts.required to require that all players have user accounts.
static java.lang.String PROP_JSETTLERS_ALLOW_DEBUG
          Property jsettlers.allow.debug to permit debug commands over TCP.
static java.lang.String PROP_JSETTLERS_BOTS_BOTGAMES_TOTAL
          Property jsettlers.bots.botgames.total will start robot-only games, a few at a time, until this many have been played.
static java.lang.String PROP_JSETTLERS_BOTS_COOKIE
          String property jsettlers.bots.cookie to specify the robot connect cookie.
static java.lang.String PROP_JSETTLERS_BOTS_SHOWCOOKIE
          Boolean property jsettlers.bots.showcookie to print the robot connect cookie to System.err during server startup.
static java.lang.String PROP_JSETTLERS_CLI_MAXCREATECHANNELS
          Property jsettlers.client.maxcreatechannels to limit the amount of chat channels that a client can create at once.
static java.lang.String PROP_JSETTLERS_CLI_MAXCREATEGAMES
          Property jsettlers.client.maxcreategames to limit the amount of games that a client can create at once.
static java.lang.String PROP_JSETTLERS_CONNECTIONS
          Property jsettlers.connections to specify the maximum number of connections allowed.
static java.lang.String PROP_JSETTLERS_GAMEOPT_PREFIX
          Property prefix jsettlers.gameopt. to specify game option defaults in a server properties file.
static java.lang.String PROP_JSETTLERS_PORT
          Property jsettlers.port to specify the port the server listens on.
static java.lang.String PROP_JSETTLERS_STARTROBOTS
          Property jsettlers.startrobots to start some robots when the server starts.
private  java.util.Properties props
          Properties for the server, or empty if that constructor wasn't used.
static java.lang.String[] PROPS_LIST
          List and descriptions of all available JSettlers properties, such as PROP_JSETTLERS_PORT and SOCDBHelper.PROP_JSETTLERS_DB_URL.
private  java.util.Random rand
          So we can get random numbers.
static int ROBOT_FORCE_ENDTURN_SECONDS
          Force robot to end their turn after this many seconds of inactivity.
static SOCRobotParameters ROBOT_PARAMS_DEFAULT
          Robot default parameters; copied for each newly connecting robot.
static SOCRobotParameters ROBOT_PARAMS_SMARTER
          Smarter robot default parameters.
private  java.lang.String robotCookie
          Randomly generated cookie string required for robot clients to connect and identify as bots using SOCImARobot.
protected  java.util.Hashtable<java.lang.String,java.util.Vector<SOCReplaceRequest>> robotDismissRequests
          table of requestst for robots to leave games
protected  java.util.Hashtable<java.lang.String,java.util.Vector<StringConnection>> robotJoinRequests
          table of requests for robots to join games
protected  java.util.Vector<StringConnection> robots
          A list of robot StringConnections connected to this server.
static java.lang.String SERVERNAME
          Name used when sending messages from the server.
(package private)  SOCServerRobotPinger serverRobotPinger
          server robot pinger
static int SOC_MAXCONN_DEFAULT
          Default maximum number of connected clients (30; maxConnections field).
static int SOC_PORT_DEFAULT
          Default tcp port number 8880 to listen, and for client to connect to remote server.
static java.lang.String SOC_SERVER_PROPS_FILENAME
          Filename "jsserver.properties" for the optional server startup properties file.
static int SOC_STARTROBOTS_DEFAULT
          Default number of bots to start (7; PROP_JSETTLERS_STARTROBOTS property).
private  java.lang.String srvShutPassword
          JM temp - generated password to allow clean server shutdown.
private  long srvShutPasswordExpire
          JM temp - expiration of srvShutPassword.
protected  long startTime
          the time that this server was started
private static java.io.BufferedReader sysInBuffered
          Buffered System.in for readPassword(String), is null until first call to that method.
private  java.lang.String utilityModeMessage
          If hasUtilityModeProp, an optional status message to print before exiting, or null.
 
Fields inherited from class soc.server.genericServer.Server
CLI_CONN_PRINT_TIMER_FIRE_MS, CLI_DISCON_PRINT_TIMER_FIRE_MS, CLI_VERSION_SET_CONSIS_CHECK_MINUTES, CLI_VERSION_SET_CONSIS_CHECK_QUICK_COUNT, cliConnDisconPrintsPending, conns, error, inQueue, numberCurrentConnections, numberOfConnections, port, strSocketName, unnamedConns, utilTimer
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
SOCServer(int p, int mc, java.lang.String databaseUserName, java.lang.String databasePassword)
          Create a Settlers of Catan server listening on TCP port p.
SOCServer(int p, java.util.Properties props)
          Create a Settlers of Catan server listening on TCP port p.
SOCServer(java.lang.String s, int mc, java.lang.String databaseUserName, java.lang.String databasePassword)
          Create a Settlers of Catan server listening on local stringport s.
 
Method Summary
private  boolean authenticateUser(StringConnection c, java.lang.String userName, java.lang.String password)
          authenticate the user: see if the user is in the db, if so then check the password.
private  int authOrRejectClientUser(StringConnection c, java.lang.String msgUser, java.lang.String msgPass, int cliVers, boolean doNameConnection, boolean allowTakeover)
          Check that the username and password (if any) is okay: Length versus PLAYER_NAME_MAX_LENGTH, name in use but not timed out versus takeover, etc.
 void checkForExpiredGames(long currentTimeMillis)
          check for games that have expired and destroy them.
 void checkForExpiredTurns(long currentTimeMillis)
          Check all games for robot turns that have expired, and end that turn, or stop waiting for non-current-player robot actions (discard picks, etc).
private static java.lang.String checkNickname_getRetryText(int nameTimeout)
          For a nickname that seems to be in use, build a text message with the time remaining before someone can attempt to take over that nickname.
private static java.lang.String checkNickname_getVersionText(int needsVersion)
          For a nickname that seems to be in use, build a text message with the minimum version number needed to take over that nickname.
private  int checkNickname(java.lang.String n, StringConnection newc, boolean withPassword)
          Check if a nickname is okay, and, if they're already logged in, whether a new replacement connection can "take over" the existing one.
static java.util.List<Triple> checkScenarioOpts(java.util.Map<?,?> opts, boolean optsAreProps, java.lang.String scName)
          When a server's properties or command line contain a default scenario (game option "SC"), check that the scenario is known and that its game options don't conflict with any others specified in the properties or command line.
private static void clearBuffer(java.lang.StringBuilder sb)
          Clear the contents of a StringBuffer by setting to ' ' each character in its current StringBuilder.length().
static boolean clientHasLocalizedStrs_gameScenarios(StringConnection c)
          Does this client's locale have localized SOCScenario names and descriptions? Checks these conditions: c.scd.wantsI18N flag is set: Has locale, new-enough version, has requested I18N strings (see that flag's javadocs).
 void connectToChannel(StringConnection c, java.lang.String ch)
          Adds a connection to a chat channel.
 boolean connectToGame(StringConnection c, java.lang.String gaName, java.util.Map<java.lang.String,SOCGameOption> gaOpts)
          Adds a connection to a game, unless they're already a member.
private  SOCGame createGameAndBroadcast(StringConnection c, java.lang.String gaName, java.util.Map<java.lang.String,SOCGameOption> gaOpts, int gVers, boolean isBotsOnly, boolean hasGameListMonitor)
          Create a new game, and announce it with a broadcast.
private  void createOrJoinGameIfUserOK(StringConnection c, java.lang.String msgUser, java.lang.String msgPass, java.lang.String gameName, java.util.Map<java.lang.String,SOCGameOption> gameOpts)
          Check username/password and create new game, or join game.
private  boolean debug_printPieceDiceNumbers_pl(SOCPlayer pl, int roll, SOCBoard board, java.lang.String pieceType, java.util.Enumeration<? extends SOCPlayingPiece> pe)
          Temporary debugging; for 1 player.
(package private)  void debug_printPieceDiceNumbers(SOCGame ga, java.lang.String message)
          Temporary debugging; call when "no player gets anything" will be printed after a roll.
protected  void destroyChannel(java.lang.String ch)
          Destroy a channel and then clean up related data, such as the owner's count of SOCClientData.getcurrentCreatedChannels().
 void destroyGame(java.lang.String gm)
          Destroy a game and clean up related data, such as the owner's count of SOCClientData.getCurrentCreatedGames().
 void destroyGameAndBroadcast(java.lang.String gaName, java.lang.String descForStackTrace)
          Destroy a game and then broadcast its deletion, including lock handling.
(package private)  void gameOverIncrGamesFinishedCount()
          Increment the "number of games finished" server-statistics field.
private  java.lang.String generateRobotCookie()
          Generate and return a string to use for robotCookie.
private static boolean getConfigBoolProperty(java.util.Properties props, java.lang.String pName, boolean pDefault)
          Get and parse a boolean config property, or use its default instead.
private static int getConfigIntProperty(java.util.Properties props, java.lang.String pName, int pDefault)
          Get and parse an integer config property, or use its default instead.
(package private)  StringConnection getConnection(java.lang.String connKey)
          Given a connection's key, return the connected client.
 SOCGame getGame(java.lang.String gaName)
          Given a game name on this server, return its game object.
 java.util.Collection<java.lang.String> getGameNames()
          Used when SOCPlayerClient is also hosting games.
 java.util.Map<java.lang.String,SOCGameOption> getGameOptions(java.lang.String gm)
          Given a game name on this server, return its game options.
 int getGameState(java.lang.String gm)
          Given a game name on this server, return its state.
 java.lang.String getUtilityModeMessage()
          If hasUtilityModeProperty(), get the optional status message to print before exiting.
private  void handleAUTHREQUEST(StringConnection c, SOCAuthRequest mes)
          Handle the optional "authentication request" message.
private  void handleCHANGEFACE(StringConnection c, SOCChangeFace mes)
          handle "change face" message.
private  void handleCREATEACCOUNT(StringConnection c, SOCCreateAccount mes)
          handle "create account" message
private  void handleGAMEOPTIONGETDEFAULTS(StringConnection c, SOCGameOptionGetDefaults mes)
          process the "game option get defaults" message.
private  void handleGAMEOPTIONGETINFOS(StringConnection c, SOCGameOptionGetInfos mes)
          process the "game option get infos" message; reply with the info, with one GAMEOPTIONINFO message per option keyname.
private  void handleGAMETEXTMSG(StringConnection c, SOCGameTextMsg gameTextMsgMes)
          Handle game text messages, including debug commands.
private  void handleIMAROBOT(StringConnection c, SOCImARobot mes)
          Handle the "I'm a robot" message.
private  void handleJOIN(StringConnection c, SOCJoin mes)
          Handle the "join a channel" message.
private  void handleJOINGAME(StringConnection c, SOCJoinGame mes)
          Handle the "join a game" message: Join or create a game.
private  void handleLEAVE(StringConnection c, SOCLeave mes)
          Handle the "leave a channel" message
private  void handleLEAVEGAME_maybeGameReset_oldRobot(java.lang.String gaName)
          Handle an unattached robot saying it is leaving the game, from handleLEAVEGAME(StringConnection, SOCLeaveGame).
private  void handleLEAVEGAME_member(StringConnection c, java.lang.String gaName)
          Handle a member leaving the game, from handleLEAVEGAME(StringConnection, SOCLeaveGame).
private  void handleLEAVEGAME(StringConnection c, SOCLeaveGame mes)
          Handle the "leave game" message
private  void handleLOCALIZEDSTRINGS(StringConnection c, SOCLocalizedStrings mes)
          Handle client request for localized i18n strings for game items.
private  void handleNEWGAMEWITHOPTIONSREQUEST(StringConnection c, SOCNewGameWithOptionsRequest mes)
          process the "new game with options request" message.
private  void handleRESETBOARDREQUEST(StringConnection c, SOCResetBoardRequest mes)
          handle "reset-board request" message.
private  void handleRESETBOARDVOTE(StringConnection c, SOCResetBoardVote mes)
          handle message of player's vote for a "reset-board" request.
private  void handleSCENARIOINFO(StringConnection c, SOCScenarioInfo mes)
          Process client request for updated SOCScenario info.
private  void handleSERVERPING(StringConnection c, SOCServerPing mes)
          Handle the client's echo of a SOCMessage.SERVERPING.
private  void handleSETSEATLOCK(StringConnection c, SOCSetSeatLock mes)
          handle "set seat lock" message.
private  void handleSITDOWN(StringConnection c, SOCSitDown mes)
          handle "sit down" message
private  void handleSTARTGAME(StringConnection c, SOCStartGame mes, int botsOnly_maxBots)
          handle "start game" message.
private  void handleVERSION(StringConnection c, SOCVersion mes)
          Handle the "version" message, client's version report.
 boolean hasUtilityModeProperty()
          True if the server was constructed with a property or command line argument which is used to run the server in Utility Mode instead of Server Mode.
private  void impl_messageToGameKeyedSpecial(SOCGame ga, boolean takeMon, java.util.List<StringConnection> members, StringConnection ex, boolean fmtSpecial, java.lang.String key, java.lang.Object... params)
          Implement messageToGameKeyedSpecial and messageToGameKeyedSpecialExcept.
private static boolean init_checkScenarioOpts(java.util.Map<?,?> opts, boolean optsAreProps, java.lang.String srcDesc, java.lang.String scName, java.lang.String scNameSrcDesc)
          During startup, call checkScenarioOpts(Map, boolean, String) and print any warnings it returns to System.err.
private static void init_propsSetGameopts(java.util.Properties pr)
          Set game option defaults from any jsettlers.gameopt.* server properties found.
private  void init_resetUserPassword(java.lang.String uname)
          If command line contains --pw-reset=username, prompt for and change that user's password.
private  void initSocServer(java.lang.String databaseUserName, java.lang.String databasePassword, java.util.Properties props)
          Common init for all constructors.
private  boolean isUserDBUserAdmin(java.lang.String uname, boolean requireList)
          Is this username on the databaseUserAdmins whitelist, if that whitelist is being used?
private  void joinGame(SOCGame gameData, StringConnection c, boolean isReset, boolean isTakingOver)
          Client has been approved to join game; send the entire state of the game to client.
 void leaveAllChannels(StringConnection c)
          Connection c is leaving the server; remove from all channels it was in.
 void leaveAllGames(StringConnection c)
          Connection c is leaving the server; remove from all games it was in.
 boolean leaveChannel(StringConnection c, java.lang.String ch, boolean destroyIfEmpty, boolean channelListLock)
          Connection c leaves the channel ch.
 void leaveConnection(StringConnection c)
          things to do when the connection c leaves
 boolean leaveGame(StringConnection c, java.lang.String gm, boolean destroyIfEmpty, boolean gameListLock)
          the connection c leaves the game gm.
static java.util.List<java.lang.String> localizeGameScenarios(java.util.Locale loc, java.util.Collection<java.lang.String> scKeys, boolean checkUnknowns_skipFirst, SOCClientData scd)
          Get localized strings for known SOCScenarios.
static java.util.Map<java.lang.String,SOCGameOption> localizeKnownOptions(java.util.Locale loc, boolean updateStaticKnownOpts)
          Given a StringManager (for a client's locale), return all known game options, localizing the descriptive names if available.
static void main(java.lang.String[] args)
          Starting the server from the command line
 void messageToChannel(java.lang.String ch, SOCMessage mes)
          Send a message to the given channel
 void messageToChannelWithMon(java.lang.String ch, SOCMessage mes)
          Send a message to the given channel WARNING: MUST HAVE THE gameList.takeMonitorForChannel(ch) before calling this method
 void messageToGame(java.lang.String ga, SOCMessage mes)
          Send a message to the given game.
 void messageToGame(java.lang.String ga, java.lang.String txt)
          Send a server text message to the given game.
 void messageToGameExcept(java.lang.String gn, StringConnection ex, SOCMessage mes, boolean takeMon)
          Send a message to all the connections in a game excluding one.
 void messageToGameExcept(java.lang.String gn, StringConnection ex, java.lang.String txt, boolean takeMon)
          Send a server text message to all the connections in a game excluding one.
 void messageToGameExcept(java.lang.String gn, java.util.Vector<StringConnection> ex, SOCMessage mes, boolean takeMon)
          Send a message to all the connections in a game excluding some.
 void messageToGameForVersions(SOCGame ga, int vmin, int vmax, SOCMessage mes, boolean takeMon)
          Send a message to all the connections in a game in a certain version range.
 void messageToGameForVersionsExcept(SOCGame ga, int vmin, int vmax, StringConnection ex, SOCMessage mes, boolean takeMon)
          Send a message to all the connections in a game in a certain version range, excluding one.
 void messageToGameKeyed(SOCGame ga, boolean takeMon, java.lang.String key)
          Send a localized SOCGameServerText game text message to a game.
 void messageToGameKeyed(SOCGame ga, boolean takeMon, java.lang.String key, java.lang.Object... params)
          Send a localized SOCGameServerText game text message (with parameters) to a game.
 void messageToGameKeyedSpecial(SOCGame ga, boolean takeMon, java.lang.String key, java.lang.Object... params)
          Send a localized SOCGameServerText game text message (with parameters) to a game, optionally with special formatting like {0,rsrcs}, optionally excluding one connection.
 void messageToGameKeyedSpecialExcept(SOCGame ga, boolean takeMon, java.util.List<StringConnection> ex, java.lang.String key, java.lang.Object... params)
          Send a localized SOCGameServerText game text message (with parameters) to a game, optionally with special formatting like {0,rsrcs}, optionally excluding some connections.
 void messageToGameKeyedSpecialExcept(SOCGame ga, boolean takeMon, StringConnection ex, java.lang.String key, java.lang.Object... params)
          Send a localized SOCGameServerText game text message (with parameters) to a game, optionally with special formatting like {0,rsrcs}, optionally excluding one connection.
 void messageToGameKeyedType(SOCGame ga, SOCKeyedMessage msg, boolean takeMon)
          Send a game a message containing data fields and also a text field to be localized.
 void messageToGameUrgent(java.lang.String ga, java.lang.String mes)
          Send an urgent SOCGameTextMsg to the given game.
 void messageToGameWithMon(java.lang.String ga, SOCMessage mes)
          Send a message to the given game.
 void messageToPlayer(StringConnection c, SOCMessage mes)
          Send a message to a player and record it
 void messageToPlayer(StringConnection c, java.lang.String ga, java.lang.String txt)
          Send a SOCGameServerText or SOCGameTextMsg game text message to a player.
 void messageToPlayerKeyed(StringConnection c, java.lang.String gaName, java.lang.String key)
          Send a localized SOCGameServerText game text message to a player.
 void messageToPlayerKeyed(StringConnection c, java.lang.String gaName, java.lang.String key, java.lang.Object... args)
          Send a localized SOCGameServerText game text message with arguments to a player.
 void messageToPlayerKeyedSpecial(StringConnection c, SOCGame ga, java.lang.String key, java.lang.Object... args)
          Send a localized SOCGameServerText game text message with arguments to a player, with special formatting like {0,rsrcs}.
private  void nameConnection(StringConnection c, boolean isReplacing)
          Name a current connection to the system, which may replace an older connection.
 boolean newConnection1(StringConnection c)
          Things to do when a new connection comes.
protected  void newConnection2(StringConnection c)
          Send welcome messages (server version and features, and the lists of channels and games (SOCChannels, SOCGames)) when a new connection comes, part 2 - c has been accepted and added to a connection list.
static java.util.Properties parseCmdline_DashedArgs(java.lang.String[] args)
          Quick-and-dirty parsing of command-line arguments with dashes.
static SOCGameOption parseCmdline_GameOption(SOCGameOption op, java.lang.String optRaw, java.util.HashMap<java.lang.String,java.lang.String> optsAlreadySet)
          Quick-and-dirty command line parsing of a game option.
private  void printAuditMessage(java.lang.String req, java.lang.String msg, java.lang.String obj, java.util.Date at, java.lang.String reqHost)
          Print a security-action audit message to System.out in a standard format.
static void printGameOptions()
          Print out the list of possible game options, and current values.
static void printUsage(boolean longFormat)
          Print command line parameter information, including options ("--" / "-").
 void processCommand(java.lang.String s, StringConnection c)
          Treat the incoming messages.
private  void processDebugCommand_gameStats(StringConnection c, java.lang.String gaName, SOCGame gameData, boolean isCheckTime)
          Print time-remaining and other game stats.
private  void processDebugCommand_who(StringConnection c, SOCGame ga, java.lang.String cmdText)
          Process unprivileged command *WHO* to show members of current game, or privileged *WHO* gameName|all|* to show all connected clients or some other game's members.
 boolean processDebugCommand(StringConnection debugCli, java.lang.String ga, java.lang.String dcmd, java.lang.String dcmdU)
          Process a debug command, sent by the "debug" client/player.
 boolean processFirstCommand(java.lang.String str, StringConnection con)
          Callback to process the client's first message command specially.
private static java.lang.StringBuilder readPassword(java.lang.String prompt)
          Read a password from the console; currently used for password reset.
private  void readyGameAskRobotsJoin(SOCGame ga, StringConnection[] robotSeats, int maxBots)
          Fill all the unlocked empty seats with robots, by asking them to join.
protected  void recordGameEvent(java.lang.String gameName, java.lang.String event)
          record events that happen during the game
private  void resetBoardAndNotify_finish(SOCGameBoardReset reBoard, SOCGame reGame)
          Complete steps 3 - n of the board-reset process outlined in resetBoardAndNotify(String, int), after any robots have left the old game.
private  void resetBoardAndNotify(java.lang.String gaName, int requestingPlayer)
          Reset the board, to a copy with same players but new layout.
(package private)  void resetBoardVoteNotifyOne(SOCGame ga, int pn, java.lang.String plName, boolean vyes)
          "Reset-board" request: Register one player's vote, and let game members know.
(package private)  int[] robotShuffleForJoin()
          shuffle the indexes to distribute load among robots
 void sendGameList(StringConnection c, int prevVers)
          Send the entire list of games to this client; this is sent once per connecting client.
(package private)  void sendGameScenarioInfo(java.lang.String scKey, SOCScenario sc, StringConnection c, boolean stringsOnly)
          If needed, send this scenario's updated info and i18n localized short/long description strings to the client.
 void serverUp()
          Callback to take care of things when server comes up, after the server socket is bound and listening, in the main thread.
(package private)  boolean setClientVersSendGamesOrReject(StringConnection c, int cvers, java.lang.String clocale, boolean isKnown)
          Set client's version and locale, and check against minimum required version CLI_VERSION_MIN.
 boolean setupLocalRobots(int numFast, int numSmart)
          Set up some robot opponents, running in our JVM for operator convenience.
private  void sitDown(SOCGame ga, StringConnection c, int pn, boolean robot, boolean isReset)
          This player is sitting down at the game.
private  void startRobotOnlyGames(boolean hasGameListMonitor)
          Start a few robot-only games if numRobotOnlyGamesRemaining > 0.
 void stopServer()
          The server is being cleanly stopped.
 void stopServer(java.lang.String stopMsg)
          The server is being cleanly stopped.
protected  void storeGameScores(SOCGame ga)
          Save game stats in the database.
 
Methods inherited from class soc.server.genericServer.Server
addConnection, broadcast, broadcastToVers, clientVersionAdd, clientVersionRem, getConnection, getConnections, getCurrentConnectionCount, getLocalSocketName, getMaxConnectedCliVersion, getMinConnectedCliVersion, getNamedConnectionCount, getPort, isCliVersionConnected, isUp, nameConnection, removeConnection, removeConnectionCleanup, run, serverDown, treat
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SOC_PORT_DEFAULT

public static final int SOC_PORT_DEFAULT
Default tcp port number 8880 to listen, and for client to connect to remote server. Should match SOCPlayerClient.SOC_PORT_DEFAULT.

8880 is the default SOCPlayerClient port since jsettlers 1.0.4, per cvs history.

Since:
1.1.09
See Also:
Constant Field Values

SOC_STARTROBOTS_DEFAULT

public static final int SOC_STARTROBOTS_DEFAULT
Default number of bots to start (7; PROP_JSETTLERS_STARTROBOTS property).

Since:
1.1.19
See Also:
Constant Field Values

SOC_MAXCONN_DEFAULT

public static final int SOC_MAXCONN_DEFAULT
Default maximum number of connected clients (30; maxConnections field). Always at least 20 more than SOC_STARTROBOTS_DEFAULT.

Since:
1.1.15

SOC_SERVER_PROPS_FILENAME

public static final java.lang.String SOC_SERVER_PROPS_FILENAME
Filename "jsserver.properties" for the optional server startup properties file.

Since:
1.1.20
See Also:
Constant Field Values

PROP_JSETTLERS_PORT

public static final java.lang.String PROP_JSETTLERS_PORT
Property jsettlers.port to specify the port the server listens on.

Since:
1.1.09
See Also:
Constant Field Values

PROP_JSETTLERS_CONNECTIONS

public static final java.lang.String PROP_JSETTLERS_CONNECTIONS
Property jsettlers.connections to specify the maximum number of connections allowed. Remember that robots count against this limit.

Since:
1.1.09
See Also:
Constant Field Values

PROP_JSETTLERS_BOTS_COOKIE

public static final java.lang.String PROP_JSETTLERS_BOTS_COOKIE
String property jsettlers.bots.cookie to specify the robot connect cookie. (By default a random one is generated.) The value must pass SOCMessage.isSingleLineAndSafe(String): Must not contain the '|' or ',' characters.

Since:
1.1.19
See Also:
PROP_JSETTLERS_BOTS_SHOWCOOKIE, Constant Field Values

PROP_JSETTLERS_BOTS_SHOWCOOKIE

public static final java.lang.String PROP_JSETTLERS_BOTS_SHOWCOOKIE
Boolean property jsettlers.bots.showcookie to print the robot connect cookie to System.err during server startup. (The default is N, the cookie is not printed.)

Format is:

Robot cookie: 03883269284ee140cb907ea203846333

Since:
1.1.19
See Also:
Constant Field Values

PROP_JSETTLERS_BOTS_BOTGAMES_TOTAL

public static final java.lang.String PROP_JSETTLERS_BOTS_BOTGAMES_TOTAL
Property jsettlers.bots.botgames.total will start robot-only games, a few at a time, until this many have been played. (The default is 0.)

If this property's value != 0, a robots-only game can be started with the *STARTBOTGAME* debug command. This can be used to test the bots with any given combination of game options and scenarios. To permit starting such games without also starting any at server startup, use a value less than 0.

Since:
2.0.00
See Also:
Constant Field Values

PROP_JSETTLERS_STARTROBOTS

public static final java.lang.String PROP_JSETTLERS_STARTROBOTS
Property jsettlers.startrobots to start some robots when the server starts. (The default is SOC_STARTROBOTS_DEFAULT.)

30% will be "smart" robots, the other 70% will be "fast" robots. Remember that robots count against the max connections limit.

Before v1.1.19 the default was 0, no robots were started by default.

Since:
1.1.09
See Also:
PROP_JSETTLERS_BOTS_BOTGAMES_TOTAL, Constant Field Values

PROP_JSETTLERS_ACCOUNTS_OPEN

public static final java.lang.String PROP_JSETTLERS_ACCOUNTS_OPEN
Boolean property jsettlers.accounts.open to permit open registration. If this property is Y, anyone can create their own user accounts. Otherwise only existing users can create new accounts after the first account.

The default is N in version 1.1.19 and newer; previously was Y by default. To require that all players have accounts in the database, see PROP_JSETTLERS_ACCOUNTS_REQUIRED. To restrict which users can create accounts, see PROP_JSETTLERS_ACCOUNTS_ADMINS.

If this field is Y when the server is initialized, the server calls features.add(SOCServerFeatures.FEAT_OPEN_REG).

Since:
1.1.19
See Also:
Constant Field Values

PROP_JSETTLERS_ACCOUNTS_REQUIRED

public static final java.lang.String PROP_JSETTLERS_ACCOUNTS_REQUIRED
Boolean property jsettlers.accounts.required to require that all players have user accounts. If this property is Y, a jdbc database is required and all users must have an account and password in the database. If a client tries to join or create a game or channel without providing a password, they will be sent SOCStatusMessage.SV_PW_REQUIRED. This property implies SOCServerFeatures.FEAT_ACCTS.

The default is N.

If PROP_JSETTLERS_ACCOUNTS_OPEN is used, anyone can create their own account (Open Registration). Otherwise see PROP_JSETTLERS_ACCOUNTS_ADMINS for the list of user admin accounts.

Since:
1.1.19
See Also:
Constant Field Values

PROP_JSETTLERS_ACCOUNTS_ADMINS

public static final java.lang.String PROP_JSETTLERS_ACCOUNTS_ADMINS
Property jsettlers.accounts.admins to restrict which usernames can create accounts. If this property is set, it is a comma-separated list of usernames (nicknames), and a user must authenticate and be on this whitelist to create user accounts.

If any other user requests account creation, the server will reply with SOCStatusMessage.SV_ACCT_NOT_CREATED_DENIED.

The server doesn't require or check at startup that the named accounts all already exist, this is just a list of names.

This property can't be set at the same time as PROP_JSETTLERS_ACCOUNTS_OPEN, they ask for opposing security policies.

Since:
1.1.19
See Also:
Constant Field Values

PROP_JSETTLERS_ALLOW_DEBUG

public static final java.lang.String PROP_JSETTLERS_ALLOW_DEBUG
Property jsettlers.allow.debug to permit debug commands over TCP. (The default is N; to allow, set to Y)

Since:
1.1.14
See Also:
Constant Field Values

PROP_JSETTLERS_CLI_MAXCREATEGAMES

public static final java.lang.String PROP_JSETTLERS_CLI_MAXCREATEGAMES
Property jsettlers.client.maxcreategames to limit the amount of games that a client can create at once. (The default is 5.) Once a game is completed and deleted (all players leave), they can create another. Set this to -1 to disable it; 0 will disallow any game creation. This limit is ignored for practice games.

Since:
1.1.10
See Also:
CLIENT_MAX_CREATE_GAMES, Constant Field Values

PROP_JSETTLERS_CLI_MAXCREATECHANNELS

public static final java.lang.String PROP_JSETTLERS_CLI_MAXCREATECHANNELS
Property jsettlers.client.maxcreatechannels to limit the amount of chat channels that a client can create at once. (The default is 2.) Once a channel is deleted (all members leave), they can create another. Set this to -1 to disable it; 0 will disallow any chat channel creation.

Since:
1.1.10
See Also:
CLIENT_MAX_CREATE_CHANNELS, SOCServerFeatures.FEAT_CHANNELS, Constant Field Values

PROP_JSETTLERS_GAMEOPT_PREFIX

public static final java.lang.String PROP_JSETTLERS_GAMEOPT_PREFIX
Property prefix jsettlers.gameopt. to specify game option defaults in a server properties file. Option names are case-insensitive past this prefix. Syntax for default value is the same as on the command line, for example:
 jsettlers.gameopt.RD=y
 jsettlers.gameopt.n7=t7

See parseCmdline_DashedArgs(String[]) for how game option properties are checked at startup.

Since:
1.1.20
See Also:
Constant Field Values

PROPS_LIST

public static final java.lang.String[] PROPS_LIST
List and descriptions of all available JSettlers properties, such as PROP_JSETTLERS_PORT and SOCDBHelper.PROP_JSETTLERS_DB_URL.

Each property name is followed in the array by a brief description: [0] is a property, [1] is its description, [2] is the next property, etc. (This was added in 1.1.13 for printUsage(boolean)}.

Since:
1.1.09

SERVERNAME

public static final java.lang.String SERVERNAME
Name used when sending messages from the server.

See Also:
Constant Field Values

CLI_VERSION_MIN

public static final int CLI_VERSION_MIN
Minimum required client version, to connect and play a game. Same format as Version.versionNumber(). Currently there is no enforced minimum (0000).

See Also:
setClientVersSendGamesOrReject(StringConnection, int, String, boolean), Constant Field Values

CLI_VERSION_MIN_DISPLAY

public static final java.lang.String CLI_VERSION_MIN_DISPLAY
Minimum required client version, in "display" form, like "1.0.00". Currently there is no minimum.

See Also:
setClientVersSendGamesOrReject(StringConnection, int, String, boolean), Constant Field Values

CLI_VERSION_ASSUMED_GUESS

public static final int CLI_VERSION_ASSUMED_GUESS
If client never tells us their version, assume they are version 1.0.0 (1000).

Since:
1.1.06
See Also:
CLI_VERSION_TIMER_FIRE_MS, handleJOINGAME(StringConnection, SOCJoinGame), Constant Field Values

CLI_VERSION_TIMER_FIRE_MS

public static final int CLI_VERSION_TIMER_FIRE_MS
Client version is guessed after this many milliseconds (1200) if the client hasn't yet sent it to us.

Since:
1.1.06
See Also:
CLI_VERSION_ASSUMED_GUESS, Constant Field Values

GAME_TIME_EXPIRE_WARN_MINUTES

public static int GAME_TIME_EXPIRE_WARN_MINUTES
If game will expire in this or fewer minutes, warn the players. Default is 10. Must be at least twice the sleep-time in SOCGameTimeoutChecker.run(). The game expiry time is set at game creation in SOCGameListAtServer.createGame(String, String, String, Map, GameHandler).

If you update this field, also update GAME_TIME_EXPIRE_CHECK_MINUTES.

Before v2.0.00 this field was named GAME_EXPIRE_WARN_MINUTES.

See Also:
checkForExpiredGames(long), SOCGameTimeoutChecker.run(), SOCGameListAtServer.GAME_TIME_EXPIRE_MINUTES, GAME_TIME_EXPIRE_ADDTIME_MINUTES

GAME_TIME_EXPIRE_CHECK_MINUTES

public static int GAME_TIME_EXPIRE_CHECK_MINUTES
Sleep time (minutes) between checks for expired games in SOCGameTimeoutChecker.run(). Default is 5 minutes. Must be at most half of GAME_TIME_EXPIRE_WARN_MINUTES so the user has time to react after seeing the warning.

Since:
2.0.00

GAME_TIME_EXPIRE_ADDTIME_MINUTES

public static final int GAME_TIME_EXPIRE_ADDTIME_MINUTES
Amount of time to add (30 minutes) when the *ADDTIME* command is used by a player.

Since:
1.1.20
See Also:
GAME_TIME_EXPIRE_WARN_MINUTES, Constant Field Values

ROBOT_FORCE_ENDTURN_SECONDS

public static int ROBOT_FORCE_ENDTURN_SECONDS
Force robot to end their turn after this many seconds of inactivity. Default is 8.

Since:
1.1.11
See Also:
checkForExpiredTurns(long)

GAME_NAME_MAX_LENGTH

public static int GAME_NAME_MAX_LENGTH
Maximum permitted game name length, default 30 characters. Before 1.1.13, the default maximum was 20 characters.

Since:
1.1.07
See Also:
createOrJoinGameIfUserOK(StringConnection, String, String, String, Map)

PLAYER_NAME_MAX_LENGTH

public static int PLAYER_NAME_MAX_LENGTH
Maximum permitted player name length, default 20 characters. The client already truncates to 20 characters in SOCPlayerClient.getValidNickname.

Since:
1.1.07
See Also:
createOrJoinGameIfUserOK(StringConnection, String, String, String, Map)

CLIENT_MAX_CREATE_GAMES

public static int CLIENT_MAX_CREATE_GAMES
Maximum number of games that a client can create at the same time (default 5). Once this limit is reached, the client must delete a game before creating a new one. Set this to -1 to disable it; 0 will disallow any game creation. This limit is ignored for practice games.

Since:
1.1.10
See Also:
PROP_JSETTLERS_CLI_MAXCREATEGAMES

CLIENT_MAX_CREATE_CHANNELS

public static int CLIENT_MAX_CREATE_CHANNELS
Maximum number of chat channels that a client can create at the same time (default 2). Once this limit is reached, the client must delete a channel before creating a new one. Set this to -1 to disable it; 0 will disallow any chat channel creation.

If this field is nonzero when the server is initialized, the server calls features.add(SOCServerFeatures.FEAT_CHANNELS). If the field value is changed afterwards, that affects new clients joining the server but does not clear FEAT_CHANNELS from the features list.

Since:
1.1.10
See Also:
PROP_JSETTLERS_CLI_MAXCREATECHANNELS

PRACTICE_STRINGPORT

public static java.lang.String PRACTICE_STRINGPORT
For local practice games (pipes, not TCP), the name of the pipe. Used to distinguish practice vs "real" games.

See Also:
LocalStringConnection

AUTH_OR_REJECT__FAILED

private static final int AUTH_OR_REJECT__FAILED
authOrRejectClientUser(....) result: Failed authentication, failed name validation, or name is already logged in and that connection hasn't timed out yet

Since:
1.1.19
See Also:
Constant Field Values

AUTH_OR_REJECT__OK

private static final int AUTH_OR_REJECT__OK
authOrRejectClientUser(....) result: Authentication succeeded

Since:
1.1.19
See Also:
Constant Field Values

AUTH_OR_REJECT__TAKING_OVER

private static final int AUTH_OR_REJECT__TAKING_OVER
authOrRejectClientUser(....) result: Authentication succeeded, is taking over another connection

Since:
1.1.19
See Also:
Constant Field Values

rand

private java.util.Random rand
So we can get random numbers.


maxConnections

protected int maxConnections
Maximum number of connections allowed. Remember that robots count against this limit. Set with PROP_JSETTLERS_CONNECTIONS.


allowDebugUser

private boolean allowDebugUser
Is a debug user allowed to run commands listed in DEBUG_COMMANDS_HELP? Default is false. Set with PROP_JSETTLERS_ALLOW_DEBUG.

Note that all practice games are debug mode, for ease of debugging; to determine this, handleGAMETEXTMSG(StringConnection, SOCGameTextMsg) checks if the client is using LocalStringConnection to talk to the server.

Since:
1.1.14
See Also:
processDebugCommand(StringConnection, String, String, String)

props

private java.util.Properties props
Properties for the server, or empty if that constructor wasn't used. Property names are held in PROP_* and SOCDBHelper.PROP_* constants. Some properties activate optional features.

Since:
1.1.09
See Also:
SOCServer(int, Properties), PROPS_LIST, getConfigBoolProperty(Properties, String, boolean), getConfigIntProperty(Properties, String, int)

hasUtilityModeProp

private boolean hasUtilityModeProp
True if props contains a property which is used to run the server in Utility Mode instead of Server Mode. In Utility Mode the server reads its properties, initializes its database connection if any, and performs one task such as a password reset or table/index creation. It won't listen on a TCP port or start other threads.

For a list of Utility Mode properties, see hasUtilityModeProperty().

Since:
1.1.20
See Also:
utilityModeMessage

utilityModeMessage

private java.lang.String utilityModeMessage
If hasUtilityModeProp, an optional status message to print before exiting, or null.

Since:
1.1.20

features

private SOCServerFeatures features
Active optional server features, if any; see SOCServerFeatures constants for currently defined features. Features are activated through the command line or props.

Since:
1.1.19

handler

private final SOCGameHandler handler
Game type handler, currently shared by all game instances.

Since:
2.0.00

acctsNotOpenRegButNoUsers

private boolean acctsNotOpenRegButNoUsers
Server internal flag to indicate that user accounts are active, and authentication is required to create accounts, and there aren't any accounts in the database yet. (Server's active features include SOCServerFeatures.FEAT_ACCTS but not SOCServerFeatures.FEAT_OPEN_REG.) This flag is set at startup, instead of querying SOCDBHelper.countUsers() every time a client connects.

Used for signaling to SOCAccountClient that it shouldn't ask for a password when connecting to create the first account, by sending the client SOCServerFeatures.FEAT_OPEN_REG along with the actually active features.

The first successful account creation will clear this flag.

handleCREATEACCOUNT(StringConnection, SOCCreateAccount) does call countUsers() and requires auth if any account exists, even if this flag is set.

Since:
1.1.19

srvShutPassword

private java.lang.String srvShutPassword
JM temp - generated password to allow clean server shutdown. Must be used before srvShutPasswordExpire.

Since:
2.0.00

srvShutPasswordExpire

private long srvShutPasswordExpire
JM temp - expiration of srvShutPassword.

Since:
2.0.00

robotCookie

private java.lang.String robotCookie
Randomly generated cookie string required for robot clients to connect and identify as bots using SOCImARobot. It isn't sent encrypted and is a weak "shared secret". Generated in generateRobotCookie() unless the server is given PROP_JSETTLERS_BOTS_COOKIE at startup, which can set it to any string or to null if the property is empty.

The value must pass SOCMessage.isSingleLineAndSafe(String): Must not contain the '|' or ',' characters.

Since:
1.1.19

robots

protected java.util.Vector<StringConnection> robots
A list of robot StringConnections connected to this server.

See Also:
SOCLocalRobotClient.robotClients

ROBOT_PARAMS_DEFAULT

public static SOCRobotParameters ROBOT_PARAMS_DEFAULT
Robot default parameters; copied for each newly connecting robot. Changing this will not change parameters of any robots already connected.

See Also:
handleIMAROBOT(StringConnection, soc.message.SOCImARobot), SOCRobotDM

ROBOT_PARAMS_SMARTER

public static SOCRobotParameters ROBOT_PARAMS_SMARTER
Smarter robot default parameters. (For practice games; not referenced by server) Same as ROBOT_PARAMS_DEFAULT but with SMART_STRATEGY, not FAST_STRATEGY.

See Also:
ROBOT_PARAMS_DEFAULT, SOCRobotDM

hasStartupPrintAndExit

private static boolean hasStartupPrintAndExit
Did the command line include an option that prints some information (like --help or --version) and should exit, instead of starting the server? Set in parseCmdline_DashedArgs(String[]).

Since:
1.1.15

hasSetGameOptions

public static boolean hasSetGameOptions
Did the properties or command line include --option / -o to set game option values? Checked in constructors for possible stderr option-values printout.

Since:
1.1.07

MSG_NICKNAME_ALREADY_IN_USE

public static final java.lang.String MSG_NICKNAME_ALREADY_IN_USE
Status Message to send, nickname already logged into the system

See Also:
Constant Field Values

MSG_NICKNAME_ALREADY_IN_USE_WAIT_TRY_AGAIN

public static final java.lang.String MSG_NICKNAME_ALREADY_IN_USE_WAIT_TRY_AGAIN
Status Message to send, nickname already logged into the system. Prepend to MSG_NICKNAME_ALREADY_IN_USE. The "take over" option is used for reconnect when a client loses connection, and server doesn't realize it. A new connection can "take over" the name after a minute's timeout.

Since:
1.1.08
See Also:
Constant Field Values

MSG_NICKNAME_ALREADY_IN_USE_NEWER_VERSION_P1

public static final java.lang.String MSG_NICKNAME_ALREADY_IN_USE_NEWER_VERSION_P1
Part 1 of Status Message to send, nickname already logged into the system with a newer client version. Prepend to version number required. The "take over" option is used for reconnect when a client loses connection, and server doesn't realize it.

Since:
1.1.08
See Also:
MSG_NICKNAME_ALREADY_IN_USE_NEWER_VERSION_P2, Constant Field Values

MSG_NICKNAME_ALREADY_IN_USE_NEWER_VERSION_P2

public static final java.lang.String MSG_NICKNAME_ALREADY_IN_USE_NEWER_VERSION_P2
Part 2 of Status Message to send, nickname already logged into the system with a newer client version. Append to version number required.

Since:
1.1.08
See Also:
MSG_NICKNAME_ALREADY_IN_USE_NEWER_VERSION_P1, Constant Field Values

NICKNAME_TAKEOVER_SECONDS_SAME_PASSWORD

public static final int NICKNAME_TAKEOVER_SECONDS_SAME_PASSWORD
Number of seconds before a connection is considered disconnected, and its nickname can be "taken over" by a new connection with the right password. Used only when a password is given by the new connection.

Since:
1.1.08
See Also:
checkNickname(String, StringConnection, boolean), Constant Field Values

NICKNAME_TAKEOVER_SECONDS_SAME_IP

public static final int NICKNAME_TAKEOVER_SECONDS_SAME_IP
Number of seconds before a connection is considered disconnected, and its nickname can be "taken over" by a new connection from the same IP. Used when no password is given by the new connection.

Since:
1.1.08
See Also:
checkNickname(String, StringConnection, boolean), Constant Field Values

NICKNAME_TAKEOVER_SECONDS_DIFFERENT_IP

public static final int NICKNAME_TAKEOVER_SECONDS_DIFFERENT_IP
Number of seconds before a connection is considered disconnected, and its nickname can be "taken over" by a new connection from a different IP. Used when no password is given by the new connection.

Since:
1.1.08
See Also:
checkNickname(String, StringConnection, boolean), Constant Field Values

channelList

protected SOCChannelList channelList
list of chat channels

Instead of calling SOCChannelList.deleteChannel(String), call destroyChannel(String) to also clean up related server data.


gameList

protected SOCGameListAtServer gameList
list of soc games


robotJoinRequests

protected java.util.Hashtable<java.lang.String,java.util.Vector<StringConnection>> robotJoinRequests
table of requests for robots to join games


robotDismissRequests

protected java.util.Hashtable<java.lang.String,java.util.Vector<SOCReplaceRequest>> robotDismissRequests
table of requestst for robots to leave games


startTime

protected long startTime
the time that this server was started


numberOfGamesStarted

protected int numberOfGamesStarted
The total number of games that have been started: GameHandler.startGame(SOCGame) has been called and game play has begun. Game state became SOCGame.READY or higher from an earlier/lower state.


numberOfGamesFinished

protected int numberOfGamesFinished
The total number of games finished: Game state became SOCGame.OVER or higher from an earlier/lower state. Incremented in gameOverIncrGamesFinishedCount().

Before v1.1.20 this was the number of games destroyed, and *STATS* wouldn't reflect a newly finished game until all players had left that game.


countFieldSync

private java.lang.Object countFieldSync
Synchronization for numberOfGamesFinished writes.

Since:
2.0.00

numberOfUsers

protected int numberOfUsers
total number of users


clientPastVersionStats

protected java.util.HashMap<java.lang.Integer,java.lang.Integer> clientPastVersionStats
Client version count stats since startup (includes bots). Incremented from handleVERSION(StringConnection, SOCVersion); currently assumes single-threaded access to this map.

Key = version number, Value = client count.

Since:
1.1.19

numRobotOnlyGamesRemaining

private int numRobotOnlyGamesRemaining
Number of robot-only games not yet started (optional feature). Set at startup from PROP_JSETTLERS_BOTS_BOTGAMES_TOTAL.

Since:
2.0.00

i18n_gameopt_PL_desc

private static final java.lang.String i18n_gameopt_PL_desc
Description string for SOCGameOption "PL" hardcoded into the SOCGameOption class, from SOCGameOption.getOption("PL", false). Used for determining whether a client's i18n locale has localized option descriptions, by comparing PL's SOCGameOption.desc to StringManager.get("gameopt.PL").

String value is captured here as soon as SOCServer is referenced, in case SOCPlayerClient's practice server will localize the descriptions used by SOCGameOption.getOption(String, boolean).

Since:
2.0.00
See Also:
#i18n_scenario_SC_WOND_desc}

i18n_scenario_SC_WOND_desc

static final java.lang.String i18n_scenario_SC_WOND_desc
Short description string for SOCScenario "SC_WOND" hardcoded into the SOCScenario class. Used for determining whether a client's i18n locale has localized scenario descriptions, by comparing SC_WOND's SOCScenario.desc to StringManager.get("gamescen.SC_WOND.n").

String value is captured here as soon as SOCServer is referenced, in case SOCPlayerClient's practice server will localize the scenario descriptions.

Since:
2.0.00
See Also:
clientHasLocalizedStrs_gameScenarios(StringConnection), i18n_gameopt_PL_desc

serverRobotPinger

SOCServerRobotPinger serverRobotPinger
server robot pinger


gameTimeoutChecker

SOCGameTimeoutChecker gameTimeoutChecker
game timeout checker


databaseUserName

java.lang.String databaseUserName

databasePassword

java.lang.String databasePassword

databaseUserAdmins

private java.util.Set<java.lang.String> databaseUserAdmins
User admins whitelist, from PROP_JSETTLERS_ACCOUNTS_ADMINS, or null if disabled. If not null, only usernames on this list can create user accounts in handleCREATEACCOUNT(StringConnection, SOCCreateAccount).

Since:
1.1.19

GENERATEROBOTCOOKIE_HEX

private static final char[] GENERATEROBOTCOOKIE_HEX
The 16 hex characters to use in generateRobotCookie().

Since:
1.1.19

GENERAL_COMMANDS_HELP

public static final java.lang.String[] GENERAL_COMMANDS_HELP
List and description of general commands that any game member can run. Used by processDebugCommand(StringConnection, String, String, String)} when *HELP* is requested.

Since:
1.1.20
See Also:
ADMIN_USER_COMMANDS_HELP, DEBUG_COMMANDS_HELP

ADMIN_COMMANDS_HEADING

private static final java.lang.String ADMIN_COMMANDS_HEADING
Heading to show above any admin commands the user is authorized to run. Declared separately from ADMIN_USER_COMMANDS_HELP for use when other admin types are added.
--- Admin Commands ---

Since:
1.1.20
See Also:
Constant Field Values

ADMIN_USER_COMMANDS_HELP

public static final java.lang.String[] ADMIN_USER_COMMANDS_HELP
List and description of user-admin commands. Along with GENERAL_COMMANDS_HELP and DEBUG_COMMANDS_HELP, used by processDebugCommand(StringConnection, String, String, String)} when *HELP* is requested by a debug/admin user who passes isUserDBUserAdmin(username, true). Preceded by ADMIN_COMMANDS_HEADING.

Since:
1.1.20
See Also:
GENERAL_COMMANDS_HELP, DEBUG_COMMANDS_HELP

DEBUG_COMMANDS_HELP

public static final java.lang.String[] DEBUG_COMMANDS_HELP
List and description of debug/admin commands. Along with GENERAL_COMMANDS_HELP and ADMIN_USER_COMMANDS_HELP, used by processDebugCommand(StringConnection, String, String, String)} when *HELP* is requested by a debug/admin user.

Since:
1.1.07
See Also:
GENERAL_COMMANDS_HELP, ADMIN_USER_COMMANDS_HELP, GameHandler.getDebugCommandsHelp()

printedUsageAlready

public static boolean printedUsageAlready
Track whether we've already called printUsage(boolean).

Since:
1.1.07

sysInBuffered

private static java.io.BufferedReader sysInBuffered
Buffered System.in for readPassword(String), is null until first call to that method.

Since:
1.1.20
Constructor Detail

SOCServer

public SOCServer(int p,
                 int mc,
                 java.lang.String databaseUserName,
                 java.lang.String databasePassword)
          throws java.net.SocketException,
                 java.io.EOFException,
                 java.sql.SQLException
Create a Settlers of Catan server listening on TCP port p. Most server threads are started here; you must start its main thread yourself. Optionally connect to a database for user info and game stats.

No bots will be started here (PROP_JSETTLERS_STARTROBOTS == 0), call setupLocalRobots(int, int) if bots are wanted.

In 1.1.07 and later, will also print game options to stderr if any option defaults require a minimum client version, or if hasSetGameOptions is set.

Parameters:
p - the TCP port that the server listens on
mc - the maximum number of connections allowed; remember that robots count against this limit.
databaseUserName - the user name for accessing the database
databasePassword - the password for the db user, or ""
Throws:
java.net.SocketException - If a network setup problem occurs
java.io.EOFException - If db setup script ran successfully and server should exit now
java.sql.SQLException - If db setup script fails

SOCServer

public SOCServer(int p,
                 java.util.Properties props)
          throws java.net.SocketException,
                 java.io.EOFException,
                 java.sql.SQLException,
                 java.lang.IllegalArgumentException
Create a Settlers of Catan server listening on TCP port p. Most server threads are started here; you must start its main thread yourself. Optionally connect to a database for user info and game stats.

The database properties are SOCDBHelper.PROP_JSETTLERS_DB_USER and SOCDBHelper.PROP_JSETTLERS_DB_PASS.

To run a DB setup script to create database tables, send its filename or relative path as SOCDBHelper.PROP_JSETTLERS_DB_SCRIPT_SETUP.

If a db URL or other DB properties are specified in props, but SOCServer can't successfully connect to that database, this constructor throws SQLException; for details see initSocServer(String, String, Properties). Other constructors can't set those properties, and will instead continue SOCServer startup and run without any database.

Will also print game options to stderr if any option defaults require a minimum client version, or if hasSetGameOptions is set.

Utility Mode:

Some properties such as SOCDBHelper.PROP_JSETTLERS_DB_SCRIPT_SETUP will initialize the server environment, connect to the database, perform a single task, and exit. This is called Utility Mode. In Utility Mode the caller should not start threads or continue normal startup (Server Mode). See hasUtilityModeProperty() for more details.

For the password reset property SOCDBHelper.PROP_IMPL_JSETTLERS_PW_RESET, the caller will need to prompt for and change the password; this constructor will not do that.

Parameters:
p - the TCP port that the server listens on
props - null, or properties containing PROP_JSETTLERS_CONNECTIONS and any other desired properties.

If props is null, the properties will be created empty and no bots will be started (PROP_JSETTLERS_STARTROBOTS == 0). If props != null but doesn't contain PROP_JSETTLERS_STARTROBOTS, the default value SOC_STARTROBOTS_DEFAULT will be used.

props may contain game option default values (property names starting with PROP_JSETTLERS_GAMEOPT_PREFIX). Calls parseCmdline_GameOption(SOCGameOption, String, HashMap) for each one found, to set its default (current) value. If a default scenario is specified (game option "SC"), the scenario may include game options which conflict with those in props: Consider calling checkScenarioOpts(Map, boolean, String) to check for that and warn the user.

If you provide props, consider checking for a jsserver.properties file (SOC_SERVER_PROPS_FILENAME) and calling Properties.load(java.io.InputStream) with it before calling this constructor.

Throws:
java.net.SocketException - If a network setup problem occurs
java.io.EOFException - If db setup script ran successfully and server should exit now
java.sql.SQLException - If db setup script fails, or need db but can't connect
java.lang.IllegalArgumentException - If props contains game options (jsettlers.gameopt.*) with bad syntax. See PROP_JSETTLERS_GAMEOPT_PREFIX for expected syntax. See parseCmdline_DashedArgs(String[]) for how game option properties are checked. Throwable.getMessage() will have problem details.
Since:
1.1.09
See Also:
PROPS_LIST

SOCServer

public SOCServer(java.lang.String s,
                 int mc,
                 java.lang.String databaseUserName,
                 java.lang.String databasePassword)
          throws java.net.SocketException,
                 java.io.EOFException,
                 java.sql.SQLException
Create a Settlers of Catan server listening on local stringport s. Most server threads are started here; you must start its main thread yourself. Optionally connect to a database for user info and game stats.

No bots will be started here (PROP_JSETTLERS_STARTROBOTS == 0), call setupLocalRobots(int, int) if bots are wanted.

In 1.1.07 and later, will also print game options to stderr if any option defaults require a minimum client version, or if hasSetGameOptions is set.

Parameters:
s - the stringport that the server listens on. If this is a "practice game" server on the user's local computer, please use PRACTICE_STRINGPORT.
mc - the maximum number of connections allowed; remember that robots count against this limit.
databaseUserName - the user name for accessing the database
databasePassword - the password for the user
Throws:
java.net.SocketException - If a network setup problem occurs
java.io.EOFException - If db setup script ran successfully and server should exit now
java.sql.SQLException - If db setup script fails
Method Detail

initSocServer

private void initSocServer(java.lang.String databaseUserName,
                           java.lang.String databasePassword,
                           java.util.Properties props)
                    throws java.net.SocketException,
                           java.io.EOFException,
                           java.sql.SQLException,
                           java.lang.IllegalArgumentException
Common init for all constructors. Prints some progress messages to System.err. Sets game option default values via init_propsSetGameopts(Properties). Starts all server threads except the main thread, unless constructed in Utility Mode (hasUtilityModeProp). If PROP_JSETTLERS_STARTROBOTS is specified, those aren't started until serverUp().

If there are problems with the network setup (Server.error != null), this method will throw SocketException.

If problems running a db setup script, this method will throw SQLException.

If we can't connect to a database, but it looks like we need one (because SOCDBHelper.PROP_JSETTLERS_DB_URL, SOCDBHelper.PROP_JSETTLERS_DB_DRIVER or SOCDBHelper.PROP_JSETTLERS_DB_JAR is specified in props), this method will throw SQLException.

Utility Mode
If a db setup script runs successfully, or props contains the password reset parameter SOCDBHelper.PROP_IMPL_JSETTLERS_PW_RESET, the server does not complete its startup; this method will set hasUtilityModeProp and (only for setup script) throw EOFException.

For the password reset parameter, the caller will need to prompt for and change the password; this method will not do that.

Parameters:
databaseUserName - Used for DB connect - not retained
databasePassword - Used for DB connect - not retained
props - null, or properties containing PROP_JSETTLERS_CONNECTIONS and any other desired properties.

If props is null, the properties will be created empty and no bots will be started (PROP_JSETTLERS_STARTROBOTS == 0). If props != null but doesn't contain PROP_JSETTLERS_STARTROBOTS, the default value SOC_STARTROBOTS_DEFAULT will be used.

props may contain game option default values (property names starting with PROP_JSETTLERS_GAMEOPT_PREFIX). Calls parseCmdline_GameOption(SOCGameOption, String, HashMap) for each one found, to set its default (current) value. If a default scenario is specified (game option "SC"), the scenario may include game options which conflict with those in props: Consider calling checkScenarioOpts(Map, boolean, String) to check for that and warn the user.

Throws:
java.net.SocketException - If a network setup problem occurs
java.io.EOFException - If db setup script ran successfully and server should exit now; thrown in Utility Mode (hasUtilityModeProp).
java.sql.SQLException - If db setup script fails, or need db but can't connect
java.lang.IllegalArgumentException - If props contains game options (jsettlers.gameopt.*) with bad syntax. See PROP_JSETTLERS_GAMEOPT_PREFIX for expected syntax. See parseCmdline_DashedArgs(String[]) for how game option properties are checked. Throwable.getMessage() will have problem details.

getConfigIntProperty

private static int getConfigIntProperty(java.util.Properties props,
                                        java.lang.String pName,
                                        int pDefault)
Get and parse an integer config property, or use its default instead.

Before v2.0.00, this method was init_getIntProperty.

Parameters:
props - Properties to look in, such as props, or null for pDefault
pName - Property name
pDefault - Default value to use if not found or not parsable
Returns:
The property's parsed integer value, or pDefault
Since:
1.1.10
See Also:
getConfigBoolProperty(Properties, String, boolean)

getConfigBoolProperty

private static boolean getConfigBoolProperty(java.util.Properties props,
                                             java.lang.String pName,
                                             boolean pDefault)
Get and parse a boolean config property, or use its default instead. True values are: T Y 1. False values are: F N 0. Not case-sensitive. Any other value will be ignored and get pDefault.

Parameters:
props - Properties to look in, such as props, or null for pDefault

Before v2.0.00, this method was init_getBoolProperty.

pName - Property name
pDefault - Default value to use if not found or not parsable
Returns:
The property's parsed value, or pDefault
Since:
1.1.14
See Also:
getConfigIntProperty(Properties, String, int)

serverUp

public void serverUp()
              throws java.lang.IllegalStateException
Callback to take care of things when server comes up, after the server socket is bound and listening, in the main thread. If PROP_JSETTLERS_STARTROBOTS is specified, starts those SOCRobotClients now. If PROP_JSETTLERS_BOTS_BOTGAMES_TOTAL is specified, waits briefly and then calls startRobotOnlyGames(boolean).

Once this method completes, server begins its main loop of listening for incoming client connections, and starting a Thread for each one to handle that client's messages.

Overrides:
serverUp in class Server
Throws:
java.lang.IllegalStateException - If server was constructed in Utility Mode and shouldn't continue normal startup; see hasUtilityModeProperty() for details.
Since:
1.1.09

generateRobotCookie

private final java.lang.String generateRobotCookie()
Generate and return a string to use for robotCookie. Currently a lowercase hex string; format or length does not have to be compatible between versions. The contents are randomly generated for each server run.

Returns:
Robot connect cookie contents to use for this server
Since:
1.1.19

connectToChannel

public void connectToChannel(StringConnection c,
                             java.lang.String ch)
Adds a connection to a chat channel. WARNING: MUST HAVE THE channelList.takeMonitorForChannel(ch) before calling this method

Parameters:
c - the Connection to be added
ch - the name of the channel

leaveChannel

public boolean leaveChannel(StringConnection c,
                            java.lang.String ch,
                            boolean destroyIfEmpty,
                            boolean channelListLock)
Connection c leaves the channel ch. If the channel becomes empty after removing c, this method can destroy it.

Locks: Must have channelList.takeMonitorForChannel(ch) when calling this method. May or may not have SOCChannelList.takeMonitor(), see channelListLock parameter.

Parameters:
c - the connection
ch - the channel
destroyIfEmpty - if true, this method will destroy the channel if it's now empty. If false, the caller must call destroyChannel(String) before calling SOCChannelList.releaseMonitor().
channelListLock - true if we have the SOCChannelList.takeMonitor() lock when called; false if it must be acquired and released within this method
Returns:
true if we destroyed the channel, or if it would have been destroyed but destroyIfEmpty is false.

destroyChannel

protected final void destroyChannel(java.lang.String ch)
Destroy a channel and then clean up related data, such as the owner's count of SOCClientData.getcurrentCreatedChannels(). Calls SOCChannelList.deleteChannel(String).

Locks: Must have channelList.takeMonitor() before calling this method.

Parameters:
ch - Name of the channel to destroy
Since:
1.1.20
See Also:
leaveChannel(StringConnection, String, boolean, boolean)

connectToGame

public boolean connectToGame(StringConnection c,
                             java.lang.String gaName,
                             java.util.Map<java.lang.String,SOCGameOption> gaOpts)
                      throws SOCGameOptionVersionException,
                             java.lang.IllegalArgumentException
Adds a connection to a game, unless they're already a member. If the game doesn't yet exist, creates it and announces the new game to all clients by calling createGameAndBroadcast(StringConnection, String, Map, int, boolean, boolean).

After this, human players are free to join, until someone clicks "Start Game". At that point, server will look for robots to fill empty seats.

Parameters:
c - the Connection to be added to the game; its name, version, and locale should already be set.
gaName - the name of the game. Not validated or trimmed, see createOrJoinGameIfUserOK(StringConnection, String, String, String, Map) for that.
gaOpts - if creating a game with options, its SOCGameOptions; otherwise null. Should already be validated, by calling SOCGameOption.adjustOptionsToKnown(Map, Map, boolean) with doServerPreadjust true.
Returns:
true if c was not a member of the game before, or if new game created; false if c was already in this game
Throws:
SOCGameOptionVersionException - if asking to create a game (gaOpts != null), but client's version is too low to join because of a requested game option's minimum version in gaOpts. Calculated via SOCGameOption.optionsNewerThanVersion(int, boolean, boolean, Map). (this exception was added in 1.1.07)
java.lang.IllegalArgumentException - if client's version is too low to join for any other reason. (this exception was added in 1.1.06)
See Also:
joinGame(SOCGame, StringConnection, boolean, boolean), #handleSTARTGAME(StringConnection, SOCStartGame), handleJOINGAME(StringConnection, SOCJoinGame)

createGameAndBroadcast

private SOCGame createGameAndBroadcast(StringConnection c,
                                       java.lang.String gaName,
                                       java.util.Map<java.lang.String,SOCGameOption> gaOpts,
                                       int gVers,
                                       boolean isBotsOnly,
                                       boolean hasGameListMonitor)
Create a new game, and announce it with a broadcast. Called from connectToGame(StringConnection, String, Map).

The new game is created with SOCGameListAtServer.createGame(String, String, String, Map, GameHandler) and will expire in SOCGameListAtServer.GAME_TIME_EXPIRE_MINUTES unless extended during play.

The broadcast will send SOCNewGameWithOptions if gaOpts != null, SOCNewGame otherwise. If some connected clients are older than gVers, the message sent to those older clients will let them know they can't connect to the new game.

Locks: Uses SOCGameList.takeMonitor() / SOCGameList.releaseMonitor(); see hasGameListMonitor parameter.

Parameters:
c - the Connection creating and owning this game; its name, version, and locale should already be set. This client connection will be added as a member of the game, and its SOCClientData.createdGame() will be called. Can be null, especially if isBotsOnly.
gaName - the name of the game, no game should exist yet with this name. Not validated or trimmed, see createOrJoinGameIfUserOK(StringConnection, String, String, String, Map) for that.
gaOpts - if creating a game with options, its SOCGameOptions; otherwise null. Should already be validated, by calling SOCGameOption.adjustOptionsToKnown(Map, Map, boolean) with doServerPreadjust true.
gVers - Game's minimum version, from SOCVersionedItem.itemsMinimumVersion (gaOpts), or -1 if null gaOpts
isBotsOnly - True if the game's only players are bots, no humans and no owner
hasGameListMonitor - True if caller holds the SOCGameList.takeMonitor() lock already. If true, this method won't take or release that monitor. Otherwise will take it before creating the game, and release it before calling Server.broadcast(String).
Returns:
Newly created game, or null if game name exists or an unexpected error occurs during creation
Since:
2.0.00

leaveGame

public boolean leaveGame(StringConnection c,
                         java.lang.String gm,
                         boolean destroyIfEmpty,
                         boolean gameListLock)
the connection c leaves the game gm. Clean up; if needed, force the current player's turn to end.

If the game becomes empty after removing c, this method can destroy it if all these conditions are true (determined by GameHandler.leaveGame(SOCGame, StringConnection)):

Locks: Has gameList.takeMonitorForGame(gm) when calling this method; should not have SOCGame.takeMonitor(). May or may not have SOCGameList.takeMonitor(), see gameListLock parameter.

Parameters:
c - the connection; if c is being dropped because of an error, this method assumes that StringConnection.disconnect() has already been called. This method won't exclude c from any communication about leaving the game, in case they are still connected and in other games.
gm - the game
destroyIfEmpty - if true, this method will destroy the game if it's now empty. If false, the caller must call destroyGame(String) before calling SOCGameList.releaseMonitor().
gameListLock - true if we have the SOCGameList.takeMonitor() lock when called; false if it must be acquired and released within this method
Returns:
true if the game was destroyed, or if it would have been destroyed but destroyIfEmpty is false.

robotShuffleForJoin

int[] robotShuffleForJoin()
shuffle the indexes to distribute load among robots

Returns:
a shuffled array of robot indexes, from 0 to ({#link robots}.size() - 1
Since:
1.1.06

setupLocalRobots

public boolean setupLocalRobots(int numFast,
                                int numSmart)
Set up some robot opponents, running in our JVM for operator convenience. Set up more than needed; when a game is started, game setup will randomize whether its humans will play against smart or fast ones. (Some will be SOCRobotDM.FAST_STRATEGY, some SMART_STRATEGY).

Before 1.1.09, this method was part of SOCPlayerClient.

Parameters:
numFast - number of fast robots, with FAST_STRATEGY
numSmart - number of smart robots, with SMART_STRATEGY
Returns:
True if robots were set up, false if an exception occurred. This typically happens if a robot class or SOCDisplaylessClient can't be loaded, due to packaging of the server-only JAR.
Since:
1.1.00
See Also:
SOCPlayerClient.startPracticeGame(), SOCPlayerClient.GameAwtDisplay.startLocalTCPServer(int), startRobotOnlyGames(boolean), SOCLocalRobotClient

destroyGame

public void destroyGame(java.lang.String gm)
Destroy a game and clean up related data, such as the owner's count of SOCClientData.getCurrentCreatedGames().

Note that if this game had the SOCGame.isBotsOnly flag, and numRobotOnlyGamesRemaining > 0, will call startRobotOnlyGames(boolean).

Locks: Must have gameList.takeMonitor() before calling this method.

Parameters:
gm - Name of the game to destroy
See Also:
leaveGame(StringConnection, String, boolean, boolean), destroyGameAndBroadcast(String, String)

destroyGameAndBroadcast

public void destroyGameAndBroadcast(java.lang.String gaName,
                                    java.lang.String descForStackTrace)
Destroy a game and then broadcast its deletion, including lock handling. Calls SOCGameList.takeMonitor(), destroyGame(String), SOCGameList.releaseMonitor(), and broadcast(SOCDeleteGame).

Parameters:
gaName - Game name to destroy
descForStackTrace - Activity description in case of exception thrown from destroyGame; will debug-print a mesasge "Exception in " + desc, followed by a stack trace.
Since:
2.0.00

getGameNames

public java.util.Collection<java.lang.String> getGameNames()
Used when SOCPlayerClient is also hosting games.

Returns:
The names (Strings) of games on this server

getGame

public SOCGame getGame(java.lang.String gaName)
Given a game name on this server, return its game object.

Parameters:
gaName - Game name
Returns:
The game, or null if none found in game list
Since:
2.0.00

getGameState

public int getGameState(java.lang.String gm)
Given a game name on this server, return its state.

Parameters:
gm - Game name
Returns:
Game's state, or -1 if no game with that name on this server
Since:
1.1.00

getGameOptions

public java.util.Map<java.lang.String,SOCGameOption> getGameOptions(java.lang.String gm)
Given a game name on this server, return its game options.

Parameters:
gm - Game name
Returns:
the game options, or null if the game doesn't exist or has no options
Since:
1.1.07

hasUtilityModeProperty

public final boolean hasUtilityModeProperty()
True if the server was constructed with a property or command line argument which is used to run the server in Utility Mode instead of Server Mode. In Utility Mode the server reads its properties, initializes its database connection if any, and performs one task such as a password reset or table/index creation. It won't listen on a TCP port or start other threads.

Utility Mode may also set a status message, see getUtilityModeMessage().

The current Utility Mode properties/arguments are:

Returns:
True if server was constructed with a Utility Mode property or command line argument
Since:
1.1.20

getUtilityModeMessage

public final java.lang.String getUtilityModeMessage()
If hasUtilityModeProperty(), get the optional status message to print before exiting.

Returns:
Optional status message, or null
Since:
1.1.20

localizeKnownOptions

public static java.util.Map<java.lang.String,SOCGameOption> localizeKnownOptions(java.util.Locale loc,
                                                                                 boolean updateStaticKnownOpts)
Given a StringManager (for a client's locale), return all known game options, localizing the descriptive names if available.

Parameters:
loc - Client's locale for StringManager i18n lookups: smgr.get("gameopt." + SOCGameOption.key)
updateStaticKnownOpts - If true, localize each SOCGameOption.desc in the static set of known options used by SOCGameOption.getOption(String, boolean) and SOCGameOption.getAllKnownOptions(); for use only by client's practice-game server
Returns:
SOCGameOption.getAllKnownOptions(), with descriptions localized if available
Since:
2.0.00

getConnection

StringConnection getConnection(java.lang.String connKey)
Given a connection's key, return the connected client. Package-level access for other server classes.

Parameters:
connKey - Client name (Object key data), as in StringConnection.getData(); if null, returns null
Returns:
The connection with this key, or null if none
Since:
2.0.00

leaveAllChannels

public void leaveAllChannels(StringConnection c)
Connection c is leaving the server; remove from all channels it was in. In channels where c was the last connection, calls destroyChannel(String).

Parameters:
c - the connection

leaveAllGames

public void leaveAllGames(StringConnection c)
Connection c is leaving the server; remove from all games it was in. In games where c was the last human player, calls destroyGame(String).

Parameters:
c - the connection

messageToChannel

public void messageToChannel(java.lang.String ch,
                             SOCMessage mes)
Send a message to the given channel

Parameters:
ch - the name of the channel
mes - the message to send

messageToChannelWithMon

public void messageToChannelWithMon(java.lang.String ch,
                                    SOCMessage mes)
Send a message to the given channel WARNING: MUST HAVE THE gameList.takeMonitorForChannel(ch) before calling this method

Parameters:
ch - the name of the channel
mes - the message to send

messageToPlayer

public void messageToPlayer(StringConnection c,
                            SOCMessage mes)
Send a message to a player and record it

Parameters:
c - the player connection
mes - the message to send

messageToPlayer

public void messageToPlayer(StringConnection c,
                            java.lang.String ga,
                            java.lang.String txt)
Send a SOCGameServerText or SOCGameTextMsg game text message to a player. Equivalent to: messageToPlayer(conn, new SOCGameServerText(ga, txt));

Parameters:
c - the player connection; if their version is 2.0.00 or newer, they will be sent SOCGameServerText, otherwise SOCGameTextMsg.
ga - game name
txt - the message text to send
Since:
1.1.08
See Also:
messageToPlayerKeyed(StringConnection, String, String)

messageToPlayerKeyed

public final void messageToPlayerKeyed(StringConnection c,
                                       java.lang.String gaName,
                                       java.lang.String key)
Send a localized SOCGameServerText game text message to a player. Equivalent to: messageToPlayer(conn, new SOCGameServerText(ga, c.getLocalized(key)));

Parameters:
c - the player connection; if their version is 2.0.00 or newer, they will be sent SOCGameServerText, otherwise SOCGameTextMsg. Null c is ignored and not an error.
gaName - game name
key - the message localization key, from StringManager.get(String), to look up and send text of
Since:
2.0.00
See Also:
messageToPlayerKeyed(StringConnection, String, String, Object...)

messageToPlayerKeyed

public final void messageToPlayerKeyed(StringConnection c,
                                       java.lang.String gaName,
                                       java.lang.String key,
                                       java.lang.Object... args)
Send a localized SOCGameServerText game text message with arguments to a player. Equivalent to: messageToPlayer(conn, new SOCGameServerText(ga, c.getLocalized(key, args)));

The localized message text must be formatted as in MessageFormat: Placeholders for args are {0} etc, single-quotes must be repeated: ''.

Parameters:
c - the player connection; if their version is 2.0.00 or newer, they will be sent SOCGameServerText, otherwise SOCGameTextMsg. Null c is ignored and not an error.
gaName - game name
key - the message localization key, from StringManager.get(String), to look up and send text of
args - Any parameters within txt's placeholders
Since:
2.0.00
See Also:
messageToPlayerKeyed(StringConnection, String, String), messageToPlayerKeyedSpecial(StringConnection, SOCGame, String, Object...)

messageToPlayerKeyedSpecial

public final void messageToPlayerKeyedSpecial(StringConnection c,
                                              SOCGame ga,
                                              java.lang.String key,
                                              java.lang.Object... args)
Send a localized SOCGameServerText game text message with arguments to a player, with special formatting like {0,rsrcs}. Equivalent to: messageToPlayer(conn, new SOCGameServerText(ga, c.getLocalizedSpecial(ga, key, args)));

The localized message text must be formatted as in MessageFormat: Placeholders for args are {0} etc, single-quotes must be repeated: ''. For the SoC-specific parameters such as {0,rsrcs}, see the javadoc for SOCStringManager.getSpecial(SOCGame, String, Object...).

Parameters:
c - the player connection; if their version is 2.0.00 or newer, they will be sent SOCGameServerText, otherwise SOCGameTextMsg. Null c is ignored and not an error.
ga - the game
key - the message localization key, from StringManager.get(String), to look up and send text of
args - Any parameters within txt's placeholders
Since:
2.0.00
See Also:
messageToPlayerKeyed(StringConnection, String, String, Object...), messageToPlayerKeyed(StringConnection, String, String)

messageToGame

public void messageToGame(java.lang.String ga,
                          SOCMessage mes)
Send a message to the given game.

Locks: Takes, releases SOCGameList.takeMonitorForGame(String).

Parameters:
ga - the name of the game
mes - the message to send. If mes is a SOCGameTextMsg whose text begins with ">>>", the client should consider this an urgent message, and draw the user's attention in some way. (See messageToGameUrgent(String, String))
See Also:
messageToGame(String, String), messageToGameWithMon(String, SOCMessage), messageToGameForVersions(SOCGame, int, int, SOCMessage, boolean)

messageToGame

public void messageToGame(java.lang.String ga,
                          java.lang.String txt)
Send a server text message to the given game. Equivalent to: messageToGame(ga, new SOCGameServerText(ga, txt));

Do not pass SOCSomeMessage.toCmd() into this method; the message type number will be GAMESERVERTEXT, not the desired SOMEMESSAGE.

Client versions older than v2.0.00 will be sent SOCGameTextMsg(ga, SERVERNAME, txt).

Locks: Takes, releases SOCGameList.takeMonitorForGame(String).

Parameters:
ga - the name of the game
txt - the message text to send. If text begins with ">>>", the client should consider this an urgent message, and draw the user's attention in some way. (See messageToGameUrgent(String, String))
Since:
1.1.08
See Also:
messageToGameKeyed(SOCGame, boolean, String), messageToGameKeyed(SOCGame, boolean, String, Object...), messageToGame(String, SOCMessage), messageToGameWithMon(String, SOCMessage), messageToGameExcept(String, StringConnection, String, boolean)

messageToGameKeyedType

public void messageToGameKeyedType(SOCGame ga,
                                   SOCKeyedMessage msg,
                                   boolean takeMon)
Send a game a message containing data fields and also a text field to be localized. Same as messageToGame(String, SOCMessage) but calls each member connection's c.getLocalized(key) for the localized text to send.

Locks: If takeMon is true, takes and releases gameList.takeMonitorForGame(gameName). Otherwise call gameList.takeMonitorForGame(gameName) before calling this method.

Parameters:
ga - The game
msg - The data message to be sent after localizing text. This message's fields are not changed here, the localization results are not kept with msg.
takeMon - Should this method take and release game's monitor via gameList.takeMonitorForGame(gameName)? True unless caller already holds that monitor.
Since:
2.0.00
See Also:
messageToGameKeyed(SOCGame, boolean, String), messageToGameKeyed(SOCGame, boolean, String, Object...)

messageToGameKeyed

public void messageToGameKeyed(SOCGame ga,
                               boolean takeMon,
                               java.lang.String key)
                        throws java.util.MissingResourceException
Send a localized SOCGameServerText game text message to a game. Same as messageToGame(String, String) but calls each member connection's c.getLocalized(key) for the localized text to send.

Client versions older than v2.0.00 will be sent SOCGameTextMsg(ga, SERVERNAME, txt).

Locks: If takeMon is true, takes and releases SOCGameList.takeMonitorForGame(String). Otherwise call gameList.takeMonitorForGame(gaName) before calling this method.

Parameters:
ga - the game object
takeMon - Should this method take and release game's monitor via SOCGameList.takeMonitorForGame(String) ? True unless caller already holds that monitor.
key - the message localization key, from StringManager.get(String), to look up and send text of. If its localized text begins with ">>>", the client should consider this an urgent message, and draw the user's attention in some way. (See messageToGameUrgent(String, String))
Throws:
java.util.MissingResourceException - if no string can be found for key; this is a RuntimeException
Since:
2.0.00
See Also:
messageToGameKeyed(SOCGame, boolean, String, Object...), messageToGameKeyedSpecial(SOCGame, boolean, String, Object...), messageToGameKeyedSpecialExcept(SOCGame, boolean, StringConnection, String, Object...), messageToGameKeyedType(SOCGame, SOCKeyedMessage, boolean), messageToGame(String, String)

messageToGameKeyed

public void messageToGameKeyed(SOCGame ga,
                               boolean takeMon,
                               java.lang.String key,
                               java.lang.Object... params)
                        throws java.util.MissingResourceException
Send a localized SOCGameServerText game text message (with parameters) to a game. Same as messageToGame(String, String) but calls each member connection's c.getLocalized(key) for the localized text to send.

Client versions older than v2.0.00 will be sent SOCGameTextMsg(ga, SERVERNAME, txt).

Locks: If takeMon is true, takes and releases SOCGameList.takeMonitorForGame(String). Otherwise call gameList.takeMonitorForGame(gaName) before calling this method.

Parameters:
ga - the game object
takeMon - Should this method take and release game's monitor via SOCGameList.takeMonitorForGame(String) ? True unless caller already holds that monitor.
key - the message localization key, from StringManager.get(String), to look up and send text of. If its localized text begins with ">>>", the client should consider this an urgent message, and draw the user's attention in some way. (See messageToGameUrgent(String, String))
params - Objects to use with {0}, {1}, etc in the localized string by calling MessageFormat.format(String, Object...).
Throws:
java.util.MissingResourceException - if no string can be found for key; this is a RuntimeException
Since:
2.0.00
See Also:
messageToGameKeyed(SOCGame, boolean, String), messageToGameKeyedSpecial(SOCGame, boolean, String, Object...), messageToGameKeyedSpecialExcept(SOCGame, boolean, StringConnection, String, Object...), messageToGameKeyedType(SOCGame, SOCKeyedMessage, boolean), messageToGame(String, String)

messageToGameKeyedSpecial

public final void messageToGameKeyedSpecial(SOCGame ga,
                                            boolean takeMon,
                                            java.lang.String key,
                                            java.lang.Object... params)
                                     throws java.util.MissingResourceException,
                                            java.lang.IllegalArgumentException
Send a localized SOCGameServerText game text message (with parameters) to a game, optionally with special formatting like {0,rsrcs}, optionally excluding one connection. Same as messageToGame(String, String) but calls each member connection's c.getLocalizedSpecial(...) for the localized text to send.

For the SoC-specific parameters such as {0,rsrcs}, see the javadoc for SOCStringManager.getSpecial(SOCGame, String, Object...).

Client versions older than v2.0.00 will be sent SOCGameTextMsg(ga, SERVERNAME, txt).

Locks: If takeMon is true, takes and releases SOCGameList.takeMonitorForGame(String). Otherwise call gameList.takeMonitorForGame(gaName) before calling this method.

Parameters:
ga - the game object
takeMon - Should this method take and release game's monitor via SOCGameList.takeMonitorForGame(String) ? True unless caller already holds that monitor.
key - the message localization key, from StringManager.get(String), to look up and send text of. If its localized text begins with ">>>", the client should consider this an urgent message, and draw the user's attention in some way. (See messageToGameUrgent(String, String))
params - Objects to use with {0}, {1}, etc in the localized string by calling MessageFormat.format(String, Object...).

These objects can include SOCResourceSet or pairs of Integers for a resource count and type; see SOCStringManager.getSpecial(SOCGame, String, Object...).

Throws:
java.util.MissingResourceException - if no string can be found for key; this is a RuntimeException
java.lang.IllegalArgumentException - if the localized pattern string has a parse error (closing '}' brace without opening '{' brace, etc)
Since:
2.0.00
See Also:
messageToGameKeyedSpecialExcept(SOCGame, boolean, StringConnection, String, Object...), messageToGameKeyed(SOCGame, boolean, String), messageToGame(String, String)

messageToGameKeyedSpecialExcept

public final void messageToGameKeyedSpecialExcept(SOCGame ga,
                                                  boolean takeMon,
                                                  StringConnection ex,
                                                  java.lang.String key,
                                                  java.lang.Object... params)
                                           throws java.util.MissingResourceException,
                                                  java.lang.IllegalArgumentException
Send a localized SOCGameServerText game text message (with parameters) to a game, optionally with special formatting like {0,rsrcs}, optionally excluding one connection. Same as messageToGame(String, String) but calls each member connection's c.getLocalizedSpecial(...) for the localized text to send.

Parameters:
ga - the game object
takeMon - Should this method take and release game's monitor via SOCGameList.takeMonitorForGame(String) ? True unless caller already holds that monitor.
ex - the excluded connection, or null
key - the message localization key, from StringManager.get(String), to look up and send text of. If its localized text begins with ">>>", the client should consider this an urgent message, and draw the user's attention in some way. (See messageToGameUrgent(String, String))
params - Objects to use with {0}, {1}, etc in the localized string by calling MessageFormat.format(String, Object...).

These objects can include SOCResourceSet or pairs of Integers for a resource count and type; see SOCStringManager.getSpecial(SOCGame, String, Object...).

Throws:
java.util.MissingResourceException - if no string can be found for key; this is a RuntimeException
java.lang.IllegalArgumentException - if the localized pattern string has a parse error (closing '}' brace without opening '{' brace, etc)
Since:
2.0.00
See Also:
messageToGameKeyedSpecialExcept(SOCGame, boolean, List, String, Object...), messageToGameKeyed(SOCGame, boolean, String), messageToGame(String, String)

messageToGameKeyedSpecialExcept

public final void messageToGameKeyedSpecialExcept(SOCGame ga,
                                                  boolean takeMon,
                                                  java.util.List<StringConnection> ex,
                                                  java.lang.String key,
                                                  java.lang.Object... params)
                                           throws java.util.MissingResourceException,
                                                  java.lang.IllegalArgumentException
Send a localized SOCGameServerText game text message (with parameters) to a game, optionally with special formatting like {0,rsrcs}, optionally excluding some connections. Same as messageToGame(String, String) but calls each member connection's c.getLocalizedSpecial(...) for the localized text to send.

Parameters:
ga - the game object
takeMon - Should this method take and release game's monitor via SOCGameList.takeMonitorForGame(String) ? True unless caller already holds that monitor.
ex - the excluded connections, or null
key - the message localization key, from StringManager.get(String), to look up and send text of. If its localized text begins with ">>>", the client should consider this an urgent message, and draw the user's attention in some way. (See messageToGameUrgent(String, String))
params - Objects to use with {0}, {1}, etc in the localized string by calling MessageFormat.format(String, Object...).

These objects can include SOCResourceSet or pairs of Integers for a resource count and type; see SOCStringManager.getSpecial(SOCGame, String, Object...).

Throws:
java.util.MissingResourceException - if no string can be found for key; this is a RuntimeException
java.lang.IllegalArgumentException - if the localized pattern string has a parse error (closing '}' brace without opening '{' brace, etc)
Since:
2.0.00
See Also:
messageToGameKeyedSpecialExcept(SOCGame, boolean, StringConnection, String, Object...), messageToGameKeyed(SOCGame, boolean, String), messageToGame(String, String)

impl_messageToGameKeyedSpecial

private final void impl_messageToGameKeyedSpecial(SOCGame ga,
                                                  boolean takeMon,
                                                  java.util.List<StringConnection> members,
                                                  StringConnection ex,
                                                  boolean fmtSpecial,
                                                  java.lang.String key,
                                                  java.lang.Object... params)
                                           throws java.util.MissingResourceException,
                                                  java.lang.IllegalArgumentException
Implement messageToGameKeyedSpecial and messageToGameKeyedSpecialExcept.

Parameters:
ga - the game object
takeMon - Should this method take and release game's monitor via SOCGameList.takeMonitorForGame(String) ? True unless caller already holds that monitor.
members - Game members to send to, from SOCGameListAtServer.getMembers(String). If we're excluding several members of the game, make a new list from getMembers, remove them from that list, then pass it to this method.
ex - the excluded connection, or null
fmtSpecial - Should this method call SOCStringManager.getSpecial(SOCGame, String, Object...) instead of the usual StringManager.get(String, Object...) ?
key - the message localization key, from StringManager.get(String), to look up and send text of. If its localized text begins with ">>>", the client should consider this an urgent message, and draw the user's attention in some way. (See messageToGameUrgent(String, String))
params - Objects to use with {0}, {1}, etc in the localized string by calling MessageFormat.format(String, Object...).

If fmtSpecial, these objects can include SOCResourceSet or pairs of Integers for a resource count and type; see SOCStringManager.getSpecial(SOCGame, String, Object...).

Throws:
java.util.MissingResourceException - if no string can be found for key; this is a RuntimeException
java.lang.IllegalArgumentException - if the localized pattern string has a parse error (closing '}' brace without opening '{' brace, etc)
Since:
2.0.00

messageToGameWithMon

public void messageToGameWithMon(java.lang.String ga,
                                 SOCMessage mes)
Send a message to the given game.

Locks: MUST HAVE THE gameList.takeMonitorForGame(ga) before calling this method.

Parameters:
ga - the name of the game
mes - the message to send
See Also:
messageToGame(String, SOCMessage), messageToGameKeyed(SOCGame, boolean, String), messageToGameForVersions(SOCGame, int, int, SOCMessage, boolean)

messageToGameExcept

public void messageToGameExcept(java.lang.String gn,
                                StringConnection ex,
                                java.lang.String txt,
                                boolean takeMon)
Send a server text message to all the connections in a game excluding one. Equivalent to: messageToGameExcept(gn, new SOCGameTextMsg(gn, SERVERNAME, txt), takeMon);

Do not pass SOCSomeMessage.toCmd() into this method; the message type number will be GAMETEXTMSG, not the desired SOMEMESSAGE.

Parameters:
gn - the name of the game
ex - the excluded connection, or null
txt - the message text to send.

If you need to format the message (with placeholders for i18n), call MessageFormat.format(fmt, args) on it first.

If text begins with ">>>", the client should consider this an urgent message, and draw the user's attention in some way. (See messageToGameUrgent(String, String))

takeMon - Should this method take and release game's monitor via SOCGameList.takeMonitorForGame(String) ? True unless caller already holds that monitor.
Since:
2.0.00
See Also:
messageToGame(String, String), messageToGameExcept(String, StringConnection, SOCMessage, boolean)

messageToGameExcept

public void messageToGameExcept(java.lang.String gn,
                                java.util.Vector<StringConnection> ex,
                                SOCMessage mes,
                                boolean takeMon)
Send a message to all the connections in a game excluding some.

Parameters:
gn - the name of the game
ex - the list of exceptions
mes - the message
takeMon - Should this method take and release game's monitor via SOCGameList.takeMonitorForGame(String) ?
See Also:
messageToGameExcept(String, StringConnection, SOCMessage, boolean)

messageToGameExcept

public void messageToGameExcept(java.lang.String gn,
                                StringConnection ex,
                                SOCMessage mes,
                                boolean takeMon)
Send a message to all the connections in a game excluding one.

Parameters:
gn - the name of the game
ex - the excluded connection, or null
mes - the message
takeMon - Should this method take and release game's monitor via SOCGameList.takeMonitorForGame(String) ?
See Also:
messageToGameExcept(String, StringConnection, String, boolean), messageToGameExcept(String, Vector, SOCMessage, boolean), messageToGameForVersionsExcept(SOCGame, int, int, StringConnection, SOCMessage, boolean)

messageToGameForVersions

public final void messageToGameForVersions(SOCGame ga,
                                           int vmin,
                                           int vmax,
                                           SOCMessage mes,
                                           boolean takeMon)
Send a message to all the connections in a game in a certain version range. Used for backwards compatibility.

Parameters:
ga - the game
vmin - Minimum version to send to, or -1. Same format as Version.versionNumber() and StringConnection.getVersion().
vmax - Maximum version to send to, or Integer.MAX_VALUE
mes - the message
takeMon - Should this method take and release game's monitor via SOCGameList.takeMonitorForGame(String) ? If the game's clients are all older than vmin or newer than vmax, nothing happens and the monitor isn't taken.
Since:
1.1.19

messageToGameForVersionsExcept

public final void messageToGameForVersionsExcept(SOCGame ga,
                                                 int vmin,
                                                 int vmax,
                                                 StringConnection ex,
                                                 SOCMessage mes,
                                                 boolean takeMon)
Send a message to all the connections in a game in a certain version range, excluding one. Used for backwards compatibility.

Parameters:
ga - the game
vmin - Minimum version to send to, or -1. Same format as Version.versionNumber() and StringConnection.getVersion().
vmax - Maximum version to send to, or Integer.MAX_VALUE
ex - the excluded connection, or null
mes - the message
takeMon - Should this method take and release game's monitor via SOCGameList.takeMonitorForGame(String) ? If the game's clients are all older than vmin or newer than vmax, nothing happens and the monitor isn't taken.
Since:
1.1.19
See Also:
messageToGameExcept(String, StringConnection, SOCMessage, boolean)

messageToGameUrgent

public void messageToGameUrgent(java.lang.String ga,
                                java.lang.String mes)
Send an urgent SOCGameTextMsg to the given game. An "urgent" message is a SOCGameTextMsg whose text begins with ">>>"; the client should draw the user's attention in some way.

Locks: Like messageToGame(String, String), will take and release the game's monitor.

Parameters:
ga - the name of the game
mes - the message to send. If mes does not begin with ">>>", will prepend ">>> " before sending mes.

leaveConnection

public void leaveConnection(StringConnection c)
things to do when the connection c leaves

This method is called within a per-client thread, after connection is removed from conns collection and version collection, and after c.disconnect() has been called.

Overrides:
leaveConnection in class Server
Parameters:
c - the connection

newConnection1

public boolean newConnection1(StringConnection c)
Things to do when a new connection comes.

If we already have maxConnections named clients, reject this new one by sending SOCRejectConnection.

If the connection is accepted, it's added to Server.unnamedConns until the player "names" it by joining or creating a game under their player name. Other communication is then done, in newConnection2(StringConnection).

Also set client's "assumed version" to -1, until we have sent and received a VERSION message.

This method is called within a per-client thread. You can send to client, but can't yet receive messages from them.

SYNCHRONIZATION NOTE: During the call to newConnection1, the monitor lock of Server.unnamedConns is held. Thus, defer as much as possible until newConnection2(StringConnection) (after the connection is accepted).

Overrides:
newConnection1 in class Server
Parameters:
c - the new Connection
Returns:
true to accept and continue, false if you have rejected this connection; if false, addConnection will call StringConnection.disconnectSoft().
See Also:
Server.addConnection(StringConnection), newConnection2(StringConnection), nameConnection(StringConnection, boolean)

newConnection2

protected void newConnection2(StringConnection c)
Send welcome messages (server version and features, and the lists of channels and games (SOCChannels, SOCGames)) when a new connection comes, part 2 - c has been accepted and added to a connection list. Unlike newConnection1(StringConnection), no connection-list locks are held when this method is called.

Client's SOCClientData appdata is set here.

This method is called within a per-client thread. You can send to client, but can't yet receive messages from them.

Overrides:
newConnection2 in class Server

nameConnection

private void nameConnection(StringConnection c,
                            boolean isReplacing)
                     throws java.lang.IllegalArgumentException
Name a current connection to the system, which may replace an older connection. Call c.setData(name) just before calling this method. Calls Server.nameConnection(StringConnection) to move the connection from the unnamed to the named connection list. Increments numberOfUsers.

If isReplacing:

Parameters:
c - Connected client; its key data (StringConnection.getData()) must not be null
isReplacing - Are we replacing / taking over a current connection?
Throws:
java.lang.IllegalArgumentException - If c isn't already connected, if c.getData() returns null, or if nameConnection has previously been called for this connection.
Since:
1.1.08

sendGameList

public void sendGameList(StringConnection c,
                         int prevVers)
Send the entire list of games to this client; this is sent once per connecting client. Or, send the set of changed games, if the client's guessed version was wrong. The list includes a flag on games which can't be joined by this client version (SOCGames.MARKER_THIS_GAME_UNJOINABLE).

If entire list, then depending on client's version, the message sent will be either GAMES or GAMESWITHOPTIONS. If set of changed games, sent as matching pairs of DELETEGAME and either NEWGAME or NEWGAMEWITHOPTIONS.

There are 2 possible scenarios for when this method is called:

- (A) Sending game list to client, for the first time: Iterate through all games, looking for ones the client's version is capable of joining. If not capable, mark the game name as such before sending it to the client. (As a special case, very old client versions "can't know" about the game they can't join, because they don't recognize the marker.) Also set the client data's hasSentGameList flag.

- (B) The client didn't give its version, and was thus identified as an old version. Now we know its newer true version, so we must tell it about games that it can now join, which couldn't have been joined by the older assumed version. So: Look for games with those criteria.

Sending the list is done here, and not in newConnection2, because we must first know the client's version.

The minimum version which recognizes the "can't join" marker is 1.1.06 (SOCGames.VERSION_FOR_UNJOINABLE). Older clients won't be sent the game names they can't join.

Locks: Calls SOCGameList.takeMonitor() / releaseMonitor

Parameters:
c - Client's connection; will call getVersion() on it
prevVers - Previously assumed version of this client; if re-sending the list, should be less than c.getVersion.
Since:
1.1.06

checkNickname

private int checkNickname(java.lang.String n,
                          StringConnection newc,
                          boolean withPassword)
Check if a nickname is okay, and, if they're already logged in, whether a new replacement connection can "take over" the existing one.

a name is ok if it hasn't been used yet, isn't the server's name, and (since 1.1.07) passes SOCMessage.isSingleLineAndSafe(String).

The "take over" option is used for reconnect when a client loses connection, and server doesn't realize it. A new connection can "take over" the name after a timeout; check the return value. (After NICKNAME_TAKEOVER_SECONDS_SAME_IP or NICKNAME_TAKEOVER_SECONDS_DIFFERENT_IP seconds) When taking over, the new connection's client version must be able to join all games that the old connection is playing, as returned by gameList.playerGamesMinVersion.

Parameters:
n - the name
newc - A new incoming connection, asking for this name
withPassword - Did the connection supply a password?
Returns:
0 if the name is okay;
-1 if OK and you are taking over a connection;
-2 if not OK by rules (fails isSingleLineAndSafe);
-vers if not OK by version (for takeover; will be -1000 lower);
or, the number of seconds after which newc can take over this name's games.
See Also:
checkNickname_getRetryText(int)

checkNickname_getRetryText

private static final java.lang.String checkNickname_getRetryText(int nameTimeout)
For a nickname that seems to be in use, build a text message with the time remaining before someone can attempt to take over that nickname. Used for reconnect when a client loses connection, and server doesn't realize it. A new connection can "take over" the name after a timeout. (NICKNAME_TAKEOVER_SECONDS_SAME_IP, NICKNAME_TAKEOVER_SECONDS_DIFFERENT_IP)

Parameters:
nameTimeout - Number of seconds before trying to reconnect
Returns:
message starting with "Please wait x seconds" or "Please wait x minute(s)"
Since:
1.1.08

checkNickname_getVersionText

private static final java.lang.String checkNickname_getVersionText(int needsVersion)
For a nickname that seems to be in use, build a text message with the minimum version number needed to take over that nickname. Used for reconnect when a client loses connection, and server doesn't realize it. A new connection can "take over" the name after a timeout.

Parameters:
needsVersion - Version number required to take it over; a positive integer in the same format as SOCGame.getClientVersionMinRequired()
Returns:
string containing the version, starting with MSG_NICKNAME_ALREADY_IN_USE_NEWER_VERSION_P1.
Since:
1.1.08

processFirstCommand

public boolean processFirstCommand(java.lang.String str,
                                   StringConnection con)
Callback to process the client's first message command specially. Look for VERSION message; if none is received, set up a timer to wait for version and (if never received) send out the game list soon.

Overrides:
processFirstCommand in class Server
Parameters:
str - Contents of first message from the client
con - Connection (client) sending this message
Returns:
true if processed here (VERSION), false if this message should be queued up and processed by the normal processCommand(String, StringConnection).

processCommand

public void processCommand(java.lang.String s,
                           StringConnection c)
Treat the incoming messages. Messages of unknown type are ignored.

Called from the single 'treater' thread. Do not block or sleep because this is single-threaded.

The first message from a client is treated by processFirstCommand(String, StringConnection) instead.

Note: When there is a choice, always use local information over information from the message. For example, use the nickname from the connection to get the player information rather than the player information from the message. This makes it harder to send false messages making players do things they didn't want to do.

Specified by:
processCommand in class Server
Parameters:
s - Contents of message from the client
c - Connection (client) sending this message

processDebugCommand

public boolean processDebugCommand(StringConnection debugCli,
                                   java.lang.String ga,
                                   java.lang.String dcmd,
                                   java.lang.String dcmdU)
Process a debug command, sent by the "debug" client/player. Some debug commands are server-wide, some apply to a specific game. If no server-wide commands match, server will call GameHandler.processDebugCommand(StringConnection, String, String, String) to check for those.

Check allowDebugUser before calling this method. For list of commands see GENERAL_COMMANDS_HELP, DEBUG_COMMANDS_HELP, ADMIN_USER_COMMANDS_HELP, and GameHandler.getDebugCommandsHelp(). "Unprivileged" general commands are handled by handleGAMETEXTMSG(StringConnection, SOCGameTextMsg).

Parameters:
debugCli - Client sending the potential debug command
ga - Game in which the message is sent
dcmd - Text message which may be a debug command
dcmdU - dcmd as uppercase, for efficiency (it's already been uppercased in caller)
Returns:
true if dcmd is a recognized debug command, false otherwise

stopServer

public void stopServer()
The server is being cleanly stopped. Shut down with a final message "The game server is shutting down".

Overrides:
stopServer in class Server

stopServer

public void stopServer(java.lang.String stopMsg)
The server is being cleanly stopped. Send a final message, disconnect all the connections, disconnect from database if connected. Currently called only by the debug command "*STOP*", and by SOCPlayerClient's locally hosted TCP server.

Parameters:
stopMsg - Final text message to send to all connected clients, or null. Will be sent as a SOCBCastTextMsg. As always, if message starts with ">>" it will be considered urgent.

authOrRejectClientUser

private int authOrRejectClientUser(StringConnection c,
                                   java.lang.String msgUser,
                                   java.lang.String msgPass,
                                   int cliVers,
                                   boolean doNameConnection,
                                   boolean allowTakeover)
Check that the username and password (if any) is okay: Length versus PLAYER_NAME_MAX_LENGTH, name in use but not timed out versus takeover, etc. Calls checkNickname(String, StringConnection, boolean) and authenticateUser(StringConnection, String, String).

If not okay, sends client a SOCStatusMessage with an appropriate status code.

If this user is already logged into another connection, checks here whether this new replacement connection can "take over" the existing one according to a timeout calculation in checkNickname(String, StringConnection, boolean).

If this connection isn't already logged on and named (c.getData() == null) and all checks pass: Unless doNameConnection is false, calls c.setData(msgUser) and nameConnection(c, isTakingOver) before returning AUTH_OR_REJECT__OK or AUTH_OR_REJECT__TAKING_OVER.

If this connection is already logged on and named (c.getData() != null), does nothing. Won't check username or password, just returns AUTH_OR_REJECT__OK.

Parameters:
c - Client's connection
msgUser - Client username (nickname) to validate and authenticate; will be trim()med.
msgPass - Password to supply to authenticateUser(StringConnection, String, String), or ""; will be trim()med.
cliVers - Client version, from StringConnection.getVersion()
doNameConnection - True if successful auth of an unnamed connection should have this method call c.setData(msgUser) and nameConnection(c, isTakingOver).

For the usual connect sequence, callers will want true. Some callers might want to check other things after this method and possibly reject the connection at that point; they will want false. Those callers must remember to call c.setData(msgUser) and nameConnection(c, (result == AUTH_OR_REJECT__TAKING_OVER)) themselves to finish authenticating a connection.

allowTakeover - True if the new connection can "take over" an older connection in response to the message it sent. If true, the caller must be prepared to send all game info/channel info that the old connection had joined, so the new connection has full info to participate in them.
Returns:
Result of the auth check: AUTH_OR_REJECT__FAILED, AUTH_OR_REJECT__OK, or (only if allowTakeover) AUTH_OR_REJECT__TAKING_OVER
Since:
1.1.19

authenticateUser

private boolean authenticateUser(StringConnection c,
                                 java.lang.String userName,
                                 java.lang.String password)
authenticate the user: see if the user is in the db, if so then check the password. if they're not in the db, but they supplied a password, then send a message (not OK). if they're not in the db, and no password, then ok.

Parameters:
c - the user's connection
userName - the user's nickname; trim before calling
password - the user's password; trim before calling
Returns:
true if the user has been authenticated

isUserDBUserAdmin

private boolean isUserDBUserAdmin(java.lang.String uname,
                                  boolean requireList)
Is this username on the databaseUserAdmins whitelist, if that whitelist is being used?

Parameters:
uname - Username to check; if null, returns false.
requireList - If true, the whitelist cannot be null. If false, this function returns true for any user when we aren't using the whitelist and its field is null.
Returns:
True only if the user is on the whitelist, or there is no list and requireList is false
Since:
1.1.20

handleSERVERPING

private void handleSERVERPING(StringConnection c,
                              SOCServerPing mes)
Handle the client's echo of a SOCMessage.SERVERPING.

Since:
1.1.08

handleVERSION

private void handleVERSION(StringConnection c,
                           SOCVersion mes)
Handle the "version" message, client's version report. May ask to disconnect, if version is too old. Otherwise send the game list. If we've already sent the game list, send changes based on true version. If they send another VERSION later, with a different version, disconnect the client.

Along with the game list, the client will need to know the game option info. This is sent when the client asks (after VERSION) for GAMEOPTIONGETINFOS.

Parameters:
c - the connection that sent the message
mes - the message

setClientVersSendGamesOrReject

boolean setClientVersSendGamesOrReject(StringConnection c,
                                       int cvers,
                                       java.lang.String clocale,
                                       boolean isKnown)
Set client's version and locale, and check against minimum required version CLI_VERSION_MIN. If version is too low, send REJECTCONNECTION. If we haven't yet sent the game list, send now. If we've already sent the game list, send changes based on true version.

Along with the game list, the client will need to know the game option info. This is sent when the client asks (after VERSION) for GAMEOPTIONGETINFOS. Game options are sent after client version is known, so the list of sent options is based on client version.

I18N: If client doesn't send a locale string, the default locale en_US is used. Robot clients will get the default locale and localeStr here, those will be cleared soon in handleIMAROBOT(StringConnection, SOCImARobot).

Locks: To set the version, will synchronize briefly on unnamedConns. If c.getVersion() is already == cvers, don't bother to lock and set it.

Package access (not private) is strictly for use of SOCClientData.SOCCDCliVersionTask.run().

Parameters:
c - Client's connection
cvers - Version reported by client, or assumed version if no report
clocale - Locale reported by client, or null if none given (was added to SOCVersion in 2.0.00)
isKnown - Is this the client's definite version, or just an assumed one? Affects c.isVersionKnown. Can set the client's known version only once; a second "known" call with a different cvers will be rejected.
Returns:
True if OK, false if rejected

handleJOIN

private void handleJOIN(StringConnection c,
                        SOCJoin mes)
Handle the "join a channel" message. If client hasn't yet sent its version, assume is version 1.0.00 (CLI_VERSION_ASSUMED_GUESS), disconnect if too low.

Requested channel name must pass SOCMessage.isSingleLineAndSafe(String). Channel name "*" is also rejected to avoid conflicts with admin commands.

Parameters:
c - the connection that sent the message
mes - the message

handleLEAVE

private void handleLEAVE(StringConnection c,
                         SOCLeave mes)
Handle the "leave a channel" message

Parameters:
c - the connection that sent the message
mes - the message

handleIMAROBOT

private void handleIMAROBOT(StringConnection c,
                            SOCImARobot mes)
Handle the "I'm a robot" message. Robots send their SOCVersion before sending this message. Their version is checked here, must equal server's version. For stability and control, the cookie in this message must match this server's robotCookie.

Bot tuning parameters are sent to the bot. Its SOCClientData.isRobot flag is set. Its SOCClientData.locale is cleared, but not its StringConnection.setI18NStringManager(SOCStringManager, String).

Sometimes a bot disconnects and quickly reconnects. In that case this method removes the disconnect/reconnect messages from Server.cliConnDisconPrintsPending so they won't be printed.

Parameters:
c - the connection that sent the message
mes - the message

handleGAMETEXTMSG

private void handleGAMETEXTMSG(StringConnection c,
                               SOCGameTextMsg gameTextMsgMes)
Handle game text messages, including debug commands. Was part of processCommand before 1.1.07.

Some commands are unprivileged and can be run by any client:

These commands are processed in this method. Others can be run only by certain users or when certain server flags are set. Those are processed in processDebugCommand(StringConnection, String, String, String).

Since:
1.1.07

processDebugCommand_gameStats

private void processDebugCommand_gameStats(StringConnection c,
                                           java.lang.String gaName,
                                           SOCGame gameData,
                                           boolean isCheckTime)
Print time-remaining and other game stats. Includes more detail beyond the end-game stats sent in SOCGameHandler.sendGameStateOVER(SOCGame).

Before v1.1.20, this method was processDebugCommand_checktime(..).

Parameters:
c - Client requesting the stats
gaName - gameData.getName()
gameData - Game to print stats
isCheckTime - True if called from *CHECKTIME* server command, false for *STATS*. If true, mark text as urgent when sending remaining time before game expires.
Since:
1.1.07

processDebugCommand_who

private void processDebugCommand_who(StringConnection c,
                                     SOCGame ga,
                                     java.lang.String cmdText)
Process unprivileged command *WHO* to show members of current game, or privileged *WHO* gameName|all|* to show all connected clients or some other game's members.

Locks: Takes/releases gameList.takeMonitorForGame(gaName) to call SOCGameListAtServer.getMembers(String).

Parameters:
c - Client sending the *WHO* command
ga - Game in which the command was sent
cmdText - Text of *WHO* command
Since:
1.1.20

handleAUTHREQUEST

private void handleAUTHREQUEST(StringConnection c,
                               SOCAuthRequest mes)
Handle the optional "authentication request" message. Sent by clients since v1.1.19 before creating a game or when connecting using SOCAccountClient.

If c.getData() != null, the client already authenticated and this method replies with SOCStatusMessage.SV_OK without checking the password in this message.

Parameters:
c - the connection that sent the message
mes - the message
Since:
1.1.19
See Also:
isUserDBUserAdmin(String, boolean)

handleJOINGAME

private void handleJOINGAME(StringConnection c,
                            SOCJoinGame mes)
Handle the "join a game" message: Join or create a game. Will join the game, or return a STATUSMESSAGE if nickname is not OK. Clients can join game as an observer, if they don't SITDOWN after joining.

If client hasn't yet sent its version, assume is version 1.0.00 (CLI_VERSION_ASSUMED_GUESS), disconnect if too low. If the client is too old to join a specific game, return a STATUSMESSAGE. (since 1.1.06)

Parameters:
c - the connection that sent the message
mes - the message

createOrJoinGameIfUserOK

private void createOrJoinGameIfUserOK(StringConnection c,
                                      java.lang.String msgUser,
                                      java.lang.String msgPass,
                                      java.lang.String gameName,
                                      java.util.Map<java.lang.String,SOCGameOption> gameOpts)
Check username/password and create new game, or join game. Called by handleJOINGAME and handleNEWGAMEWITHOPTIONSREQUEST. JOINGAME or NEWGAMEWITHOPTIONSREQUEST may be the first message with the client's username and password, so c.getData() may be null. Assumes client's version is already received or guessed.

Game name and player name have a maximum length and some disallowed characters; see parameters. Check the client's SOCClientData.getCurrentCreatedGames() vs CLIENT_MAX_CREATE_GAMES.

If client is replacing/taking over their own lost connection, first tell them they're rejoining all their other games. That way, the requested game's window will appear last, not hidden behind the others.

Process if gameOpts != null:

Parameters:
c - connection requesting the game, must not be null
msgUser - username of client in message. Must pass SOCMessage.isSingleLineAndSafe(String) and be at most PLAYER_NAME_MAX_LENGTH characters. Calls msgUser.trim() before checking length.
msgPass - password of client in message; will be trim()med.
gameName - name of game to create/join. Must pass SOCMessage.isSingleLineAndSafe(String) and be at most GAME_NAME_MAX_LENGTH characters. Calls gameName.trim() before checking length. Game name "*" is also rejected to avoid conflicts with admin commands.
gameOpts - if game has options, contains SOCGameOption to create new game; if not null, will not join an existing game. Will validate and adjust by calling SOCGameOption.adjustOptionsToKnown(Map, Map, boolean) with doServerPreadjust true.
Since:
1.1.07

startRobotOnlyGames

private void startRobotOnlyGames(boolean hasGameListMonitor)
Start a few robot-only games if numRobotOnlyGamesRemaining > 0.

Locks: May or may not have SOCGameList.takeMonitor() when calling; see hasGameListMonitor parameter. If not already held, this method takes and releases that monitor.

Parameters:
hasGameListMonitor - True if caller holds the SOCGameList.takeMonitor() lock already
Since:
2.0.00

handleLEAVEGAME

private void handleLEAVEGAME(StringConnection c,
                             SOCLeaveGame mes)
Handle the "leave game" message

Parameters:
c - the connection that sent the message
mes - the message

handleLEAVEGAME_member

private void handleLEAVEGAME_member(StringConnection c,
                                    java.lang.String gaName)
Handle a member leaving the game, from handleLEAVEGAME(StringConnection, SOCLeaveGame).

Since:
1.1.07

handleLEAVEGAME_maybeGameReset_oldRobot

private void handleLEAVEGAME_maybeGameReset_oldRobot(java.lang.String gaName)
Handle an unattached robot saying it is leaving the game, from handleLEAVEGAME(StringConnection, SOCLeaveGame). Ignore the robot (since it's not a member of the game) unless gamestate is SOCGame.READY_RESET_WAIT_ROBOT_DISMISS.

Since:
1.1.07

handleSITDOWN

private void handleSITDOWN(StringConnection c,
                           SOCSitDown mes)
handle "sit down" message

Parameters:
c - the connection that sent the message
mes - the message

handleSTARTGAME

private void handleSTARTGAME(StringConnection c,
                             SOCStartGame mes,
                             int botsOnly_maxBots)
handle "start game" message. Game state must be NEW, or this message is ignored. Ask some robots to fill empty seats, or begin the game if no robots needed.

Called when clients have sat at a new game and a client asks to start it, not called during game board reset.

For robot debugging, a client can start and observe a robots-only game if the PROP_JSETTLERS_BOTS_BOTGAMES_TOTAL property != 0 (including < 0).

Parameters:
c - the connection that sent the message
mes - the message
botsOnly_maxBots - For bot debugging, maximum number of bots to add to the game, or 0 to fill all empty seats. This parameter is used only when requesting a new robots-only game using the *STARTBOTGAME* debug command; ignored otherwise.

readyGameAskRobotsJoin

private void readyGameAskRobotsJoin(SOCGame ga,
                                    StringConnection[] robotSeats,
                                    int maxBots)
                             throws java.lang.IllegalStateException,
                                    java.lang.IllegalArgumentException
Fill all the unlocked empty seats with robots, by asking them to join. Builds a Vector of StringConnections of robots asked to join, and adds it to the robotJoinRequests table. Game state should be READY. At most SOCGame.getAvailableSeatCount() robots will be asked.

Called by handleSTARTGAME, resetBoardAndNotify.

Once the robots have all responded (from their own threads/clients) and joined up, the game can begin.

Parameters:
ga - Game to ask robots to join
robotSeats - If robotSeats is null, robots are randomly selected. If non-null, a MAXPLAYERS-sized array of StringConnections. Any vacant non-locked seat, with index i, is filled with the robot whose connection is robotSeats[i]. Other indexes should be null, and won't be used.
maxBots - Maximum number of bots to add, or 0 to fill all empty seats
Throws:
java.lang.IllegalStateException - if ga.gamestate is not READY, or if ga.version is somehow newer than server's version (which is assumed to be robots' version).
java.lang.IllegalArgumentException - if robotSeats is not null but wrong length, or if a robotSeat element is null but that seat wants a robot (vacant non-locked).

debug_printPieceDiceNumbers

void debug_printPieceDiceNumbers(SOCGame ga,
                                 java.lang.String message)
Temporary debugging; call when "no player gets anything" will be printed after a roll.

Parameters:
ga - Game data
message - "no player gets anything" string
Since:
2.0.00

debug_printPieceDiceNumbers_pl

private boolean debug_printPieceDiceNumbers_pl(SOCPlayer pl,
                                               int roll,
                                               SOCBoard board,
                                               java.lang.String pieceType,
                                               java.util.Enumeration<? extends SOCPlayingPiece> pe)
Temporary debugging; for 1 player. Similar code to SOCGame.getResourcesGainedFromRollPieces(int, soc.game.SOCResourceSet, soc.game.SOCResourceSet, int, java.util.Collection, int).

Returns:
true if this player appears to have a resource on a hex numbered roll
Since:
2.0.00

handleCHANGEFACE

private void handleCHANGEFACE(StringConnection c,
                              SOCChangeFace mes)
handle "change face" message.

Parameters:
c - the connection
mes - the message

handleSETSEATLOCK

private void handleSETSEATLOCK(StringConnection c,
                               SOCSetSeatLock mes)
handle "set seat lock" message.

Parameters:
c - the connection
mes - the message

handleRESETBOARDREQUEST

private void handleRESETBOARDREQUEST(StringConnection c,
                                     SOCResetBoardRequest mes)
handle "reset-board request" message. If multiple human players, start a vote. Otherwise, reset the game to a copy with same name and (copy of) same players, new layout.

The requesting player doesn't vote, but server still sends the vote-request-message, to tell that client their request was accepted and voting has begun.

If only one player remains (all other humans have left at end), ask them to start a new game instead. This is a rare occurrence and we shouldn't bring in new robots and all, since we already have an interface to set up a game.

If any human player's client is too old to vote for reset, assume they vote yes.

Parameters:
c - the connection
mes - the message
See Also:
resetBoardAndNotify(String, int)

handleRESETBOARDVOTE

private void handleRESETBOARDVOTE(StringConnection c,
                                  SOCResetBoardVote mes)
handle message of player's vote for a "reset-board" request. Register the player's vote. If all votes have now arrived, and the vote is unanimous, reset the game to a copy with same name and players, new layout.

Parameters:
c - the connection
mes - the message
See Also:
resetBoardAndNotify(String, int)

resetBoardVoteNotifyOne

void resetBoardVoteNotifyOne(SOCGame ga,
                             int pn,
                             java.lang.String plName,
                             boolean vyes)
"Reset-board" request: Register one player's vote, and let game members know. If vote succeeded, go ahead and reset the game. If vote rejected, let everyone know.

Parameters:
ga - Game for this reset vote
pn - Player number who is voting
plName - Name of player who is voting
vyes - Player's vote, Yes or no

clientHasLocalizedStrs_gameScenarios

public static final boolean clientHasLocalizedStrs_gameScenarios(StringConnection c)
Does this client's locale have localized SOCScenario names and descriptions? Checks these conditions:

Parameters:
c - Client connection
Returns:
True if the client meets all the conditions listed above, false otherwise
Since:
2.0.00

localizeGameScenarios

public static java.util.List<java.lang.String> localizeGameScenarios(java.util.Locale loc,
                                                                     java.util.Collection<java.lang.String> scKeys,
                                                                     boolean checkUnknowns_skipFirst,
                                                                     SOCClientData scd)
Get localized strings for known SOCScenarios. Assumes client locale has scenario strings: Call clientHasLocalizedStrs_gameScenarios(StringConnection) before calling this method. Fills and returns a list with each scKeys key, scenario name, scenario description from c.getLocalized("gamescen." + scKey + ".n") and ("gamescen." + scKey + ".d").

Parameters:
loc - Client's locale for StringManager i18n lookups. This is passed instead of the client connection to simplify SOCPlayerClient's localizations before starting its practice server.
scKeys - Scenario keynames to localize, such as a List of keynames or the Set returned from SOCScenario.getAllKnownScenarioKeynames(). null to use SOCScenario.getAllKnownScenarioKeynames().
checkUnknowns_skipFirst - Switch to allow calling this method from multiple places:
  • If false, assumes scKeys has no unknown keys, will not call SOCScenario.getScenario(String) to verify them. scKeys could be SOCScenario.getAllKnownScenarioKeynames(), for example. The localized strings for each scKey are looked up and added to the list if found. If any scKey is missing localized string(s), that key won't be in the returned list.
  • If true, assumes scKeys is a List of keys from a client, and may have scenario names unknown at this server version. Will ignore the first entry because in the client message, the first list entry isn't a scenario key. Will call SOCScenario.getScenario(String) on each key to verify it exists. The localized strings for each known scKey are looked up and added to the list. If the scenario is unknown or its strings aren't localized, the key and SOCLocalizedStrings.MARKER_KEY_UNKNOWN are added instead.
scd - Optional client data to track which scenario strings are sent to client, or null. This method will update scd.scenariosInfoSent.
Returns:
Localized string list, may be empty but will never be null, in same format as the message returned from server to client: Scenario keys with localized strings have 3 consecutive entries in the list: Key, name, description. If checkUnknowns_skipFirst, unknown scenarios have 2 consecutive entries in the list: Key, SOCLocalizedStrings.MARKER_KEY_UNKNOWN.
Since:
2.0.00

handleLOCALIZEDSTRINGS

private void handleLOCALIZEDSTRINGS(StringConnection c,
                                    SOCLocalizedStrings mes)
Handle client request for localized i18n strings for game items. Added 2015-01-14 for v2.0.00.


handleGAMEOPTIONGETDEFAULTS

private void handleGAMEOPTIONGETDEFAULTS(StringConnection c,
                                         SOCGameOptionGetDefaults mes)
process the "game option get defaults" message. User has clicked the "New Game" button for the first time, client needs SOCGameOption values. Responds to client by sending GAMEOPTIONGETDEFAULTS. All of server's known options are sent, except empty string-valued options. Depending on client version, server's response may include option names that the client is too old to use; the client is able to ignore them. If the client is older than SOCGameOption.VERSION_FOR_LONGER_OPTNAMES, options with long names won't be sent.

I18N: Since the New Game dialog will need localized strings for SOCScenarios, v2.0.00 sends those strings before the game option default values, so the client will have them before showing the dialog.

Parameters:
c - the connection
mes - the message
Since:
1.1.07

handleGAMEOPTIONGETINFOS

private void handleGAMEOPTIONGETINFOS(StringConnection c,
                                      SOCGameOptionGetInfos mes)
process the "game option get infos" message; reply with the info, with one GAMEOPTIONINFO message per option keyname. Mark the end of the option list with GAMEOPTIONINFO("-"). If this list is empty, "-" will be the only GAMEOPTIONGETINFO message sent.

We check the default values, not current values, so the list is unaffected by cases where some option values are restricted to newer client versions. Any option where opt.minVersion is too new for this client's version, is sent as SOCGameOption.OTYPE_UNKNOWN. If the client is older than SOCGameOption.VERSION_FOR_LONGER_OPTNAMES, options with long names won't be sent.

Parameters:
c - the connection
mes - the message
Since:
1.1.07

handleSCENARIOINFO

private void handleSCENARIOINFO(StringConnection c,
                                SOCScenarioInfo mes)
Process client request for updated SOCScenario info. Added 2015-09-21 for v2.0.00.


sendGameScenarioInfo

void sendGameScenarioInfo(java.lang.String scKey,
                          SOCScenario sc,
                          StringConnection c,
                          boolean stringsOnly)
If needed, send this scenario's updated info and i18n localized short/long description strings to the client. Checks whether the scenario has been added or changed since the client's version, whether the scenario has strings in the client's locale, and whether the client has already been sent this scenario's info or strings.

Sends nothing if scKey and sc are both null. Sends nothing if client's version is older than 2.0.00 (SOCScenario.VERSION_FOR_SCENARIOS). Will not send localized strings if locale is null. Checks and updates the connection's SOCClientData.sentAllScenarioStrings, SOCClientData.sentAllScenarioInfo, SOCClientData.scenariosInfoSent and related tracking fields.

Scenario's minVersion isn't checked here; may send information about a scenario that's too new for the client's version to join games with it.

Parameters:
scKey - Scenario keyname, from game.getGameOptionStringValue("SC"), or null. Sends nothing if scKey and sc are both null.
sc - Scenario data if known, or null to use SOCScenario.getScenario(scKey). When sc != null, will always send a SOCScenarioInfo message even if SOCClientData.sentAllScenarioInfo is set, unless client version is too old.
c - Client connection
stringsOnly - If true, send only localized strings, not entire SOCScenarioInfo.
Since:
2.0.00

handleNEWGAMEWITHOPTIONSREQUEST

private void handleNEWGAMEWITHOPTIONSREQUEST(StringConnection c,
                                             SOCNewGameWithOptionsRequest mes)
process the "new game with options request" message. For messages sent, and other details, see createOrJoinGameIfUserOK(StringConnection, String, String, String, Map).

Because this message is sent only by clients newer than 1.1.06, we definitely know that the client has already sent its version information.

Parameters:
c - the connection
mes - the message
Since:
1.1.07

handleCREATEACCOUNT

private void handleCREATEACCOUNT(StringConnection c,
                                 SOCCreateAccount mes)
handle "create account" message

Parameters:
c - the connection
mes - the message

joinGame

private void joinGame(SOCGame gameData,
                      StringConnection c,
                      boolean isReset,
                      boolean isTakingOver)
Client has been approved to join game; send the entire state of the game to client. Gets the game's handler and calls GameHandler.joinGame(SOCGame, StringConnection, boolean, boolean); see that method's javadoc for details.

Parameters:
gameData - Game to join
c - The connection of joining client
isReset - Game is a board-reset of an existing game; should always be false when server is calling, board resets are up to the GameHandler.
isTakingOver - Client is re-joining; this connection replaces an earlier one which is defunct because of a network problem. If isTakingOver, don't send anything to other players.
See Also:
connectToGame(StringConnection, String, Map), createOrJoinGameIfUserOK(StringConnection, String, String, String, Map)

sitDown

private void sitDown(SOCGame ga,
                     StringConnection c,
                     int pn,
                     boolean robot,
                     boolean isReset)
This player is sitting down at the game. The server has already validated that the game isn't full and their seat is empty, or has removed a bot to make room at that seat.

Calls SOCGame.addPlayer(String, int). Announces with SOCSitDown to all game members. Sends sitting player their own data via GameHandler.sitDown_sendPrivateInfo(SOCGame, StringConnection, int). If game is waiting for robots to join, and sitting player is the last bot, start the game.

Parameters:
ga - the game
c - the connection for the player
pn - which seat the player is taking
robot - true if this player is a robot
isReset - Game is a board-reset of an existing game

resetBoardAndNotify

private void resetBoardAndNotify(java.lang.String gaName,
                                 int requestingPlayer)
Reset the board, to a copy with same players but new layout. Here's the general outline; step 1 and 2 are done immediately here, steps 3 through n are done (after robots are dismissed) within resetBoardAndNotify_finish(SOCGameBoardReset, SOCGame).
  1. Reset the board, remember player positions. If there are robots, set game state to SOCGame.READY_RESET_WAIT_ROBOT_DISMISS.
  2. Send ResetBoardAuth to each client (like sending JoinGameAuth at new game) Humans will reset their copy of the game. Robots will leave the game, and soon be requested to re-join. (This simplifies the robot client.) If the game was in initial placement or was already over at reset time, different robots will be randomly chosen to join the reset game.
  3. If there were robots, wait for them all to leave the old game. Otherwise, (race condition) they may leave the new game as it is forming. Set SOCGame.boardResetOngoingInfo. Wait for them to leave the old game before continuing. The call will be made from handleLEAVEGAME_maybeGameReset_oldRobot(String).
  4. If no robots, immediately call resetBoardAndNotify_finish(SOCGameBoardReset, SOCGame).

    This ends this method. Step 3 and the rest are in resetBoardAndNotify_finish(SOCGameBoardReset, SOCGame).

  5. Send messages as if each human player has clicked "join" (except JoinGameAuth)
  6. Send as if each human player has clicked "sit here"
  7. If no robots, send to game as if someone else has clicked "start game", and set up state to begin game play.
  8. If there are robots, set up wait-request queue (robotJoinRequests). Game will wait for robots to send JOINGAME and SITDOWN, as they do when joining a newly created game. Once all robots have re-joined, the game will begin.


resetBoardAndNotify_finish

private void resetBoardAndNotify_finish(SOCGameBoardReset reBoard,
                                        SOCGame reGame)
Complete steps 3 - n of the board-reset process outlined in resetBoardAndNotify(String, int), after any robots have left the old game.

Parameters:
reBoard - Board reset data, from SOCGameListAtServer.resetBoard(String) or reGame.boardResetOngoingInfo
reGame - The new game created by the reset, with gamestate NEW or READY_RESET_WAIT_ROBOT_DISMISS
Since:
1.1.07

gameOverIncrGamesFinishedCount

void gameOverIncrGamesFinishedCount()
Increment the "number of games finished" server-statistics field. Call when a game's state becomes SOCGame.OVER (or higher) from a lower/earlier state.

Thread-safe; synchronizes on an internal object. Package-level access for calls from GameHandlers.

Since:
2.0.00

storeGameScores

protected void storeGameScores(SOCGame ga)
Save game stats in the database. if all the players stayed for the whole game, or if the game has any human players, record the scores in the database.

Does nothing unless property jsettlers.db.save.games is true. (SOCDBHelper.PROP_JSETTLERS_DB_SAVE_GAMES)

Parameters:
ga - the game; state should be SOCGame.OVER

recordGameEvent

protected void recordGameEvent(java.lang.String gameName,
                               java.lang.String event)
record events that happen during the game

Parameters:
gameName - the name of the game
event - the event

checkForExpiredGames

public void checkForExpiredGames(long currentTimeMillis)
check for games that have expired and destroy them. If games are about to expire, send a warning. As of version 1.1.09, practice games (SOCGame.isPractice flag set) don't expire. Is callback method every few minutes from SOCGameTimeoutChecker.run().

Parameters:
currentTimeMillis - The time when called, from System.currentTimeMillis()
See Also:
GAME_TIME_EXPIRE_WARN_MINUTES, checkForExpiredTurns(long)

checkForExpiredTurns

public void checkForExpiredTurns(long currentTimeMillis)
Check all games for robot turns that have expired, and end that turn, or stop waiting for non-current-player robot actions (discard picks, etc). Robot turns may end from inactivity or from an illegal placement. Checks each game's SOCGame.lastActionTime field, and calls GameHandler.endTurnIfInactive(SOCGame, long) if the last action is older than ROBOT_FORCE_ENDTURN_SECONDS.

Is callback method every few seconds from SOCGameTimeoutChecker.run().

Parameters:
currentTimeMillis - The time when called, from System.currentTimeMillis()
Since:
1.1.11
See Also:
ROBOT_FORCE_ENDTURN_SECONDS, checkForExpiredGames(long)

parseCmdline_GameOption

public static SOCGameOption parseCmdline_GameOption(SOCGameOption op,
                                                    java.lang.String optRaw,
                                                    java.util.HashMap<java.lang.String,java.lang.String> optsAlreadySet)
                                             throws java.lang.IllegalArgumentException
Quick-and-dirty command line parsing of a game option. Calls SOCGameOption.setKnownOptionCurrentValue(SOCGameOption).

Note that an unknown SOCScenario name (value of game option "SC") isn't treated as an error here; SC's value will be set to the unknown scenario. Code elsewhere will print an error and halt startup.

Parameters:
op - Game option, as parsed by SGO.parseOptionNameValue(optNameValue, true) or SGO.parseOptionNameValue(optkey, optval, true).
Keyname should be case-insensitive; note both of those calls include forceNameUpcase == true.
null is allowed and will throw IllegalArgumentException("Unknown or malformed game option: " + optRaw).
optRaw - To include in exception text or a value into optsAlreadySet, the option name or name=value from command line. Should not be null.
optsAlreadySet - For tracking, game option names we've already encountered on the command line. This method will add (optName, optNameValue) to this map. Can be null if not needed.
Returns:
the parsed SOCGameOption
Throws:
java.lang.IllegalArgumentException - if bad name, bad value, or already set from command line. Throwable.getMessage() will have problem details:
Since:
1.1.07

parseCmdline_DashedArgs

public static java.util.Properties parseCmdline_DashedArgs(java.lang.String[] args)
Quick-and-dirty parsing of command-line arguments with dashes.

Checks first for the optional server startup properties file "jsserver.properties" (SOC_SERVER_PROPS_FILENAME). If the file exists but there is an error reading it, calls System.exit(1) to exit because currently only main(..) calls this method. For details on the java properties file syntax (# starts a comment line, etc), see Properties.load(java.io.InputStream).

If a property appears on the command line and also in jsserver.properties, the command line's value overrides the file's.

If any game options are set ("-o", "--option"), then hasSetGameOptions is set to true, and SOCGameOption.setKnownOptionCurrentValue(SOCGameOption) is called to set them globally.

If jsserver.properties file contains game option properties (jsettlers.gameopt.*), they will be checked for possible problems:

See PROP_JSETTLERS_GAMEOPT_PREFIX for game option property syntax.

If args[] is empty, it will use defaults for PROP_JSETTLERS_PORT and PROP_JSETTLERS_CONNECTIONS}.

Does not use a PROP_JSETTLERS_STARTROBOTS default, that's handled in initSocServer(String, String, Properties).

Sets hasStartupPrintAndExit if appropriate.

Parameters:
args - args as passed to main
Returns:
Properties collection of args, or null for argument error. Will contain at least PROP_JSETTLERS_PORT, PROP_JSETTLERS_CONNECTIONS, SOCDBHelper.PROP_JSETTLERS_DB_USER, SOCDBHelper.PROP_JSETTLERS_DB_PASS.
Since:
1.1.07

init_propsSetGameopts

private static final void init_propsSetGameopts(java.util.Properties pr)
                                         throws java.lang.IllegalArgumentException
Set game option defaults from any jsettlers.gameopt.* server properties found. Option keynames are case-insensitive past that prefix. See PROP_JSETTLERS_GAMEOPT_PREFIX for expected syntax. Calls parseCmdline_GameOption(SOCGameOption, String, HashMap) for each one found, to set its current value in SOCGameOptions's static set of known opts.

Note that an unknown SOCSscenario name (value of game option "SC") is not an error here; init_checkScenarioOpts(Map, boolean, String, String, String) will check for that and its caller will halt startup if found.

Parameters:
pr - Properties which may contain PROP_JSETTLERS_GAMEOPT_PREFIX* entries
Throws:
java.lang.IllegalArgumentException - if any game option property has a bad name or value. Throwable.getMessage() will collect all option problems to 1 string, separated by "\n":
Since:
1.1.20

checkScenarioOpts

public static java.util.List<Triple> checkScenarioOpts(java.util.Map<?,?> opts,
                                                       boolean optsAreProps,
                                                       java.lang.String scName)
When a server's properties or command line contain a default scenario (game option "SC"), check that the scenario is known and that its game options don't conflict with any others specified in the properties or command line.

The scenario named in opts.get("SC") or scName is retrieved with SOCScenario.getScenario(String); an empty scenario name "" is treated as an unknown scenario.

The scenario will be the default scenario, but its option values aren't set as default at server startup. When a new game begins using that scenario, at that time scenario options override any other options specified for the game (except whichever "VP" is greater is kept). Since the user may specify a different scenario, 'conflicting' options in opts are only potentially a problem and will be returned as a list for warnings (not errors) to be printed during server init.

Parameters:
opts - Option name key and value strings, typically from command line or properties file parsing. See optsIsFromProps for format of opts keys and values.
optsAreProps - If true, opts keys and values are from the properties file: key = PROP_JSETTLERS_GAMEOPT_PREFIX + optname, value = option value. Option names are not case-sensitive but PROP_JSETTLERS_GAMEOPT_PREFIX is.
If false, keys and values are from command line parsing: key = uppercase optname, value = optkey + "=" + option value.
scName - Scenario name to check against, or null to use value of opts.get("SC"); never ""
Since:
2.0.00

init_checkScenarioOpts

private static boolean init_checkScenarioOpts(java.util.Map<?,?> opts,
                                              boolean optsAreProps,
                                              java.lang.String srcDesc,
                                              java.lang.String scName,
                                              java.lang.String scNameSrcDesc)
During startup, call checkScenarioOpts(Map, boolean, String) and print any warnings it returns to System.err. An unknown scenario name is printed as an error not a warning. An empty scenario name "" from opts.get("SC") or scName is treated as an unknown scenario.

Parameters:
opts - Options to check, see checkScenarioOpts(Map, boolean, String)
optsAreProps - Are opts from properties or command line? See checkScenarioOpts(Map, boolean, String).
srcDesc - Description of opts for warning message text: "Command line" or properties filename "jsserver.properties"
scName - Scenario name to check against, or null to use value of opts.get("SC"); never ""
scNameSrcDesc - If scName isn't from opts, lowercase description of its source for warnings (like srcDesc), otherwise null. If scNameSrcDesc != null, will not print a warning if scName is unknown, to avoid repeating the warning already printed when that SC was checked while parsing its source.
Returns:
True if the provided scenario name is known or there is no "SC" option, false if unknown.
Since:
2.0.00

init_resetUserPassword

private void init_resetUserPassword(java.lang.String uname)
If command line contains --pw-reset=username, prompt for and change that user's password.

If successful, sets getUtilityModeMessage() to "The password was changed" or similar; if unsuccessful (no db, user not found, etc), prints an error and sets getUtilityModeMessage() to null.

Parameters:
uname - Username to change password
Since:
1.1.20

printAuditMessage

private void printAuditMessage(java.lang.String req,
                               java.lang.String msg,
                               java.lang.String obj,
                               java.util.Date at,
                               java.lang.String reqHost)
Print a security-action audit message to System.out in a standard format.
Example with object:
Audit: Requested jsettlers account creation, already exists: 'obj' by 'req' from reqHost at at
Example without object:
Audit: Requested jsettlers account creation, this requester not on account admin whitelist: 'req' from reqHost at at

Parameters:
req - Requesting user, or null if unknown
msg - Message text
obj - Object affected by the action, or null if none
at - Timestamp, or null to use current time
reqHost - Requester client's hostname, from StringConnection.host()
Since:
1.1.20

printUsage

public static void printUsage(boolean longFormat)
Print command line parameter information, including options ("--" / "-").

Parameters:
longFormat - short or long? Long format gives details and also calls Version.printVersionText(java.io.PrintStream, String) beforehand. Short format is printed at most once, after checking printedUsageAlready.
Since:
1.1.07

printGameOptions

public static void printGameOptions()
Print out the list of possible game options, and current values.

Since:
1.1.07

clearBuffer

private static void clearBuffer(java.lang.StringBuilder sb)
Clear the contents of a StringBuffer by setting to ' ' each character in its current StringBuilder.length().

Parameters:
sb - StringBuilder to clear
Since:
1.1.20

readPassword

private static java.lang.StringBuilder readPassword(java.lang.String prompt)
Read a password from the console; currently used for password reset. Blocks the calling thread while waiting for input.

This rudimentary method exists for compatability: java 1.5 doesn't have System.console.readPassword(), and the Eclipse console also doesn't offer System.console.

The input is not masked because there's no cross-platform way to do so in 1.5.

Parameters:
prompt - Optional password prompt; default is "Password:"
Returns:
The password read, or an empty string "" if an error occurred. This is returned as a mutable StringBuilder so the caller can clear its contents when done, using clearBuffer(StringBuilder). If ^C or an error occurs, returns null.
Since:
1.1.20

main

public static void main(java.lang.String[] args)
Starting the server from the command line

Checks for the optional server startup properties file "jsserver.properties", and parses the command line for switches. If a property appears on the command line and also in jsserver.properties, the command line's value overrides the file's.

Creates and starts a SOCServer via SOCServer(int, Properties).

If there are problems with the network setup, or with running a db setup script, this method will call System.exit(1).

If a db setup script runs successfully, this method will call System.exit(2).

Parameters:
args - arguments: port number, etc
See Also:
printUsage(boolean)