Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/network3/src/network/PacketManager.h @ 1234

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

a lot of changes in order to make it possible to have mulpiple clients with each one a new ship
camera changes
object changes
synchronisable: backsyncronisation should be possible now
gamestatemanager/gamestateclient: functions for backsyncronisation
some changes in order to get the input system (the old one) on the client working
TODO something with the camera position is wrong at the moment (clientside)

File size: 4.1 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
41//enum netowk generally used to set the type ID of a packet
42namespace network
43{
44  /*
45  * class to generate packets
46  *
47  * @autor: Dumeni Manatschal
48  *
49  */
50  class PacketGenerator
51  {
52  public:
53    PacketGenerator();
54    //call one of this functions out of an instance of PacketGenerator to create a packet
55    ENetPacket* acknowledgement( int state, int reliable = ENET_PACKET_FLAG_RELIABLE );
56    ENetPacket* command( int dataLength, void *data, int reliable = ENET_PACKET_FLAG_RELIABLE );
57    ENetPacket* mousem( double x, double y, int reliable = ENET_PACKET_FLAG_RELIABLE );
58    ENetPacket* keystrike( char press, int reliable = ENET_PACKET_FLAG_RELIABLE );
59    ENetPacket* chatMessage( const char* message, int reliable = ENET_PACKET_FLAG_RELIABLE );
60    ENetPacket* gstate( GameStateCompressed *states, int reliable = ENET_PACKET_FLAG_RELIABLE );
61    ENetPacket* clid( int classid, std::string classname, int reliable = ENET_PACKET_FLAG_RELIABLE );
62    ENetPacket* generateWelcome( int clientID,int shipID, bool allowed, int reliable = ENET_PACKET_FLAG_RELIABLE );
63    ENetPacket* generateConnectRequest( int reliable = ENET_PACKET_FLAG_RELIABLE );
64  private:
65  };
66
67  /*
68  * class used to decode incoming packets
69  *
70  * @autor: Dumeni Manatschal
71  *
72  */
73  class _NetworkExport PacketDecoder
74  {
75  public:
76    PacketDecoder();
77    virtual ~PacketDecoder();
78    //call this function to decode, it calls the right decoding function below
79    bool elaborate( ENetPacket* packet, int clientId );
80  protected:
81
82    virtual void processChat( chat *data, int clientId);
83
84
85  private:
86
87
88
89    void acknowledgement( ENetPacket* packet, int clientId = CLIENTID_CLIENT );
90    bool command( ENetPacket* packet, int clientId );
91    void mousem( ENetPacket* packet, int clientId = CLIENTID_CLIENT );
92    void keystrike( ENetPacket* packet, int clientId = CLIENTID_CLIENT );
93    void chatMessage( ENetPacket* packet, int clientId = CLIENTID_CLIENT);
94    void gstate( ENetPacket* packet );
95    void clid( ENetPacket *packet);
96    bool decodeWelcome( ENetPacket* packet, int clientID = CLIENTID_CLIENT );
97    bool decodeConnectRequest( ENetPacket *packet, int clientID = CLIENTID_CLIENT );
98
99    //process data
100    //two functions are note yet implemented!
101    virtual void processGamestate(GameStateCompressed *state);
102    virtual void processAck( ack *data, int clientID);
103    virtual void processClassid( classid *cid);
104    virtual bool processWelcome( welcome *w );
105    virtual bool processConnectRequest( connectRequest *con, int clientID );
106    //virtual void processAck( ack *data);
107
108    //print functions
109    void printAck( ack* data );
110    void printMouse( mouse* data );
111    void printKey( keyboard* 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.