summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorattilamolnar <attilamolnar@hush.com>2012-10-01 00:48:00 +0200
committerattilamolnar <attilamolnar@hush.com>2013-04-10 19:27:23 +0200
commitc5d1a7843ed016c374b21242fccaca47e04b5a37 (patch)
tree1756805c49afd1c22e68e22270ea463d8992784d
parentca0083cba90c8830f5018b73eb715665a8db9dd7 (diff)
BanCache: Don't repeat ourselves, one BanCacheManager::AddHit() and one BanCacheHit constructor is enough
-rw-r--r--include/bancache.h20
-rw-r--r--src/bancache.cpp15
-rw-r--r--src/xline.cpp5
3 files changed, 5 insertions, 35 deletions
diff --git a/include/bancache.h b/include/bancache.h
index a99e97856..9f7402336 100644
--- a/include/bancache.h
+++ b/include/bancache.h
@@ -44,21 +44,9 @@ class CoreExport BanCacheHit
*/
time_t Expiry;
- BanCacheHit(const std::string &ip, const std::string &type, const std::string &reason)
- {
- this->Type = type;
- this->Reason = reason;
- this->IP = ip;
- this->Expiry = ServerInstance->Time() + 86400; // a day. this might seem long, but entries will be removed as glines/etc expire.
- }
-
- // overridden to allow custom time
BanCacheHit(const std::string &ip, const std::string &type, const std::string &reason, time_t seconds)
+ : Type(type), Reason(reason), IP(ip), Expiry(ServerInstance->Time() + seconds)
{
- this->Type = type;
- this->Reason = reason;
- this->IP = ip;
- this->Expiry = ServerInstance->Time() + seconds;
}
};
@@ -79,11 +67,9 @@ class CoreExport BanCacheManager
* @param ip The IP the item is for.
* @param type The type of ban cache item. std::string. .empty() means it's a negative match (user is allowed freely).
* @param reason The reason for the ban. Left .empty() if it's a negative match.
+ * @param seconds Number of seconds before nuking the bancache entry, the default is a day. This might seem long, but entries will be removed as glines/etc expire.
*/
- BanCacheHit *AddHit(const std::string &ip, const std::string &type, const std::string &reason);
-
- // Overridden to allow an optional number of seconds before expiry
- BanCacheHit *AddHit(const std::string &ip, const std::string &type, const std::string &reason, time_t seconds);
+ BanCacheHit *AddHit(const std::string &ip, const std::string &type, const std::string &reason, time_t seconds = 0);
BanCacheHit *GetHit(const std::string &ip);
bool RemoveHit(BanCacheHit *b);
diff --git a/src/bancache.cpp b/src/bancache.cpp
index 52449e55e..72f8728d3 100644
--- a/src/bancache.cpp
+++ b/src/bancache.cpp
@@ -23,19 +23,6 @@
#include "inspircd.h"
#include "bancache.h"
-BanCacheHit *BanCacheManager::AddHit(const std::string &ip, const std::string &type, const std::string &reason)
-{
- BanCacheHit *b;
-
- if (this->BanHash->find(ip) != this->BanHash->end()) // can't have two cache entries on the same IP, sorry..
- return NULL;
-
- b = new BanCacheHit(ip, type, reason);
-
- this->BanHash->insert(std::make_pair(ip, b));
- return b;
-}
-
BanCacheHit *BanCacheManager::AddHit(const std::string &ip, const std::string &type, const std::string &reason, time_t seconds)
{
BanCacheHit *b;
@@ -43,7 +30,7 @@ BanCacheHit *BanCacheManager::AddHit(const std::string &ip, const std::string &t
if (this->BanHash->find(ip) != this->BanHash->end()) // can't have two cache entries on the same IP, sorry..
return NULL;
- b = new BanCacheHit(ip, type, reason, seconds);
+ b = new BanCacheHit(ip, type, reason, (seconds ? seconds : 86400));
this->BanHash->insert(std::make_pair(ip, b));
return b;
diff --git a/src/xline.cpp b/src/xline.cpp
index 53cbe5c96..2fdf71b17 100644
--- a/src/xline.cpp
+++ b/src/xline.cpp
@@ -545,10 +545,7 @@ void XLine::DefaultApply(User* u, const std::string &line, bool bancache)
if (bancache)
{
ServerInstance->Logs->Log("BANCACHE", DEBUG, "BanCache: Adding positive hit (" + line + ") for " + u->GetIPString());
- if (this->duration > 0)
- ServerInstance->BanCache->AddHit(u->GetIPString(), this->type, line + "-Lined: " + this->reason, this->duration);
- else
- ServerInstance->BanCache->AddHit(u->GetIPString(), this->type, line + "-Lined: " + this->reason);
+ ServerInstance->BanCache->AddHit(u->GetIPString(), this->type, line + "-Lined: " + this->reason, this->duration);
}
}