Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/merge/src/network/PacketManager.h @ 1361

Last change on this file since 1361 was 1361, checked in by scheusso, 16 years ago

reverted some changes from previous version

File size: 4.5 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 <inttypes.h>
36#include <enet/enet.h>
37
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 );
61    ENetPacket* acknowledgement( int state, int reliable = ENET_PACKET_FLAG_RELIABLE );
62    ENetPacket* command( int dataLength, void *data, int reliable = ENET_PACKET_FLAG_RELIABLE );
63    ENetPacket* mousem( double x, double y, int reliable = ENET_PACKET_FLAG_RELIABLE );
64    ENetPacket* keystrike( char press, int reliable = ENET_PACKET_FLAG_RELIABLE );
65    ENetPacket* chatMessage( const char* message, int reliable = ENET_PACKET_FLAG_RELIABLE );
66    ENetPacket* gstate( GameStateCompressed *states, int reliable = ENET_PACKET_FLAG_RELIABLE );
67//    ENetPacket* gstate( GameStateCompressed *states, int reliable = 0 );
68    ENetPacket* clid( int classid, std::string classname, int reliable = ENET_PACKET_FLAG_RELIABLE );
69    ENetPacket* generateWelcome( int clientID,int shipID, bool allowed, int reliable = ENET_PACKET_FLAG_RELIABLE );
70    ENetPacket* generateConnectRequest( int reliable = ENET_PACKET_FLAG_RELIABLE );
71  private:
72    bool addCRC( ENetPacket *packet);
73  };
74
75  /*
76  * class used to decode incoming packets
77  *
78  * @autor: Dumeni Manatschal
79  *
80  */
81  class _NetworkExport PacketDecoder
82  {
83  public:
84    PacketDecoder();
85    virtual ~PacketDecoder();
86    //call this function to decode, it calls the right decoding function below
87    bool elaborate( ENetPacket* packet, int clientId );
88  protected:
89
90    virtual void processChat( chat *data, int clientId);
91
92
93  private:
94    bool testAndRemoveCRC(ENetPacket *packet);
95
96
97    void acknowledgement( ENetPacket* packet, int clientId = CLIENTID_CLIENT );
98    bool command( ENetPacket* packet, int clientId );
99    void mousem( ENetPacket* packet, int clientId = CLIENTID_CLIENT );
100    void keystrike( ENetPacket* packet, int clientId = CLIENTID_CLIENT );
101    void chatMessage( ENetPacket* packet, int clientId = CLIENTID_CLIENT );
102    void gstate( ENetPacket* packet, int clientID = CLIENTID_CLIENT );
103    void clid( ENetPacket *packet);
104    bool decodeWelcome( ENetPacket* packet, int clientID = CLIENTID_CLIENT );
105    bool decodeConnectRequest( ENetPacket *packet, int clientID = CLIENTID_CLIENT );
106
107    //process data
108    //two functions are note yet implemented!
109    virtual void processGamestate(GameStateCompressed *state, int clientID);
110    virtual void processAck( ack *data, int clientID);
111    virtual void processClassid( classid *cid);
112    virtual bool processWelcome( welcome *w );
113    virtual bool processConnectRequest( connectRequest *con, int clientID );
114    //virtual void processAck( ack *data);
115
116    //print functions
117    void printAck( ack* data );
118    void printMouse( mouse* data );
119    void printKey( keyboard* data );
120    void printChat( chat* data, int clientId );
121    void printGamestate( GameStateCompressed *data );
122    void printClassid( classid *cid);
123  };
124}
125
126#endif /* _PacketManager_H__ */
Note: See TracBrowser for help on using the repository browser.