MCPcopy Create free account
hub / github.com/ddnet/ddnet / Recv

Method Recv

src/engine/shared/network_server.cpp:586–687  ·  view source on GitHub ↗

TODO: chopp up this function into smaller working parts */

Source from the content-addressed store, hash-verified

584 TODO: chopp up this function into smaller working parts
585*/
586int CNetServer::Recv(CNetChunk *pChunk, SECURITY_TOKEN *pResponseToken)
587{
588 while(true)
589 {
590 // Unpack next chunk from stored packet if available
591 if(m_PacketChunkUnpacker.UnpackNextChunk(pChunk))
592 return 1;
593
594 // TODO: empty the recvinfo
595 NETADDR Addr;
596 unsigned char *pData;
597 int Bytes = net_udp_recv(m_Socket, &Addr, &pData);
598
599 // no more packets for now
600 if(Bytes <= 0)
601 break;
602
603 // check if we just should drop the packet
604 char aBuf[128];
605 if(NetBan() && NetBan()->IsBanned(&Addr, aBuf, sizeof(aBuf)))
606 {
607 // banned, reply with a message
608 CNetBase::SendControlMsg(m_Socket, &Addr, 0, NET_CTRLMSG_CLOSE, aBuf, str_length(aBuf) + 1, NET_SECURITY_TOKEN_UNSUPPORTED);
609 continue;
610 }
611
612 // Check size and unpack packet flags early so we can determine the sixup
613 // state correctly for connection-oriented packets before unpacking them.
614 std::optional<int> Flags = CNetBase::UnpackPacketFlags(pData, Bytes);
615 if(!Flags)
616 {
617 continue;
618 }
619
620 SECURITY_TOKEN Token;
621 int Slot = (*Flags & NET_PACKETFLAG_CONNLESS) == 0 ? GetClientSlot(Addr) : -1;
622 bool Sixup = Slot != -1 && m_aSlots[Slot].m_Connection.m_Sixup;
623 if(CNetBase::UnpackPacket(pData, Bytes, &m_RecvBuffer, Sixup, &Token, pResponseToken) == 0)
624 {
625 if(m_RecvBuffer.m_Flags & NET_PACKETFLAG_CONNLESS)
626 {
627 if(Sixup && Token != GetToken(Addr) && Token != GetGlobalToken())
628 {
629 continue;
630 }
631
632 pChunk->m_Flags = NETSENDFLAG_CONNLESS;
633 pChunk->m_ClientId = -1;
634 pChunk->m_Address = Addr;
635 pChunk->m_DataSize = m_RecvBuffer.m_DataSize;
636 pChunk->m_pData = m_RecvBuffer.m_aChunkData;
637 if(m_RecvBuffer.m_Flags & NET_PACKETFLAG_EXTENDED)
638 {
639 pChunk->m_Flags |= NETSENDFLAG_EXTENDED;
640 mem_copy(pChunk->m_aExtraData, m_RecvBuffer.m_aExtraData, sizeof(pChunk->m_aExtraData));
641 }
642 return 1;
643 }

Callers 4

mainFunction · 0.45
PumpNetworkMethod · 0.45
UpdateMethod · 0.45
PumpNetworkMethod · 0.45

Calls 8

net_udp_recvFunction · 0.85
str_lengthFunction · 0.85
mem_copyFunction · 0.85
IsDDNetControlMsgFunction · 0.85
UnpackNextChunkMethod · 0.80
FeedMethod · 0.80
FeedPacketMethod · 0.80
IsBannedMethod · 0.45

Tested by

no test coverage detected