UTRemoteBot::UTMessage Class Reference

The UTMessage class represents either a bot or vizualizer message from/to the server. It handles all of the nasty parsing that must be done on the messages and allows classes using messages to obtain their contents via a few different accessors. Each accessors assumes that the user of this class knows what kind of data they need from the attribute they are requesting and so they can call the correct method. More...

List of all members.

Public Member Functions

 UTMessage (string message)
 Constructor: Saves the original message, verifies matching brackets, sets the completeness indicator, and does the main parsing of the message. If the message isn't complete, messageContents and messageKeys should be set to NONE so that they don't crash anything since they could have no values.
override string ToString ()
 Override for the System.Object ToString message.
string GetStringValue (string key)
 The the value of a key as a string.
string[] GetSublistKeys (string sublist)
 The keys of a sublist (for instance PlayerScores for individual players in a UTMessage.GAME message) are obtained as a string array. A sublist will end whenever we get a closing } that has been left in the list assuming the algorithm for parsing is the same as mentioned in the parsing algorithm.

If there are no keys, a UTAttributeTypeException should be thrown. It is on the head of the people who call this class to catch it. The message should read: "Error: programmer has misused getSublistKeys in the UTMessage class."

UTVector GetVector3Value (string key)
 This is useful for methods that need to obtain the location, velocity, and other 3d values from a message. They will all be returned as floats. This method will throw a UTAttributeTypeException if the key doesn't have 3 floats attached as values to it. The error message for this exception is: "Error: programmer has misused getVector3Value in the UTMessage class.".
int GetIntValue (string key)
 Obtain an integer value from a specific key name in the message. An example of an integer value would be score. This method will throw a UTAttributeTypeException if the value cannont be interpreted as an integer. The error message for this will be: "Error: programmer has misused getIntValue in the UTMessage class.".
bool GetBoolValue (string key)
float GetFloatValue (string key)
 Obtain a float value from a specific key name in the message. This method will throw a UTAttributeTypeException if the value cannont be interpreted as an integer. The error message for this will be: "Error: programmer has misused getFloatValue in the UTMessage class.".
bool IsProperMessage ()
 Let's the caller know if a message internal to this object is actually formatted correctly for sending/receiving.
virtual void SetMessage (string message)
 This method allows us to reuse the UTMessage objects instead of always having to create new ones whenever we want new messages. The class clobbers the old string message with a new one and parses/checks the new message in a similar manny to what happens when the class is created.
bool IsType (string type)
 Checks to see if two message types are the same.

Public Attributes

const string BEGIN = "BEG"
 Beginning of a synchronous message set.
const string PLAYER = "PLR"
 A message about an opponent player that is being seen.
const string NAVIGATION = "NAV"
 A message about a navigation point that is within view.
const string INVENTORY = "INV"
 A message about an inventory point that is within view.
const string DOMINATION = "DOM"
 A message about a domination point within view.
const string FLAG = "FLG"
 A message about a flag within view for a capture the flag game.
const string MOVER = "MOV"
 A mover has been sited.
const string SELF = "SLF"
 A self message containing information about the current bot information.
const string GAME = "GAM"
 Game messages contain information about the current game.
const string END = "END"
 The end of a set of synchronous messages.
const string DUPLICATE_NAME = "DUP"
 This bot has the same name as one currently in the game.
const string INFO = "NFO"
 A starting information message.
const string WALL = "WAL"
 The bot has bumped into a wall head on.
const string BUMP = "BMP"
 The bot has bumped another bot.
const string PROJECTILE = "PRJ"
 The bot has an incoming projectile.
const string DAMAGE = "DAM"
 The bot has taken damage.
const string DIE = "DIE"
 The bot has just died.
const string KILL = "KIL"
 The opponent has just died.
const string FINISHED = "FIN"
 The game has finished. Another could start shortly.
const string PONG = "PONG"
 Pong is the received message from the server after a "ping" is sent by the client.
const string FALL = "FALL"
 The bot hit a dropoff.
const string ADDED_INVENTORY = "AIN"
 The bot just picked something up.
const string GLOBAL_CHAT_RCV = "VMS"
 Received for any message broadcast on the global chat channel.
const string TEAM_CHAT_RCV = "VMT"
 Received for any message sent on the team chat channel.
