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