* | Inspire Internet Relay Chat Daemon |
* +------------------------------------+
*
- * InspIRCd: (C) 2002-2009 InspIRCd Development Team
+ * InspIRCd: (C) 2002-2010 InspIRCd Development Team
* See: http://wiki.inspircd.org/Credits
*
* This program is free but copyrighted software; see
/** Holds settings and state associated with channel mode +F
*/
-class nickfloodsettings : public classbase
+class nickfloodsettings
{
- private:
- InspIRCd* ServerInstance;
public:
int secs;
int nicks;
int counter;
bool locked;
- nickfloodsettings(InspIRCd *Instance, int b, int c) : ServerInstance(Instance), secs(b), nicks(c)
+ nickfloodsettings(int b, int c) : secs(b), nicks(c)
{
- reset = Instance->Time() + secs;
+ reset = ServerInstance->Time() + secs;
counter = 0;
locked = false;
};
{
public:
SimpleExtItem<nickfloodsettings> ext;
- NickFlood(InspIRCd* Instance, Module* Creator) : ModeHandler(Instance, Creator, 'F', 1, 0, false, MODETYPE_CHANNEL, false),
+ NickFlood(Module* Creator) : ModeHandler(Creator, "nickflood", 'F', PARAM_SETONLY, MODETYPE_CHANNEL),
ext("nickflood", Creator) { }
- ModePair ModeSet(User* source, User* dest, Channel* channel, const std::string ¶meter)
- {
- nickfloodsettings* x = ext.get(channel);
- if (x)
- return std::make_pair(true, ConvToStr(x->nicks)+":"+ConvToStr(x->secs));
- else
- return std::make_pair(false, parameter);
- }
-
ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding)
{
nickfloodsettings *f = ext.get(channel);
if (!f)
{
parameter = ConvToStr(nnicks) + ":" +ConvToStr(nsecs);
- f = new nickfloodsettings(ServerInstance, nsecs, nnicks);
+ f = new nickfloodsettings(nsecs, nnicks);
ext.set(channel, f);
channel->SetModeParam('F', parameter);
return MODEACTION_ALLOW;
// new mode param, replace old with new
if ((nsecs > 0) && (nnicks > 0))
{
- f = new nickfloodsettings(ServerInstance, nsecs, nnicks);
+ f = new nickfloodsettings(nsecs, nnicks);
ext.set(channel, f);
channel->SetModeParam('F', parameter);
return MODEACTION_ALLOW;
public:
- ModuleNickFlood(InspIRCd* Me)
- : Module(Me), nf(Me, this)
+ ModuleNickFlood()
+ : nf(this)
{
if (!ServerInstance->Modes->AddMode(&nf))
throw ModuleException("Could not add new modes!");
- Extensible::Register(&nf.ext);
+ ServerInstance->Extensions.Register(&nf.ext);
Implementation eventlist[] = { I_OnUserPreNick, I_OnUserPostNick };
ServerInstance->Modules->Attach(eventlist, this, 2);
}
for (UCListIter i = user->chans.begin(); i != user->chans.end(); i++)
{
- Channel *channel = i->first;
+ Channel *channel = *i;
+ ModResult res;
nickfloodsettings *f = nf.ext.get(channel);
if (f)
{
- if (CHANOPS_EXEMPT(ServerInstance, 'F') && channel->GetStatus(user) == STATUS_OP)
+ FIRST_MOD_RESULT(OnChannelRestrictionApply, res, (user,channel,"nickflood"));
+ if (res == MOD_RES_ALLOW)
continue;
if (f->islocked())
{
f->clear();
f->lock();
- channel->WriteChannelWithServ((char*)ServerInstance->Config->ServerName, "NOTICE %s :No nick changes are allowed for 60 seconds because there have been more than %d nick changes in %d seconds.", channel->name.c_str(), f->nicks, f->secs);
+ channel->WriteChannelWithServ((char*)ServerInstance->Config->ServerName.c_str(), "NOTICE %s :No nick changes are allowed for 60 seconds because there have been more than %d nick changes in %d seconds.", channel->name.c_str(), f->nicks, f->secs);
return MOD_RES_DENY;
}
}
for (UCListIter i = user->chans.begin(); i != user->chans.end(); ++i)
{
- Channel *channel = i->first;
+ Channel *channel = *i;
+ ModResult res;
nickfloodsettings *f = nf.ext.get(channel);
if (f)
{
- if (CHANOPS_EXEMPT(ServerInstance, 'F') && channel->GetStatus(user) == STATUS_OP)
+ FIRST_MOD_RESULT(OnChannelRestrictionApply, res, (user,channel,"nickflood"));
+ if (res == MOD_RES_ALLOW)
return;
/* moved this here to avoid incrementing the counter for nick
~ModuleNickFlood()
{
- ServerInstance->Modes->DelMode(&nf);
}
Version GetVersion()
{
- return Version("Channel mode F - nick flood protection", VF_COMMON | VF_VENDOR);
+ return Version("Channel mode F - nick flood protection", VF_VENDOR);
}
};