]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_conn_join.cpp
Remove InspIRCd* parameters and fields
[user/henk/code/inspircd.git] / src / modules / m_conn_join.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/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 users to join the specified channel(s) on connect */
17
18 class ModuleConnJoin : public Module
19 {
20         private:
21                 std::string JoinChan;
22                 std::vector<std::string> Joinchans;
23
24
25                 int tokenize(const std::string &str, std::vector<std::string> &tokens)
26                 {
27                         // skip delimiters at beginning.
28                         std::string::size_type lastPos = str.find_first_not_of(",", 0);
29                         // find first "non-delimiter".
30                         std::string::size_type pos = str.find_first_of(",", lastPos);
31
32                         while (std::string::npos != pos || std::string::npos != lastPos)
33                         {
34                                 // found a token, add it to the vector.
35                                 tokens.push_back(str.substr(lastPos, pos - lastPos));
36                                 // skip delimiters. Note the "not_of"
37                                 lastPos = str.find_first_not_of(",", pos);
38                                 // find next "non-delimiter"
39                                 pos = str.find_first_of(",", lastPos);
40                         }
41                         return tokens.size();
42                 }
43
44         public:
45                 ModuleConnJoin()
46                                         {
47                         OnRehash(NULL);
48                         Implementation eventlist[] = { I_OnPostConnect, I_OnRehash };
49                         ServerInstance->Modules->Attach(eventlist, this, 2);
50                 }
51
52                 void Prioritize()
53                 {
54                         ServerInstance->Modules->SetPriority(this, I_OnPostConnect, PRIORITY_LAST);
55                 }
56
57
58                 virtual void OnRehash(User* user)
59                 {
60                         ConfigReader* conf = new ConfigReader;
61                         JoinChan = conf->ReadValue("autojoin", "channel", 0);
62                         Joinchans.clear();
63                         if (!JoinChan.empty())
64                                 tokenize(JoinChan,Joinchans);
65                         delete conf;
66                 }
67
68                 virtual ~ModuleConnJoin()
69                 {
70                 }
71
72                 virtual Version GetVersion()
73                 {
74                         return Version("Forces users to join the specified channel(s) on connect", VF_VENDOR,API_VERSION);
75                 }
76
77                 virtual void OnPostConnect(User* user)
78                 {
79                         if (!IS_LOCAL(user))
80                                 return;
81
82                         for(std::vector<std::string>::iterator it = Joinchans.begin(); it != Joinchans.end(); it++)
83                                 if (ServerInstance->IsChannel(it->c_str(), ServerInstance->Config->Limits.ChanMax))
84                                         Channel::JoinUser(user, it->c_str(), false, "", false, ServerInstance->Time());
85                 }
86
87 };
88
89
90 MODULE_INIT(ModuleConnJoin)