|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectnet.sf.freecol.server.FreeColServer
public final class FreeColServer
The main control class for the FreeCol server. This class both starts and
keeps references to all of the server objects and the game model objects.
If you would like to start a new server you just create a new object of this
class.
| Nested Class Summary | |
|---|---|
static class |
FreeColServer.GameState
Constant for storing the state of the game. |
| Field Summary | |
|---|---|
private Unit |
activeUnit
An active unit specified in a saved game. |
private AIMain |
aiMain
|
static java.lang.String |
defaultSpec
The specification to use when loading old format games where a spec may not be readily available. |
private ServerGame |
game
|
private FreeColServer.GameState |
gameState
Stores the current state of the game. |
private static java.lang.String |
HEX_DIGITS
Hex constant digits for get/restoreRandomState. |
private static java.lang.String |
HIGH_SCORE_FILE
|
static java.util.Comparator<HighScore> |
highScoreComparator
|
private java.util.List<HighScore> |
highScores
The high scores on this server. |
private InGameController |
inGameController
|
private InGameInputHandler |
inGameInputHandler
|
private boolean |
integrity
Did the integrity check succeed |
private static java.util.logging.Logger |
logger
|
private MapGenerator |
mapGenerator
|
private static int |
META_SERVER_UPDATE_INTERVAL
|
static int |
MINIMUM_SAVEGAME_VERSION
The oldest save game format that can still be loaded. |
private java.lang.String |
name
The name of this server. |
private static int |
NUMBER_OF_HIGH_SCORES
|
private java.lang.String |
owner
|
private int |
port
|
private PreGameController |
preGameController
|
private PreGameInputHandler |
preGameInputHandler
|
private boolean |
publicServer
|
private java.util.Random |
random
The private provider for random numbers. |
static int |
SAVEGAME_VERSION
The save game format used for saving games. |
private Server |
server
|
private boolean |
singleplayer
|
private UserConnectionHandler |
userConnectionHandler
|
| Constructor Summary | |
|---|---|
FreeColServer(FreeColSavegameFile savegame,
int port,
java.lang.String name)
Starts a new server in a specified mode and with a specified port and loads the game from the given file. |
|
FreeColServer(FreeColSavegameFile savegame,
int port,
java.lang.String name,
Specification specification)
Starts a new server in a specified mode and with a specified port and loads the game from the given file. |
|
FreeColServer(Specification specification,
boolean publicServer,
boolean singleplayer,
int port,
java.lang.String name)
Starts a new server in a specified mode and with a specified port. |
|
FreeColServer(Specification specification,
boolean publicServer,
boolean singleplayer,
int port,
java.lang.String name,
NationOptions.Advantages advantages)
|
|
| Method Summary | |
|---|---|
ServerPlayer |
addAIPlayer(Nation nation)
Adds a new AIPlayer to the Game. |
private void |
addBooleanOption(java.lang.String id,
java.lang.String gr,
boolean defaultValue)
|
private void |
addIntegerOption(java.lang.String id,
java.lang.String gr,
int defaultValue)
|
private void |
addStringOption(java.lang.String id,
java.lang.String gr,
java.lang.String defaultValue)
|
static XMLStream |
createXMLStreamReader(FreeColSavegameFile fis)
Creates a XMLStream for reading the given file. |
private void |
fixGameOptions()
|
Unit |
getActiveUnit()
Gets the active unit specified in a saved game, if any. |
IndianSettlement |
getAdjacentIndianSettlementSafely(java.lang.String settlementId,
Unit unit)
Get an adjacent Indian settlement by ID, validating as much as possible, including checking whether the nation involved has been contacted. |
Settlement |
getAdjacentSettlementSafely(java.lang.String settlementId,
Unit unit)
Get a settlement by ID, validating the ID as much as possible. |
AIMain |
getAIMain()
Gets the main AI-object. |
AIPlayer |
getAIPlayer(Player player)
Gets the AI player corresponding to a given player. |
Controller |
getController()
Gets the Controller. |
ServerGame |
getGame()
Gets the Game that is being played. |
FreeColServer.GameState |
getGameState()
Gets the current state of the game. |
java.util.List<HighScore> |
getHighScores()
Get the HighScores value. |
InGameController |
getInGameController()
Gets the controller being used while the game is running. |
InGameInputHandler |
getInGameInputHandler()
Gets the InGameInputHandler. |
boolean |
getIntegrity()
Gets the integrity check result. |
MapGenerator |
getMapGenerator()
Gets the MapGenerator this FreeColServer is
using when creating random maps. |
java.lang.String |
getName()
Returns the name of this server. |
int |
getNumberOfLivingHumanPlayers()
Gets the number of human players in this game that is still playing. |
java.lang.String |
getOwner()
Gets the owner of the Game. |
ServerPlayer |
getPlayer(Connection connection)
Gets a Player specified by a connection. |
PreGameInputHandler |
getPreGameInputHandler()
Gets the PreGameInputHandler. |
static java.lang.String |
getRandomState(java.util.Random random)
Get the internal state of a random number generator as a string. |
private static int |
getSavegameVersion(FreeColSavegameFile fis)
Gets the save game version from a saved game. |
Server |
getServer()
Gets the network server responsible of handling the connections. |
java.util.Random |
getServerRandom()
Gets the server random number generator. |
int |
getSlotsAvailable()
Gets the number of player that may connect. |
Specification |
getSpecification()
Gets the specification from the game run by this server. |
Unit |
getUnitSafely(java.lang.String unitId,
ServerPlayer serverPlayer)
Get a unit by ID, validating the ID as much as possible. |
UserConnectionHandler |
getUserConnectionHandler()
Gets the UserConnectionHandler. |
boolean |
isSingleplayer()
Checks if the user is playing in singleplayer mode. |
Game |
loadGame(FreeColSavegameFile fis)
Loads a game. |
Game |
loadGame(FreeColSavegameFile fis,
Specification specification)
Loads a game. |
void |
loadHighScores()
Loads high scores. |
boolean |
newHighScore(Player player)
Adds a new high score for player and returns true
if possible. |
static ServerGame |
readGame(FreeColSavegameFile fis,
Specification specification,
FreeColServer server)
Reads just the game part from a save game. |
static void |
removeAutosaves(java.lang.String prefix)
Removes automatically created save games. |
void |
removeFromMetaServer()
Removes this server from the metaserver's list. |
static java.util.Random |
restoreRandomState(java.lang.String state)
Restore a previously saved state. |
void |
revealMapForAllPlayers()
Makes the entire map visible for all players. |
void |
saveGame(java.io.File file,
java.lang.String username,
OptionGroup options)
Saves a game. |
void |
saveGame(java.io.File file,
java.lang.String username,
OptionGroup options,
java.awt.image.BufferedImage image)
Saves a game. |
void |
saveHighScores()
Saves high scores. |
void |
setActiveUnit(Unit unit)
Gets the active unit specified in a saved game, if any. |
void |
setAIMain(AIMain aiMain)
Sets the main AI-object. |
void |
setGame(ServerGame game)
Sets the Game that is being played. |
void |
setGameState(FreeColServer.GameState state)
Sets the current state of the game. |
void |
setMapGenerator(MapGenerator mapGenerator)
Sets the MapGenerator this FreeColServer is
using when creating random maps. |
void |
setName(java.lang.String name)
Sets the name of this server. |
void |
setOwner(java.lang.String owner)
Sets the owner of the game. |
void |
setPublicServer(boolean publicServer)
Sets the public server. |
void |
setServerRandom(java.util.Random random)
Sets the server random number generator. |
void |
setSingleplayer(boolean singleplayer)
Sets the mode of the game: singleplayer/multiplayer. |
void |
shutdown()
|
void |
startMetaServerUpdateThread()
Starts the metaserver update thread if publicServer == true. |
void |
updateMetaServer()
Sends information about this server to the meta-server. |
void |
updateMetaServer(boolean firstTime)
Sends information about this server to the meta-server. |
private static void |
v11FixServerObjects(java.util.List<java.lang.String> serverStrings,
FreeColSavegameFile fis)
At savegame version 11 (new in 0.10.0) several classes were added to serverObjects. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private static final java.util.logging.Logger logger
private static final int META_SERVER_UPDATE_INTERVAL
private static final int NUMBER_OF_HIGH_SCORES
private static final java.lang.String HIGH_SCORE_FILE
private static final java.lang.String HEX_DIGITS
public static final int SAVEGAME_VERSION
public static final int MINIMUM_SAVEGAME_VERSION
public static final java.lang.String defaultSpec
private FreeColServer.GameState gameState
private Server server
private final UserConnectionHandler userConnectionHandler
private final PreGameController preGameController
private final PreGameInputHandler preGameInputHandler
private final InGameInputHandler inGameInputHandler
private final InGameController inGameController
private ServerGame game
private AIMain aiMain
private MapGenerator mapGenerator
private boolean singleplayer
private java.lang.String owner
private boolean publicServer
private final int port
private java.lang.String name
private java.util.Random random
private boolean integrity
private Unit activeUnit
private java.util.List<HighScore> highScores
public static final java.util.Comparator<HighScore> highScoreComparator
| Constructor Detail |
|---|
public FreeColServer(Specification specification,
boolean publicServer,
boolean singleplayer,
int port,
java.lang.String name)
throws java.io.IOException,
NoRouteToServerException
publicServer - This value should be set to true in
order to appear on the meta server's listing.singleplayer - Sets the game as singleplayer (if true) or
multiplayer (if false).port - The TCP port to use for the public socket. That is the port
the clients will connect to.name - The name of the server, or null if the default
name should be used.
java.io.IOException - if the public socket cannot be created (the exception
will be logged by this class).
NoRouteToServerException
public FreeColServer(Specification specification,
boolean publicServer,
boolean singleplayer,
int port,
java.lang.String name,
NationOptions.Advantages advantages)
throws java.io.IOException,
NoRouteToServerException
java.io.IOException
NoRouteToServerException
public FreeColServer(FreeColSavegameFile savegame,
int port,
java.lang.String name)
throws java.io.IOException,
FreeColException,
NoRouteToServerException
savegame - The file where the game data is located.port - The TCP port to use for the public socket. That is the port
the clients will connect to.name - The name of the server, or null if the default
name should be used.
java.io.IOException - if the public socket cannot be created (the exception
will be logged by this class).
FreeColException - if the savegame could not be loaded.
NoRouteToServerException - if an error occurs
public FreeColServer(FreeColSavegameFile savegame,
int port,
java.lang.String name,
Specification specification)
throws java.io.IOException,
FreeColException,
NoRouteToServerException
savegame - The file where the game data is located.port - The TCP port to use for the public socket. That is the port
the clients will connect to.name - The name of the server, or null if the default
name should be used.specification - a Specification value
java.io.IOException - if the public socket cannot be created (the exception
will be logged by this class).
FreeColException - if the savegame could not be loaded.
NoRouteToServerException - if an error occurs| Method Detail |
|---|
public void setSingleplayer(boolean singleplayer)
singleplayer - Sets the game as singleplayer (if true) or
multiplayer (if false).public boolean isSingleplayer()
public Specification getSpecification()
public UserConnectionHandler getUserConnectionHandler()
UserConnectionHandler.
UserConnectionHandler that is beeing used when
new client connect.public Controller getController()
Controller.
Controller.public PreGameInputHandler getPreGameInputHandler()
PreGameInputHandler.
PreGameInputHandler.public InGameInputHandler getInGameInputHandler()
InGameInputHandler.
InGameInputHandler.public InGameController getInGameController()
public ServerGame getGame()
Game that is being played.
Game which is the main class of the game-model
being used in this game.public void setGame(ServerGame game)
Game that is being played.
game - The new Game.public void setAIMain(AIMain aiMain)
aiMain - The main AI-object which is responsible for controlling,
updating and saving the AI objects.public AIMain getAIMain()
public FreeColServer.GameState getGameState()
FreeColServer.GameState.STARTING_GAME, FreeColServer.GameState.IN_GAME and
FreeColServer.GameState.ENDING_GAME.public void setGameState(FreeColServer.GameState state)
state - The new state to be set. One of: FreeColServer.GameState.STARTING_GAME,
FreeColServer.GameState.IN_GAME and FreeColServer.GameState.ENDING_GAME.public Server getServer()
public boolean getIntegrity()
public java.util.Random getServerRandom()
public void setServerRandom(java.util.Random random)
random - The new random number generator.public MapGenerator getMapGenerator()
MapGenerator this FreeColServer is
using when creating random maps.
MapGenerator.public void setMapGenerator(MapGenerator mapGenerator)
MapGenerator this FreeColServer is
using when creating random maps.
mapGenerator - The MapGenerator.
public void updateMetaServer()
throws NoRouteToServerException
public == true.
NoRouteToServerExceptionpublic java.lang.String getName()
public void setName(java.lang.String name)
name - The name.public java.lang.String getOwner()
Game.
public void setOwner(java.lang.String owner)
owner - The new owner of the game.public Unit getActiveUnit()
public void setActiveUnit(Unit unit)
unit - The active unit to save.public void setPublicServer(boolean publicServer)
publicServer - The new public server flag.public void startMetaServerUpdateThread()
publicServer == true.
This update is really a "Hi! I am still here!"-message, since an
additional update should be sent when a new player is added to/removed
from this server etc.
public void updateMetaServer(boolean firstTime)
throws NoRouteToServerException
public == true.
firstTime - Should be set to true> when calling this method
for the first time.
NoRouteToServerException - if the meta-server cannot connect to
this server.public void removeFromMetaServer()
public == true.
public int getSlotsAvailable()
public int getNumberOfLivingHumanPlayers()
public void saveGame(java.io.File file,
java.lang.String username,
OptionGroup options)
throws java.io.IOException
file - The file where the data will be written.username - The username of the player saving the game.
java.io.IOException - If a problem was encountered while trying to open,
write or close the file.
public void saveGame(java.io.File file,
java.lang.String username,
OptionGroup options,
java.awt.image.BufferedImage image)
throws java.io.IOException
file - The file where the data will be written.username - The username of the player saving the game.image - an Image value
java.io.IOException - If a problem was encountered while trying to open,
write or close the file.
public static XMLStream createXMLStreamReader(FreeColSavegameFile fis)
throws java.io.IOException
XMLStream for reading the given file.
Compression is automatically detected.
fis - The file to be read.
XMLStreamr.
java.io.IOException - if thrown while loading the game or if a
XMLStreamException have been thrown by the
parser.
public Game loadGame(FreeColSavegameFile fis)
throws java.io.IOException,
FreeColException
fis - The file where the game data is located.
java.io.IOException - If a problem was encountered while trying to open,
read or close the file.
java.io.IOException - if thrown while loading the game or if a
XMLStreamException have been thrown by the
parser.
FreeColException - if the savegame contains incompatible data.
public static ServerGame readGame(FreeColSavegameFile fis,
Specification specification,
FreeColServer server)
throws java.io.IOException,
FreeColException
fis - The stream to read from.specification - The Specification to use in the game.server - Use this (optional) server to load into.
FreeColException - if the format is incompatible.
java.io.IOException - if there is a problem reading the stream.
public Game loadGame(FreeColSavegameFile fis,
Specification specification)
throws FreeColException,
java.io.IOException
fis - The file where the game data is located.specification - a Specification value
FreeColException - if the savegame contains incompatible data.
java.io.IOException - if there is problem reading a stream.
private static int getSavegameVersion(FreeColSavegameFile fis)
throws FreeColException
fis - The saved game.
FreeColException - if the version is incompatible.private void fixGameOptions()
private void addBooleanOption(java.lang.String id,
java.lang.String gr,
boolean defaultValue)
private void addIntegerOption(java.lang.String id,
java.lang.String gr,
int defaultValue)
private void addStringOption(java.lang.String id,
java.lang.String gr,
java.lang.String defaultValue)
private static void v11FixServerObjects(java.util.List<java.lang.String> serverStrings,
FreeColSavegameFile fis)
serverStrings - A list of server object {type, id} pairs to add to.fis - The savegame to scan.public static void removeAutosaves(java.lang.String prefix)
public void revealMapForAllPlayers()
public ServerPlayer getPlayer(Connection connection)
Player specified by a connection.
connection - The connection to use while searching for a
ServerPlayer.
public Unit getUnitSafely(java.lang.String unitId,
ServerPlayer serverPlayer)
throws java.lang.IllegalStateException
unitId - The ID of the unit to be found.serverPlayer - The ServerPlayer to whom the unit must belong.
java.lang.IllegalStateException - on failure to validate the unitId
in any way.
In the worst case this may be indicative of a malign client.
public Settlement getAdjacentSettlementSafely(java.lang.String settlementId,
Unit unit)
throws java.lang.IllegalStateException
settlementId - The ID of the Settlement to be found.unit - A Unit which must be adjacent
to the Settlement.
java.lang.IllegalStateException - on failure to validate the settlementId
in any way.
In the worst case this may be indicative of a malign client.
public IndianSettlement getAdjacentIndianSettlementSafely(java.lang.String settlementId,
Unit unit)
throws java.lang.IllegalStateException
settlementId - The ID of the Settlement to be found.unit - A Unit which must be adjacent
to the Settlement.
java.lang.IllegalStateException - on failure to validate the settlementId
in any way.
In the worst case this may be indicative of a malign client.public ServerPlayer addAIPlayer(Nation nation)
nation - a Nation value
ServerPlayer valuepublic AIPlayer getAIPlayer(Player player)
player - The Player to look up.
public java.util.List<HighScore> getHighScores()
HighScores value.
List valuepublic boolean newHighScore(Player player)
true
if possible.
player - a Player value
boolean value
public void saveHighScores()
throws java.io.IOException
java.io.IOException - If a problem was encountered while trying to open,
write or close the file.
public void loadHighScores()
throws java.io.IOException,
FreeColException
java.io.IOException - If a problem was encountered while trying to open,
read or close the file.
java.io.IOException - if thrown while loading the game or if a
XMLStreamException have been thrown by the
parser.
FreeColException - if the savegame contains incompatible data.public void shutdown()
public static java.lang.String getRandomState(java.util.Random random)
random - The Random to use.
String encapsulating the object state.
public static java.util.Random restoreRandomState(java.lang.String state)
throws java.io.IOException
state - The saved state (@see #getRandomState()).
Random.
java.io.IOException - if unable to restore state.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||