[1056] | 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 | |
---|
[673] | 29 | #ifndef _PacketManager_H__ |
---|
| 30 | #define _PacketManager_H__ |
---|
[199] | 31 | |
---|
[1062] | 32 | #include "NetworkPrereqs.h" |
---|
| 33 | |
---|
[400] | 34 | #include <string> |
---|
[199] | 35 | #include <enet/enet.h> |
---|
| 36 | |
---|
[1021] | 37 | #include "core/CoreIncludes.h" |
---|
| 38 | |
---|
[440] | 39 | #define CLIENTID_CLIENT -1 |
---|
| 40 | |
---|
[777] | 41 | //enum netowk generally used to set the type ID of a packet |
---|
| 42 | namespace network |
---|
| 43 | { |
---|
| 44 | /* |
---|
| 45 | * class to generate packets |
---|
[1056] | 46 | * |
---|
[777] | 47 | * @autor: Dumeni Manatschal |
---|
[1056] | 48 | * |
---|
| 49 | */ |
---|
[777] | 50 | class PacketGenerator |
---|
| 51 | { |
---|
| 52 | public: |
---|
| 53 | PacketGenerator(); |
---|
| 54 | //call one of this functions out of an instance of PacketGenerator to create a packet |
---|
| 55 | ENetPacket* acknowledgement( int state, int reliable = ENET_PACKET_FLAG_RELIABLE ); |
---|
| 56 | ENetPacket* mousem( double x, double y, int reliable = ENET_PACKET_FLAG_RELIABLE ); |
---|
| 57 | ENetPacket* keystrike( char press, int reliable = ENET_PACKET_FLAG_RELIABLE ); |
---|
| 58 | ENetPacket* chatMessage( const char* message, int reliable = ENET_PACKET_FLAG_RELIABLE ); |
---|
| 59 | ENetPacket* gstate( GameStateCompressed *states, int reliable = ENET_PACKET_FLAG_RELIABLE ); |
---|
| 60 | ENetPacket* clid( int classid, std::string classname, int reliable = ENET_PACKET_FLAG_RELIABLE ); |
---|
| 61 | private: |
---|
| 62 | }; |
---|
[199] | 63 | |
---|
[777] | 64 | /* |
---|
| 65 | * class used to decode incoming packets |
---|
[1056] | 66 | * |
---|
[777] | 67 | * @autor: Dumeni Manatschal |
---|
[1056] | 68 | * |
---|
[777] | 69 | */ |
---|
| 70 | class _NetworkExport PacketDecoder |
---|
| 71 | { |
---|
| 72 | public: |
---|
| 73 | PacketDecoder(); |
---|
| 74 | virtual ~PacketDecoder(); |
---|
| 75 | //call this function to decode, it calls the right decoding function below |
---|
| 76 | bool elaborate( ENetPacket* packet, int clientId ); |
---|
| 77 | protected: |
---|
[415] | 78 | |
---|
[777] | 79 | virtual void processChat( chat *data, int clientId); |
---|
[415] | 80 | |
---|
[199] | 81 | |
---|
[777] | 82 | private: |
---|
| 83 | |
---|
| 84 | |
---|
| 85 | |
---|
| 86 | void acknowledgement( ENetPacket* packet, int clientId = CLIENTID_CLIENT ); |
---|
| 87 | void mousem( ENetPacket* packet, int clientId = CLIENTID_CLIENT ); |
---|
| 88 | void keystrike( ENetPacket* packet, int clientId = CLIENTID_CLIENT ); |
---|
| 89 | void chatMessage( ENetPacket* packet, int clientId = CLIENTID_CLIENT); |
---|
| 90 | void gstate( ENetPacket* packet ); |
---|
| 91 | void clid( ENetPacket *packet); |
---|
| 92 | |
---|
| 93 | //process data |
---|
| 94 | //two functions are note yet implemented! |
---|
| 95 | virtual void processGamestate(GameStateCompressed *state); |
---|
| 96 | virtual void processAck( ack *data, int clientID); |
---|
[1021] | 97 | virtual void processClassid( classid *cid); |
---|
[777] | 98 | //virtual void processAck( ack *data); |
---|
| 99 | |
---|
| 100 | //print functions |
---|
| 101 | void printAck( ack* data ); |
---|
| 102 | void printMouse( mouse* data ); |
---|
| 103 | void printKey( keyboard* data ); |
---|
| 104 | void printChat( chat* data, int clientId ); |
---|
| 105 | void printGamestate( GameStateCompressed *data ); |
---|
| 106 | void printClassid( classid *cid); |
---|
| 107 | }; |
---|
[199] | 108 | } |
---|
| 109 | |
---|
[673] | 110 | #endif /* _PacketManager_H__ */ |
---|