Advertisement
Guest User

Untitled

a guest
Jun 27th, 2015
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.11 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. /* $ModDesc: Forces users to join the specified channel(s) on connect */
  26.  
  27. static void JoinChannels(const std::string& uuid, const std::string& chanlist)
  28. {
  29.     User* user = ServerInstance->FindUUID(uuid);
  30.     if(!user || !user->chans.empty())
  31.         return;
  32.  
  33.     irc::commasepstream chans(chanlist);
  34.     std::string chan;
  35.  
  36.     while (chans.GetToken(chan))
  37.     {
  38.         if (ServerInstance->IsChannel(chan.c_str(), ServerInstance->Config->Limits.ChanMax))
  39.             Channel::JoinUser(user, chan.c_str(), false, "", false, ServerInstance->Time());
  40.     }
  41. }
  42.  
  43. class JoinTimer : public Timer
  44. {
  45. private:
  46.     std::string uuid;
  47.     const std::string channels;
  48.  
  49. public:
  50.     JoinTimer(const std::string& u, const std::string& chans, unsigned int delay)
  51.         : Timer(delay, ServerInstance->Time(), false)
  52.         , uuid(u), channels(chans)
  53.     {
  54.     }
  55.  
  56.     virtual void Tick(time_t time)
  57.     {
  58.         JoinChannels(uuid, channels);
  59.     }
  60. };
  61.  
  62. class ModuleConnJoin : public Module
  63. {
  64.     public:
  65.         void init()
  66.         {
  67.             Implementation eventlist[] = { I_OnPostConnect };
  68.             ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
  69.         }
  70.  
  71.         void Prioritize()
  72.         {
  73.             ServerInstance->Modules->SetPriority(this, I_OnPostConnect, PRIORITY_LAST);
  74.         }
  75.  
  76.         Version GetVersion()
  77.         {
  78.             return Version("Forces users to join the specified channel(s) on connect", VF_VENDOR);
  79.         }
  80.  
  81.         void OnPostConnect(User* user)
  82.         {
  83.             LocalUser* localuser = IS_LOCAL(user);
  84.             if (!localuser)
  85.                 return;
  86.  
  87.             ConfigTag* tag = ServerInstance->Config->ConfValue("autojoin");
  88.            
  89.             std::string defchans = tag->getString("channel");
  90.             std::string chanlist = localuser->GetClass()->config->getString("autojoin");
  91.            
  92.             unsigned int defdelay = tag->getInt("delay", 0);
  93.             unsigned int chandelay = localuser->GetClass()->config->getInt("autojoindelay", 0);
  94.  
  95.            
  96.             if(chanlist.empty())
  97.             {
  98.                 if (defchans.empty())
  99.                     return;
  100.                 chanlist = defchans;
  101.                 chandelay = defdelay;
  102.             }  
  103.            
  104.             if(!chandelay)
  105.                 JoinChannels(localuser->uuid, chanlist);
  106.             else
  107.             {
  108.                 JoinTimer* JT = new JoinTimer(localuser->uuid, chanlist, chandelay);   
  109.                 ServerInstance->Timers->AddTimer(JT);
  110.             }
  111.         }
  112. };
  113.  
  114.  
  115. MODULE_INIT(ModuleConnJoin)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement