soc.client
Class SOCDisplaylessPlayerClient

java.lang.Object
  extended by soc.client.SOCDisplaylessPlayerClient
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
SOCRobotClient

public class SOCDisplaylessPlayerClient
extends java.lang.Object
implements java.lang.Runnable

GUI-less standalone client for connecting to the SOCServer. 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.

The SOCRobotClient is based on this client. Because of this, some methods (such as handleVERSION(boolean, SOCVersion)) assume the client and server are the same version.

Since client and server are the same version, this client ignores game option sync and scenario synchronization messages (SOCGameOptionInfo, SOCScenarioInfo). Being GUI-less, it ignores i18n localization messages (SOCLocalizedStrings).

Author:
Robert S Thomas

Field Summary
protected  java.util.Hashtable<java.lang.String,?> channels
          Chat channels; for general use, or possibly in a future version to control bots.
protected  boolean connected
           
protected  java.lang.String doc
           
protected  java.lang.Exception ex
           
protected  java.util.Hashtable<java.lang.String,SOCGame> games
          the games we're playing
protected  boolean gotPassword
          true if we've stored the password
protected  java.lang.String host
           
protected  java.io.DataInputStream in
           
protected  java.lang.String lastMessage
           
protected  java.lang.String nickname
          the nickname
protected  java.io.DataOutputStream out
           
protected  java.lang.String password
          the password
protected  int port
           
protected  java.lang.Thread reader
           
protected  boolean rejected
          were we rejected from server? (full or robot name taken)
protected  java.net.Socket s
           
protected  SOCServerFeatures sFeatures
          Server's active optional features, sent soon after connect, or null if unknown.
protected  LocalStringConnection sLocal
           
protected  SOCServerFeatures sLocalFeatures
          Server's active optional features, sent soon after connect, or null if unknown.
protected  int sLocalVersion
          Server version number, sent soon after connect, or -1 if unknown.
protected static java.lang.String STATSPREFEX
           
protected  java.lang.String strSocketName
           
protected  int sVersion
          Server version number, sent soon after connect, or -1 if unknown.
 
Constructor Summary
SOCDisplaylessPlayerClient()
          Create a SOCDisplaylessPlayerClient, which would connect to localhost port 8889.
SOCDisplaylessPlayerClient(java.lang.String s, boolean visual)
          Constructor for connecting to a local game (practice) on a local stringport.
SOCDisplaylessPlayerClient(java.lang.String h, int p, boolean visual)
          Constructor for connecting to the specified host, on the specified port.
 
Method Summary
 void acceptOffer(SOCGame ga, int from)
          the user is accepting an offer
 void bankTrade(SOCGame ga, SOCResourceSet give, SOCResourceSet get)
          the user wants to trade with the bank or a port.
 void buildRequest(SOCGame ga, int piece)
          request to build something
 void buyDevCard(SOCGame ga)
          request to buy a development card
 void cancelBuildRequest(SOCGame ga, int piece)
          request to cancel building something
 void changeFace(SOCGame ga, int id)
          the user is changing the face image
 void choosePlayer(SOCGame ga, int ch)
          The user chose a player to steal from, or (game state SOCGame.WAITING_FOR_ROBBER_OR_PIRATE) chose whether to move the robber or the pirate, or (game state SOCGame.WAITING_FOR_ROB_CLOTH_OR_RESOURCE) chose whether to steal a resource or cloth.
 void chSend(java.lang.String ch, java.lang.String mes)
          send a text message to a channel
 void clearOffer(SOCGame ga)
          the user is clearing an offer
 void destroy()
          destroy the applet
 void discard(SOCGame ga, SOCResourceSet rs)
          the user wants to discard
protected  void disconnect()
          disconnect from the net, and from any local practice server
 void discoveryPick(SOCGame ga, SOCResourceSet rscs)
          the user picked 2 resources to discover
 void endTurn(SOCGame ga)
          the user is done with the turn
 java.lang.String getNickname()
           
protected  void handleBCASTTEXTMSG(SOCBCastTextMsg mes)
          handle a broadcast text message
protected  void handleBOARDLAYOUT(SOCBoardLayout mes)
          handle the "board layout" message
static boolean handleBOARDLAYOUT2(java.util.Map<java.lang.String,SOCGame> games, SOCBoardLayout2 mes)
          handle the "board layout" message, new format
static boolean handleBOARDSPECIALEDGE(java.util.Map<java.lang.String,SOCGame> games, SOCBoardSpecialEdge mes)
          Handle the "board special edge" message: Set or clear a special edge on the board.
protected  void handleCANCELBUILDREQUEST(SOCCancelBuildRequest mes)
          handle the rare "cancel build request" message; usually not sent from server to client.
protected  void handleCHANGEFACE(SOCChangeFace mes)
          handle the "change face" message
protected  void handleCHANNELS(SOCChannels mes)
          handle the "list of channels" message
protected  void handleCHOOSEPLAYERREQUEST(SOCChoosePlayerRequest mes)
          handle the "choose player request" message
protected  void handleCLEAROFFER(SOCClearOffer mes)
          handle the "clear offer" message
