Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | Related Pages | Examples

clientpacket.h

00001 /***************************************************************************
00002  * The contents of this file are subject to the Mozilla Public             *
00003  * License Version 1.1 (the "License"); you may not use this file          *
00004  * except in compliance with the License. You may obtain a copy of         *
00005  * the License at http://www.mozilla.org/MPL/                              *
00006  *                                                                         *
00007  * Software distributed under the License is distributed on an "AS         *
00008  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or              *
00009  * implied. See the License for the specific language governing            *
00010  * rights and limitations under the License.                               *
00011  *                                                                         *
00012  * The Original Code is Game Network Framework (GaNeF).                    *
00013  *                                                                         *
00014  * The Initial Developers of the Original Code are                         *
00015  * Lars Langer and Emanuel Greisen                                         *
00016  * Copyright (C) 2005. Lars Langer & Emanuel Greisen                       *
00017  * All Rights Reserved.                                                    *
00018  *                                                                         *
00019  * Contributor(s):                                                         *
00020  *   none yet....                                                          *
00021  *                                                                         *
00022  ***************************************************************************/
00023 #ifndef CLIENTPACKET_H
00024 #define CLIENTPACKET_H
00025 
00026 #include "../common/frameworkpacket.h"
00027 
00028 template<class PacketType>
00029 class Plugin;
00030 
00031 class ClientFramework;
00032 class ClientData;
00033 
00034 /**
00035  * @ingroup Client
00036  * @brief This packet is used from the client-side when sending/receiving packets.
00037  *
00038  * @author Lars Langer and Emanuel Greisen
00039  */
00040 class ClientPacket : public FrameworkPacket
00041 {
00042 private:
00043    ClientFramework * framework;
00044 
00045 protected:
00046    /// Constructor used when client-data is signaling back.
00047    ClientPacket(ClientFramework * f, unsigned int receiver, unsigned char type=4, unsigned char priority=1, unsigned int bodysize=INITIAL_BODY_SIZE, bool reliable=false);
00048 
00049 public:
00050    /// Constructor used when receiving packets.
00051    ClientPacket(char * data, unsigned int size);
00052    /// Constructor used when client-data is signaling back.
00053    ClientPacket(const ClientData * fdata, unsigned char type=4, unsigned char priority=1, bool reliable=false);
00054    ~ClientPacket();
00055 
00056 public:
00057    /// This will create an ack-packet.
00058    static ClientPacket * createAckPacket(ClientPacket * packet);
00059    static ClientPacket * createDummyPacket( );
00060    static ClientPacket * createSystemPacket(ClientFramework * f, FrameworkPacket::SpecialReceivers receiver );
00061    /// Will create a plugin packet from a plugin.
00062    static ClientPacket * createPluginPacket( const Plugin<ClientPacket> * plugin, const ClientPacket * _packet );
00063 
00064 
00065 
00066 public:
00067    /// This method makes the packet ready for sending (htonl(...) is called on header fields).
00068    void makeSendReady();
00069    /// Will return the ID of the user for whom that packet is from/to.
00070    unsigned int getUserID() const { return 0; }; // The server has 0 as id
00071 
00072 ///@name Readers
00073 ///@throws PacketError is thrown if you try to read beyond the size of the packet.
00074 /// <p>
00075 /// The following methods are used when reading from a packet.
00076 ///@{
00077 public:
00078    /// The class T must be a subclass of ClientData.
00079    template<class T>
00080    void readPtr(ClientData * receiver, T ** ptrptr, ClientFramework * framework);
00081    /// The class T must be a subclass of ClientData.
00082    template<class T>
00083    T * readObject(ClientFramework * f);
00084    /// This method will create a new packet of size psize from current possition.
00085    ClientPacket * readPacket(unsigned int psize);
00086    ///@}
00087 
00088 };
00089 
00090 #endif

Generated on Mon Feb 6 12:24:50 2006 for Ganef by  doxygen 1.4.4