Class ConnectController


  • public final class ConnectController
    extends FreeColClientHolder
    The controller responsible for starting a server and connecting to it.
    • Field Detail

      • logger

        private static final java.util.logging.Logger logger
      • savedKeys

        private static final java.util.List<java.lang.String> savedKeys
        Fixed argument list for startSavedGame.
    • Constructor Detail

      • ConnectController

        public ConnectController​(FreeColClient freeColClient)
        Creates a new ConnectController.
        Parameters:
        freeColClient - The FreeColClient for 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 StringTemplate error 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 the FreeColServer.
        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). StartGamePanel does 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 to FreeColServer.startGame().
        Parameters:
        state - The state of the server.
        game - The new Game to 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 - The Specification for 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 - The Specification for 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).