protected  void handleCLEARTRADEMSG(SOCClearTradeMsg mes)
          handle the "clear trade message" message
protected  void handleDELETECHANNEL(SOCDeleteChannel mes)
          handle the "delete channel" message
protected  void handleDELETEGAME(SOCDeleteGame mes)
          handle the "delete game" message
protected  void handleDEVCARDACTION(boolean isPractice, SOCDevCardAction mes)
          handle the "development card action" message
protected  void handleDEVCARDCOUNT(SOCDevCardCount mes)
          handle the "number of development cards" message
protected  void handleDICERESULT(SOCDiceResult mes)
          handle the "dice result" message
protected  void handleDICERESULTRESOURCES(SOCDiceResultResources mes)
          Handle all players' dice roll result resources.
protected static void handleDICERESULTRESOURCES(SOCDiceResultResources mes, SOCGame ga)
          Handle all players' dice roll result resources: static version to share with SOCPlayerClient.
protected  void handleDISCARDREQUEST(SOCDiscardRequest mes)
          handle the "discard request" message
protected  void handleFIRSTPLAYER(SOCFirstPlayer mes)
          handle the "first player" message
protected  void handleGAMEMEMBERS(SOCGameMembers mes)
          handle the "game members" message
protected  void handleGAMES(SOCGames mes)
          handle the "list of games" message
protected  void handleGAMESERVERTEXT(SOCGameServerText mes)
          handle the "game server text" message; stub for now
protected  void handleGAMESTATE(SOCGameState mes)
          handle the "game state" message
protected  void handleGAMESTATS(SOCGameStats mes)
          handle the "game stats" message
protected  void handleGAMETEXTMSG(SOCGameTextMsg mes)
          handle the "game text message" message
static boolean handleINVENTORYITEMACTION(java.util.Hashtable<java.lang.String,SOCGame> games, SOCInventoryItemAction mes)
          Handle the "inventory item action" message by updating player inventory.
protected  void handleJOIN(SOCJoin mes)
          handle the "join channel" message
protected  void handleJOINAUTH(SOCJoinAuth mes)
          handle the "join authorization" message
protected  void handleJOINGAME(SOCJoinGame mes)
          handle the "join game" message
protected  void handleJOINGAMEAUTH(SOCJoinGameAuth mes, boolean isPractice)
          handle the "join game authorization" message
protected  void handleLARGESTARMY(SOCLargestArmy mes)
          handle the "largest army" message
protected  void handleLEAVE(SOCLeave mes)
          handle the "leave channel" message
protected  void handleLEAVEGAME(SOCLeaveGame mes)
          handle the "leave game" message
protected  void handleLONGESTROAD(SOCLongestRoad mes)
          handle the "longest road" message
protected  void handleMAKEOFFER(SOCMakeOffer mes)
          handle the "make offer" message
protected  void handleMEMBERS(SOCMembers mes)
          handle the "members" message
protected  void handleMOVEPIECE(SOCMovePiece mes)
          Handle moving a piece (a ship) around on the board.
protected  void handleMOVEROBBER(SOCMoveRobber mes)
          handle the "robber moved" or "pirate moved" message.
protected  void handleNEWCHANNEL(SOCNewChannel mes)
          handle the "new channel" message
protected  void handleNEWGAME(SOCNewGame mes)
          handle the "new game" message
protected  void handlePIECEVALUE(SOCPieceValue mes)
          Update a village piece's value on the board (cloth remaining) in _SC_CLVI, or a pirate fortress's strength in _SC_PIRI.
static void handlePLAYERELEMENT_numKnights(SOCPlayerElement mes, SOCPlayer pl, SOCGame ga)
          Update a player's amount of knights, and game's largest army, for handlePLAYERELEMENT(SOCPlayerElement).
static void handlePLAYERELEMENT_numPieces(SOCPlayerElement mes, SOCPlayer pl, int pieceType)
          Update a player's amount of a playing piece, for handlePLAYERELEMENT(SOCPlayerElement).
static void handlePLAYERELEMENT_numRsrc(SOCPlayerElement mes, SOCPlayer pl, int rtype)
          Update a player's amount of a resource, for handlePLAYERELEMENT(SOCPlayerElement).
static void handlePLAYERELEMENT_simple(SOCPlayerElement mes, SOCGame ga, SOCPlayer pl, int pn)
          Update game data for a simple player element or flag, for handlePLAYERELEMENT(SOCPlayerElement).
protected  void handlePLAYERELEMENT(SOCPlayerElement mes)
          handle the "player information" message
static void handlePOTENTIALSETTLEMENTS(SOCPotentialSettlements mes, java.util.Hashtable<java.lang.String,SOCGame> games)
          handle the "list of potential settlements" message
static void handlePUTPIECE(SOCPutPiece mes, SOCGame ga)
          handle the "put piece" message
protected  void handleREJECTCONNECTION(SOCRejectConnection mes)
          handle the "reject connection" message
protected  void handleREJECTOFFER(SOCRejectOffer mes)
          handle the "reject offer" message
