Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/network/packet/ClassID.cc @ 2687

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

minor change in classID

  • Property svn:eol-style set to native
File size: 2.3 KB
RevLine 
[1711]1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Oliver Scheuss, (C) 2008
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29
30
[1701]31#include "ClassID.h"
32#include "core/CoreIncludes.h"
[1837]33#include <cstring>
[1705]34#include <assert.h>
[1701]35
[2171]36namespace orxonox {
[1701]37namespace packet {
38
[1856]39
[2669]40
[1701]41  ClassID::ClassID( unsigned int classID, std::string className )
[1711]42 : Packet()
[1701]43{
44  flags_ = flags_ | PACKET_FLAGS_CLASSID;
45  classNameLength_=className.length()+1;
[1705]46  assert(getSize());
[1701]47  data_=new unsigned char[ getSize() ];
[1708]48  assert(data_);
[1713]49  *(ENUM::Type *)(data_ + _PACKETID ) = ENUM::ClassID;
50  *(unsigned int *)(data_ + _CLASSID ) = classID;
51  *(unsigned int *)(data_ + _CLASSNAMELENGTH ) = classNameLength_;
52  memcpy( data_+_CLASSNAME, (void *)className.c_str(), classNameLength_ );
[1701]53}
54
[1907]55ClassID::ClassID( uint8_t* data, unsigned int clientID )
[1711]56  : Packet(data, clientID)
[1701]57{
[1708]58  memcpy( (void *)&classNameLength_, &data[ _CLASSNAMELENGTH ], sizeof(classNameLength_) );
[1701]59}
60
61ClassID::~ClassID()
62{
63}
64
65unsigned int ClassID::getSize() const{
[2171]66  return sizeof(packet::ENUM::Type) + 2*sizeof(uint32_t) + classNameLength_;
[1701]67}
68
69bool ClassID::process(){
[2669]70  COUT(3) << "processing classid: " << getClassID() << " name: " << getClassName() << std::endl;
71  Identifier *id=ClassByString( std::string(getClassName()) );
[1701]72  if(id==NULL)
73    return false;
74  id->setNetworkID( getClassID() );
[1711]75  delete this;
[1701]76  return true;
77}
78
[2669]79
[1701]80unsigned int ClassID::getClassID(){
[1907]81  return *(uint32_t *)(data_ + _CLASSID);
[1701]82}
83
84} //namespace packet
[2171]85}//namespace orxonox
Note: See TracBrowser for help on using the repository browser.