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, 17 years ago
  • commented 2 functions to make the network source compile
File size: 2.2 KB
RevLine 
[199]1#ifndef PACKETMANAGER_H_
2#define PACKETMANAGER_H_
3
4#include <enet/enet.h>
[341]5#include "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,
[332]14        CHAT,
15        GAMESTATE
[199]16};
17
[223]18/*
19 * class to generate packets
20 *
[332]21 * @autor: Dumeni Manatschal
[223]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 );
[332]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 *
[332]56 * @autor: Dumeni Manatschal
[223]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 );
[332]92        void gstate( ENetPacket* packet );
[199]93       
[369]94  //process data
[374]95  //two functions are note yet implemented!
96  //virtual void processGamestate(GameState *state);
[369]97  virtual void processChat( chat *data);
[374]98  //virtual void processAck( ack *data);
[369]99 
[199]100        //print functions
101        void printAck( ack* data );
102        void printMouse( mouse* data );
103        void printKey( keyboard* data );
104        void printChat( chat* data );
[332]105        void printGamestate( GameState* data );
[199]106};
107}
108
109#endif /*PACKETMANAGER_H_*/
Note: See TracBrowser for help on using the repository browser.