[673] | 1 | #ifndef _PacketManager_H__ |
---|
| 2 | #define _PacketManager_H__ |
---|
[199] | 3 | |
---|
[400] | 4 | #include <string> |
---|
[199] | 5 | #include <enet/enet.h> |
---|
[415] | 6 | #include "PacketTypes.h" |
---|
[199] | 7 | |
---|
[440] | 8 | #define CLIENTID_CLIENT -1 |
---|
| 9 | |
---|
[223] | 10 | //enum netowk generaly used to set the type ID of a packet |
---|
[413] | 11 | namespace network{ |
---|
| 12 | |
---|
[415] | 13 | |
---|
[199] | 14 | |
---|
[415] | 15 | |
---|
| 16 | |
---|
[223] | 17 | /* |
---|
| 18 | * class to generate packets |
---|
| 19 | * |
---|
[332] | 20 | * @autor: Dumeni Manatschal |
---|
[223] | 21 | * |
---|
| 22 | */ |
---|
[199] | 23 | class PacketGenerator |
---|
| 24 | { |
---|
| 25 | public: |
---|
| 26 | PacketGenerator(); |
---|
[223] | 27 | //call one of this functions out of an instance of PacketGenerator to create a packet |
---|
[199] | 28 | ENetPacket* acknowledgement( int state, int reliable = ENET_PACKET_FLAG_RELIABLE ); |
---|
| 29 | ENetPacket* mousem( double x, double y, int reliable = ENET_PACKET_FLAG_RELIABLE ); |
---|
| 30 | ENetPacket* keystrike( char press, int reliable = ENET_PACKET_FLAG_RELIABLE ); |
---|
[440] | 31 | ENetPacket* chatMessage( const char* message, int reliable = ENET_PACKET_FLAG_RELIABLE ); |
---|
| 32 | ENetPacket* gstate( GameStateCompressed *states, int reliable = ENET_PACKET_FLAG_RELIABLE ); |
---|
| 33 | ENetPacket* clid( int classid, std::string classname, int reliable = ENET_PACKET_FLAG_RELIABLE ); |
---|
[199] | 34 | private: |
---|
| 35 | }; |
---|
| 36 | |
---|
[223] | 37 | /* |
---|
| 38 | * class used to decode incoming packets |
---|
| 39 | * |
---|
[332] | 40 | * @autor: Dumeni Manatschal |
---|
[223] | 41 | * |
---|
| 42 | */ |
---|
[199] | 43 | class PacketDecoder |
---|
| 44 | { |
---|
| 45 | public: |
---|
| 46 | PacketDecoder(); |
---|
[531] | 47 | virtual ~PacketDecoder(); |
---|
[223] | 48 | //call this function to decode, it calls the right decoding function below |
---|
[203] | 49 | bool elaborate( ENetPacket* packet, int clientId ); |
---|
[478] | 50 | protected: |
---|
| 51 | |
---|
| 52 | virtual void processChat( chat *data, int clientId); |
---|
[415] | 53 | |
---|
[478] | 54 | |
---|
[199] | 55 | private: |
---|
[400] | 56 | |
---|
[401] | 57 | |
---|
[199] | 58 | |
---|
[440] | 59 | void acknowledgement( ENetPacket* packet, int clientId = CLIENTID_CLIENT ); |
---|
| 60 | void mousem( ENetPacket* packet, int clientId = CLIENTID_CLIENT ); |
---|
| 61 | void keystrike( ENetPacket* packet, int clientId = CLIENTID_CLIENT ); |
---|
| 62 | void chatMessage( ENetPacket* packet, int clientId = CLIENTID_CLIENT); |
---|
| 63 | void gstate( ENetPacket* packet ); |
---|
| 64 | void clid( ENetPacket *packet); |
---|
[199] | 65 | |
---|
[369] | 66 | //process data |
---|
[374] | 67 | //two functions are note yet implemented! |
---|
[620] | 68 | virtual void processGamestate(GameStateCompressed *state); |
---|
| 69 | virtual void processAck( ack *data, int clientID); |
---|
[475] | 70 | void processClassid( classid *cid); |
---|
[374] | 71 | //virtual void processAck( ack *data); |
---|
[369] | 72 | |
---|
[199] | 73 | //print functions |
---|
| 74 | void printAck( ack* data ); |
---|
| 75 | void printMouse( mouse* data ); |
---|
| 76 | void printKey( keyboard* data ); |
---|
[440] | 77 | void printChat( chat* data, int clientId ); |
---|
[413] | 78 | void printGamestate( GameStateCompressed *data ); |
---|
[440] | 79 | void printClassid( classid *cid); |
---|
[199] | 80 | }; |
---|
| 81 | } |
---|
| 82 | |
---|
[673] | 83 | #endif /* _PacketManager_H__ */ |
---|