/* $ModDesc: Provides channel mode +j (join flood protection) */
-class joinfloodsettings
+class joinfloodsettings : public classbase
{
public:
public:
JoinFlood() : ModeHandler('j', 1, 0, false, MODETYPE_CHANNEL, false) { }
+ ModePair ModeSet(userrec* source, userrec* dest, chanrec* channel, const std::string ¶meter)
+ {
+ joinfloodsettings* x;
+ if (channel->GetExt("joinflood",x))
+ return std::make_pair(true, ConvToStr(x->joins)+":"+ConvToStr(x->secs));
+ else
+ return std::make_pair(false, parameter);
+ }
+
+ bool CheckTimeStamp(time_t theirs, time_t ours, const std::string &their_param, const std::string &our_param, chanrec* channel)
+ {
+ /* When TS is equal, the alphabetically later one wins */
+ return (their_param < our_param);
+ }
+
ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
{
+ joinfloodsettings* dummy;
+
if (adding)
{
char ndata[MAXBUF];
}
else
{
- if (!channel->GetExt("joinflood"))
+ if (!channel->GetExt("joinflood", dummy))
{
parameter = ConvToStr(njoins) + ":" +ConvToStr(nsecs);
joinfloodsettings *f = new joinfloodsettings(nsecs,njoins);
- channel->Extend("joinflood",(char*)f);
+ channel->Extend("joinflood", f);
channel->SetMode('j', true);
channel->SetModeParam('j', parameter.c_str(), true);
return MODEACTION_ALLOW;
}
else
{
- if (channel->GetExt("joinflood"))
+ if (channel->GetExt("joinflood", dummy))
{
- joinfloodsettings *f = (joinfloodsettings*)channel->GetExt("joinflood");
+ joinfloodsettings *f;
+ channel->GetExt("joinflood", f);
DELETE(f);
channel->Shrink("joinflood");
channel->SetMode('j', false);
{
if (chan)
{
- joinfloodsettings *f = (joinfloodsettings*)chan->GetExt("joinflood");
- if (f)
+ joinfloodsettings *f;
+ if (chan->GetExt("joinflood", f))
{
if (f->islocked())
{
virtual void OnUserJoin(userrec* user, chanrec* channel)
{
- joinfloodsettings *f = (joinfloodsettings*)channel->GetExt("joinflood");
- if (f)
+ joinfloodsettings *f;
+ if (channel->GetExt("joinflood",f))
{
f->addjoin();
if (f->shouldlock())
{
f->clear();
f->lock();
- WriteChannelWithServ((char*)Srv->GetServerName().c_str(), channel, "NOTICE %s :This channel has been closed to new users for 60 seconds because there have been more than %d joins in %d seconds.",channel->name,f->joins,f->secs);
+ channel->WriteChannelWithServ((char*)Srv->GetServerName().c_str(), "NOTICE %s :This channel has been closed to new users for 60 seconds because there have been more than %d joins in %d seconds.", channel->name, f->joins, f->secs);
}
}
}
void OnChannelDelete(chanrec* chan)
{
- if (chan->GetExt("joinflood"))
+ joinfloodsettings *f;
+ if (chan->GetExt("joinflood",f))
{
- joinfloodsettings *f = (joinfloodsettings*)chan->GetExt("joinflood");
DELETE(f);
chan->Shrink("joinflood");
}