X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_silence.cpp;h=f809d7d5762e0ed545b989f4b668e61d20df9e75;hb=9422f4157ccff0482cd70105ada3bd9325455eaa;hp=2bc58821d92f2c4e6f72a3ab9909d0e7d80a6ff5;hpb=0b34769b9e3b9e823763cfd8bf3e2d64c2426710;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_silence.cpp b/src/modules/m_silence.cpp index 2bc58821d..f809d7d57 100644 --- a/src/modules/m_silence.cpp +++ b/src/modules/m_silence.cpp @@ -11,13 +11,6 @@ * --------------------------------------------------- */ -#include -#include -#include -#include "users.h" -#include "channels.h" -#include "modules.h" -#include "hashcomp.h" #include "inspircd.h" #include "wildcard.h" @@ -30,11 +23,13 @@ typedef std::map silencelist; class cmd_silence : public command_t { + unsigned int& maxsilence; public: - cmd_silence (InspIRCd* Instance) : command_t(Instance,"SILENCE", 0, 0) + 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); } CmdResult Handle (const char** parameters, int pcnt, userrec *user) @@ -64,7 +59,7 @@ class cmd_silence : public command_t char action = *parameters[0]; if (!mask.length()) - { + { // 'SILENCE +' or 'SILENCE -', assume *!*@* mask = "*!*@*"; } @@ -79,22 +74,21 @@ class cmd_silence : public command_t // does it contain any entries and does it exist? if (sl) { - if (sl->size()) + silencelist::iterator i = sl->find(mask.c_str()); + if (i != sl->end()) { - silencelist::iterator i = sl->find(mask.c_str()); - if (i != sl->end()) + sl->erase(i); + user->WriteServ("950 %s %s :Removed %s from silence list",user->nick, user->nick, mask.c_str()); + if (!sl->size()) { - sl->erase(i); - user->WriteServ("950 %s %s :Removed %s from silence list",user->nick, user->nick, mask.c_str()); + // 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 - { - // 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"); - } + user->WriteServ("952 %s %s :%s does not exist on your silence list",user->nick, user->nick, mask.c_str()); } } else if (action == '+') @@ -114,6 +108,11 @@ class cmd_silence : public command_t 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->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; @@ -127,22 +126,31 @@ class ModuleSilence : public Module { cmd_silence* mycommand; + unsigned int maxsilence; public: ModuleSilence(InspIRCd* Me) - : Module::Module(Me) + : Module(Me), maxsilence(32) { - - mycommand = new cmd_silence(ServerInstance); + 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 OnUserQuit(userrec* user, const std::string &reason) + 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, 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! @@ -158,7 +166,7 @@ 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, CUList &exempt_list) @@ -197,32 +205,8 @@ class ModuleSilence : public Module virtual Version GetVersion() { - return Version(1,1,0,1,VF_VENDOR,API_VERSION); - } -}; - - -class ModuleSilenceFactory : public ModuleFactory -{ - public: - ModuleSilenceFactory() - { + return Version(1, 1, 0, 0, VF_COMMON | VF_VENDOR, API_VERSION); } - - ~ModuleSilenceFactory() - { - } - - virtual Module * CreateModule(InspIRCd* Me) - { - return new ModuleSilence(Me); - } - }; - -extern "C" void * init_module( void ) -{ - return new ModuleSilenceFactory; -} - +MODULE_INIT(ModuleSilence)