diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-01-22 15:51:06 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-01-22 15:51:06 +0000 |
commit | 02280596a038d1d7ad245a2c7808d57d80ab0a42 (patch) | |
tree | bab22a05250db57b6e37df75f7a9a09b20836ca2 /src | |
parent | 9295960ea1b6821fc8c03f4cc672f0e49215d750 (diff) |
Added OnChannelDelete() method (called on KICK, PART or QUIT where a channel is deleted for cleanup of metadata)
Added m_messageflood.so (not yet finished, do not use yet)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@2826 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-rw-r--r-- | src/channels.cpp | 2 | ||||
-rw-r--r-- | src/helperfuncs.cpp | 3 | ||||
-rw-r--r-- | src/modules.cpp | 1 | ||||
-rw-r--r-- | src/modules/m_messageflood.cpp | 193 |
4 files changed, 199 insertions, 0 deletions
diff --git a/src/channels.cpp b/src/channels.cpp index fa8c56188..2b1fac5f2 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -442,6 +442,7 @@ chanrec* del_channel(userrec *user, const char* cname, const char* reason, bool if (iter != chanlist.end()) { log(DEBUG,"del_channel: destroyed: %s",Ptr->name); + FOREACH_MOD(I_OnChannelDelete,OnChannelDelete(Ptr)); delete Ptr; chanlist.erase(iter); } @@ -531,6 +532,7 @@ void kick_channel(userrec *src,userrec *user, chanrec *Ptr, char* reason) if (iter != chanlist.end()) { log(DEBUG,"del_channel: destroyed: %s",Ptr->name); + FOREACH_MOD(I_OnChannelDelete,OnChannelDelete(Ptr)); delete Ptr; chanlist.erase(iter); } diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp index 456b6b5b1..767cb7caa 100644 --- a/src/helperfuncs.cpp +++ b/src/helperfuncs.cpp @@ -979,7 +979,10 @@ void purge_empty_chans(userrec* u) { log(DEBUG,"del_channel: destroyed: %s",i2->second->name); if (i2->second) + { + FOREACH_MOD(I_OnChannelDelete,OnChannelDelete(i2->second)); delete i2->second; + } chanlist.erase(i2); purge++; u->chans[i].channel = NULL; diff --git a/src/modules.cpp b/src/modules.cpp index 1d20239d7..390efe5bf 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -298,6 +298,7 @@ void Module::OnDelQLine(userrec* source, std::string nickmask) { }; void Module::OnDelELine(userrec* source, std::string hostmask) { }; void Module::OnCleanup(int target_type, void* item) { }; void Module::Implements(char* Implements) { for (int j = 0; j < 255; j++) Implements[j] = 0; }; +void Module::OnChannelDelete(chanrec* chan) { }; Priority Module::Prioritize() { return PRIORITY_DONTCARE; } /* server is a wrapper class that provides methods to all of the C-style diff --git a/src/modules/m_messageflood.cpp b/src/modules/m_messageflood.cpp new file mode 100644 index 000000000..980c78dff --- /dev/null +++ b/src/modules/m_messageflood.cpp @@ -0,0 +1,193 @@ +/* +------------------------------------+ + * | Inspire Internet Relay Chat Daemon | + * +------------------------------------+ + * + * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev. + * E-mail: + * <brain@chatspike.net> + * <Craig@chatspike.net> + * + * Written by Craig Edwards, Craig McLure, and others. + * This program is free but copyrighted software; see + * the file COPYING for details. + * + * --------------------------------------------------- + */ + +using namespace std; + +#include <stdio.h> +#include "users.h" +#include "channels.h" +#include "modules.h" +#include "helperfuncs.h" + +/* $ModDesc: Provides channel mode +f (message flood protection) */ + +class floodsettings +{ + bool ban; + int secs; + int lines; + + floodsettings() : ban(0), secs(0), lines(0) {}; + floodsettings(bool a, int b, int c) : ban(a), secs(b), lines(c) {}; +} + +class ModuleMsgFlood : public Module +{ + Server *Srv; + + public: + + ModuleMsgFlood(Server* Me) + : Module::Module(Me) + { + Srv = Me; + Srv->AddExtendedMode('f',MT_CHANNEL,false,1,0); + } + + virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms) + { + if ((modechar == 'f') && (type == MT_CHANNEL)) + { + if (mode_on) + { + std::string FloodParams = params[0]; + chanrec* c = (chanrec*)target; + char data[MAXBUF]; + strlcpy(data,FloodParams.c_str(),MAXBUF); + char* lines = data; + char* secs = NULL; + bool ban = false; + if (*data == '*') + { + ban = true; + data++; + } + else + { + ban = false; + } + while (*data) + { + if (*data == ':') + { + *data = 0; + data++; + secs = data; + break; + } + else data++; + } + if (secs) + { + /* Set up the flood parameters for this channel */ + int nlines = atoi(lines); + int nsecs = atoi(secs); + if ((nlines<1) || (nsecs<1)) + { + WriteServ(user->fd,"608 %s %s :Invalid flood parameter",user->nick,c->name); + return 0; + } + else + { + if (!c->GetExt("flood")) + { + floodsettings *f = new floodsettings(ban,nlines,nsecs); + c->Extend("flood",(char*)f); + } + } + return 1; + } + else + { + WriteServ(user->fd,"608 %s %s :Invalid flood parameter",user->nick,c->name); + return 0; + } + + } + else + { + if (c->GetExt("flood")) + { + floodsettings *f = (floodsettings*)c->GetExt("flood"); + delete f; + c->Shrink("flood"); + } + } + return 1; + } + return 0; + } + + void OnChannelDelete(chanrec* chan) + { + if (c->GetExt("flood")) + { + floodsettings *f = (floodsettings*)c->GetExt("flood"); + delete f; + c->Shrink("flood"); + } + } + + void Implements(char* List) + { + List[I_On005Numeric] = List[I_OnExtendedMode] = List[I_OnChannelDelete] = 1; + } + + virtual void On005Numeric(std::string &output) + { + std::stringstream line(output); + std::string temp1, temp2; + while (!line.eof()) + { + line >> temp1; + if (temp1.substr(0,10) == "CHANMODES=") + { + // By doing this we're *assuming* no other module has fucked up the CHANMODES= + // section of the 005 numeric. If they have, we're going DOWN in a blaze of glory, + // with a honking great EXCEPTION :) + temp1.insert(temp1.find(",")+1,"L"); + } + temp2 = temp2 + temp1 + " "; + } + if (temp2.length()) + output = temp2.substr(0,temp2.length()-1); + } + + virtual ~ModuleMsgFlood() + { + } + + virtual Version GetVersion() + { + return Version(1,0,0,0,VF_STATIC|VF_VENDOR); + } +}; + + +class ModuleMsgFloodFactory : public ModuleFactory +{ + public: + ModuleMsgFloodFactory() + { + } + + ~ModuleMsgFloodFactory() + { + } + + virtual Module * CreateModule(Server* Me) + { + return new ModuleMsgFlood(Me); + } + +}; + + +extern "C" void * init_module( void ) +{ + return new ModuleMsgFloodFactory; +} + |