Change socket client recvTcp to use if guards

This commit is contained in:
Jack Garrard 2022-10-29 17:41:54 -07:00
parent 7e128679ab
commit 158f782a2a

View file

@ -276,12 +276,21 @@ bool SocketClient::recvTcp() {
}
}
if(valread > 0) {
if(valread <= 0) { // if we error'd, close the socket
Logger::log("valread was zero! Disconnecting.\n");
this->socket_errno = nn::socket::GetLastErrno();
this->closeSocket();
return false;
}
Packet* header = reinterpret_cast<Packet*>(recvBuf);
int fullSize = header->mPacketSize + sizeof(Packet);
if (fullSize <= MAXPACKSIZE && fullSize > 0 && valread == sizeof(Packet)) {
if (!(fullSize <= MAXPACKSIZE && fullSize > 0 && valread == sizeof(Packet))) {
Logger::log("Failed to acquire valid data! Packet Type: %d Full Packet Size %d valread size: %d\n", header->mType, fullSize, valread);
return true;
}
if (header->mType != PLAYERINF && header->mType != HACKCAPINF) {
Logger::log("Received packet (from %02X%02X):", header->mUserID.data[0],
@ -296,7 +305,10 @@ bool SocketClient::recvTcp() {
char* packetBuf = (char*)mHeap->alloc(fullSize);
if (packetBuf) {
if (!packetBuf) {
return true;
}
memcpy(packetBuf, recvBuf, sizeof(Packet));
@ -330,18 +342,8 @@ bool SocketClient::recvTcp() {
} else {
mHeap->free(packetBuf);
}
}
} else {
Logger::log("Failed to acquire valid data! Packet Type: %d Full Packet Size %d valread size: %d\n", header->mType, fullSize, valread);
}
return true;
} else { // if we error'd, close the socket
Logger::log("valread was zero! Disconnecting.\n");
this->socket_errno = nn::socket::GetLastErrno();
this->closeSocket();
return false;
}
}
bool SocketClient::recvUdp() {