MCPcopy Create free account
hub / github.com/cppla/ServerStatus / Ban

Method Ban

server/src/netban.cpp:281–322  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

279
280template<class T>
281int 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
324template<class T>
325int CNetBan::Unban(T *pBanPool, const typename T::CDataType *pData)

Callers

nothing calls this directly

Calls 6

dbg_msgFunction · 0.85
time_timestampFunction · 0.85
str_copyFunction · 0.85
FindMethod · 0.80
AddMethod · 0.80
UpdateMethod · 0.45

Tested by

no test coverage detected