Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/network/src/network/packet/ClassID.cc @ 1708

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

small error in classid.cc

File size: 1.8 KB
Line 
1#include "ClassID.h"
2#include "Packet.h"
3#include "core/CoreIncludes.h"
4#include <string>
5#include <assert.h>
6
7namespace network {
8namespace packet {
9
10#define PACKET_FLAGS_CLASSID  ENET_PACKET_FLAG_RELIABLE
11#define _PACKETID             0
12#define _CLASSID              _PACKETID + sizeof(ENUM::Type)
13#define _CLASSNAMELENGTH      _CLASSID + sizeof(unsigned int)
14#define _CLASSNAME            _CLASSNAMELENGTH + sizeof(classNameLength_)
15 
16  ClassID::ClassID( unsigned int classID, std::string className )
17 : PacketContent()
18{
19  flags_ = flags_ | PACKET_FLAGS_CLASSID;
20  classNameLength_=className.length()+1;
21  assert(getSize());
22  data_=new unsigned char[ getSize() ];
23  assert(data_);
24  *(packet::ENUM::Type *)&data_[ _PACKETID ] = packet::ENUM::ClassID;
25  *(unsigned int *)&data_[ _CLASSID ] = classID;
26  *(unsigned int *)&data_[ _CLASSNAMELENGTH ] = classNameLength_;
27  memcpy( &data_[ _CLASSNAME ], (void *)className.c_str(), classNameLength_ );
28}
29
30ClassID::ClassID( unsigned char *data, int clientID )
31  : PacketContent(data, clientID)
32{
33  memcpy( (void *)&classNameLength_, &data[ _CLASSNAMELENGTH ], sizeof(classNameLength_) );
34}
35
36ClassID::~ClassID()
37{
38}
39
40unsigned char *ClassID::getData(){
41  return data_;
42}
43
44unsigned int ClassID::getSize() const{
45  return sizeof(network::packet::ENUM::Type) + 2*sizeof(unsigned int) + classNameLength_;
46}
47
48bool ClassID::process(){
49  orxonox::Identifier *id=ID( std::string((const char*)&data_[ sizeof(network::packet::ENUM::Type) ]) );
50  if(id==NULL)
51    return false;
52  id->setNetworkID( getClassID() );
53  return true;
54}
55
56unsigned int ClassID::getClassID(){
57  return *(unsigned int *)&data_[ _CLASSID ];
58}
59
60// unsigned int ClassID::getClassNameLength(){
61//   return *(unsigned int *)&data[ _CLASSNAMELENGTH ];
62// }
63
64} //namespace packet
65}//namespace network
Note: See TracBrowser for help on using the repository browser.