summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Vassdal <shutter@canternet.org>2014-01-30 06:32:03 -0800
committerAttila Molnar <attilamolnar@hush.com>2014-01-30 22:12:18 +0100
commit9e1399c12824e759f605dca601621159a5be618c (patch)
tree9669525601fee44e8f6b9298612a2bd2e79d3372 /src
parent86a7fa3a06c44470707e586896eca54fc506dfc7 (diff)
m_conn_join: Allow time-delayed joins
Diffstat (limited to 'src')
-rw-r--r--src/modules/m_conn_join.cpp65
1 files changed, 57 insertions, 8 deletions
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<JoinTimer>& ext;
+
+ public:
+ JoinTimer(LocalUser* u, SimpleExtItem<JoinTimer>& 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<JoinTimer> 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));
}
};