mirror of
https://github.com/rehlds/rehlds.git
synced 2024-12-29 08:05:50 +03:00
Merge pull request #652 from WPMGPRoSToTeMa/fix-net-queuepacket-workflow
Fixed NET_QueuePacket workflow
This commit is contained in:
commit
83f53fb5c5
@ -860,91 +860,120 @@ qboolean NET_GetLong(unsigned char *pData, int size, int *outSize)
|
|||||||
|
|
||||||
qboolean NET_QueuePacket(netsrc_t sock)
|
qboolean NET_QueuePacket(netsrc_t sock)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
#ifdef REHLDS_FIXES
|
||||||
unsigned char buf[MAX_UDP_PACKET];
|
while (true)
|
||||||
|
#endif // REHLDS_FIXES
|
||||||
#ifdef _WIN32
|
|
||||||
for (int protocol = 0; protocol < 2; protocol++)
|
|
||||||
#else
|
|
||||||
for (int protocol = 0; protocol < 1; protocol++)
|
|
||||||
#endif // _WIN32
|
|
||||||
{
|
{
|
||||||
SOCKET net_socket;
|
int ret = -1;
|
||||||
|
unsigned char buf[MAX_UDP_PACKET];
|
||||||
|
|
||||||
if (protocol == 0)
|
|
||||||
net_socket = ip_sockets[sock];
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
else
|
for (int protocol = 0; protocol < 2; protocol++)
|
||||||
net_socket = ipx_sockets[sock];
|
#else
|
||||||
|
for (int protocol = 0; protocol < 1; protocol++)
|
||||||
|
#endif // _WIN32
|
||||||
|
{
|
||||||
|
SOCKET net_socket;
|
||||||
|
|
||||||
|
if (protocol == 0)
|
||||||
|
net_socket = ip_sockets[sock];
|
||||||
|
#ifdef _WIN32
|
||||||
|
else
|
||||||
|
net_socket = ipx_sockets[sock];
|
||||||
#endif // _WIN32
|
#endif // _WIN32
|
||||||
|
|
||||||
if (net_socket == INV_SOCK)
|
if (net_socket == INV_SOCK)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
struct sockaddr from;
|
struct sockaddr from;
|
||||||
socklen_t fromlen = sizeof(from);
|
socklen_t fromlen = sizeof(from);
|
||||||
ret = CRehldsPlatformHolder::get()->recvfrom(net_socket, (char *)buf, sizeof buf, 0, &from, &fromlen);
|
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;
|
||||||
|
#endif // _WIN32
|
||||||
|
|
||||||
|
if (err != WSAEWOULDBLOCK && err != WSAECONNRESET && err != WSAECONNREFUSED)
|
||||||
|
{
|
||||||
|
if (err == WSAEMSGSIZE)
|
||||||
|
{
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
SockadrToNetadr(&from, &in_from);
|
||||||
|
if (ret != MAX_UDP_PACKET)
|
||||||
|
break;
|
||||||
|
|
||||||
|
Con_NetPrintf("%s: Oversize packet from %s\n", __func__, NET_AdrToString(in_from));
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef REHLDS_FIXES
|
||||||
if (ret == -1)
|
if (ret == -1)
|
||||||
{
|
{
|
||||||
int err = NET_GetLastError();
|
return NET_LagPacket(FALSE, sock, NULL, NULL);
|
||||||
#ifdef _WIN32
|
}
|
||||||
if (err == WSAENETRESET)
|
if (ret == MAX_UDP_PACKET)
|
||||||
continue;
|
{
|
||||||
#endif // _WIN32
|
continue;
|
||||||
|
}
|
||||||
|
#else // REHLDS_FIXES
|
||||||
|
if (ret == -1 || ret == MAX_UDP_PACKET)
|
||||||
|
{
|
||||||
|
return NET_LagPacket(FALSE, sock, NULL, NULL);
|
||||||
|
}
|
||||||
|
#endif // REHLDS_FIXES
|
||||||
|
|
||||||
if (err != WSAEWOULDBLOCK && err != WSAECONNRESET && err != WSAECONNREFUSED)
|
NET_TransferRawData(&in_message, buf, ret);
|
||||||
{
|
|
||||||
if (err == WSAEMSGSIZE)
|
if (*(int32 *)in_message.data != NET_HEADER_FLAG_SPLITPACKET)
|
||||||
{
|
{
|
||||||
Con_DPrintf("%s: Ignoring oversized network message\n", __func__);
|
return NET_LagPacket(TRUE, sock, &in_from, &in_message);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
if (in_message.cursize < 9)
|
||||||
if (g_pcls.state != ca_dedicated)
|
{
|
||||||
{
|
Con_NetPrintf("Invalid split packet length %i\n", in_message.cursize);
|
||||||
Sys_Error("%s: %s", __func__, NET_ErrorString(err));
|
#ifdef REHLDS_FIXES
|
||||||
}
|
continue;
|
||||||
Con_Printf("%s: %s\n", __func__, NET_ErrorString(err));
|
#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");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef REHLDS_FIXES
|
||||||
|
if (!NET_GetLong(in_message.data, ret, &in_message.cursize))
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
SockadrToNetadr(&from, &in_from);
|
return TRUE;
|
||||||
if (ret != MAX_UDP_PACKET)
|
#else // REHLDS_FIXES
|
||||||
break;
|
return NET_GetLong(in_message.data, ret, &in_message.cursize);
|
||||||
|
#endif // REHLDS_FIXES
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
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 (in_message.cursize < 9)
|
|
||||||
{
|
|
||||||
Con_NetPrintf("Invalid split packet length %i\n", in_message.cursize);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
#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;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return NET_GetLong(in_message.data, ret, &in_message.cursize);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DLL_EXPORT int NET_Sleep_Timeout()
|
DLL_EXPORT int NET_Sleep_Timeout()
|
||||||
|
Loading…
Reference in New Issue
Block a user