X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_svshold.cpp;h=e74f3324ba936ff324326d4f94b86fbd273e5df8;hb=de4e4860091fe5a9a530acdb25f9a17e22323acf;hp=bd80bb048b72b924229ada9bfa1f43cb0bd17227;hpb=4ab1c43c1eee708fc50a4808f714a731891b75e8;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_svshold.cpp b/src/modules/m_svshold.cpp index bd80bb048..e74f3324b 100644 --- a/src/modules/m_svshold.cpp +++ b/src/modules/m_svshold.cpp @@ -22,39 +22,50 @@ #include "inspircd.h" #include "xline.h" +#include "modules/stats.h" -/* $ModDesc: Implements SVSHOLD. Like Q:Lines, but can only be added/removed by Services. */ +namespace +{ + bool silent; +} /** Holds a SVSHold item */ class SVSHold : public XLine { public: - irc::string nickname; + std::string nickname; - SVSHold(time_t s_time, long d, std::string src, std::string re, std::string nick) + SVSHold(time_t s_time, long d, const std::string& src, const std::string& re, const std::string& nick) : XLine(s_time, d, src, re, "SVSHOLD") { - this->nickname = nick.c_str(); + this->nickname = nick; } - bool Matches(User *u) + bool Matches(User* u) CXX11_OVERRIDE { if (u->nick == nickname) return true; return false; } - bool Matches(const std::string &s) + bool Matches(const std::string& s) CXX11_OVERRIDE { - if (nickname == s) - return true; - return false; + return InspIRCd::Match(s, nickname); + } + + void DisplayExpiry() CXX11_OVERRIDE + { + if (!silent) + { + ServerInstance->SNO->WriteToSnoMask('x', "Removing expired SVSHOLD %s (set by %s %ld seconds ago)", + nickname.c_str(), source.c_str(), (long)(ServerInstance->Time() - set_time)); + } } - const char* Displayable() + const std::string& Displayable() CXX11_OVERRIDE { - return nickname.c_str(); + return nickname; } }; @@ -67,12 +78,12 @@ class SVSHoldFactory : public XLineFactory /** Generate a shun */ - XLine* Generate(time_t set_time, long duration, std::string source, std::string reason, std::string xline_specific_mask) + XLine* Generate(time_t set_time, long duration, std::string source, std::string reason, std::string xline_specific_mask) CXX11_OVERRIDE { return new SVSHold(set_time, duration, source, reason, xline_specific_mask); } - bool AutoApplyToUserList(XLine *x) + bool AutoApplyToUserList(XLine* x) CXX11_OVERRIDE { return false; } @@ -86,15 +97,14 @@ class CommandSvshold : public Command CommandSvshold(Module* Creator) : Command(Creator, "SVSHOLD", 1) { flags_needed = 'o'; this->syntax = " [ :]"; - TRANSLATE4(TR_TEXT, TR_TEXT, TR_TEXT, TR_END); } - CmdResult Handle(const std::vector ¶meters, User *user) + CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE { /* syntax: svshold nickname time :reason goes here */ /* 'time' is a human-readable timestring, like 2d3h2s. */ - if (!ServerInstance->ULine(user->server)) + if (!user->server->IsULine()) { /* don't allow SVSHOLD from non-ulined clients */ return CMD_FAILURE; @@ -104,7 +114,8 @@ class CommandSvshold : public Command { if (ServerInstance->XLines->DelLine(parameters[0].c_str(), "SVSHOLD", user)) { - ServerInstance->SNO->WriteToSnoMask('x',"%s removed SVSHOLD on %s",user->nick.c_str(),parameters[0].c_str()); + if (!silent) + ServerInstance->SNO->WriteToSnoMask('x',"%s removed SVSHOLD on %s",user->nick.c_str(),parameters[0].c_str()); } else { @@ -121,6 +132,9 @@ class CommandSvshold : public Command if (ServerInstance->XLines->AddLine(r, user)) { + if (silent) + return CMD_SUCCESS; + if (!duration) { ServerInstance->SNO->WriteGlobalSno('x', "%s added permanent SVSHOLD for %s: %s", user->nick.c_str(), parameters[0].c_str(), parameters[2].c_str()); @@ -128,7 +142,7 @@ class CommandSvshold : public Command else { time_t c_requires_crap = duration + ServerInstance->Time(); - std::string timestr = ServerInstance->TimeString(c_requires_crap); + std::string timestr = InspIRCd::TimeString(c_requires_crap); ServerInstance->SNO->WriteGlobalSno('x', "%s added timed SVSHOLD for %s, expires on %s: %s", user->nick.c_str(), parameters[0].c_str(), timestr.c_str(), parameters[2].c_str()); } } @@ -142,47 +156,52 @@ class CommandSvshold : public Command return CMD_SUCCESS; } - RouteDescriptor GetRouting(User* user, const std::vector& parameters) + RouteDescriptor GetRouting(User* user, const Params& parameters) CXX11_OVERRIDE { return ROUTE_BROADCAST; } }; -class ModuleSVSHold : public Module +class ModuleSVSHold : public Module, public Stats::EventListener { CommandSvshold cmd; SVSHoldFactory s; public: - ModuleSVSHold() : cmd(this) + ModuleSVSHold() + : Stats::EventListener(this) + , cmd(this) { } void init() CXX11_OVERRIDE { ServerInstance->XLines->RegisterFactory(&s); - ServerInstance->Modules->AddService(cmd); - Implementation eventlist[] = { I_OnUserPreNick, I_OnStats }; - ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation)); } - ModResult OnStats(char symbol, User* user, string_list &out) CXX11_OVERRIDE + void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE + { + ConfigTag* tag = ServerInstance->Config->ConfValue("svshold"); + silent = tag->getBool("silent", true); + } + + ModResult OnStats(Stats::Context& stats) CXX11_OVERRIDE { - if(symbol != 'S') + if (stats.GetSymbol() != 'S') return MOD_RES_PASSTHRU; - ServerInstance->XLines->InvokeStats("SVSHOLD", 210, user, out); + ServerInstance->XLines->InvokeStats("SVSHOLD", 210, stats); return MOD_RES_DENY; } - ModResult OnUserPreNick(User *user, const std::string &newnick) CXX11_OVERRIDE + ModResult OnUserPreNick(LocalUser* user, const std::string& newnick) CXX11_OVERRIDE { XLine *rl = ServerInstance->XLines->MatchesLine("SVSHOLD", newnick); if (rl) { - user->WriteServ( "432 %s %s :Services reserved nickname: %s", user->nick.c_str(), newnick.c_str(), rl->reason.c_str()); + user->WriteNumeric(ERR_ERRONEUSNICKNAME, newnick, InspIRCd::Format("Services reserved nickname: %s", rl->reason.c_str())); return MOD_RES_DENY; }