summaryrefslogtreecommitdiff
path: root/modules/pseudoclients/nickserv.cpp
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2013-05-05 01:55:04 -0400
committerAdam <Adam@anope.org>2013-05-05 01:55:04 -0400
commit1d0bb9b26b7ad58ab0bf979ac046f4511b3bf12b (patch)
tree4486f0784bdf050fd7eb225c0cb9df352ce1f45a /modules/pseudoclients/nickserv.cpp
parent781defb7076ddfddf723ca08cd0a518b6657b64f (diff)
Rework the config file reader to be much more flexible and move many configuration directives to the actual modules they are used in.
Diffstat (limited to 'modules/pseudoclients/nickserv.cpp')
-rw-r--r--modules/pseudoclients/nickserv.cpp136
1 files changed, 94 insertions, 42 deletions
diff --git a/modules/pseudoclients/nickserv.cpp b/modules/pseudoclients/nickserv.cpp
index cde1fbbf7..3f4250fb6 100644
--- a/modules/pseudoclients/nickserv.cpp
+++ b/modules/pseudoclients/nickserv.cpp
@@ -18,6 +18,7 @@ class NickServCollide;
typedef std::map<Anope::string, NickServCollide *> nickservcollides_map;
+static ServiceReference<NickServService> nickserv("NickServService", "NickServ");
static nickservcollides_map NickServCollides;
/** Timer for colliding nicks to force people off of nicknames
@@ -98,15 +99,15 @@ class MyNickServService : public NickServService
return;
}
- if (Config->NoNicknameOwnership)
+ if (Config->GetBlock("options")->Get<bool>("nonicknameownership"))
return;
if (u->IsRecognized(false) || !na->nc->HasExt("KILL_IMMED"))
{
if (na->nc->HasExt("SECURE"))
- u->SendMessage(NickServ, NICK_IS_SECURE, Config->UseStrictPrivMsgString.c_str(), Config->NickServ.c_str());
+ u->SendMessage(NickServ, NICK_IS_SECURE, Config->StrictPrivmsg.c_str(), NickServ->nick.c_str());
else
- u->SendMessage(NickServ, NICK_IS_REGISTERED, Config->UseStrictPrivMsgString.c_str(), Config->NickServ.c_str());
+ u->SendMessage(NickServ, NICK_IS_REGISTERED, Config->StrictPrivmsg.c_str(), NickServ->nick.c_str());
}
if (na->nc->HasExt("KILLPROTECT") && !u->IsRecognized(false))
@@ -118,13 +119,15 @@ class MyNickServService : public NickServService
}
else if (na->nc->HasExt("KILL_QUICK"))
{
- u->SendMessage(NickServ, _("If you do not change within %s, I will change your nick."), Anope::Duration(Config->NSKillQuick, u->Account()).c_str());
- new NickServCollide(u, Config->NSKillQuick);
+ time_t killquick = Config->GetModule("nickserv")->Get<time_t>("killquick", "60s");
+ u->SendMessage(NickServ, _("If you do not change within %s, I will change your nick."), Anope::Duration(killquick, u->Account()).c_str());
+ new NickServCollide(u, killquick);
}
else
{
- u->SendMessage(NickServ, _("If you do not change within %s, I will change your nick."), Anope::Duration(Config->NSKill, u->Account()).c_str());
- new NickServCollide(u, Config->NSKill);
+ time_t kill = Config->GetModule("nickserv")->Get<time_t>("kill", "20s");
+ u->SendMessage(NickServ, _("If you do not change within %s, I will change your nick."), Anope::Duration(kill, u->Account()).c_str());
+ new NickServCollide(u, kill);
}
}
@@ -134,7 +137,7 @@ class MyNickServService : public NickServService
{
const NickAlias *u_na = NickAlias::Find(user->nick);
user->Login(na->nc);
- if (u_na && *u_na->nc == *na->nc && !Config->NoNicknameOwnership && na->nc->HasExt("UNCONFIRMED") == false)
+ if (u_na && *u_na->nc == *na->nc && !Config->GetBlock("options")->Get<bool>("nonicknameownership") && na->nc->HasExt("UNCONFIRMED") == false)
user->SetMode(NickServ, "REGISTERED");
}
};
@@ -142,13 +145,16 @@ class MyNickServService : public NickServService
class ExpireCallback : public Timer
{
public:
- ExpireCallback(Module *o) : Timer(o, Config->ExpireTimeout, Anope::CurTime, true) { }
+ ExpireCallback(Module *o) : Timer(o, Config->GetBlock("options")->Get<time_t>("expiretimeout"), Anope::CurTime, true) { }
void Tick(time_t) anope_override
{
if (Anope::NoExpire || Anope::ReadOnly)
return;
+ time_t unconfirmed_expire = Config->GetModule(this->GetOwner())->Get<time_t>("unconfirmedexpire", "1d");
+ time_t nickserv_expire = Config->GetModule(this->GetOwner())->Get<time_t>("expire");
+
for (nickalias_map::const_iterator it = NickAliasList->begin(), it_end = NickAliasList->end(); it != it_end; )
{
NickAlias *na = it->second;
@@ -161,9 +167,9 @@ class ExpireCallback : public Timer
bool expire = false;
if (na->nc->HasExt("UNCONFIRMED"))
- if (Config->NSUnconfirmedExpire && Anope::CurTime - na->time_registered >= Config->NSUnconfirmedExpire)
+ if (unconfirmed_expire && Anope::CurTime - na->time_registered >= unconfirmed_expire)
expire = true;
- if (Config->NSExpire && Anope::CurTime - na->last_seen >= Config->NSExpire)
+ if (nickserv_expire && Anope::CurTime - na->last_seen >= nickserv_expire)
expire = true;
if (na->HasExt("NO_EXPIRE"))
expire = false;
@@ -185,19 +191,16 @@ class ExpireCallback : public Timer
class NickServCore : public Module
{
- MyNickServService mynickserv;
+ MyNickServService nickserv;
ExpireCallback expires;
+ std::vector<Anope::string> defaults;
public:
- NickServCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR), mynickserv(this), expires(this)
+ NickServCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR), nickserv(this), expires(this)
{
-
- NickServ = BotInfo::Find(Config->NickServ);
- if (!NickServ)
- throw ModuleException("No bot named " + Config->NickServ);
-
- Implementation i[] = { I_OnBotDelete, I_OnDelNick, I_OnDelCore, I_OnChangeCoreDisplay, I_OnNickIdentify, I_OnNickGroup,
- I_OnNickUpdate, I_OnUserConnect, I_OnPostUserLogoff, I_OnServerSync, I_OnUserNickChange, I_OnPreHelp, I_OnPostHelp };
+ Implementation i[] = { I_OnReload, I_OnBotDelete, I_OnDelNick, I_OnDelCore, I_OnChangeCoreDisplay, I_OnNickIdentify, I_OnNickGroup,
+ I_OnNickUpdate, I_OnUserConnect, I_OnPostUserLogoff, I_OnServerSync, I_OnUserNickChange, I_OnPreHelp, I_OnPostHelp,
+ I_OnNickCoreCreate, I_OnUserQuit };
ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation));
}
@@ -206,6 +209,28 @@ class NickServCore : public Module
NickServ = NULL;
}
+ void OnReload(Configuration::Conf *conf) anope_override
+ {
+ const Anope::string &nsnick = conf->GetModule(this)->Get<const Anope::string &>("client");
+
+ if (nsnick.empty())
+ throw ConfigException(this->name + ": <client> must be defined");
+
+ BotInfo *bi = BotInfo::Find(nsnick, true);
+ if (!bi)
+ throw ConfigException(this->name + ": no bot named " + nsnick);
+
+ NickServ = bi;
+
+ spacesepstream(conf->GetModule(this)->Get<const Anope::string &>("defaults", "secure memo_signon memo_receive")).GetTokens(defaults);
+ if (defaults.empty())
+ {
+ defaults.push_back("SECURE");
+ defaults.push_back("MEMO_SIGNON");
+ defaults.push_back("MEMO_RECEIVE");
+ }
+ }
+
void OnBotDelete(BotInfo *bi) anope_override
{
if (bi == NickServ)
@@ -246,14 +271,16 @@ class NickServCore : public Module
void OnNickIdentify(User *u) anope_override
{
- if (!Config->NoNicknameOwnership)
+ Configuration::Block *block = Config->GetModule(this);
+
+ if (!Config->GetBlock("options")->Get<bool>("nonicknameownership"))
{
const NickAlias *this_na = NickAlias::Find(u->nick);
if (this_na && this_na->nc == u->Account() && u->Account()->HasExt("UNCONFIRMED") == false)
u->SetMode(NickServ, "REGISTERED");
}
- if (Config->NSModeOnID)
+ if (block->Get<bool>("modeonid", "yes"))
for (User::ChanUserList::iterator it = u->chans.begin(), it_end = u->chans.end(); it != it_end; ++it)
{
ChanUserContainer *cc = it->second;
@@ -262,17 +289,18 @@ class NickServCore : public Module
c->SetCorrectModes(u, true, true);
}
- if (!Config->NSModesOnID.empty())
- u->SetModes(NickServ, "%s", Config->NSModesOnID.c_str());
+ const Anope::string &modesonid = block->Get<const Anope::string &>("modesonid");
+ if (!modesonid.empty())
+ u->SetModes(NickServ, "%s", modesonid.c_str());
- if (Config->NSForceEmail && u->Account()->email.empty())
+ if (block->Get<bool>("forceemail") && u->Account()->email.empty())
{
u->SendMessage(NickServ, _("You must now supply an e-mail for your nick.\n"
"This e-mail will allow you to retrieve your password in\n"
"case you forget it."));
u->SendMessage(NickServ, _("Type \002%s%s SET EMAIL \037e-mail\037\002 in order to set your e-mail.\n"
"Your privacy is respected; this e-mail won't be given to\n"
- "any third-party person."), Config->UseStrictPrivMsgString.c_str(), Config->NickServ.c_str());
+ "any third-party person."), Config->StrictPrivmsg.c_str(), NickServ->nick.c_str());
}
if (u->Account()->HasExt("UNCONFIRMED"))
@@ -280,8 +308,9 @@ class NickServCore : public Module
u->SendMessage(NickServ, _("Your email address is not confirmed. To confirm it, follow the instructions that were emailed to you when you registered."));
const NickAlias *this_na = NickAlias::Find(u->Account()->display);
time_t time_registered = Anope::CurTime - this_na->time_registered;
- if (Config->NSUnconfirmedExpire > time_registered)
- u->SendMessage(NickServ, _("Your account will expire, if not confirmed, in %s"), Anope::Duration(Config->NSUnconfirmedExpire - time_registered).c_str());
+ time_t unconfirmed_expire = Config->GetModule(this)->Get<time_t>("unconfirmedexpire", "1d");
+ if (unconfirmed_expire > time_registered)
+ u->SendMessage(NickServ, _("Your account will expire, if not confirmed, in %s"), Anope::Duration(unconfirmed_expire - time_registered).c_str());
}
}
@@ -308,10 +337,11 @@ class NickServCore : public Module
return;
const NickAlias *na = NickAlias::Find(u->nick);
- if (!Config->NoNicknameOwnership && !Config->NSUnregisteredNotice.empty() && !na)
- u->SendMessage(NickServ, Config->NSUnregisteredNotice);
+ const Anope::string &unregistered_notice = Config->GetModule(this)->Get<const Anope::string &>("unregistered_notice");
+ if (!Config->GetBlock("options")->Get<bool>("nonicknameownership") && !unregistered_notice.empty() && !na)
+ u->SendMessage(NickServ, unregistered_notice);
else if (na)
- this->mynickserv.Validate(u);
+ this->nickserv.Validate(u);
}
void OnPostUserLogoff(User *u) anope_override
@@ -327,7 +357,7 @@ class NickServCore : public Module
{
User *u = it->second;
if (u->server == s && !u->IsIdentified())
- this->mynickserv.Validate(u);
+ this->nickserv.Validate(u);
}
}
@@ -340,13 +370,13 @@ class NickServCore : public Module
/* Remove +r, but keep an account associated with the user */
u->RemoveMode(NickServ, "REGISTERED");
- this->mynickserv.Validate(u);
+ this->nickserv.Validate(u);
}
else
{
/* Reset +r and re-send account (even though it really should be set at this point) */
IRCD->SendLogin(u);
- if (!Config->NoNicknameOwnership && na->nc == u->Account() && na->nc->HasExt("UNCONFIRMED") == false)
+ if (!Config->GetBlock("options")->Get<bool>("nonicknameownership") && na->nc == u->Account() && na->nc->HasExt("UNCONFIRMED") == false)
u->SetMode(NickServ, "REGISTERED");
Log(NickServ) << u->GetMask() << " automatically identified for group " << u->Account()->display;
}
@@ -363,45 +393,67 @@ class NickServCore : public Module
EventReturn OnPreHelp(CommandSource &source, const std::vector<Anope::string> &params) anope_override
{
- if (!params.empty() || source.c || source.service->nick != Config->NickServ)
+ if (!params.empty() || source.c || source.service != NickServ)
return EVENT_CONTINUE;
- if (!Config->NoNicknameOwnership)
+ if (!Config->GetBlock("options")->Get<bool>("nonicknameownership"))
source.Reply(_("\002%s\002 allows you to register a nickname and\n"
"prevent others from using it. The following\n"
"commands allow for registration and maintenance of\n"
"nicknames; to use them, type \002%s%s \037command\037\002.\n"
"For more information on a specific command, type\n"
- "\002%s%s %s \037command\037\002.\n "), Config->NickServ.c_str(), Config->UseStrictPrivMsgString.c_str(), Config->NickServ.c_str(), Config->UseStrictPrivMsgString.c_str(), Config->NickServ.c_str(), source.command.c_str());
+ "\002%s%s %s \037command\037\002.\n "), NickServ->nick.c_str(), Config->StrictPrivmsg.c_str(), NickServ->nick.c_str(), Config->StrictPrivmsg.c_str(), NickServ->nick.c_str(), source.command.c_str());
else
source.Reply(_("\002%s\002 allows you to register an account.\n"
"The following commands allow for registration and maintenance of\n"
"accounts; to use them, type \002%s%s \037command\037\002.\n"
"For more information on a specific command, type\n"
- "\002%s%s %s \037command\037\002.\n "), Config->NickServ.c_str(), Config->UseStrictPrivMsgString.c_str(), Config->NickServ.c_str(), Config->UseStrictPrivMsgString.c_str(), Config->NickServ.c_str(), source.command.c_str());
+ "\002%s%s %s \037command\037\002.\n "), NickServ->nick.c_str(), Config->StrictPrivmsg.c_str(), NickServ->nick.c_str(), Config->StrictPrivmsg.c_str(), NickServ->nick.c_str(), source.command.c_str());
return EVENT_CONTINUE;
}
void OnPostHelp(CommandSource &source, const std::vector<Anope::string> &params) anope_override
{
- if (!params.empty() || source.c || source.service->nick != Config->NickServ)
+ if (!params.empty() || source.c || source.service != NickServ)
return;
if (source.IsServicesOper())
source.Reply(_(" \n"
"Services Operators can also drop any nickname without needing\n"
"to identify for the nick, and may view the access list for\n"
"any nickname."));
- if (Config->NSExpire >= 86400)
+ time_t nickserv_expire = Config->GetModule(this)->Get<time_t>("expire");
+ if (nickserv_expire >= 86400)
source.Reply(_(" \n"
"Accounts that are not used anymore are subject to \n"
"the automatic expiration, i.e. they will be deleted\n"
- "after %d days if not used."), Config->NSExpire / 86400);
+ "after %d days if not used."), nickserv_expire / 86400);
source.Reply(_(" \n"
"\002NOTICE:\002 This service is intended to provide a way for\n"
"IRC users to ensure their identity is not compromised.\n"
"It is \002NOT\002 intended to facilitate \"stealing\" of\n"
"nicknames or other malicious actions. Abuse of %s\n"
"will result in, at minimum, loss of the abused\n"
- "nickname(s)."), Config->NickServ.c_str());
+ "nickname(s)."), NickServ->nick.c_str());
+ }
+
+ void OnNickCoreCreate(NickCore *nc)
+ {
+ /* Set default flags */
+ for (unsigned i = 0; i < defaults.size(); ++i)
+ this->ExtendMetadata(defaults[i].upper());
+ }
+
+ void OnUserQuit(User *u, const Anope::string &msg)
+ {
+ if (u->server && !u->server->GetQuitReason().empty() && Config->GetModule(this)->Get<bool>("hidenetsplitquit"))
+ return;
+
+ /* Update last quit and last seen for the user */
+ NickAlias *na = NickAlias::Find(u->nick);
+ if (na && !na->nc->HasExt("SUSPENDED") && (u->IsRecognized() || u->IsIdentified(true)))
+ {
+ na->last_seen = Anope::CurTime;
+ na->last_quit = msg;
+ }
}
};