[1701] | 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() |
---|
[1706] | 46 | { |
---|
| 47 | if(data_) delete[] data_; |
---|
| 48 | } |
---|
[1701] | 49 | virtual unsigned char *getData()=0; |
---|
| 50 | virtual unsigned int getSize() const =0; |
---|
[1706] | 51 | int getClientID() |
---|
| 52 | { |
---|
| 53 | return clientID_; |
---|
| 54 | } |
---|
[1701] | 55 | virtual bool process()=0; |
---|
[1706] | 56 | enet_uint32 getFlags() |
---|
| 57 | { |
---|
| 58 | return flags_; |
---|
| 59 | } |
---|
[1701] | 60 | protected: |
---|
| 61 | PacketContent() |
---|
[1706] | 62 | { |
---|
| 63 | flags_ = PACKET_FLAG_DEFAULT; |
---|
[1701] | 64 | data_=0; } |
---|
[1705] | 65 | PacketContent( unsigned char *data, int clientID ) |
---|
| 66 | { flags_ = PACKET_FLAG_DEFAULT; data_=data; clientID_=clientID; } |
---|
[1701] | 67 | PacketContent(const PacketContent& p){ |
---|
| 68 | flags_=p.flags_; |
---|
| 69 | if(p.data_){ |
---|
| 70 | data_ = new unsigned char[p.getSize()]; |
---|
| 71 | memcpy(data_, p.data_, p.getSize()); |
---|
| 72 | }else |
---|
| 73 | data_=0; |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | enet_uint32 flags_; |
---|
| 77 | unsigned char *data_; |
---|
[1705] | 78 | int clientID_; |
---|
[1701] | 79 | private: |
---|
| 80 | }; |
---|
| 81 | |
---|
| 82 | } //namespace packet |
---|
| 83 | |
---|
| 84 | } //namespace network |
---|
| 85 | |
---|
| 86 | #endif |
---|