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 | #ifndef NETWORKPACKETCONTENT_H |
---|
29 | #define NETWORKPACKETCONTENT_H |
---|
30 | |
---|
31 | #include <enet/enet.h> |
---|
32 | #include <string.h> |
---|
33 | |
---|
34 | #define PACKET_FLAG_DEFAULT ENET_PACKET_FLAG_NO_ALLOCATE |
---|
35 | |
---|
36 | namespace network { |
---|
37 | |
---|
38 | namespace packet{ |
---|
39 | |
---|
40 | /** |
---|
41 | @author Oliver Scheuss <scheusso [at] ee.ethz.ch> |
---|
42 | */ |
---|
43 | class PacketContent{ |
---|
44 | public: |
---|
45 | virtual ~PacketContent() |
---|
46 | { if(data_) delete[] data_; } |
---|
47 | virtual unsigned char *getData()=0; |
---|
48 | virtual unsigned int getSize() const =0; |
---|
49 | int getClientID(){return clientID_;} |
---|
50 | virtual bool process()=0; |
---|
51 | enet_uint32 getFlags(){ return flags_; } |
---|
52 | protected: |
---|
53 | PacketContent() |
---|
54 | { flags_ = PACKET_FLAG_DEFAULT; |
---|
55 | data_=0; } |
---|
56 | PacketContent( unsigned char *data, int clientID ) |
---|
57 | { flags_ = PACKET_FLAG_DEFAULT; data_=data; clientID_=clientID; } |
---|
58 | PacketContent(const PacketContent& p){ |
---|
59 | flags_=p.flags_; |
---|
60 | if(p.data_){ |
---|
61 | data_ = new unsigned char[p.getSize()]; |
---|
62 | memcpy(data_, p.data_, p.getSize()); |
---|
63 | }else |
---|
64 | data_=0; |
---|
65 | } |
---|
66 | |
---|
67 | enet_uint32 flags_; |
---|
68 | unsigned char *data_; |
---|
69 | int clientID_; |
---|
70 | private: |
---|
71 | }; |
---|
72 | |
---|
73 | } //namespace packet |
---|
74 | |
---|
75 | } //namespace network |
---|
76 | |
---|
77 | #endif |
---|