From fda98a3ef411330e139a1e2c709aa5e72dcebd47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Sat, 4 Jun 2022 10:02:45 +0200 Subject: [PATCH] Rename variables and use class in crapnet tool --- src/tools/crapnet.cpp | 72 +++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/src/tools/crapnet.cpp b/src/tools/crapnet.cpp index 33c4d1b41..2bed25164 100644 --- a/src/tools/crapnet.cpp +++ b/src/tools/crapnet.cpp @@ -8,10 +8,10 @@ #include -struct CPacket +struct SPacket { - CPacket *m_pPrev; - CPacket *m_pNext; + SPacket *m_pPrev; + SPacket *m_pNext; NETADDR m_SendTo; int64_t m_Timestamp; @@ -20,11 +20,11 @@ struct CPacket char m_aData[1]; }; -static CPacket *m_pFirst = (CPacket *)0; -static CPacket *m_pLast = (CPacket *)0; -static int m_CurrentLatency = 0; +static SPacket *g_pFirst = (SPacket *)0; +static SPacket *g_pLast = (SPacket *)0; +static int g_CurrentLatency = 0; -struct CPingConfig +struct SPingConfig { int m_Base; int m_Flux; @@ -34,17 +34,17 @@ struct CPingConfig int m_DelayFreq; }; -static CPingConfig m_aConfigPings[] = { +static SPingConfig g_aConfigPings[] = { // base flux spike loss delay delayfreq {0, 0, 0, 0, 0, 0}, {40, 20, 100, 0, 0, 0}, {140, 40, 200, 0, 0, 0}, }; -static int m_ConfigNumpingconfs = std::size(m_aConfigPings); -static int m_ConfigInterval = 10; // seconds between different pingconfigs -static int m_ConfigLog = 0; -static int m_ConfigReorder = 0; +static int g_ConfigNumpingconfs = std::size(g_aConfigPings); +static int g_ConfigInterval = 10; // seconds between different pingconfigs +static int g_ConfigLog = 0; +static int g_ConfigReorder = 0; void Run(unsigned short Port, NETADDR Dest) { @@ -56,13 +56,13 @@ void Run(unsigned short Port, NETADDR Dest) while(true) { - static int Lastcfg = 0; - int n = ((time_get() / time_freq()) / m_ConfigInterval) % m_ConfigNumpingconfs; - CPingConfig Ping = m_aConfigPings[n]; + static int s_Lastcfg = 0; + int n = ((time_get() / time_freq()) / g_ConfigInterval) % g_ConfigNumpingconfs; + SPingConfig Ping = g_aConfigPings[n]; - if(n != Lastcfg) + if(n != s_Lastcfg) dbg_msg("crapnet", "cfg = %d", n); - Lastcfg = n; + s_Lastcfg = n; // handle incoming packets while(true) @@ -77,13 +77,13 @@ void Run(unsigned short Port, NETADDR Dest) if((rand() % 100) < Ping.m_Loss) // drop the packet { - if(m_ConfigLog) + if(g_ConfigLog) dbg_msg("crapnet", "dropped packet"); continue; } // create new packet - CPacket *p = (CPacket *)malloc(sizeof(CPacket) + Bytes); + SPacket *p = (SPacket *)malloc(sizeof(SPacket) + Bytes); if(net_addr_comp(&From, &Dest) == 0) p->m_SendTo = Src; // from the server @@ -94,16 +94,16 @@ void Run(unsigned short Port, NETADDR Dest) } // queue packet - p->m_pPrev = m_pLast; + p->m_pPrev = g_pLast; p->m_pNext = 0; - if(m_pLast) - m_pLast->m_pNext = p; + if(g_pLast) + g_pLast->m_pNext = p; else { - m_pFirst = p; - m_pLast = p; + g_pFirst = p; + g_pLast = p; } - m_pLast = p; + g_pLast = p; // set data in packet p->m_Timestamp = time_get(); @@ -130,7 +130,7 @@ void Run(unsigned short Port, NETADDR Dest) } Delaycounter--; - if(m_ConfigLog) + if(g_ConfigLog) { char aAddrStr[NETADDR_MAXSTRSIZE]; net_addr_str(&From, aAddrStr, sizeof(aAddrStr), true); @@ -138,8 +138,8 @@ void Run(unsigned short Port, NETADDR Dest) } } - CPacket *p = 0; - CPacket *pNext = m_pFirst; + SPacket *p = 0; + SPacket *pNext = g_pFirst; while(true) { p = pNext; @@ -147,25 +147,25 @@ void Run(unsigned short Port, NETADDR Dest) break; pNext = p->m_pNext; - if((time_get() - p->m_Timestamp) > m_CurrentLatency) + if((time_get() - p->m_Timestamp) > g_CurrentLatency) { char aFlags[] = " "; - if(m_ConfigReorder && (rand() % 2) == 0 && p->m_pNext) + if(g_ConfigReorder && (rand() % 2) == 0 && p->m_pNext) { aFlags[0] = 'R'; - p = m_pFirst->m_pNext; + p = g_pFirst->m_pNext; } if(p->m_pNext) p->m_pNext->m_pPrev = p->m_pPrev; else - m_pLast = p->m_pPrev; + g_pLast = p->m_pPrev; if(p->m_pPrev) p->m_pPrev->m_pNext = p->m_pNext; else - m_pFirst = p->m_pNext; + g_pFirst = p->m_pNext; // send and remove packet net_udp_send(Socket, &p->m_SendTo, p->m_aData, p->m_DataSize); @@ -175,15 +175,15 @@ void Run(unsigned short Port, NETADDR Dest) int MsSpike = Ping.m_Spike; int MsFlux = Ping.m_Flux; int MsPing = Ping.m_Base; - m_CurrentLatency = ((time_freq() * MsPing) / 1000) + (int64_t)(((time_freq() * MsFlux) / 1000) * Flux); // 50ms + g_CurrentLatency = ((time_freq() * MsPing) / 1000) + (int64_t)(((time_freq() * MsFlux) / 1000) * Flux); // 50ms if(MsSpike && (p->m_ID % 100) == 0) { - m_CurrentLatency += (time_freq() * MsSpike) / 1000; + g_CurrentLatency += (time_freq() * MsSpike) / 1000; aFlags[1] = 'S'; } - if(m_ConfigLog) + if(g_ConfigLog) { char aAddrStr[NETADDR_MAXSTRSIZE]; net_addr_str(&p->m_SendTo, aAddrStr, sizeof(aAddrStr), true);