| [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 |  | 
|---|
| [2171] | 31 | #include "network/NetworkPrereqs.h" | 
|---|
| [2087] | 32 |  | 
|---|
| [1711] | 33 | #include <map> | 
|---|
| [1701] | 34 |  | 
|---|
| [2171] | 35 | namespace orxonox { | 
|---|
| [1701] | 36 |  | 
|---|
 | 37 | namespace packet{ | 
|---|
| [2087] | 38 |  | 
|---|
| [1701] | 39 | namespace ENUM{ | 
|---|
 | 40 |   enum Direction{ | 
|---|
 | 41 |     Incoming, | 
|---|
 | 42 |     Outgoing, | 
|---|
 | 43 |     Bidirectional | 
|---|
 | 44 |   }; | 
|---|
 | 45 |   enum Type{ | 
|---|
 | 46 |     Acknowledgement, | 
|---|
 | 47 |     Gamestate, | 
|---|
 | 48 |     ClassID, | 
|---|
| [1705] | 49 |     Chat, | 
|---|
| [1907] | 50 |     Welcome, | 
|---|
 | 51 |     DeleteObjects | 
|---|
| [1701] | 52 |   }; | 
|---|
 | 53 | } | 
|---|
| [2087] | 54 |  | 
|---|
| [1701] | 55 | /** | 
|---|
 | 56 |         @author Oliver Scheuss <scheusso [at] ee.ethz.ch> | 
|---|
 | 57 | */ | 
|---|
| [2087] | 58 | class _NetworkExport Packet{ | 
|---|
| [1701] | 59 |   public: | 
|---|
| [1711] | 60 |     Packet(const Packet &p); | 
|---|
| [1709] | 61 |     virtual ~Packet(); | 
|---|
| [1711] | 62 |     static Packet *createPacket(ENetPacket *packet, ENetPeer *peer); | 
|---|
 | 63 |     static void deletePacket(ENetPacket *packet); | 
|---|
| [2087] | 64 |  | 
|---|
| [1711] | 65 |     virtual unsigned char *getData(){ return data_; }; | 
|---|
 | 66 |     virtual unsigned int getSize() const =0; | 
|---|
 | 67 |     virtual bool process()=0; | 
|---|
| [2773] | 68 |     uint32_t getFlags() | 
|---|
| [1711] | 69 |       { return flags_; } | 
|---|
 | 70 |     int getClientID() | 
|---|
 | 71 |       { return clientID_; } | 
|---|
 | 72 |     void setClientID( int id ) | 
|---|
 | 73 |       { clientID_ = id; } | 
|---|
| [2087] | 74 |  | 
|---|
| [1701] | 75 |     bool send(); | 
|---|
 | 76 |   protected: | 
|---|
| [1711] | 77 |     Packet(); | 
|---|
| [1907] | 78 |     Packet(uint8_t *data, unsigned int clientID); | 
|---|
| [1713] | 79 | //    Packet(ENetPacket *packet, ENetPeer *peer); | 
|---|
| [2773] | 80 |     uint32_t flags_; | 
|---|
| [1907] | 81 |     unsigned int clientID_; | 
|---|
| [1751] | 82 |     ENUM::Direction packetDirection_; | 
|---|
| [2087] | 83 |     /** Pointer to the data. Be careful when deleting it because it might | 
|---|
 | 84 |         point to a location that was allocated by ENet. | 
|---|
 | 85 |         See bDataENetAllocated_ */ | 
|---|
| [1907] | 86 |     uint8_t *data_; | 
|---|
| [2087] | 87 |     /** Tells whether data_ was allocated by ENet or ourselves. | 
|---|
 | 88 |         data_ might no correlate with enetPacket_->data. */ | 
|---|
 | 89 |     bool bDataENetAllocated_; | 
|---|
| [1701] | 90 |   private: | 
|---|
| [2171] | 91 |     static std::map<size_t, Packet *> packetMap_; | 
|---|
| [1701] | 92 |     ENetPacket *enetPacket_; | 
|---|
 | 93 | }; | 
|---|
 | 94 |  | 
|---|
 | 95 | } //namespace packet | 
|---|
 | 96 |  | 
|---|
| [2171] | 97 | } //namespace orxonox | 
|---|
| [1701] | 98 |  | 
|---|
 | 99 | #endif | 
|---|