X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_operjoin.cpp;h=aa4e777729f596ce1c94fa657a1718bb2d13e21f;hb=66098d307c036997e51eaea21724615e27fdc3e9;hp=ee237f6359b930fa94f55213163418fd8b4d8a96;hpb=7272faf573f5240b87428c696a5960c7db6455c9;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_operjoin.cpp b/src/modules/m_operjoin.cpp index ee237f635..aa4e77772 100644 --- a/src/modules/m_operjoin.cpp +++ b/src/modules/m_operjoin.cpp @@ -6,21 +6,43 @@ using namespace std; #include "channels.h" #include "modules.h" #include "helperfuncs.h" +#include "inspircd.h" -/* $ModDesc: Forces opers to join a specified channel on oper-up */ +/* $ModDesc: Forces opers to join the specified channel(s) on oper-up */ + +extern InspIRCd* ServerInstance; class ModuleOperjoin : public Module { private: std::string operChan; ConfigReader* conf; - Server* Srv; + + + int tokenize(const string &str, std::vector &tokens) + { + // skip delimiters at beginning. + string::size_type lastPos = str.find_first_not_of(",", 0); + // find first "non-delimiter". + string::size_type pos = str.find_first_of(",", lastPos); + + while (string::npos != pos || string::npos != lastPos) + { + // found a token, add it to the vector. + tokens.push_back(str.substr(lastPos, pos - lastPos)); + // skip delimiters. Note the "not_of" + lastPos = str.find_first_not_of(",", pos); + // find next "non-delimiter" + pos = str.find_first_of(",", lastPos); + } + return tokens.size(); + } public: - ModuleOperjoin(Server* Me) + ModuleOperjoin(InspIRCd* Me) : Module::Module(Me) { - Srv = Me; + conf = new ConfigReader; operChan = conf->ReadValue("operjoin", "channel", 0); } @@ -30,15 +52,15 @@ class ModuleOperjoin : public Module List[I_OnPostOper] = List[I_OnRehash] = 1; } - virtual void OnRehash(std::string parameter) + virtual void OnRehash(const std::string ¶meter) { - delete conf; + DELETE(conf); conf = new ConfigReader; } virtual ~ModuleOperjoin() { - delete conf; + DELETE(conf); } virtual Version GetVersion() @@ -46,11 +68,14 @@ class ModuleOperjoin : public Module return Version(1,0,0,1,VF_VENDOR); } - virtual void OnPostOper(userrec* user, std::string opertype) + virtual void OnPostOper(userrec* user, const std::string &opertype) { if(operChan != "") { - Srv->JoinUserToChannel(user,operChan,""); + std::vector operChans; + tokenize(operChan,operChans); + for(std::vector::iterator it = operChans.begin(); it != operChans.end(); it++) + chanrec::JoinUser(ServerInstance, user, it->c_str(), false); } } @@ -60,22 +85,21 @@ class ModuleOperjoin : public Module class ModuleOperjoinFactory : public ModuleFactory { public: - ModuleOperjoinFactory() - { - } - - ~ModuleOperjoinFactory() - { - } - - virtual Module * CreateModule(Server* Me) - { - return new ModuleOperjoin(Me); - } + ModuleOperjoinFactory() + { + } + + ~ModuleOperjoinFactory() + { + } + + virtual Module * CreateModule(InspIRCd* Me) + { + return new ModuleOperjoin(Me); + } }; extern "C" void * init_module( void ) { - return new ModuleOperjoinFactory; + return new ModuleOperjoinFactory; } -