SDC C-Project CF Review 프로그램
kojingeun
2023-11-24 c112cf54a238afa473e7eb0ea6298e06f4957658
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#pragma once
 
#include <winsock2.h>
#define PACKET_HEADERSIZE        (sizeof(int) * 3 + sizeof(SHORT) * 4)    
 
class AFX_EXT_CLASS CNetPacket  
{
public:
    CNetPacket();
    CNetPacket(const CNetPacket* rhs);
    virtual ~CNetPacket();
 
    //////////////////////////////////////////////////////////////////////////
    // Packet Header
    void        SetVersion(SHORT sNetworkCode, SHORT sVersion);
    void        SetPacketCode(int nCode)    { m_nPacketCode = nCode; }
    void        SetModuleNo(int nModuleNo)    { m_nModuleNo = nModuleNo; }
    int            Read_PacketHeader(WSABUF* pWsaBuf);
    int            Read_PacketBody(char* pBuf);
 
    // º¯¼ö¿¡ Á¢±Ù
    int            GetSize() const                    { return m_nSize; }
    SHORT        GetNetworkCode() const            { return m_sNetworkCode; }
    SHORT        GetVersion() const                { return m_sVersion; }
    int            GetPacketCode() const            { return m_nPacketCode; }
    int            GetResult() const                { return m_sResult; }
    int            GetPacketIndex() const            { return m_sPacketIndex; }
    int            GetModuleNo() const                { return m_nModuleNo; }
 
    //////////////////////////////////////////////////////////////////////////
    // Packet Body
    void        ResetValues();
        
    BOOL        SetShort(short sValue);
    BOOL        SetInt(int nValue);
    BOOL        SetDouble(double dValue);
    BOOL        SetString(const CString& strString);
    BOOL        SetBuffer(int nSize, const char* pBuffer);
 
    int            GetShortCount()                { return m_nShortCount; }
    int            GetIntCount()                { return m_nIntCount; }
    int            GetDoubleCount()            { return m_nDoubleCount; }
    int            GetStringCount()            { return m_nStringCount; }
    int            GetBufferSize()                { return m_nBufferSize; }
 
    short        GetShort(int nIdx) const;
    int            GetInt(int nIdx) const;
    double        GetDouble(int nIdx) const;
    CString        GetString(int nIdx) const;
    const char*    GetBuffer()  const;
 
    //////////////////////////////////////////////////////////////////////////
    // °ü¸® ÇÔ¼öµé
    void        UnlockPacket()                { m_bUsing = FALSE; }
    BOOL        IsUsing() const                { return m_bUsing; }
    void        LockPacket()                { m_bUsing = TRUE; }
protected:
    BOOL        m_bUsing;
 
    //////////////////////////////////////////////////////////////////////////
    // Packet Header ºÎºÐ
    int            m_nSize;                // Size¸¦ Æ÷ÇÔÇÑ Àüü ÆÐŶ Å©±â            4 bytes
    SHORT        m_sNetworkCode;            // Program Code * 10 + Network Code        2 bytes
    SHORT        m_sVersion;                // Network Module Version                2 bytes
    int            m_nPacketCode;            // Packet Code  4 bytes
    SHORT        m_sPacketIndex;            // ¿©·¯ PacketÀÏ ¶§ÀÇ Index                2 bytes
    SHORT        m_sResult;                // Result - ´Ü¼ø Ack µîÀ» À§ÇÑ ¿¹¾à°ø°£    2 bytes
    int            m_nModuleNo;            // Module Number                        4 bytes
 
    SHORT        m_sSetNetworkCode;        // Program Code * 10 + Network Code        2 bytes
    SHORT        m_sSetVersion;            // Network Module Version                2 bytes
 
    //////////////////////////////////////////////////////////////////////////
    // Packet Body ºÎºÐ
    int            m_nShortCount;
    int            m_nShortArraySize;
    short*        m_psShort;
 
    int            m_nIntCount;
    int            m_nIntArraySize;
    int*        m_pnInt;
 
    int            m_nDoubleCount;
    int            m_nDoubleArraySize;
    double*        m_pdDouble;
 
    int            m_nStringCount;
    int            m_nStringArraySize;
    CString*    m_pstrString;
 
    int            m_nBufferSize;
    char*        m_pBuffer;
};