| [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> |
|---|
| 35 | #include <enet/enet.h> |
|---|
| 36 | |
|---|
| 37 | #include "core/CoreIncludes.h" |
|---|
| 38 | |
|---|
| 39 | #define CLIENTID_CLIENT -1 |
|---|
| [1360] | 40 | #define NETWORK_CRC32POLY 0x04C11DB7 /* CRC-32 Polynom */ |
|---|
| [1232] | 41 | |
|---|
| 42 | //enum netowk generally used to set the type ID of a packet |
|---|
| 43 | namespace network |
|---|
| 44 | { |
|---|
| 45 | /* |
|---|
| 46 | * class to generate packets |
|---|
| 47 | * |
|---|
| 48 | * @autor: Dumeni Manatschal |
|---|
| 49 | * |
|---|
| 50 | */ |
|---|
| [1360] | 51 | //void calcCRC(uint32_t &crc32, int bit); |
|---|
| 52 | uint32_t calcCRC(unsigned char *data, unsigned int dataLength); |
|---|
| 53 | |
|---|
| [1232] | 54 | class PacketGenerator |
|---|
| 55 | { |
|---|
| 56 | public: |
|---|
| 57 | PacketGenerator(); |
|---|
| 58 | //call one of this functions out of an instance of PacketGenerator to create a packet |
|---|
| [1360] | 59 | ENetPacket* acknowledgement( int state, int reliable = 0 ); // we do not want reliability |
|---|
| [1232] | 60 | ENetPacket* command( int dataLength, void *data, int reliable = ENET_PACKET_FLAG_RELIABLE ); |
|---|
| 61 | ENetPacket* mousem( double x, double y, int reliable = ENET_PACKET_FLAG_RELIABLE ); |
|---|
| 62 | ENetPacket* keystrike( char press, int reliable = ENET_PACKET_FLAG_RELIABLE ); |
|---|
| 63 | ENetPacket* chatMessage( const char* message, int reliable = ENET_PACKET_FLAG_RELIABLE ); |
|---|
| [1360] | 64 | ENetPacket* gstate( GameStateCompressed *states, int reliable = 0 ); // we do not want reliability of gamestates |
|---|
| [1232] | 65 | ENetPacket* clid( int classid, std::string classname, int reliable = ENET_PACKET_FLAG_RELIABLE ); |
|---|
| 66 | ENetPacket* generateWelcome( int clientID,int shipID, bool allowed, int reliable = ENET_PACKET_FLAG_RELIABLE ); |
|---|
| 67 | ENetPacket* generateConnectRequest( int reliable = ENET_PACKET_FLAG_RELIABLE ); |
|---|
| 68 | private: |
|---|
| [1360] | 69 | bool addCRC( ENetPacket *packet); |
|---|
| [1232] | 70 | }; |
|---|
| 71 | |
|---|
| 72 | /* |
|---|
| 73 | * class used to decode incoming packets |
|---|
| 74 | * |
|---|
| 75 | * @autor: Dumeni Manatschal |
|---|
| 76 | * |
|---|
| 77 | */ |
|---|
| 78 | class _NetworkExport PacketDecoder |
|---|
| 79 | { |
|---|
| 80 | public: |
|---|
| 81 | PacketDecoder(); |
|---|
| 82 | virtual ~PacketDecoder(); |
|---|
| 83 | //call this function to decode, it calls the right decoding function below |
|---|
| 84 | bool elaborate( ENetPacket* packet, int clientId ); |
|---|
| 85 | protected: |
|---|
| 86 | |
|---|
| 87 | virtual void processChat( chat *data, int clientId); |
|---|
| 88 | |
|---|
| 89 | |
|---|
| 90 | private: |
|---|
| [1360] | 91 | bool testAndRemoveCRC(ENetPacket *packet); |
|---|
| [1232] | 92 | |
|---|
| 93 | |
|---|
| 94 | void acknowledgement( ENetPacket* packet, int clientId = CLIENTID_CLIENT ); |
|---|
| 95 | bool command( ENetPacket* packet, int clientId ); |
|---|
| 96 | void mousem( ENetPacket* packet, int clientId = CLIENTID_CLIENT ); |
|---|
| 97 | void keystrike( ENetPacket* packet, int clientId = CLIENTID_CLIENT ); |
|---|
| [1245] | 98 | void chatMessage( ENetPacket* packet, int clientId = CLIENTID_CLIENT ); |
|---|
| 99 | void gstate( ENetPacket* packet, int clientID = CLIENTID_CLIENT ); |
|---|
| [1232] | 100 | void clid( ENetPacket *packet); |
|---|
| 101 | bool decodeWelcome( ENetPacket* packet, int clientID = CLIENTID_CLIENT ); |
|---|
| 102 | bool decodeConnectRequest( ENetPacket *packet, int clientID = CLIENTID_CLIENT ); |
|---|
| 103 | |
|---|
| 104 | //process data |
|---|
| 105 | //two functions are note yet implemented! |
|---|
| [1245] | 106 | virtual void processGamestate(GameStateCompressed *state, int clientID); |
|---|
| [1232] | 107 | virtual void processAck( ack *data, int clientID); |
|---|
| 108 | virtual void processClassid( classid *cid); |
|---|
| 109 | virtual bool processWelcome( welcome *w ); |
|---|
| 110 | virtual bool processConnectRequest( connectRequest *con, int clientID ); |
|---|
| 111 | //virtual void processAck( ack *data); |
|---|
| 112 | |
|---|
| 113 | //print functions |
|---|
| 114 | void printAck( ack* data ); |
|---|
| 115 | void printMouse( mouse* data ); |
|---|
| 116 | void printKey( keyboard* data ); |
|---|
| 117 | void printChat( chat* data, int clientId ); |
|---|
| 118 | void printGamestate( GameStateCompressed *data ); |
|---|
| 119 | void printClassid( classid *cid); |
|---|
| 120 | }; |
|---|
| 121 | } |
|---|
| 122 | |
|---|
| 123 | #endif /* _PacketManager_H__ */ |
|---|