mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-19 14:38:18 +00:00
Merge branch 'netlimit' into DDRace
This commit is contained in:
commit
84e7bb5658
|
@ -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;
|
||||
|
@ -556,7 +558,7 @@ int CServer::SendMsgEx(CMsgPacker *pMsg, int Flags, int ClientID, bool System)
|
|||
Packet.m_Flags |= NETSENDFLAG_FLUSH;
|
||||
|
||||
// write message to demo recorder
|
||||
if(!(Flags&MSGFLAG_NORECORD))
|
||||
if(m_DemoRecorder.IsRecording() && !(Flags&MSGFLAG_NORECORD))
|
||||
m_DemoRecorder.RecordMessage(pMsg->Data(), pMsg->Size());
|
||||
|
||||
if(!(Flags&MSGFLAG_NOSEND))
|
||||
|
@ -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()) > g_Config.m_SvNetlimit)
|
||||
{
|
||||
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;
|
||||
|
|
|
@ -221,4 +221,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, 10000, 1000, 1000000, CFGFLAG_SERVER, "Netlimit: Maximum amount of traffic a client is allowed to use (in kb/s)")
|
||||
|
||||
#endif
|
||||
|
|
|
@ -183,6 +183,9 @@ void CDemoRecorder::Write(int Type, const void *pData, int Size)
|
|||
if(!m_File)
|
||||
return;
|
||||
|
||||
if(Size > 64*1024)
|
||||
return;
|
||||
|
||||
/* pad the data with 0 so we get an alignment of 4,
|
||||
else the compression won't work and miss some bytes */
|
||||
mem_copy(aBuffer2, pData, Size);
|
||||
|
|
|
@ -105,17 +105,19 @@ 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;
|
||||
|
||||
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 +132,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