protected  void handleREMOVEPIECE(SOCRemovePiece mes)
          A player's piece (a ship) has been removed from the board.
protected  void handleRESETBOARDAUTH(SOCResetBoardAuth mes)
          handle board reset (new game with same players, same game name, new layout).
protected  void handleRESOURCECOUNT(SOCResourceCount mes)
          handle "resource count" message
protected  void handleREVEALFOGHEX(SOCRevealFogHex mes)
          Reveal a hidden hex on the board.
protected  void handleSETPLAYEDDEVCARD(SOCSetPlayedDevCard mes)
          handle the "set played dev card flag" message
protected  void handleSETSEATLOCK(SOCSetSeatLock mes)
          handle the "set seat lock" message
protected static void handleSETSPECIALITEM(java.util.Map<java.lang.String,SOCGame> games, SOCSetSpecialItem mes)
          Handle the "set special item" message.
protected  void handleSETTURN(SOCSetTurn mes)
          handle the "set turn" message
static void handleSIMPLEACTION(java.util.Map<java.lang.String,SOCGame> games, SOCSimpleAction mes)
          Update any game data from "simple action" announcements from the server.
static void handleSIMPLEREQUEST(java.util.Map<java.lang.String,SOCGame> games, SOCSimpleRequest mes)
          Update any game data from "simple request" announcements from the server.
protected  void handleSITDOWN(SOCSitDown mes)
          handle the "player sitting down" message
protected static void handleSTARTGAME(java.util.Hashtable<java.lang.String,SOCGame> games, SOCStartGame mes)
          handle the "start game" message
protected  void handleSTATUSMESSAGE(SOCStatusMessage mes)
          handle the "status message" message
protected  void handleTEXTMSG(SOCTextMsg mes)
          handle a text message
protected  void handleTURN(SOCTurn mes)
          handle the "turn" message
private  void handleVERSION(boolean isLocal, SOCVersion mes)
          Handle the "version" message, server's version report.
 void leaveChannel(java.lang.String ch)
          the user leaves the given channel
 void leaveGame(SOCGame ga)
          the user leaves the given game
static void main(java.lang.String[] args)
          for stand-alones
 void monopolyPick(SOCGame ga, int res)
          the user picked a resource to monopolize
 void moveRobber(SOCGame ga, SOCPlayer pl, int coord)
          the player wants to move the robber
 void offerTrade(SOCGame ga, SOCTradeOffer offer)
          the user is making an offer to trade with another player.
 void pickFreeResources(SOCGame ga, SOCResourceSet rs)
          The user wants to pick these resources to gain from the gold hex.
 void pickSpecialItem(SOCGame ga, java.lang.String typeKey, int gi, int pi)
          Send a request to pick a Special Item, using a SOCSetSpecialItem(PICK, typeKey, gi, pi, owner=-1, coord=-1, level=0) message.
 void playDevCard(SOCGame ga, int dc)
          the user wants to play a development card
 boolean put(java.lang.String s)
          write a message to the net
 void putPiece(SOCGame ga, SOCPlayingPiece pp)
          put a piece on the board
 void rejectOffer(SOCGame ga)
          the user is rejecting the current offers
 void resend()
          resend the last message
 void rollDice(SOCGame ga)
          the user rolls the dice
 void run()
          continuously read from the net in a separate thread
 void sendText(SOCGame ga, java.lang.String me)
          send a text message to the people in the game
 void setSeatLock(SOCGame ga, int pn, SOCGame.SeatLockState sl)
          The user is locking or unlocking a seat.
 void simpleRequest(SOCGame ga, int ourPN, int reqType, int value1, int value2)
          Send a SOCSimpleRequest to the server.
 void sitDown(SOCGame ga, int pn)
          the user sits down to play
 void startGame(SOCGame ga)
          the user is starting the game
 void treat(SOCMessage mes)
          Treat the incoming messages.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STATSPREFEX

protected static java.lang.String STATSPREFEX

doc

protected java.lang.String doc

lastMessage

protected java.lang.String lastMessage

host

protected java.lang.String host

port

protected int port

strSocketName

protected java.lang.String strSocketName

s

protected java.net.Socket s

in

protected java.io.DataInputStream in

out

protected java.io.DataOutputStream out

sLocal

protected LocalStringConnection sLocal

sVersion

protected int sVersion
Server version number, sent soon after connect, or -1 if unknown. sLocalVersion should always equal our own version.


sLocalVersion

protected int sLocalVersion
Server version number, sent soon after connect, or -1 if unknown. sLocalVersion should always equal our own version.


sFeatures

protected SOCServerFeatures sFeatures
Server's active optional features, sent soon after connect, or null if unknown. sLocalFeatures goes with our locally hosted server, if any.

Since:
1.1.19

sLocalFeatures

protected SOCServerFeatures sLocalFeatures
Server's active optional features, sent soon after connect, or null if unknown. sLocalFeatures goes with our locally hosted server, if any.

Since:
1.1.19

reader

protected java.lang.Thread reader

ex

protected java.lang.Exception ex

connected

protected boolean connected

