Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/FICN/src/network/PacketManager.h @ 374

Last change on this file since 374 was 374, checked in by rgrieder, 16 years ago
  • commented 2 functions to make the network source compile
File size: 2.2 KB
Line 
1#ifndef PACKETMANAGER_H_
2#define PACKETMANAGER_H_
3
4#include <enet/enet.h>
5#include "GameStateManager.h"
6
7//enum netowk generaly used to set the type ID of a packet
8namespace network
9{
10enum packet_id {
11        ACK,
12        MOUSE,
13        KEYBOARD,
14        CHAT,
15        GAMESTATE
16};
17
18/*
19 * class to generate packets
20 *
21 * @autor: Dumeni Manatschal
22 *
23*/ 
24class PacketGenerator
25{
26public:
27        PacketGenerator();
28        //call one of this functions out of an instance of PacketGenerator to create a packet
29        ENetPacket* acknowledgement( int state, int reliable = ENET_PACKET_FLAG_RELIABLE );
30        ENetPacket* mousem( double x, double y, int reliable = ENET_PACKET_FLAG_RELIABLE );
31        ENetPacket* keystrike( char press, int reliable = ENET_PACKET_FLAG_RELIABLE );
32        ENetPacket* chatMessage( const char* message, int reliable = ENET_PACKET_FLAG_RELIABLE );
33        ENetPacket* gstate( GameState* states, int reliable = ENET_PACKET_FLAG_RELIABLE );
34private:
35        //used to set the bytes in the right order
36        struct ack {
37                int id;
38                int a;
39        };
40
41        struct mouse {
42                int id;
43                double x;
44                double y;
45        };
46
47        struct keyboard {
48                int id;
49                char press;
50        };     
51};
52
53/*
54 * class used to decode incoming packets
55 *
56 * @autor: Dumeni Manatschal
57 *
58*/
59class PacketDecoder
60{
61public:
62        PacketDecoder();
63        //call this function to decode, it calls the right decoding function below
64        bool elaborate( ENetPacket* packet, int clientId );
65private:
66        struct ack {
67                int id;
68                int a;
69        };
70
71        struct mouse {
72                int id;
73                double x;
74                double y;
75        };
76
77        struct keyboard {
78                int id;
79                char press;
80        };
81        //only in this class, not PacketGenerator, used as pattern to put incoming
82        //bytes inside
83        struct chat {
84                int id;
85                const char* message;
86        };
87       
88        void acknowledgement( ENetPacket* packet );
89        void mousem( ENetPacket* packet );
90        void keystrike( ENetPacket* packet );
91        void chatMessage( ENetPacket* packet );
92        void gstate( ENetPacket* packet );
93       
94  //process data
95  //two functions are note yet implemented!
96  //virtual void processGamestate(GameState *state);
97  virtual void processChat( chat *data);
98  //virtual void processAck( ack *data);
99 
100        //print functions
101        void printAck( ack* data );
102        void printMouse( mouse* data );
103        void printKey( keyboard* data );
104        void printChat( chat* data );
105        void printGamestate( GameState* data );
106};
107}
108
109#endif /*PACKETMANAGER_H_*/
Note: See TracBrowser for help on using the repository browser.