Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/lod2/src/network/packet/Packet.h @ 2473

Last change on this file since 2473 was 2087, checked in by landauf, 16 years ago

merged objecthierarchy branch back to trunk

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