mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-20 06:58:20 +00:00
More advanced netlimit
This commit is contained in:
parent
a83c5702ff
commit
60865b7dbf
|
@ -848,20 +848,19 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket)
|
|||
if(g_Config.m_SvNetlimit && Msg != NETMSG_REQUEST_MAP_DATA)
|
||||
{
|
||||
int64 Now = time_get();
|
||||
int64 Diff = Now - m_aClients[ClientID].m_TrafficSince;
|
||||
float Alpha = g_Config.m_SvNetlimitAlpha / 100.0;
|
||||
float Limit = (float) g_Config.m_SvNetlimit * 1024 / time_freq();
|
||||
|
||||
if (Now - m_aClients[ClientID].m_TrafficSince > time_freq() * 5)
|
||||
{
|
||||
m_aClients[ClientID].m_Traffic = 0;
|
||||
m_aClients[ClientID].m_TrafficSince = Now;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((Now - m_aClients[ClientID].m_TrafficSince) / time_freq() > 0 && m_aClients[ClientID].m_Traffic / ((Now - m_aClients[ClientID].m_TrafficSince) / time_freq()) > g_Config.m_SvNetlimit * 1024)
|
||||
if (m_aClients[ClientID].m_Traffic > Limit)
|
||||
{
|
||||
m_NetServer.NetBan()->BanAddr(&pPacket->m_Address, 60, "Stressing network");
|
||||
return;
|
||||
}
|
||||
m_aClients[ClientID].m_Traffic += pPacket->m_DataSize;
|
||||
if (Diff > 100)
|
||||
{
|
||||
m_aClients[ClientID].m_Traffic = (Alpha * ((float) pPacket->m_DataSize / Diff)) + (1.0 - Alpha) * m_aClients[ClientID].m_Traffic;
|
||||
m_aClients[ClientID].m_TrafficSince = Now;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -118,7 +118,7 @@ public:
|
|||
int m_Latency;
|
||||
int m_SnapRate;
|
||||
|
||||
int64 m_Traffic;
|
||||
float m_Traffic;
|
||||
int64 m_TrafficSince;
|
||||
|
||||
int m_LastAckedSnapshot;
|
||||
|
|
|
@ -222,6 +222,7 @@ MACRO_CONFIG_INT(SvGlobalBantime, sv_global_ban_time, 60, 0, 1440, CFGFLAG_SERVE
|
|||
MACRO_CONFIG_INT(SvEvents, sv_events, 1, 0, 1, CFGFLAG_SERVER, "Enable triggering of server events, like the happy eyeemotes on some holidays.")
|
||||
|
||||
// netlimit
|
||||
MACRO_CONFIG_INT(SvNetlimit, sv_netlimit, 10, 0, 1000, CFGFLAG_SERVER, "Netlimit: Maximum amount of traffic a client is allowed to use (in kb/s)")
|
||||
MACRO_CONFIG_INT(SvNetlimit, sv_netlimit, 500, 0, 10000, CFGFLAG_SERVER, "Netlimit: Maximum amount of traffic a client is allowed to use (in kb/s)")
|
||||
MACRO_CONFIG_INT(SvNetlimitAlpha, sv_netlimit_alpha, 50, 1, 100, CFGFLAG_SERVER, "Netlimit: Alpha of Exponention moving average")
|
||||
|
||||
#endif
|
||||
|
|
|
@ -76,7 +76,7 @@ int CNetServer::Update()
|
|||
if(m_aSlots[i].m_Connection.State() == NET_CONNSTATE_ERROR)
|
||||
{
|
||||
if (Now - m_aSlots[i].m_Connection.ConnectTime() < time_freq() && NetBan())
|
||||
NetBan()->BanAddr(ClientAddr(i), 60, "Stressing network");
|
||||
NetBan()->BanAddr(ClientAddr(i), 60, "Too many connections");
|
||||
else
|
||||
Drop(i, m_aSlots[i].m_Connection.ErrorString());
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue