Commit d15ebf6d authored by WPMGPRoSToTeMa's avatar WPMGPRoSToTeMa

Fixed NET_QueuePacket workflow

parent 469908f5
......@@ -860,91 +860,120 @@ qboolean NET_GetLong(unsigned char *pData, int size, int *outSize)
qboolean NET_QueuePacket(netsrc_t sock)
{
int ret = -1;
unsigned char buf[MAX_UDP_PACKET];
#ifdef REHLDS_FIXES
while (true)
#endif // REHLDS_FIXES
{
int ret = -1;
unsigned char buf[MAX_UDP_PACKET];
#ifdef _WIN32
for (int protocol = 0; protocol < 2; protocol++)
for (int protocol = 0; protocol < 2; protocol++)
#else
for (int protocol = 0; protocol < 1; protocol++)
for (int protocol = 0; protocol < 1; protocol++)
#endif // _WIN32
{
SOCKET net_socket;
{
SOCKET net_socket;
if (protocol == 0)
net_socket = ip_sockets[sock];
if (protocol == 0)
net_socket = ip_sockets[sock];
#ifdef _WIN32
else
net_socket = ipx_sockets[sock];
else
net_socket = ipx_sockets[sock];
#endif // _WIN32
if (net_socket == INV_SOCK)
continue;
if (net_socket == INV_SOCK)
continue;
struct sockaddr from;
socklen_t fromlen = sizeof(from);
ret = CRehldsPlatformHolder::get()->recvfrom(net_socket, (char *)buf, sizeof buf, 0, &from, &fromlen);
if (ret == -1)
{
int err = NET_GetLastError();
struct sockaddr from;
socklen_t fromlen = sizeof(from);
ret = CRehldsPlatformHolder::get()->recvfrom(net_socket, (char *)buf, sizeof buf, 0, &from, &fromlen);
if (ret == -1)
{
int err = NET_GetLastError();
#ifdef _WIN32
if (err == WSAENETRESET)
continue;
if (err == WSAENETRESET)
continue;
#endif // _WIN32
if (err != WSAEWOULDBLOCK && err != WSAECONNRESET && err != WSAECONNREFUSED)
{
if (err == WSAEMSGSIZE)
{
Con_DPrintf("%s: Ignoring oversized network message\n", __func__);
}
else
if (err != WSAEWOULDBLOCK && err != WSAECONNRESET && err != WSAECONNREFUSED)
{
if (g_pcls.state != ca_dedicated)
if (err == WSAEMSGSIZE)
{
Sys_Error("%s: %s", __func__, NET_ErrorString(err));
Con_DPrintf("%s: Ignoring oversized network message\n", __func__);
}
else
{
if (g_pcls.state != ca_dedicated)
{
Sys_Error("%s: %s", __func__, NET_ErrorString(err));
}
Con_Printf("%s: %s\n", __func__, NET_ErrorString(err));
}
Con_Printf("%s: %s\n", __func__, NET_ErrorString(err));
}
continue;
}
continue;
}
SockadrToNetadr(&from, &in_from);
if (ret != MAX_UDP_PACKET)
break;
SockadrToNetadr(&from, &in_from);
if (ret != MAX_UDP_PACKET)
break;
Con_NetPrintf("%s: Oversize packet from %s\n", __func__, NET_AdrToString(in_from));
}
Con_NetPrintf("%s: Oversize packet from %s\n", __func__, NET_AdrToString(in_from));
}
if (ret == -1 || ret == MAX_UDP_PACKET)
{
return NET_LagPacket(FALSE, sock, NULL, NULL);
}
#ifdef REHLDS_FIXES
if (ret == -1)
{
return NET_LagPacket(FALSE, sock, NULL, NULL);
}
if (ret == MAX_UDP_PACKET)
{
continue;
}
#else // REHLDS_FIXES
if (ret == -1 || ret == MAX_UDP_PACKET)
{
return NET_LagPacket(FALSE, sock, NULL, NULL);
}
#endif // REHLDS_FIXES
NET_TransferRawData(&in_message, buf, ret);
NET_TransferRawData(&in_message, buf, ret);
if (*(int32 *)in_message.data != NET_HEADER_FLAG_SPLITPACKET)
{
return NET_LagPacket(TRUE, sock, &in_from, &in_message);
}
if (*(int32 *)in_message.data != NET_HEADER_FLAG_SPLITPACKET)
{
return NET_LagPacket(TRUE, sock, &in_from, &in_message);
}
if (in_message.cursize < 9)
{
Con_NetPrintf("Invalid split packet length %i\n", in_message.cursize);
return FALSE;
}
if (in_message.cursize < 9)
{
Con_NetPrintf("Invalid split packet length %i\n", in_message.cursize);
#ifdef REHLDS_FIXES
continue;
#else // REHLDS_FIXES
return FALSE;
#endif // REHLDS_FIXES
}
#ifdef REHLDS_FIXES
// Only server can send split packets, there is no server<->server communication, so server can't receive split packets
if (sock == NS_SERVER)
{
Con_NetPrintf("Someone tries to send split packet to the server\n");
return FALSE;
}
// Only server can send split packets, there is no server<->server communication, so server can't receive split packets
if (sock == NS_SERVER)
{
Con_NetPrintf("Someone tries to send split packet to the server\n");
continue;
}
#endif
return NET_GetLong(in_message.data, ret, &in_message.cursize);
#ifdef REHLDS_FIXES
if (!NET_GetLong(in_message.data, ret, &in_message.cursize))
{
continue;
}
return TRUE;
#else // REHLDS_FIXES
return NET_GetLong(in_message.data, ret, &in_message.cursize);
#endif // REHLDS_FIXES
}
}
DLL_EXPORT int NET_Sleep_Timeout()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment