MCPcopy Create free account
hub / github.com/ZDoom/Raze / PacketGet

Function PacketGet

source/common/engine/i_net.cpp:279–359  ·  view source on GitHub ↗

PacketGet

Source from the content-addressed store, hash-verified

277// PacketGet
278//
279void PacketGet (void)
280{
281 int c;
282 socklen_t fromlen;
283 sockaddr_in fromaddress;
284 int node;
285
286 fromlen = sizeof(fromaddress);
287 c = recvfrom (mysocket, (char*)TransmitBuffer, TRANSMIT_SIZE, 0,
288 (sockaddr *)&fromaddress, &fromlen);
289 node = FindNode (&fromaddress);
290
291 if (node >= 0 && c == SOCKET_ERROR)
292 {
293 int err = WSAGetLastError();
294
295 if (err == WSAECONNRESET)
296 { // The remote node aborted unexpectedly, so pretend it sent an exit packet
297
298 if (StartWindow != NULL)
299 {
300 I_NetMessage ("The connection from %s was dropped.\n",
301 GetPlayerName(node).GetChars());
302 }
303 else
304 {
305 Printf("The connection from %s was dropped.\n",
306 GetPlayerName(node).GetChars());
307 }
308
309 doomcom.data[0] = NCMD_EXIT;
310 c = 1;
311 }
312 else if (err != WSAEWOULDBLOCK)
313 {
314 I_Error ("GetPacket: %s", neterror ());
315 }
316 else
317 {
318 doomcom.remotenode = -1; // no packet
319 return;
320 }
321 }
322 else if (node >= 0 && c > 0)
323 {
324 doomcom.data[0] = TransmitBuffer[0] & ~NCMD_COMPRESSED;
325 if (TransmitBuffer[0] & NCMD_COMPRESSED)
326 {
327 uLongf msgsize = MAX_MSGLEN - 1;
328 int err = uncompress(doomcom.data + 1, &msgsize, TransmitBuffer + 1, c - 1);
329// Printf("recv %d/%lu\n", c, msgsize + 1);
330 if (err != Z_OK)
331 {
332 Printf("Net decompression failed (zlib error %s)\n", M_ZLibError(err).GetChars());
333 // Pretend no packet
334 doomcom.remotenode = -1;
335 return;
336 }

Callers 1

I_NetCmdFunction · 0.85

Calls 9

FindNodeFunction · 0.85
I_NetMessageFunction · 0.85
GetPlayerNameFunction · 0.85
PrintfFunction · 0.85
I_ErrorFunction · 0.85
neterrorFunction · 0.85
M_ZLibErrorFunction · 0.85
PreSendFunction · 0.85
GetCharsMethod · 0.45

Tested by

no test coverage detected