soc.client
Class ServerGametypeInfo

java.lang.Object
  extended by soc.client.ServerGametypeInfo

 class ServerGametypeInfo
extends java.lang.Object

Track the server's information about the game type: valid game option set, scenarios, etc. Client has one instance for remote tcp server, one for practice server. For simplicity, getters/setters are not included: Synchronize on the object to set/read its fields.

In v2.0.00 and newer, also tracks all SOCScenarios' i18n localized strings.

Interaction with client-server messages at connect:

  1. First, this object is created; allOptionsReceived false, newGameWaitingForOpts false. optionSet is set at client from SOCGameOption.getAllKnownOptions().
  2. At server connect, ask and receive info about options, if our version and the server's version differ. Once this is done, allOptionsReceived == true. If server is older than 1.1.07, optionSet becomes null here because older servers don't support game options.
  3. When user wants to create a new game, askedDefaultsAlready is false; ask server for its defaults (current option values for any new game). Also set newGameWaitingForOpts = true.
  4. Server will respond with its current option values. This sets defaultsReceived and updates optionSet. It's possible that the server's defaults contain option names that are unknown at our version. If so, allOptionsReceived is cleared, and we ask the server about those specific options. Otherwise, clear newGameWaitingForOpts.
  5. If waiting on option info from defaults above, the server replies with option info. (They may remain as type SOCGameOption.OTYPE_UNKNOWN.) Once these are all received, set allOptionsReceived = true, clear newGameWaitingForOpts.
  6. Once newGameWaitingForOpts == false, show the NewGameOptionsFrame.

Server scenario info is sent on demand, instead of sending all info when the client connects:

Before v2.0.00 this class was SOCPlayerClient.GameOptionServerSet.

Since:
1.1.07
Author:
jdmonin

Field Summary
 boolean allOptionsReceived
          If true, we know all options on this server, or the server is too old to support options.
 boolean allScenInfoReceived
          If true, the server sent us information on all added or changed scenarios, and any localized i18n scenario strings (allScenStringsReceived).
 boolean allScenStringsReceived
          If true, the server sent us all scenarios' i18n strings, has none for our locale, or is too old to support them.
 boolean askedDefaultsAlready
          Have we asked the server for default values?
 long askedDefaultsTime
          If askedDefaultsAlready, the time it was asked, as returned by System.currentTimeMillis().
 boolean defaultsReceived
          Has the server told us defaults?
 java.lang.String gameInfoWaitingForOpts
          If non-null, we're waiting to hear about game options because user has clicked 'game info' on a game.
 boolean newGameWaitingForOpts
          If true, we've asked the server about defaults or options because we're about to create a new game.
 java.util.Map<java.lang.String,SOCGameOption> optionSet
          Options will be null if SOCPlayerClient.sVersion is less than SOCNewGameWithOptions.VERSION_FOR_NEWGAMEWITHOPTIONS (1.1.07).
 java.util.HashSet<java.lang.String> scenKeys
          Any scenario keynames for which the server has sent us updated info or i18n strings or responded with "unknown".
 
Constructor Summary
ServerGametypeInfo()
          Create a new ServerGametypeInfo, with an optionSet defaulting to our client version's SOCGameOption.getAllKnownOptions().
 
Method Summary
 void noMoreOptions(boolean askedDefaults)
          The server doesn't have any more options to send (or none at all, from its version).
 java.util.List<java.lang.String> receiveDefaults(java.util.Map<java.lang.String,SOCGameOption> servOpts)
          Set of default options has been received from the server, examine them.
 boolean receiveInfo(SOCGameOptionInfo gi)
          After calling receiveDefaults, call this as each GAMEOPTIONGETINFO is received.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

allOptionsReceived

public boolean allOptionsReceived
If true, we know all options on this server, or the server is too old to support options.


newGameWaitingForOpts

public boolean newGameWaitingForOpts
If true, we've asked the server about defaults or options because we're about to create a new game. When all are received, we should create and show a NewGameOptionsFrame.


gameInfoWaitingForOpts

public java.lang.String gameInfoWaitingForOpts
If non-null, we're waiting to hear about game options because user has clicked 'game info' on a game. When all are received, we should create and show a NewGameOptionsFrame with that game's options.


optionSet

public java.util.Map<java.lang.String,SOCGameOption> optionSet
Options will be null if SOCPlayerClient.sVersion is less than SOCNewGameWithOptions.VERSION_FOR_NEWGAMEWITHOPTIONS (1.1.07). Otherwise, set from SOCGameOption.getAllKnownOptions() and update from server as needed.


askedDefaultsAlready

public boolean askedDefaultsAlready
Have we asked the server for default values?


defaultsReceived

public boolean defaultsReceived
Has the server told us defaults?


askedDefaultsTime

public long askedDefaultsTime
If askedDefaultsAlready, the time it was asked, as returned by System.currentTimeMillis().


allScenStringsReceived

public boolean allScenStringsReceived
If true, the server sent us all scenarios' i18n strings, has none for our locale, or is too old to support them.

The server sends all scenario strings when client has asked for game option defaults for the dialog to create a new game.

Since:
2.0.00
See Also:
scenKeys, allScenInfoReceived

allScenInfoReceived

public boolean allScenInfoReceived
If true, the server sent us information on all added or changed scenarios, and any localized i18n scenario strings (allScenStringsReceived).

Since:
2.0.00
See Also:
scenKeys

scenKeys

public java.util.HashSet<java.lang.String> scenKeys
Any scenario keynames for which the server has sent us updated info or i18n strings or responded with "unknown". Empty if server hasn't sent any, ignored if allScenStringsReceived or allScenStringsReceived.

Since:
2.0.00
Constructor Detail

ServerGametypeInfo

public ServerGametypeInfo()
Create a new ServerGametypeInfo, with an optionSet defaulting to our client version's SOCGameOption.getAllKnownOptions().

Method Detail

noMoreOptions

public void noMoreOptions(boolean askedDefaults)
The server doesn't have any more options to send (or none at all, from its version). Set fields as if we've already received the complete set of options, and aren't waiting for any more.

Check the server version against SOCNewGameWithOptions.VERSION_FOR_NEWGAMEWITHOPTIONS (1.1.07). If the server is too old to understand options, right after calling this method you must set optionSet = null.

Parameters:
askedDefaults - Should we also set the askedDefaultsAlready flag? It not, leave it unchanged.

receiveDefaults

public java.util.List<java.lang.String> receiveDefaults(java.util.Map<java.lang.String,SOCGameOption> servOpts)
Set of default options has been received from the server, examine them. Sets allOptionsReceived, defaultsReceived, optionSet. If we already have non-null optionSet, merge (update the values) instead of replacing the entire set with servOpts.

Parameters:
servOpts - The allowable SOCGameOption received from the server. Assumes has been parsed already against the locally known opts, so ones that we don't know are SOCGameOption.OTYPE_UNKNOWN.
Returns:
null if all are known, or a Vector of key names for unknown options.

receiveInfo

public boolean receiveInfo(SOCGameOptionInfo gi)
After calling receiveDefaults, call this as each GAMEOPTIONGETINFO is received. Updates allOptionsReceived.

Parameters:
gi - Message from server with info on one parameter
Returns:
true if all are known, false if more are unknown after this one