const string TOKENIZED_MSG_RCV = "VMG"
 Received for any message sent to another player.
const string FOOT_CHANGED_ZONES = "ZCF"
 The bot's foot changed zones.
const string HEAD_CHANGED_ZONES = "ZCH"
 The bot's head changed zones.
const string BOT_CHANGED_ZONES = "ZCB"
 The whole bot changed zones.
const string CHANGED_WEAPON = "CWP"
 The bot changed weapons.
const string HEAR_PICKUP = "HRP"
 Something was picked up by another bot and this bot heard it. Very rarely heard.
const string HEAR_NOISE = "HRN"
 The bot heard another bot. Very rare for this to happen.
const string HIT = "HIT"
 Another player has been hurt.
const string PATH_NODES = "PTH"
 A string of path nodes that your bot can travel to get from one location to another. Received after asking for a path to a particular node.
const string GET_PATH = "GETPATH"
 Get a path to a particular node.
const string CHECK_REACH = "RCH"
 Check the reachability of a node from this particular location. Reachability is done with a line-of-site check and so may have some problems for a bot who actually wants to get there.
const string NONE = "NONE"
const string PING = "PING"
 Ping is sent to a server in order to make sure a connection is working correctly.
const string MESSAGE = "MESSAGE"
 We want to send out a chat message.
const string INITIALIZE = "INIT"
 The client wants to initialize connecting it's bot to the server.
const string SETWALK = "SETWALK"
 The client wants to set whether the bot is walking or running. Give with the argument of true for walking and anything else for running.
const string JUMP = "JUMP"
 The client wants the bot to jump.
const string STRAFE = "STRAFE"
 The client wants the strafe in a particular direction.
const string SHOOT = "SHOOT"
 The client wants start shooting at something.
const string STOPSHOOT = "STOPSHOOT"
 The client wants stop shooting at something.
const string CHANGEWEAPON = "CHANGEWEAPON"
 The client wants change the bot's weapon.
const string CHECKREACH = "CHECKREACH"
 The client wants change the bot's weapon.
const string STOP = "STOP"
 The client wants to stop all movement of the bot.
const string RUNTO = "RUNTO"
 The bot wants to run somewhere.
const string ROTATE = "ROTATE"
 The bot wants to turn. Remember that if too many turn commands are sent at once, nothing will happen as the bot needs time to react.
const string TURNTO = "TURNTO"
 Another version of rotating.
const string LOCATION = "LOCATION"
 Attribute for location in x,y, and z coordinates.
const string ROTATION = "ROTATION"
 Attribute for rotation in roll, pitch, and yaw coordinates.
const string VELOCITY = "VELOCITY"
 Attribute for velocity in x, y, and z directions.
const string ID = "ID"
 The bots ID. This should be different from a bots name.
const string REACHABLE = "REACHABLE"
 Contains information about whether or not this node is reachable.
const string MSGCLASS = "CLASS"
 Message class. Not often used.
const string TEAM = "TEAM"
 Team information.
const string NAME = "NAME"
 The bot name given by a client.
const string WEAPON = "WEAPON"
 The current weapon.
const string HEALTH = "HEALTH"
 The current health.
const string ARMOR = "ARMOR"
 The current armor.
const string AMMO = "CURRENTAMMO"
 The current ammo.
const string AGENT_KILLER = "KILLER"
 The agent killer. Not really used.
const string AGENT_KILLER_DAMAGE_TYPE = "DAMAGETYPE"
 The agent killed damage type. Not really used.
const string TARGET = "TARGET"
 The target for attacks.
const int TEAM_RED = 0
 The red team in the game.
const int TEAM_BLUE = 1
 The blue team in the game.
const int TEAM_GREEN = 2
 The green team in the game.
const int TEAM_GOLD = 3
 The gold team in the game.
const int DONT_CARE = 255
 For games without teams or those who really don't care.

Protected Attributes

