Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/network/src/network/packet/Chat.cc @ 1705

Last change on this file since 1705 was 1705, checked in by scheusso, 16 years ago

further changes

File size: 1.1 KB
Line 
1#include "Chat.h"
2#include "Packet.h"
3
4namespace network {
5namespace 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
12Chat::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
24Chat::Chat( unsigned char *data, int clientID )
25  : PacketContent(data, clientID)
26{
27  messageLength_ = *(unsigned int *)&data[ _MESSAGELENGTH ];
28}
29
30Chat::~Chat()
31{
32}
33
34unsigned char *Chat::getData(){
35  return data_;
36}
37
38unsigned int Chat::getSize() const{
39  return _MESSAGE + messageLength_;
40}
41
42bool Chat::process(){
43  //TODO: change this !!!
44  return true;
45}
46
47unsigned 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.