| 279 | |
| 280 | template<class T> |
| 281 | int CNetBan::Ban(T *pBanPool, const typename T::CDataType *pData, int Seconds, const char *pReason) |
| 282 | { |
| 283 | // do not ban localhost |
| 284 | if(NetMatch(pData, &m_LocalhostIPV4) || NetMatch(pData, &m_LocalhostIPV6)) |
| 285 | { |
| 286 | dbg_msg("net_ban", "ban failed (localhost)"); |
| 287 | return -1; |
| 288 | } |
| 289 | |
| 290 | int Stamp = Seconds > 0 ? time_timestamp()+Seconds : CBanInfo::EXPIRES_NEVER; |
| 291 | |
| 292 | // set up info |
| 293 | CBanInfo Info = {0}; |
| 294 | Info.m_Expires = Stamp; |
| 295 | str_copy(Info.m_aReason, pReason, sizeof(Info.m_aReason)); |
| 296 | |
| 297 | // check if it already exists |
| 298 | CNetHash NetHash(pData); |
| 299 | CBan<typename T::CDataType> *pBan = pBanPool->Find(pData, &NetHash); |
| 300 | if(pBan) |
| 301 | { |
| 302 | // adjust the ban |
| 303 | pBanPool->Update(pBan, &Info); |
| 304 | char aBuf[128]; |
| 305 | MakeBanInfo(pBan, aBuf, sizeof(aBuf), MSGTYPE_LIST); |
| 306 | dbg_msg("net_ban", aBuf); |
| 307 | return 1; |
| 308 | } |
| 309 | |
| 310 | // add ban and print result |
| 311 | pBan = pBanPool->Add(pData, &Info, &NetHash); |
| 312 | if(pBan) |
| 313 | { |
| 314 | char aBuf[128]; |
| 315 | MakeBanInfo(pBan, aBuf, sizeof(aBuf), MSGTYPE_BANADD); |
| 316 | dbg_msg("net_ban", aBuf); |
| 317 | return 0; |
| 318 | } |
| 319 | else |
| 320 | dbg_msg("net_ban", "ban failed (full banlist)"); |
| 321 | return -1; |
| 322 | } |
| 323 | |
| 324 | template<class T> |
| 325 | int CNetBan::Unban(T *pBanPool, const typename T::CDataType *pData) |