rejected

protected boolean rejected
were we rejected from server? (full or robot name taken)


nickname

protected java.lang.String nickname
the nickname


password

protected java.lang.String password
the password


gotPassword

protected boolean gotPassword
true if we've stored the password


channels

protected java.util.Hashtable<java.lang.String,?> channels
Chat channels; for general use, or possibly in a future version to control bots.


games

protected java.util.Hashtable<java.lang.String,SOCGame> games
the games we're playing

Constructor Detail

SOCDisplaylessPlayerClient

public SOCDisplaylessPlayerClient()
Create a SOCDisplaylessPlayerClient, which would connect to localhost port 8889. Does not actually connect; subclass must connect, such as SOCRobotClient.init()

Note: The default JSettlers server port is 8880.


SOCDisplaylessPlayerClient

public SOCDisplaylessPlayerClient(java.lang.String h,
                                  int p,
                                  boolean visual)
Constructor for connecting to the specified host, on the specified port. Does not actually connect; subclass must connect, such as SOCRobotClient.init()

Parameters:
h - host
p - port
visual - true if this client is visual

SOCDisplaylessPlayerClient

public SOCDisplaylessPlayerClient(java.lang.String s,
                                  boolean visual)
Constructor for connecting to a local game (practice) on a local stringport. Does not actually connect; subclass must connect, such as SOCRobotClient.init()

Parameters:
s - the stringport that the server listens on
visual - true if this client is visual
Method Detail

getNickname

public java.lang.String getNickname()
Returns:
the nickname of this user

run

public void run()
continuously read from the net in a separate thread

Specified by:
run in interface java.lang.Runnable

resend

public void resend()
resend the last message


put

public boolean put(java.lang.String s)
write a message to the net

Parameters:
s - the message
Returns:
true if the message was sent, false if not

treat

public void treat(SOCMessage mes)
Treat the incoming messages. Messages of unknown type are ignored (mes will be null from SOCMessage.toMsg(String)).

Note: Currently, SOCRobotClient.treat(mes) does not generally call this method. New messages should be added in both places if both displayless and robot should handle them. The robot treat's switch case can call super.treat before or after any robot-specific handling.

Parameters:
mes - the message

handleSTATUSMESSAGE

protected void handleSTATUSMESSAGE(SOCStatusMessage mes)
handle the "status message" message

Parameters:
mes - the message

handleJOINAUTH

protected void handleJOINAUTH(SOCJoinAuth mes)
handle the "join authorization" message

Parameters:
mes - the message

handleVERSION

private void handleVERSION(boolean isLocal,
                           SOCVersion mes)
Handle the "version" message, server's version report.

Because SOCDisplaylessPlayerClient is used only for the robot, and the robot should always be the same version as the server, don't ask server for info about game option deltas between the two versions.

If somehow the server isn't our version, print an error and disconnect.

Parameters:
isLocal - Is the server local, or remote? Client can be connected only to local, or remote.
mes - the message

handleJOIN

protected void handleJOIN(SOCJoin mes)
handle the "join channel" message

Parameters:
mes - the message

handleMEMBERS

protected void handleMEMBERS(SOCMembers mes)
handle the "members" message

Parameters:
mes - the message

handleNEWCHANNEL

protected void handleNEWCHANNEL(SOCNewChannel mes)
handle the "new channel" message

Parameters:
mes - the message

handleCHANNELS

protected void handleCHANNELS(SOCChannels mes)
handle the "list of channels" message

Parameters:
mes - the message

handleBCASTTEXTMSG

protected void handleBCASTTEXTMSG(SOCBCastTextMsg mes)
handle a broadcast text message

Parameters:
mes - the message

handleTEXTMSG

protected void handleTEXTMSG(SOCTextMsg mes)
handle a text message

Parameters:
mes - the message

handleLEAVE

protected void handleLEAVE(SOCLeave mes)
handle the "leave channel" message

Parameters:
mes - the message

handleDELETECHANNEL

protected void handleDELETECHANNEL(SOCDeleteChannel mes)
handle the "delete channel" message

Parameters:
mes - the message

handleGAMES

protected void handleGAMES(SOCGames mes)
handle the "list of games" message

Parameters:
mes - the message

handleJOINGAMEAUTH

protected void handleJOINGAMEAUTH(SOCJoinGameAuth mes,
                                  boolean isPractice)
handle the "join game authorization" message

Parameters:
mes - the message
isPractice - Is the server local for practice, or remote?

handleJOINGAME

protected void handleJOINGAME(SOCJoinGame mes)
handle the "join game" message

Parameters:
mes - the message

handleLEAVEGAME

protected void handleLEAVEGAME(SOCLeaveGame mes)
handle the "leave game" message

Parameters:
mes - the message

handleNEWGAME

protected void handleNEWGAME(SOCNewGame mes)
handle the "new game" message

Parameters:
mes - the message

handleDELETEGAME

protected void handleDELETEGAME(SOCDeleteGame mes)
handle the "delete game" message

Parameters:
mes - the message

handleGAMEMEMBERS

