|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object soc.client.SOCPlayerClient
public class SOCPlayerClient
Standalone client for connecting to the SOCServer. (For applet see SOCApplet
.)
Prompts for name and password, displays list of games and channels available.
The actual game is played in a separate SOCPlayerInterface
window.
If you want another connection port, you have to specify it as the "port" argument in the html source. If you run this as a stand-alone, you have to specify the port.
At startup or init, will try to connect to server via SOCPlayerClient.ClientNetwork.connect(String, int)
.
See that method for more details.
There are three possible servers to which a client can be connected:
localTCPServer
practiceServer
SOCGame.isPractice
flag determines which connection to use.
Once connected, messages from the server are processed in SOCPlayerClient.MessageTreater.treat(SOCMessage, boolean)
.
Nested Class Summary | |
---|---|
static class |
SOCPlayerClient.ClientNetwork
Helper object to encapsulate and deal with network connectivity. |
private static class |
SOCPlayerClient.ClientWindowAdapter
React to windowOpened, windowClosing events for GameAwtDisplay's Frame. |
static class |
SOCPlayerClient.GameAwtDisplay
A SOCPlayerClient.GameDisplay implementation for AWT. |
static interface |
SOCPlayerClient.GameDisplay
A facade for the SOCPlayerClient to use to invoke actions in the GUI |
static class |
SOCPlayerClient.GameManager
Nested class for processing outgoing messages (putting). |
private static class |
SOCPlayerClient.GameOptionDefaultsTimeoutTask
TimerTask used when new game is asked for, to prevent waiting forever for game option defaults . |
private static class |
SOCPlayerClient.GameOptionsTimeoutTask
TimerTask used soon after client connect, to prevent waiting forever for game options info
(assume slow connection or server bug). |
private class |
SOCPlayerClient.MessageTreater
Nested class for processing incoming messages (treating). |
Field Summary | |
---|---|
private java.util.Map<java.lang.String,PlayerClientListener> |
clientListeners
Map from game-name to the listener for that game. |
(package private) java.util.Locale |
cliLocale
Locale for i18n message lookups used for strings . |
java.lang.String |
DEFAULT_PRACTICE_GAMENAME
For practice games, default game name ("Practice"). |
private SOCPlayerClient.GameDisplay |
gameDisplay
Display for all user interface, including and beyond games. |
private SOCPlayerClient.GameManager |
gameManager
Helper object to send outgoing network traffic to the server. |
protected static java.lang.String |
GAMENAME_PREFIX_CANNOT_JOIN
text prefix to show games this client cannot join. |
protected java.util.Hashtable<java.lang.String,SOCGame> |
games
the games we're currently playing |
protected java.util.Map<java.lang.String,java.lang.String> |
gamesUnjoinableOverride
the unjoinable game names from serverGames that player has asked to join,
and been told they can't. |
protected boolean |
gotPassword
true if we've stored the password and the server's replied that it's correct |
protected java.util.Vector<java.lang.String> |
ignoreList
the ignore list |
static boolean |
isJavaOnOSX
For use in password fields, and possibly by other places, detect if we're running on Mac OS X. |
protected boolean |
isNGOFWaitingForAuthStatus
true if user clicked "new game" and, before showing NewGameOptionsFrame , we've
sent the nickname (username) and password to the server and are waiting for a response. |
protected int |
lastFaceChange
face ID chosen most recently (for use in new games) |
private SOCPlayerClient.ClientNetwork |
net
Helper object to deal with network connectivity. |
protected java.lang.String |
nickname
the nickname; null until validated and set by getValidNickname(true) |
protected int |
numPracticeGames
Number of practice games started; used for naming practice games |
protected java.lang.String |
password
the password for nickname . |
protected ServerGametypeInfo |
practiceServGameOpts
Track the game options available at the remote server, at the practice server. |
protected SOCGameList |
serverGames
all announced game names on the remote server, including games which we can't join due to limitations of the client. |
protected SOCServerFeatures |
sFeatures
Server's active optional features, sent soon after connect, or null if unknown. |
private SOCStringManager |
strings
i18n text strings in our cliLocale . |
protected int |
sVersion
Server version number for remote server, sent soon after connect, 0 if no server, or -1 if version unknown. |
protected ServerGametypeInfo |
tcpServGameOpts
Track the game options available at the remote server, at the practice server. |
private SOCPlayerClient.MessageTreater |
treater
Helper object to receive incoming network traffic from the server. |
Constructor Summary | |
---|---|
SOCPlayerClient()
Create a SOCPlayerClient connecting to localhost port SOCPlayerClient.ClientNetwork.SOC_PORT_DEFAULT . |
Method Summary | |
---|---|
void |
addToGameList(java.lang.String gameName,
java.lang.String gameOptsStr,
boolean addToSrvList)
Add a new game to the initial window's list of games, and possibly to the server games list . |
protected void |
addToIgnoreList(java.lang.String name)
add this name to the ignore list |
protected void |
checkGameoptsForUnknownScenario(java.util.Map<java.lang.String,SOCGameOption> opts)
Check these game options to see if they contain a scenario we don't yet have full info about. |
void |
connect(java.lang.String chost,
int cport,
java.lang.String cuser,
java.lang.String cpass)
Connect and give feedback by showing MESSAGE_PANEL. |
void |
dispose()
network trouble; if possible, ask if they want to play locally (practiceServer vs. |
SOCPlayerClient.GameManager |
getGameManager()
|
SOCPlayerClient.ClientNetwork |
getNet()
|
java.lang.String |
getNickname()
|
int |
getServerVersion(SOCGame game)
Server version, for checking feature availability. |
void |
leaveChannel(java.lang.String ch)
the user leaves the given channel |
protected void |
localizeGameScenarios(java.util.List<java.lang.String> scStrs,
boolean skipFirst,
boolean sentAll,
boolean isPractice)
Localize SOCScenario names and descriptions with strings from the server. |
static void |
main(java.lang.String[] args)
for stand-alones |
protected boolean |
onIgnoreList(java.lang.String name)
|
protected void |
removeFromIgnoreList(java.lang.String name)
remove this name from the ignore list |
void |
setGameDisplay(SOCPlayerClient.GameDisplay gd)
Set our game display interface. |
void |
startPracticeGame()
Create a game name, and start a practice game. |
void |
startPracticeGame(java.lang.String practiceGameName,
java.util.Map<java.lang.String,SOCGameOption> gameOpts,
boolean mainPanelIsActive)
Setup for practice game (on the non-tcp server). |
void |
updateGameEndStats(java.lang.String game,
int[] scores)
If we're playing in a game that's just finished, update the scores. |
static void |
usage()
for stand-alones |
(package private) boolean |
wantsI18nStrings(boolean isPractice)
Should this client request localized strings (I18N) from the server if available? Checks server version, checks whether client locale differs from the fallback "en_US" . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private final SOCStringManager strings
cliLocale
.
protected static final java.lang.String GAMENAME_PREFIX_CANNOT_JOIN
public static final boolean isJavaOnOSX
final java.util.Locale cliLocale
strings
. Also sent to server while connecting.
Override if needed in the constructor by reading the
PROP_JSETTLERS_LOCALE
system property "jsettlers.locale"
.
private SOCPlayerClient.ClientNetwork net
private SOCPlayerClient.MessageTreater treater
private SOCPlayerClient.GameManager gameManager
private SOCPlayerClient.GameDisplay gameDisplay
protected int sVersion
Version.versionNumber()
, not sVersion
,
so always check SOCGame.isPractice
before checking this field.
protected SOCServerFeatures sFeatures
SOCGame.isPractice
before checking this field.
tcpServGameOpts
protected ServerGametypeInfo tcpServGameOpts
SOCPlayerClient.GameAwtDisplay.gameWithOptionsBeginSetup(boolean, boolean)
and/or SOCPlayerClient.MessageTreater.handleVERSION(boolean, SOCVersion)
.
These fields are never null, even if the respective server is not connected or not running.
For a summary of the flags and variables involved with game options,
and the client/server interaction about their values, see
ServerGametypeInfo
's javadoc.
Scenario strings are localized by localizeGameScenarios(List, boolean, boolean, boolean)
.
sFeatures
protected ServerGametypeInfo practiceServGameOpts
SOCPlayerClient.GameAwtDisplay.gameWithOptionsBeginSetup(boolean, boolean)
and/or SOCPlayerClient.MessageTreater.handleVERSION(boolean, SOCVersion)
.
These fields are never null, even if the respective server is not connected or not running.
For a summary of the flags and variables involved with game options,
and the client/server interaction about their values, see
ServerGametypeInfo
's javadoc.
Scenario strings are localized by localizeGameScenarios(List, boolean, boolean, boolean)
.
sFeatures
public final java.lang.String DEFAULT_PRACTICE_GAMENAME
strings
lookup.
protected java.lang.String nickname
getValidNickname(true)
protected java.lang.String password
nickname
. If the server's authenticated this password,
the gotPassword
flag is set.
protected boolean gotPassword
isNGOFWaitingForAuthStatus
protected boolean isNGOFWaitingForAuthStatus
NewGameOptionsFrame
, we've
sent the nickname (username) and password to the server and are waiting for a response.
Used only with TCP servers, not with practiceServer
.
protected int lastFaceChange
protected java.util.Hashtable<java.lang.String,SOCGame> games
protected SOCGameList serverGames
Key is the game name, without the UNJOINABLE prefix.
This field is null until handleGAMES
,
handleGAMESWITHOPTIONS
,
handleNEWGAME
or handleNEWGAMEWITHOPTIONS
is called.
protected java.util.Map<java.lang.String,java.lang.String> gamesUnjoinableOverride
serverGames
that player has asked to join,
and been told they can't. If they click again, try to connect.
(This is a failsafe against bugs in server or client version-recognition.)
Both key and value are the game name, without the UNJOINABLE prefix.
private final java.util.Map<java.lang.String,PlayerClientListener> clientListeners
protected java.util.Vector<java.lang.String> ignoreList
protected int numPracticeGames
Constructor Detail |
---|
public SOCPlayerClient()
SOCPlayerClient.ClientNetwork.SOC_PORT_DEFAULT
.
Initializes helper objects (except SOCPlayerClient.GameDisplay
), locale, SOCStringManager
.
The locale will be the current user's default locale, unless overridden by setting the
PROP_JSETTLERS_LOCALE
system property "jsettlers.locale"
.
Must call SOCApplet.init()
, or setGameDisplay(GameDisplay)
and then
SOCPlayerClient.GameDisplay.initVisualElements()
, to start up and do layout.
Must then call connect(String, int, String, String)
or SOCPlayerClient.ClientNetwork.connect(String, int)
to join a TCP server, or SOCPlayerClient.GameDisplay.clickPracticeButton()
or SOCPlayerClient.GameAwtDisplay.startLocalTCPServer(int)
to start a server locally.
Method Detail |
---|
public void setGameDisplay(SOCPlayerClient.GameDisplay gd)
SOCPlayerClient.GameDisplay.initVisualElements()
.
public void connect(java.lang.String chost, int cport, java.lang.String cuser, java.lang.String cpass)
SOCPlayerClient.GameDisplay.connect(String, String)
to set username and password,
then SOCPlayerClient.ClientNetwork.connect(String, int)
to make the connection.
chost
- Hostname to connect to, or null for localhostcport
- Port number to connect tocuser
- User nicknamecpass
- User optional passwordpublic java.lang.String getNickname()
SOCPlayerClient.GameAwtDisplay.getValidNickname(boolean)
final boolean wantsI18nStrings(boolean isPractice)
"en_US"
.
isPractice
- True if checking for local practice server, not a remote server
protected void checkGameoptsForUnknownScenario(java.util.Map<java.lang.String,SOCGameOption> opts)
Do not call for practice games: Assumes this is the TCP server, because for practice games we already have full info about scenarios and their strings.
opts
- Game options to check for "SC"
, or null
protected void localizeGameScenarios(java.util.List<java.lang.String> scStrs, boolean skipFirst, boolean sentAll, boolean isPractice)
SOCScenario
names and descriptions with strings from the server.
Updates scenario data in practiceServGameOpts
or tcpServGameOpts
.
scStrs
- Scenario localized strings, same format as SOCLocalizedStrings
params.skipFirst
- If true skip the first element of scStrs
, it isn't a scenario keyname.sentAll
- True if no further strings will be received; is SOCLocalizedStrings.FLAG_SENT_ALL
set?
If true, sets ServerGametypeInfo.allScenStringsReceived
.isPractice
- Is the server SOCPlayerClient.ClientNetwork.practiceServer
, not remote?public void addToGameList(java.lang.String gameName, java.lang.String gameOptsStr, boolean addToSrvList)
server games list
.
gameName
- the game name to add to the list;
may have the prefix SOCGames.MARKER_THIS_GAME_UNJOINABLE
gameOptsStr
- String of packed game options
, or nulladdToSrvList
- Should this game be added to the list of remote-server games?
Practice games should not be added.
The serverGames
list also has a flag for cannotJoin.SOCPlayerClient.GameDisplay.addToGameList(boolean, String, String, boolean)
public void updateGameEndStats(java.lang.String game, int[] scores)
public void leaveChannel(java.lang.String ch)
ch
- the name of the channelpublic SOCPlayerClient.GameManager getGameManager()
protected boolean onIgnoreList(java.lang.String name)
protected void addToIgnoreList(java.lang.String name)
name
- the name to addprotected void removeFromIgnoreList(java.lang.String name)
name
- the name to removepublic void startPracticeGame()
SOCPlayerClient.GameAwtDisplay.MAIN_PANEL
is initialized.
public void startPracticeGame(java.lang.String practiceGameName, java.util.Map<java.lang.String,SOCGameOption> gameOpts, boolean mainPanelIsActive)
SOCPlayerClient.ClientNetwork.practiceServer
, client, and robots are started.
practiceGameName
- Unique name to give practice game; if name unknown, call
startPracticeGame()
insteadgameOpts
- Set of game options
to use, or nullmainPanelIsActive
- Is the SOCPlayerClient main panel active?
False if we're being called from elsewhere, such as
SOCConnectOrPracticePanel
.public int getServerVersion(SOCGame game)
game
- Game being played on a practice or tcp server.
Version.versionNumber()
,
or 0 or -1.public void dispose()
public static void usage()
public static void main(java.lang.String[] args)
public SOCPlayerClient.ClientNetwork getNet()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |