More advanced netlimit

This commit is contained in:
def 2013-08-04 17:50:12 +02:00
parent a83c5702ff
commit 60865b7dbf
4 changed files with 13 additions and 13 deletions

View file

@ -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)
if (m_aClients[ClientID].m_Traffic > Limit)
{
m_aClients[ClientID].m_Traffic = 0;
m_aClients[ClientID].m_TrafficSince = Now;
m_NetServer.NetBan()->BanAddr(&pPacket->m_Address, 60, "Stressing network");
return;
}
else
if (Diff > 100)
{
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)
{
m_NetServer.NetBan()->BanAddr(&pPacket->m_Address, 60, "Stressing network");
return;
}
m_aClients[ClientID].m_Traffic += pPacket->m_DataSize;
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;
}
}

View file

@ -118,7 +118,7 @@ public:
int m_Latency;
int m_SnapRate;
int64 m_Traffic;
float m_Traffic;
int64 m_TrafficSince;
int m_LastAckedSnapshot;

View file

@ -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

View file

@ -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());
}