soc.message
Class SOCMessageTemplate2s

java.lang.Object
  extended by soc.message.SOCMessage
      extended by soc.message.SOCMessageTemplate2s
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, SOCMessageForGame
Direct Known Subclasses:
SOCNewGameWithOptions

public abstract class SOCMessageTemplate2s
extends SOCMessage
implements SOCMessageForGame

Template for per-game message types with 2 string parameters. The second parameter can be optional. Your class javadoc should explain the meaning of param1 and param2, so that you won't need to write getters for those.

You will have to write parseDataStr, because of its return type and because it's static.

Sample implementation:

   // format of s: REJECTCARDNAME sep game sep2 cardid sep2 cardname
   public static SOCRejectCardName parseDataStr(final String s)
   {
       String ga; // the game name
       String cid; // the card id
       String cname; // the card name, or null for unknown

       StringTokenizer st = new StringTokenizer(s, sep2);

       try
       {
           ga = st.nextToken();
           cid = st.nextToken();
           cname = st.nextToken();
       }
       catch (Exception e)
       {
           return null;
       }

        return new SOCRejectCardName(ga, cid, cname);
   }

Since:
1.1.00
Author:
Jeremy D Monin <jeremy@nand.net>
See Also:
Serialized Form

Field Summary
protected  java.lang.String game
          Name of the game.
protected  java.lang.String p1
          First string parameter.
protected  java.lang.String p2
          Second, optional string parameter; null if missing.
private static long serialVersionUID
           
 
Fields inherited from class soc.message.SOCMessage
ACCEPTOFFER, ADMINPING, ADMINRESET, AUTHREQUEST, BANKTRADE, BCASTTEXTMSG, BOARDLAYOUT, BOARDLAYOUT2, BOARDSPECIALEDGE, BUILDREQUEST, BUYCARDREQUEST, CANCELBUILDREQUEST, CHANGEFACE, CHANNELS, CHOOSEPLAYER, CHOOSEPLAYERREQUEST, CLEAROFFER, CLEARTRADEMSG, CREATEACCOUNT, DEBUGFREEPLACE, DELETECHANNEL, DELETEGAME, DEVCARDACTION, DEVCARDCOUNT, DICERESULT, DICERESULTRESOURCES, DISCARD, DISCARDREQUEST, DISCOVERYPICK, ENDTURN, FIRSTPLAYER, GAME_NONE, GAMEMEMBERS, GAMEOPTIONGETDEFAULTS, GAMEOPTIONGETINFOS, GAMEOPTIONINFO, GAMES, GAMESERVERTEXT, GAMESTATE, GAMESTATS, GAMESWITHOPTIONS, GAMETEXTMSG, IMAROBOT, INVENTORYITEMACTION, JOIN, JOINAUTH, JOINGAME, JOINGAMEAUTH, LARGESTARMY, LASTSETTLEMENT, LEAVE, LEAVEALL, LEAVEGAME, LEGALEDGES, LOCALIZEDSTRINGS, LONGESTROAD, MAKEOFFER, MEMBERS, messageType, MONOPOLYPICK, MOVEPIECE, MOVEPIECEREQUEST, MOVEROBBER, NEWCHANNEL, NEWGAME, NEWGAMEWITHOPTIONS, NEWGAMEWITHOPTIONSREQUEST, NULLMESSAGE, PICKRESOURCES, PICKRESOURCESREQUEST, PIECEVALUE, PLAYDEVCARDREQUEST, PLAYERELEMENT, PLAYERELEMENTS, PLAYERSTATS, POTENTIALSETTLEMENTS, PUTPIECE, REJECTCONNECTION, REJECTOFFER, REMOVEPIECE, RESETBOARDAUTH, RESETBOARDREJECT, RESETBOARDREQUEST, RESETBOARDVOTE, RESETBOARDVOTEREQUEST, RESOURCECOUNT, REVEALFOGHEX, ROBOTDISMISS, ROBOTJOINGAMEREQUEST, ROLLDICE, ROLLDICEPROMPT, ROLLDICEREQUEST, SCENARIOINFO, sep, sep_char, sep2, sep2_char, SERVERPING, SETPLAYEDDEVCARD, SETSEATLOCK, SETSPECIALITEM, SETTURN, SETUPDONE, SIMPLEACTION, SIMPLEREQUEST, SITDOWN, STARTGAME, STATUSMESSAGE, SVPTEXTMSG, TEXTMSG, TIMINGPING, TURN, UPDATEROBOTPARAMS, VERSION
 
Constructor Summary
protected SOCMessageTemplate2s(int id, java.lang.String ga, java.lang.String p1, java.lang.String p2)
          Create a new message.
 
Method Summary
 java.lang.String getGame()
          Name of game this message is for.
 java.lang.String getParam1()
           
 java.lang.String getParam2()
           
 java.lang.String toCmd()
          MESSAGETYPE sep game sep2 param1 sep2 param2
protected static java.lang.String toCmd(int messageType, java.lang.String ga, java.lang.String param1, java.lang.String param2)
          MESSAGETYPE sep game sep2 param1 sep2 param2
 java.lang.String toString()
          Simple human-readable representation, used for debug purposes.
 
Methods inherited from class soc.message.SOCMessage
arrayIntoStringBuf, enumIntoStringBuf, getClassNameShort, getMaximumVersion, getMinimumVersion, getType, isSingleLineAndSafe, isSingleLineAndSafe, toMsg
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface soc.message.SOCMessageForGame
getType
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

game

protected java.lang.String game
Name of the game.


p1

protected java.lang.String p1
First string parameter.


p2

protected java.lang.String p2
Second, optional string parameter; null if missing.

Constructor Detail

SOCMessageTemplate2s

protected SOCMessageTemplate2s(int id,
                               java.lang.String ga,
                               java.lang.String p1,
                               java.lang.String p2)
Create a new message. The second parameter is optional here; your subclass may decide to make it mandatory.

Parameters:
id - Message type ID
ga - Name of game this message is for
p1 - First parameter
p2 - Second parameter, or null
Method Detail

getGame

public java.lang.String getGame()
Description copied from interface: SOCMessageForGame
Name of game this message is for. Must not be null if message is in per-game structures or code.

At the server, the message treater dispatches incoming SOCMessageForGames based on their getGame():

Specified by:
getGame in interface SOCMessageForGame
Returns:
the name of the game
See Also:
SOCMessage.GAME_NONE

getParam1

public java.lang.String getParam1()
Returns:
the first parameter

getParam2

public java.lang.String getParam2()
Returns:
the second parameter, or null

toCmd

public java.lang.String toCmd()
MESSAGETYPE sep game sep2 param1 sep2 param2

Specified by:
toCmd in class SOCMessage
Returns:
the command String

toCmd

protected static java.lang.String toCmd(int messageType,
                                        java.lang.String ga,
                                        java.lang.String param1,
                                        java.lang.String param2)
MESSAGETYPE sep game sep2 param1 sep2 param2

Parameters:
messageType - The message type id
ga - the game name
param1 - The first parameter
param2 - The second parameter, or null
Returns:
the command string

toString

public java.lang.String toString()
Description copied from class: SOCMessage
Simple human-readable representation, used for debug purposes.

Specified by:
toString in class SOCMessage
Returns:
a human readable form of the message