diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/modules/m_joinflood.cpp | 126 |
1 files changed, 64 insertions, 62 deletions
diff --git a/src/modules/m_joinflood.cpp b/src/modules/m_joinflood.cpp index ae31ab67c..6cc54db68 100644 --- a/src/modules/m_joinflood.cpp +++ b/src/modules/m_joinflood.cpp @@ -92,88 +92,89 @@ class joinfloodsettings unlocktime = time(NULL) + 60; } - }; -class ModuleJoinFlood : public Module +class JoinFlood : public ModeHandler { - Server *Srv; - public: - - ModuleJoinFlood(Server* Me) - : Module::Module(Me) - { - Srv = Me; - Srv->AddExtendedMode('j',MT_CHANNEL,false,1,0); - } - - virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms) + JoinFlood() : ModeHandler('j', 1, 0, false, MODETYPE_CHANNEL, false) { } + + ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding) { - if ((modechar == 'j') && (type == MT_CHANNEL)) + if (adding) { - if (mode_on) + char ndata[MAXBUF]; + char* data = ndata; + strlcpy(ndata,parameter.c_str(),MAXBUF); + char* joins = data; + char* secs = NULL; + while (*data) { - std::string FloodParams = params[0]; - chanrec* c = (chanrec*)target; - char ndata[MAXBUF]; - char* data = ndata; - strlcpy(ndata,FloodParams.c_str(),MAXBUF); - char* joins = data; - char* secs = NULL; - while (*data) + if (*data == ':') { - if (*data == ':') - { - *data = 0; - data++; - secs = data; - break; - } - else data++; + *data = 0; + data++; + secs = data; + break; } - if (secs) + else data++; + } + if (secs) + { + /* Set up the flood parameters for this channel */ + int njoins = atoi(joins); + int nsecs = atoi(secs); + if ((njoins<1) || (nsecs<1)) { - /* Set up the flood parameters for this channel */ - int njoins = atoi(joins); - int nsecs = atoi(secs); - if ((njoins<1) || (nsecs<1)) - { - WriteServ(user->fd,"608 %s %s :Invalid flood parameter",user->nick,c->name); - return 0; - } - else - { - if (!c->GetExt("joinflood")) - { - joinfloodsettings *f = new joinfloodsettings(nsecs,njoins); - c->Extend("joinflood",(char*)f); - } - } - return 1; + WriteServ(source->fd,"608 %s %s :Invalid flood parameter",source->nick,channel->name); + parameter = ""; + return MODEACTION_DENY; } else { - WriteServ(user->fd,"608 %s %s :Invalid flood parameter",user->nick,c->name); - return 0; + if (!channel->GetExt("joinflood")) + { + joinfloodsettings *f = new joinfloodsettings(nsecs,njoins); + channel->Extend("joinflood",(char*)f); + return MODEACTION_ALLOW; + } } - } else { - chanrec* c = (chanrec*)target; - if (c->GetExt("joinflood")) - { - joinfloodsettings *f = (joinfloodsettings*)c->GetExt("joinflood"); - DELETE(f); - c->Shrink("joinflood"); - } + WriteServ(source->fd,"608 %s %s :Invalid flood parameter",source->nick,channel->name); + return MODEACTION_DENY; } - return 1; } - return 0; + else + { + if (channel->GetExt("joinflood")) + { + joinfloodsettings *f = (joinfloodsettings*)channel->GetExt("joinflood"); + DELETE(f); + channel->Shrink("joinflood"); + return MODEACTION_ALLOW; + } + } + return MODEACTION_DENY; } +}; +class ModuleJoinFlood : public Module +{ + Server *Srv; + JoinFlood* jf; + + public: + + ModuleJoinFlood(Server* Me) + : Module::Module(Me) + { + Srv = Me; + jf = new JoinFlood(); + Srv->AddMode(jf, 'j'); + } + virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname) { if (chan) @@ -218,7 +219,7 @@ class ModuleJoinFlood : public Module void Implements(char* List) { - List[I_On005Numeric] = List[I_OnExtendedMode] = List[I_OnChannelDelete] = List[I_OnUserPreJoin] = List[I_OnUserJoin] = 1; + List[I_On005Numeric] = List[I_OnChannelDelete] = List[I_OnUserPreJoin] = List[I_OnUserJoin] = 1; } virtual void On005Numeric(std::string &output) @@ -228,6 +229,7 @@ class ModuleJoinFlood : public Module virtual ~ModuleJoinFlood() { + DELETE(jf); } virtual Version GetVersion() |