]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_operjoin.cpp
d12bc193225bbade732b1dc028bc40cf77ceb86b
[user/henk/code/inspircd.git] / src / modules / m_operjoin.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15 #include "users.h"
16 #include "channels.h"
17 #include "modules.h"
18
19 /* $ModDesc: Forces opers to join the specified channel(s) on oper-up */
20
21 class ModuleOperjoin : public Module
22 {
23         private:
24                 std::string operChan;
25                 std::vector<std::string> operChans;             
26
27                 int tokenize(const string &str, std::vector<std::string> &tokens)
28                 {
29                         // skip delimiters at beginning.
30                         string::size_type lastPos = str.find_first_not_of(",", 0);
31                         // find first "non-delimiter".
32                         string::size_type pos = str.find_first_of(",", lastPos);
33
34                         while (string::npos != pos || string::npos != lastPos)
35                         {
36                                 // found a token, add it to the vector.
37                                 tokens.push_back(str.substr(lastPos, pos - lastPos));
38                                 // skip delimiters. Note the "not_of"
39                                 lastPos = str.find_first_not_of(",", pos);
40                                 // find next "non-delimiter"
41                                 pos = str.find_first_of(",", lastPos);
42                         }
43                         return tokens.size();
44                 }
45
46         public:
47                 ModuleOperjoin(InspIRCd* Me) : Module(Me)
48                 {
49                         OnRehash(NULL, "");
50                 }
51
52                 void Implements(char* List)
53                 {
54                         List[I_OnPostOper] = List[I_OnRehash] = 1;
55                 }
56
57                 virtual void OnRehash(userrec* user, const std::string &parameter)
58                 {
59                         ConfigReader* conf = new ConfigReader(ServerInstance);
60
61                         operChan = conf->ReadValue("operjoin", "channel", 0);
62                         operChans.clear();
63                         if (!operChan.empty())
64                                 tokenize(operChan,operChans);
65
66                         DELETE(conf);
67                 }
68
69                 virtual ~ModuleOperjoin()
70                 {
71                 }
72
73                 virtual Version GetVersion()
74                 {
75                         return Version(1,1,0,1,VF_VENDOR,API_VERSION);
76                 }
77
78                 virtual void OnPostOper(userrec* user, const std::string &opertype)
79                 {
80                         if (!IS_LOCAL(user))
81                                 return;
82
83                         for(std::vector<std::string>::iterator it = operChans.begin(); it != operChans.end(); it++)
84                                 if (ServerInstance->IsChannel(it->c_str()))
85                                         chanrec::JoinUser(ServerInstance, user, it->c_str(), false, "", ServerInstance->Time(true));
86                 }
87
88 };
89
90 MODULE_INIT(ModuleOperjoin)