Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/network/PacketManager.h @ 1642

Last change on this file since 1642 was 1505, checked in by rgrieder, 16 years ago

f* svn: It doesn't even inform you if you attempt to set a non existing property. It is svn:eol-style and not eol-style when using the command by the way…

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