1#ifndef ENGINE_SHARED_NETBAN_H
2#define ENGINE_SHARED_NETBAN_H
31 return NetComp(pAddr1, pAddr2) == 0;
49 str_format(pBuffer, BufferSize,
"'%s'", aAddrStr);
58 str_format(pBuffer, BufferSize,
"'%s' - '%s'", aAddrStr1, aAddrStr2);
103 template<
class T,
int HashCount>
123 if(
NetComp(&pBan->m_Data, pData) == 0)
154 int Ban(T *pBanPool,
const typename T::CDataType *pData,
int Seconds,
const char *pReason,
bool VerbatimReason);
156 int Unban(T *pBanPool,
const typename T::CDataType *pData);
180 virtual int BanAddr(
const NETADDR *pAddr,
int Seconds,
const char *pReason,
bool VerbatimReason);
186 bool IsBanned(
const NETADDR *pOrigAddr,
char *pBuf,
unsigned BufferSize)
const;
201 if(pBan == 0 || pBuf == 0)
211 str_copy(aBuf,
"You have been banned");
CBan< CDataType > * Add(const CDataType *pData, const CBanInfo *pInfo, const CNetHash *pNetHash)
Definition: netban.cpp:84
CBan< CDataType > * First() const
Definition: netban.h:117
CBan< CDataType > * m_pFirstFree
Definition: netban.h:139
CBan< CDataType > * First(const CNetHash *pNetHash) const
Definition: netban.h:118
T CDataType
Definition: netban.h:107
CBan< CDataType > m_aBans[MAX_BANS]
Definition: netban.h:138
void Reset()
Definition: netban.cpp:177
@ MAX_BANS
Definition: netban.h:134
CBan< CDataType > * Find(const CDataType *pData, const CNetHash *pNetHash) const
Definition: netban.h:119
int Remove(CBan< CDataType > *pBan)
Definition: netban.cpp:118
CBan< CDataType > * Get(int Index) const
Definition: netban.cpp:196
int m_CountUsed
Definition: netban.h:141
void InsertUsed(CBan< CDataType > *pBan)
Definition: netban.cpp:47
bool IsFull() const
Definition: netban.h:115
CBan< CDataType > * m_pFirstUsed
Definition: netban.h:140
void Update(CBan< CDataType > *pBan, const CBanInfo *pInfo)
Definition: netban.cpp:154
CBan< CDataType > * m_aapHashList[HashCount][256]
Definition: netban.h:137
int Num() const
Definition: netban.h:114
int m_HashIndex
Definition: netban.h:66
int m_Hash
Definition: netban.h:65
static int MakeHashArray(const NETADDR *pAddr, CNetHash aHash[17])
Definition: netban.cpp:32
void UnbanAll()
Definition: netban.cpp:170
class IConsole * m_pConsole
Definition: netban.h:158
virtual int BanAddr(const NETADDR *pAddr, int Seconds, const char *pReason, bool VerbatimReason)
Definition: netban.cpp:313
CBanPool< NETADDR, 1 > CBanAddrPool
Definition: netban.h:146
bool IsBanned(const NETADDR *pOrigAddr, char *pBuf, unsigned BufferSize) const
Definition: netban.cpp:372
bool NetMatch(const CNetRange *pRange, const NETADDR *pAddr) const
Definition: netban.h:40
static void ConBan(class IConsole::IResult *pResult, void *pUser)
Definition: netban.cpp:409
void MakeBanInfo(const CBan< T > *pBan, char *pBuf, unsigned BuffSize, int Type) const
Definition: netban.h:199
CBanRangePool m_BanRangePool
Definition: netban.h:161
static void ConUnbanRange(class IConsole::IResult *pResult, void *pUser)
Definition: netban.cpp:457
bool NetMatch(const NETADDR *pAddr1, const NETADDR *pAddr2) const
Definition: netban.h:29
class IStorage * Storage() const
Definition: netban.h:174
const char * NetToString(const NETADDR *pData, char *pBuffer, unsigned BufferSize) const
Definition: netban.h:45
CBanAddrPool m_BanAddrPool
Definition: netban.h:160
CBanPool< CNetRange, 16 > CBanRangePool
Definition: netban.h:147
virtual ~CNetBan()
Definition: netban.h:176
void Update()
Definition: netban.cpp:293
static void ConUnban(class IConsole::IResult *pResult, void *pUser)
Definition: netban.cpp:440
bool NetMatch(const CNetRange *pRange, const NETADDR *pAddr, int Start, int Length) const
Definition: netban.h:34
CBan< CNetRange > CBanRange
Definition: netban.h:149
int UnbanByIndex(int Index)
Definition: netban.cpp:341
int Ban(T *pBanPool, const typename T::CDataType *pData, int Seconds, const char *pReason, bool VerbatimReason)
Definition: netban.cpp:211
int UnbanByRange(const CNetRange *pRange)
Definition: netban.cpp:332
static void ConBansFind(class IConsole::IResult *pResult, void *pUser)
Definition: netban.cpp:532
CBan< NETADDR > CBanAddr
Definition: netban.h:148
static void ConBans(class IConsole::IResult *pResult, void *pUser)
Definition: netban.cpp:479
int Unban(T *pBanPool, const typename T::CDataType *pData)
Definition: netban.cpp:256
NETADDR m_LocalhostIpV6
Definition: netban.h:162
static void ConBansSave(class IConsole::IResult *pResult, void *pUser)
Definition: netban.cpp:581
@ MSGTYPE_BANADD
Definition: netban.h:169
@ MSGTYPE_PLAYER
Definition: netban.h:167
@ MSGTYPE_LIST
Definition: netban.h:168
@ MSGTYPE_BANREM
Definition: netban.h:170
class IStorage * m_pStorage
Definition: netban.h:159
NETADDR m_LocalhostIpV4
Definition: netban.h:162
const char * NetToString(const CNetRange *pData, char *pBuffer, unsigned BufferSize) const
Definition: netban.h:53
virtual int BanRange(const CNetRange *pRange, int Seconds, const char *pReason)
Definition: netban.cpp:318
static void ConBanRange(class IConsole::IResult *pResult, void *pUser)
Definition: netban.cpp:424
void Init(class IConsole *pConsole, class IStorage *pStorage)
Definition: netban.cpp:273
int UnbanByAddr(const NETADDR *pAddr)
Definition: netban.cpp:327
class IConsole * Console() const
Definition: netban.h:173
static void ConUnbanAll(class IConsole::IResult *pResult, void *pUser)
Definition: netban.cpp:471
NETADDR m_UB
Definition: netban.h:16
bool IsValid() const
Definition: netban.h:18
NETADDR m_LB
Definition: netban.h:15
int mem_comp(const void *a, const void *b, size_t size)
Definition: system.cpp:184
bool net_addr_str(const NETADDR *addr, char *string, int max_length, int add_port)
Definition: system.cpp:1147
int str_copy(char *dst, const char *src, int dst_size)
Definition: system.cpp:2761
int64_t time_timestamp()
Definition: system.cpp:2641
int NetComp(const NETADDR *pAddr1, const NETADDR *pAddr2)
Definition: netban.h:7
bool m_VerbatimReason
Definition: netban.h:84
int64_t m_Expires
Definition: netban.h:82
char m_aReason[REASON_LENGTH]
Definition: netban.h:83
@ EXPIRES_NEVER
Definition: netban.h:79
@ REASON_LENGTH
Definition: netban.h:80
T m_Data
Definition: netban.h:90
CBan * m_pHashNext
Definition: netban.h:95
CBanInfo m_Info
Definition: netban.h:91
CBan * m_pNext
Definition: netban.h:99
CNetHash m_NetHash
Definition: netban.h:92
CBan * m_pPrev
Definition: netban.h:100
CBan * m_pHashPrev
Definition: netban.h:96
unsigned char ip[16]
Definition: types.h:69
unsigned int type
Definition: types.h:68
#define str_format
Definition: system.cpp:2830
@ NETADDR_MAXSTRSIZE
Definition: types.h:45
@ NETTYPE_IPV4
Definition: types.h:50