Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

corrected errors

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