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

Function Run

src/tools/crapnet.cpp:52–201  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

50static int g_ConfigReorder = 0;
51
52static void Run(unsigned short Port, NETADDR Dest)
53{
54 NETADDR Src = {NETTYPE_IPV4, {0, 0, 0, 0}, Port};
55 NETSOCKET Socket = net_udp_create(Src);
56
57 int Id = 0;
58 int Delaycounter = 0;
59
60 while(true)
61 {
62 static int s_Lastcfg = 0;
63 int n = ((time_get() / time_freq()) / g_ConfigInterval) % g_ConfigNumpingconfs;
64 SPingConfig Ping = g_aConfigPings[n];
65
66 if(n != s_Lastcfg)
67 dbg_msg("crapnet", "cfg = %d", n);
68 s_Lastcfg = n;
69
70 // handle incoming packets
71 while(true)
72 {
73 // fetch data
74 int DataTrash = 0;
75 NETADDR From;
76 unsigned char *pData;
77 int Bytes = net_udp_recv(Socket, &From, &pData);
78 if(Bytes <= 0)
79 break;
80
81 if((rand() % 100) < Ping.m_Loss) // drop the packet
82 {
83 if(g_ConfigLog)
84 dbg_msg("crapnet", "dropped packet");
85 continue;
86 }
87
88 // create new packet
89 SPacket *p = (SPacket *)malloc(sizeof(SPacket) + Bytes);
90
91 if(net_addr_comp(&From, &Dest) == 0)
92 p->m_SendTo = Src; // from the server
93 else
94 {
95 Src = From; // from the client
96 p->m_SendTo = Dest;
97 }
98
99 // queue packet
100 p->m_pPrev = g_pLast;
101 p->m_pNext = nullptr;
102 if(g_pLast)
103 g_pLast->m_pNext = p;
104 else
105 {
106 g_pFirst = p;
107 g_pLast = p;
108 }
109 g_pLast = p;

Callers 1

mainFunction · 0.70

Calls 9

net_udp_createFunction · 0.85
time_getFunction · 0.85
time_freqFunction · 0.85
dbg_msgFunction · 0.85
net_udp_recvFunction · 0.85
net_addr_compFunction · 0.85
mem_copyFunction · 0.85
net_addr_strFunction · 0.85
net_udp_sendFunction · 0.85

Tested by

no test coverage detected