Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/network/src/network/PacketManager.h @ 290

Last change on this file since 290 was 290, checked in by dumenim, 16 years ago

added gamestates to packetCode/Decode classes

File size: 2.0 KB
RevLine 
[199]1#ifndef PACKETMANAGER_H_
2#define PACKETMANAGER_H_
3
4#include <enet/enet.h>
[290]5#include <network/GameStateManager.h>
[199]6
[223]7//enum netowk generaly used to set the type ID of a packet
[199]8namespace network
9{
10enum packet_id {
11        ACK,
12        MOUSE,
13        KEYBOARD,
[290]14        CHAT,
15        GAMESTATE
[199]16};
17
[223]18/*
19 * class to generate packets
20 *
21 * Autor: Dumeni Manatschal
22 *
23*/ 
[199]24class PacketGenerator
25{
26public:
27        PacketGenerator();
[223]28        //call one of this functions out of an instance of PacketGenerator to create a packet
[199]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 );
[290]33        ENetPacket* gstate( GameState* states, int reliable = ENET_PACKET_FLAG_RELIABLE );
[199]34private:
[223]35        //used to set the bytes in the right order
[199]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
[223]53/*
54 * class used to decode incoming packets
55 *
56 * Autor: Dumeni Manatschal
57 *
58*/
[199]59class PacketDecoder
60{
61public:
62        PacketDecoder();
[223]63        //call this function to decode, it calls the right decoding function below
[203]64        bool elaborate( ENetPacket* packet, int clientId );
[199]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        };
[223]81        //only in this class, not PacketGenerator, used as pattern to put incoming
82        //bytes inside
[199]83        struct chat {
84                int id;
85                const char* message;
86        };
87       
[203]88        void acknowledgement( ENetPacket* packet );
89        void mousem( ENetPacket* packet );
90        void keystrike( ENetPacket* packet );
91        void chatMessage( ENetPacket* packet );
[290]92        void gstate( ENetPacket* packet );
[199]93       
94        //print functions
95        void printAck( ack* data );
96        void printMouse( mouse* data );
97        void printKey( keyboard* data );
98        void printChat( chat* data );
[290]99        void printGamestate( GameState* data );
[199]100};
101}
102
103#endif /*PACKETMANAGER_H_*/
Note: See TracBrowser for help on using the repository browser.