net.sf.freecol.client.control
Class ConnectController

java.lang.Object
  extended by net.sf.freecol.client.control.ConnectController

public final class ConnectController
extends java.lang.Object

The controller responsible for starting a server and connecting to it. PreGameInputHandler will be set as the input handler when a successful login has been completed,


Field Summary
private  FreeColClient freeColClient
           
private static java.util.logging.Logger logger
           
 
Constructor Summary
ConnectController(FreeColClient freeColClient)
          Creates a new ConnectController.
 
Method Summary
 java.util.ArrayList<ServerInfo> getServerList()
          Gets a list of servers from the meta server.
private  java.util.List<java.lang.String> getVacantPlayers(java.lang.String host, int port)
          Returns a list of vacant players on a given server.
 void joinMultiplayerGame(java.lang.String username, java.lang.String host, int port)
          Starts a new multiplayer game by connecting to the server.
 void loadGame()
          Opens a dialog where the user should specify the filename and loads the game.
 void loadGame(java.io.File file)
          Loads a game from the given file.
private  void loadModFragments(Specification specification)
           
 boolean login(java.lang.String username, java.lang.String host, int port)
          Starts the client and connects to host:port.
 void logout(boolean notifyServer)
          Sends a logout message to the server.
 void quitGame(boolean bStopServer)
          Quits the current game.
 void quitGame(boolean bStopServer, boolean notifyServer)
          Quits the current game.
 void reconnect()
          Reconnects to the server.
 void startMultiplayerGame(Specification specification, boolean publicServer, java.lang.String username, int port, NationOptions.Advantages advantages, OptionGroup level)
          Starts a multiplayer server and connects to it.
 void startSingleplayerGame(Specification specification, java.lang.String username, NationOptions.Advantages advantages)
          Starts a new singleplayer game by connecting to the server.
 
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

freeColClient

private final FreeColClient freeColClient
Constructor Detail

ConnectController

public ConnectController(FreeColClient freeColClient)
Creates a new ConnectController.

Parameters:
freeColClient - The main controller.
Method Detail

startMultiplayerGame

public void startMultiplayerGame(Specification specification,
                                 boolean publicServer,
                                 java.lang.String username,
                                 int port,
                                 NationOptions.Advantages advantages,
                                 OptionGroup level)
Starts a multiplayer server and connects to it.

Parameters:
username - The name to use when logging in.
port - The port in which the server should listen for new clients.
level - a DifficultyLevel value

startSingleplayerGame

public void startSingleplayerGame(Specification specification,
                                  java.lang.String username,
                                  NationOptions.Advantages advantages)
Starts a new singleplayer game by connecting to the server.

Parameters:
specification - a Specification value
username - The name to use when logging in.
advantages - an Advantages value

joinMultiplayerGame

public void joinMultiplayerGame(java.lang.String username,
                                java.lang.String host,
                                int port)
Starts a new multiplayer game by connecting to the server.

Parameters:
username - The name to use when logging in.
host - The name of the machine running the FreeColServer.
port - The port to use when connecting to the host.

login

public boolean login(java.lang.String username,
                     java.lang.String host,
                     int port)
Starts the client and connects to host:port.

Parameters:
username - The name to use when logging in. This should be a unique identifier.
host - The name of the machine running the FreeColServer.
port - The port to use when connecting to the host.
Returns:
a boolean value

reconnect

public void reconnect()
Reconnects to the server.


loadGame

public void loadGame()
Opens a dialog where the user should specify the filename and loads the game.


loadGame

public void loadGame(java.io.File file)
Loads a game from the given file.

Parameters:
file - The File.

logout

public void logout(boolean notifyServer)
Sends a logout message to the server.

Parameters:
notifyServer - Whether or not the server should be notified of the logout. For example: if the server kicked us out then we don't need to confirm with a logout message.

quitGame

public void quitGame(boolean bStopServer,
                     boolean notifyServer)
Quits the current game. If a server is running it will be stopped if bStopServer is true. If a server is running through this client and bStopServer is true then the clients connected to that server will be notified. If a local client is connected to a server then the server will be notified with a logout in case notifyServer is true.

Parameters:
bStopServer - Indicates whether or not a server that was started through this client should be stopped.
notifyServer - Whether or not the server should be notified of the logout. For example: if the server kicked us out then we don't need to confirm with a logout message.

quitGame

public void quitGame(boolean bStopServer)
Quits the current game. If a server is running it will be stopped if bStopServer is true. The server and perhaps the clients (if a server is running through this client and bStopServer is true) will be notified.

Parameters:
bStopServer - Indicates whether or not a server that was started through this client should be stopped.

getVacantPlayers

private java.util.List<java.lang.String> getVacantPlayers(java.lang.String host,
                                                          int port)
Returns a list of vacant players on a given server.

Parameters:
host - The name of the machine running the FreeColServer.
port - The port to use when connecting to the host.
Returns:
A list of available usernames.

getServerList

public java.util.ArrayList<ServerInfo> getServerList()
Gets a list of servers from the meta server.

Returns:
A list of ServerInfo objects.

loadModFragments

private void loadModFragments(Specification specification)