mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Try to implement netlimit (level too high, map downloads might fail)
This commit is contained in:
parent
8720186c75
commit
82f3734dd7
|
@ -249,9 +249,17 @@ 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;
|
||||
|
||||
|
|
|
@ -105,17 +105,64 @@ int CNetServer::Recv(CNetChunk *pChunk)
|
|||
if(Bytes <= 0)
|
||||
break;
|
||||
|
||||
// check if we just should drop the packet
|
||||
char aBuf[128];
|
||||
if(NetBan() && NetBan()->IsBanned(&Addr, aBuf, sizeof(aBuf)))
|
||||
{
|
||||
// banned, reply with a message
|
||||
CNetBase::SendControlMsg(m_Socket, &Addr, 0, NET_CTRLMSG_CLOSE, aBuf, str_length(aBuf)+1);
|
||||
continue;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
// check if we just should drop the packet
|
||||
char aBuf[128];
|
||||
if(NetBan() && NetBan()->IsBanned(&Addr, aBuf, sizeof(aBuf)))
|
||||
{
|
||||
// banned, reply with a message
|
||||
CNetBase::SendControlMsg(m_Socket, &Addr, 0, NET_CTRLMSG_CLOSE, aBuf, str_length(aBuf)+1);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(m_RecvUnpacker.m_Data.m_Flags&NET_PACKETFLAG_CONNLESS)
|
||||
{
|
||||
pChunk->m_Flags = NETSENDFLAG_CONNLESS;
|
||||
|
@ -130,7 +177,7 @@ int CNetServer::Recv(CNetChunk *pChunk)
|
|||
// TODO: check size here
|
||||
if(m_RecvUnpacker.m_Data.m_Flags&NET_PACKETFLAG_CONTROL && m_RecvUnpacker.m_Data.m_aChunkData[0] == NET_CTRLMSG_CONNECT)
|
||||
{
|
||||
bool Found = false;
|
||||
Found = false;
|
||||
|
||||
// check if we already got this client
|
||||
for(int i = 0; i < MaxClients(); i++)
|
||||
|
|
Loading…
Reference in a new issue