-
Notifications
You must be signed in to change notification settings - Fork 6
/
cMessage.cpp
64 lines (52 loc) · 1.4 KB
/
cMessage.cpp
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
#include "stdafx.h"
#include "cMessage.h"
cMessage::cMessage(BYTE *pbData, const stFragmentHeader *Header)
{
m_dwSequence = Header->m_dwSequence;
m_dwID = Header->m_dwID;
m_wGroup = Header->m_wGroup;
m_wCount = Header->m_wCount;
m_pbData = new BYTE[m_wCount * 0x1C0];
m_pbReceived = new bool[m_wCount];
memset(m_pbReceived, 0, sizeof(bool) * m_wCount);
m_wSize = 0;
AddChunk(pbData, Header->m_wSize - sizeof(stFragmentHeader), Header->m_wIndex);
}
cMessage::~cMessage()
{
if (m_pbData) {
delete []m_pbData;
m_pbData = NULL;
}
if (m_pbReceived) {
delete []m_pbReceived;
m_pbReceived = NULL;
}
}
void cMessage::AddChunk(BYTE *pbData, int iSize, int iIndex)
{
memcpy(&m_pbData[iIndex * 0x1C0], pbData, iSize);
m_pbReceived[iIndex] = true;
if ( iIndex == (m_wCount - 1) )
{
m_wSize = ((m_wCount - 1) * 0x1C0) + iSize;
}
else if (iSize < 0x1C0)
{
//Size should never be less than 0x1C0 if it isn't the last chunk
MessageBox(NULL, "This should never happen", "Fragment bug!!", MB_OK);
}
SetStream(m_pbData, m_wSize);
}
bool cMessage::IsComplete(void)
{
for (int i = 0; i < m_wCount; i++)
{
if (m_pbReceived[i] != true) { return false; }
}
return true;
}
int cMessage::GetChunkCount() { return m_wCount; }
int cMessage::GetLength() { return m_wSize; }
BYTE *cMessage::GetData() { return m_pbData; }
BYTE *cMessage::GetChunk(int iIndex){ return m_pbData + (0x1C0 * iIndex); }