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_operjoin.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 opers to join the specified channel(s) on oper-up */
00020 
00021 class ModuleOperjoin : public Module
00022 {
00023         private:
00024                 std::string operChan;
00025                 std::vector<std::string> operChans;
00026                 bool override;
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                 ModuleOperjoin(InspIRCd* Me) : Module(Me)
00049                 {
00050                         OnRehash(NULL, "");
00051                 }
00052 
00053                 void Implements(char* List)
00054                 {
00055                         List[I_OnPostOper] = List[I_OnRehash] = 1;
00056                 }
00057 
00058                 virtual void OnRehash(userrec* user, const std::string &parameter)
00059                 {
00060                         ConfigReader* conf = new ConfigReader(ServerInstance);
00061     
00062                         operChan = conf->ReadValue("operjoin", "channel", 0);
00063                         override = conf->ReadFlag("operjoin", "override", "0", 0);
00064                         operChans.clear();
00065                         if (!operChan.empty())
00066                                 tokenize(operChan,operChans);
00067 
00068                         DELETE(conf);
00069                 }
00070 
00071                 virtual ~ModuleOperjoin()
00072                 {
00073                 }
00074 
00075                 virtual Version GetVersion()
00076                 {
00077                         return Version(1,1,0,1,VF_VENDOR,API_VERSION);
00078                 }
00079 
00080                 virtual void OnPostOper(userrec* user, const std::string &opertype)
00081                 {
00082                         if (!IS_LOCAL(user))
00083                                 return;
00084 
00085                         for(std::vector<std::string>::iterator it = operChans.begin(); it != operChans.end(); it++)
00086                                 if (ServerInstance->IsChannel(it->c_str()))
00087                                         chanrec::JoinUser(ServerInstance, user, it->c_str(), override, "", ServerInstance->Time(true));
00088                 }
00089 
00090 };
00091 
00092 MODULE_INIT(ModuleOperjoin)