string[] messageKeys = null
 An array of keys that represent everything that follows a { in a message. These can be considered the names of data in a message.
string[] messageContents = null
 The contents associated with each key. Note that where there are contents within contents, they will exist as extra pieces of data in line rather than a nested structure in the array.
bool isSynch = true
 We have synchronous (game info) and asynchronous (somebody died) info messages from the server. Most messages are synchronous and so isSynch starts out as true.

Properties

bool IsSynchronous
 Need to see if a message is synchronous.
string MessageType
 The message type of the name.
string[] Keys
string[] Values

Private Member Functions

void CleanContents ()
bool VerifyMatchingBrackets (string message)
 Counts brackets and makes sure they match. Sets the complete variable to true if the brackets match. Using the ToCharArray method of the string class may be helpful for this method.
void PreParseMessage (string message)
 Sets the type of the message and takes the main attributes of it and hands them off to be parsed. The way this is done in the answer (you can do it however you want as long as you document the algorithm) is that a Regex object is used with UTMessage.DELIMITER for its string in creation. This object is then used to Split the message into an array of strings based on when the "{" is seen since it always precedes a new piece/keyword in the message. The keywords are kept in a string array separate from the values that they have. All are stored as strings to make things easy at this end. Ending spaces and "}"'s are stripped off except the ending "}" that occurs in multi-part keywords where the actual keyword has a whole body of {}'s inside of it with no value. The fact that multi-part keywords will have a value of NONE and the sublist of the keyword will end with a "}" means that we can get various sublists relatively easily.
void SetSynchronous ()
 Sets up whether isSynch is true or false depending on the type of the message. This method must be called whenever the messageName gets set.
string CleanEndings (string message)
 If the parsing method used above is used, it becomes necessary to strip the ending } values before trying to return the attribute/vale before the ending } of sublists. It should not be stripped off of the source message, but needs to be stripped before the attributes/values are returned to a caller.

Private Attributes

string messageName = NONE
 All messages have a name. The name is equivalent to the type of the message such as GAM or FIN. Initially, all message names should be set to NONE.
string originalMessage = ""
 The original string message. Useful when we want to dump printed information about a message. This message will be kept up-to-date with the rest of the message structure.
const string DELIMITER = "{"
 The delimiter for a message. This can be set on the server side.
bool complete = false
 Since we don't check for completeness of the message before this object is created, we'll note it inside the object - false means something's missing.


Detailed Description

The UTMessage class represents either a bot or vizualizer message from/to the server. It handles all of the nasty parsing that must be done on the messages and allows classes using messages to obtain their contents via a few different accessors. Each accessors assumes that the user of this class knows what kind of data they need from the attribute they are requesting and so they can call the correct method.


Constructor & Destructor Documentation

UTRemoteBot::UTMessage::UTMessage string  message  )  [inline]
 

Constructor: Saves the original message, verifies matching brackets, sets the completeness indicator, and does the main parsing of the message. If the message isn't complete, messageContents and messageKeys should be set to NONE so that they don't crash anything since they could have no values.

Parameters:
message A string message from the server.


Member Function Documentation

void UTRemoteBot::UTMessage::CleanContents  )  [inline, private]
 

string UTRemoteBot::UTMessage::CleanEndings string  message  )  [inline, private]
 

If the parsing method used above is used, it becomes necessary to strip the ending } values before trying to return the attribute/vale before the ending } of sublists. It should not be stripped off of the source message, but needs to be stripped before the attributes/values are returned to a caller.

Parameters:
message The attribute we are trying to clean up.
Returns:
A cleaned string value.

bool UTRemoteBot::UTMessage::GetBoolValue string  key  )  [inline]
 

float UTRemoteBot::UTMessage::GetFloatValue string  key  )  [inline]
 

Obtain a float value from a specific key name in the message. This method will throw a UTAttributeTypeException if the value cannont be interpreted as an integer. The error message for this will be: "Error: programmer has misused getFloatValue in the UTMessage class.".

Parameters:
key The name of the attribute that should have a float value.
Returns:
The floating point value associated with a key for a string.

int UTRemoteBot::UTMessage::GetIntValue string  key  )  [inline]
 

Obtain an integer value from a specific key name in the message. An example of an integer value would be score. This method will throw a UTAttributeTypeException if the value cannont be interpreted as an integer. The error message for this will be: "Error: programmer has misused getIntValue in the UTMessage class.".

Parameters:
key The name of the attribute that should have an integer value.
Returns:
The integer value associated with a key for a string.

string UTRemoteBot::UTMessage::GetStringValue string  key  )  [inline]
 

The the value of a key as a string.

