soc.util
Class SOCServerFeatures

java.lang.Object
  extended by soc.util.SOCServerFeatures

public class SOCServerFeatures
extends java.lang.Object

Set of optional server features that are currently active. Sent from server to client during connect via SOCVersion fields.

Added in v1.1.19 (VERSION_FOR_SERVERFEATURES); earlier clients assume the server is using the features defined in 1.1.19. Use the SOCServerFeatures(true) constructor when connecting to a server older than 1.1.19. See that constructor's javadoc for the list of features always assumed active before 1.1.19.

Feature names are kept simple (lowercase alphanumerics, underscore, dash) for encoding into network message fields.

Locks: Not thread-safe. Caller must guard against potential multi-threaded modifications or access.

Since:
1.1.19
Author:
Jeremy D Monin <jeremy@nand.net>

Field Summary
static java.lang.String FEAT_ACCTS
          User accounts defined in a persistent database.
static java.lang.String FEAT_CHANNELS
          Chat channels.
static java.lang.String FEAT_OPEN_REG
          Open registration.
private  java.lang.String featureList
          Active feature list, or null if none.
private static char SEP_CHAR
          Separator character ';' between features in featureList.
static int VERSION_FOR_SERVERFEATURES
          Minimum version (1.1.19) of client/server which send and recognize server features
 
Constructor Summary
SOCServerFeatures(boolean withOldDefaults)
          Create a new empty SOCServerFeatures, with none active or defaults active.
SOCServerFeatures(SOCServerFeatures feats)
          Create a new SOCServerFeatures by copying another.
SOCServerFeatures(java.lang.String encodedList)
          Create a new SOCServerFeatures from an encoded list; useful at client.
 
Method Summary
 void add(java.lang.String featureName)
          Add this active feature.
 java.lang.String getEncodedList()
          Get the encoded list of all active features, to send to a client for SOCServerFeatures(String).
 boolean isActive(java.lang.String featureName)
          Is this feature active?
 java.lang.String toString()
          Human-readable representation of active features.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

VERSION_FOR_SERVERFEATURES

public static final int VERSION_FOR_SERVERFEATURES
Minimum version (1.1.19) of client/server which send and recognize server features

See Also:
Constant Field Values

FEAT_ACCTS

public static final java.lang.String FEAT_ACCTS
User accounts defined in a persistent database. If this feature is active, nicknames and passwords are authenticated. Otherwise there are no passwords defined (FEAT_OPEN_REG).

When this feature is active but the db is empty (new install), the server will tell clients that FEAT_OPEN_REG is active; see that feature's javadoc for details.

The server can optionally be configured to require accounts, see SOCServer.PROP_JSETTLERS_ACCOUNTS_REQUIRED.

See Also:
Constant Field Values

FEAT_CHANNELS

public static final java.lang.String FEAT_CHANNELS
Chat channels. If this feature is active, users are allowed to create chat channels. Otherwise no channels are allowed.

See Also:
Constant Field Values

FEAT_OPEN_REG

public static final java.lang.String FEAT_OPEN_REG
Open registration. If this feature is active, anyone can create their own user accounts. Otherwise only existing users can create new accounts (FEAT_ACCTS).
Special case during FEAT_ACCTS server install:
When a newly installed server requires authentication to create new accounts, but no accounts exist in the database yet, the server tells clients that FEAT_OPEN_REG is active so that SOCAccountClient won't ask for a username and password.

See Also:
Constant Field Values

SEP_CHAR

private static char SEP_CHAR
Separator character ';' between features in featureList. Avoid separators defined in SOCMessage.


featureList

private java.lang.String featureList
Active feature list, or null if none. If not null, the list starts and ends with SEP_CHAR for ease of search.

Constructor Detail

SOCServerFeatures

public SOCServerFeatures(boolean withOldDefaults)
Create a new empty SOCServerFeatures, with none active or defaults active. After construction, use add(String) to add active features.

Parameters:
withOldDefaults - If false, nothing is active. If true, include the default features which were assumed always active in servers older than v1.1.19 (VERSION_FOR_SERVERFEATURES): FEAT_ACCTS, FEAT_CHANNELS, FEAT_OPEN_REG.

SOCServerFeatures

public SOCServerFeatures(java.lang.String encodedList)
                  throws java.lang.IllegalArgumentException
Create a new SOCServerFeatures from an encoded list; useful at client.

Parameters:
encodedList - List from getEncodedList(), or null or "" for none
Throws:
java.lang.IllegalArgumentException - if encodedList is not empty but doesn't start and end with the separator character

SOCServerFeatures

public SOCServerFeatures(SOCServerFeatures feats)
                  throws java.lang.NullPointerException
Create a new SOCServerFeatures by copying another.

Parameters:
feats - Copy from this to create the new SOCServerFeatures
Throws:
java.lang.NullPointerException - if feats == null
Method Detail

isActive

public boolean isActive(java.lang.String featureName)
                 throws java.lang.IllegalArgumentException
Is this feature active?

Parameters:
featureName - A defined feature name, such as FEAT_ACCTS
Returns:
True if featureName is in the features list
Throws:
java.lang.IllegalArgumentException - if featureName is null or ""

add

public void add(java.lang.String featureName)
         throws java.lang.IllegalArgumentException
Add this active feature.

Parameters:
featureName - A defined feature name, such as FEAT_ACCTS
Throws:
java.lang.IllegalArgumentException - if featureName is null or ""

getEncodedList

public java.lang.String getEncodedList()
Get the encoded list of all active features, to send to a client for SOCServerFeatures(String).

Returns:
The active features list, or null if none

toString

public java.lang.String toString()
Human-readable representation of active features. Based on super.toString + featureList. Possible Formats:

Overrides:
toString in class java.lang.Object