]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_operjoin.cpp
4308068e3e83aaa57b2a36744282d183fbfc9bc4
[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 "users.h"
15 #include "channels.h"
16 #include "modules.h"
17 #include "inspircd.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                 ConfigReader* conf;
27                 
28
29                 int tokenize(const string &str, std::vector<std::string> &tokens)
30                 {
31                         // skip delimiters at beginning.
32                         string::size_type lastPos = str.find_first_not_of(",", 0);
33                         // find first "non-delimiter".
34                         string::size_type pos = str.find_first_of(",", lastPos);
35
36                         while (string::npos != pos || string::npos != lastPos)
37                         {
38                                 // found a token, add it to the vector.
39                                 tokens.push_back(str.substr(lastPos, pos - lastPos));
40                                 // skip delimiters. Note the "not_of"
41                                 lastPos = str.find_first_not_of(",", pos);
42                                 // find next "non-delimiter"
43                                 pos = str.find_first_of(",", lastPos);
44                         }
45                         return tokens.size();
46                 }
47
48         public:
49                 ModuleOperjoin(InspIRCd* Me)
50                         : Module::Module(Me)
51                 {
52                         
53                         conf = new ConfigReader(ServerInstance);
54                         operChan = conf->ReadValue("operjoin", "channel", 0);
55                         operChans.clear();
56                         if (!operChan.empty())
57                                 tokenize(operChan,operChans);
58                 }
59
60                 void Implements(char* List)
61                 {
62                         List[I_OnPostOper] = List[I_OnRehash] = 1;
63                 }
64
65                 virtual void OnRehash(userrec* user, const std::string &parameter)
66                 {
67                         DELETE(conf);
68                         conf = new ConfigReader(ServerInstance);
69                         operChan = conf->ReadValue("operjoin", "channel", 0);
70                         operChans.clear();
71                         if (!operChan.empty())
72                                 tokenize(operChan,operChans);
73                 }
74
75                 virtual ~ModuleOperjoin()
76                 {
77                         DELETE(conf);
78                 }
79
80                 virtual Version GetVersion()
81                 {
82                         return Version(1,1,0,1,VF_VENDOR,API_VERSION);
83                 }
84
85                 virtual void OnPostOper(userrec* user, const std::string &opertype)
86                 {
87                         if (!IS_LOCAL(user))
88                                 return;
89
90                         for(std::vector<std::string>::iterator it = operChans.begin(); it != operChans.end(); it++)
91                                 if (ServerInstance->IsChannel(it->c_str()))
92                                         chanrec::JoinUser(ServerInstance, user, it->c_str(), false, "");
93                 }
94
95 };
96
97 class ModuleOperjoinFactory : public ModuleFactory
98 {
99         public:
100                 ModuleOperjoinFactory()
101                 {
102                 }
103
104                 ~ModuleOperjoinFactory()
105                 {
106                 }
107
108                 virtual Module * CreateModule(InspIRCd* Me)
109                 {
110                         return new ModuleOperjoin(Me);
111                 }
112 };
113
114 extern "C" void * init_module( void )
115 {
116         return new ModuleOperjoinFactory;
117 }