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

@@ -954,7 +954,6 @@ std::vector<char*> netprot::recvPacks(SOCKET sock, Buffer* buf) {
std::vector<char*> lsPck;
int len = 0, end = 0;
char * cursor = nullptr, * next = buf->ptr, * last = buf->ptr;
const char footer[sizeof(uint32_t)] = { '\0', '\r', '\0', '\n' };
while (true) {
int bytes = recv(sock, &buf->ptr[len], buf->len - len, 0);
@@ -978,7 +977,7 @@ std::vector<char*> netprot::recvPacks(SOCKET sock, Buffer* buf) {
cursor--;
next = cursor + 1;
cmp = memcmp(cursor, footer, sizeof(uint32_t));
cmp = memcmp(cursor, Footer, sizeof(uint32_t));
if (cmp == 0) {
lsPck.push_back(last);
cursor += sizeof(uint32_t);
@@ -996,45 +995,45 @@ std::vector<char*> netprot::recvPacks(SOCKET sock, Buffer* buf) {
}
template <>
void netprot::sendPack<netprot::Packet>(SOCKET sock, Packet* pack, char** buf, uint32_t* buflen) {
void netprot::sendPack<netprot::Packet>(SOCKET sock, Packet* pack, Buffer* buf) {
switch (pack->type) {
case PACKET_TYPE::INPUT:
sendPack<Input>(sock, (Input*)pack->ptr, buf, buflen);
sendPack<Input>(sock, (Input*)pack->ptr, buf);
return;
case PACKET_TYPE::OUTPUT:
sendPack<Output>(sock, (Output*)pack->ptr, buf, buflen);
sendPack<Output>(sock, (Output*)pack->ptr, buf);
return;
case PACKET_TYPE::SYNC:
sendPack<Sync>(sock, (Sync*)pack->ptr, buf, buflen);
sendPack<Sync>(sock, (Sync*)pack->ptr, buf);
return;
case PACKET_TYPE::TEAMINF:
sendPack<TeamInfo>(sock, (TeamInfo*)pack->ptr, buf, buflen);
sendPack<TeamInfo>(sock, (TeamInfo*)pack->ptr, buf);
return;
case PACKET_TYPE::PLAYINF:
sendPack<PlayerInfo>(sock, (PlayerInfo*)pack->ptr, buf, buflen);
sendPack<PlayerInfo>(sock, (PlayerInfo*)pack->ptr, buf);
return;
case PACKET_TYPE::LOGINF:
sendPack<LoginInfo>(sock, (LoginInfo*)pack->ptr, buf, buflen);
sendPack<LoginInfo>(sock, (LoginInfo*)pack->ptr, buf);
return;
case PACKET_TYPE::CHUNKMOD:
//sendPack<ChunkMod>(sock, (ChunkMod*)pack->ptr, buf, buflen);
//sendPack<ChunkMod>(sock, (ChunkMod*)pack->ptr, buf);
case PACKET_TYPE::PLAYERMOD:
//sendPack<PlayerMod>(sock, (PlayerMod*)pack->ptr, buf, buflen);
//sendPack<PlayerMod>(sock, (PlayerMod*)pack->ptr, buf);
return;
case PACKET_TYPE::PICKUPMOD:
//sendPack<PickupMod>(sock, (PickupMod*)pack->ptr, buf, buflen);
//sendPack<PickupMod>(sock, (PickupMod*)pack->ptr, buf);
return;
case PACKET_TYPE::GAMEINFO:
sendPack<GameInfo>(sock, (GameInfo*)pack->ptr, buf, buflen);
sendPack<GameInfo>(sock, (GameInfo*)pack->ptr, buf);
return;
case PACKET_TYPE::ENDINFO:
//sendPack<EndInfo>(sock, (EndInfo*)pack->ptr, buf, buflen);
//sendPack<EndInfo>(sock, (EndInfo*)pack->ptr, buf);
return;
case PACKET_TYPE::CHAT:
sendPack<Chat>(sock, (Chat*)pack->ptr, buf, buflen);
sendPack<Chat>(sock, (Chat*)pack->ptr, buf);
return;
case PACKET_TYPE::ERRLOG:
sendPack<ErrorLog>(sock, (ErrorLog*)pack->ptr, buf, buflen);
sendPack<ErrorLog>(sock, (ErrorLog*)pack->ptr, buf);
return;
case PACKET_TYPE::LAST_PACK: [[fallthrough]];
case PACKET_TYPE::ERR: [[fallthrough]];
@@ -1044,46 +1043,46 @@ void netprot::sendPack<netprot::Packet>(SOCKET sock, Packet* pack, char** buf, u
}
template <>
void netprot::sendPackTo<netprot::Packet>(SOCKET sock, Packet* pack, char** buf, uint32_t* buflen, sockaddr_in* sockad) {
void netprot::sendPackTo<netprot::Packet>(SOCKET sock, Packet* pack, Buffer* buf, sockaddr_in* sockad) {
switch (pack->type) {
case PACKET_TYPE::INPUT:
sendPackTo<Input>(sock, (Input*)pack->ptr, buf, buflen, sockad);
sendPackTo<Input>(sock, (Input*)pack->ptr, buf, sockad);
return;
case PACKET_TYPE::OUTPUT:
sendPackTo<Output>(sock, (Output*)pack->ptr, buf, buflen, sockad);
sendPackTo<Output>(sock, (Output*)pack->ptr, buf, sockad);
return;
case PACKET_TYPE::SYNC:
sendPackTo<Sync>(sock, (Sync*)pack->ptr, buf, buflen, sockad);
sendPackTo<Sync>(sock, (Sync*)pack->ptr, buf, sockad);
return;
case PACKET_TYPE::TEAMINF:
sendPackTo<TeamInfo>(sock, (TeamInfo*)pack->ptr, buf, buflen, sockad);
sendPackTo<TeamInfo>(sock, (TeamInfo*)pack->ptr, buf, sockad);
return;
case PACKET_TYPE::PLAYINF:
sendPackTo<PlayerInfo>(sock, (PlayerInfo*)pack->ptr, buf, buflen, sockad);
sendPackTo<PlayerInfo>(sock, (PlayerInfo*)pack->ptr, buf, sockad);
return;
case PACKET_TYPE::LOGINF:
sendPackTo<LoginInfo>(sock, (LoginInfo*)pack->ptr, buf, buflen, sockad);
sendPackTo<LoginInfo>(sock, (LoginInfo*)pack->ptr, buf, sockad);
return;
case PACKET_TYPE::CHUNKMOD:
//sendPackTo<ChunkMod>(sock, (ChunkMod*)pack->ptr, buf, buflen, sockad);
//sendPackTo<ChunkMod>(sock, (ChunkMod*)pack->ptr, buf, sockad);
return;
case PACKET_TYPE::PLAYERMOD:
//sendPackTo<PlayerMod>(sock, (PlayerMod*)pack->ptr, buf, buflen, sockad);
//sendPackTo<PlayerMod>(sock, (PlayerMod*)pack->ptr, buf, sockad);
return;
case PACKET_TYPE::PICKUPMOD:
//sendPackTo<PickupMod>(sock, (PickupMod*)pack->ptr, buf, buflen, sockad);
//sendPackTo<PickupMod>(sock, (PickupMod*)pack->ptr, buf, sockad);
return;
case PACKET_TYPE::GAMEINFO:
sendPackTo<GameInfo>(sock, (GameInfo*)pack->ptr, buf, buflen, sockad);
sendPackTo<GameInfo>(sock, (GameInfo*)pack->ptr, buf, sockad);
return;
case PACKET_TYPE::ENDINFO:
//sendPackTo<EndInfo>(sock, (EndInfo*)pack->ptr, buf, buflen, sockad);
//sendPackTo<EndInfo>(sock, (EndInfo*)pack->ptr, buf, sockad);
return;
case PACKET_TYPE::CHAT:
sendPackTo<Chat>(sock, (Chat*)pack->ptr, buf, buflen, sockad);
sendPackTo<Chat>(sock, (Chat*)pack->ptr, buf, sockad);
return;
case PACKET_TYPE::ERRLOG:
sendPackTo<ErrorLog>(sock, (ErrorLog*)pack->ptr, buf, buflen, sockad);
sendPackTo<ErrorLog>(sock, (ErrorLog*)pack->ptr, buf, sockad);
return;
case PACKET_TYPE::LAST_PACK: [[fallthrough]];
case PACKET_TYPE::ERR: [[fallthrough]];