diff options
-rw-r--r-- | include/modules.h | 4 | ||||
-rw-r--r-- | modules/commands/cs_xop.cpp | 2 | ||||
-rw-r--r-- | modules/commands/ns_suspend.cpp | 88 | ||||
-rw-r--r-- | modules/pseudoclients/nickserv.cpp | 13 |
4 files changed, 89 insertions, 18 deletions
diff --git a/include/modules.h b/include/modules.h index 99ddc8259..2be3d5534 100644 --- a/include/modules.h +++ b/include/modules.h @@ -490,9 +490,9 @@ class CoreExport Module : public Extensible /** Called before a nick expires * @param na The nick - * @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to halt the command and not process it + * @param expire Set to true to allow the nick to expire */ - virtual EventReturn OnPreNickExpire(NickAlias *na) { return EVENT_CONTINUE; } + virtual void OnPreNickExpire(NickAlias *na, bool &expire) { } /** Called when a nick drops * @param na The nick diff --git a/modules/commands/cs_xop.cpp b/modules/commands/cs_xop.cpp index e132f19f5..d23b24b81 100644 --- a/modules/commands/cs_xop.cpp +++ b/modules/commands/cs_xop.cpp @@ -399,7 +399,7 @@ class XOPBase : public Command Log(override ? LOG_OVERRIDE : LOG_COMMAND, u, this, ci) << "ADD " << mask; FOREACH_MOD(I_OnAccessAdd, OnAccessAdd(ci, u, acc)); - source.Reply(("\002%s\002 added to %s %s list."), acc->mask.c_str(), ci->name.c_str(), source.command.c_str()); + source.Reply(_("\002%s\002 added to %s %s list."), acc->mask.c_str(), ci->name.c_str(), source.command.c_str()); } void DoDel(CommandSource &source, ChannelInfo *ci, const std::vector<Anope::string> ¶ms, XOPType level) diff --git a/modules/commands/ns_suspend.cpp b/modules/commands/ns_suspend.cpp index c4934788a..b2cd5b18c 100644 --- a/modules/commands/ns_suspend.cpp +++ b/modules/commands/ns_suspend.cpp @@ -13,13 +13,43 @@ #include "module.h" +struct NickSuspend : ExtensibleItem, Serializable<NickSuspend> +{ + Anope::string nick; + time_t when; + + serialized_data serialize() + { + serialized_data sd; + + sd["nick"] << this->nick; + sd["when"] << this->when; + + return sd; + } + + static void unserialize(serialized_data &sd) + { + NickAlias *na = findnick(sd["nick"].astr()); + if (na == NULL) + return; + + NickSuspend *ns = new NickSuspend(); + + sd["nick"] >> ns->nick; + sd["when"] >> ns->when; + + na->Extend("ns_suspend_expire", ns); + } +}; + class CommandNSSuspend : public Command { public: - CommandNSSuspend(Module *creator) : Command(creator, "nickserv/suspend", 2, 2) + CommandNSSuspend(Module *creator) : Command(creator, "nickserv/suspend", 2, 3) { this->SetDesc(_("Suspend a given nick")); - this->SetSyntax(_("\037nickname\037 \037reason\037")); + this->SetSyntax(_("\037nickname\037 [+\037expiry\037] \037reason\037")); } void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) @@ -27,7 +57,9 @@ class CommandNSSuspend : public Command User *u = source.u; const Anope::string &nick = params[0]; - const Anope::string &reason = params[1]; + Anope::string expiry = params[1]; + Anope::string reason = params.size() > 2 ? params[2] : ""; + time_t expiry_secs = Config->NSSuspendExpire; if (readonly) { @@ -35,6 +67,14 @@ class CommandNSSuspend : public Command return; } + if (expiry[0] != '+') + { + reason = expiry + " " + reason; + reason.trim(); + } + else + expiry_secs = dotime(expiry); + NickAlias *na = findnick(nick); if (!na) { @@ -71,7 +111,16 @@ class CommandNSSuspend : public Command } } - Log(LOG_ADMIN, u, this) << "for " << nick << " (" << (!reason.empty() ? reason : "No reason") << ")"; + if (expiry_secs > 0) + { + NickSuspend *ns = new NickSuspend(); + ns->nick = na->nick; + ns->when = Anope::CurTime + expiry_secs; + + na->Extend("ns_suspend_expire", ns); + } + + Log(LOG_ADMIN, u, this) << "for " << nick << " (" << (!reason.empty() ? reason : "No reason") << "), expires in " << (expiry_secs ? do_strftime(Anope::CurTime + expiry_secs) : "never"); source.Reply(_("Nick %s is now suspended."), nick.c_str()); FOREACH_MOD(I_OnNickSuspended, OnNickSuspend(na)); @@ -84,7 +133,9 @@ class CommandNSSuspend : public Command this->SendSyntax(source); source.Reply(" "); source.Reply(_("Suspends a registered nickname, which prevents from being used\n" - "while keeping all the data for that nick.")); + "while keeping all the data for that nick. If an expiry is given\n" + "the nick will be unsuspended after that period of time, else the\n" + "default expiry from the configuration is used.")); return true; } }; @@ -152,6 +203,33 @@ class NSSuspend : public Module { this->SetAuthor("Anope"); + Implementation i[] = { I_OnPreNickExpire }; + ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation)); + + Serializable<NickSuspend>::Alloc.Register("NickSuspend"); + } + + ~NSSuspend() + { + for (nickalias_map::const_iterator it = NickAliasList.begin(), it_end = NickAliasList.end(); it != it_end; ++it) + it->second->Shrink("ns_suspend_expire"); + } + + void OnPreNickExpire(NickAlias *na, bool &expire) + { + if (!na->nc->HasFlag(NI_SUSPENDED)) + return; + + expire = false; + + NickSuspend *ns = na->GetExt<NickSuspend *>("ns_suspend_expire"); + if (ns != NULL && ns->when < Anope::CurTime) + { + na->last_seen = Anope::CurTime; + na->nc->UnsetFlag(NI_SUSPENDED); + + Log(LOG_NORMAL, "expire", findbot(Config->NickServ)) << "Expiring suspend for " << na->nick; + } } }; diff --git a/modules/pseudoclients/nickserv.cpp b/modules/pseudoclients/nickserv.cpp index 4e6678250..595236bfa 100644 --- a/modules/pseudoclients/nickserv.cpp +++ b/modules/pseudoclients/nickserv.cpp @@ -105,22 +105,15 @@ class ExpireCallback : public CallBack if (na->nc->HasFlag(NI_UNCONFIRMED)) if (Config->NSUnconfirmedExpire && Anope::CurTime - na->time_registered >= Config->NSUnconfirmedExpire) expire = true; - if (na->nc->HasFlag(NI_SUSPENDED)) - { - if (Config->NSSuspendExpire && Anope::CurTime - na->last_seen >= Config->NSSuspendExpire) - expire = true; - } - else if (Config->NSExpire && Anope::CurTime - na->last_seen >= Config->NSExpire) + if (Config->NSExpire && Anope::CurTime - na->last_seen >= Config->NSExpire) expire = true; if (na->HasFlag(NS_NO_EXPIRE)) expire = false; + + FOREACH_MOD(I_OnPreNickExpire, OnPreNickExpire(na, expire)); if (expire) { - EventReturn MOD_RESULT; - FOREACH_RESULT(I_OnPreNickExpire, OnPreNickExpire(na)); - if (MOD_RESULT == EVENT_STOP) - continue; Anope::string extra; if (na->nc->HasFlag(NI_SUSPENDED)) extra = "suspended "; |