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