net.sf.freecol
Class FreeCol

java.lang.Object
  extended by net.sf.freecol.FreeCol

public final class FreeCol
extends java.lang.Object

This class is responsible for handling the command-line arguments and starting either the stand-alone server or the client-GUI.

See Also:
FreeColClient, FreeColServer

Field Summary
private static java.io.File autoSaveDirectory
          Directory containing automatically created save games.
private static boolean checkIntegrity
           
static java.lang.String CLIENT_THREAD
           
private static java.io.File clientOptionsFile
           
private static boolean consoleLogging
           
private static java.lang.String dataFolder
           
private static int DEBUG_FULL
           
private static int DEBUG_LIMITED
           
private static int DEBUG_OFF
           
private static int debugLevel
           
private static java.lang.String debugRunSave
           
private static int debugRunTurns
           
static int DEFAULT_PORT
           
private static java.lang.String DEFAULT_SPLASH_FILE
           
static java.lang.String DEFAULT_TC
           
private static java.lang.String fontName
           
private static java.lang.String FREECOL_REVISION
           
private static java.lang.String FREECOL_VERSION
           
private static FreeColClient freeColClient
           
private static long freeColSeed
           
private static boolean introVideo
           
private static boolean javaCheck
           
private static java.lang.String logFile
           
private static java.util.logging.Logger logger
           
private static java.util.logging.Level logLevel
           
private static java.io.File mainUserDirectory
           
private static boolean memoryCheck
           
static java.lang.String META_SERVER_ADDRESS
           
static int META_SERVER_PORT
           
static java.lang.String METASERVER_THREAD
           
private static java.lang.String MIN_JDK_VERSION
           
private static org.apache.commons.cli.Options options
           
private static boolean publicServer
           
private static java.io.File saveDirectory
           
private static java.io.File savegameFile
           
static java.lang.String SERVER_THREAD
           
private static java.lang.String serverName
           
private static int serverPort
           
private static boolean sound
           
private static java.lang.String splashFilename
           
private static boolean standAloneServer
           
private static java.lang.String tc
           
private static java.io.File tcUserDirectory
           
private static java.io.File userModsDirectory
           
private static java.awt.Dimension windowSize
           
 
Constructor Summary
private FreeCol()
           
 
Method Summary
private static boolean checkJavaVersion()
          Ensure that the Java version is good enough.
static void completeDebugRun()
          Complete debug run.
private static void createAndSetDirectories()
          Creates a freecol dir for the current user.
static java.io.File getAutosaveDirectory()
          Returns the directory where the autogenerated savegames should be put.
static java.io.File getClientOptionsFile()
          Returns the file containing the client options.
static java.io.File getDataDirectory()
          Returns the data directory.
static java.lang.String getDebugRunSaveName()
          Gets the name of a file to save to at the end of a debug run.
static int getDebugRunTurns()
          Gets the turns to run in debug mode.
static int getDefaultPort()
          Returns the default server network port.
static FreeColClient getFreeColClient()
          Gets the FreeColClient.
static long getFreeColSeed()
          Gets the seed for the PRNG.
static java.util.Locale getLocale()
          Determines the Locale to be used.
static java.lang.String getLogFile()
          Returns the name of the log file.
static java.io.File getOptionsDirectory()
          Returns the directory for saving options.
static java.lang.String getRevision()
          Gets the current revision of game.
static java.io.File getSaveDirectory()
          Returns the directory where the savegames should be put.
static java.io.InputStream getSpecificationInputStream()
           
static java.io.File getStandardModsDirectory()
          Gets the mods directory.
static java.io.File getUserModsDirectory()
          Gets the user mods directory.
static java.lang.String getVersion()
          Gets the current version of game.
private static void handleArgs(java.lang.String[] args)
          Checks the command-line arguments and takes appropriate actions for each of them.
static void incrementFreeColSeed()
          Increments the seed for the PRNG.
private static void initLogging()
          Initialize loggers.
private static boolean insistDirectory(java.io.File file)
          Try to make a directory.
static boolean isDebugRunComplete()
          Is a debug run complete?
static boolean isInDebugMode()
          Checks if the program is in "Debug mode".
static boolean isInFullDebugMode()
          Checks if the program is in the full debug mode, rather than the limited version which does not initialize a player colony.
static void main(java.lang.String[] args)
          The entrypoint.
private static void printUsage()
           
static void setInDebugMode(boolean debug)
          Sets the "debug mode" to be active or not.
static void setSaveDirectory(java.io.File saveDirectory)
          Set the directory where the savegames should be put.
private static void setSavegame(java.lang.String name)
          Set up the save file and directory
private static void startServer()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

private static final java.util.logging.Logger logger

META_SERVER_ADDRESS

public static final java.lang.String META_SERVER_ADDRESS
See Also:
Constant Field Values

META_SERVER_PORT

public static final int META_SERVER_PORT
See Also:
Constant Field Values

DEFAULT_PORT

public static final int DEFAULT_PORT
See Also:
Constant Field Values

CLIENT_THREAD

public static final java.lang.String CLIENT_THREAD
See Also:
Constant Field Values

SERVER_THREAD

public static final java.lang.String SERVER_THREAD
See Also:
Constant Field Values

METASERVER_THREAD

public static final java.lang.String METASERVER_THREAD
See Also:
Constant Field Values

DEFAULT_TC

public static final java.lang.String DEFAULT_TC
See Also:
Constant Field Values

FREECOL_VERSION

private static final java.lang.String FREECOL_VERSION
See Also:
Constant Field Values

FREECOL_REVISION

private static java.lang.String FREECOL_REVISION

MIN_JDK_VERSION

private static final java.lang.String MIN_JDK_VERSION
See Also:
Constant Field Values

DEFAULT_SPLASH_FILE

private static final java.lang.String DEFAULT_SPLASH_FILE
See Also:
Constant Field Values

sound

private static boolean sound

javaCheck

private static boolean javaCheck

memoryCheck

private static boolean memoryCheck

consoleLogging

private static boolean consoleLogging

introVideo

private static boolean introVideo

dataFolder

private static java.lang.String dataFolder

logFile

private static java.lang.String logFile

freeColClient

private static FreeColClient freeColClient

standAloneServer

private static boolean standAloneServer

publicServer

private static boolean publicServer

DEBUG_OFF

private static final int DEBUG_OFF
See Also:
Constant Field Values

DEBUG_LIMITED

private static final int DEBUG_LIMITED
See Also:
Constant Field Values

DEBUG_FULL

private static final int DEBUG_FULL
See Also:
Constant Field Values

debugLevel

private static int debugLevel

debugRunTurns

private static int debugRunTurns

debugRunSave

private static java.lang.String debugRunSave

fontName

private static java.lang.String fontName

serverPort

private static int serverPort

serverName

private static java.lang.String serverName

mainUserDirectory

private static java.io.File mainUserDirectory

saveDirectory

private static java.io.File saveDirectory

autoSaveDirectory

private static java.io.File autoSaveDirectory
Directory containing automatically created save games. At program start, the path of this directory is based on the path where to store regular save games. If the value of saveGame is changed by the user during the game, then the value of autoSaveDirectory will not be effected.


tcUserDirectory

private static java.io.File tcUserDirectory

userModsDirectory

private static java.io.File userModsDirectory

tc

private static java.lang.String tc

savegameFile

private static java.io.File savegameFile

clientOptionsFile

private static java.io.File clientOptionsFile

logLevel

private static java.util.logging.Level logLevel

checkIntegrity

private static boolean checkIntegrity

options

private static final org.apache.commons.cli.Options options

splashFilename

private static java.lang.String splashFilename

windowSize

private static java.awt.Dimension windowSize

freeColSeed

private static long freeColSeed
Constructor Detail

FreeCol

private FreeCol()
Method Detail

main

public static void main(java.lang.String[] args)
The entrypoint.

Parameters:
args - The command-line arguments.

initLogging

private static void initLogging()
Initialize loggers.


getLocale

public static java.util.Locale getLocale()
Determines the Locale to be used.

Returns:
Currently this method returns the locale set by the ClientOptions (read directly from "options.xml"). This behavior will probably be changed.

getDefaultPort

public static int getDefaultPort()
Returns the default server network port.

Returns:
The port number.

getClientOptionsFile

public static java.io.File getClientOptionsFile()
Returns the file containing the client options.

