#ifndef _PACKET_BASE #define _PACKET_BASE //////////////////////////////////////////////////////////////////////////////////////////////////// // // ¼­¹öÀÇ ¹öÆÛ¸µ »óÅ // // SS_SMOOTH : ¿øÈ°ÇÑ ¼ÒÅë ÁßÀÓ. // SS_LOADED : ¾à°£ÀÇ ºÎÇϰ¡ ÀÖ½¿. (50 % of bufferring) // SS_BUSY : °úÁßÇÑ ºÎÇϰ¡ ÀÖ½¿. (70 % of bufferring) // SS_VERYBUSY : ±Ø½ÉÇÑ °úºÎÇÏ »óÅÂÀÓ (ÆÐŶ ¼Õ½ÇÀ» ÃÊ·¡ÇÒ ¼ö ÀÖ½¿.) // //////////////////////////////////////////////////////////////////////////////////////////////////// union ServerInfo { enum ServerState { SS_SMOOTH, SS_LOADED, SS_BUSY, SS_VERYBUSY }; struct sSrvState { unsigned short wError; // ¿¡·¯ ÄÚµå unsigned short wSrvState; // ¼­¹ö »óÅ }; sSrvState SrvState; unsigned long dwServerInfo; }; //////////////////////////////////////////////////////////////////////////////////////////////////// // ±âº» ÆÐŶ #pragma pack(1) struct PktBase { enum PktBaseErr { NO_SERVER_ERR = 0, SERVER_ERROR = 1 }; typedef unsigned char StartType; typedef unsigned char CMDType; typedef unsigned short LengthType; protected: StartType m_StartBit; CMDType m_Cmd; LengthType m_Len; // Çì´õ ±æÀ̸¦ Æ÷ÇÔÇÑ ÆÐŶ ±æÀÌ unsigned long m_CodePage; ServerInfo m_SrvInfo; public: inline void InitPtHead(unsigned short Len_In, unsigned char Cmd_In, unsigned short State_In, unsigned short Error_In); inline void InitPtHead(unsigned short Len_In, unsigned char Cmd_In, unsigned long Tick_In); inline void SetError(unsigned short Error) { m_SrvInfo.SrvState.wError = Error; } inline unsigned short GetError(void) { return m_SrvInfo.SrvState.wError; } inline unsigned short GetState(void) { return m_SrvInfo.SrvState.wSrvState; } inline StartType GetStartBit(void) { return m_StartBit; } inline void SetCodePage(unsigned long Code) { m_CodePage = Code; } inline unsigned long GetCodePage(void) { return m_CodePage; } inline void SetServerInfo(unsigned long Info) { m_SrvInfo.dwServerInfo = Info; } inline unsigned long GetServerInfo(void) { return m_SrvInfo.dwServerInfo; } inline CMDType GetCmd(void) const { return m_Cmd; } inline bool IsCrypt(void); inline void SetCrypt(void); inline bool IsCompress(void); inline void SetCompress(void); inline LengthType GetUncompressLen(void); inline void SetLen(LengthType Len); inline LengthType GetLen(void); }; typedef PktBase* LPPktBase; // ¿©·¯°³¸¦ ¾ÐÃàÇØ¼­ º¸³¾ ¶§ »ç¿ëÇÏ´Â ÆÐŶ Çì´õ. struct PktBlockCompressedBase { public: unsigned short GetLength() const { return m_usLength; } unsigned char GetCmd() const { return m_cCommand; } unsigned char GetExtra() const { return m_cExtra; } void InitPtHead(unsigned short usLength, unsigned char cCmd, unsigned char cExtra) { m_usLength = usLength; m_cCommand = cCmd; m_cExtra = cExtra; } protected: unsigned short m_usLength; unsigned char m_cCommand; unsigned char m_cExtra; }; #pragma pack() const unsigned int PktBaseSize = sizeof(PktBase); const PktBase::StartType StartBit = 0xFF; // ½ÃÀÛ ºñÆ® const PktBase::LengthType Crypt = 0x8000; // ¾Ïȣȭ ¿©ºÎ - 1000B const PktBase::LengthType Compress = 0x4000; // ¾ÐÃà ¿©ºÎ - 0100B const PktBase::LengthType LengthHdr = 0xC000; // 1100B const PktBase::LengthType LengthMask = 0x3FFF; // ½ÇÁ¦ ±æÀÌ ¾ò¾î³»´À ¸¶½ºÅ© °ª. ÀüºÎ 14ºñÆ®. ÃÖ´ë 16383byte. const PktBase::LengthType PktMinLen = sizeof(PktBase); const PktBase::LengthType PktMaxLen = 16383; const PktBase::LengthType MIN_PACKET_LEN = sizeof(PktBase); const PktBase::LengthType MAX_PACKET_LEN = 16383; inline bool PktBase::IsCrypt(void) { return ((m_Len & Crypt) == Crypt) ? true : false; } inline void PktBase::SetCrypt(void) { m_Len |= Crypt; } inline bool PktBase::IsCompress(void) { return ((m_Len & Compress) == Compress) ? true : false; } inline void PktBase::SetCompress(void) { m_Len |= Compress; } inline PktBase::LengthType PktBase::GetUncompressLen(void) { return PktMaxLen; } inline void PktBase::SetLen(PktBase::LengthType Len) { m_Len = (m_Len & LengthHdr) | Len; } inline PktBase::LengthType PktBase::GetLen(void) { return m_Len & LengthMask; } //Interface///////////////////////////////////////////////////////////////////////////////////// // // ÆÐŶ ÇØ´õ ÃʱâÈ­ // // Parameter : // 1st : ±æÀÌ[In] // 2st : Ä¿¸Çµå[In] // 3st : ¼­¹ö »óÅÂ[In] // 4st : ¿¡·¯[In] // // Return : // /////////////////////////////////////////////////////////////////////////////////////////////// inline void PktBase::InitPtHead(unsigned short Len_In, unsigned char Cmd_In, unsigned short State_In, unsigned short Error_In) { m_StartBit = StartBit; m_Cmd = Cmd_In; m_Len = Len_In; m_CodePage = 0; m_SrvInfo.SrvState.wSrvState = State_In; m_SrvInfo.SrvState.wError = Error_In; } inline void PktBase::InitPtHead(unsigned short Len_In, unsigned char Cmd_In, unsigned long Tick_In) { m_StartBit = StartBit; m_Cmd = Cmd_In; m_Len = Len_In; m_CodePage = 0; m_SrvInfo.dwServerInfo = Tick_In; } #endif