Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 2144 was 1763, checked in by rgrieder, 16 years ago

added svn:eol-style native to all the files that were missing it

  • Property svn:eol-style set to native
File size: 2.1 KB
Line 
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 <scheusso [at] ee.ethz.ch>, (C) 2008
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "Chat.h"
30#include <assert.h>
31
32namespace network {
33namespace packet {
34 
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)
39
40Chat::Chat( std::string& message, int clientID )
41 : Packet()
42{
43  flags_ = flags_ | PACKET_FLAGS_CHAT;
44  messageLength_ = message.length()+1;
45  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;
50}
51
52Chat::Chat( unsigned char *data, int clientID )
53  : Packet(data, clientID)
54{
55  messageLength_ = *(unsigned int *)&data[ _MESSAGELENGTH ];
56}
57
58Chat::~Chat()
59{
60}
61
62unsigned int Chat::getSize() const{
63  return _MESSAGE + messageLength_;
64}
65
66bool Chat::process(){
67  //TODO: change this !!!
68  assert(0);
69  delete this;
70  return true;
71}
72
73unsigned char *Chat::getMessage(){
74  return &data_[ _MESSAGE ];
75}
76
77} //namespace packet
78} //namespace network
Note: See TracBrowser for help on using the repository browser.