X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_silence.cpp;h=7f8b49287dfcf33c249c088306a84d9ba6f25df9;hb=d54fd9b1e6b31f69332a9241b5f17330c0ad61e0;hp=e3cd36f76eda478c2a5a4614f3d11e52153f6219;hpb=dc8f5d02f77aeabefaefe88005b99c8b47030ab7;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_silence.cpp b/src/modules/m_silence.cpp index e3cd36f76..7f8b49287 100644 --- a/src/modules/m_silence.cpp +++ b/src/modules/m_silence.cpp @@ -22,8 +22,9 @@ using namespace std; #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 */ @@ -36,10 +37,10 @@ typedef std::vector silencelist; class cmd_silence : public command_t { public: - cmd_silence() : command_t("SILENCE", 0, 0) + cmd_silence (InspIRCd* Instance) : command_t(Instance,"SILENCE", 0, 0) { this->source = "m_silence.so"; - syntax = "{[+|-]}"; + syntax = "{[+|-]}"; } void Handle (const char** parameters, int pcnt, userrec *user) @@ -55,19 +56,27 @@ class cmd_silence : public command_t { 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",user->nick, user->nick,c->c_str()); } } - WriteServ(user->fd,"272 %s :End of Silence List",user->nick); + user->WriteServ("272 %s :End of Silence List",user->nick); } else if (pcnt > 0) { // one or more parameters, add or delete entry from the list (only the first parameter is used) - const 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; user->GetExt("silence_list", sl); @@ -77,20 +86,18 @@ class cmd_silence : public command_t 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 (listitem == mask) + { + sl->erase(i); + user->WriteServ("950 %s %s :Removed %s from silence list",user->nick, user->nick, mask.c_str()); + break; + } + } } - if (!sl->size()) + else { // tidy up -- if a user's list is empty, theres no use having it // hanging around in the user record. @@ -99,9 +106,8 @@ class cmd_silence : public command_t } } } - else if (nick[0] == '+') + else if (action == '+') { - nick++; // fetch the user's current silence list silencelist* sl; user->GetExt("silence_list", sl); @@ -111,19 +117,17 @@ class cmd_silence : public command_t sl = new silencelist; user->Extend(std::string("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++) { irc::string listitem = n->c_str(); - irc::string target = nick; - if (listitem == target) + if (listitem == mask) { - WriteServ(user->fd,"952 %s %s :%s is already on your silence list",user->nick, user->nick,nick); + user->WriteServ("952 %s %s :%s is already on your silence list",user->nick, user->nick, mask.c_str()); return; } } - sl->push_back(std::string(nick)); - WriteServ(user->fd,"951 %s %s :Added %s!*@* to silence list",user->nick, user->nick,nick); + sl->push_back(mask); + user->WriteServ("951 %s %s :Added %s to silence list",user->nick, user->nick, mask.c_str()); return; } } @@ -133,16 +137,16 @@ class cmd_silence : public command_t class ModuleSilence : public Module { - Server *Srv; + cmd_silence* mycommand; public: - ModuleSilence(Server* Me) + ModuleSilence(InspIRCd* Me) : Module::Module(Me) { - Srv = Me; - mycommand = new cmd_silence(); - Srv->AddCommand(mycommand); + + mycommand = new cmd_silence(ServerInstance); + ServerInstance->AddCommand(mycommand); } void Implements(char* List) @@ -184,9 +188,7 @@ class ModuleSilence : public Module { 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->c_str())) { return 1; } @@ -223,7 +225,7 @@ class ModuleSilenceFactory : public ModuleFactory { } - virtual Module * CreateModule(Server* Me) + virtual Module * CreateModule(InspIRCd* Me) { return new ModuleSilence(Me); }