X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_conn_join.cpp;h=d5a095e7f89721df6e99f5492ebe76d04fe8921d;hb=90abe2cd475c8ca2e81626f565d173e9f56d1251;hp=fdcf82dccdd3a6066350bb52a012fa1c4c42cfe6;hpb=1031f333332cf1b09db4fd632f141143ee637c34;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_conn_join.cpp b/src/modules/m_conn_join.cpp index fdcf82dcc..d5a095e7f 100644 --- a/src/modules/m_conn_join.cpp +++ b/src/modules/m_conn_join.cpp @@ -22,37 +22,93 @@ #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, 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 { - public: - void Prioritize() - { - ServerInstance->Modules->SetPriority(this, I_OnPostConnect, PRIORITY_LAST); - } + SimpleExtItem ext; + std::string defchans; + unsigned int defdelay; - Version GetVersion() CXX11_OVERRIDE - { - return Version("Forces users to join the specified channel(s) on connect", VF_VENDOR); - } + public: + ModuleConnJoin() : ext("join_timer", this) + { + } - void OnPostConnect(User* user) CXX11_OVERRIDE - { - LocalUser* localuser = IS_LOCAL(user); - if (!localuser) - return; + void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE + { + ConfigTag* tag = ServerInstance->Config->ConfValue("autojoin"); + defchans = tag->getString("channel"); + defdelay = tag->getInt("delay", 0, 0, 60); + } - std::string chanlist = ServerInstance->Config->ConfValue("autojoin")->getString("channel"); - chanlist = localuser->GetClass()->config->getString("autojoin", chanlist); + void Prioritize() + { + ServerInstance->Modules->SetPriority(this, I_OnPostConnect, PRIORITY_LAST); + } - irc::commasepstream chans(chanlist); - std::string chan; + Version GetVersion() CXX11_OVERRIDE + { + return Version("Forces users to join the specified channel(s) on connect", VF_VENDOR); + } - while (chans.GetToken(chan)) - { - if (ServerInstance->IsChannel(chan)) - Channel::JoinUser(localuser, chan); - } + void OnPostConnect(User* user) CXX11_OVERRIDE + { + LocalUser* localuser = IS_LOCAL(user); + if (!localuser) + return; + + std::string chanlist = localuser->GetClass()->config->getString("autojoin"); + unsigned int chandelay = localuser->GetClass()->config->getInt("autojoindelay", 0, 0, 60); + + if (chanlist.empty()) + { + if (defchans.empty()) + return; + chanlist = defchans; + chandelay = defdelay; } + + if (!chandelay) + JoinChannels(localuser, chanlist); + else + ext.set(localuser, new JoinTimer(localuser, ext, chanlist, chandelay)); + } }; MODULE_INIT(ModuleConnJoin)