summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2007-11-02 12:35:18 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2007-11-02 12:35:18 +0000
commit786093b7515e923921f65125ab5bf18f2279f923 (patch)
treeabb6d9fe100b2fcb9d1543077a276ec291670243 /src
parentbc6c0898c5d3899e0fbb2171b14c2e23f172d954 (diff)
xline gutting, once more. There is no longer an active_lines vector, and no requirement for sorting. Expiry will be cheked on a per-line basis for each positive hit on that line,
saving on cpu time. git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@8457 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-rw-r--r--src/commands/cmd_nick.cpp2
-rw-r--r--src/users.cpp10
-rw-r--r--src/xline.cpp155
3 files changed, 48 insertions, 119 deletions
diff --git a/src/commands/cmd_nick.cpp b/src/commands/cmd_nick.cpp
index 04b03055e..aaa6698ac 100644
--- a/src/commands/cmd_nick.cpp
+++ b/src/commands/cmd_nick.cpp
@@ -60,7 +60,7 @@ CmdResult CommandNick::Handle (const char** parameters, int, User *user)
}
else
{
- QLine* mq = ServerInstance->XLines->matches_qline(parameters[0]);
+ XLine* mq = ServerInstance->XLines->MatchesLine('Q',parameters[0]);
if (mq)
{
ServerInstance->SNO->WriteToSnoMask('x', "Q-Lined nickname %s from %s!%s@%s: %s", parameters[0], user->nick, user->ident, user->host, mq->reason);
diff --git a/src/users.cpp b/src/users.cpp
index 5f61ce1df..0f451d2a9 100644
--- a/src/users.cpp
+++ b/src/users.cpp
@@ -830,10 +830,10 @@ void User::AddClient(InspIRCd* Instance, int socket, int port, bool iscached, in
}
#endif
- New->exempt = (Instance->XLines->matches_exception(New) != NULL);
+ New->exempt = (Instance->XLines->MatchesLine('E',New) != NULL);
if (!New->exempt)
{
- ZLine* r = Instance->XLines->matches_zline(New);
+ XLine* r = Instance->XLines->MatchesLine('Z',New);
if (r)
{
@@ -942,7 +942,7 @@ void User::FullConnect()
if (!this->exempt)
{
- GLine* r = ServerInstance->XLines->matches_gline(this);
+ XLine* r = ServerInstance->XLines->MatchesLine('G',this);
if (r)
{
@@ -955,7 +955,7 @@ void User::FullConnect()
return;
}
- KLine* n = ServerInstance->XLines->matches_kline(this);
+ XLine* n = ServerInstance->XLines->MatchesLine('K',this);
if (n)
{
@@ -1065,7 +1065,7 @@ bool User::ForceNickChange(const char* newnick)
return false;
}
- if (ServerInstance->XLines->matches_qline(newnick))
+ if (ServerInstance->XLines->MatchesLine('Q',newnick))
{
ServerInstance->stats->statsCollisions++;
return false;
diff --git a/src/xline.cpp b/src/xline.cpp
index 8fbb73280..a3ae9ffa8 100644
--- a/src/xline.cpp
+++ b/src/xline.cpp
@@ -120,9 +120,6 @@ bool XLineManager::AddLine(XLine* line, User* user)
return false;
/*ELine* item = new ELine(ServerInstance, ServerInstance->Time(), duration, source, reason, ih.first.c_str(), ih.second.c_str());*/
-
- active_lines.push_back(line);
- sort(active_lines.begin(), active_lines.end(), XLineManager::XSortComparison);
pending_lines.push_back(line);
lookup_lines[line->type][line->Displayable()] = line;
line->OnAdd();
@@ -135,51 +132,40 @@ bool XLineManager::AddLine(XLine* line, User* user)
return true;
}
-/*bool XLineManager::AddZLine(long duration, const char* source, const char* reason, const char* ipaddr)
-{
- if (strchr(ipaddr,'@'))
- {
- while (*ipaddr != '@')
- ipaddr++;
- ipaddr++;
- }*/
-
-// deletes a g:line, returns true if the line existed and was removed
+// deletes a line, returns true if the line existed and was removed
bool XLineManager::DelLine(const char* hostmask, char type, User* user, bool simulate)
{
- IdentHostPair ih = IdentSplit(hostmask);
- for (std::vector<XLine*>::iterator i = active_lines.begin(); i != active_lines.end(); i++)
- {
- if ((*i)->type == type)
- {
- if ((*i)->MatchesLiteral(hostmask))
- {
- if (!simulate)
- {
- (*i)->Unset();
+ std::map<char, std::map<std::string, XLine*> >::iterator x = lookup_lines.find(type);
- if (lookup_lines.find(type) != lookup_lines.end())
- lookup_lines[type].erase(hostmask);
+ if (x == lookup_lines.end())
+ return false;
- FOREACH_MOD(I_OnDelLine,OnDelLine(user, *i));
+ std::map<std::string, XLine*>::iterator y = lookup_lines[type].find(hostmask);
- std::vector<XLine*>::iterator pptr = std::find(pending_lines.begin(), pending_lines.end(), *i);
- if (pptr != pending_lines.end())
- pending_lines.erase(pptr);
+ if (y == lookup_lines[type].end())
+ return false;
- if (!(*i)->duration)
- PermLines--;
+ if (simulate)
+ return true;
- delete *i;
- active_lines.erase(i);
- }
- return true;
- }
- }
- }
+ FOREACH_MOD(I_OnDelLine,OnDelLine(user, y->second));
- return false;
+ y->second->Unset();
+
+ lookup_lines[type].erase(hostmask);
+
+ std::vector<XLine*>::iterator pptr = std::find(pending_lines.begin(), pending_lines.end(), y->second);
+ if (pptr != pending_lines.end())
+ pending_lines.erase(pptr);
+
+ if (y->second->duration)
+ PermLines--;
+
+ delete y->second;
+ lookup_lines[type].erase(y);
+
+ return true;
}
@@ -198,101 +184,43 @@ void ELine::Unset()
// returns a pointer to the reason if a nickname matches a qline, NULL if it didnt match
-QLine* XLineManager::matches_qline(const char* nick)
-{
- if (lookup_lines.find('Q') == lookup_lines.end())
- return NULL;
-
- if (lookup_lines.find('Q') != lookup_lines.end() && lookup_lines['Q'].empty())
- return NULL;
-
- for (std::vector<XLine*>::iterator i = active_lines.begin(); i != active_lines.end(); i++)
- if ((*i)->type == 'Q' && (*i)->Matches(nick))
- return (QLine*)(*i);
- return NULL;
-}
-
-// returns a pointer to the reason if a host matches a gline, NULL if it didnt match
-
-GLine* XLineManager::matches_gline(User* user)
+XLine* XLineManager::MatchesLine(const char type, User* user)
{
- if (lookup_lines.find('G') == lookup_lines.end())
- return NULL;
-
- if (lookup_lines.find('G') != lookup_lines.end() && lookup_lines['G'].empty())
- return NULL;
-
- for (std::vector<XLine*>::iterator i = active_lines.begin(); i != active_lines.end(); i++)
- if ((*i)->type == 'G' && (*i)->Matches(user))
- return (GLine*)(*i);
-
- return NULL;
-}
+ std::map<char, std::map<std::string, XLine*> >::iterator x = lookup_lines.find(type);
-ELine* XLineManager::matches_exception(User* user)
-{
- if (lookup_lines.find('E') == lookup_lines.end())
+ if (x == lookup_lines.end())
return NULL;
- if (lookup_lines.find('E') != lookup_lines.end() && lookup_lines['E'].empty())
- return NULL;
- for (std::vector<XLine*>::iterator i = active_lines.begin(); i != active_lines.end(); i++)
+ for (std::map<std::string, XLine*>::iterator i = x->second.begin(); i != x->second.end(); i++)
{
- if ((*i)->type == 'E' && (*i)->Matches(user))
- return (ELine*)(*i);
+ if (i->second->Matches(user))
+ return i->second;
}
return NULL;
}
-// returns a pointer to the reason if an ip address matches a zline, NULL if it didnt match
-
-ZLine* XLineManager::matches_zline(User *u)
-{
- if (lookup_lines.find('Z') == lookup_lines.end())
- return NULL;
-
- if (lookup_lines.find('Z') != lookup_lines.end() && lookup_lines['Z'].empty())
- return NULL;
-
- for (std::vector<XLine*>::iterator i = active_lines.begin(); i != active_lines.end(); i++)
- if ((*i)->type == 'Z' && (*i)->Matches(u))
- return (ZLine*)(*i);
- return NULL;
-}
-
-// returns a pointer to the reason if a host matches a kline, NULL if it didnt match
-
-KLine* XLineManager::matches_kline(User* user)
+XLine* XLineManager::MatchesLine(const char type, const std::string &pattern)
{
- if (lookup_lines.find('K') == lookup_lines.end())
- return NULL;
+ std::map<char, std::map<std::string, XLine*> >::iterator x = lookup_lines.find(type);
- if (lookup_lines.find('K') != lookup_lines.end() && lookup_lines['K'].empty())
+ if (x == lookup_lines.end())
return NULL;
- for (std::vector<XLine*>::iterator i = active_lines.begin(); i != active_lines.end(); i++)
- if ((*i)->Matches(user))
- return (KLine*)(*i);
+ for (std::map<std::string, XLine*>::iterator i = x->second.begin(); i != x->second.end(); i++)
+ {
+ if (i->second->Matches(pattern))
+ return i->second;
+ }
return NULL;
}
-bool XLineManager::XSortComparison(const XLine *one, const XLine *two)
-{
- return (one->expiry) < (two->expiry);
-}
// removes lines that have expired
void XLineManager::expire_lines()
{
- time_t current = ServerInstance->Time();
-
- /* Because we now store all our XLines in sorted order using ((*i)->duration + (*i)->set_time) as a key, this
- * means that to expire the XLines we just need to do a while, picking off the top few until there are
- * none left at the head of the queue that are after the current time. We use PermLines as an offset into the
- * vector past the first item with a duration 0.
- */
+/* time_t current = ServerInstance->Time();
std::vector<XLine*>::iterator start = active_lines.begin() + PermLines;
@@ -313,9 +241,10 @@ void XLineManager::expire_lines()
delete *start;
active_lines.erase(start);
- }
+ }*/
}
+
// applies lines, removing clients and changing nicks etc as applicable
void XLineManager::ApplyLines()
{