forked from derandark/PhatAC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFragStack.cpp
69 lines (54 loc) · 1.28 KB
/
FragStack.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
64
65
66
67
68
#include "StdAfx.h"
#include "FragStack.h"
FragmentStack::FragmentStack(FragPacket_s *frag)
{
FragHeader_s *header = &frag->header;
m_dwSequence = header->dwSequence;
m_dwID = header->dwID;
m_wGroup = header->wGroup;
m_wCount = header->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;
AddFragment(frag);
}
FragmentStack::~FragmentStack()
{
SafeDeleteArray(m_pbData);
SafeDeleteArray(m_pbReceived);
}
void FragmentStack::AddFragment(FragPacket_s *frag)
{
BYTE* data = frag->data;
DWORD datalen = frag->header.wSize - sizeof(FragHeader_s);
WORD index = frag->header.wIndex;
WORD count = frag->header.wCount;
memcpy(&m_pbData[index * 0x1C0], data, datalen);
m_pbReceived[index] = true;
if (index == (count - 1))
{
m_wSize = (WORD) (((count - 1) * 0x1C0) + datalen);
}
else if (datalen < 0x1C0)
{
//Size should never be less than 0x1C0 if it isn't the last chunk
LOG(Temp, Normal, "This should never happen\n");
}
}
bool FragmentStack::IsComplete(void)
{
for (int i = 0; i < m_wCount; i++)
{
if (m_pbReceived[i] != true) { return false; }
}
return true;
}
int FragmentStack::GetLength(void)
{
return m_wSize;
}
BYTE *FragmentStack::GetData(void)
{
return m_pbData;
}