Move packet type check to after packet data recv

This commit is contained in:
Jack Garrard 2022-08-27 01:47:52 -07:00
parent d4df8f030c
commit b18671f113

View file

@ -133,8 +133,7 @@ bool SocketClient::RECV() {
int fullSize = header->mPacketSize + sizeof(Packet); int fullSize = header->mPacketSize + sizeof(Packet);
if (header->mType > PacketType::UNKNOWN && header->mType < PacketType::End && if (fullSize <= MAXPACKSIZE && fullSize > 0 && valread == sizeof(Packet)) {
fullSize <= MAXPACKSIZE && fullSize > 0 && valread == sizeof(Packet)) {
if (header->mType != PLAYERINF && header->mType != HACKCAPINF) { if (header->mType != PLAYERINF && header->mType != HACKCAPINF) {
Logger::log("Received packet (from %02X%02X):", header->mUserID.data[0], Logger::log("Received packet (from %02X%02X):", header->mUserID.data[0],
@ -171,6 +170,12 @@ bool SocketClient::RECV() {
} }
} }
if (!(header->mType > PacketType::UNKNOWN && header->mType < PacketType::End)) {
Logger::log("Failed to acquire valid packet type! Packet Type: %d Full Packet Size %d valread size: %d", header->mType, fullSize, valread);
free(packetBuf);
return true;
}
Packet *packet = reinterpret_cast<Packet*>(packetBuf); Packet *packet = reinterpret_cast<Packet*>(packetBuf);
if(mPacketQueue.size() < maxBufSize - 1) { if(mPacketQueue.size() < maxBufSize - 1) {
@ -180,7 +185,7 @@ bool SocketClient::RECV() {
} }
} }
} else { } else {
Logger::log("Failed to aquire valid data! Packet Type: %d Full Packet Size %d valread size: %d", header->mType, fullSize, valread); Logger::log("Failed to acquire valid data! Packet Type: %d Full Packet Size %d valread size: %d", header->mType, fullSize, valread);
} }
return true; return true;