*guttural scream*
This commit is contained in:
@@ -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 <>
|
||||
|
@@ -183,19 +183,21 @@ namespace netprot {
|
||||
|
||||
template <class T>
|
||||
void sendPack(SOCKET sock, T* pack, Buffer* buf) {
|
||||
const char footer[sizeof(uint32_t)] = { '\0', '\r', '\0', '\n' };
|
||||
netprot::Serialize(pack, &buf->ptr, &buf->len);
|
||||
memset(&buf->ptr[buf->len], '\0', sizeof(uint64_t) + sizeof(uint8_t));
|
||||
buf->len += sizeof(uint64_t) + sizeof(uint8_t);
|
||||
memcpy(&buf->ptr[buf->len], footer, sizeof(uint32_t));
|
||||
buf->len += sizeof(uint32_t);
|
||||
send(sock, buf->ptr, buf->len, 0);
|
||||
buf->rstLen();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void sendPackTo(SOCKET sock, T* pack, Buffer* buf, sockaddr_in* sockad) {
|
||||
const char footer[sizeof(uint32_t)] = { '\0', '\r', '\0', '\n' };
|
||||
sockaddr_in addr = *sockad;
|
||||
netprot::Serialize(pack, &buf->ptr, &buf->len);
|
||||
memset(&buf->ptr[buf->len], '\0', sizeof(uint64_t) + sizeof(uint8_t));
|
||||
buf->len += sizeof(uint64_t) + sizeof(uint8_t);
|
||||
memcpy(&buf->ptr[buf->len], footer, sizeof(uint32_t));
|
||||
buf->len += sizeof(uint32_t);
|
||||
sendto(sock, buf->ptr, buf->len, 0, (sockaddr*)&addr, sizeof(addr));
|
||||
buf->rstLen();
|
||||
}
|
||||
|
Reference in New Issue
Block a user