From 9e1399c12824e759f605dca601621159a5be618c Mon Sep 17 00:00:00 2001 From: Daniel Vassdal Date: Thu, 30 Jan 2014 06:32:03 -0800 Subject: m_conn_join: Allow time-delayed joins --- src/modules/m_conn_join.cpp | 65 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 57 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/modules/m_conn_join.cpp b/src/modules/m_conn_join.cpp index aec32e192..cbe8b0be3 100644 --- a/src/modules/m_conn_join.cpp +++ b/src/modules/m_conn_join.cpp @@ -22,9 +22,52 @@ #include "inspircd.h" +static void JoinChannels(LocalUser* u, const std::string& chanlist) +{ + irc::commasepstream chans(chanlist); + std::string chan; + + while (chans.GetToken(chan)) + { + if (ServerInstance->IsChannel(chan)) + Channel::JoinUser(u, chan); + } +} + +class JoinTimer : public Timer +{ + private: + LocalUser* const user; + const std::string channels; + SimpleExtItem& ext; + + public: + JoinTimer(LocalUser* u, SimpleExtItem& ex, const std::string& chans, unsigned int delay) + : Timer(delay, ServerInstance->Time(), false) + , user(u), channels(chans), ext(ex) + { + ServerInstance->Timers->AddTimer(this); + } + + bool Tick(time_t time) CXX11_OVERRIDE + { + if (user->chans.empty()) + JoinChannels(user, channels); + + ext.unset(user); + return false; + } +}; + class ModuleConnJoin : public Module { + SimpleExtItem ext; + public: + ModuleConnJoin() : ext("join_timer", this) + { + } + void Prioritize() { ServerInstance->Modules->SetPriority(this, I_OnPostConnect, PRIORITY_LAST); @@ -41,17 +84,23 @@ class ModuleConnJoin : public Module if (!localuser) return; - std::string chanlist = ServerInstance->Config->ConfValue("autojoin")->getString("channel"); - chanlist = localuser->GetClass()->config->getString("autojoin", chanlist); - - irc::commasepstream chans(chanlist); - std::string chan; + std::string chanlist = localuser->GetClass()->config->getString("autojoin"); + unsigned int chandelay = localuser->GetClass()->config->getInt("autojoindelay", 0, 0, 60); - while (chans.GetToken(chan)) + if (chanlist.empty()) { - if (ServerInstance->IsChannel(chan)) - Channel::JoinUser(localuser, chan); + ConfigTag* tag = ServerInstance->Config->ConfValue("autojoin"); + chanlist = tag->getString("channel"); + chandelay = tag->getInt("delay", 0, 0, 60); } + + if (chanlist.empty()) + return; + + if (!chandelay) + JoinChannels(localuser, chanlist); + else + ext.set(localuser, new JoinTimer(localuser, ext, chanlist, chandelay)); } }; -- cgit v1.2.3