[1168] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * > www.orxonox.net < |
---|
| 4 | * |
---|
| 5 | * |
---|
| 6 | * License notice: |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
| 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 21 | * |
---|
| 22 | * Author: |
---|
| 23 | * Dumeni Manatschal, (C) 2007 |
---|
| 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
[1232] | 29 | #ifndef _PacketManager_H__ |
---|
| 30 | #define _PacketManager_H__ |
---|
| 31 | |
---|
| 32 | #include "NetworkPrereqs.h" |
---|
| 33 | |
---|
| 34 | #include <string> |
---|
[1336] | 35 | #include <inttypes.h> |
---|
[1232] | 36 | #include <enet/enet.h> |
---|
| 37 | |
---|
| 38 | #include "core/CoreIncludes.h" |
---|
| 39 | |
---|
| 40 | #define CLIENTID_CLIENT -1 |
---|
[1336] | 41 | #define NETWORK_CRC32POLY 0x04C11DB7 /* CRC-32 Polynom */ |
---|
[1232] | 42 | |
---|
| 43 | //enum netowk generally used to set the type ID of a packet |
---|
| 44 | namespace network |
---|
| 45 | { |
---|
| 46 | /* |
---|
| 47 | * class to generate packets |
---|
| 48 | * |
---|
| 49 | * @autor: Dumeni Manatschal |
---|
| 50 | * |
---|
| 51 | */ |
---|
[1336] | 52 | //void calcCRC(uint32_t &crc32, int bit); |
---|
| 53 | uint32_t calcCRC(unsigned char *data, unsigned int dataLength); |
---|
| 54 | |
---|
[1232] | 55 | class PacketGenerator |
---|
| 56 | { |
---|
| 57 | public: |
---|
| 58 | PacketGenerator(); |
---|
| 59 | //call one of this functions out of an instance of PacketGenerator to create a packet |
---|
| 60 | ENetPacket* acknowledgement( int state, int reliable = ENET_PACKET_FLAG_RELIABLE ); |
---|
| 61 | ENetPacket* command( int dataLength, void *data, int reliable = ENET_PACKET_FLAG_RELIABLE ); |
---|
| 62 | ENetPacket* mousem( double x, double y, int reliable = ENET_PACKET_FLAG_RELIABLE ); |
---|
| 63 | ENetPacket* keystrike( char press, int reliable = ENET_PACKET_FLAG_RELIABLE ); |
---|
| 64 | ENetPacket* chatMessage( const char* message, int reliable = ENET_PACKET_FLAG_RELIABLE ); |
---|
| 65 | ENetPacket* gstate( GameStateCompressed *states, int reliable = ENET_PACKET_FLAG_RELIABLE ); |
---|
| 66 | ENetPacket* clid( int classid, std::string classname, int reliable = ENET_PACKET_FLAG_RELIABLE ); |
---|
| 67 | ENetPacket* generateWelcome( int clientID,int shipID, bool allowed, int reliable = ENET_PACKET_FLAG_RELIABLE ); |
---|
| 68 | ENetPacket* generateConnectRequest( int reliable = ENET_PACKET_FLAG_RELIABLE ); |
---|
| 69 | private: |
---|
[1336] | 70 | bool addCRC( ENetPacket *packet); |
---|
[1232] | 71 | }; |
---|
| 72 | |
---|
| 73 | /* |
---|
| 74 | * class used to decode incoming packets |
---|
| 75 | * |
---|
| 76 | * @autor: Dumeni Manatschal |
---|
| 77 | * |
---|
| 78 | */ |
---|
| 79 | class _NetworkExport PacketDecoder |
---|
| 80 | { |
---|
| 81 | public: |
---|
| 82 | PacketDecoder(); |
---|
| 83 | virtual ~PacketDecoder(); |
---|
| 84 | //call this function to decode, it calls the right decoding function below |
---|
| 85 | bool elaborate( ENetPacket* packet, int clientId ); |
---|
| 86 | protected: |
---|
| 87 | |
---|
| 88 | virtual void processChat( chat *data, int clientId); |
---|
| 89 | |
---|
| 90 | |
---|
| 91 | private: |
---|
[1336] | 92 | bool testAndRemoveCRC(ENetPacket *packet); |
---|
[1232] | 93 | |
---|
| 94 | |
---|
| 95 | void acknowledgement( ENetPacket* packet, int clientId = CLIENTID_CLIENT ); |
---|
| 96 | bool command( ENetPacket* packet, int clientId ); |
---|
| 97 | void mousem( ENetPacket* packet, int clientId = CLIENTID_CLIENT ); |
---|
| 98 | void keystrike( ENetPacket* packet, int clientId = CLIENTID_CLIENT ); |
---|
[1245] | 99 | void chatMessage( ENetPacket* packet, int clientId = CLIENTID_CLIENT ); |
---|
| 100 | void gstate( ENetPacket* packet, int clientID = CLIENTID_CLIENT ); |
---|
[1232] | 101 | void clid( ENetPacket *packet); |
---|
| 102 | bool decodeWelcome( ENetPacket* packet, int clientID = CLIENTID_CLIENT ); |
---|
| 103 | bool decodeConnectRequest( ENetPacket *packet, int clientID = CLIENTID_CLIENT ); |
---|
| 104 | |
---|
| 105 | //process data |
---|
| 106 | //two functions are note yet implemented! |
---|
[1245] | 107 | virtual void processGamestate(GameStateCompressed *state, int clientID); |
---|
[1232] | 108 | virtual void processAck( ack *data, int clientID); |
---|
| 109 | virtual void processClassid( classid *cid); |
---|
| 110 | virtual bool processWelcome( welcome *w ); |
---|
| 111 | virtual bool processConnectRequest( connectRequest *con, int clientID ); |
---|
| 112 | //virtual void processAck( ack *data); |
---|
| 113 | |
---|
| 114 | //print functions |
---|
| 115 | void printAck( ack* data ); |
---|
| 116 | void printMouse( mouse* data ); |
---|
| 117 | void printKey( keyboard* data ); |
---|
| 118 | void printChat( chat* data, int clientId ); |
---|
| 119 | void printGamestate( GameStateCompressed *data ); |
---|
| 120 | void printClassid( classid *cid); |
---|
| 121 | }; |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | #endif /* _PacketManager_H__ */ |
---|