|
||||||||||
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 | |
---|---|
static java.util.Comparator<HighScore> |
highScoreComparator
|
static int |
MINIMUM_SAVEGAME_VERSION
The oldest save game format that can still be loaded. |
static int |
SAVEGAME_VERSION
The save game format used for saving games. |
Constructor Summary | |
---|---|
FreeColServer(boolean publicServer,
boolean singleplayer,
int port,
java.lang.String name)
Starts a new server in a specified mode and with a specified port. |
|
FreeColServer(boolean publicServer,
boolean singleplayer,
int port,
java.lang.String name,
NationOptions nationOptions)
|
|
FreeColServer(FreeColSavegameFile savegame,
boolean publicServer,
boolean singleplayer,
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. |
Method Summary | |
---|---|
ServerPlayer |
addAIPlayer(Nation nation)
Adds a new AIPlayer to the Game. |
static void |
checkSavegameVersion(javax.xml.stream.XMLStreamReader xsr)
|
static XMLStream |
createXMLStreamReader(FreeColSavegameFile fis)
Creates a XMLStream for reading the given file. |
void |
enterRevengeMode(java.lang.String username)
Enters revenge mode against those evil AIs. |
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. |
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. |
IMapGenerator |
getMapGenerator()
Gets the MapGenerator this FreeColServer is
using when creating random maps. |
ServerModelController |
getModelController()
Gets the ModelController . |
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 . |
java.lang.String |
getRandomState(java.util.Random random)
Get the internal state of a random number generator as a string. |
Server |
getServer()
Gets the network server responsible of handling the connections. |
java.util.Random |
getServerRandom()
Get the server-private random number generator. |
int |
getSlotsAvailable()
Gets the number of player that may connect. |
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. |
java.lang.String |
loadGame(FreeColSavegameFile fis)
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 void |
removeAutosaves(java.lang.String prefix)
Removes automatically created save games. |
void |
removeFromMetaServer()
Removes this server from the metaserver's list. |
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)
Saves a game. |
void |
saveHighScores()
Saves high scores. |
void |
setAIMain(AIMain aiMain)
Sets the main AI-object. |
void |
setGameState(FreeColServer.GameState state)
Sets the current state of the game. |
void |
setMapGenerator(IMapGenerator 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 |
setSingleplayer(boolean singleplayer)
Sets the mode of the game: singleplayer/multiplayer. |
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. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int SAVEGAME_VERSION
public static final int MINIMUM_SAVEGAME_VERSION
public static final java.util.Comparator<HighScore> highScoreComparator
Constructor Detail |
---|
public FreeColServer(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(boolean publicServer, boolean singleplayer, int port, java.lang.String name, NationOptions nationOptions) throws java.io.IOException, NoRouteToServerException
java.io.IOException
NoRouteToServerException
public FreeColServer(FreeColSavegameFile savegame, boolean publicServer, boolean singleplayer, int port, java.lang.String name) throws java.io.IOException, FreeColException, NoRouteToServerException
savegame
- The file where the game data is located.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).
FreeColException
- if the savegame could not be loaded.
NoRouteToServerException
Method Detail |
---|
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 enterRevengeMode(java.lang.String username)
username
- The player to enter revenge mode.public IMapGenerator getMapGenerator()
MapGenerator
this FreeColServer
is
using when creating random maps.
MapGenerator
.public void setMapGenerator(IMapGenerator mapGenerator)
MapGenerator
this FreeColServer
is
using when creating random maps.
mapGenerator
- The MapGenerator
.public void updateMetaServer() throws NoRouteToServerException
public == true
.
NoRouteToServerException
public java.lang.String getName()
public void setName(java.lang.String name)
name
- The name.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 java.lang.String getOwner()
Game
.
loadGame(net.sf.freecol.common.io.FreeColSavegameFile)
public void saveGame(java.io.File file, java.lang.String username) 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 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 java.lang.String 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 void checkSavegameVersion(javax.xml.stream.XMLStreamReader xsr) throws FreeColException
FreeColException
public static void removeAutosaves(java.lang.String prefix)
public void setSingleplayer(boolean singleplayer)
singleplayer
- Sets the game as singleplayer (if true) or
multiplayer (if false).public boolean isSingleplayer()
public void revealMapForAllPlayers()
public ServerPlayer getPlayer(Connection connection)
Player
specified by a connection.
connection
- The connection to use while searching for a
ServerPlayer
.
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 ServerModelController getModelController()
ModelController
.
FreeColGameObject
s.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 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 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 java.util.List<HighScore> getHighScores()
HighScores
value.
List
valuepublic boolean newHighScore(Player player)
true
if possible.
player
- a Player
value
boolean
valuepublic 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 java.lang.String getRandomState(java.util.Random random)
random
- The Random
to use.
String
encapsulating the object state.public 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 |