Line | |
---|
1 | #include "Chat.h" |
---|
2 | #include "Packet.h" |
---|
3 | |
---|
4 | namespace network { |
---|
5 | namespace packet { |
---|
6 | |
---|
7 | #define PACKET_FLAGS_CHAT ENET_PACKET_FLAG_RELIABLE |
---|
8 | #define _PACKETID 0 |
---|
9 | #define _MESSAGELENGTH _PACKETID + sizeof(ENUM::Type) |
---|
10 | #define _MESSAGE _MESSAGELENGTH + sizeof(unsigned int) |
---|
11 | |
---|
12 | Chat::Chat( std::string& message, int clientID ) |
---|
13 | : PacketContent() |
---|
14 | { |
---|
15 | flags_ = flags_ | PACKET_FLAGS_CHAT; |
---|
16 | messageLength_ = message.length()+1; |
---|
17 | data_=new unsigned char[ getSize() ]; |
---|
18 | *(ENUM::Type *)&data_[ _PACKETID ] = packet::ENUM::Chat; |
---|
19 | *(unsigned int *)&data_[ _MESSAGELENGTH ] = messageLength_; |
---|
20 | memcpy( &data_[ _MESSAGE ], (void *)message.c_str(), messageLength_ ); |
---|
21 | clientID_=clientID; |
---|
22 | } |
---|
23 | |
---|
24 | Chat::Chat( unsigned char *data, int clientID ) |
---|
25 | : PacketContent(data, clientID) |
---|
26 | { |
---|
27 | messageLength_ = *(unsigned int *)&data[ _MESSAGELENGTH ]; |
---|
28 | } |
---|
29 | |
---|
30 | Chat::~Chat() |
---|
31 | { |
---|
32 | } |
---|
33 | |
---|
34 | unsigned char *Chat::getData(){ |
---|
35 | return data_; |
---|
36 | } |
---|
37 | |
---|
38 | unsigned int Chat::getSize() const{ |
---|
39 | return _MESSAGE + messageLength_; |
---|
40 | } |
---|
41 | |
---|
42 | bool Chat::process(){ |
---|
43 | //TODO: change this !!! |
---|
44 | return true; |
---|
45 | } |
---|
46 | |
---|
47 | unsigned char *Chat::getMessage(){ |
---|
48 | return &data_[ _MESSAGE ]; |
---|
49 | } |
---|
50 | |
---|
51 | } //namespace packet |
---|
52 | } //namespace network |
---|
Note: See
TracBrowser
for help on using the repository browser.