protected void handleGAMEMEMBERS(SOCGameMembers mes)
handle the "game members" message

Parameters:
mes - the message

handleGAMESTATS

protected void handleGAMESTATS(SOCGameStats mes)
handle the "game stats" message


handleGAMETEXTMSG

protected void handleGAMETEXTMSG(SOCGameTextMsg mes)
handle the "game text message" message

Parameters:
mes - the message

handleGAMESERVERTEXT

protected void handleGAMESERVERTEXT(SOCGameServerText mes)
handle the "game server text" message; stub for now

Parameters:
mes - the message

handleDICERESULTRESOURCES

protected void handleDICERESULTRESOURCES(SOCDiceResultResources mes)
Handle all players' dice roll result resources. Looks up the game and calls handleDICERESULTRESOURCES(SOCDiceResultResources, SOCGame) so the players gain resources.

Since:
2.0.00

handleDICERESULTRESOURCES

protected static void handleDICERESULTRESOURCES(SOCDiceResultResources mes,
                                                SOCGame ga)
Handle all players' dice roll result resources: static version to share with SOCPlayerClient. Game players gain resources.

Since:
2.0.00

handleSITDOWN

protected void handleSITDOWN(SOCSitDown mes)
handle the "player sitting down" message

Parameters:
mes - the message

handleBOARDLAYOUT

protected void handleBOARDLAYOUT(SOCBoardLayout mes)
handle the "board layout" message

Parameters:
mes - the message

handleBOARDLAYOUT2

public static boolean handleBOARDLAYOUT2(java.util.Map<java.lang.String,SOCGame> games,
                                         SOCBoardLayout2 mes)
handle the "board layout" message, new format

Parameters:
games - Games the client is playing, for method reuse by SOCPlayerClient
mes - the message
Returns:
True if game was found and layout understood, false otherwise
Since:
1.1.08

handleSTARTGAME

protected static void handleSTARTGAME(java.util.Hashtable<java.lang.String,SOCGame> games,
                                      SOCStartGame mes)
handle the "start game" message

Parameters:
games - The hashtable of client's SOCGames; key = game name
mes - the message

handleGAMESTATE

protected void handleGAMESTATE(SOCGameState mes)
handle the "game state" message

Parameters:
mes - the message

handleSETTURN

protected void handleSETTURN(SOCSetTurn mes)
handle the "set turn" message

Parameters:
mes - the message

handleFIRSTPLAYER

protected void handleFIRSTPLAYER(SOCFirstPlayer mes)
handle the "first player" message

Parameters:
mes - the message

handleTURN

protected void handleTURN(SOCTurn mes)
handle the "turn" message

Parameters:
mes - the message

handlePLAYERELEMENT

protected void handlePLAYERELEMENT(SOCPlayerElement mes)
handle the "player information" message

Parameters:
mes - the message

handlePLAYERELEMENT_simple

public static void handlePLAYERELEMENT_simple(SOCPlayerElement mes,
                                              SOCGame ga,
                                              SOCPlayer pl,
                                              int pn)
Update game data for a simple player element or flag, for handlePLAYERELEMENT(SOCPlayerElement). Handles ASK_SPECIAL_BUILD, NUM_PICK_GOLD_HEX_RESOURCES, SCENARIO_CLOTH_COUNT, etc.

To avoid code duplication, also called from SOCPlayerClient.MessageTreater.handlePLAYERELEMENT(SOCPlayerElement) and SOCRobotBrain.run().

Parameters:
mes - Message with amount and action (SET/GAIN/LOSE)
ga - Game to update
pl - Player to update
pn - Player number from message (sometimes -1 for none)
Since:
2.0.00

handlePLAYERELEMENT_numPieces

public static void handlePLAYERELEMENT_numPieces(SOCPlayerElement mes,
                                                 SOCPlayer pl,
                                                 int pieceType)
Update a player's amount of a playing piece, for handlePLAYERELEMENT(SOCPlayerElement). To avoid code duplication, also called from SOCPlayerClient.MessageTreater.handlePLAYERELEMENT(SOCPlayerElement) and SOCRobotBrain.run().

Parameters:
mes - Message with amount and action (SET/GAIN/LOSE)
pl - Player to update
pieceType - Playing piece type, as in SOCPlayingPiece.ROAD

handlePLAYERELEMENT_numKnights

public static void handlePLAYERELEMENT_numKnights(SOCPlayerElement mes,
                                                  SOCPlayer pl,
                                                  SOCGame ga)
Update a player's amount of knights, and game's largest army, for handlePLAYERELEMENT(SOCPlayerElement). To avoid code duplication, also called from SOCPlayerClient.MessageTreater.handlePLAYERELEMENT(SOCPlayerElement) and SOCRobotBrain.run().

Parameters:
mes - Message with amount and action (SET/GAIN/LOSE)
pl - Player to update
ga - Game of player

handlePLAYERELEMENT_numRsrc

public static void handlePLAYERELEMENT_numRsrc(SOCPlayerElement mes,
                                               SOCPlayer pl,
                                               int rtype)
