]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_conn_join.cpp
This properly fixes options:hidebans and options:hidesplits by providing the facility...
[user/henk/code/inspircd.git] / src / modules / m_conn_join.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 users to join the specified channel(s) on connect */
20
21 class ModuleConnJoin : public Module
22 {
23         private:
24                 std::string JoinChan;
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                 ModuleConnJoin(InspIRCd* Me)
49                         : Module::Module(Me)
50                 {
51                         conf = new ConfigReader(ServerInstance);
52                         JoinChan = conf->ReadValue("autojoin", "channel", 0);
53                 }
54
55                 void Implements(char* List)
56                 {
57                         List[I_OnPostConnect] = List[I_OnRehash] = 1;
58                 }
59
60                 virtual void OnRehash(userrec* user, const std::string &parameter)
61                 {
62                         DELETE(conf);
63                         conf = new ConfigReader(ServerInstance);
64                 }
65
66                 virtual ~ModuleConnJoin()
67                 {
68                         DELETE(conf);
69                 }
70
71                 virtual Version GetVersion()
72                 {
73                         return Version(1,1,0,1,VF_VENDOR,API_VERSION);
74                 }
75
76                 virtual void OnPostConnect(userrec* user)
77                 {
78                         if (!IS_LOCAL(user))
79                                 return;
80
81                         if (!JoinChan.empty())
82                         {
83                                 std::vector<std::string> Joinchans;
84                                 tokenize(JoinChan,Joinchans);
85                                 for(std::vector<std::string>::iterator it = Joinchans.begin(); it != Joinchans.end(); it++)
86                                         chanrec::JoinUser(ServerInstance, user, it->c_str(), false);
87                         }
88
89                 }
90
91 };
92
93 class ModuleConnJoinFactory : public ModuleFactory
94 {
95         public:
96                 ModuleConnJoinFactory()
97                 {
98                 }
99
100                 ~ModuleConnJoinFactory()
101                 {
102                 }
103
104                 virtual Module * CreateModule(InspIRCd* Me)
105                 {
106                         return new ModuleConnJoin(Me);
107                 }
108 };
109
110 extern "C" void * init_module( void )
111 {
112         return new ModuleConnJoinFactory;
113 }