[199] | 1 | #ifndef PACKETMANAGER_H_ |
---|
| 2 | #define PACKETMANAGER_H_ |
---|
| 3 | |
---|
| 4 | #include <enet/enet.h> |
---|
| 5 | |
---|
[223] | 6 | //enum netowk generaly used to set the type ID of a packet |
---|
[199] | 7 | namespace network |
---|
| 8 | { |
---|
| 9 | enum packet_id { |
---|
| 10 | ACK, |
---|
| 11 | MOUSE, |
---|
| 12 | KEYBOARD, |
---|
| 13 | CHAT |
---|
| 14 | }; |
---|
| 15 | |
---|
[223] | 16 | /* |
---|
| 17 | * class to generate packets |
---|
| 18 | * |
---|
| 19 | * Autor: Dumeni Manatschal |
---|
| 20 | * |
---|
| 21 | */ |
---|
[199] | 22 | class PacketGenerator |
---|
| 23 | { |
---|
| 24 | public: |
---|
| 25 | PacketGenerator(); |
---|
[223] | 26 | //call one of this functions out of an instance of PacketGenerator to create a packet |
---|
[199] | 27 | ENetPacket* acknowledgement( int state, int reliable = ENET_PACKET_FLAG_RELIABLE ); |
---|
| 28 | ENetPacket* mousem( double x, double y, int reliable = ENET_PACKET_FLAG_RELIABLE ); |
---|
| 29 | ENetPacket* keystrike( char press, int reliable = ENET_PACKET_FLAG_RELIABLE ); |
---|
| 30 | ENetPacket* chatMessage( const char* message, int reliable = ENET_PACKET_FLAG_RELIABLE ); |
---|
| 31 | private: |
---|
[223] | 32 | //used to set the bytes in the right order |
---|
[199] | 33 | struct ack { |
---|
| 34 | int id; |
---|
| 35 | int a; |
---|
| 36 | }; |
---|
| 37 | |
---|
| 38 | struct mouse { |
---|
| 39 | int id; |
---|
| 40 | double x; |
---|
| 41 | double y; |
---|
| 42 | }; |
---|
| 43 | |
---|
| 44 | struct keyboard { |
---|
| 45 | int id; |
---|
| 46 | char press; |
---|
| 47 | }; |
---|
| 48 | }; |
---|
| 49 | |
---|
[223] | 50 | /* |
---|
| 51 | * class used to decode incoming packets |
---|
| 52 | * |
---|
| 53 | * Autor: Dumeni Manatschal |
---|
| 54 | * |
---|
| 55 | */ |
---|
[199] | 56 | class PacketDecoder |
---|
| 57 | { |
---|
| 58 | public: |
---|
| 59 | PacketDecoder(); |
---|
[223] | 60 | //call this function to decode, it calls the right decoding function below |
---|
[203] | 61 | bool elaborate( ENetPacket* packet, int clientId ); |
---|
[199] | 62 | private: |
---|
| 63 | struct ack { |
---|
| 64 | int id; |
---|
| 65 | int a; |
---|
| 66 | }; |
---|
| 67 | |
---|
| 68 | struct mouse { |
---|
| 69 | int id; |
---|
| 70 | double x; |
---|
| 71 | double y; |
---|
| 72 | }; |
---|
| 73 | |
---|
| 74 | struct keyboard { |
---|
| 75 | int id; |
---|
| 76 | char press; |
---|
| 77 | }; |
---|
[223] | 78 | //only in this class, not PacketGenerator, used as pattern to put incoming |
---|
| 79 | //bytes inside |
---|
[199] | 80 | struct chat { |
---|
| 81 | int id; |
---|
| 82 | const char* message; |
---|
| 83 | }; |
---|
| 84 | |
---|
[203] | 85 | void acknowledgement( ENetPacket* packet ); |
---|
| 86 | void mousem( ENetPacket* packet ); |
---|
| 87 | void keystrike( ENetPacket* packet ); |
---|
| 88 | void chatMessage( ENetPacket* packet ); |
---|
[199] | 89 | |
---|
| 90 | //print functions |
---|
| 91 | void printAck( ack* data ); |
---|
| 92 | void printMouse( mouse* data ); |
---|
| 93 | void printKey( keyboard* data ); |
---|
| 94 | void printChat( chat* data ); |
---|
| 95 | void printPeer( ENetPeer* peer ); |
---|
| 96 | }; |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | #endif /*PACKETMANAGER_H_*/ |
---|