Main Page   Class Hierarchy   Compound List   File List   Compound Members  

MessagePacket Class Reference

Message Packet. More...

#include <messagepacket.h>

List of all members.

Public Methods

 MessagePacket ()
 Creates an empty writable MessagePacket.

 MessagePacket (UDPpacket &src)
 Creates a readable MessagePacket filled with the contents of the UDPpacket.

void append (string newMsg)
 Appends a message to the packet. More...

void append (const MessagePacket &msgPacket)
 Appends two MessagePacket. More...

void clear ()
 Empties the message packet. More...

string next ()
 Returns the next message. More...

bool remainingMessages () const
 Tells if there are still some messages in the packet. More...

bool writable () const
 Indicates if we can write to this MessagePacket. More...

bool readable () const
 Indicates if we can read from this MessagePacket. More...

int size () const
 Returns the size in bytes of the message data. More...

int packetSize () const
 Returns the size in bytes of the whole message packet. More...

const char * getRawData () const
 Returns the string containing the whole bunch of data. More...

void print () const
 Useful for debugging.

void setClientIndex (Sint32 index)
 Sets the client index of the packet. More...

Sint32 getClientIndex () const
 Gets the client index of the packet sender. More...


Private Attributes

string msgList
 Messages are appended to the end of the string, separated by the magic string defined in SEPARATOR, which I consider is pretty unlikely to appear later during the game in a regular message.

bool _writable
 Indicates whether we can or cannot write to this MessagePacket.

unsigned pointer
 When reading, indicates the position of the next message in the list.


Static Private Attributes

const string SEPARATOR = string("$}")
 String that separates the different messages in the packet.

const int HEADER_LENGTH = sizeof(Uint32) + sizeof(Sint32)
 Length of the information before the actual data.


Detailed Description

Message Packet.

These are the messages to be sent over the network The network module doesn't understand about the format of the message string, just delivers it


Member Function Documentation

void MessagePacket::append const MessagePacket &    msgPacket
 

Appends two MessagePacket.

Appends another message packet to the end of this packet, perhaps making some optimizations in order to reduce information redundancy. Throws an string as the result of an exception if "this" is in read mode.

Parameters:
newMsg  the message to be appended

void MessagePacket::append string    newMsg
 

Appends a message to the packet.

Appends another message to the end of the packet. Throws an string as the result of an exception if "this" is in read mode.

Parameters:
newMsg  the message to be appended.

void MessagePacket::clear  
 

Empties the message packet.

Empties the message packet. Throws an string as the result of an exception if "this" is in read mode.

Sint32 MessagePacket::getClientIndex   const
 

Gets the client index of the packet sender.

Gets the client index of the packet sender, to facilitate its management in the server.

Returns:
the index indicating the index of the client that sends the MessagePacket.

const char* MessagePacket::getRawData   const [inline]
 

Returns the string containing the whole bunch of data.

This is supposed to be used by the NetManager.

Returns:
a constant string containing the actual data to be sent.

string MessagePacket::next  
 

Returns the next message.

Returns the next message to be read, and advances the pointer. Throws an exception if there are no more messages left.

Returns:
a string object containing the text of the read message.

int MessagePacket::packetSize   const [inline]
 

Returns the size in bytes of the whole message packet.

Returns:
the length of the data string, containing headers, etc.

bool MessagePacket::readable   const [inline]
 

Indicates if we can read from this MessagePacket.

Indicates whether we can or cannot read from this MessagePacket. Notice that we cannot read from and write to a MessagePacket at the same time.

Returns:
true if we can read from the packet; false otherwise.

bool MessagePacket::remainingMessages   const
 

Tells if there are still some messages in the packet.

Returns:
true if there are still messages, false otherwise.

void MessagePacket::setClientIndex Sint32    index
 

Sets the client index of the packet.

Sets the client index of the packet, to facilitate its management in the server.

Parameters:
index  indicates the index of the client that sends the MessagePacket.

int MessagePacket::size   const [inline]
 

Returns the size in bytes of the message data.

Returns:
the length of the relevant part of the data string, not containing headers, etc.

bool MessagePacket::writable   const [inline]
 

Indicates if we can write to this MessagePacket.

Indicates whether we can or cannot write to this MessagePacket. Notice that we cannot read from and write to a MessagePacket at the same time.

Returns:
true if we can write to the packet; false otherwise.


The documentation for this class was generated from the following files:
Generated on Thu Jun 6 17:22:22 2002 for Perihelion by doxygen1.2.15