Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 346 was 341, checked in by rgrieder, 17 years ago
  • removed folder src/class_hierarchy
  • removed a few unnec. files in src/
  • added a few files in src/orxonox to make weapon system and hud work
  • restructured all CMLs
  • adjusted all the #include directives (only one include directory now: src)
  • moved ENET library linkage to CML in src/orxonox
File size: 2.0 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        //print functions
95        void printAck( ack* data );
96        void printMouse( mouse* data );
97        void printKey( keyboard* data );
98        void printChat( chat* data );
99        void printGamestate( GameState* data );
100};
101}
102
103#endif /*PACKETMANAGER_H_*/
Note: See TracBrowser for help on using the repository browser.