Update a player's amount of a resource, for handlePLAYERELEMENT(SOCPlayerElement).

To avoid code duplication, also called from SOCPlayerClient.MessageTreater.handlePLAYERELEMENT(SOCPlayerElement) and SOCRobotBrain.run().

Parameters:
mes - Message with amount and action (SET/GAIN/LOSE)
pl - Player to update
rtype - Type of resource, like SOCResourceConstants.CLAY

handleRESOURCECOUNT

protected void handleRESOURCECOUNT(SOCResourceCount mes)
handle "resource count" message

Parameters:
mes - the message

handleDICERESULT

protected void handleDICERESULT(SOCDiceResult mes)
handle the "dice result" message

Parameters:
mes - the message

handlePUTPIECE

public static void handlePUTPIECE(SOCPutPiece mes,
                                  SOCGame ga)
handle the "put piece" message

This method is public static for access by SOCRobotBrain.handlePUTPIECE_updateGameData(SOCPutPiece).

Parameters:
mes - the message
ga - Message's game from SOCPutPiece.getGame(); if null, message is ignored

handleCANCELBUILDREQUEST

protected void handleCANCELBUILDREQUEST(SOCCancelBuildRequest mes)
handle the rare "cancel build request" message; usually not sent from server to client.

- When sent from client to server, CANCELBUILDREQUEST means the player has changed their mind about spending resources to build a piece. Only allowed during normal game play (PLACING_ROAD, PLACING_SETTLEMENT, or PLACING_CITY).

When sent from server to client:

- During game startup (START1B or START2B):
Sent from server, CANCELBUILDREQUEST means the current player wants to undo the placement of their initial settlement.

- During piece placement (PLACING_ROAD, PLACING_CITY, PLACING_SETTLEMENT, PLACING_FREE_ROAD1 or PLACING_FREE_ROAD2):

Sent from server, CANCELBUILDREQUEST means the player has sent an illegal PUTPIECE (bad building location). Humans can probably decide a better place to put their road, but robots must cancel the build request and decide on a new plan.

Our client can ignore this case, because the server also sends a text message that the human player is capable of reading and acting on.

Parameters:
mes - the message

handleMOVEROBBER

protected void handleMOVEROBBER(SOCMoveRobber mes)
handle the "robber moved" or "pirate moved" message.

Parameters:
mes - the message

handleDISCARDREQUEST

protected void handleDISCARDREQUEST(SOCDiscardRequest mes)
handle the "discard request" message

Parameters:
mes - the message

handleCHOOSEPLAYERREQUEST

protected void handleCHOOSEPLAYERREQUEST(SOCChoosePlayerRequest mes)
handle the "choose player request" message

Parameters:
mes - the message

handleMAKEOFFER

protected void handleMAKEOFFER(SOCMakeOffer mes)
handle the "make offer" message

Parameters:
mes - the message

handleCLEAROFFER

protected void handleCLEAROFFER(SOCClearOffer mes)
handle the "clear offer" message

Parameters:
mes - the message

handleREJECTOFFER

protected void handleREJECTOFFER(SOCRejectOffer mes)
handle the "reject offer" message

Parameters:
mes - the message

handleCLEARTRADEMSG

protected void handleCLEARTRADEMSG(SOCClearTradeMsg mes)
handle the "clear trade message" message

Parameters:
mes - the message

handleDEVCARDCOUNT

protected void handleDEVCARDCOUNT(SOCDevCardCount mes)
handle the "number of development cards" message

Parameters:
mes - the message

handleDEVCARDACTION

protected void handleDEVCARDACTION(boolean isPractice,
                                   SOCDevCardAction mes)
handle the "development card action" message

Parameters:
isPractice - Is the server local, or remote? Client can be connected only to local, or remote.
mes - the message

handleSETPLAYEDDEVCARD

protected void handleSETPLAYEDDEVCARD(SOCSetPlayedDevCard mes)
handle the "set played dev card flag" message

Parameters:
mes - the message

handleINVENTORYITEMACTION

public static boolean handleINVENTORYITEMACTION(java.util.Hashtable<java.lang.String,SOCGame> games,
                                                SOCInventoryItemAction mes)
Handle the "inventory item action" message by updating player inventory.

Parameters:
games - The hashtable of client's SOCGames; key = game name
mes - the message
Returns:
True if this message is a "cannot play this type now" from server for our client player.
Since:
2.0.00

handlePOTENTIALSETTLEMENTS

public static void handlePOTENTIALSETTLEMENTS(SOCPotentialSettlements mes,
                                              java.util.Hashtable<java.lang.String,SOCGame> games)
                                       throws java.lang.IllegalStateException
handle the "list of potential settlements" message

Parameters:
mes - the message
games - The hashtable of client's SOCGames; key = game name
Throws:
java.lang.IllegalStateException - if the board has SOCBoardLarge.getAddedLayoutPart("AL") != null but badly formed (node list number 0, or a node list number not followed by a land area number). This Added Layout Part is rarely used, and this would be discovered quickly while testing the board layout that contained it.

handleCHANGEFACE

