Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/network/packet/Packet.h @ 3182

Last change on this file since 3182 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
RevLine 
[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]35namespace orxonox {
[1701]36
37namespace packet{
[2087]38
[1701]39namespace ENUM{
40  enum Direction{
41    Incoming,
42    Outgoing,
43    Bidirectional
44  };
45  enum Type{
46    Acknowledgement,
[3084]47    Chat,
48    ClassID,
49    DeleteObjects,
50    FunctionIDs,
51    FunctionCalls,
[1701]52    Gamestate,
[3084]53    Welcome
[1701]54  };
55}
[2087]56
[1701]57/**
58        @author Oliver Scheuss <scheusso [at] ee.ethz.ch>
59*/
[2087]60class _NetworkExport Packet{
[1701]61  public:
[1711]62    Packet(const Packet &p);
[1709]63    virtual ~Packet();
[1711]64    static Packet *createPacket(ENetPacket *packet, ENetPeer *peer);
65    static void deletePacket(ENetPacket *packet);
[2087]66
[1711]67    virtual unsigned char *getData(){ return data_; };
68    virtual unsigned int getSize() const =0;
69    virtual bool process()=0;
[3084]70    inline uint32_t getFlags()
[1711]71      { return flags_; }
[3084]72    inline int getClientID()
[1711]73      { return clientID_; }
[3084]74    inline void setClientID( int id )
[1711]75      { clientID_ = id; }
[2087]76
[1701]77    bool send();
78  protected:
[1711]79    Packet();
[1907]80    Packet(uint8_t *data, unsigned int clientID);
[1713]81//    Packet(ENetPacket *packet, ENetPeer *peer);
[3084]82    inline bool isDataENetAllocated() const
83      { return bDataENetAllocated_; }
84
[2773]85    uint32_t flags_;
[1907]86    unsigned int clientID_;
[1751]87    ENUM::Direction packetDirection_;
[2087]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_ */
[1907]91    uint8_t *data_;
[2087]92    /** Tells whether data_ was allocated by ENet or ourselves.
93        data_ might no correlate with enetPacket_->data. */
94    bool bDataENetAllocated_;
[1701]95  private:
[2171]96    static std::map<size_t, Packet *> packetMap_;
[1701]97    ENetPacket *enetPacket_;
98};
99
100} //namespace packet
101
[2171]102} //namespace orxonox
[1701]103
104#endif
Note: See TracBrowser for help on using the repository browser.