* | Inspire Internet Relay Chat Daemon |
* +------------------------------------+
*
- * InspIRCd: (C) 2002-2008 InspIRCd Development Team
- * See: http://www.inspircd.org/wiki/index.php/Credits
+ * InspIRCd: (C) 2002-2009 InspIRCd Development Team
+ * See: http://wiki.inspircd.org/Credits
*
* This program is free but copyrighted software; see
* the file COPYING for details.
/* $ModDesc: Provides channel mode +J (delay rejoin after kick) */
-inline int strtoint(const std::string &str)
+static inline int strtoint(const std::string &str)
{
std::istringstream ss(str);
int result;
class KickRejoin : public ModeHandler
{
public:
- KickRejoin(InspIRCd* Instance) : ModeHandler(Instance, 'J', 1, 0, false, MODETYPE_CHANNEL, false) { }
+ SimpleExtItem<delaylist> ext;
+ KickRejoin(Module* Creator) : ModeHandler(Creator, 'J', PARAM_SETONLY, MODETYPE_CHANNEL),
+ ext("norejoinusers", Creator) { }
ModePair ModeSet(User* source, User* dest, Channel* channel, const std::string ¶meter)
{
return std::make_pair(true, channel->GetModeParameter('J'));
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, Channel* channel)
- {
- /* When TS is equal, the alphabetically later one wins */
- return (their_param < our_param);
}
-
- ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding, bool)
+
+ ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding)
{
if (!adding)
{
- // Taking the mode off, we need to clean up.
- delaylist* dl;
-
- if (channel->GetExt("norejoinusers", dl))
- {
- delete dl;
- channel->Shrink("norejoinusers");
- }
-
+ ext.unset(channel);
+
if (!channel->IsModeSet('J'))
{
return MODEACTION_DENY;
}
else
{
- channel->SetMode('J', false);
+ channel->SetModeParam('J', "");
return MODEACTION_ALLOW;
}
}
if (!channel->IsModeSet('J'))
{
parameter = ConvToStr(atoi(parameter.c_str()));
- channel->SetModeParam('J', parameter.c_str(), adding);
- channel->SetMode('J', adding);
+ channel->SetModeParam('J', parameter);
return MODEACTION_ALLOW;
}
else
{
// new mode param, replace old with new
parameter = ConvToStr(atoi(parameter.c_str()));
- cur_param = ConvToStr(atoi(cur_param.c_str()));
if (parameter != "0")
{
- channel->SetModeParam('J', cur_param.c_str(), false);
- channel->SetModeParam('J', parameter.c_str(), adding);
+ channel->SetModeParam('J', parameter);
return MODEACTION_ALLOW;
}
else
class ModuleKickNoRejoin : public Module
{
-
- KickRejoin* kr;
-
+ KickRejoin kr;
+
public:
-
- ModuleKickNoRejoin(InspIRCd* Me)
- : Module(Me)
+
+ ModuleKickNoRejoin()
+ : kr(this)
{
-
- kr = new KickRejoin(ServerInstance);
- if (!ServerInstance->Modes->AddMode(kr))
+ if (!ServerInstance->Modes->AddMode(&kr))
throw ModuleException("Could not add new modes!");
- Implementation eventlist[] = { I_OnCleanup, I_OnChannelDelete, I_OnUserPreJoin, I_OnUserKick };
- ServerInstance->Modules->Attach(eventlist, this, 4);
+ Extensible::Register(&kr.ext);
+ Implementation eventlist[] = { I_OnUserPreJoin, I_OnUserKick };
+ ServerInstance->Modules->Attach(eventlist, this, 2);
}
- virtual int 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)
{
- delaylist* dl;
- if (chan->GetExt("norejoinusers", dl))
+ delaylist* dl = kr.ext.get(chan);
+ if (dl)
{
std::vector<User*> itemstoremove;
-
+
for (delaylist::iterator iter = dl->begin(); iter != dl->end(); iter++)
{
- if (iter->second > time(NULL))
+ if (iter->second > ServerInstance->Time())
{
- if (iter->first == user)
+ if (iter->first == user)
{
- user->WriteServ( "495 %s %s :You cannot rejoin this channel yet after being kicked (+J)", user->nick, chan->name);
- return 1;
+ user->WriteNumeric(ERR_DELAYREJOIN, "%s %s :You must wait %s seconds after being kicked to rejoin (+J)", user->nick.c_str(), chan->name.c_str(), chan->GetModeParameter('J').c_str());
+ return MOD_RES_DENY;
}
}
else
itemstoremove.push_back(iter->first);
}
}
-
+
for (unsigned int i = 0; i < itemstoremove.size(); i++)
dl->erase(itemstoremove[i]);
-
+
if (!dl->size())
- {
- // Now it's empty..
- delete dl;
- chan->Shrink("norejoinusers");
- }
+ kr.ext.unset(chan);
}
}
- return 0;
+ return MOD_RES_PASSTHRU;
}
-
- virtual void OnUserKick(User* source, User* user, Channel* chan, const std::string &reason, bool &silent)
+
+ void OnUserKick(User* source, Membership* memb, const std::string &reason, CUList& excepts)
{
- if (chan->IsModeSet('J') && (source != user))
+ if (memb->chan->IsModeSet('J') && (source != memb->user))
{
- delaylist* dl;
- if (!chan->GetExt("norejoinusers", dl))
+ delaylist* dl = kr.ext.get(memb->chan);
+ if (dl)
{
dl = new delaylist;
- chan->Extend("norejoinusers", dl);
+ kr.ext.set(memb->chan, dl);
}
- (*dl)[user] = time(NULL) + strtoint(chan->GetModeParameter('J'));
+ (*dl)[memb->user] = ServerInstance->Time() + strtoint(memb->chan->GetModeParameter('J'));
}
}
-
- virtual void OnChannelDelete(Channel* chan)
- {
- delaylist* dl;
-
- if (chan->GetExt("norejoinusers", dl))
- {
- delete dl;
- chan->Shrink("norejoinusers");
- }
- }
-
- virtual void OnCleanup(int target_type, void* item)
- {
- if(target_type == TYPE_CHANNEL)
- OnChannelDelete((Channel*)item);
- }
-
- virtual ~ModuleKickNoRejoin()
+ ~ModuleKickNoRejoin()
{
- ServerInstance->Modes->DelMode(kr);
- delete kr;
+ ServerInstance->Modes->DelMode(&kr);
}
-
- virtual Version GetVersion()
+
+ Version GetVersion()
{
- return Version(1, 2, 0, 0, VF_COMMON | VF_VENDOR, API_VERSION);
+ return Version("Channel mode J, kick-no-rejoin", VF_COMMON | VF_VENDOR);
}
};