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