Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/audio/src/network/PacketManager.h @ 311

Last change on this file since 311 was 278, checked in by nicolasc, 17 years ago

merged network

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