The InspIRCd Project
Home | Developers | Wiki | Forums | Bug Tracker | SVN | Download | Blog | Stats
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 #include "users.h"
00016 #include "channels.h"
00017 #include "modules.h"
00018 
00019 /* $ModDesc: Forces users to join the specified channel(s) on connect */
00020 
00021 class ModuleConnJoin : public Module
00022 {
00023         private:
00024                 std::string JoinChan;
00025                 std::vector<std::string> Joinchans;
00026                 
00027 
00028                 int tokenize(const string &str, std::vector<std::string> &tokens)
00029                 {
00030                         // skip delimiters at beginning.
00031                         string::size_type lastPos = str.find_first_not_of(",", 0);
00032                         // find first "non-delimiter".
00033                         string::size_type pos = str.find_first_of(",", lastPos);
00034 
00035                         while (string::npos != pos || string::npos != lastPos)
00036                         {
00037                                 // found a token, add it to the vector.
00038                                 tokens.push_back(str.substr(lastPos, pos - lastPos));
00039                                 // skip delimiters. Note the "not_of"
00040                                 lastPos = str.find_first_not_of(",", pos);
00041                                 // find next "non-delimiter"
00042                                 pos = str.find_first_of(",", lastPos);
00043                         }
00044                         return tokens.size();
00045                 }
00046 
00047         public:
00048                 ModuleConnJoin(InspIRCd* Me)
00049                         : Module(Me)
00050                 {
00051                         OnRehash(NULL, "");
00052                 }
00053 
00054                 Priority Prioritize()
00055                 {
00056                         return PRIORITY_LAST;
00057                 }
00058 
00059                 void Implements(char* List)
00060                 {
00061                         List[I_OnPostConnect] = List[I_OnRehash] = 1;
00062                 }
00063 
00064                 virtual void OnRehash(userrec* user, const std::string &parameter)
00065                 {
00066                         ConfigReader* conf = new ConfigReader(ServerInstance);
00067                         JoinChan = conf->ReadValue("autojoin", "channel", 0);
00068                         Joinchans.clear();
00069                         if (!JoinChan.empty())
00070                                 tokenize(JoinChan,Joinchans);
00071                         DELETE(conf);
00072                 }
00073 
00074                 virtual ~ModuleConnJoin()
00075                 {
00076                 }
00077 
00078                 virtual Version GetVersion()
00079                 {
00080                         return Version(1,1,0,1,VF_VENDOR,API_VERSION);
00081                 }
00082 
00083                 virtual void OnPostConnect(userrec* user)
00084                 {
00085                         if (!IS_LOCAL(user))
00086                                 return;
00087 
00088                         for(std::vector<std::string>::iterator it = Joinchans.begin(); it != Joinchans.end(); it++)
00089                                 if (ServerInstance->IsChannel(it->c_str()))
00090                                         chanrec::JoinUser(ServerInstance, user, it->c_str(), false, "", ServerInstance->Time(true));
00091                 }
00092 
00093 };
00094 
00095 
00096 MODULE_INIT(ModuleConnJoin)