| 210 | |
| 211 | template<class T> |
| 212 | int CNetBan::Ban(T *pBanPool, const typename T::CDataType *pData, int Seconds, const char *pReason, bool VerbatimReason) |
| 213 | { |
| 214 | // do not ban localhost |
| 215 | if(NetMatch(pData, &m_LocalhostIpV4) || NetMatch(pData, &m_LocalhostIpV6)) |
| 216 | { |
| 217 | Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "net_ban", "ban failed (localhost)"); |
| 218 | return -1; |
| 219 | } |
| 220 | |
| 221 | int64_t Stamp = Seconds > 0 ? time_timestamp() + Seconds : static_cast<int64_t>(CBanInfo::EXPIRES_NEVER); |
| 222 | |
| 223 | // set up info |
| 224 | CBanInfo Info = {0}; |
| 225 | Info.m_Expires = Stamp; |
| 226 | Info.m_VerbatimReason = VerbatimReason; |
| 227 | str_copy(Info.m_aReason, pReason); |
| 228 | |
| 229 | // check if it already exists |
| 230 | CNetHash NetHash(pData); |
| 231 | CBan<typename T::CDataType> *pBan = pBanPool->Find(pData, &NetHash); |
| 232 | if(pBan) |
| 233 | { |
| 234 | // adjust the ban |
| 235 | pBanPool->Update(pBan, &Info); |
| 236 | char aBuf[256]; |
| 237 | MakeBanInfo(pBan, aBuf, sizeof(aBuf), MSGTYPE_LIST); |
| 238 | Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "net_ban", aBuf); |
| 239 | return 1; |
| 240 | } |
| 241 | |
| 242 | // add ban and print result |
| 243 | pBan = pBanPool->Add(pData, &Info, &NetHash); |
| 244 | if(pBan) |
| 245 | { |
| 246 | char aBuf[256]; |
| 247 | MakeBanInfo(pBan, aBuf, sizeof(aBuf), MSGTYPE_BANADD); |
| 248 | Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "net_ban", aBuf); |
| 249 | return 0; |
| 250 | } |
| 251 | else |
| 252 | Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "net_ban", "ban failed (full banlist)"); |
| 253 | return -1; |
| 254 | } |
| 255 | |
| 256 | template<class T> |
| 257 | int CNetBan::Unban(T *pBanPool, const typename T::CDataType *pData) |