Changeset 1907 for code/trunk/src/network/packet/Chat.cc
- Timestamp:
- Oct 12, 2008, 7:40:47 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/network/packet/Chat.cc
r1763 r1907 29 29 #include "Chat.h" 30 30 #include <assert.h> 31 #include "network/Host.h" 31 32 32 33 namespace network { 33 34 namespace packet { 34 35 35 #define PACKET_FLAGS_CHAT ENET_PACKET_FLAG_RELIABLE 36 #define _PACKETID 0 37 #define _MESSAGELENGTH _PACKETID + sizeof(ENUM::Type) 38 #define _MESSAGE _MESSAGELENGTH + sizeof(unsigned int) 36 #define PACKET_FLAGS_CHAT ENET_PACKET_FLAG_RELIABLE 37 #define _PACKETID 0 38 const int _PLAYERID = _PACKETID + sizeof(ENUM::Type); 39 #define _MESSAGELENGTH _PLAYERID + sizeof(uint32_t) 40 #define _MESSAGE _MESSAGELENGTH + sizeof(uint32_t) 39 41 40 Chat::Chat( std::string & message, int clientID )42 Chat::Chat( std::string message, unsigned int playerID ) 41 43 : Packet() 42 44 { … … 44 46 messageLength_ = message.length()+1; 45 47 data_=new unsigned char[ getSize() ]; 46 *(ENUM::Type *) &data_[ _PACKETID ]= ENUM::Chat;47 *(unsigned int *) &data_[ _MESSAGELENGTH ] = messageLength_;48 memcpy( &data_[ _MESSAGE ], (void *)message.c_str(), messageLength_ );49 clientID_=clientID;48 *(ENUM::Type *)(data_ + _PACKETID ) = ENUM::Chat; 49 *(unsigned int *)(data_ + _PLAYERID ) = playerID; 50 *(unsigned int *)(data_ + _MESSAGELENGTH ) = messageLength_; 51 memcpy( data_+_MESSAGE, (void *)message.c_str(), messageLength_ ); 50 52 } 51 53 52 Chat::Chat( u nsigned char *data,int clientID )54 Chat::Chat( uint8_t* data, unsigned int clientID ) 53 55 : Packet(data, clientID) 54 56 { 55 messageLength_ = *(u nsigned int *)&data[ _MESSAGELENGTH ];57 messageLength_ = *(uint32_t *)(data + _MESSAGELENGTH ); 56 58 } 57 59 … … 65 67 66 68 bool Chat::process(){ 67 //TODO: change this !!! 68 assert(0); 69 bool b = Host::incomingChat(std::string((const char*)data_+_MESSAGE), *(uint32_t *)(data_+_PLAYERID)); 69 70 delete this; 70 return true;71 return b; 71 72 } 72 73 73 74 unsigned char *Chat::getMessage(){ 74 return &data_[ _MESSAGE ];75 return data_ + _MESSAGE; 75 76 } 76 77
Note: See TracChangeset
for help on using the changeset viewer.