summaryrefslogtreecommitdiff
path: root/src/modules/m_joinflood.cpp
diff options
context:
space:
mode:
authordanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2009-09-13 20:30:25 +0000
committerdanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2009-09-13 20:30:25 +0000
commit6d57bbe05c31c79eaad02fe81cfb9c1ed6b79c58 (patch)
treee0c89ed36b00f4c2925d7f39c32a835657b0fa6e /src/modules/m_joinflood.cpp
parent7eea21b8d43b0d5993e88b62d9d4894c2af49303 (diff)
Change Extensible to use strongly typed entries
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11696 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/modules/m_joinflood.cpp')
-rw-r--r--src/modules/m_joinflood.cpp68
1 files changed, 25 insertions, 43 deletions
diff --git a/src/modules/m_joinflood.cpp b/src/modules/m_joinflood.cpp
index 180d58376..853ddee75 100644
--- a/src/modules/m_joinflood.cpp
+++ b/src/modules/m_joinflood.cpp
@@ -86,12 +86,14 @@ class joinfloodsettings : public classbase
class JoinFlood : public ModeHandler
{
public:
- JoinFlood(InspIRCd* Instance, Module* Creator) : ModeHandler(Instance, Creator, 'j', 1, 0, false, MODETYPE_CHANNEL, false) { }
+ SimpleExtItem<joinfloodsettings> ext;
+ JoinFlood(InspIRCd* Instance, Module* Creator) : ModeHandler(Instance, Creator, 'j', 1, 0, false, MODETYPE_CHANNEL, false),
+ ext("joinflood", Creator) { }
ModePair ModeSet(User* source, User* dest, Channel* channel, const std::string &parameter)
{
- joinfloodsettings* x;
- if (channel->GetExt("joinflood",x))
+ joinfloodsettings* x = ext.get(channel);
+ if (x)
return std::make_pair(true, ConvToStr(x->joins)+":"+ConvToStr(x->secs));
else
return std::make_pair(false, parameter);
@@ -99,8 +101,6 @@ class JoinFlood : public ModeHandler
ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding)
{
- joinfloodsettings* dummy;
-
if (adding)
{
char ndata[MAXBUF];
@@ -133,11 +133,12 @@ class JoinFlood : public ModeHandler
}
else
{
- if (!channel->GetExt("joinflood", dummy))
+ joinfloodsettings* f = ext.get(channel);
+ if (!f)
{
parameter = ConvToStr(njoins) + ":" +ConvToStr(nsecs);
- joinfloodsettings *f = new joinfloodsettings(ServerInstance, nsecs, njoins);
- channel->Extend("joinflood", f);
+ f = new joinfloodsettings(ServerInstance, nsecs, njoins);
+ ext.set(channel, f);
channel->SetModeParam('j', parameter);
return MODEACTION_ALLOW;
}
@@ -155,12 +156,8 @@ class JoinFlood : public ModeHandler
// new mode param, replace old with new
if ((nsecs > 0) && (njoins > 0))
{
- joinfloodsettings* f;
- channel->GetExt("joinflood", f);
- delete f;
f = new joinfloodsettings(ServerInstance, nsecs, njoins);
- channel->Shrink("joinflood");
- channel->Extend("joinflood", f);
+ ext.set(channel, f);
channel->SetModeParam('j', parameter);
return MODEACTION_ALLOW;
}
@@ -180,12 +177,10 @@ class JoinFlood : public ModeHandler
}
else
{
- if (channel->GetExt("joinflood", dummy))
+ joinfloodsettings* f = ext.get(channel);
+ if (f)
{
- joinfloodsettings *f;
- channel->GetExt("joinflood", f);
- delete f;
- channel->Shrink("joinflood");
+ ext.unset(channel);
channel->SetModeParam('j', "");
return MODEACTION_ALLOW;
}
@@ -207,37 +202,35 @@ class ModuleJoinFlood : public Module
if (!ServerInstance->Modes->AddMode(&jf))
throw ModuleException("Could not add new modes!");
+ Extensible::Register(&jf.ext);
Implementation eventlist[] = { I_OnChannelDelete, I_OnUserPreJoin, I_OnUserJoin };
ServerInstance->Modules->Attach(eventlist, this, 3);
}
- virtual ModResult OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven)
+ ModResult OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven)
{
if (chan)
{
- joinfloodsettings *f;
- if (chan->GetExt("joinflood", f))
+ joinfloodsettings *f = jf.ext.get(chan);
+ if (f && f->islocked())
{
- if (f->islocked())
- {
- user->WriteNumeric(609, "%s %s :This channel is temporarily unavailable (+j). Please try again later.",user->nick.c_str(),chan->name.c_str());
- return MOD_RES_DENY;
- }
+ user->WriteNumeric(609, "%s %s :This channel is temporarily unavailable (+j). Please try again later.",user->nick.c_str(),chan->name.c_str());
+ return MOD_RES_DENY;
}
}
return MOD_RES_PASSTHRU;
}
- virtual void OnUserJoin(User* user, Channel* channel, bool sync, bool &silent, bool created)
+ void OnUserJoin(User* user, Channel* channel, bool sync, bool &silent, bool created)
{
- joinfloodsettings *f;
-
/* We arent interested in JOIN events caused by a network burst */
if (sync)
return;
+ joinfloodsettings *f = jf.ext.get(channel);
+
/* But all others are OK */
- if (channel->GetExt("joinflood",f))
+ if (f)
{
f->addjoin();
if (f->shouldlock())
@@ -249,23 +242,12 @@ class ModuleJoinFlood : public Module
}
}
- void OnChannelDelete(Channel* chan)
- {
- joinfloodsettings *f;
- if (chan->GetExt("joinflood",f))
- {
- delete f;
- chan->Shrink("joinflood");
- }
- }
-
-
- virtual ~ModuleJoinFlood()
+ ~ModuleJoinFlood()
{
ServerInstance->Modes->DelMode(&jf);
}
- virtual Version GetVersion()
+ Version GetVersion()
{
return Version("$Id$", VF_COMMON | VF_VENDOR, API_VERSION);
}