Returns:
The file.

getFreeColClient

public static FreeColClient getFreeColClient()
Gets the FreeColClient.

Returns:
The FreeColClient, or null if the game is run as a standalone server.

insistDirectory

private static boolean insistDirectory(java.io.File file)
Try to make a directory.

Parameters:
file - A File specifying where to make the directory.
Returns:
True if the directory is there after the call.

createAndSetDirectories

private static void createAndSetDirectories()
Creates a freecol dir for the current user. The directory is created within the current user's home directory. This directory will be called "freecol" and underneath that directory a "save" directory will be created. For MacOS X the Library/FreeCol is used (which is the standard path for application related files). For os.name beginning with "Windows" JFileChooser() is used to find the path to "My Documents" (or localized equivalent)


setSavegame

private static void setSavegame(java.lang.String name)
Set up the save file and directory

Parameters:
name - the name of the save file to use

getSaveDirectory

public static java.io.File getSaveDirectory()
Returns the directory where the savegames should be put.

Returns:
The directory where the savegames should be put.

setSaveDirectory

public static void setSaveDirectory(java.io.File saveDirectory)
Set the directory where the savegames should be put.

Parameters:
saveDirectory - a File value for the savegame directory

getDataDirectory

public static java.io.File getDataDirectory()
Returns the data directory.

Returns:
The directory where the data files are located.

getStandardModsDirectory

public static java.io.File getStandardModsDirectory()
Gets the mods directory.

Returns:
The directory where the standard mods are located.

getUserModsDirectory

public static java.io.File getUserModsDirectory()
Gets the user mods directory.

Returns:
The directory where user mods are located, or null if none.

getAutosaveDirectory

public static java.io.File getAutosaveDirectory()
Returns the directory where the autogenerated savegames should be put.

Returns:
The directory.

getOptionsDirectory

public static java.io.File getOptionsDirectory()
Returns the directory for saving options.

Returns:
The directory.

getSpecificationInputStream

public static java.io.InputStream getSpecificationInputStream()
                                                       throws java.io.IOException
Throws:
java.io.IOException

checkJavaVersion

private static boolean checkJavaVersion()
Ensure that the Java version is good enough. JDK 1.4 or better is required.

Returns:
true if Java version is at least 1.5.0.

handleArgs

private static void handleArgs(java.lang.String[] args)
Checks the command-line arguments and takes appropriate actions for each of them.

Parameters:
args - The command-line arguments.

printUsage

private static void printUsage()

getVersion

public static java.lang.String getVersion()
Gets the current version of game.

Returns:
The current version of the game using the format "x.y.z", where "x" is major, "y" is minor and "z" is revision.

getRevision

public static java.lang.String getRevision()
Gets the current revision of game.

Returns:
The current version and SVN Revision of the game.

getLogFile

public static java.lang.String getLogFile()
Returns the name of the log file.

Returns:
a String value

isInDebugMode

public static boolean isInDebugMode()
Checks if the program is in "Debug mode".

Returns:
true if the program is in debug mode and false otherwise.

isInFullDebugMode

public static boolean isInFullDebugMode()
Checks if the program is in the full debug mode, rather than the limited version which does not initialize a player colony.

Returns:
true if the program is in the higher level mode and false otherwise.

setInDebugMode

public static void setInDebugMode(boolean debug)
Sets the "debug mode" to be active or not.

Parameters:
debug - Should be true in order to active debug mode and false otherwise.

getDebugRunTurns

public static int getDebugRunTurns()
Gets the turns to run in debug mode.

Returns:
The turns to run in debug mode.

completeDebugRun

public static void completeDebugRun()
Complete debug run.


isDebugRunComplete

public static boolean isDebugRunComplete()
Is a debug run complete?

Returns:
True if a debug run is complete.

getDebugRunSaveName

public static java.lang.String getDebugRunSaveName()
Gets the name of a file to save to at the end of a debug run.

Returns:
The name of a file to save to at the end of a debug run.

getFreeColSeed

public static long getFreeColSeed()
Gets the seed for the PRNG.

Returns:
The seed.

incrementFreeColSeed

public static void incrementFreeColSeed()
Increments the seed for the PRNG.


startServer

private static void startServer()