summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/xline.h13
-rw-r--r--src/xline.cpp150
2 files changed, 107 insertions, 56 deletions
diff --git a/include/xline.h b/include/xline.h
index 9fd4d0bea..fd25976f4 100644
--- a/include/xline.h
+++ b/include/xline.h
@@ -82,6 +82,10 @@ class CoreExport XLine : public classbase
/** Expiry time
*/
time_t expiry;
+
+ /** Q, K, etc. Don't change this. Constructors set it.
+ */
+ char type;
};
/** KLine class
@@ -101,6 +105,7 @@ class CoreExport KLine : public XLine
{
identmask = strdup(ident);
hostmask = strdup(host);
+ type = 'K';
}
/** Destructor
@@ -138,6 +143,7 @@ class CoreExport GLine : public XLine
{
identmask = strdup(ident);
hostmask = strdup(host);
+ type = 'G';
}
/** Destructor
@@ -175,6 +181,7 @@ class CoreExport ELine : public XLine
{
identmask = strdup(ident);
hostmask = strdup(host);
+ type = 'E';
}
~ELine()
@@ -208,6 +215,7 @@ class CoreExport ZLine : public XLine
ZLine(time_t s_time, long d, const char* src, const char* re, const char* ip) : XLine(s_time, d, src, re)
{
ipaddr = strdup(ip);
+ type = 'Z';
}
/** Destructor
@@ -241,6 +249,7 @@ class CoreExport QLine : public XLine
QLine(time_t s_time, long d, const char* src, const char* re, const char* nickname) : XLine(s_time, d, src, re)
{
nick = strdup(nickname);
+ type = 'Q';
}
/** Destructor
@@ -310,6 +319,10 @@ class CoreExport XLineManager
/** This functor is used by the std::sort() function to keep all lines in order
*/
static bool XSortComparison (const XLine *one, const XLine *two);
+
+ /** Used to hold XLines which have not yet been applied.
+ */
+ std::vector<XLine *> pending_lines;
public:
/* Lists for temporary lines with an expiry time */
diff --git a/src/xline.cpp b/src/xline.cpp
index 71e94aab7..193d31cf1 100644
--- a/src/xline.cpp
+++ b/src/xline.cpp
@@ -171,6 +171,7 @@ bool XLineManager::AddGLine(long duration, const char* source,const char* reason
glines.push_back(item);
sort(glines.begin(), glines.end(),XLineManager::XSortComparison);
+ pending_lines.push_back(item);
return true;
}
@@ -188,6 +189,7 @@ bool XLineManager::AddELine(long duration, const char* source, const char* reaso
elines.push_back(item);
sort(elines.begin(), elines.end(),XLineManager::XSortComparison);
+ pending_lines.push_back(item);
return true;
}
@@ -203,6 +205,7 @@ bool XLineManager::AddQLine(long duration, const char* source, const char* reaso
qlines.push_back(item);
sort(qlines.begin(), qlines.end(),XLineManager::XSortComparison);
+ pending_lines.push_back(item);
return true;
}
@@ -225,6 +228,7 @@ bool XLineManager::AddZLine(long duration, const char* source, const char* reaso
zlines.push_back(item);
sort(zlines.begin(), zlines.end(),XLineManager::XSortComparison);
+ pending_lines.push_back(item);
return true;
}
@@ -242,6 +246,7 @@ bool XLineManager::AddKLine(long duration, const char* source, const char* reaso
klines.push_back(item);
sort(klines.begin(), klines.end(),XLineManager::XSortComparison);
+ pending_lines.push_back(item);
return true;
}
@@ -357,7 +362,7 @@ QLine* XLineManager::matches_qline(const char* nick)
return NULL;
for (std::vector<QLine*>::iterator i = qlines.begin(); i != qlines.end(); i++)
- if ((*i)->Matches(user))
+ if ((*i)->Matches(nick))
return (*i);
return NULL;
}
@@ -542,7 +547,6 @@ void XLineManager::expire_lines()
void XLineManager::ApplyLines()
{
- int What = 0; // XXX remove me
char reason[MAXBUF];
XLine* check = NULL;
@@ -552,63 +556,97 @@ void XLineManager::ApplyLines()
if (elines.size())
{
- // ignore people matching exempts
+ // ignore people matching exempts -- XXX cache the exempt state in userrec permanently?
+ // should be fairly easy to accomplish really, and might achieve some nice gains?
if (matches_exception(u))
continue;
}
- if ((What & APPLY_GLINES) && (glines.size()))
- {
- if ((check = matches_gline(u)))
- {
- snprintf(reason,MAXBUF,"G-Lined: %s",check->reason);
- if (*ServerInstance->Config->MoronBanner)
- u->WriteServ("NOTICE %s :*** %s", u->nick, ServerInstance->Config->MoronBanner);
- if (ServerInstance->Config->HideBans)
- User::QuitUser(ServerInstance, u, "G-Lined", reason);
- else
- User::QuitUser(ServerInstance, u, reason);
- }
- }
- if ((What & APPLY_KLINES) && (klines.size()))
- {
- if ((check = matches_kline(u)))
- {
- snprintf(reason,MAXBUF,"K-Lined: %s",check->reason);
- if (*ServerInstance->Config->MoronBanner)
- u->WriteServ("NOTICE %s :*** %s", u->nick, ServerInstance->Config->MoronBanner);
- if (ServerInstance->Config->HideBans)
- User::QuitUser(ServerInstance, u, "K-Lined", reason);
- else
- User::QuitUser(ServerInstance, u, reason);
- }
- }
- if ((What & APPLY_QLINES) && (qlines.size()))
- {
- if ((check = matches_qline(u->nick)))
- {
- snprintf(reason,MAXBUF,"Q-Lined: %s",check->reason);
- if (*ServerInstance->Config->MoronBanner)
- u->WriteServ("NOTICE %s :*** %s", u->nick, ServerInstance->Config->MoronBanner);
- if (ServerInstance->Config->HideBans)
- User::QuitUser(ServerInstance, u, "Q-Lined", reason);
- else
- User::QuitUser(ServerInstance, u, reason);
- }
- }
- if ((What & APPLY_ZLINES) && (zlines.size()))
+
+ for (std::vector<XLine *>::iterator i = pending_lines.begin(); i != pending_lines.end(); i++)
{
- if ((check = matches_zline(u)))
+ XLine *x = (*i);
+
+ switch (x->type)
{
- snprintf(reason,MAXBUF,"Z-Lined: %s", check->reason);
- if (*ServerInstance->Config->MoronBanner)
- u->WriteServ("NOTICE %s :*** %s", u->nick, ServerInstance->Config->MoronBanner);
- if (ServerInstance->Config->HideBans)
- User::QuitUser(ServerInstance, u, "Z-Lined", reason);
- else
- User::QuitUser(ServerInstance, u, reason);
+ case 'Z':
+ {
+ ZLine *z = dynamic_cast<ZLine *>(x);
+
+ if (z->Matches(u))
+ {
+ snprintf(reason,MAXBUF,"Z-Lined: %s", check->reason);
+ if (*ServerInstance->Config->MoronBanner)
+ u->WriteServ("NOTICE %s :*** %s", u->nick, ServerInstance->Config->MoronBanner);
+ if (ServerInstance->Config->HideBans)
+ User::QuitUser(ServerInstance, u, "Z-Lined", reason);
+ else
+ User::QuitUser(ServerInstance, u, reason);
+ }
+ break;
+ }
+ case 'G':
+ {
+ GLine *g = dynamic_cast<GLine *>(x);
+
+ if (g->Matches(u))
+ {
+ snprintf(reason,MAXBUF,"G-Lined: %s",check->reason);
+ if (*ServerInstance->Config->MoronBanner)
+ u->WriteServ("NOTICE %s :*** %s", u->nick, ServerInstance->Config->MoronBanner);
+ if (ServerInstance->Config->HideBans)
+ User::QuitUser(ServerInstance, u, "G-Lined", reason);
+ else
+ User::QuitUser(ServerInstance, u, reason);
+ }
+ break;
+ }
+ case 'Q':
+ {
+ QLine *q = dynamic_cast<QLine *>(x);
+
+ if (q->Matches(u))
+ {
+ snprintf(reason,MAXBUF,"Q-Lined: %s",check->reason);
+ if (*ServerInstance->Config->MoronBanner)
+ u->WriteServ("NOTICE %s :*** %s", u->nick, ServerInstance->Config->MoronBanner);
+ if (ServerInstance->Config->HideBans)
+ User::QuitUser(ServerInstance, u, "Q-Lined", reason);
+ else
+ User::QuitUser(ServerInstance, u, reason);
+ }
+ break;
+ }
+ case 'K':
+ {
+ KLine *k = dynamic_cast<KLine *>(x);
+
+ if (k->Matches(u))
+ {
+ snprintf(reason,MAXBUF,"K-Lined: %s",check->reason);
+ if (*ServerInstance->Config->MoronBanner)
+ u->WriteServ("NOTICE %s :*** %s", u->nick, ServerInstance->Config->MoronBanner);
+ if (ServerInstance->Config->HideBans)
+ User::QuitUser(ServerInstance, u, "K-Lined", reason);
+ else
+ User::QuitUser(ServerInstance, u, reason);
+ }
+ break;
+ }
+ case 'E':
+ {
+// ELine *e = dynamic_cast<ELine *>(x);
+ break;
+ }
+ default:
+ {
+ ServerInstance->Log(DEBUG, "Unknown line type pending: %c", x->type);
+ break;
+ }
}
}
}
+
+ pending_lines.clear();
}
void XLineManager::stats_k(User* user, string_list &results)
@@ -650,10 +688,10 @@ XLineManager::XLineManager(InspIRCd* Instance) : ServerInstance(Instance)
{
}
-virtual bool Matches(const std::string &str)
-{
- return false;
-}
+//irtual bool Matches(const std::string &str)
+//{
+ //return false;
+//}
bool KLine::Matches(User *u)
{
@@ -704,7 +742,7 @@ bool ZLine::Matches(User *u)
bool QLine::Matches(User *u)
{
- if (match(user->nick, this->nick))
+ if (match(u->nick, this->nick))
return true;
return false;