Parameters:
key The string name of the key that we want to get the value information from. For example: UTMessage.ROTATION
Returns:
The string value of the key or NONE if there are none. Note that for attributes within attributes the top level one will return NONE, meaning that the subattributes should be looked up by themselves. Getting a string should never throw a type error since all messages are really strings underneath.

string [] UTRemoteBot::UTMessage::GetSublistKeys string  sublist  )  [inline]
 

The keys of a sublist (for instance PlayerScores for individual players in a UTMessage.GAME message) are obtained as a string array. A sublist will end whenever we get a closing } that has been left in the list assuming the algorithm for parsing is the same as mentioned in the parsing algorithm.

If there are no keys, a UTAttributeTypeException should be thrown. It is on the head of the people who call this class to catch it. The message should read: "Error: programmer has misused getSublistKeys in the UTMessage class."

Parameters:
sublist Get the sub-keys of a parent key for attributes with lists of attributes.
Returns:
A string array containing the sub-keys.

UTVector UTRemoteBot::UTMessage::GetVector3Value string  key  )  [inline]
 

This is useful for methods that need to obtain the location, velocity, and other 3d values from a message. They will all be returned as floats. This method will throw a UTAttributeTypeException if the key doesn't have 3 floats attached as values to it. The error message for this exception is: "Error: programmer has misused getVector3Value in the UTMessage class.".

Parameters:
key The name of a key with a vector of values (like UTMessage.LOCATION)
Returns:
A DirectX Vector3. The default value of this vector is all -1's

bool UTRemoteBot::UTMessage::IsProperMessage  )  [inline]
 

Let's the caller know if a message internal to this object is actually formatted correctly for sending/receiving.

Returns:
true if the message is properly formatted with {}'s and false otherwise

bool UTRemoteBot::UTMessage::IsType string  type  )  [inline]
 

Checks to see if two message types are the same.

Parameters:
type The type to check this message against.
Returns:
True if they are the same and false otherwise.

void UTRemoteBot::UTMessage::PreParseMessage string  message  )  [inline, private]
 

Sets the type of the message and takes the main attributes of it and hands them off to be parsed. The way this is done in the answer (you can do it however you want as long as you document the algorithm) is that a Regex object is used with UTMessage.DELIMITER for its string in creation. This object is then used to Split the message into an array of strings based on when the "{" is seen since it always precedes a new piece/keyword in the message. The keywords are kept in a string array separate from the values that they have. All are stored as strings to make things easy at this end. Ending spaces and "}"'s are stripped off except the ending "}" that occurs in multi-part keywords where the actual keyword has a whole body of {}'s inside of it with no value. The fact that multi-part keywords will have a value of NONE and the sublist of the keyword will end with a "}" means that we can get various sublists relatively easily.

Parameters:
message The original message that needs to be parsed.

virtual void UTRemoteBot::UTMessage::SetMessage string  message  )  [inline, virtual]
 

This method allows us to reuse the UTMessage objects instead of always having to create new ones whenever we want new messages. The class clobbers the old string message with a new one and parses/checks the new message in a similar manny to what happens when the class is created.

Parameters:
message A valid UT string message.

void UTRemoteBot::UTMessage::SetSynchronous  )  [inline, private]
 

Sets up whether isSynch is true or false depending on the type of the message. This method must be called whenever the messageName gets set.

override string UTRemoteBot::UTMessage::ToString  )  [inline]
 

Override for the System.Object ToString message.

Returns:
The original string message.

bool UTRemoteBot::UTMessage::VerifyMatchingBrackets string  message  )  [inline, private]
 

Counts brackets and makes sure they match. Sets the complete variable to true if the brackets match. Using the ToCharArray method of the string class may be helpful for this method.

Parameters:
message A string message to check correctness of
Returns:
true or false


Member Data Documentation

const string UTRemoteBot::UTMessage::ADDED_INVENTORY = "AIN"
 

The bot just picked something up.

const string UTRemoteBot::UTMessage::AGENT_KILLER = "KILLER"
 

The agent killer. Not really used.

const string UTRemoteBot::UTMessage::AGENT_KILLER_DAMAGE_TYPE = "DAMAGETYPE"
 

The agent killed damage type. Not really used.

const string UTRemoteBot::UTMessage::AMMO = "CURRENTAMMO"
 

The current ammo.

