]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_operjoin.cpp
Fix these to use new hook system (u_listmode wasnt fixed yet)
[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 "inspircd.h"
15
16 /* $ModDesc: Forces opers to join the specified channel(s) on oper-up */
17
18 class ModuleOperjoin : public Module
19 {
20         private:
21                 std::string operChan;
22                 std::vector<std::string> operChans;             
23
24                 int tokenize(const string &str, std::vector<std::string> &tokens)
25                 {
26                         // skip delimiters at beginning.
27                         string::size_type lastPos = str.find_first_not_of(",", 0);
28                         // find first "non-delimiter".
29                         string::size_type pos = str.find_first_of(",", lastPos);
30
31                         while (string::npos != pos || string::npos != lastPos)
32                         {
33                                 // found a token, add it to the vector.
34                                 tokens.push_back(str.substr(lastPos, pos - lastPos));
35                                 // skip delimiters. Note the "not_of"
36                                 lastPos = str.find_first_not_of(",", pos);
37                                 // find next "non-delimiter"
38                                 pos = str.find_first_of(",", lastPos);
39                         }
40                         return tokens.size();
41                 }
42
43         public:
44                 ModuleOperjoin(InspIRCd* Me) : Module(Me)
45                 {
46                         OnRehash(NULL, "");
47                 Implementation eventlist[] = { I_OnPostOper, I_OnRehash };
48                 ServerInstance->Modules->Attach(eventlist, this, 2);
49                 }
50
51                 void Implements(char* List)
52                 {
53                         List[I_OnPostOper] = List[I_OnRehash] = 1;
54                 }
55
56                 virtual void OnRehash(User* user, const std::string &parameter)
57                 {
58                         ConfigReader* conf = new ConfigReader(ServerInstance);
59
60                         operChan = conf->ReadValue("operjoin", "channel", 0);
61                         operChans.clear();
62                         if (!operChan.empty())
63                                 tokenize(operChan,operChans);
64
65                         delete conf;
66                 }
67
68                 virtual ~ModuleOperjoin()
69                 {
70                 }
71
72                 virtual Version GetVersion()
73                 {
74                         return Version(1,1,0,1,VF_VENDOR,API_VERSION);
75                 }
76
77                 virtual void OnPostOper(User* user, const std::string &opertype)
78                 {
79                         if (!IS_LOCAL(user))
80                                 return;
81
82                         for(std::vector<std::string>::iterator it = operChans.begin(); it != operChans.end(); it++)
83                                 if (ServerInstance->IsChannel(it->c_str()))
84                                         Channel::JoinUser(ServerInstance, user, it->c_str(), false, "", ServerInstance->Time(true));
85                 }
86
87 };
88
89 MODULE_INIT(ModuleOperjoin)