summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-07-09 15:14:14 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-07-09 15:14:14 +0000
commit9d8022a06563e9a11b6d16b139090cde82fad877 (patch)
tree873370e0105b72e1d5cf566ca7bf6b0e8c30f4a9
parent8be30d2589d400a1de6bd61dba238c6d12c00ec4 (diff)
Port to new API (last mode that has akward parameters done, yay!)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@4224 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r--src/modules/m_messageflood.cpp145
1 files changed, 75 insertions, 70 deletions
diff --git a/src/modules/m_messageflood.cpp b/src/modules/m_messageflood.cpp
index c5df268ea..2cbecfdac 100644
--- a/src/modules/m_messageflood.cpp
+++ b/src/modules/m_messageflood.cpp
@@ -83,95 +83,99 @@ class floodsettings
}
};
-class ModuleMsgFlood : public Module
+class MsgFlood : public ModeHandler
{
- 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 &params)
+ MsgFlood() : ModeHandler('f', 1, 0, false, MODETYPE_CHANNEL, false) { }
+
+ ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)
{
- if ((modechar == 'f') && (type == MT_CHANNEL))
+ if (adding)
{
- if (mode_on)
+ char ndata[MAXBUF];
+ char* data = ndata;
+ strlcpy(ndata,parameter.c_str(),MAXBUF);
+ char* lines = data;
+ char* secs = NULL;
+ bool ban = false;
+ if (*data == '*')
{
- std::string FloodParams = params[0];
- chanrec* c = (chanrec*)target;
- char ndata[MAXBUF];
- char* data = ndata;
- strlcpy(ndata,FloodParams.c_str(),MAXBUF);
- char* lines = data;
- char* secs = NULL;
- bool ban = false;
- if (*data == '*')
+ ban = true;
+ lines++;
+ }
+ else
+ {
+ ban = false;
+ }
+ while (*data)
+ {
+ if (*data == ':')
{
- ban = true;
- lines++;
+ *data = 0;
+ data++;
+ secs = data;
+ break;
}
- else
+ 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))
{
- ban = false;
+ WriteServ(source->fd,"608 %s %s :Invalid flood parameter",source->nick,channel->name);
+ parameter = "";
+ return MODEACTION_DENY;
}
- while (*data)
+ else
{
- if (*data == ':')
+ if (!channel->GetExt("flood"))
{
- *data = 0;
- data++;
- secs = data;
- break;
+ floodsettings *f = new floodsettings(ban,nsecs,nlines);
+ channel->Extend("flood",(char*)f);
+ return MODEACTION_ALLOW;
}
- 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,nsecs,nlines);
- c->Extend("flood",(char*)f);
- }
- }
- return 1;
- }
- else
- {
- WriteServ(user->fd,"608 %s %s :Invalid flood parameter",user->nick,c->name);
- return 0;
- }
-
}
else
{
- chanrec* c = (chanrec*)target;
- if (c->GetExt("flood"))
- {
- floodsettings *f = (floodsettings*)c->GetExt("flood");
- DELETE(f);
- c->Shrink("flood");
- }
+ WriteServ(source->fd,"608 %s %s :Invalid flood parameter",source->nick,channel->name);
+ parameter = "";
+ return MODEACTION_DENY;
}
- return 1;
}
- return 0;
+ else
+ {
+ if (channel->GetExt("flood"))
+ {
+ floodsettings *f = (floodsettings*)channel->GetExt("flood");
+ DELETE(f);
+ channel->Shrink("flood");
+ return MODEACTION_ALLOW;
+ }
+ }
+
+ return MODEACTION_DENY;
}
+};
+class ModuleMsgFlood : public Module
+{
+ Server *Srv;
+ MsgFlood* mf;
+
+ public:
+
+ ModuleMsgFlood(Server* Me)
+ : Module::Module(Me)
+ {
+ Srv = Me;
+ mf = new MsgFlood();
+ Srv->AddMode(mf, 'f');
+ }
+
void ProcessMessages(userrec* user,chanrec* dest, const std::string &text)
{
if (IS_LOCAL(user))
@@ -226,7 +230,7 @@ class ModuleMsgFlood : public Module
void Implements(char* List)
{
- List[I_On005Numeric] = List[I_OnExtendedMode] = List[I_OnChannelDelete] = List[I_OnUserNotice] = List[I_OnUserMessage] = 1;
+ List[I_On005Numeric] = List[I_OnChannelDelete] = List[I_OnUserNotice] = List[I_OnUserMessage] = 1;
}
virtual void On005Numeric(std::string &output)
@@ -236,6 +240,7 @@ class ModuleMsgFlood : public Module
virtual ~ModuleMsgFlood()
{
+ DELETE(mf);
}
virtual Version GetVersion()