This commit is contained in:
MarcEricMartel
2023-11-01 09:19:26 -04:00
parent e5d9eb2fa6
commit 88acc268b8
2 changed files with 41 additions and 42 deletions

View File

@@ -31,6 +31,8 @@ namespace netprot {
PACKET_TYPE type = PACKET_TYPE::ERR;
};
inline const char Footer[sizeof(uint32_t)] = { '\0', '\r', '\0', '\n' };
struct Keys {
bool forward,
backward,
@@ -165,39 +167,37 @@ namespace netprot {
template <class T>
void sendPack(SOCKET sock, T* pack, char** buf, uint32_t* buflen) {
netprot::Serialize(pack, buf, buflen);
memset(&buf[*buflen], '\0', sizeof(uint64_t) + sizeof(uint8_t));
buflen += (sizeof(uint64_t) + sizeof(uint8_t));
memcpy(*buf + *buflen, Footer, sizeof(uint32_t));
*buflen += sizeof(Footer);
send(sock, *buf, *buflen, 0);
*buflen = BUFFER_LENGTH;
}
template <class T>
void sendPackTo(SOCKET sock, T* pack, char** buf, uint32_t* buflen, sockaddr_in* sockad) {
sockaddr_in addr = *sockad;
const sockaddr_in addr = *sockad;
netprot::Serialize(pack, buf, buflen);
memset(&buf[*buflen], '\0', sizeof(uint64_t) + sizeof(uint8_t));
buflen += (sizeof(uint64_t) + sizeof(uint8_t));
memcpy(*buf + *buflen, Footer, sizeof(uint32_t));
*buflen += sizeof(Footer);
sendto(sock, *buf, *buflen, 0, (sockaddr*)&addr, sizeof(addr));
*buflen = BUFFER_LENGTH;
}
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);
memcpy(&buf->ptr[buf->len], footer, sizeof(uint32_t));
buf->len += sizeof(uint32_t);
memcpy(&buf->ptr[buf->len], Footer, sizeof(uint32_t));
buf->len += sizeof(Footer);
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;
const sockaddr_in addr = *sockad;
netprot::Serialize(pack, &buf->ptr, &buf->len);
memcpy(&buf->ptr[buf->len], footer, sizeof(uint32_t));
buf->len += sizeof(uint32_t);
memcpy(&buf->ptr[buf->len], Footer, sizeof(uint32_t));
buf->len += sizeof(Footer);
sendto(sock, buf->ptr, buf->len, 0, (sockaddr*)&addr, sizeof(addr));
buf->rstLen();
}