Main Page Modules Namespace List Class Hierarchy Alphabetical List Compound List File List Namespace Members Compound Members File Members Related Pages

# dePacket.hpp

Go to the documentation of this file.

    00001 ///////////////////////////////////////////////////////////////////////////////
    00002 /// @file dePacket.hpp
    00003 ///
    00004 /// @brief
    00005 ///
    00006 /// @author trajar
    00007 ///
    00008 /// This file is the intellectual property of Novus Delta, LLC.. Usage of the
    00009 /// contents of this file is subject to the Destiny3D Member License which
    00010 /// can be found at http://www.destiny3d.com.  Any other usage is prohibited.
    00011 ///
    00012 /// This file is distributed "AS IS" without warranty of any kind.  Novus
    00013 /// Delta, LLC. does not guarantee the fitness of the contents of this file
    00014 /// for any particular purpose.
    00015 ///
    00016 /// Copyright (C) 2001-2003 Novus Delta, LLC. All Rights Reserved.
    00017 ///
    00018 /// <hr>
    00019 ///                                 Change History
    00020 /// <hr>
    00021 ///
    00022 /// @date Jun 2002
    00023 /// @author trajar
    00024 /// @remarks Creation
    00025 ///
    00026 ///////////////////////////////////////////////////////////////////////////////
    00027
    00028 #ifndef _DEPACKET_HPP
    00029 #define _DEPACKET_HPP
    00030
    00031 #ifndef     _DENET_HPP
    00032  #include   "deNet.hpp"
    00033 #endif
    00034
    00035 #ifndef     _DENETMSG_HPP
    00036  #include   "deNetMsg.hpp"
    00037 #endif
    00038
    00039 class DENET_API dePacket
    00040 {
    00041 public:
    00042
    00043     // packet flags
    00044     enum eFlag
    00045     {
    00046         PACKET_SEND_RECP_CONFIRMATION   =   0x01,
    00047         PACKET_FRAGMENT_BEGIN           =   0x02,
    00048         PACKET_FRAGMENT_END             =   0x04,
    00049         PACKET_FRAGMENT                 =   0x06, // (0x2|0x4)
    00050     };
    00051
    00052     // public packet header
    00053     struct PacketHeader
    00054     {
    00055         hNetUser    Recipient;
    00056         BYTE        Type;
    00057         BYTE        Flags;
    00058
    00059         union
    00060         {
    00061             struct
    00062             {
    00063                 hNetUser    Sender;
    00064                 WORD        LocalID;
    00065             };
    00066
    00067             DWORD           ID;
    00068         };
    00069         WORD        NetMsgID;
    00070         WORD        SubID;
    00071         DWORD       Size;
    00072         DWORD       TotalSize;
    00073     };
    00074
    00075     dePacket(void);
    00076     dePacket( const BYTE * pData, DWORD dwFlags = NULL );
    00077     dePacket( const PacketHeader& pHeader, const void * m_Data, DWORD dwFlags = NULL );
    00078     virtual ~dePacket(void);
    00079
    00080     bool                NeedRecvConfirmation(void)  const { return m_Header.Flags & dePacket::PACKET_SEND_RECP_CONFIRMATION != 0; }
    00081     bool                IsFragmented(void)          const { return m_Header.Flags & dePacket::PACKET_FRAGMENT != 0; }
    00082     BYTE *              GetData(void)               const { return m_Data; }
    00083     const PacketHeader& GetHeader(void)             const { return m_Header; }
    00084
    00085     static dePacket *   SortPackets( dePacket * pPackets, int iNumPackets );
    00086     static dePacket *   ConsolidatePackets( const dePacket * pPackets, int iNumPackets );
    00087
    00088 protected:
    00089
    00090     BYTE *          m_Data;
    00091     PacketHeader    m_Header;
    00092
    00093 public:
    00094
    00095     static int ComparePacket( const void * l, const void * r );
    00096     friend bool operator !=     ( const dePacket& l, const dePacket& r ) {  return ( l.m_Header.ID != r.m_Header.ID );  }
    00097     friend bool operator ==		( const dePacket& l, const dePacket& r ) { return ( l.m_Header.ID == r.m_Header.ID );  }
    00098     friend bool operator >      ( const dePacket& l, const dePacket& r ) {  if( l.m_Header.ID == r.m_Header.ID ) return l.m_Header.SubID >  r.m_Header.SubID; else return l.m_Header.ID > r.m_Header.ID;  }
    00099     friend bool operator <      ( const dePacket& l, const dePacket& r ) {  if( l.m_Header.ID == r.m_Header.ID ) return l.m_Header.SubID <  r.m_Header.SubID; else return l.m_Header.ID < r.m_Header.ID;  }
    00100     dePacket& operator =        ( const dePacket& r );
    00101 };
    00102
    00103 #endif