1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
19 /* $ModDesc: Forces users to join the specified channel(s) on connect */
21 class ModuleConnJoin : public Module
25 std::vector<std::string> Joinchans;
28 int tokenize(const string &str, std::vector<std::string> &tokens)
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);
35 while (string::npos != pos || string::npos != lastPos)
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);
48 ModuleConnJoin(InspIRCd* Me)
54 void Implements(char* List)
56 List[I_OnPostConnect] = List[I_OnRehash] = 1;
59 virtual void OnRehash(userrec* user, const std::string ¶meter)
61 ConfigReader* conf = new ConfigReader(ServerInstance);
62 JoinChan = conf->ReadValue("autojoin", "channel", 0);
64 if (!JoinChan.empty())
65 tokenize(JoinChan,Joinchans);
69 virtual ~ModuleConnJoin()
73 virtual Version GetVersion()
75 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
78 virtual void OnPostConnect(userrec* user)
83 for(std::vector<std::string>::iterator it = Joinchans.begin(); it != Joinchans.end(); it++)
84 if (ServerInstance->IsChannel(it->c_str()))
85 chanrec::JoinUser(ServerInstance, user, it->c_str(), false, "", ServerInstance->Time(true));
90 class ModuleConnJoinFactory : public ModuleFactory
93 ModuleConnJoinFactory()
97 ~ModuleConnJoinFactory()
101 virtual Module * CreateModule(InspIRCd* Me)
103 return new ModuleConnJoin(Me);
107 extern "C" void * init_module( void )
109 return new ModuleConnJoinFactory;