Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/gui/src/network/PacketManager.h @ 1688

Last change on this file since 1688 was 1652, checked in by rgrieder, 16 years ago
  • clean up in OrxonoxPlatform.h
  • that's it
  • Property svn:eol-style set to native
File size: 3.9 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 *      Dumeni Manatschal, (C) 2007
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#ifndef _PacketManager_H__
30#define _PacketManager_H__
31
32#include "NetworkPrereqs.h"
33
34#include <string>
35#include <enet/enet.h>
36
37#include "util/Integers.h"
38#include "core/CoreIncludes.h"
39
40#define CLIENTID_CLIENT -1
41#define NETWORK_CRC32POLY 0x04C11DB7 /* CRC-32 Polynom */
42
43//enum netowk generally used to set the type ID of a packet
44namespace network
45{
46  /*
47  * class to generate packets
48  *
49  * @autor: Dumeni Manatschal
50  *
51  */
52  //void calcCRC(uint32_t &crc32, int bit);
53  uint32_t calcCRC(unsigned char *data, unsigned int dataLength);
54 
55  class PacketGenerator
56  {
57  public:
58    PacketGenerator();
59    //call one of this functions out of an instance of PacketGenerator to create a packet
60    ENetPacket* acknowledgement( int state, int reliable = 0 ); // we do not want reliability
61    ENetPacket* command( int dataLength, void *data, int reliable = ENET_PACKET_FLAG_RELIABLE );
62    ENetPacket* chatMessage( const char* message, int reliable = ENET_PACKET_FLAG_RELIABLE );
63    ENetPacket* gstate( GameStateCompressed *states, int reliable = 0 ); // we do not want reliability of gamestates
64    ENetPacket* clid( int classid, std::string classname, int reliable = ENET_PACKET_FLAG_RELIABLE );
65    ENetPacket* generateWelcome( int clientID,int shipID, bool allowed, int reliable = ENET_PACKET_FLAG_RELIABLE );
66    ENetPacket* generateConnectRequest( int reliable = ENET_PACKET_FLAG_RELIABLE );
67  private:
68    bool addCRC( ENetPacket *packet);
69  };
70
71  /*
72  * class used to decode incoming packets
73  *
74  * @autor: Dumeni Manatschal
75  *
76  */
77  class _NetworkExport PacketDecoder
78  {
79  public:
80    PacketDecoder();
81    virtual ~PacketDecoder();
82    //call this function to decode, it calls the right decoding function below
83    bool elaborate( ENetPacket* packet, int clientId );
84  protected:
85
86    virtual void processChat( chat *data, int clientId);
87
88
89  private:
90    bool testAndRemoveCRC(ENetPacket *packet);
91
92
93    void acknowledgement( ENetPacket* packet, int clientId = CLIENTID_CLIENT );
94    bool command( ENetPacket* packet, int clientId );
95    void chatMessage( ENetPacket* packet, int clientId = CLIENTID_CLIENT );
96    void gstate( ENetPacket* packet, int clientID = CLIENTID_CLIENT );
97    void clid( ENetPacket *packet);
98    bool decodeWelcome( ENetPacket* packet, int clientID = CLIENTID_CLIENT );
99    bool decodeConnectRequest( ENetPacket *packet, int clientID = CLIENTID_CLIENT );
100
101    //process data
102    //two functions are note yet implemented!
103    virtual void processGamestate(GameStateCompressed *state, int clientID);
104    virtual void processAck( ack *data, int clientID);
105    virtual void processClassid( classid *cid);
106    virtual bool processWelcome( welcome *w );
107    virtual bool processConnectRequest( connectRequest *con, int clientID );
108    //virtual void processAck( ack *data);
109
110    //print functions
111    void printAck( ack* data );
112    void printChat( chat* data, int clientId );
113    void printGamestate( GameStateCompressed *data );
114    void printClassid( classid *cid);
115  };
116}
117
118#endif /* _PacketManager_H__ */
Note: See TracBrowser for help on using the repository browser.