Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

corrected some errors

File size: 2.6 KB
RevLine 
[199]1#ifndef PACKETMANAGER_H_
2#define PACKETMANAGER_H_
3
[400]4#include <string>
[199]5#include <enet/enet.h>
[341]6#include "GameStateManager.h"
[199]7
[223]8//enum netowk generaly used to set the type ID of a packet
[199]9namespace network
10{
11enum packet_id {
12        ACK,
13        MOUSE,
14        KEYBOARD,
[332]15        CHAT,
[400]16        GAMESTATE ,
17        CLASSID
[199]18};
19
[223]20/*
21 * class to generate packets
22 *
[332]23 * @autor: Dumeni Manatschal
[223]24 *
25*/ 
[199]26class PacketGenerator
27{
28public:
29        PacketGenerator();
[223]30        //call one of this functions out of an instance of PacketGenerator to create a packet
[199]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 );
[332]35        ENetPacket* gstate( GameState* states, int reliable = ENET_PACKET_FLAG_RELIABLE );
[400]36        ENetPacket* clid( int classid, std::string classname, int reliable = ENET_PACKET_FLAG_RELIABLE );
[199]37private:
[223]38        //used to set the bytes in the right order
[199]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
[223]56/*
57 * class used to decode incoming packets
58 *
[332]59 * @autor: Dumeni Manatschal
[223]60 *
61*/
[199]62class PacketDecoder
63{
64public:
65        PacketDecoder();
[223]66        //call this function to decode, it calls the right decoding function below
[203]67        bool elaborate( ENetPacket* packet, int clientId );
[401]68        struct classid{
69          int id;
70          int length;
71          int classid;
72          const char *message;
73        };
[199]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        };
[223]90        //only in this class, not PacketGenerator, used as pattern to put incoming
91        //bytes inside
[199]92        struct chat {
93                int id;
94                const char* message;
95        };
[400]96       
[401]97       
[199]98       
[203]99        void acknowledgement( ENetPacket* packet );
100        void mousem( ENetPacket* packet );
101        void keystrike( ENetPacket* packet );
102        void chatMessage( ENetPacket* packet );
[332]103        void gstate( ENetPacket* packet );
[400]104        void clid( ENetPacket *packet);
[199]105       
[369]106  //process data
[374]107  //two functions are note yet implemented!
108  //virtual void processGamestate(GameState *state);
[369]109  virtual void processChat( chat *data);
[400]110  virtual void processClassid( classid *cid);
[374]111  //virtual void processAck( ack *data);
[369]112 
[199]113        //print functions
114        void printAck( ack* data );
115        void printMouse( mouse* data );
116        void printKey( keyboard* data );
117        void printChat( chat* data );
[332]118        void printGamestate( GameState* data );
[400]119        void printClassid( classid *cid);
[199]120};
121}
122
123#endif /*PACKETMANAGER_H_*/
Note: See TracBrowser for help on using the repository browser.