1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
16 /* $ModDesc: Forces opers to join the specified channel(s) on oper-up */
18 class ModuleOperjoin : public Module
22 std::vector<std::string> operChans;
23 std::map<std::string, std::vector<std::string> > operTypeChans; // Channels specific to an oper type.
26 int tokenize(const std::string &str, std::vector<std::string> &tokens)
28 // skip delimiters at beginning.
29 std::string::size_type lastPos = str.find_first_not_of(",", 0);
30 // find first "non-delimiter".
31 std::string::size_type pos = str.find_first_of(",", lastPos);
33 while (std::string::npos != pos || std::string::npos != lastPos)
35 // found a token, add it to the vector.
36 tokens.push_back(str.substr(lastPos, pos - lastPos));
37 // skip delimiters. Note the "not_of"
38 lastPos = str.find_first_not_of(",", pos);
39 // find next "non-delimiter"
40 pos = str.find_first_of(",", lastPos);
48 Implementation eventlist[] = { I_OnPostOper, I_OnRehash };
49 ServerInstance->Modules->Attach(eventlist, this, 2);
53 virtual void OnRehash(User* user)
55 ConfigReader* conf = new ConfigReader;
57 operChan = conf->ReadValue("operjoin", "channel", 0);
58 override = conf->ReadFlag("operjoin", "override", "0", 0);
60 if (!operChan.empty())
61 tokenize(operChan,operChans);
63 std::map<std::string, std::vector<std::string> >().swap(operTypeChans);
65 int olines = conf->Enumerate("type");
66 for (int index = 0; index < olines; ++index)
68 std::string chanList = conf->ReadValue("type", "autojoin", index);
69 if (!chanList.empty())
71 tokenize(chanList, operTypeChans[conf->ReadValue("type", "name", index)]);
78 virtual ~ModuleOperjoin()
82 virtual Version GetVersion()
84 return Version("Forces opers to join the specified channel(s) on oper-up", VF_VENDOR, API_VERSION);
87 virtual void OnPostOper(User* user, const std::string &opertype, const std::string &opername)
92 for(std::vector<std::string>::iterator it = operChans.begin(); it != operChans.end(); it++)
93 if (ServerInstance->IsChannel(it->c_str(), ServerInstance->Config->Limits.ChanMax))
94 Channel::JoinUser(user, it->c_str(), override, "", false, ServerInstance->Time());
96 std::map<std::string, std::vector<std::string> >::iterator i = operTypeChans.find(user->oper);
98 if (i != operTypeChans.end())
100 const std::vector<std::string>& list = i->second;
101 for (std::vector<std::string>::const_iterator it = list.begin(); it != list.end(); ++it)
103 if (ServerInstance->IsChannel(it->c_str(), ServerInstance->Config->Limits.ChanMax))
105 Channel::JoinUser(user, it->c_str(), override, "", false, ServerInstance->Time());
113 MODULE_INIT(ModuleOperjoin)