protected void handleCHANGEFACE(SOCChangeFace mes)
handle the "change face" message

Parameters:
mes - the message

handleREJECTCONNECTION

protected void handleREJECTCONNECTION(SOCRejectConnection mes)
handle the "reject connection" message

Parameters:
mes - the message

handleLONGESTROAD

protected void handleLONGESTROAD(SOCLongestRoad mes)
handle the "longest road" message

Parameters:
mes - the message

handleLARGESTARMY

protected void handleLARGESTARMY(SOCLargestArmy mes)
handle the "largest army" message

Parameters:
mes - the message

handleSETSEATLOCK

protected void handleSETSEATLOCK(SOCSetSeatLock mes)
handle the "set seat lock" message

Parameters:
mes - the message

handleRESETBOARDAUTH

protected void handleRESETBOARDAUTH(SOCResetBoardAuth mes)
handle board reset (new game with same players, same game name, new layout). Create new Game object, destroy old one. For human players, the reset message will be followed with others which will fill in the game state. For robots, they must discard game state and ask to re-join.

Parameters:
mes - the message
See Also:
SOCServer.resetBoardAndNotify(String, int), SOCGame.resetAsCopy()

handleSIMPLEREQUEST

public static void handleSIMPLEREQUEST(java.util.Map<java.lang.String,SOCGame> games,
                                       SOCSimpleRequest mes)
Update any game data from "simple request" announcements from the server. Currently ignores them except for:

Parameters:
games - Games the client is playing, for method reuse by SOCPlayerClient
mes - the message
Since:
2.0.00

handleSIMPLEACTION

public static void handleSIMPLEACTION(java.util.Map<java.lang.String,SOCGame> games,
                                      SOCSimpleAction mes)
Update any game data from "simple action" announcements from the server. Currently ignores them except for:

Parameters:
games - Games the client is playing, for method reuse by SOCPlayerClient
mes - the message
Since:
1.1.19

handleMOVEPIECE

protected void handleMOVEPIECE(SOCMovePiece mes)
Handle moving a piece (a ship) around on the board.

Since:
2.0.00

handleREMOVEPIECE

protected void handleREMOVEPIECE(SOCRemovePiece mes)
A player's piece (a ship) has been removed from the board. Updates game state.

Currently, only ships can be removed, in game scenario _SC_PIRI. Other pieceTypes are ignored.

Since:
2.0.00

handleREVEALFOGHEX

protected void handleREVEALFOGHEX(SOCRevealFogHex mes)
Reveal a hidden hex on the board.

Since:
2.0.00

handlePIECEVALUE

protected void handlePIECEVALUE(SOCPieceValue mes)
Update a village piece's value on the board (cloth remaining) in _SC_CLVI, or a pirate fortress's strength in _SC_PIRI.

Since:
2.0.00

handleBOARDSPECIALEDGE

public static final boolean handleBOARDSPECIALEDGE(java.util.Map<java.lang.String,SOCGame> games,
                                                   SOCBoardSpecialEdge mes)
Handle the "board special edge" message: Set or clear a special edge on the board.

Parameters:
games - Games the client is playing, for method reuse by SOCPlayerClient
mes - the message
Returns:
True if game was found and layout understood, false otherwise; false if the game doesn't use SOCBoardLarge.
Since:
2.0.00

handleSETSPECIALITEM

protected static void handleSETSPECIALITEM(java.util.Map<java.lang.String,SOCGame> games,
                                           SOCSetSpecialItem mes)
Handle the "set special item" message. This method handles only OP_SET and OP_CLEAR and ignores other operations, such as OP_PICK. If your client needs to react to those other operations, override this method.

Parameters:
games - Games the client is playing, for method reuse by SOCPlayerClient
mes - the message
Since:
2.0.00

chSend

public void chSend(java.lang.String ch,
                   java.lang.String mes)
send a text message to a channel

Parameters:
ch - the name of the channel
mes - the message

leaveChannel

public void leaveChannel(java.lang.String ch)
the user leaves the given channel

Parameters:
ch - the name of the channel

disconnect

protected void disconnect()
disconnect from the net, and from any local practice server


buyDevCard

public void buyDevCard(SOCGame ga)
request to buy a development card

Parameters:
ga - the game

buildRequest

public void buildRequest(SOCGame ga,
                         int piece)
request to build something

Parameters:
ga - the game
piece - the type of piece, from SOCPlayingPiece constants, or -1 to request the Special Building Phase.

cancelBuildRequest

public void cancelBuildRequest(SOCGame ga,
                               int piece)
request to cancel building something

Parameters:
ga - the game
piece - the type of piece from SOCPlayingPiece

putPiece

public void putPiece(SOCGame ga,
                     SOCPlayingPiece pp)
put a piece on the board

Parameters:
ga - the game where the action is taking place
pp - the piece being placed

moveRobber

public void moveRobber(SOCGame ga,
                       SOCPlayer pl,
                       int coord)
the player wants to move the robber

Parameters:
ga - the game
pl - the player
coord - where the player wants the robber

simpleRequest

