soc.server
Class SOCClientData

java.lang.Object
  extended by soc.server.SOCClientData

public class SOCClientData
extends java.lang.Object

The server's place to track client-specific information across games. The win-loss count is kept here. Not tied to any database; information here is only for the current session, not persistent across disconnects/reconnects by clients.

Since:
1.1.04
Author:
Jeremy D Monin

Nested Class Summary
private static class SOCClientData.SOCCDCliVersionTask
          TimerTask at client connect, to guess the client version if it isn't sent soon enough.
 
Field Summary
 boolean checkedLocaleScenStrings
          If true we've called SOCServer.clientHasLocalizedStrs_gameScenarios(StringConnection), storing the result in localeHasScenStrings.
private  SOCClientData.SOCCDCliVersionTask cliVersionTask
          TimerTask for connect-time client-version timer
private  java.lang.Object countFieldSync
          Synchronization for win-loss count and other counter fields
private  int currentCreatedChannels
          Number of games/channels this client has created, which currently exist (not deleted)
private  int currentCreatedGames
          Number of games/channels this client has created, which currently exist (not deleted)
 long disconnectLastPingMillis
          Are we considering a request to disconnect this client? If so, the time we sent a ping (and awaiting a reply).
 boolean isBuiltInRobot
          Is this robot connection the built-in robot (not a 3rd-party), with the original AI?
 boolean isRobot
          Is this connection a robot?
 java.util.Locale locale
          Client's reported JVM locale, or null, as in Locale.getDefault().
 boolean localeHasScenStrings
          If true we've called SOCServer.clientHasLocalizedStrs_gameScenarios(StringConnection), and this client's locale is not null and has at least some localized scenario strings (see that method's javadoc for details).
 java.lang.String localeStr
          Client's reported JVM locale, or null, as in Locale.toString().
private  int losses
          Number of games won and lost since client connected
 java.lang.String robot3rdPartyBrainClass
          For 3rd-party robots, their type (brain class).
 java.util.Map<java.lang.String,java.lang.String> scenariosInfoSent
          The SOCScenario keynames for which we've sent localized strings or all scenario info fields.
static java.lang.String SENT_SCEN_INFO
          For a scenario keyname in scenariosInfoSent, value indicating that the client was sent all scenario info fields (not only localized scenario strings).
static java.lang.String SENT_SCEN_STRINGS
          For a scenario keyname in scenariosInfoSent, value indicating that the client was sent localized scenario strings (not all scenario info fields), or that the client requested them and no localized strings were found for that scenario.
 boolean sentAllScenarioInfo
          True if we've sent all updated SOCScenario info.
 boolean sentAllScenarioStrings
          True if we've sent localized strings for all SOCScenarios.
private  boolean sentGameList
          Has the server's game list been sent to the client yet? Please synchronize on SOCGameList.takeMonitor() / releaseMonitor.
 boolean wantsI18N
          If this flag is set, client has determined it wants localized strings (I18N), and asked for them early in the connect process by sending a message that had SOCGameOptionGetInfos.hasTokenGetI18nDescs() true.
private  int wins
          Number of games won and lost since client connected
 
Constructor Summary
SOCClientData()
           
 
Method Summary
 void clearVersionTimer()
          Cancel the version timer, don't fire it.
 void copyClientPlayerStats(SOCClientData source)
          Copy the client's win-loss record from another SOCClientData.
 void createdChannel()
          Client has created a channel; update the count.
 void createdGame()
          Client has created a game; update the count.
 void deletedChannel()
          Client has deleted a channel they created; update the count.
 void deletedGame()
          Client has deleted a game they created; update the count.
 int getcurrentCreatedChannels()
           
 int getCurrentCreatedGames()
           
 int getLosses()
           
 int getWins()
           
 boolean hasSentGameList()
          Has the server's game list been sent to the client yet? Please synchronize on SOCGameList.takeMonitor() / releaseMonitor.
 void lostGame()
          Client has lost a game; update win-loss count.
 void setSentGameList()
          Set flag: Has the server's game list been sent to the client yet? Please synchronize on SOCGameList.takeMonitor() / releaseMonitor.
 void setVersionTimer(SOCServer sr, StringConnection con)
          Set up the version timer.
 void wonGame()
          Client has won a game; update win-loss count.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

wins

private int wins
Number of games won and lost since client connected


losses

private int losses
Number of games won and lost since client connected


locale

public java.util.Locale locale
Client's reported JVM locale, or null, as in Locale.getDefault(). Sent via Locale.toString() as part of the SOCVersion message. Kept as localeStr and also parsed to this field. Not sent from jsettlers clients older than 2.0.00; if null, should probably assume en_US since older versions had all messages in english. Bots always use a null locale; they don't care about message text contents, and a null locale means they won't set any SOCGame.hasMultiLocales flag by joining.

Since:
2.0.00
See Also:
wantsI18N

localeStr

public java.lang.String localeStr
Client's reported JVM locale, or null, as in Locale.toString(). Sent as part of the SOCVersion message, kept here and also parsed to locale. Not sent from jsettlers clients older than 2.0.00; if null, should probably assume en_US since older versions had all messages in english. Bots always use a null locale, see locale javadoc for details.

Since:
2.0.00
See Also:
wantsI18N

wantsI18N

public boolean wantsI18N
If this flag is set, client has determined it wants localized strings (I18N), and asked for them early in the connect process by sending a message that had SOCGameOptionGetInfos.hasTokenGetI18nDescs() true. Server can later check this flag to see if responses to various client request messages should include localized strings.

Set this flag only if:

Since:
2.0.00
See Also:
locale

currentCreatedGames

private int currentCreatedGames
Number of games/channels this client has created, which currently exist (not deleted)

Since:
1.1.10

currentCreatedChannels

private int currentCreatedChannels
Number of games/channels this client has created, which currently exist (not deleted)

Since:
1.1.10

countFieldSync

private java.lang.Object countFieldSync
Synchronization for win-loss count and other counter fields


sentGameList

private boolean sentGameList
Has the server's game list been sent to the client yet? Please synchronize on SOCGameList.takeMonitor() / releaseMonitor.

Since:
1.1.06

checkedLocaleScenStrings

public boolean checkedLocaleScenStrings
If true we've called SOCServer.clientHasLocalizedStrs_gameScenarios(StringConnection), storing the result in localeHasScenStrings.

Since:
2.0.00

localeHasScenStrings

public boolean localeHasScenStrings
If true we've called SOCServer.clientHasLocalizedStrs_gameScenarios(StringConnection), and this client's locale is not null and has at least some localized scenario strings (see that method's javadoc for details).

Since:
2.0.00
See Also:
checkedLocaleScenStrings, sentAllScenarioStrings

sentAllScenarioStrings

public boolean sentAllScenarioStrings
True if we've sent localized strings for all SOCScenarios. To reduce network traffic, those large strings aren't sent unless the client is creating a new game and needs the scenario dropdown.

Also true if the client's locale doesn't have localized strings for scenarios, or if the client is too old (1.1.xx) to use i18n localization.

Since:
2.0.00
See Also:
scenariosInfoSent, sentAllScenarioInfo, localeHasScenStrings

sentAllScenarioInfo

public boolean sentAllScenarioInfo
True if we've sent all updated SOCScenario info. Like sentAllScenarioStrings, scenario info messages aren't sent unless needed.

Also true if the client is too old (1.1.xx) to use scenarios.

Since:
2.0.00
See Also:
scenariosInfoSent, sentAllScenarioStrings

SENT_SCEN_STRINGS

public static final java.lang.String SENT_SCEN_STRINGS
For a scenario keyname in scenariosInfoSent, value indicating that the client was sent localized scenario strings (not all scenario info fields), or that the client requested them and no localized strings were found for that scenario.

Since:
2.0.00
See Also:
SENT_SCEN_INFO, Constant Field Values

SENT_SCEN_INFO

public static final java.lang.String SENT_SCEN_INFO
For a scenario keyname in scenariosInfoSent, value indicating that the client was sent all scenario info fields (not only localized scenario strings).

Since:
2.0.00
See Also:
SENT_SCEN_STRINGS, Constant Field Values

scenariosInfoSent

public java.util.Map<java.lang.String,java.lang.String> scenariosInfoSent
The SOCScenario keynames for which we've sent localized strings or all scenario info fields. To reduce network traffic, those large strings aren't sent unless the client is joining a game with a scenario, or has requested them.

For any scenario's keyname here, the value will be either SENT_SCEN_STRINGS or SENT_SCEN_INFO. If a scenario's key isn't contained in this map, nothing has been sent about it unless the sentAllScenarioStrings flag is set.

Null if sentAllScenarioStrings or if client hasn't requested any or joined any game that has a scenario.

SOCGameOption strings are also localized, but aren't tracked the same way because game option strings are all sent when the client connects.

Since:
2.0.00

isRobot

public boolean isRobot
Is this connection a robot?

Since:
1.1.07

isBuiltInRobot

public boolean isBuiltInRobot
Is this robot connection the built-in robot (not a 3rd-party), with the original AI?

Since:
1.1.09
See Also:
robot3rdPartyBrainClass, SOCImARobot

robot3rdPartyBrainClass

public java.lang.String robot3rdPartyBrainClass
For 3rd-party robots, their type (brain class). When isBuiltInRobot, this field is null, not SOCImARobot.RBCLASS_BUILTIN.

Since:
1.1.09

disconnectLastPingMillis

public long disconnectLastPingMillis
Are we considering a request to disconnect this client? If so, the time we sent a ping (and awaiting a reply). Same format as System.currentTimeMillis(). Value is 0 otherwise. Only client versions 1.1.08 and higher respond to the SOCMessage.SERVERPING message.

Since:
1.1.08

cliVersionTask

private SOCClientData.SOCCDCliVersionTask cliVersionTask
TimerTask for connect-time client-version timer

Since:
1.1.06
Constructor Detail

SOCClientData

public SOCClientData()
Method Detail

wonGame

public void wonGame()
Client has won a game; update win-loss count. Thread-safe; synchronizes on an internal object.


lostGame

public void lostGame()
Client has lost a game; update win-loss count. Thread-safe; synchronizes on an internal object.


createdGame

public void createdGame()
Client has created a game; update the count. Thread-safe; synchronizes on an internal object.

Since:
1.1.10

createdChannel

public void createdChannel()
Client has created a channel; update the count. Thread-safe; synchronizes on an internal object.

Since:
1.1.10

deletedGame

public void deletedGame()
Client has deleted a game they created; update the count. Thread-safe; synchronizes on an internal object.

Since:
1.1.10

deletedChannel

public void deletedChannel()
Client has deleted a channel they created; update the count. Thread-safe; synchronizes on an internal object.

Since:
1.1.10

getWins

public int getWins()
Returns:
Number of games won by this client in this session

getLosses

public int getLosses()
Returns:
Number of games lost by this client in this session

getCurrentCreatedGames

public int getCurrentCreatedGames()
Returns:
Number of games this client has created, which currently exist (not deleted)
Since:
1.1.10

getcurrentCreatedChannels

public int getcurrentCreatedChannels()
Returns:
Number of channels this client has created, which currently exist (not deleted)
Since:
1.1.10

copyClientPlayerStats

public void copyClientPlayerStats(SOCClientData source)
Copy the client's win-loss record from another SOCClientData. (getWins(), getLosses()).

Parameters:
source - Copy from here
Since:
1.1.08

hasSentGameList

public boolean hasSentGameList()
Has the server's game list been sent to the client yet? Please synchronize on SOCGameList.takeMonitor() / releaseMonitor.

Since:
1.1.06

setSentGameList

public void setSentGameList()
Set flag: Has the server's game list been sent to the client yet? Please synchronize on SOCGameList.takeMonitor() / releaseMonitor.

Since:
1.1.06

setVersionTimer

public void setVersionTimer(SOCServer sr,
                            StringConnection con)
Set up the version timer. It will fire after SOCServer.CLI_VERSION_TIMER_FIRE_MS milliseconds.

Parameters:
sr - Our SOCServer
con - Connection for this timer / this clientdata
Since:
1.1.06

clearVersionTimer

public void clearVersionTimer()
Cancel the version timer, don't fire it.

Since:
1.1.06