const string UTRemoteBot::UTMessage::ARMOR = "ARMOR"
 

The current armor.

const string UTRemoteBot::UTMessage::BEGIN = "BEG"
 

Beginning of a synchronous message set.

const string UTRemoteBot::UTMessage::BOT_CHANGED_ZONES = "ZCB"
 

The whole bot changed zones.

const string UTRemoteBot::UTMessage::BUMP = "BMP"
 

The bot has bumped another bot.

const string UTRemoteBot::UTMessage::CHANGED_WEAPON = "CWP"
 

The bot changed weapons.

const string UTRemoteBot::UTMessage::CHANGEWEAPON = "CHANGEWEAPON"
 

The client wants change the bot's weapon.

const string UTRemoteBot::UTMessage::CHECK_REACH = "RCH"
 

Check the reachability of a node from this particular location. Reachability is done with a line-of-site check and so may have some problems for a bot who actually wants to get there.

const string UTRemoteBot::UTMessage::CHECKREACH = "CHECKREACH"
 

The client wants change the bot's weapon.

bool UTRemoteBot::UTMessage::complete = false [private]
 

Since we don't check for completeness of the message before this object is created, we'll note it inside the object - false means something's missing.

const string UTRemoteBot::UTMessage::DAMAGE = "DAM"
 

The bot has taken damage.

const string UTRemoteBot::UTMessage::DELIMITER = "{" [private]
 

The delimiter for a message. This can be set on the server side.

const string UTRemoteBot::UTMessage::DIE = "DIE"
 

The bot has just died.

const string UTRemoteBot::UTMessage::DOMINATION = "DOM"
 

A message about a domination point within view.

const int UTRemoteBot::UTMessage::DONT_CARE = 255
 

For games without teams or those who really don't care.

const string UTRemoteBot::UTMessage::DUPLICATE_NAME = "DUP"
 

This bot has the same name as one currently in the game.

const string UTRemoteBot::UTMessage::END = "END"
 

The end of a set of synchronous messages.

const string UTRemoteBot::UTMessage::FALL = "FALL"
 

The bot hit a dropoff.

const string UTRemoteBot::UTMessage::FINISHED = "FIN"
 

The game has finished. Another could start shortly.

const string UTRemoteBot::UTMessage::FLAG = "FLG"
 

A message about a flag within view for a capture the flag game.

const string UTRemoteBot::UTMessage::FOOT_CHANGED_ZONES = "ZCF"
 

The bot's foot changed zones.

const string UTRemoteBot::UTMessage::GAME = "GAM"
 

Game messages contain information about the current game.

const string UTRemoteBot::UTMessage::GET_PATH = "GETPATH"
 

Get a path to a particular node.

const string UTRemoteBot::UTMessage::GLOBAL_CHAT_RCV = "VMS"
 

Received for any message broadcast on the global chat channel.

const string UTRemoteBot::UTMessage::HEAD_CHANGED_ZONES = "ZCH"
 

The bot's head changed zones.

const string UTRemoteBot::UTMessage::HEALTH = "HEALTH"
 

The current health.

const string UTRemoteBot::UTMessage::HEAR_NOISE = "HRN"
 

The bot heard another bot. Very rare for this to happen.

const string UTRemoteBot::UTMessage::HEAR_PICKUP = "HRP"
 

Something was picked up by another bot and this bot heard it. Very rarely heard.

const string UTRemoteBot::UTMessage::HIT = "HIT"
 

Another player has been hurt.

const string UTRemoteBot::UTMessage::ID = "ID"
 

The bots ID. This should be different from a bots name.

const string UTRemoteBot::UTMessage::INFO = "NFO"
 

A starting information message.

const string UTRemoteBot::UTMessage::INITIALIZE = "INIT"
 

The client wants to initialize connecting it's bot to the server.

const string UTRemoteBot::UTMessage::INVENTORY = "INV"
 

A message about an inventory point that is within view.

bool UTRemoteBot::UTMessage::isSynch = true [protected]
 

We have synchronous (game info) and asynchronous (somebody died) info messages from the server. Most messages are synchronous and so isSynch starts out as true.

const string UTRemoteBot::UTMessage::JUMP = "JUMP"
 

The client wants the bot to jump.

const string UTRemoteBot::UTMessage::KILL = "KIL"
 