public void simpleRequest(SOCGame ga,
                          int ourPN,
                          int reqType,
                          int value1,
                          int value2)
Send a SOCSimpleRequest to the server. reqType gives the request type, and the optional value1 and value2 depend on request type.

Parameters:
ga - the game
ourPN - our player's player number
reqType - Request type, such as SOCSimpleRequest.SC_PIRI_FORT_ATTACK. See SOCSimpleRequest public int fields for possible types and their meanings.
value1 - First optional detail value, or 0
value2 - Second optional detail value, or 0
Since:
2.0.00

pickSpecialItem

public void pickSpecialItem(SOCGame ga,
                            java.lang.String typeKey,
                            int gi,
                            int pi)
Send a request to pick a Special Item, using a SOCSetSpecialItem(PICK, typeKey, gi, pi, owner=-1, coord=-1, level=0) message.

Parameters:
ga - Game
typeKey - Special item type. Typically a SOCGameOption keyname; see the SOCSpecialItem class javadoc for details.
gi - Game Item Index, as in SOCGame.getSpecialItem(String, int) or SOCSpecialItem.playerPickItem(String, SOCGame, SOCPlayer, int, int), or -1
pi - Player Item Index, as in SOCSpecialItem.playerPickItem(String, SOCGame, SOCPlayer, int, int), or -1
Since:
2.0.00

sendText

public void sendText(SOCGame ga,
                     java.lang.String me)
send a text message to the people in the game

Parameters:
ga - the game
me - the message

leaveGame

public void leaveGame(SOCGame ga)
the user leaves the given game

Parameters:
ga - the game

sitDown

public void sitDown(SOCGame ga,
                    int pn)
the user sits down to play

Parameters:
ga - the game
pn - the number of the seat where the user wants to sit

startGame

public void startGame(SOCGame ga)
the user is starting the game

Parameters:
ga - the game

rollDice

public void rollDice(SOCGame ga)
the user rolls the dice

Parameters:
ga - the game

endTurn

public void endTurn(SOCGame ga)
the user is done with the turn

Parameters:
ga - the game

discard

public void discard(SOCGame ga,
                    SOCResourceSet rs)
the user wants to discard

Parameters:
ga - the game
rs - Resources to discard

pickFreeResources

public void pickFreeResources(SOCGame ga,
                              SOCResourceSet rs)
The user wants to pick these resources to gain from the gold hex.

Parameters:
ga - the game
rs - Resources to gain
Since:
2.0.00

choosePlayer

public void choosePlayer(SOCGame ga,
                         int ch)
The user chose a player to steal from, or (game state SOCGame.WAITING_FOR_ROBBER_OR_PIRATE) chose whether to move the robber or the pirate, or (game state SOCGame.WAITING_FOR_ROB_CLOTH_OR_RESOURCE) chose whether to steal a resource or cloth.

Parameters:
ga - the game
ch - the player number, or SOCChoosePlayer.CHOICE_MOVE_ROBBER to move the robber or SOCChoosePlayer.CHOICE_MOVE_PIRATE to move the pirate ship. See SOCChoosePlayer.SOCChoosePlayer(String, int) for meaning of ch for game state WAITING_FOR_ROB_CLOTH_OR_RESOURCE.

rejectOffer

public void rejectOffer(SOCGame ga)
the user is rejecting the current offers

Parameters:
ga - the game

acceptOffer

public void acceptOffer(SOCGame ga,
                        int from)
the user is accepting an offer

Parameters:
ga - the game
from - the number of the player that is making the offer

clearOffer

public void clearOffer(SOCGame ga)
the user is clearing an offer

Parameters:
ga - the game

bankTrade

public void bankTrade(SOCGame ga,
                      SOCResourceSet give,
                      SOCResourceSet get)
the user wants to trade with the bank or a port.

Parameters:
ga - the game
give - what is being offered
get - what the player wants

offerTrade

public void offerTrade(SOCGame ga,
                       SOCTradeOffer offer)
the user is making an offer to trade with another player.

Parameters:
ga - the game
offer - the trade offer

playDevCard

public void playDevCard(SOCGame ga,
                        int dc)
the user wants to play a development card

Parameters:
ga - the game
dc - the type of development card

discoveryPick

public void discoveryPick(SOCGame ga,
                          SOCResourceSet rscs)
the user picked 2 resources to discover

Parameters:
ga - the game
rscs - the resources

monopolyPick

public void monopolyPick(SOCGame ga,
                         int res)
the user picked a resource to monopolize

Parameters:
ga - the game
res - the resource

changeFace

public void changeFace(SOCGame ga,
                       int id)
the user is changing the face image

Parameters:
ga - the game
id - the image id

setSeatLock

public void setSeatLock(SOCGame ga,
                        int pn,
                        SOCGame.SeatLockState sl)
The user is locking or unlocking a seat.

Parameters:
ga - the game
pn - the seat number
sl - new seat lock state; remember that servers older than v2.0.00 won't recognize CLEAR_ON_RESET
Since:
2.0.00

destroy

public void destroy()
destroy the applet


main

public static void main(java.lang.String[] args)
for stand-alones