|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object soc.message.SOCMessage
public abstract class SOCMessage
Messages used for game data, events, and chatting on a channel.
No objects, only strings and integers, are to be sent over the network
between servers and clients! Your game's code must guarantee that no string
sent contains a separator character (sep_char
or sep2_char
).
To help with this, use isSingleLineAndSafe(String)
.
Text announcements (SOCGameServerText
or SOCGameTextMsg
)
are often sent after data messages.
The message data is sent over the network as type ID + data strings built by each SOCMessage subclass's toCmd() method.
On the remote end, it's reconstructed to a new instance of the
appropriate SOCMessage subclass, by the subclass' required method
static SOCMessageSubclass parseDataStr(String).
parseDataStr is called from toMsg(String)
in this class.
The client receives messages in SOCPlayerClient.MessageTreater.treat(SOCMessage, boolean)
.
The server receives messages in SOCServer.processCommand(String, StringConnection)
.
To create and add a new message type:
toMsg(String)
. Again, note the version.
In the switch you will call yourMessageType.parseDataStr(data).
If your message class extends SOCMessageTemplateMs or SOCMessageTemplateMi,
instead call yourMessageType.parseDataStr(multiData).
SOCMessageForGame
.
SOCRevealFogHex
and SOCSetTurn
are good example subclasses.)
Template parent-classes can help; the example subclasses extend them.
Be sure to override the minimum version reported in getMinimumVersion()
.
Set serialVersionUID to the version it's added in.
for example, if adding for version 1.1.09:
private static final long serialVersionUID = 1109L;
Note: Most things added to SOCPlayerClient.treat should also be added to
SOCDisplaylessPlayerClient.treat(SOCMessage)
,
to SOCRobotClient.treat(SOCMessage)
,
and possibly to SOCRobotBrain.run()
.
If the message is player-state related, you might also want to add it in your game type's soc.server.GameHandler.sitDown_sendPrivateInfo().
Backwards compatibility: Unknown message types are ignored by client and by server.
Technically they are returned as null from toMsg(String)
if the local copy
(the old version's code) of SOCMessage doesn't know that message type.
Format:
For most messages, at most one sep
token per message, which separates the messagetype number
from the message data; multiple SEP2 are allowed after SEP.
For multi-messages, multiple SEP are allowed; see SOCMessageMulti
.
Field Summary | |
---|---|
static int |
ACCEPTOFFER
|
static int |
ADMINPING
|
static int |
ADMINRESET
|
static int |
AUTHREQUEST
Authentication request, to do so without creating or joining a game or channel; see SOCAuthRequest . |
static int |
BANKTRADE
|
static int |
BCASTTEXTMSG
|
static int |
BOARDLAYOUT
|
static int |
BOARDLAYOUT2
|
static int |
BOARDSPECIALEDGE
Make an edge on the board special or no longer special ( SOCBoardSpecialEdge ). |
static int |
BUILDREQUEST
|
static int |
BUYCARDREQUEST
|
static int |
CANCELBUILDREQUEST
|
static int |
CHANGEFACE
|
static int |
CHANNELS
|
static int |
CHOOSEPLAYER
|
static int |
CHOOSEPLAYERREQUEST
|
static int |
CLEAROFFER
|
static int |
CLEARTRADEMSG
|
static int |
CREATEACCOUNT
|
static int |
DEBUGFREEPLACE
|
static int |
DELETECHANNEL
|
static int |
DELETEGAME
|
static int |
DEVCARDACTION
SOCDevCardAction message; before v2.0.00, this type was DEVCARD (class name SOCDevCard ). |
static int |
DEVCARDCOUNT
|
static int |
DICERESULT
|
static int |
DICERESULTRESOURCES
SOCDiceResultResources - All resources gained by players from a dice roll. |
static int |
DISCARD
|
static int |
DISCARDREQUEST
|
static int |
DISCOVERYPICK
|
static int |
ENDTURN
|
static int |
FIRSTPLAYER
|
static java.lang.String |
GAME_NONE
"Not for any game" marker, used when any of the SOCMessageTemplate* message types
(which all implement SOCMessageForGame ) are used for convenience for non-game messages
such as SOCLocalizedStrings . |
static int |
GAMEMEMBERS
|
static int |
GAMEOPTIONGETDEFAULTS
|
static int |
GAMEOPTIONGETINFOS
|
static int |
GAMEOPTIONINFO
|
static int |
GAMES
|
static int |
GAMESERVERTEXT
SOCGameServerText - Game text announcements from the server. |
static int |
GAMESTATE
|
static int |
GAMESTATS
|
static int |
GAMESWITHOPTIONS
|
static int |
GAMETEXTMSG
SOCGameTextMsg - Game text from players. |
static int |
IMAROBOT
|
static int |
INVENTORYITEMACTION
SOCInventoryItemAction message: Add or remove a SOCInventoryItem
(excluding SOCDevCard s) from a player's inventory. |
static int |
JOIN
|
static int |
JOINAUTH
|
static int |
JOINGAME
|
static int |
JOINGAMEAUTH
|
static int |
LARGESTARMY
|
static int |
LASTSETTLEMENT
|
static int |
LEAVE
|
static int |
LEAVEALL
|
static int |
LEAVEGAME
|
static int |
LEGALEDGES
Legal road or ship edges for the large sea board. |
static int |
LOCALIZEDSTRINGS
SOCLocalizedStrings - Localized i18n strings for items such as game options or scenarios. |
static int |
LONGESTROAD
|
static int |
MAKEOFFER
|
static int |
MEMBERS
|
protected int |
messageType
An ID identifying the type of message |
static int |
MONOPOLYPICK
|
static int |
MOVEPIECE
Move a piece to another location; server reply to MOVEPIECEREQUEST . |
static int |
MOVEPIECEREQUEST
Ask server to move a piece to another location. |
static int |
MOVEROBBER
|
static int |
NEWCHANNEL
|
static int |
NEWGAME
|
static int |
NEWGAMEWITHOPTIONS
|
static int |
NEWGAMEWITHOPTIONSREQUEST
|
static int |
NULLMESSAGE
|
static int |
PICKRESOURCES
Client reply to PICKRESOURCESREQUEST . |
static int |
PICKRESOURCESREQUEST
Ask client to pick this many resources, when they have a settlement or city next to a gold hex. |
static int |
PIECEVALUE
Update the value(s) of a piece on the board. |
static int |
PLAYDEVCARDREQUEST
|
static int |
PLAYERELEMENT
|
static int |
PLAYERELEMENTS
|
static int |
PLAYERSTATS
|
static int |
POTENTIALSETTLEMENTS
|
static int |
PUTPIECE
|
static int |
REJECTCONNECTION
|
static int |
REJECTOFFER
|
static int |
REMOVEPIECE
SOCRemovePiece - Remove a piece from the board; currently used only with ships. |
static int |
RESETBOARDAUTH
|
static int |
RESETBOARDREJECT
|
static int |
RESETBOARDREQUEST
|
static int |
RESETBOARDVOTE
|
static int |
RESETBOARDVOTEREQUEST
|
static int |
RESOURCECOUNT
|
static int |
REVEALFOGHEX
Reveal a hidden hex on the board; server to all clients in game. |
static int |
ROBOTDISMISS
|
static int |
ROBOTJOINGAMEREQUEST
|
static int |
ROLLDICE
|
static int |
ROLLDICEPROMPT
|
static int |
ROLLDICEREQUEST
|
static int |
SCENARIOINFO
SOCScenarioInfo - Client's request about available SOCScenario s,
or server's reply about a single scenario. |
static java.lang.String |
sep
Token separators. |
static char |
sep_char
main separator token sep , as character. |
static java.lang.String |
sep2
secondary separator token SEP2, as string. |
static char |
sep2_char
secondary separator token sep2 , as character. |
private static long |
serialVersionUID
|
static int |
SERVERPING
|
static int |
SETPLAYEDDEVCARD
|
static int |
SETSEATLOCK
|
static int |
SETSPECIALITEM
SOCSetSpecialItem - Special Item requests and change announcements. |
static int |
SETTURN
|
static int |
SETUPDONE
|
static int |
SIMPLEACTION
SOCSimpleAction - Generic message type for simple actions for players. |
static int |
SIMPLEREQUEST
SOCSimpleRequest - Generic message type for simple requests by players. |
static int |
SITDOWN
|
static int |
STARTGAME
|
static int |
STATUSMESSAGE
|
static int |
SVPTEXTMSG
Text that a player has been awarded Special Victory Point(s). |
static int |
TEXTMSG
|
static int |
TIMINGPING
|
static int |
TURN
|
static int |
UPDATEROBOTPARAMS
|
static int |
VERSION
|
Constructor Summary | |
---|---|
SOCMessage()
|
Method Summary | |
---|---|
protected static void |
arrayIntoStringBuf(int[] ia,
java.lang.StringBuffer sb,
boolean useHex)
For use in toString: Append int array contents to stringbuffer, formatted as "{ 1 2 3 4 5 }". |
protected static void |
enumIntoStringBuf(java.util.Enumeration<java.lang.String> se,
java.lang.StringBuffer sb)
For use in toString: Append string enum contents to stringbuffer, formatted as "a,b,c,d,e". |
java.lang.String |
getClassNameShort()
Utility, get the short simple name of the class: SOCResetBoardVote, not soc.message.SOCResetBoardVote |
int |
getMaximumVersion()
To identify obsolete message types, give the maximum version where this type is used. |
int |
getMinimumVersion()
To identify new message types, give the minimum version where this type is used. |
int |
getType()
|
static boolean |
isSingleLineAndSafe(java.lang.String s)
Test whether a string is non-empty and its characters are all 'safe' as a single-line string: No newlines or control characters ,
no line separators or paragraph separators . |
static boolean |
isSingleLineAndSafe(java.lang.String s,
boolean allowSepChars)
Variant of isSingleLineAndSafe(String) that can optionally
allow sep_char or sep2_char . |
abstract java.lang.String |
toCmd()
Converts the contents of this message into a String that can be transferred by a client or server. |
static SOCMessage |
toMsg(java.lang.String s)
Convert a string into a SOCMessage. |
abstract java.lang.String |
toString()
Simple human-readable representation, used for debug purposes. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
private static final long serialVersionUID
public static final int AUTHREQUEST
SOCAuthRequest
.
public static final int NULLMESSAGE
public static final int NEWCHANNEL
public static final int MEMBERS
public static final int CHANNELS
public static final int JOIN
public static final int TEXTMSG
public static final int LEAVE
public static final int DELETECHANNEL
public static final int LEAVEALL
public static final int PUTPIECE
public static final int GAMETEXTMSG
SOCGameTextMsg
- Game text from players.
Before v2.0.00, messages from the server also used this type.
In 2.0.00 and later, text from the server is GAMESERVERTEXT
instead.
public static final int LEAVEGAME
public static final int SITDOWN
public static final int JOINGAME
public static final int BOARDLAYOUT
public static final int DELETEGAME
public static final int NEWGAME
public static final int GAMEMEMBERS
public static final int STARTGAME
public static final int GAMES
public static final int JOINAUTH
public static final int JOINGAMEAUTH
public static final int IMAROBOT
public static final int ROBOTJOINGAMEREQUEST
public static final int PLAYERELEMENT
public static final int GAMESTATE
public static final int TURN
public static final int SETUPDONE
public static final int DICERESULT
public static final int DISCARDREQUEST
public static final int ROLLDICEREQUEST
public static final int ROLLDICE
public static final int ENDTURN
public static final int DISCARD
public static final int MOVEROBBER
public static final int CHOOSEPLAYER
public static final int CHOOSEPLAYERREQUEST
public static final int REJECTOFFER
public static final int CLEAROFFER
public static final int ACCEPTOFFER
public static final int BANKTRADE
public static final int MAKEOFFER
public static final int CLEARTRADEMSG
public static final int BUILDREQUEST
public static final int CANCELBUILDREQUEST
public static final int BUYCARDREQUEST
public static final int DEVCARDACTION
SOCDevCardAction
message; before v2.0.00, this type was DEVCARD
(class name SOCDevCard
).
public static final int DEVCARDCOUNT
public static final int SETPLAYEDDEVCARD
public static final int PLAYDEVCARDREQUEST
public static final int DISCOVERYPICK
public static final int MONOPOLYPICK
public static final int FIRSTPLAYER
public static final int SETTURN
public static final int ROBOTDISMISS
public static final int POTENTIALSETTLEMENTS
public static final int CHANGEFACE
public static final int REJECTCONNECTION
public static final int LASTSETTLEMENT
public static final int GAMESTATS
public static final int BCASTTEXTMSG
public static final int RESOURCECOUNT
public static final int ADMINPING
public static final int ADMINRESET
public static final int LONGESTROAD
public static final int LARGESTARMY
public static final int SETSEATLOCK
public static final int STATUSMESSAGE
public static final int CREATEACCOUNT
public static final int UPDATEROBOTPARAMS
public static final int ROLLDICEPROMPT
public static final int RESETBOARDREQUEST
public static final int RESETBOARDAUTH
public static final int RESETBOARDVOTEREQUEST
public static final int RESETBOARDVOTE
public static final int RESETBOARDREJECT
public static final int NEWGAMEWITHOPTIONSREQUEST
public static final int NEWGAMEWITHOPTIONS
public static final int GAMEOPTIONGETDEFAULTS
public static final int GAMEOPTIONGETINFOS
public static final int GAMEOPTIONINFO
public static final int GAMESWITHOPTIONS
public static final int BOARDLAYOUT2
public static final int PLAYERSTATS
public static final int PLAYERELEMENTS
public static final int DEBUGFREEPLACE
public static final int TIMINGPING
public static final int SIMPLEREQUEST
SOCSimpleRequest
- Generic message type for simple requests by players.
public static final int SIMPLEACTION
SOCSimpleAction
- Generic message type for simple actions for players.
public static final int GAMESERVERTEXT
SOCGameServerText
- Game text announcements from the server.
Before v2.0.00, server text announcements were sent as GAMETEXTMSG
just like player chat messages.
public static final int DICERESULTRESOURCES
SOCDiceResultResources
- All resources gained by players from a dice roll.
Before v2.0.00, these were sent as SOCPlayerElement(GAIN)
and GAMETEXTMSG
.
public static final int MOVEPIECEREQUEST
MOVEPIECE
if okay.
public static final int MOVEPIECE
MOVEPIECEREQUEST
.
public static final int REMOVEPIECE
SOCRemovePiece
- Remove a piece from the board; currently used only with ships.
public static final int PICKRESOURCESREQUEST
PICKRESOURCES
.
public static final int PICKRESOURCES
PICKRESOURCESREQUEST
.
Has picked these resource types/counts.
public static final int REVEALFOGHEX
public static final int PIECEVALUE
public static final int LEGALEDGES
public static final int SVPTEXTMSG
SOCPlayerElement
with the SVP total.
public static final int BOARDSPECIALEDGE
SOCBoardSpecialEdge
).
Used in some game scenarios.
public static final int INVENTORYITEMACTION
SOCInventoryItemAction
message: Add or remove a SOCInventoryItem
(excluding SOCDevCard
s) from a player's inventory.
Used in some game scenarios.
DEVCARDACTION
,
Constant Field Valuespublic static final int SETSPECIALITEM
SOCSetSpecialItem
- Special Item requests and change announcements.
SOCSpecialItem
s are used in some game scenarios.
public static final int LOCALIZEDSTRINGS
SOCLocalizedStrings
- Localized i18n strings for items such as game options or scenarios.
public static final int SCENARIOINFO
SOCScenarioInfo
- Client's request about available SOCScenario
s,
or server's reply about a single scenario.
public static final int VERSION
public static final int SERVERPING
public static final java.lang.String sep
SOCMessageMulti
.
SEP is "|".
public static final java.lang.String sep2
public static final char sep_char
sep
, as character. SEP is '|'.
public static final char sep2_char
sep2
, as character. SEP2 is ','.
public static final java.lang.String GAME_NONE
SOCMessageTemplate*
message types
(which all implement SOCMessageForGame
) are used for convenience for non-game messages
such as SOCLocalizedStrings
.
No actual game, option, or scenario will ever have the same name as this marker, because the marker fails
isSingleLineAndSafe(String, false)
by
including a control character.
protected int messageType
Constructor Detail |
---|
public SOCMessage()
Method Detail |
---|
public int getType()
public int getMinimumVersion()
When overriding, write the entire method on a single line for easier visibility of the version when searching the source code.
public int getMaximumVersion()
Integer.MAX_VALUE
.
Integer.MAX_VALUE
.public abstract java.lang.String toCmd()
For most message types, at most one sep
token is allowed,
separating the type ID from the rest of the parameters.
For multi-messages (@link SOCMessageMulti}, multiple sep
tokens
are allowed. Multi-messages are parsed with:
static SOCMessageSubclass parseDataStr(String[])
public abstract java.lang.String toString()
toString
in class java.lang.Object
protected static void arrayIntoStringBuf(int[] ia, java.lang.StringBuffer sb, boolean useHex) throws java.lang.NullPointerException
ia
- int array to append. 0 length is allowed, null is not.sb
- StringBuffer to which ia will be appended, as "{ 1 2 3 4 5 }"useHex
- If true, append ia as hexidecimal strings.
Uses Integer.toHexString(int)
after checking the sign bit.
(Added in 2.0.00)
java.lang.NullPointerException
- if ia or sb is nullprotected static void enumIntoStringBuf(java.util.Enumeration<java.lang.String> se, java.lang.StringBuffer sb) throws java.lang.ClassCastException, java.lang.NullPointerException
se
- Enum of String to append. 0 length is allowed, null is not allowed.sb
- StringBuffer to which se will be appended, as "a,b,c,d,e"
java.lang.ClassCastException
- if se.nextElement() returns non-String
java.lang.NullPointerException
- if se or sb is nullpublic java.lang.String getClassNameShort()
public static final boolean isSingleLineAndSafe(java.lang.String s)
control characters
,
no line separators or paragraph separators
.
Whitespace character type Character.SPACE_SEPARATOR
is OK.
Must not contain sep_char
or sep2_char
.
s
- string to test; if null, returns false.
isSingleLineAndSafe(String, boolean)
public static final boolean isSingleLineAndSafe(java.lang.String s, boolean allowSepChars)
isSingleLineAndSafe(String)
that can optionally
allow sep_char
or sep2_char
.
See that method for other conditions checked here.
s
- string to test; if null, returns false.allowSepChars
- If true, string can contain sep_char
or sep2_char
public static SOCMessage toMsg(java.lang.String s)
s
- String to convert
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |