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