X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_silence.cpp;h=f809d7d5762e0ed545b989f4b668e61d20df9e75;hb=9422f4157ccff0482cd70105ada3bd9325455eaa;hp=dea78c5268f74d4eb6c4e988ef985301786aee1d;hpb=5d407fb44c759524881712a80febb86b4506ddbf;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_silence.cpp b/src/modules/m_silence.cpp index dea78c526..f809d7d57 100644 --- a/src/modules/m_silence.cpp +++ b/src/modules/m_silence.cpp @@ -2,155 +2,160 @@ * | Inspire Internet Relay Chat Daemon | * +------------------------------------+ * - * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev. - * E-mail: - * - * - * - * Written by Craig Edwards, Craig McLure, and others. + * InspIRCd: (C) 2002-2007 InspIRCd Development Team + * See: http://www.inspircd.org/wiki/index.php/Credits + * * This program is free but copyrighted software; see * the file COPYING for details. * * --------------------------------------------------- */ -using namespace std; - -#include -#include -#include -#include "users.h" -#include "channels.h" -#include "modules.h" -#include "helperfuncs.h" -#include "hashcomp.h" +#include "inspircd.h" +#include "wildcard.h" /* $ModDesc: Provides support for the /SILENCE command */ - // This typedef holds a silence list. Each user may or may not have a // silencelist, if a silence list is empty for a user, he/she does not // have one of these structures associated with their user record. -typedef std::vector silencelist; +typedef std::map silencelist; class cmd_silence : public command_t { + unsigned int& maxsilence; public: - cmd_silence() : command_t("SILENCE", 0, 1) + cmd_silence (InspIRCd* Instance, unsigned int &max) : command_t(Instance,"SILENCE", 0, 0), maxsilence(max) { this->source = "m_silence.so"; + syntax = "{[+|-]}"; + TRANSLATE2(TR_TEXT, TR_END); } - void Handle (char **parameters, int pcnt, userrec *user) + CmdResult Handle (const char** parameters, int pcnt, userrec *user) { if (!pcnt) { // no parameters, show the current silence list. // Use Extensible::GetExt to fetch the silence list - silencelist* sl = (silencelist*)user->GetExt("silence_list"); + silencelist* sl; + user->GetExt("silence_list", sl); // if the user has a silence list associated with their user record, show it if (sl) { - for (silencelist::const_iterator c = sl->begin(); c < sl->end(); c++) + for (silencelist::const_iterator c = sl->begin(); c != sl->end(); c++) { - WriteServ(user->fd,"271 %s %s %s!*@*",user->nick, user->nick,c->c_str()); + user->WriteServ("271 %s %s %s :%lu",user->nick, user->nick, c->first.c_str(), (unsigned long)c->second); } } - WriteServ(user->fd,"272 %s :End of Silence List",user->nick); + user->WriteServ("272 %s :End of Silence List",user->nick); + + return CMD_SUCCESS; } else if (pcnt > 0) { // one or more parameters, add or delete entry from the list (only the first parameter is used) - char *nick = parameters[0]; - if (nick[0] == '-') + std::string mask = parameters[0] + 1; + char action = *parameters[0]; + + if (!mask.length()) + { + // 'SILENCE +' or 'SILENCE -', assume *!*@* + mask = "*!*@*"; + } + + ModeParser::CleanMask(mask); + + if (action == '-') { - // removing an item from the list - nick++; // fetch their silence list - silencelist* sl = (silencelist*)user->GetExt("silence_list"); + silencelist* sl; + user->GetExt("silence_list", sl); // does it contain any entries and does it exist? if (sl) { - if (sl->size()) - { - for (silencelist::iterator i = sl->begin(); i != sl->end(); i++) - { - // search through for the item - irc::string listitem = i->c_str(); - irc::string target = nick; - if (listitem == target) - { - sl->erase(i); - WriteServ(user->fd,"950 %s %s :Removed %s!*@* from silence list",user->nick, user->nick,nick); - // we have modified the vector from within a loop, we must now bail out - return; - } - } - } - if (!sl->size()) + silencelist::iterator i = sl->find(mask.c_str()); + if (i != sl->end()) { - // tidy up -- if a user's list is empty, theres no use having it - // hanging around in the user record. - DELETE(sl); - user->Shrink("silence_list"); + sl->erase(i); + user->WriteServ("950 %s %s :Removed %s from silence list",user->nick, user->nick, mask.c_str()); + if (!sl->size()) + { + // tidy up -- if a user's list is empty, theres no use having it + // hanging around in the user record. + DELETE(sl); + user->Shrink("silence_list"); + } } + else + user->WriteServ("952 %s %s :%s does not exist on your silence list",user->nick, user->nick, mask.c_str()); } } - else if (nick[0] == '+') + else if (action == '+') { - nick++; // fetch the user's current silence list - silencelist* sl = (silencelist*)user->GetExt("silence_list"); + silencelist* sl; + user->GetExt("silence_list", sl); // what, they dont have one??? WE'RE ALL GONNA DIE! ...no, we just create an empty one. if (!sl) { sl = new silencelist; - user->Extend(std::string("silence_list"),(char*)sl); + user->Extend("silence_list", sl); } - // add the nick to it -- silence only takes nicks for some reason even though its list shows masks - for (silencelist::iterator n = sl->begin(); n != sl->end(); n++) + silencelist::iterator n = sl->find(mask.c_str()); + if (n != sl->end()) { - irc::string listitem = n->c_str(); - irc::string target = nick; - if (listitem == target) - { - WriteServ(user->fd,"952 %s %s :%s is already on your silence list",user->nick, user->nick,nick); - return; - } + user->WriteServ("952 %s %s :%s is already on your silence list",user->nick, user->nick, mask.c_str()); + return CMD_FAILURE; + } + if (sl->size() >= maxsilence) + { + user->WriteServ("952 %s %s :Your silence list is full",user->nick, user->nick, mask.c_str()); + return CMD_FAILURE; } - sl->push_back(std::string(nick)); - WriteServ(user->fd,"951 %s %s :Added %s!*@* to silence list",user->nick, user->nick,nick); - return; + sl->insert(std::make_pair(mask.c_str(), ServerInstance->Time())); + user->WriteServ("951 %s %s :Added %s to silence list",user->nick, user->nick, mask.c_str()); + return CMD_SUCCESS; } } - return; + return CMD_SUCCESS; } }; class ModuleSilence : public Module { - Server *Srv; + cmd_silence* mycommand; + unsigned int maxsilence; public: - ModuleSilence(Server* Me) - : Module::Module(Me) + ModuleSilence(InspIRCd* Me) + : Module(Me), maxsilence(32) { - Srv = Me; - mycommand = new cmd_silence(); - Srv->AddCommand(mycommand); + OnRehash(NULL, ""); + mycommand = new cmd_silence(ServerInstance, maxsilence); + ServerInstance->AddCommand(mycommand); } void Implements(char* List) { - List[I_OnUserQuit] = List[I_On005Numeric] = List[I_OnUserPreNotice] = List[I_OnUserPreMessage] = 1; + List[I_OnRehash] = List[I_OnUserQuit] = List[I_On005Numeric] = List[I_OnUserPreNotice] = List[I_OnUserPreMessage] = 1; + } + + virtual void OnRehash(userrec* user, const std::string ¶meter) + { + ConfigReader Conf(ServerInstance); + maxsilence = Conf.ReadInteger("silence", "maxentries", 0, true); + if (!maxsilence) + maxsilence = 32; } - virtual void OnUserQuit(userrec* user, const std::string &reason) + virtual void OnUserQuit(userrec* user, const std::string &reason, const std::string &oper_message) { // when the user quits tidy up any silence list they might have just to keep things tidy // and to prevent a HONKING BIG MEMORY LEAK! - silencelist* sl = (silencelist*)user->GetExt("silence_list"); + silencelist* sl; + user->GetExt("silence_list", sl); if (sl) { DELETE(sl); @@ -161,26 +166,25 @@ class ModuleSilence : public Module virtual void On005Numeric(std::string &output) { // we don't really have a limit... - output = output + " SILENCE=999"; + output = output + " SILENCE=" + ConvToStr(maxsilence); } - virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status) + virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list) { // im not sure how unreal's silence operates but ours is sensible. It blocks notices and // privmsgs from people on the silence list, directed privately at the user. // channel messages are unaffected (ever tried to follow the flow of conversation in // a channel when you've set an ignore on the two most talkative people?) - if (target_type == TYPE_USER) + if ((target_type == TYPE_USER) && (IS_LOCAL(user))) { userrec* u = (userrec*)dest; - silencelist* sl = (silencelist*)u->GetExt("silence_list"); + silencelist* sl; + u->GetExt("silence_list", sl); if (sl) { for (silencelist::const_iterator c = sl->begin(); c != sl->end(); c++) { - irc::string listitem = c->c_str(); - irc::string target = user->nick; - if (listitem == target) + if (match(user->GetFullHost(), c->first.c_str())) { return 1; } @@ -190,9 +194,9 @@ class ModuleSilence : public Module return 0; } - virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status) + virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list) { - return OnUserPreNotice(user,dest,target_type,text,status); + return OnUserPreNotice(user,dest,target_type,text,status,exempt_list); } virtual ~ModuleSilence() @@ -201,32 +205,8 @@ class ModuleSilence : public Module virtual Version GetVersion() { - return Version(1,0,0,1,VF_VENDOR); + return Version(1, 1, 0, 0, VF_COMMON | VF_VENDOR, API_VERSION); } }; - -class ModuleSilenceFactory : public ModuleFactory -{ - public: - ModuleSilenceFactory() - { - } - - ~ModuleSilenceFactory() - { - } - - virtual Module * CreateModule(Server* Me) - { - return new ModuleSilence(Me); - } - -}; - - -extern "C" void * init_module( void ) -{ - return new ModuleSilenceFactory; -} - +MODULE_INIT(ModuleSilence)