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

serverpacket.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 SERVERPACKET_H
00024 #define SERVERPACKET_H
00025 
00026 #include "../common/frameworkpacket.h"
00027 #include "client.h"
00028 
00029 template<class PacketType>
00030 class Plugin;
00031 class ServerData;
00032 
00033 /**
00034  * @ingroup Server
00035  * @brief This packet is used from the server-side when sending/receiving packets.
00036  *
00037  * @author Lars Langer and Emanuel Greisen
00038 */
00039 class ServerPacket : public FrameworkPacket
00040 {
00041 public:
00042    Client * client;
00043 
00044 private:
00045    ServerPacket(unsigned int receiver,unsigned char type=4,unsigned char priority=0,unsigned int bodysize=INITIAL_BODY_SIZE, bool reliable=false);
00046 public:
00047    /// Constructor used when receiving packets.
00048    ServerPacket(char * data, unsigned int size);
00049 
00050    ServerPacket(const ServerData * fdata,unsigned char type,unsigned char priority,bool reliable);
00051    ~ServerPacket();
00052 
00053 public:
00054    /// This will init a "Create-object" packet
00055    static ServerPacket * initCreateObjectPacket(const ServerData * fdata, unsigned char prio);
00056    /// This will init a "Destroy-object" packet
00057    static ServerPacket * initDestroyObjectPacket(const ServerData * fdata, unsigned char prio);
00058    /// Used to ack packets
00059    static ServerPacket * createAckPacket( ServerPacket * packet );
00060    /// Will create an empty dummy packet ready for writing into.
00061    static ServerPacket * createDummyPacket();
00062    /// Will create a system packet.
00063    static ServerPacket * createSystemPacket( FrameworkPacket::SpecialReceivers receiver );
00064    /// Will create a plugin packet from a plugin.
00065    static ServerPacket * createPluginPacket( const Plugin<ServerPacket> * plugin, const ServerPacket * packet);
00066 
00067 public:
00068    /// This method makes the packet ready for sending (htonl(...) is called on header fields).
00069    void makeSendReady();
00070    /// Will return the id of the client for whom this packet is to/from.
00071    unsigned int getUserID() const { return client ? client->getId() : 0; }; // If we have no receiver, we just return 0
00072 
00073 ///@name Writers
00074 ///@throws PacketError is thrown if you try to write beyond the hard-coded max-size of the packet.
00075 /// <p>
00076 /// The following methods are used when writing to a packet.
00077 ///@{
00078 public:
00079    void writePtr( const ServerData * obj );
00080    void writeObject( const ServerData * obj );
00081 ///@}
00082 
00083 ///@name Readers
00084 ///@throws PacketError is thrown if you try to read beyond the size of the packet.
00085 /// <p>
00086 /// The following methods are used when reading from a packet.
00087 ///@{
00088 public:
00089    /// This method will create a new packet of size psize from current possition.
00090    ServerPacket * readPacket(unsigned int psize);
00091 ///@}
00092 
00093 };
00094 
00095 #endif

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