Package net.sf.freecol.client.control
Class ConnectController
- java.lang.Object
-
- net.sf.freecol.client.control.FreeColClientHolder
-
- net.sf.freecol.client.control.ConnectController
-
public final class ConnectController extends FreeColClientHolder
The controller responsible for starting a server and connecting to it.
-
-
Constructor Summary
Constructors Constructor Description ConnectController(FreeColClient freeColClient)Creates a newConnectController.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private StringTemplateconnect(java.lang.String user, java.lang.String host, int port)Establish the user connection.booleanjoinMultiplayerGame(java.lang.String host, int port)Join an existing multiplayer game.voidlogin(FreeColServer.ServerState state, Game game, java.lang.String user, boolean single, boolean current)Complete a login.booleanlogout(Game.LogoutReason reason)Complete log out of this client from the server.voidmainTitle()Reset to the MainPanel.voidnewGame()Reset to the NewPanel (except in the map editor).booleanrequestLogin(java.lang.String user, java.lang.String host, int port)Request this client log in to host:port.booleanrequestLogout(Game.LogoutReason reason)Request that this client log out from the server.booleanstartMultiplayerGame(Specification specification, boolean publicServer, java.net.InetAddress address, int port)Starts a multiplayer server and connects to it.booleanstartSavedGame(java.io.File file)Loads and starts a game from the given file.booleanstartSinglePlayerGame(Specification spec)Starts a new single player game by connecting to the server.-
Methods inherited from class net.sf.freecol.client.control.FreeColClientHolder
askServer, currentPlayerIsMyPlayer, getClientOptions, getConnectController, getFreeColClient, getFreeColServer, getGame, getGUI, getMap, getMyPlayer, getSpecification, igc, pgc
-
-
-
-
Constructor Detail
-
ConnectController
public ConnectController(FreeColClient freeColClient)
Creates a newConnectController.- Parameters:
freeColClient- TheFreeColClientfor the game.
-
-
Method Detail
-
connect
private StringTemplate connect(java.lang.String user, java.lang.String host, int port)
Establish the user connection.- Parameters:
user- The player name.host- The host name to connect to.port- The host port to connect to.- Returns:
- Null on success, an
StringTemplateerror message on failure.
-
requestLogout
public boolean requestLogout(Game.LogoutReason reason)
Request that this client log out from the server.- Parameters:
reason- The reason to logout from the server.- Returns:
- True if the player is already logged out, or a logout request was sent.
-
logout
public boolean logout(Game.LogoutReason reason)
Complete log out of this client from the server.- Parameters:
reason- The reason to logout from the server.- Returns:
- True if the logout completes.
-
requestLogin
public boolean requestLogin(java.lang.String user, java.lang.String host, int port)Request this client log in to host:port. Public for the test suite.- Parameters:
user- The name of the player to use.host- The name of the machine running theFreeColServer.port- The port to use when connecting to the host.- Returns:
- True if the player was already logged in, or if the login message was sent.
-
login
public void login(FreeColServer.ServerState state, Game game, java.lang.String user, boolean single, boolean current)
Complete a login. If we are joining a running game, there is little more needed to be done. If we are restoring from saved, the game should include a map and a full complement of players, including ours. Otherwise we may still need to select a nation, and optionally change game or map options (using several possible messages).StartGamePaneldoes this. When all the parameters are in place and all players are ready (trivially true in single player, needs checking in multiplayer) the client needs to send a requestLaunch message to ask the server to start the game. That is either done here or by the start game panel. requestLaunch effectively transfers control toFreeColServer.startGame().- Parameters:
state- The state of the server.game- The newGameto attach to.user- The name of the player in the game.single- True if this is a single player game.current- True if the player is the current player.
-
startSinglePlayerGame
public boolean startSinglePlayerGame(Specification spec)
Starts a new single player game by connecting to the server. FIXME: connect client/server directly (not using network-classes)- Parameters:
spec- TheSpecificationfor the game.- Returns:
- True if the game starts successfully.
-
startSavedGame
public boolean startSavedGame(java.io.File file)
Loads and starts a game from the given file.- Parameters:
file- The saved game.- Returns:
- True if the game starts successully.
-
startMultiplayerGame
public boolean startMultiplayerGame(Specification specification, boolean publicServer, java.net.InetAddress address, int port)
Starts a multiplayer server and connects to it.- Parameters:
specification- TheSpecificationfor the game.publicServer- Whether to make the server public.address- The address in which the server should listen for new clients.port- The port in which the server should listen for new clients.- Returns:
- True if the game is started successfully.
-
joinMultiplayerGame
public boolean joinMultiplayerGame(java.lang.String host, int port)Join an existing multiplayer game.- Parameters:
host- The name of the machine running the server.port- The port to use when connecting to the host.- Returns:
- True if the game starts successfully.
-
mainTitle
public void mainTitle()
Reset to the MainPanel. Called from ShowMainAction.
-
newGame
public void newGame()
Reset to the NewPanel (except in the map editor).
-
-