mirror of
https://github.com/anope/anope.git
synced 2026-06-12 19:14:47 +02:00
Used std::list for ignore's IgnoreData instead of using the old C-style double-linked list, also removed the addition of an ignore when a command "takes too long".
This commit is contained in:
+1
-1
@@ -327,7 +327,7 @@ E bool is_on_access(User *u, NickCore *nc);
|
||||
/**** process.c ****/
|
||||
|
||||
E int allow_ignore;
|
||||
E IgnoreData *ignore;
|
||||
E std::list<IgnoreData *> ignore;
|
||||
|
||||
E void add_ignore(const Anope::string &nick, time_t delta);
|
||||
E IgnoreData *get_ignore(const Anope::string &nick);
|
||||
|
||||
@@ -777,7 +777,6 @@ struct EList
|
||||
|
||||
struct IgnoreData
|
||||
{
|
||||
IgnoreData *prev, *next;
|
||||
Anope::string mask;
|
||||
time_t time; /* When do we stop ignoring them? */
|
||||
};
|
||||
|
||||
+11
-25
@@ -53,17 +53,15 @@ class CommandOSIgnore : public Command
|
||||
|
||||
CommandReturn DoList(User *u)
|
||||
{
|
||||
IgnoreData *id;
|
||||
|
||||
if (!ignore)
|
||||
if (ignore.empty())
|
||||
{
|
||||
notice_lang(Config.s_OperServ, u, OPER_IGNORE_LIST_EMPTY);
|
||||
return MOD_CONT;
|
||||
}
|
||||
|
||||
notice_lang(Config.s_OperServ, u, OPER_IGNORE_LIST);
|
||||
for (id = ignore; id; id = id->next)
|
||||
u->SendMessage(Config.s_OperServ, "%s", id->mask.c_str());
|
||||
for (std::list<IgnoreData *>::iterator ign = ignore.begin(), ign_end = ignore.end(); ign != ign_end; ++ign)
|
||||
u->SendMessage(Config.s_OperServ, "%s", (*ign)->mask.c_str());
|
||||
|
||||
return MOD_CONT;
|
||||
}
|
||||
@@ -154,11 +152,7 @@ class OSIgnore : public Module
|
||||
IgnoreData *ign = new IgnoreData();
|
||||
ign->mask = params[2];
|
||||
ign->time = params[3].is_number_only() ? convertTo<time_t>(params[3]) : 0;
|
||||
ign->prev = NULL;
|
||||
ign->next = ignore;
|
||||
if (ignore)
|
||||
ignore->prev = ign;
|
||||
ignore = ign;
|
||||
ignore.push_front(ign);
|
||||
|
||||
return EVENT_STOP;
|
||||
}
|
||||
@@ -168,30 +162,22 @@ class OSIgnore : public Module
|
||||
|
||||
void OnDatabaseWrite(void (*Write)(const Anope::string &))
|
||||
{
|
||||
IgnoreData *ign, *next;
|
||||
time_t now = time(NULL);
|
||||
|
||||
for (ign = ignore; ign; ign = next)
|
||||
for (std::list<IgnoreData *>::iterator ign = ignore.begin(), ign_end = ignore.end(); ign != ign_end; )
|
||||
{
|
||||
next = ign->next;
|
||||
|
||||
if (ign->time && ign->time <= now)
|
||||
if ((*ign)->time && (*ign)->time <= now)
|
||||
{
|
||||
Alog(LOG_DEBUG) << "[os_ignore] Expiring ignore entry " << ign->mask;
|
||||
if (ign->prev)
|
||||
ign->prev->next = ign->next;
|
||||
else if (ignore == ign)
|
||||
ignore = ign->next;
|
||||
if (ign->next)
|
||||
ign->next->prev = ign->prev;
|
||||
delete ign;
|
||||
ign = NULL;
|
||||
Alog(LOG_DEBUG) << "[os_ignore] Expiring ignore entry " << (*ign)->mask;
|
||||
delete *ign;
|
||||
ign = ignore.erase(ign);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::stringstream buf;
|
||||
buf << "OS IGNORE " << ign->mask << " " << ign->time;
|
||||
buf << "OS IGNORE " << (*ign)->mask << " " << (*ign)->time;
|
||||
Write(buf.str());
|
||||
++ign;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,14 +194,6 @@ int m_privmsg(const Anope::string &source, const Anope::string &receiver, const
|
||||
else if (!Config.s_BotServ.empty() && bi->nick.equals_ci(Config.s_BotServ))
|
||||
botserv(u, bi, message);
|
||||
}
|
||||
|
||||
/* Add to ignore list if the command took a significant amount of time. */
|
||||
if (allow_ignore)
|
||||
{
|
||||
stoptime = time(NULL);
|
||||
if (stoptime > starttime && source.find('.') == Anope::string::npos)
|
||||
add_ignore(source, stoptime - starttime);
|
||||
}
|
||||
}
|
||||
|
||||
return MOD_CONT;
|
||||
|
||||
+53
-74
@@ -18,27 +18,24 @@
|
||||
int allow_ignore = 1;
|
||||
|
||||
/* Masks to ignore. */
|
||||
IgnoreData *ignore;
|
||||
std::list<IgnoreData *> ignore;
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Add a mask/nick to the ignorelits for delta seconds.
|
||||
* Add a mask/nick to the ignorelist for delta seconds.
|
||||
* @param nick Nick or (nick!)user@host to add to the ignorelist.
|
||||
* @param delta Seconds untill new entry is set to expire. 0 for permanent.
|
||||
*/
|
||||
void add_ignore(const Anope::string &nick, time_t delta)
|
||||
{
|
||||
IgnoreData *ign;
|
||||
Anope::string tmp, mask;
|
||||
size_t user, host;
|
||||
User *u;
|
||||
time_t now;
|
||||
if (nick.empty())
|
||||
return;
|
||||
now = time(NULL);
|
||||
/* If it s an existing user, we ignore the hostmask. */
|
||||
if ((u = finduser(nick)))
|
||||
Anope::string mask;
|
||||
User *u = finduser(nick);
|
||||
size_t user, host;
|
||||
if (u)
|
||||
mask = "*!*@" + u->host;
|
||||
/* Determine whether we get a nick or a mask. */
|
||||
else if ((host = nick.find('@')) != Anope::string::npos)
|
||||
@@ -59,28 +56,26 @@ void add_ignore(const Anope::string &nick, time_t delta)
|
||||
else
|
||||
mask = nick + "!*@*";
|
||||
/* Check if we already got an identical entry. */
|
||||
for (ign = ignore; ign; ign = ign->next)
|
||||
if (mask.equals_ci(ign->mask))
|
||||
std::list<IgnoreData *>::iterator ign = ignore.begin(), ign_end = ignore.end();
|
||||
for (; ign != ign_end; ++ign)
|
||||
if (mask.equals_ci((*ign)->mask))
|
||||
break;
|
||||
time_t now = time(NULL);
|
||||
/* Found one.. */
|
||||
if (ign)
|
||||
if (ign != ign_end)
|
||||
{
|
||||
if (!delta)
|
||||
ign->time = 0;
|
||||
else if (ign->time < now + delta)
|
||||
ign->time = now + delta;
|
||||
(*ign)->time = 0;
|
||||
else if ((*ign)->time < now + delta)
|
||||
(*ign)->time = now + delta;
|
||||
}
|
||||
/* Create new entry.. */
|
||||
else
|
||||
{
|
||||
ign = new IgnoreData;
|
||||
ign->mask = mask;
|
||||
ign->time = !delta ? 0 : now + delta;
|
||||
ign->prev = NULL;
|
||||
ign->next = ignore;
|
||||
if (ignore)
|
||||
ignore->prev = ign;
|
||||
ignore = ign;
|
||||
IgnoreData *newign = new IgnoreData();
|
||||
newign->mask = mask;
|
||||
newign->time = delta ? now + delta : 0;
|
||||
ignore.push_front(newign);
|
||||
Alog(LOG_DEBUG) << "Added new ignore entry for " << mask;
|
||||
}
|
||||
}
|
||||
@@ -96,30 +91,27 @@ void add_ignore(const Anope::string &nick, time_t delta)
|
||||
*/
|
||||
IgnoreData *get_ignore(const Anope::string &nick)
|
||||
{
|
||||
IgnoreData *ign;
|
||||
Anope::string tmp;
|
||||
size_t user, host;
|
||||
time_t now;
|
||||
User *u;
|
||||
if (nick.empty())
|
||||
return NULL;
|
||||
/* User has disabled the IGNORE system */
|
||||
if (!allow_ignore)
|
||||
return NULL;
|
||||
now = time(NULL);
|
||||
u = finduser(nick);
|
||||
User *u = finduser(nick);
|
||||
std::list<IgnoreData *>::iterator ign = ignore.begin(), ign_end = ignore.end();
|
||||
/* If we find a real user, match his mask against the ignorelist. */
|
||||
if (u)
|
||||
{
|
||||
/* Opers are not ignored, even if a matching entry may be present. */
|
||||
if (is_oper(u))
|
||||
return NULL;
|
||||
for (ign = ignore; ign; ign = ign->next)
|
||||
if (match_usermask(ign->mask, u))
|
||||
for (; ign != ign_end; ++ign)
|
||||
if (match_usermask((*ign)->mask, u))
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
Anope::string tmp;
|
||||
size_t user, host;
|
||||
/* We didn't get a user.. generate a valid mask. */
|
||||
if ((host = nick.find('@')) != Anope::string::npos)
|
||||
{
|
||||
@@ -137,26 +129,22 @@ IgnoreData *get_ignore(const Anope::string &nick)
|
||||
/* We only got a nick.. */
|
||||
else
|
||||
tmp = nick + "!*@*";
|
||||
for (ign = ignore; ign; ign = ign->next)
|
||||
if (Anope::Match(tmp, ign->mask))
|
||||
for (; ign != ign_end; ++ign)
|
||||
if (Anope::Match(tmp, (*ign)->mask))
|
||||
break;
|
||||
}
|
||||
time_t now = time(NULL);
|
||||
/* Check whether the entry has timed out */
|
||||
if (ign && ign->time != 0 && ign->time <= now)
|
||||
if (ign != ign_end && (*ign)->time && (*ign)->time <= now)
|
||||
{
|
||||
Alog(LOG_DEBUG) << "Expiring ignore entry " << ign->mask;
|
||||
if (ign->prev)
|
||||
ign->prev->next = ign->next;
|
||||
else if (ignore == ign)
|
||||
ignore = ign->next;
|
||||
if (ign->next)
|
||||
ign->next->prev = ign->prev;
|
||||
delete ign;
|
||||
ign = NULL;
|
||||
Alog(LOG_DEBUG) << "Expiring ignore entry " << (*ign)->mask;
|
||||
delete *ign;
|
||||
ignore.erase(ign);
|
||||
ign = ign_end = ignore.end();
|
||||
}
|
||||
if (ign && debug)
|
||||
Alog(LOG_DEBUG) << "Found ignore entry (" << ign->mask << ") for " << nick;
|
||||
return ign;
|
||||
if (ign != ign_end && debug)
|
||||
Alog(LOG_DEBUG) << "Found ignore entry (" << (*ign)->mask << ") for " << nick;
|
||||
return ign == ign_end ? NULL : *ign;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
@@ -168,14 +156,13 @@ IgnoreData *get_ignore(const Anope::string &nick)
|
||||
*/
|
||||
int delete_ignore(const Anope::string &nick)
|
||||
{
|
||||
IgnoreData *ign;
|
||||
Anope::string tmp;
|
||||
size_t user, host;
|
||||
User *u;
|
||||
if (nick.empty())
|
||||
return 0;
|
||||
/* If it s an existing user, we ignore the hostmask. */
|
||||
if ((u = finduser(nick)))
|
||||
Anope::string tmp;
|
||||
size_t user, host;
|
||||
User *u = finduser(nick);
|
||||
if (u)
|
||||
tmp = "*!*@" + u->host;
|
||||
/* Determine whether we get a nick or a mask. */
|
||||
else if ((host = nick.find('@')) != Anope::string::npos)
|
||||
@@ -195,22 +182,17 @@ int delete_ignore(const Anope::string &nick)
|
||||
/* We only got a nick.. */
|
||||
else
|
||||
tmp = nick + "!*@*";
|
||||
for (ign = ignore; ign; ign = ign->next)
|
||||
if (tmp.equals_ci(ign->mask))
|
||||
std::list<IgnoreData *>::iterator ign = ignore.begin(), ign_end = ignore.end();
|
||||
for (; ign != ign_end; ++ign)
|
||||
if (tmp.equals_ci((*ign)->mask))
|
||||
break;
|
||||
/* No matching ignore found. */
|
||||
if (!ign)
|
||||
if (ign == ign_end)
|
||||
return 0;
|
||||
Alog(LOG_DEBUG) << "Deleting ignore entry " << ign->mask;
|
||||
Alog(LOG_DEBUG) << "Deleting ignore entry " << (*ign)->mask;
|
||||
/* Delete the entry and all references to it. */
|
||||
if (ign->prev)
|
||||
ign->prev->next = ign->next;
|
||||
else if (ignore == ign)
|
||||
ignore = ign->next;
|
||||
if (ign->next)
|
||||
ign->next->prev = ign->prev;
|
||||
delete ign;
|
||||
ign = NULL;
|
||||
delete *ign;
|
||||
ignore.erase(ign);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -222,19 +204,16 @@ int delete_ignore(const Anope::string &nick)
|
||||
*/
|
||||
int clear_ignores()
|
||||
{
|
||||
IgnoreData *ign, *next;
|
||||
int i = 0;
|
||||
if (!ignore)
|
||||
if (ignore.empty())
|
||||
return 0;
|
||||
for (ign = ignore; ign; ign = next)
|
||||
for (std::list<IgnoreData *>::iterator ign = ignore.begin(), ign_end = ignore.end(); ign != ign_end; ++ign)
|
||||
{
|
||||
next = ign->next;
|
||||
Alog(LOG_DEBUG) << "Deleting ignore entry " << ign->mask;
|
||||
delete ign;
|
||||
++i;
|
||||
Alog(LOG_DEBUG) << "Deleting ignore entry " << (*ign)->mask;
|
||||
delete *ign;
|
||||
}
|
||||
ignore = NULL;
|
||||
return i;
|
||||
int deleted = ignore.size();
|
||||
ignore.clear();
|
||||
return deleted;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
Reference in New Issue
Block a user