summaryrefslogtreecommitdiff
path: root/engine/sv_ipratelimit.h
diff options
context:
space:
mode:
Diffstat (limited to 'engine/sv_ipratelimit.h')
-rw-r--r--engine/sv_ipratelimit.h55
1 files changed, 55 insertions, 0 deletions
diff --git a/engine/sv_ipratelimit.h b/engine/sv_ipratelimit.h
new file mode 100644
index 0000000..74f4c8e
--- /dev/null
+++ b/engine/sv_ipratelimit.h
@@ -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