mirror of
https://github.com/nillerusr/source-engine.git
synced 2026-08-13 20:21:06 +00:00
1
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose: rate limits OOB server queries
|
||||
//
|
||||
//=============================================================================//
|
||||
|
||||
#ifndef SVIPRATELIMIT_H
|
||||
#define SVIPRATELIMIT_H
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "netadr.h"
|
||||
#include "sv_ipratelimit.h"
|
||||
#include "convar.h"
|
||||
#include "utlrbtree.h"
|
||||
|
||||
class CIPRateLimit
|
||||
{
|
||||
public:
|
||||
CIPRateLimit(ConVar *maxSec, ConVar *maxWindow, ConVar *maxSecGlobal);
|
||||
~CIPRateLimit();
|
||||
|
||||
// updates an ip entry, return true if the ip is allowed, false otherwise
|
||||
bool CheckIP( netadr_t ip );
|
||||
|
||||
private:
|
||||
bool CheckIPInternal( netadr_t ip );
|
||||
|
||||
enum { MAX_TREE_SIZE = 32768, START_TREE_SIZE = 2048, FLUSH_TIMEOUT = 120 };
|
||||
|
||||
typedef int ip_t;
|
||||
struct iprate_s
|
||||
{
|
||||
ip_t ip;
|
||||
long lastTime;
|
||||
int count;
|
||||
};
|
||||
|
||||
static bool LessIP( const struct CIPRateLimit::iprate_s &lhs, const struct CIPRateLimit::iprate_s &rhs );
|
||||
|
||||
CUtlRBTree< struct iprate_s, ip_t > m_IPTree;
|
||||
int m_iGlobalCount;
|
||||
long m_lLastTime;
|
||||
double m_flFlushTime;
|
||||
|
||||
ConVar *m_maxSec;
|
||||
ConVar *m_maxWindow;
|
||||
ConVar *m_maxSecGlobal;
|
||||
};
|
||||
|
||||
// returns false if this IP exceeds rate limits
|
||||
bool CheckConnectionLessRateLimits( netadr_t & adr );
|
||||
|
||||
#endif // SVIPRATELIMIT_H
|
||||
Reference in New Issue
Block a user