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