The InspIRCd Project
Home | Developers | Wiki | Forums | Bug Tracker | SVN | Download
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

m_conn_join.cpp

Go to the documentation of this file.
00001 /*       +------------------------------------+
00002  *       | Inspire Internet Relay Chat Daemon |
00003  *       +------------------------------------+
00004  *
00005  *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
00006  * See: http://www.inspircd.org/wiki/index.php/Credits
00007  *
00008  * This program is free but copyrighted software; see
00009  *            the file COPYING for details.
00010  *
00011  * ---------------------------------------------------
00012  */
00013 
00014 #include "inspircd.h"
00015 
00016 /* $ModDesc: Forces users to join the specified channel(s) on connect */
00017 
00018 class ModuleConnJoin : public Module
00019 {
00020         private:
00021                 std::string JoinChan;
00022                 std::vector<std::string> Joinchans;
00023 
00024 
00025                 int tokenize(const std::string &str, std::vector<std::string> &tokens)
00026                 {
00027                         // skip delimiters at beginning.
00028                         std::string::size_type lastPos = str.find_first_not_of(",", 0);
00029                         // find first "non-delimiter".
00030                         std::string::size_type pos = str.find_first_of(",", lastPos);
00031 
00032                         while (std::string::npos != pos || std::string::npos != lastPos)
00033                         {
00034                                 // found a token, add it to the vector.
00035                                 tokens.push_back(str.substr(lastPos, pos - lastPos));
00036                                 // skip delimiters. Note the "not_of"
00037                                 lastPos = str.find_first_not_of(",", pos);
00038                                 // find next "non-delimiter"
00039                                 pos = str.find_first_of(",", lastPos);
00040                         }
00041                         return tokens.size();
00042                 }
00043 
00044         public:
00045                 ModuleConnJoin(InspIRCd* Me)
00046                         : Module(Me)
00047                 {
00048                         OnRehash(NULL, "");
00049                         Implementation eventlist[] = { I_OnPostConnect, I_OnRehash };
00050                         ServerInstance->Modules->Attach(eventlist, this, 2);
00051                 }
00052 
00053                 void Prioritize()
00054                 {
00055                         ServerInstance->Modules->SetPriority(this, I_OnPostConnect, PRIO_LAST);
00056                 }
00057 
00058 
00059                 virtual void OnRehash(User* user, const std::string &parameter)
00060                 {
00061                         ConfigReader* conf = new ConfigReader(ServerInstance);
00062                         JoinChan = conf->ReadValue("autojoin", "channel", 0);
00063                         Joinchans.clear();
00064                         if (!JoinChan.empty())
00065                                 tokenize(JoinChan,Joinchans);
00066                         delete conf;
00067                 }
00068 
00069                 virtual ~ModuleConnJoin()
00070                 {
00071                 }
00072 
00073                 virtual Version GetVersion()
00074                 {
00075                         return Version("$Id: m_conn_join.cpp 10291 2008-08-25 20:35:51Z w00t $", VF_VENDOR,API_VERSION);
00076                 }
00077 
00078                 virtual void OnPostConnect(User* user)
00079                 {
00080                         if (!IS_LOCAL(user))
00081                                 return;
00082 
00083                         for(std::vector<std::string>::iterator it = Joinchans.begin(); it != Joinchans.end(); it++)
00084                                 if (ServerInstance->IsChannel(it->c_str(), ServerInstance->Config->Limits.ChanMax))
00085                                         Channel::JoinUser(ServerInstance, user, it->c_str(), false, "", false, ServerInstance->Time());
00086                 }
00087 
00088 };
00089 
00090 
00091 MODULE_INIT(ModuleConnJoin)