Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/pch/src/network/packet/Packet.h @ 3114

Last change on this file since 3114 was 3084, checked in by landauf, 16 years ago

merged netp3 branch back to trunk

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