mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Move netlimit over to regular server
This commit is contained in:
parent
82f3734dd7
commit
71ba923133
|
@ -446,6 +446,8 @@ int CServer::Init()
|
|||
m_aClients[i].m_aClan[0] = 0;
|
||||
m_aClients[i].m_Country = -1;
|
||||
m_aClients[i].m_Snapshots.Init();
|
||||
m_aClients[i].m_Traffic = 0;
|
||||
m_aClients[i].m_TrafficSince = 0;
|
||||
}
|
||||
|
||||
m_CurrentGameTick = 0;
|
||||
|
@ -843,6 +845,26 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket)
|
|||
if(Unpacker.Error())
|
||||
return;
|
||||
|
||||
int64 Now = time_get();
|
||||
|
||||
if(Msg != NETMSG_REQUEST_MAP_DATA)
|
||||
{
|
||||
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()) > 100000)
|
||||
{
|
||||
m_NetServer.NetBan()->BanAddr(&pPacket->m_Address, 60, "Stressing network");
|
||||
return;
|
||||
}
|
||||
m_aClients[ClientID].m_Traffic += pPacket->m_DataSize;
|
||||
}
|
||||
}
|
||||
|
||||
if(Sys)
|
||||
{
|
||||
// system message
|
||||
|
|
|
@ -118,6 +118,9 @@ public:
|
|||
int m_Latency;
|
||||
int m_SnapRate;
|
||||
|
||||
int64 m_Traffic;
|
||||
int64 m_TrafficSince;
|
||||
|
||||
int m_LastAckedSnapshot;
|
||||
int m_LastInputTick;
|
||||
CSnapshotStorage m_Snapshots;
|
||||
|
|
|
@ -249,17 +249,9 @@ class CNetServer
|
|||
CNetConnection m_Connection;
|
||||
};
|
||||
|
||||
struct CTraffic
|
||||
{
|
||||
NETADDR m_Address;
|
||||
int64 m_Traffic;
|
||||
int64 m_TrafficSince;
|
||||
};
|
||||
|
||||
NETSOCKET m_Socket;
|
||||
class CNetBan *m_pNetBan;
|
||||
CSlot m_aSlots[NET_MAX_CLIENTS];
|
||||
CTraffic m_aTraffics[NET_MAX_CLIENTS];
|
||||
int m_MaxClients;
|
||||
int m_MaxClientsPerIP;
|
||||
|
||||
|
|
|
@ -115,51 +115,6 @@ int CNetServer::Recv(CNetChunk *pChunk)
|
|||
}
|
||||
|
||||
bool Found = false;
|
||||
bool Spam = false;
|
||||
int64 Now = time_get();
|
||||
|
||||
for(int i = 0; i < MaxClients(); i++)
|
||||
{
|
||||
if (net_addr_comp(&m_aTraffics[i].m_Address, &Addr) == 0)
|
||||
{
|
||||
if (Now - m_aTraffics[i].m_TrafficSince > time_freq() * 5)
|
||||
{
|
||||
m_aTraffics[i].m_Traffic = 0;
|
||||
m_aTraffics[i].m_TrafficSince = Now;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((Now - m_aTraffics[i].m_TrafficSince) / time_freq() > 0 && m_aTraffics[i].m_Traffic / ((Now - m_aTraffics[i].m_TrafficSince) / time_freq()) > 10000 /* * m_MaxClientsPerIP*/)
|
||||
{
|
||||
Spam = true;
|
||||
break;
|
||||
}
|
||||
m_aTraffics[i].m_Traffic += Bytes;
|
||||
}
|
||||
Found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (Spam)
|
||||
{
|
||||
NetBan()->BanAddr(&Addr, 60, "Stressing network");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!Found)
|
||||
{
|
||||
for(int i = 0; i < MaxClients(); i++)
|
||||
{
|
||||
if (Now - m_aTraffics[i].m_TrafficSince > time_freq() * 5)
|
||||
{
|
||||
m_aTraffics[i].m_Address = Addr;
|
||||
m_aTraffics[i].m_Traffic = 0;
|
||||
m_aTraffics[i].m_TrafficSince = Now;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(CNetBase::UnpackPacket(m_RecvUnpacker.m_aBuffer, Bytes, &m_RecvUnpacker.m_Data) == 0)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue