#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "helperfuncs.h"
#include "inspircd.h"
/* $ModDesc: Provides channel mode +f (message flood protection) */
-
-
+/** Holds flood settings and state for mode +f
+ */
class floodsettings : public classbase
{
public:
floodsettings(bool a, int b, int c) : ban(a), secs(b), lines(c)
{
reset = time(NULL) + secs;
- log(DEBUG,"Create new floodsettings: %lu %lu",time(NULL),reset);
};
void addmessage(userrec* who)
if (iter != counters.end())
{
iter->second++;
- log(DEBUG,"Count for %s is now %d",who->nick,iter->second);
}
else
{
counters[who] = 1;
- log(DEBUG,"Count for %s is now *1*",who->nick);
}
if (time(NULL) > reset)
{
- log(DEBUG,"floodsettings timer Resetting.");
counters.clear();
reset = time(NULL) + secs;
}
std::map<userrec*,int>::iterator iter = counters.find(who);
if (iter != counters.end())
{
- log(DEBUG,"should kick? %d, %d",iter->second,this->lines);
return (iter->second >= this->lines);
}
else return false;
}
};
+/** Handles channel mode +f
+ */
class MsgFlood : public ModeHandler
{
public:
channel->SetModeParam('f', parameter.c_str(), true);
return MODEACTION_ALLOW;
}
+ else
+ {
+ if (((nlines != f->lines) || (nsecs != f->secs)) && ((nsecs > 0) && (nlines > 0)))
+ {
+ delete f;
+ floodsettings *f = new floodsettings(ban,nsecs,nlines);
+ parameter = ConvToStr(nlines) + ":" +ConvToStr(nsecs);
+ channel->Shrink("flood");
+ channel->Extend("flood",f);
+ channel->SetModeParam('f', parameter.c_str(), true);
+ return MODEACTION_ALLOW;
+ }
+ }
}
}
else
n.push_back("+b");
n.push_back(user->MakeWildHost());
Event rmode((char *)&n, NULL, "send_mode");
- rmode.Send();
+ rmode.Send(ServerInstance);
}
dest->ServerKickUser(user, "Channel flood triggered (mode +f)", true);
}
void Implements(char* List)
{
- List[I_On005Numeric] = List[I_OnChannelDelete] = List[I_OnUserNotice] = List[I_OnUserMessage] = 1;
- }
-
- virtual void On005Numeric(std::string &output)
- {
- ServerInstance->ModeGrok->InsertMode(output, "f", 3);
+ List[I_OnChannelDelete] = List[I_OnUserNotice] = List[I_OnUserMessage] = 1;
}
virtual ~ModuleMsgFlood()
{
+ ServerInstance->Modes->DelMode(mf);
DELETE(mf);
}
virtual Version GetVersion()
{
- return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
+ return Version(1, 0, 0, 0, VF_COMMON | VF_VENDOR);
}
};