]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_operjoin.cpp
Release 2.0.13
[user/henk/code/inspircd.git] / src / modules / m_operjoin.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
5  *   Copyright (C) 2008 Thomas Stagner <aquanight@inspircd.org>
6  *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
7  *   Copyright (C) 2005-2007 Robin Burchell <robin+git@viroteck.net>
8  *   Copyright (C) 2006-2007 Craig Edwards <craigedwards@brainbox.cc>
9  *   Copyright (C) 2004 Christopher Hall <typobox43@gmail.com>
10  *
11  * This file is part of InspIRCd.  InspIRCd is free software: you can
12  * redistribute it and/or modify it under the terms of the GNU General Public
13  * License as published by the Free Software Foundation, version 2.
14  *
15  * This program is distributed in the hope that it will be useful, but WITHOUT
16  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22  */
23
24
25 #include "inspircd.h"
26
27 /* $ModDesc: Forces opers to join the specified channel(s) on oper-up */
28
29 class ModuleOperjoin : public Module
30 {
31         private:
32                 std::string operChan;
33                 std::vector<std::string> operChans;
34                 bool override;
35
36                 int tokenize(const std::string &str, std::vector<std::string> &tokens)
37                 {
38                         // skip delimiters at beginning.
39                         std::string::size_type lastPos = str.find_first_not_of(",", 0);
40                         // find first "non-delimiter".
41                         std::string::size_type pos = str.find_first_of(",", lastPos);
42
43                         while (std::string::npos != pos || std::string::npos != lastPos)
44                         {
45                                 // found a token, add it to the vector.
46                                 tokens.push_back(str.substr(lastPos, pos - lastPos));
47                                 // skip delimiters. Note the "not_of"
48                                 lastPos = str.find_first_not_of(",", pos);
49                                 // find next "non-delimiter"
50                                 pos = str.find_first_of(",", lastPos);
51                         }
52                         return tokens.size();
53                 }
54
55         public:
56                 void init()
57                 {
58                         OnRehash(NULL);
59                         Implementation eventlist[] = { I_OnPostOper, I_OnRehash };
60                         ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
61                 }
62
63
64                 virtual void OnRehash(User* user)
65                 {
66                         ConfigTag* tag = ServerInstance->Config->ConfValue("operjoin");
67
68                         operChan = tag->getString("channel");
69                         override = tag->getBool("override", false);
70                         operChans.clear();
71                         if (!operChan.empty())
72                                 tokenize(operChan,operChans);
73                 }
74
75                 virtual ~ModuleOperjoin()
76                 {
77                 }
78
79                 virtual Version GetVersion()
80                 {
81                         return Version("Forces opers to join the specified channel(s) on oper-up", VF_VENDOR);
82                 }
83
84                 virtual void OnPostOper(User* user, const std::string &opertype, const std::string &opername)
85                 {
86                         if (!IS_LOCAL(user))
87                                 return;
88
89                         for(std::vector<std::string>::iterator it = operChans.begin(); it != operChans.end(); it++)
90                                 if (ServerInstance->IsChannel(it->c_str(), ServerInstance->Config->Limits.ChanMax))
91                                         Channel::JoinUser(user, it->c_str(), override, "", false, ServerInstance->Time());
92
93                         std::string chanList = IS_OPER(user)->getConfig("autojoin");
94                         if (!chanList.empty())
95                         {
96                                 std::vector<std::string> typechans;
97                                 tokenize(chanList, typechans);
98                                 for (std::vector<std::string>::const_iterator it = typechans.begin(); it != typechans.end(); ++it)
99                                 {
100                                         if (ServerInstance->IsChannel(it->c_str(), ServerInstance->Config->Limits.ChanMax))
101                                         {
102                                                 Channel::JoinUser(user, it->c_str(), override, "", false, ServerInstance->Time());
103                                         }
104                                 }
105                         }
106                 }
107 };
108
109 MODULE_INIT(ModuleOperjoin)