00001 #ifdef _MSC_VER // if the compiler is from Microsoft 00002 #pragma warning(disable:4786) 00003 #endif 00004 00005 #include <string> 00006 #include <SDL_net.h> 00007 00008 using namespace std; 00009 00010 // $$$ Needed features: 00011 // - Somehow add the sequence number to the message 00012 // - If we think it is useful, provide a smart 'append' 00013 // method that removes redundant info and compacts the data to be sent 00014 00021 class MessagePacket 00022 { 00023 public: 00027 MessagePacket(); 00028 00032 MessagePacket(UDPpacket& src); 00033 00040 void append(string newMsg); 00041 00049 void append(const MessagePacket& msgPacket); 00050 00056 void clear(); 00057 00064 string next(); 00065 00070 bool remainingMessages() const; 00071 00078 bool writable() const {return _writable;}; 00079 00086 bool readable() const {return ! _writable;}; 00087 00092 int size() const {return msgList.size() - HEADER_LENGTH;}; 00093 00098 int packetSize() const {return msgList.size();}; 00099 00105 const char* getRawData() const {return msgList.c_str();}; 00106 00110 void print() const; 00111 00117 void setClientIndex(Sint32 index); 00118 00124 Sint32 getClientIndex() const; 00125 00126 private: 00132 string msgList; 00133 00137 bool _writable; 00138 00142 unsigned pointer; 00143 00147 static const string SEPARATOR; 00148 00152 static const int HEADER_LENGTH; 00153 };