Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 2742 was 2710, checked in by rgrieder, 16 years ago

Merged buildsystem3 containing buildsystem2 containing Adi's buildsystem branch back to the trunk.
Please update the media directory if you were not using buildsystem3 before.

  • 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#include <enet/enet.h>
[2171]35#include <boost/thread/recursive_mutex.hpp>
[1701]36
[2171]37namespace orxonox {
[1701]38
39namespace packet{
[2087]40
[1701]41namespace ENUM{
42  enum Direction{
43    Incoming,
44    Outgoing,
45    Bidirectional
46  };
47  enum Type{
48    Acknowledgement,
49    Gamestate,
50    ClassID,
[1705]51    Chat,
[1907]52    Welcome,
53    DeleteObjects
[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;
70    enet_uint32 getFlags()
71      { return flags_; }
72    int getClientID()
73      { return clientID_; }
74    void setClientID( int id )
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);
[1711]82    enet_uint32 flags_;
[1907]83    unsigned int clientID_;
[1751]84    ENUM::Direction packetDirection_;
[2087]85    /** Pointer to the data. Be careful when deleting it because it might
86        point to a location that was allocated by ENet.
87        See bDataENetAllocated_ */
[1907]88    uint8_t *data_;
[2087]89    /** Tells whether data_ was allocated by ENet or ourselves.
90        data_ might no correlate with enetPacket_->data. */
91    bool bDataENetAllocated_;
[1701]92  private:
[2171]93    static std::map<size_t, Packet *> packetMap_;
94    //! Static mutex for any packetMap_ access
95    static boost::recursive_mutex packetMap_mutex;
[1701]96    ENetPacket *enetPacket_;
97};
98
99} //namespace packet
100
[2171]101} //namespace orxonox
[1701]102
103#endif
Note: See TracBrowser for help on using the repository browser.