The opponent has just died.

const string UTRemoteBot::UTMessage::LOCATION = "LOCATION"
 

Attribute for location in x,y, and z coordinates.

const string UTRemoteBot::UTMessage::MESSAGE = "MESSAGE"
 

We want to send out a chat message.

string [] UTRemoteBot::UTMessage::messageContents = null [protected]
 

The contents associated with each key. Note that where there are contents within contents, they will exist as extra pieces of data in line rather than a nested structure in the array.

string [] UTRemoteBot::UTMessage::messageKeys = null [protected]
 

An array of keys that represent everything that follows a { in a message. These can be considered the names of data in a message.

string UTRemoteBot::UTMessage::messageName = NONE [private]
 

All messages have a name. The name is equivalent to the type of the message such as GAM or FIN. Initially, all message names should be set to NONE.

const string UTRemoteBot::UTMessage::MOVER = "MOV"
 

A mover has been sited.

const string UTRemoteBot::UTMessage::MSGCLASS = "CLASS"
 

Message class. Not often used.

const string UTRemoteBot::UTMessage::NAME = "NAME"
 

The bot name given by a client.

const string UTRemoteBot::UTMessage::NAVIGATION = "NAV"
 

A message about a navigation point that is within view.

const string UTRemoteBot::UTMessage::NONE = "NONE"
 

string UTRemoteBot::UTMessage::originalMessage = "" [private]
 

The original string message. Useful when we want to dump printed information about a message. This message will be kept up-to-date with the rest of the message structure.

const string UTRemoteBot::UTMessage::PATH_NODES = "PTH"
 

A string of path nodes that your bot can travel to get from one location to another. Received after asking for a path to a particular node.

const string UTRemoteBot::UTMessage::PING = "PING"
 

Ping is sent to a server in order to make sure a connection is working correctly.

const string UTRemoteBot::UTMessage::PLAYER = "PLR"
 

A message about an opponent player that is being seen.

const string UTRemoteBot::UTMessage::PONG = "PONG"
 

Pong is the received message from the server after a "ping" is sent by the client.

const string UTRemoteBot::UTMessage::PROJECTILE = "PRJ"
 

The bot has an incoming projectile.

const string UTRemoteBot::UTMessage::REACHABLE = "REACHABLE"
 

Contains information about whether or not this node is reachable.

const string UTRemoteBot::UTMessage::ROTATE = "ROTATE"
 

The bot wants to turn. Remember that if too many turn commands are sent at once, nothing will happen as the bot needs time to react.

const string UTRemoteBot::UTMessage::ROTATION = "ROTATION"
 

Attribute for rotation in roll, pitch, and yaw coordinates.

const string UTRemoteBot::UTMessage::RUNTO = "RUNTO"
 

The bot wants to run somewhere.

const string UTRemoteBot::UTMessage::SELF = "SLF"
 

A self message containing information about the current bot information.

const string UTRemoteBot::UTMessage::SETWALK = "SETWALK"
 

The client wants to set whether the bot is walking or running. Give with the argument of true for walking and anything else for running.

const string UTRemoteBot::UTMessage::SHOOT = "SHOOT"
 

The client wants start shooting at something.

const string UTRemoteBot::UTMessage::STOP = "STOP"
 

The client wants to stop all movement of the bot.

const string UTRemoteBot::UTMessage::STOPSHOOT = "STOPSHOOT"
 

The client wants stop shooting at something.

const string UTRemoteBot::UTMessage::STRAFE = "STRAFE"
 

The client wants the strafe in a particular direction.

const string UTRemoteBot::UTMessage::TARGET = "TARGET"
 

The target for attacks.

const string UTRemoteBot::UTMessage::TEAM = "TEAM"
 

Team information.

const int UTRemoteBot::UTMessage::TEAM_BLUE = 1
 

The blue team in the game.

const string UTRemoteBot::UTMessage::TEAM_CHAT_RCV = "VMT"
 

Received for any message sent on the team chat channel.

const int UTRemoteBot::UTMessage::TEAM_GOLD = 3
 

The gold team in the game.

const int UTRemoteBot::UTMessage::TEAM_GREEN = 2
 

The green team in the game.

const int UTRemoteBot::UTMessage::TEAM_RED = 0
 

The red team in the game.