[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 NETWORKPACKET_H |
---|
| 29 | #define NETWORKPACKET_H |
---|
| 30 | |
---|
[1711] | 31 | #include <map> |
---|
[1701] | 32 | #include <enet/enet.h> |
---|
| 33 | |
---|
| 34 | namespace network { |
---|
| 35 | |
---|
| 36 | namespace packet{ |
---|
| 37 | |
---|
| 38 | namespace ENUM{ |
---|
| 39 | enum Direction{ |
---|
| 40 | Incoming, |
---|
| 41 | Outgoing, |
---|
| 42 | Bidirectional |
---|
| 43 | }; |
---|
| 44 | enum Type{ |
---|
| 45 | Acknowledgement, |
---|
| 46 | Gamestate, |
---|
| 47 | ClassID, |
---|
[1705] | 48 | Chat, |
---|
| 49 | Welcome |
---|
[1701] | 50 | }; |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | /** |
---|
| 54 | @author Oliver Scheuss <scheusso [at] ee.ethz.ch> |
---|
| 55 | */ |
---|
| 56 | class Packet{ |
---|
| 57 | public: |
---|
[1711] | 58 | Packet(const Packet &p); |
---|
[1709] | 59 | virtual ~Packet(); |
---|
[1711] | 60 | static Packet *createPacket(ENetPacket *packet, ENetPeer *peer); |
---|
| 61 | static void deletePacket(ENetPacket *packet); |
---|
[1701] | 62 | |
---|
[1711] | 63 | virtual unsigned char *getData(){ return data_; }; |
---|
| 64 | virtual unsigned int getSize() const =0; |
---|
| 65 | virtual bool process()=0; |
---|
| 66 | enet_uint32 getFlags() |
---|
| 67 | { return flags_; } |
---|
| 68 | int getClientID() |
---|
| 69 | { return clientID_; } |
---|
| 70 | void setClientID( int id ) |
---|
| 71 | { clientID_ = id; } |
---|
[1701] | 72 | |
---|
| 73 | bool send(); |
---|
| 74 | protected: |
---|
[1711] | 75 | Packet(); |
---|
| 76 | Packet(unsigned char *data, int clientID); |
---|
[1713] | 77 | // Packet(ENetPacket *packet, ENetPeer *peer); |
---|
[1711] | 78 | enet_uint32 flags_; |
---|
| 79 | int clientID_; |
---|
[1751] | 80 | ENUM::Direction packetDirection_; |
---|
[1711] | 81 | unsigned char *data_; |
---|
[1701] | 82 | private: |
---|
[1711] | 83 | static std::map<ENetPacket *, Packet *> packetMap_; |
---|
[1701] | 84 | ENetPacket *enetPacket_; |
---|
| 85 | }; |
---|
| 86 | |
---|
| 87 | } //namespace packet |
---|
| 88 | |
---|
| 89 | } //namespace network |
---|
| 90 | |
---|
| 91 | #endif |
---|