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 * ---------------------------------------------------
16 /* $ModDesc: Forces users to join the specified channel(s) on connect */
18 class ModuleConnJoin : public Module
22 std::vector<std::string> Joinchans;
25 int tokenize(const string &str, std::vector<std::string> &tokens)
27 // skip delimiters at beginning.
28 string::size_type lastPos = str.find_first_not_of(",", 0);
29 // find first "non-delimiter".
30 string::size_type pos = str.find_first_of(",", lastPos);
32 while (string::npos != pos || string::npos != lastPos)
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);
45 ModuleConnJoin(InspIRCd* Me)
49 Implementation eventlist[] = { I_OnPostConnect, I_OnRehash };
50 ServerInstance->Modules->Attach(eventlist, this, 2);
55 ServerInstance->Modules->SetPriority(this, I_OnPostConnect, PRIO_LAST);
58 void Implements(char* List)
60 List[I_OnPostConnect] = List[I_OnRehash] = 1;
63 virtual void OnRehash(User* user, const std::string ¶meter)
65 ConfigReader* conf = new ConfigReader(ServerInstance);
66 JoinChan = conf->ReadValue("autojoin", "channel", 0);
68 if (!JoinChan.empty())
69 tokenize(JoinChan,Joinchans);
73 virtual ~ModuleConnJoin()
77 virtual Version GetVersion()
79 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
82 virtual void OnPostConnect(User* user)
87 for(std::vector<std::string>::iterator it = Joinchans.begin(); it != Joinchans.end(); it++)
88 if (ServerInstance->IsChannel(it->c_str()))
89 Channel::JoinUser(ServerInstance, user, it->c_str(), false, "", ServerInstance->Time(true));
95 MODULE_INIT(ModuleConnJoin)