mirror of
https://github.com/ddnet/ddnet.git
synced 2024-09-20 01:24:18 +00:00
sv_server_info_per_second, sv_van_conn_per_second: allow 0 to disable
Clean up code a bit, also allow larger values
This commit is contained in:
parent
bbb1b2cdef
commit
85bb376bdc
|
@ -285,7 +285,6 @@ CServer::CServer()
|
|||
|
||||
m_ServerInfoFirstRequest = 0;
|
||||
m_ServerInfoNumRequests = 0;
|
||||
m_ServerInfoHighLoad = false;
|
||||
|
||||
#ifdef CONF_FAMILY_UNIX
|
||||
m_ConnLoggingSocketCreated = false;
|
||||
|
@ -1472,20 +1471,24 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket)
|
|||
|
||||
void CServer::SendServerInfoConnless(const NETADDR *pAddr, int Token, int Type)
|
||||
{
|
||||
const int MaxRequests = g_Config.m_SvServerInfoPerSecond;
|
||||
int64 Now = Tick();
|
||||
bool SendClients = true;
|
||||
|
||||
if(g_Config.m_SvServerInfoPerSecond)
|
||||
{
|
||||
SendClients = m_ServerInfoNumRequests <= g_Config.m_SvServerInfoPerSecond;
|
||||
const int64 Now = Tick();
|
||||
|
||||
if(Now <= m_ServerInfoFirstRequest + TickSpeed())
|
||||
{
|
||||
m_ServerInfoNumRequests++;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ServerInfoHighLoad = m_ServerInfoNumRequests > MaxRequests;
|
||||
m_ServerInfoNumRequests = 1;
|
||||
m_ServerInfoFirstRequest = Now;
|
||||
}
|
||||
}
|
||||
|
||||
bool SendClients = m_ServerInfoNumRequests <= MaxRequests && !m_ServerInfoHighLoad;
|
||||
SendServerInfo(pAddr, Token, Type, SendClients);
|
||||
}
|
||||
|
||||
|
|
|
@ -222,7 +222,6 @@ public:
|
|||
|
||||
int m_RconRestrict;
|
||||
|
||||
bool m_ServerInfoHighLoad;
|
||||
int64 m_ServerInfoFirstRequest;
|
||||
int m_ServerInfoNumRequests;
|
||||
|
||||
|
|
|
@ -140,8 +140,8 @@ MACRO_CONFIG_INT(SvRconVote, sv_rcon_vote, 0, 0, 1, CFGFLAG_SERVER, "Only allow
|
|||
|
||||
MACRO_CONFIG_INT(SvPlayerDemoRecord, sv_player_demo_record, 0, 0, 1, CFGFLAG_SERVER, "Automatically record demos for each player")
|
||||
MACRO_CONFIG_INT(SvDemoChat, sv_demo_chat, 0, 0, 1, CFGFLAG_SERVER, "Record chat for demos")
|
||||
MACRO_CONFIG_INT(SvServerInfoPerSecond, sv_server_info_per_second, 50, 1, 1000, CFGFLAG_SERVER, "Maximum number of complete server info responses that are sent out per second")
|
||||
MACRO_CONFIG_INT(SvVanConnPerSecond, sv_van_conn_per_second, 10, 1, 1000, CFGFLAG_SERVER, "Antispoof specific ratelimit")
|
||||
MACRO_CONFIG_INT(SvServerInfoPerSecond, sv_server_info_per_second, 50, 0, 10000, CFGFLAG_SERVER, "Maximum number of complete server info responses that are sent out per second (0 for no limit)")
|
||||
MACRO_CONFIG_INT(SvVanConnPerSecond, sv_van_conn_per_second, 10, 0, 10000, CFGFLAG_SERVER, "Antispoof specific ratelimit (0 for no limit)")
|
||||
|
||||
MACRO_CONFIG_STR(EcBindaddr, ec_bindaddr, 128, "localhost", CFGFLAG_ECON, "Address to bind the external console to. Anything but 'localhost' is dangerous")
|
||||
MACRO_CONFIG_INT(EcPort, ec_port, 0, 0, 0, CFGFLAG_ECON, "Port to use for the external console")
|
||||
|
|
|
@ -319,7 +319,6 @@ class CNetServer
|
|||
unsigned char m_SecurityTokenSeed[16];
|
||||
|
||||
// vanilla connect flood detection
|
||||
bool m_VConnHighLoad;
|
||||
int64 m_VConnFirst;
|
||||
int m_VConnNum;
|
||||
|
||||
|
|
|
@ -71,7 +71,6 @@ bool CNetServer::Open(NETADDR BindAddr, CNetBan *pNetBan, int MaxClients, int Ma
|
|||
m_NumConAttempts = 0;
|
||||
m_TimeNumConAttempts = time_get();
|
||||
|
||||
m_VConnHighLoad = false;
|
||||
m_VConnNum = 0;
|
||||
m_VConnFirst = 0;
|
||||
|
||||
|
@ -336,21 +335,25 @@ void CNetServer::OnPreConnMsg(NETADDR &Addr, CNetPacketConstruct &Packet)
|
|||
if (IsCtrl && CtrlMsg == NET_CTRLMSG_CONNECT)
|
||||
{
|
||||
if (g_Config.m_SvVanillaAntiSpoof && g_Config.m_Password[0] == '\0')
|
||||
{
|
||||
bool Flooding = false;
|
||||
|
||||
if (g_Config.m_SvVanConnPerSecond)
|
||||
{
|
||||
// detect flooding
|
||||
int64 Now = time_get();
|
||||
Flooding = m_VConnNum > g_Config.m_SvVanConnPerSecond;
|
||||
const int64 Now = time_get();
|
||||
|
||||
if(Now <= m_VConnFirst + time_freq())
|
||||
{
|
||||
m_VConnNum++;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_VConnHighLoad = m_VConnNum > g_Config.m_SvVanConnPerSecond;
|
||||
m_VConnNum = 1;
|
||||
m_VConnFirst = Now;
|
||||
}
|
||||
|
||||
bool Flooding = m_VConnNum > g_Config.m_SvVanConnPerSecond || m_VConnHighLoad;
|
||||
}
|
||||
|
||||
if (g_Config.m_Debug && Flooding)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue