diff options
-rw-r--r-- | include/bancache.h | 3 | ||||
-rw-r--r-- | src/bancache.cpp | 29 |
2 files changed, 20 insertions, 12 deletions
diff --git a/include/bancache.h b/include/bancache.h index ea09d389f..9cff91802 100644 --- a/include/bancache.h +++ b/include/bancache.h @@ -58,8 +58,9 @@ typedef std::tr1::unordered_map<std::string, BanCacheHit*, std::tr1::hash<std::s */ class CoreExport BanCacheManager { - private: BanCacheHash* BanHash; + bool RemoveIfExpired(BanCacheHash::iterator& it); + public: /** Creates and adds a Ban Cache item. diff --git a/src/bancache.cpp b/src/bancache.cpp index 784f5ded6..2d60bd381 100644 --- a/src/bancache.cpp +++ b/src/bancache.cpp @@ -39,18 +39,22 @@ BanCacheHit *BanCacheManager::GetHit(const std::string &ip) if (i == this->BanHash->end()) return NULL; // free and safe - else - { - if (ServerInstance->Time() > i->second->Expiry) - { - ServerInstance->Logs->Log("BANCACHE", DEBUG, "Hit on " + ip + " is out of date, removing!"); - delete i->second; - BanHash->erase(i); - return NULL; // out of date - } - return i->second; // hit. - } + if (RemoveIfExpired(i)) + return NULL; // expired + + return i->second; // hit. +} + +bool BanCacheManager::RemoveIfExpired(BanCacheHash::iterator& it) +{ + if (ServerInstance->Time() < it->second->Expiry) + return false; + + ServerInstance->Logs->Log("BANCACHE", DEBUG, "Hit on " + it->first + " is out of date, removing!"); + delete it->second; + it = BanHash->erase(it); + return true; } void BanCacheManager::RemoveEntries(const std::string& type, bool positive) @@ -62,6 +66,9 @@ void BanCacheManager::RemoveEntries(const std::string& type, bool positive) for (BanCacheHash::iterator i = BanHash->begin(); i != BanHash->end(); ) { + if (RemoveIfExpired(i)) + continue; // updates the iterator if expired + BanCacheHit* b = i->second; bool remove = false; |