*guttural scream*

This commit is contained in:
MarcEricMartel
2023-11-01 06:12:38 -04:00
parent 48078182a1
commit 88a8553608
4 changed files with 41 additions and 34 deletions

View File

@@ -531,25 +531,7 @@ bool netprot::Deserialize(Output* out, char* buf, uint32_t *buflen) {
memcpy(&out->direction, vec, sizeof(uint32_t) * 3);
uint8_t subvec[3 * sizeof(uint32_t)] = { 0,0,0,0,0,0,0,0,0,0,0,0 };
memcpy(subvec, &buf[2 + sizeof(uint64_t) * 2 + sizeof(uint32_t) * 3], sizeof(uint8_t) * 12);
uint32_t vec[3] = {
(uint32_t)subvec[0] << 24 |
(uint32_t)subvec[1] << 16 |
(uint32_t)subvec[2] << 8 |
(uint32_t)subvec[3],
(uint32_t)subvec[4] << 24 |
(uint32_t)subvec[5] << 16 |
(uint32_t)subvec[6] << 8 |
(uint32_t)subvec[7],
(uint32_t)subvec[8] << 24 |
(uint32_t)subvec[9] << 16 |
(uint32_t)subvec[10] << 8 |
(uint32_t)subvec[11] };
memcpy(&out->direction, vec, sizeof(uint32_t) * 3);
memcpy(subvec, &buf[2 + sizeof(uint64_t) * 2 + sizeof(uint32_t) * 6], sizeof(uint8_t) * 12);
uint32_t vec2[3] = {
(uint32_t)subvec[0] << 24 |
(uint32_t)subvec[1] << 16 |
@@ -971,9 +953,8 @@ netprot::Packet netprot::makePack(void* ptr, PACKET_TYPE type) {
std::vector<char*> netprot::recvPacks(SOCKET sock, Buffer* buf) {
std::vector<char*> lsPck;
int len = 0, end = 0;
bool pck_received = false;
char * cursor = nullptr, * next = buf->ptr, * last = buf->ptr;
const char footer[sizeof(uint64_t) + sizeof(uint8_t)] = { '\0', '\0', '\0', '\0', '\0' };
const char footer[sizeof(uint32_t)] = { '\0', '\r', '\0', '\n' };
while (true) {
int bytes = recv(sock, &buf->ptr[len], buf->len - len, 0);
@@ -982,6 +963,23 @@ std::vector<char*> netprot::recvPacks(SOCKET sock, Buffer* buf) {
len += bytes;
end = len;
for (int x = 0; x < len; ++x)
switch (buf->ptr[x]) {
case '\0':
std::putchar('n');
break;
case '\r':
std::putchar('i');
break;
case '\n':
std::putchar('a');
break;
default:
std::putchar(buf->ptr[x]);
break;
}
std::puts("");
while (true) {
int cmp = 0;
@@ -991,14 +989,16 @@ std::vector<char*> netprot::recvPacks(SOCKET sock, Buffer* buf) {
if (end < 0)
break;
cursor = (char*)memchr(next, '\0', end);
next = cursor + 1;
cursor = (char*)memchr(next, '\r', end);
if (cursor) {
cmp = memcmp(cursor, &footer, sizeof(uint64_t) + sizeof(uint8_t));
cursor--;
next = cursor + 1;
cmp = memcmp(cursor, footer, sizeof(uint32_t));
if (cmp == 0) {
lsPck.push_back(last);
cursor += sizeof(uint64_t) + sizeof(uint8_t);
cursor += sizeof(uint32_t);
last = cursor;
next = cursor + 1;
}
@@ -1010,9 +1010,6 @@ std::vector<char*> netprot::recvPacks(SOCKET sock, Buffer* buf) {
};
}
}
for (int x = 0; x < buf->len; ++x)
std::putchar(buf->ptr[x]);
std::puts("");
}
template <>