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);
46 ModuleOperjoin(InspIRCd* Me) : Module(Me)
49 Implementation eventlist[] = { I_OnPostOper, I_OnRehash };
50 ServerInstance->Modules->Attach(eventlist, this, 2);
54 virtual void OnRehash(User* user)
56 ConfigReader* conf = new ConfigReader(ServerInstance);
58 operChan = conf->ReadValue("operjoin", "channel", 0);
59 override = conf->ReadFlag("operjoin", "override", "0", 0);
61 if (!operChan.empty())
62 tokenize(operChan,operChans);
64 std::map<std::string, std::vector<std::string> >().swap(operTypeChans);
66 int olines = conf->Enumerate("type");
67 for (int index = 0; index < olines; ++index)
69 std::string chanList = conf->ReadValue("type", "autojoin", index);
70 if (!chanList.empty())
72 tokenize(chanList, operTypeChans[conf->ReadValue("type", "name", index)]);
79 virtual ~ModuleOperjoin()
83 virtual Version GetVersion()
85 return Version("$Id$", VF_VENDOR, API_VERSION);
88 virtual void OnPostOper(User* user, const std::string &opertype, const std::string &opername)
93 for(std::vector<std::string>::iterator it = operChans.begin(); it != operChans.end(); it++)
94 if (ServerInstance->IsChannel(it->c_str(), ServerInstance->Config->Limits.ChanMax))
95 Channel::JoinUser(ServerInstance, user, it->c_str(), override, "", false, ServerInstance->Time());
97 std::map<std::string, std::vector<std::string> >::iterator i = operTypeChans.find(user->oper);
99 if (i != operTypeChans.end())
101 const std::vector<std::string>& list = i->second;
102 for (std::vector<std::string>::const_iterator it = list.begin(); it != list.end(); ++it)
104 if (ServerInstance->IsChannel(it->c_str(), ServerInstance->Config->Limits.ChanMax))
106 Channel::JoinUser(ServerInstance, user, it->c_str(), override, "", false, ServerInstance->Time());
114 MODULE_INIT(ModuleOperjoin)