Skip to content

Commit

Permalink
Apply some of the jwmelto's suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
atupone committed Mar 28, 2024
1 parent 5372787 commit 88e1690
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/bzfs/bzfs.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -7666,7 +7666,7 @@ int main(int argc, char **argv)
unsigned char ubuf[MaxPacketLen];
bool udpLinkRequest;
// interface to the UDP Receive routines
int buffLen;
int buffLen = MaxPacketLen;
int id = NetHandler::udpReceive((char *) ubuf, buffLen, &uaddr,
udpLinkRequest);
if (id == -1)
Expand All @@ -7689,12 +7689,12 @@ int main(int argc, char **argv)
sendUDPupdate(id);

unsigned char *buf = ubuf;
uint16_t len;

// handle the command for UDP
// checking if more messages are on the same datagram
while (buffLen >= 4)
{
uint16_t len;
handleCommand(id, buf, true);
nboUnpackUShort(buf, len);
buf += len + 4;
Expand Down
14 changes: 7 additions & 7 deletions src/game/NetHandler.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -136,29 +136,29 @@ int NetHandler::getUdpSocket()
return udpSocket;
}

int NetHandler::udpReceive(char *buffer, int &n, struct sockaddr_in *uaddr,
int NetHandler::udpReceive(char *buffer, int &buffLen, struct sockaddr_in *uaddr,
bool &udpLinkRequest)
{
AddrLen recvlen = sizeof(*uaddr);
uint16_t len;
uint16_t code;
while (true)
{
n = recvfrom(udpSocket, buffer, MaxUDPPacketLen, 0, (struct sockaddr *) uaddr,
&recvlen);
if ((n < 0) || (n >= 4))
buffLen = recvfrom(udpSocket, buffer, buffLen, 0, (struct sockaddr *) uaddr,
&recvlen);
if ((buffLen < 0) || (buffLen >= 4))
break;
}
// Error receiving data (or no data)
if (n < 0 || uaddr->sin_port < 1024)
if (buffLen < 0 || uaddr->sin_port < 1024)
return -1;

// read head
const void *buf = buffer;
buf = nboUnpackUShort(buf, len);
buf = nboUnpackUShort(buf, code);

if (len + 4 > n)
if (len + 4 > buffLen)
return -1;

// if (code != MsgPlayerUpdateSmall && code != MsgPlayerUpdate)
Expand Down Expand Up @@ -231,7 +231,7 @@ than %s:%d\n",
logDebugMessage(4,"Player slot %d uread() %s:%d len %d from %s:%d on %i\n",
id,
inet_ntoa(netPlayer[id]->uaddr.sin_addr),
ntohs(netPlayer[id]->uaddr.sin_port), n,
ntohs(netPlayer[id]->uaddr.sin_port), buffLen,
inet_ntoa(uaddr->sin_addr), ntohs(uaddr->sin_port),
udpSocket);
#ifdef NETWORK_STATS
Expand Down

0 comments on commit 88e1690

Please sign in to comment.