Class UserServerAPI


  • public class UserServerAPI
    extends ServerAPI
    Implementation of the ServerAPI for a player with a real connection to the server.
    • Field Detail

      • connection

        private Connection connection
        The connection used to communicate with the server.
      • name

        private java.lang.String name
        The last name used to login with.
      • host

        private java.lang.String host
        The last host connected to.
      • port

        private int port
        The last port connected to.
      • messageHandler

        private MessageHandler messageHandler
        The last message handler specified.
    • Constructor Detail

      • UserServerAPI

        public UserServerAPI()
        Create the new user wrapper for the server API.
    • Method Detail

      • getName

        private java.lang.String getName()
        Name accessor.
        Returns:
        The connection name.
      • getHost

        private java.lang.String getHost()
        Host accessor.
        Returns:
        The connection host.
      • getPort

        private int getPort()
        Port accessor.
        Returns:
        The connection port.
      • updateParameters

        private void updateParameters​(java.lang.String name,
                                      java.lang.String host,
                                      int port)
        Update the connection parameters so as to allow reconnection.
        Parameters:
        name - The connection name.
        host - The host connected to.
        port - The port connected to.
      • updateConnection

        private void updateConnection​(Connection c)
        A connection has been made, save it and its parameters.
        Parameters:
        c - The new Connection.
      • newConnection

        private static Connection newConnection​(java.lang.String name,
                                                java.lang.String host,
                                                int port)
                                         throws java.io.IOException
        Create a new connection.
        Parameters:
        name - The name to associate with the connection.
        host - The name of the host to connect to.
        port - The port to connect to.
        Returns:
        The new Connection.
        Throws:
        java.io.IOException - on failure to connect.
      • connect

        public Connection connect​(java.lang.String name,
                                  java.lang.String host,
                                  int port)
                           throws java.io.IOException
        Connects a client to host:port (or more).
        Specified by:
        connect in class ServerAPI
        Parameters:
        name - The name for the thread.
        host - The name of the machine running the FreeColServer.
        port - The port to use when connecting to the host.
        Returns:
        True if the connection succeeded.
        Throws:
        java.io.IOException - on connection failure.
      • disconnect

        public boolean disconnect()
        Disconnect from the server.
        Specified by:
        disconnect in class ServerAPI
        Returns:
        True if disconnected.
      • reconnect

        public Connection reconnect()
                             throws java.io.IOException
        Reconnect to the server.
        Specified by:
        reconnect in class ServerAPI
        Returns:
        The reestablished Connection.
        Throws:
        java.io.IOException - on failure to connect.
      • getConnection

        public Connection getConnection()
        Get the connection to communicate with the server.
        Specified by:
        getConnection in class ServerAPI
        Returns:
        The Connection to the server.
      • setMessageHandler

        public void setMessageHandler​(MessageHandler mh)
        Sets the message handler for the connection.
        Overrides:
        setMessageHandler in class ServerAPI
        Parameters:
        mh - The new MessageHandler.