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