mirror of
https://github.com/CraftyBoss/SuperMarioOdysseyOnline.git
synced 2025-01-03 14:11:08 +00:00
Change socket client recvTcp to use if guards
This commit is contained in:
parent
7e128679ab
commit
158f782a2a
1 changed files with 63 additions and 61 deletions
|
@ -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() {
|
||||
|
|
Loading…
Reference in a new issue