]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_operjoin.cpp
52901fe6fcab85e9e75a923a847de6b813fde65e
[user/henk/code/inspircd.git] / src / modules / m_operjoin.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2010 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/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
16 /* $ModDesc: Forces opers to join the specified channel(s) on oper-up */
17
18 class ModuleOperjoin : public Module
19 {
20         private:
21                 std::string operChan;
22                 std::vector<std::string> operChans;
23                 bool override;
24
25                 int tokenize(const std::string &str, std::vector<std::string> &tokens)
26                 {
27                         // skip delimiters at beginning.
28                         std::string::size_type lastPos = str.find_first_not_of(",", 0);
29                         // find first "non-delimiter".
30                         std::string::size_type pos = str.find_first_of(",", lastPos);
31
32                         while (std::string::npos != pos || std::string::npos != lastPos)
33                         {
34                                 // found a token, add it to the vector.
35                                 tokens.push_back(str.substr(lastPos, pos - lastPos));
36                                 // skip delimiters. Note the "not_of"
37                                 lastPos = str.find_first_not_of(",", pos);
38                                 // find next "non-delimiter"
39                                 pos = str.find_first_of(",", lastPos);
40                         }
41                         return tokens.size();
42                 }
43
44         public:
45                 ModuleOperjoin()
46                 {
47                         OnRehash(NULL);
48                         Implementation eventlist[] = { I_OnPostOper, I_OnRehash };
49                         ServerInstance->Modules->Attach(eventlist, this, 2);
50                 }
51
52
53                 virtual void OnRehash(User* user)
54                 {
55                         ConfigReader conf;
56
57                         operChan = conf.ReadValue("operjoin", "channel", 0);
58                         override = conf.ReadFlag("operjoin", "override", "0", 0);
59                         operChans.clear();
60                         if (!operChan.empty())
61                                 tokenize(operChan,operChans);
62                 }
63
64                 virtual ~ModuleOperjoin()
65                 {
66                 }
67
68                 virtual Version GetVersion()
69                 {
70                         return Version("Forces opers to join the specified channel(s) on oper-up", VF_VENDOR);
71                 }
72
73                 virtual void OnPostOper(User* user, const std::string &opertype, const std::string &opername)
74                 {
75                         if (!IS_LOCAL(user))
76                                 return;
77
78                         for(std::vector<std::string>::iterator it = operChans.begin(); it != operChans.end(); it++)
79                                 if (ServerInstance->IsChannel(it->c_str(), ServerInstance->Config->Limits.ChanMax))
80                                         Channel::JoinUser(user, it->c_str(), override, "", false, ServerInstance->Time());
81
82                         std::string chanList = IS_OPER(user)->getConfig("autojoin");
83                         if (!chanList.empty())
84                         {
85                                 std::vector<std::string> typechans;
86                                 tokenize(chanList, typechans);
87                                 for (std::vector<std::string>::const_iterator it = typechans.begin(); it != typechans.end(); ++it)
88                                 {
89                                         if (ServerInstance->IsChannel(it->c_str(), ServerInstance->Config->Limits.ChanMax))
90                                         {
91                                                 Channel::JoinUser(user, it->c_str(), override, "", false, ServerInstance->Time());
92                                         }
93                                 }
94                         }
95                 }
96 };
97
98 MODULE_INIT(ModuleOperjoin)