Advertisement
Guest User

Untitled

a guest
Jun 26th, 2015
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.18 KB | None | 0 0
  1. /*
  2.  * InspIRCd -- Internet Relay Chat Daemon
  3.  *
  4.  *   Copyright (C) 2010 Daniel De Graaf <danieldg@inspircd.org>
  5.  *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
  6.  *   Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
  7.  *   Copyright (C) 2007 Craig Edwards <craigedwards@brainbox.cc>
  8.  *
  9.  * This file is part of InspIRCd.  InspIRCd is free software: you can
  10.  * redistribute it and/or modify it under the terms of the GNU General Public
  11.  * License as published by the Free Software Foundation, version 2.
  12.  *
  13.  * This program is distributed in the hope that it will be useful, but WITHOUT
  14.  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  15.  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
  16.  * details.
  17.  *
  18.  * You should have received a copy of the GNU General Public License
  19.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  20.  */
  21.  
  22.  
  23. #include "inspircd.h"
  24.  
  25. static void JoinChannels(LocalUser* u, const std::string& chanlist)
  26. {
  27.     irc::commasepstream chans(chanlist);
  28.     std::string chan;
  29.  
  30.     while (chans.GetToken(chan))
  31.     {
  32.         if (ServerInstance->IsChannel(chan.c_str(), ServerInstance->Config->Limits.ChanMax))
  33.         {
  34.             ServerInstance->Logs->Log("MODULE", DEBUG,"Joining channel: " + chan);
  35.             Channel::JoinUser(u, chan.c_str(), false, "", false, ServerInstance->Time());
  36.         }
  37.     }
  38. }
  39.  
  40. class JoinTimer : public Timer
  41. {
  42.  private:
  43.     LocalUser* const user;
  44.     const std::string channels;
  45.  
  46.  public:
  47.     JoinTimer(LocalUser* u, const std::string& chans, unsigned int delay)
  48.         : Timer(delay, ServerInstance->Time(), false)
  49.         , user(u), channels(chans)
  50.     {
  51.     }
  52.  
  53.     void Tick(time_t time)
  54.     {
  55.         ServerInstance->Logs->Log("MODULE", DEBUG,"autojoin loaded def channels: " + channels);
  56.         if (user->chans.empty())
  57.             JoinChannels(user, channels);
  58.     }
  59. };
  60.  
  61. class ModuleConnJoin : public Module
  62. {
  63.    
  64.  
  65.  public:
  66.     ModuleConnJoin()
  67.     {
  68.     }
  69.  
  70.     void init()
  71.     {
  72.         Implementation eventlist[] = { I_OnPostConnect };
  73.         ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
  74.         ServerInstance->Logs->Log("MODULE", DEBUG,"m_conn_join loaded");
  75.     }
  76.  
  77.     void Prioritize()
  78.     {
  79.         ServerInstance->Modules->SetPriority(this, I_OnPostConnect, PRIORITY_LAST);
  80.     }
  81.  
  82.     Version GetVersion()
  83.     {
  84.         return Version("Forces users to join the specified channel(s) on connect", VF_VENDOR);
  85.     }
  86.  
  87.     void OnPostConnect(User* user)
  88.     {
  89.         LocalUser* localuser = IS_LOCAL(user);
  90.         if (!localuser)
  91.             return;
  92.  
  93.         std::string defchans;
  94.         unsigned int defdelay;
  95.  
  96.         ConfigTag* tag = ServerInstance->Config->ConfValue("autojoin");
  97.         defchans = tag->getString("channel");
  98.         defdelay = tag->getInt("delay", 5);
  99.  
  100.         std::string chanlist = localuser->GetClass()->config->getString("autojoin");
  101.         unsigned int chandelay = localuser->GetClass()->config->getInt("autojoindelay", 5);
  102.  
  103.         if (chanlist.empty())
  104.         {
  105.             if (defchans.empty())
  106.                 return;
  107.             chanlist = defchans;
  108.             chandelay = defdelay;
  109.         }
  110.  
  111.         if (!chandelay)
  112.             JoinChannels(localuser, chanlist);
  113.         else
  114.         {
  115.             JoinTimer* t = new JoinTimer(localuser, chanlist, chandelay);
  116.             ServerInstance->Timers->AddTimer(t);
  117.         }
  118.     }
  119. };
  120.  
  121. MODULE_INIT(ModuleConnJoin)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement