00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "inspircd.h"
00015
00016
00017
00018 class ModuleOperjoin : public Module
00019 {
00020 private:
00021 std::string operChan;
00022 std::vector<std::string> operChans;
00023 std::map<std::string, std::vector<std::string> > operTypeChans;
00024 bool override;
00025
00026 int tokenize(const std::string &str, std::vector<std::string> &tokens)
00027 {
00028
00029 std::string::size_type lastPos = str.find_first_not_of(",", 0);
00030
00031 std::string::size_type pos = str.find_first_of(",", lastPos);
00032
00033 while (std::string::npos != pos || std::string::npos != lastPos)
00034 {
00035
00036 tokens.push_back(str.substr(lastPos, pos - lastPos));
00037
00038 lastPos = str.find_first_not_of(",", pos);
00039
00040 pos = str.find_first_of(",", lastPos);
00041 }
00042 return tokens.size();
00043 }
00044
00045 public:
00046 ModuleOperjoin(InspIRCd* Me) : Module(Me)
00047 {
00048 OnRehash(NULL, "");
00049 Implementation eventlist[] = { I_OnPostOper, I_OnRehash };
00050 ServerInstance->Modules->Attach(eventlist, this, 2);
00051 }
00052
00053
00054 virtual void OnRehash(User* user, const std::string ¶meter)
00055 {
00056 ConfigReader* conf = new ConfigReader(ServerInstance);
00057
00058 operChan = conf->ReadValue("operjoin", "channel", 0);
00059 override = conf->ReadFlag("operjoin", "override", "0", 0);
00060 operChans.clear();
00061 if (!operChan.empty())
00062 tokenize(operChan,operChans);
00063
00064 std::map<std::string, std::vector<std::string> >().swap(operTypeChans);
00065
00066 int olines = conf->Enumerate("type");
00067 for (int index = 0; index < olines; ++index)
00068 {
00069 std::string chanList = conf->ReadValue("type", "autojoin", index);
00070 if (!chanList.empty())
00071 {
00072 tokenize(chanList, operTypeChans[conf->ReadValue("type", "name", index)]);
00073 }
00074 }
00075
00076 delete conf;
00077 }
00078
00079 virtual ~ModuleOperjoin()
00080 {
00081 }
00082
00083 virtual Version GetVersion()
00084 {
00085 return Version("$Id: m_operjoin.cpp 10291 2008-08-25 20:35:51Z w00t $", VF_VENDOR, API_VERSION);
00086 }
00087
00088 virtual void OnPostOper(User* user, const std::string &opertype, const std::string &opername)
00089 {
00090 if (!IS_LOCAL(user))
00091 return;
00092
00093 for(std::vector<std::string>::iterator it = operChans.begin(); it != operChans.end(); it++)
00094 if (ServerInstance->IsChannel(it->c_str(), ServerInstance->Config->Limits.ChanMax))
00095 Channel::JoinUser(ServerInstance, user, it->c_str(), override, "", false, ServerInstance->Time());
00096
00097 std::map<std::string, std::vector<std::string> >::iterator i = operTypeChans.find(user->oper);
00098
00099 if (i != operTypeChans.end())
00100 {
00101 const std::vector<std::string>& list = i->second;
00102 for (std::vector<std::string>::const_iterator it = list.begin(); it != list.end(); ++it)
00103 {
00104 if (ServerInstance->IsChannel(it->c_str(), ServerInstance->Config->Limits.ChanMax))
00105 {
00106 Channel::JoinUser(ServerInstance, user, it->c_str(), override, "", false, ServerInstance->Time());
00107 }
00108 }
00109 }
00110 }
00111
00112 };
00113
00114 MODULE_INIT(ModuleOperjoin)