moderation.cpp

Go to the documentation of this file.
00001 /*
00002 #########################################################################
00003 #
00004 #  This file is part of trustyRC.
00005 #
00006 #  trustyRC, fully modular IRC robot 
00007 #  Copyright (C) 2006-2008 Nicoleau Fabien 
00008 #
00009 #  trustyRC is free software: you can redistribute it and/or modify
00010 #  it under the terms of the GNU General Public License as published by
00011 #  the Free Software Foundation, either version 3 of the License, or
00012 #  (at your option) any later version.
00013 #
00014 #  trustyRC is distributed in the hope that it will be useful,
00015 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 #  GNU General Public License for more details.
00018 #
00019 #  You should have received a copy of the GNU General Public License
00020 #  along with trustyRC.  If not, see <http://www.gnu.org/licenses/>.
00021 #
00022 #########################################################################
00023 */
00024 
00029 #include "moderation.h"
00030 
00034 Moderation::Moderation(BotKernel*b)
00035 {
00036         this->author = "eponyme";
00037         this->description = "channels moderation";
00038         this->version = VERSION;
00039         this->name = "moderation";
00040         this->bindFunction("op",IN_COMMAND_HANDLER,"op",0,10);
00041         this->bindFunction("unop",IN_COMMAND_HANDLER,"unop",0,10);
00042         this->bindFunction("voice",IN_COMMAND_HANDLER,"voice",0,10);
00043         this->bindFunction("unvoice",IN_COMMAND_HANDLER,"unvoice",0,10);
00044         this->bindFunction("topic",IN_COMMAND_HANDLER,"topic",0,10);
00045         this->bindFunction("kick",IN_COMMAND_HANDLER,"kick",0,10);
00046         this->bindFunction("kickall",IN_COMMAND_HANDLER,"kickall",0,10);
00047         this->bindFunction("opall",IN_COMMAND_HANDLER,"opall",0,10);
00048         this->bindFunction("unopall",IN_COMMAND_HANDLER,"unopall",0,10);
00049         this->bindFunction("voiceall",IN_COMMAND_HANDLER,"voiceall",0,10);
00050         this->bindFunction("unvoiceall",IN_COMMAND_HANDLER,"unvoiceall",0,10);
00051         this->bindFunction("masskick",IN_COMMAND_HANDLER,"masskick",0,10);
00052         this->bindFunction("randomkick",IN_COMMAND_HANDLER,"randomKick",0,10);
00053         this->bindFunction("autoop",IN_COMMAND_HANDLER,"autoop",0,10);
00054         this->bindFunction("unautoop",IN_COMMAND_HANDLER,"unautoop",0,10);
00055         this->bindFunction("autovoice",IN_COMMAND_HANDLER,"autovoice",0,10);
00056         this->bindFunction("unautovoice",IN_COMMAND_HANDLER,"unautovoice",0,10);
00057         this->bindFunction("protecttopic",IN_COMMAND_HANDLER,"protecttopic",0,10);
00058         this->bindFunction("unprotecttopic",IN_COMMAND_HANDLER,"unprotecttopic",0,10);
00059         this->bindFunction("protectmodes",IN_COMMAND_HANDLER,"protectmodes",0,10);
00060         this->bindFunction("unprotectmodes",IN_COMMAND_HANDLER,"unprotectmodes",0,10);
00061         this->bindFunction("banmask",IN_COMMAND_HANDLER,"banmask",0,10);
00062         this->bindFunction("banlist",IN_COMMAND_HANDLER,"banlist",0,10);
00063         this->bindFunction("ban",IN_COMMAND_HANDLER,"ban",0,10);
00064         this->bindFunction("baninfos",IN_COMMAND_HANDLER,"baninfos",0,10);
00065         this->bindFunction("bandel",IN_COMMAND_HANDLER,"bandel",0,10);
00066         this->bindFunction("unbanall",IN_COMMAND_HANDLER,"unbanall",0,10);
00067         this->bindFunction("invite",IN_COMMAND_HANDLER,"invite",0,10);
00068         this->bindFunction("15",IN_LOOP,"clearOutBans",0,10);
00069         this->bindFunction("JOIN",IN_TYPE_HANDLER,"joinHandler",0,10);
00070         this->bindFunction("PART",IN_TYPE_HANDLER,"partHandler",0,10);
00071         this->bindFunction("QUIT",IN_TYPE_HANDLER,"quitHandler",0,10);
00072         this->bindFunction("KICK",IN_TYPE_HANDLER,"kickHandler",0,10);
00073         this->bindFunction("MODE",IN_TYPE_HANDLER,"modeHandler",0,10);
00074         this->bindFunction("MODE",IN_TYPE_HANDLER,"modeHandlerProtect",0,10);
00075         this->bindFunction("TOPIC",IN_TYPE_HANDLER,"topicHandler",0,10);
00076    this->bindFunction("474",IN_TYPE_HANDLER,"bannedHandler",0,10);
00077         this->bindFunction("332",IN_TYPE_HANDLER,"topicJoin",0,10);
00078    this->addRequirement("admin");
00079    this->addRequirement("usersinfos");
00080 
00081    this->doc = new TiXmlDocument(b->getDatasDir()+"moderation.xml");
00082    if ( this->doc->LoadFile() )
00083    {
00084       this->root = this->doc->FirstChild();
00085    }
00086    else
00087    {
00088       this->initFile();
00089    }
00090 }
00091 
00095 void Moderation::initFile()
00096 {
00097    TiXmlElement born("trustyrc_moderation");
00098    this->doc->InsertEndChild(born);
00099    this->root = this->doc->FirstChild();
00100    TiXmlElement bansNode("bans");
00101    this->root->InsertEndChild(bansNode);
00102    this->doc->SaveFile();
00103 }
00104 
00115 bool Moderation::addBan(string channel,string mask,unsigned int duration,string by,string reason)
00116 {
00117    if ( !this->isBanned(channel,mask) )
00118    {
00119       TiXmlElement * elemChan;
00120       TiXmlHandle docHandle (this->doc);
00121       TiXmlHandle bansHandle = docHandle.FirstChild("trustyrc_moderation").FirstChild("bans") ;
00122       elemChan = bansHandle.FirstChild(channel.substr(1)).Element() ;
00123       if(!elemChan) {
00124          TiXmlElement newChan(channel.substr(1));
00125          bansHandle.Element()->InsertEndChild(newChan);
00126          elemChan = bansHandle.FirstChild(channel.substr(1)).Element() ;
00127       }
00128       time_t now;
00129            time(&now);
00130            char date[17];
00131       TiXmlElement item("ban");
00132       item.SetAttribute("mask",mask);
00133       item.SetAttribute("timestamp",now);
00134            strftime(date,18,"%y-%m-%d %X",localtime(&now));
00135         item.SetAttribute("date",date);
00136       item.SetAttribute("duration",duration);
00137       item.SetAttribute("by",by);
00138       item.SetAttribute("reason",reason);
00139       elemChan->InsertEndChild(item);
00140       this->doc->SaveFile();
00141       return true;
00142    }
00143    return false;
00144 } 
00145 
00152 bool Moderation::isBanned(string channel,string mask)
00153 {
00154    TiXmlHandle docHandle (this->doc);
00155    TiXmlElement * elem;
00156    elem = docHandle.FirstChild("trustyrc_moderation").FirstChild("bans").FirstChild(channel.substr(1)).Element();
00157    if (elem) {
00158       for( elem=elem->FirstChildElement(); elem!=0; elem=elem->NextSiblingElement() ) {
00159                    if ( Tools::ircMaskMatch(mask,elem->Attribute("mask")) ) {
00160             return true;
00161          }
00162            }
00163       return false;
00164    }
00165    return false;
00166 }
00167 
00174 string Moderation::delBan(string channel,unsigned int index)
00175 {
00176    string mask = "";
00177    TiXmlHandle docHandle (this->doc);
00178    TiXmlNode * parent ;
00179    TiXmlElement * elem = docHandle.FirstChild("trustyrc_moderation").FirstChild("bans").FirstChild(channel.substr(1)).Child(index).Element() ;
00180    if ( elem ) {
00181       mask = elem->Attribute("mask");
00182       parent = elem->Parent();
00183       parent->RemoveChild(elem);
00184       if ( parent->FirstChild() == NULL ) {
00185          parent->Parent()->RemoveChild(parent);
00186       }
00187       this->doc->SaveFile();
00188       return mask;
00189    }
00190    return mask;
00191 }
00192 
00198 vector<string> Moderation::getBanList(string channel)
00199 {
00200    unsigned int i = 0 ;
00201    vector<string> back;
00202    TiXmlHandle docHandle (this->doc);
00203    TiXmlElement * elem = docHandle.FirstChild("trustyrc_moderation").FirstChild("bans").FirstChild(channel.substr(1)).Element();
00204    if (elem) {
00205       for( elem=elem->FirstChildElement(); elem!=0; elem=elem->NextSiblingElement() ) {
00206          back.push_back("#"+Tools::intToStr(i)+":"+elem->Attribute("mask") );
00207          i++;
00208            }
00209    }
00210    else {
00211       back.push_back("No bans for "+channel);
00212    }
00213    return back;
00214 }
00215 
00222 vector<string> Moderation::banInfos(string channel,unsigned int index)
00223 {
00224         char date[17];
00225    time_t futur;
00226    string endBan = "";
00227    vector<string> result;
00228    TiXmlHandle docHandle (this->doc);
00229    TiXmlElement * elem = docHandle.FirstChild("trustyrc_moderation").FirstChild("bans").FirstChild(channel.substr(1)).Child(index).Element() ;
00230    if ( elem ) {
00231       result.push_back(string(elem->Attribute("mask"))+" by " +string(elem->Attribute("by"))); 
00232       futur = Tools::strToInt(elem->Attribute("timestamp"))+Tools::strToInt(elem->Attribute("duration")) ;
00233       if ( futur > Tools::strToInt(elem->Attribute("timestamp")) ) {
00234          strftime(date,18,"%y-%m-%d %X",localtime(&futur));
00235          endBan = " to " +string(date) ;
00236       }
00237       else {
00238          endBan = " (permanent)" ;
00239       }
00240       result.push_back("on "+string(elem->Attribute("date"))+endBan+" : "+string(elem->Attribute("reason"))); 
00241    }
00242    else {
00243       result.push_back("nonexistent"); 
00244    }
00245    return(result);
00246 }
00247 
00255 vector<string> Moderation::clearList(string channel)
00256 {
00257    vector<string> deletedBans;
00258    deletedBans.clear();
00259    TiXmlNode * parent;
00260    TiXmlElement*chan,*elem;
00261    TiXmlHandle docHandle (this->doc);
00262    chan = docHandle.FirstChild("trustyrc_moderation").FirstChild("bans").FirstChild(channel.substr(1)).Element();
00263    if (chan) {
00264       parent = chan->Parent();
00265       for( elem=chan->FirstChildElement(); elem!=0; elem=elem->NextSiblingElement() ) {
00266          deletedBans.push_back(elem->Attribute("mask"));
00267            }
00268       parent->RemoveChild(chan);
00269       this->doc->SaveFile();
00270    }
00271    return deletedBans;
00272 }
00273 
00280 vector<string> Moderation::clearOutBans(vector<string> myChans)
00281 {
00282    time_t now;
00283    time(&now);
00284    bool deleted=false;
00285    vector<string> deletedBans;
00286    deletedBans.clear();
00287    TiXmlNode * parent;
00288    TiXmlHandle docHandle (this->doc);
00289    TiXmlElement * elem,* elem2;
00290    elem = docHandle.FirstChild("trustyrc_moderation").FirstChild("bans").Element();
00291    if (elem) {
00292       for( elem=elem->FirstChildElement(); elem!=0; elem=elem->NextSiblingElement() ) {
00293          if ( Tools::isInVector(myChans,elem->ValueStr()) )
00294          {
00295             for (elem2=elem->FirstChildElement();elem2!=0;elem2=elem2->NextSiblingElement()) {
00296                if ( ((string)elem2->Attribute("duration")!="0") && ((now - ((Tools::strToInt(elem2->Attribute("timestamp")))+(Tools::strToInt(elem2->Attribute("duration"))))) >= 0 ))  {
00297                   deletedBans.push_back(IRCProtocol::unban(elem2->Attribute("mask"),"#"+elem->ValueStr()));
00298                   elem->RemoveChild(elem2);
00299                   deleted=true;
00300                }
00301             }
00302             parent = elem->Parent();
00303             if ( elem->FirstChild() == NULL )  {
00304                parent->RemoveChild(elem) ;
00305                deleted=true;
00306             }
00307          }
00308            }
00309    }
00310    if(deleted) {
00311       this->doc->SaveFile();
00312    }
00313    return deletedBans;
00314 }
00315 
00325 bool Moderation::checkAccess(string channel,string mask,unsigned int level,BotKernel*b)
00326 {
00327    pPlugin * ppAdm = b->getPlugin("admin");
00328    Admin*adm = NULL;
00329    if ( ppAdm != NULL ) {
00330       adm = (Admin*)ppAdm->object ;
00331       if ( adm->getUserLevel(channel,mask) >= level ) {
00332          return true; 
00333       }
00334    } 
00335    return false; 
00336 }
00337 
00348 bool Moderation::hasOpPrivileges(string channel,string mask,string nick,BotKernel*b)
00349 {
00350    pPlugin * ppAdm = b->getPlugin("admin");
00351    pPlugin * ppUser = b->getPlugin("usersinfos");
00352    Admin*adm = NULL;
00353    UsersInfos*ui = NULL;
00354    if ( ppAdm != NULL ) {
00355       adm = (Admin*)ppAdm->object ;
00356       if ( adm->isSuperAdmin(mask) ) {
00357          return true; 
00358       }
00359       if ( adm->getUserLevel(channel,mask) >= 2 ) {
00360          return true; 
00361       }
00362    }  
00363    if ( ppUser != NULL ) {
00364       ui = (UsersInfos*)ppUser->object ;
00365       if (ui->hasMode(channel,nick,'o')) {
00366          return true;
00367       }
00368    }
00369    return false;
00370 }
00371 
00381 bool Moderation::checkMode(string channel,string nick,char mode,BotKernel*b)
00382 {
00383    pPlugin * ppUser = b->getPlugin("usersinfos");
00384    UsersInfos*ui = NULL;
00385    if ( ppUser != NULL ) {
00386       ui = (UsersInfos*)ppUser->object ;
00387       if (ui->hasMode(channel,nick,mode)) {
00388          return true;
00389       }
00390       else {
00391          return false;
00392       } 
00393    }
00394    return false;
00395 }
00396 
00409 vector<string*> Moderation::getChanUsersList(string channel,BotKernel*b)
00410 {
00411    map<string,Channel*>* users;
00412    vector<string*> list;
00413    map<string,Channel*>::iterator fter ;
00414    pPlugin * ppUser = b->getPlugin("usersinfos");
00415    UsersInfos*ui = NULL;
00416    if ( ppUser != NULL ) {
00417       ui = (UsersInfos*)ppUser->object ;
00418       users = ui->getUsers();
00419       fter = users->find(channel);
00420       if ( fter != users->end() ) {
00421          return ((Channel*)fter->second)->getUsers();
00422       }
00423    }
00424    return list;
00425 }
00426 
00432 unsigned int Moderation::getRejoinAttempts(string channel)
00433 {
00434         map<string,int>::iterator fter = this->rejoinAttempts.find(channel);
00435         if ( fter != this->rejoinAttempts.end() ) {
00436                 return fter->second ;
00437         }
00438         else {
00439                 return 0;
00440         }
00441 }
00442 
00447 void Moderation::bumpRejoinAttempts(string channel)
00448 {
00449         map<string,int>::iterator fter = this->rejoinAttempts.find(channel);
00450         if ( fter != this->rejoinAttempts.end() ) {
00451                 this->rejoinAttempts[channel] += 1 ;
00452         }
00453         else {
00454                 this->rejoinAttempts[channel] = 1 ;
00455         }
00456 }
00457 
00462 void Moderation::clearRejoinAttempts(string channel)
00463 {
00464         map<string,int>::iterator fter = this->rejoinAttempts.find(channel);
00465         if ( fter != this->rejoinAttempts.end() ) {
00466                 this->rejoinAttempts.erase(fter);
00467         }
00468 }
00469 
00470 extern "C"
00471 {
00472         Plugin *contruct_moderation(BotKernel*b)
00473         {
00474                 return new Moderation(b);
00475         }
00476         void destroy_moderation(Plugin*p)
00477         {
00478                 delete p;
00479         }
00480         bool unbanall (Message*m,Plugin*p,BotKernel*b)
00481    {
00482       Moderation*mod = (Moderation*)p;
00483       vector<string> bans;
00484       if (m->isPublic()) {
00485          if ( mod->hasOpPrivileges(m->getSource(),m->getSender(),m->getNickSender(),b)) {
00486             bans = mod->clearList(m->getSource()) ;
00487             b->send(IRCProtocol::applyModes(m->getSource(),bans,'-','b',4) ) ;
00488          }
00489       }
00490       return true;
00491    }
00492         bool bandel (Message*m,Plugin*p,BotKernel*b)
00493    {
00494       string mask = "";
00495       Moderation*mod = (Moderation*)p;
00496       if (m->isPublic() && (m->nbParts() == 5)) {
00497          if ( mod->hasOpPrivileges(m->getSource(),m->getSender(),m->getNickSender(),b)) {
00498             mask = mod->delBan(m->getSource(),Tools::strToInt(m->getPart(4)));
00499             if (mask!="") {
00500                b->send( IRCProtocol::unban(mask,m->getSource()) ) ;
00501             }
00502          }
00503       }
00504       return true;
00505    }
00506         bool baninfos (Message*m,Plugin*p,BotKernel*b)
00507    {
00508       Moderation*mod = (Moderation*)p;
00509       if (m->isPublic() && (m->nbParts() == 5)) {
00510          if ( mod->hasOpPrivileges(m->getSource(),m->getSender(),m->getNickSender(),b)) {
00511             b->send( IRCProtocol::sendNotices(m->getNickSender(),mod->banInfos(m->getSource(),Tools::strToInt(m->getPart(4)))) ) ;
00512          }
00513       }
00514       return true;
00515    }
00516         bool banlist (Message*m,Plugin*p,BotKernel*b)
00517    {
00518       Moderation*mod = (Moderation*)p;
00519       if (m->isPublic()) {
00520          if ( mod->hasOpPrivileges(m->getSource(),m->getSender(),m->getNickSender(),b)) {
00521             b->send( IRCProtocol::sendNotices(m->getNickSender(),Tools::gatherVectorElements(mod->getBanList(m->getSource())," ",3)) ) ;
00522          }
00523       }
00524       return true;
00525    }
00526         bool ban (Message*m,Plugin*p,BotKernel*b)
00527    {
00528       string mask,host;
00529       ConfigurationFile*cff = b->getCONFF();
00530       map<string,Channel*>* users;
00531       map<string,Channel*>::iterator fter ;
00532       vector<string> nicks;
00533       pPlugin * ppUser = b->getPlugin("usersinfos");
00534       UsersInfos*ui = NULL;
00535       Moderation*mod = (Moderation*)p;
00536       if ( ppUser != NULL )
00537       {
00538          ui = (UsersInfos*)ppUser->object;
00539          if (m->isPublic()) {
00540             if ( mod->hasOpPrivileges(m->getSource(),m->getSender(),m->getNickSender(),b)) {
00541                if ( (m->nbParts() >= 7) && (m->getPart(5).length() <= 9) ) {
00542                   users = ui->getUsers();
00543                   fter = users->find(m->getSource());
00544                   if ( fter != users->end() ) {
00545                      host = ((Channel*)fter->second)->getHostByNick(m->getPart(4)) ;
00546                      if (host != "" ) {
00547                         mask ="*!*@"+ host ;
00548                         mod->addBan(m->getSource(),mask,Tools::strtimeToSeconds(m->getPart(5)),m->getSender(),Tools::vectorToString(m->getSplit()," ",6));
00549                         b->send(IRCProtocol::ban(mask,m->getSource()));
00550                         if ( cff->getValue(p->getName()+".autokick") == "1" ) {
00551                            b->send(IRCProtocol::kick(m->getPart(4),m->getSource(),"["+m->getPart(5)+"]"+Tools::vectorToString(m->getSplit()," ",6)) ) ;
00552                         }
00553                      }
00554                   }
00555                }
00556             }
00557          }
00558       }
00559       return true;
00560    }   
00561         bool banmask (Message*m,Plugin*p,BotKernel*b)
00562    {
00563       ConfigurationFile*cff = b->getCONFF();
00564       vector<string> nicks;
00565       vector<string*> users;
00566       Moderation*mod = (Moderation*)p;
00567       if (m->isPublic()) {
00568          if ( mod->hasOpPrivileges(m->getSource(),m->getSender(),m->getNickSender(),b)) {
00569             if ( (m->nbParts() >= 7) && (m->getPart(5).length() <= 9) ) {
00570                mod->addBan(m->getSource(),m->getPart(4),Tools::strtimeToSeconds(m->getPart(5)),m->getSender(),Tools::vectorToString(m->getSplit()," ",6));
00571                b->send(IRCProtocol::ban(m->getPart(4),m->getSource()));
00572                if ( cff->getValue(p->getName()+".autokick") == "1" ) {
00573                   users = mod->getChanUsersList(m->getSource(),b);
00574                   for(unsigned int i = 0 ; i < users.size() ; i ++ ) {
00575                      if ( Tools::ircMaskMatch(users[i][0]+"!"+users[i][2]+"@"+users[i][1],m->getPart(4)) && (users[i][0]!=b->getNick()) ) {
00576                         b->send(IRCProtocol::kick(users[i][0],m->getSource(),"["+m->getPart(5)+"]"+Tools::vectorToString(m->getSplit()," ",6)) ) ;
00577                      }
00578                   }
00579                }
00580             }
00581          }
00582       }
00583       return true;
00584    }
00585         bool op (Message*m,Plugin*p,BotKernel*b)
00586    {
00587       vector<string> nicks;
00588       Moderation*mod = (Moderation*)p;
00589       if (m->isPublic()) {
00590          if ( mod->hasOpPrivileges(m->getSource(),m->getSender(),m->getNickSender(),b)) {
00591             if ( m->getSplit().size() >= 5 ) {
00592                for (unsigned int i = 4 ; i < m->getSplit().size(); i ++)
00593                                            nicks.push_back(m->getPart(i));
00594             }
00595             else {
00596                                    nicks.push_back(m->getNickSender());
00597                            }
00598             b->send(IRCProtocol::op(nicks,m->getSource()));
00599          }
00600       }
00601       return true;
00602    }
00603         bool unop (Message*m,Plugin*p,BotKernel*b)
00604    {
00605       vector<string> nicks;
00606       Moderation*mod = (Moderation*)p;
00607       if (m->isPublic()) {
00608          if ( mod->hasOpPrivileges(m->getSource(),m->getSender(),m->getNickSender(),b)) {
00609             if ( m->getSplit().size() >= 5 ) {
00610                for (unsigned int i = 4 ; i < m->getSplit().size(); i ++)
00611                   if ( m->getPart(i) != b->getNick() ) {
00612                                            nicks.push_back(m->getPart(i));
00613                   }
00614             }
00615             else {
00616                                 nicks.push_back(m->getNickSender());
00617                         }
00618             b->send(IRCProtocol::unop(nicks,m->getSource()));
00619          }
00620       }
00621       return true;
00622    }
00623         bool voice (Message*m,Plugin*p,BotKernel*b)
00624    {
00625       vector<string> nicks;
00626       Moderation*mod = (Moderation*)p;
00627       if (m->isPublic()) {
00628          if ( mod->hasOpPrivileges(m->getSource(),m->getSender(),m->getNickSender(),b)) {
00629             if ( m->getSplit().size() >= 5 ) {
00630                for (unsigned int i = 4 ; i < m->getSplit().size(); i ++)
00631                                         nicks.push_back(m->getPart(i));
00632             }
00633             else {
00634                                 nicks.push_back(m->getNickSender());
00635                         }
00636             b->send(IRCProtocol::voice(nicks,m->getSource()));
00637          }
00638       }
00639       return true;
00640    }
00641         bool unvoice (Message*m,Plugin*p,BotKernel*b)
00642    {
00643       vector<string> nicks;
00644       Moderation*mod = (Moderation*)p;
00645       if (m->isPublic()) {
00646          if ( mod->hasOpPrivileges(m->getSource(),m->getSender(),m->getNickSender(),b)) {
00647             if ( m->getSplit().size() >= 5 ) {
00648                for (unsigned int i = 4 ; i < m->getSplit().size(); i ++)
00649                                         nicks.push_back(m->getPart(i));
00650             }
00651             else {
00652                                 nicks.push_back(m->getNickSender());
00653                         }
00654             b->send(IRCProtocol::unvoice(nicks,m->getSource()));
00655          }
00656       }
00657       return true;
00658    }
00659         bool topic (Message*m,Plugin*p,BotKernel*b)
00660    {
00661       vector<string> nicks;
00662       Moderation*mod = (Moderation*)p;
00663       if (m->isPublic()) {
00664          if ( mod->hasOpPrivileges(m->getSource(),m->getSender(),m->getNickSender(),b)) {
00665             b->send(IRCProtocol::changeTopic(m->getSource(),Tools::vectorToString(m->getSplit()," ",4)));
00666          }
00667       }
00668       return true;
00669    }
00670         bool kick (Message*m,Plugin*p,BotKernel*b)
00671    {
00672       Moderation*mod = (Moderation*)p;
00673       if (m->isPublic()) {
00674          if ( (m->getSplit().size() > 4) && (m->getPart(4)!=b->getNick() )) {
00675             if ( mod->hasOpPrivileges(m->getSource(),m->getSender(),m->getNickSender(),b)) {
00676                b->send(IRCProtocol::kick(m->getPart(4),m->getSource(),Tools::vectorToString(m->getSplit()," ",5)));
00677             }
00678          }
00679       }
00680       return true;
00681    }
00682         bool masskick (Message*m,Plugin*p,BotKernel*b)
00683    {
00684       vector<string> kicks;
00685       Moderation*mod = (Moderation*)p;
00686       if (m->isPublic()) {
00687          if ( mod->hasOpPrivileges(m->getSource(),m->getSender(),m->getNickSender(),b)) {
00688             for (unsigned int i = 4 ; i < m->getSplit().size(); i ++) {
00689                if ( m->getPart(i) != b->getNick() )
00690                   kicks.push_back(IRCProtocol::kick(m->getPart(i),m->getSource(),"o/"));
00691             }
00692             b->getSysLog()->log("MASSKICK on "+m->getSource()+" (by "+m->getSender()+")",INFO);
00693             b->send(kicks);
00694          }
00695       }
00696       return true;
00697    }
00698         bool opall (Message*m,Plugin*p,BotKernel*b)
00699    {
00700       vector<string*> users;
00701       Moderation*mod = (Moderation*)p;
00702       vector<string> opers;
00703       if (m->isPublic()) {
00704          if ( mod->hasOpPrivileges(m->getSource(),m->getSender(),m->getNickSender(),b)) {
00705             users = mod->getChanUsersList(m->getSource(),b);
00706             for (unsigned int i = 0 ; i < users.size() ; i ++ ) {
00707                if (!mod->checkMode(m->getSource(),users[i][0],'o',b)) {
00708                   opers.push_back(users[i][0]);
00709                }
00710             }
00711             b->getSysLog()->log("OPALL on "+m->getSource()+" (by "+m->getSender()+")",INFO);
00712             b->send(IRCProtocol::op(opers,m->getSource()));
00713          }
00714       }
00715       return true;
00716    }
00717         bool unopall (Message*m,Plugin*p,BotKernel*b)
00718    {
00719       vector<string*> users;
00720       Moderation*mod = (Moderation*)p;
00721       vector<string> unopers;
00722       if (m->isPublic()) {
00723          if ( mod->hasOpPrivileges(m->getSource(),m->getSender(),m->getNickSender(),b)) {
00724             users = mod->getChanUsersList(m->getSource(),b);
00725             for (unsigned int i = 0 ; i < users.size() ; i ++ )
00726             {
00727                if ( (users[i][0] != b->getNick()) && (mod->checkMode(m->getSource(),users[i][0],'o',b)) ) {
00728                   unopers.push_back(users[i][0]);
00729                }
00730             }
00731             b->getSysLog()->log("UNOPALL on "+m->getSource()+" (by "+m->getSender()+")",INFO);
00732             b->send(IRCProtocol::unop(unopers,m->getSource()));
00733          }
00734       }
00735       return true;
00736    }
00737         bool voiceall (Message*m,Plugin*p,BotKernel*b)
00738    {
00739       vector<string*> users;
00740       Moderation*mod = (Moderation*)p;
00741       vector<string> voices;
00742       if (m->isPublic()) {
00743          if ( mod->hasOpPrivileges(m->getSource(),m->getSender(),m->getNickSender(),b)) {
00744             users = mod->getChanUsersList(m->getSource(),b);
00745             for (unsigned int i = 0 ; i < users.size() ; i ++ ) {
00746                if (!mod->checkMode(m->getSource(),users[i][0],'v',b)) {
00747                   voices.push_back(users[i][0]);
00748                }
00749             }
00750             b->getSysLog()->log("VOICEALL on "+m->getSource()+" (by "+m->getSender()+")",INFO);
00751             b->send(IRCProtocol::voice(voices,m->getSource()));
00752          }
00753       }
00754       return true;
00755    }
00756         bool unvoiceall (Message*m,Plugin*p,BotKernel*b)
00757    {
00758       vector<string*> users;
00759       Moderation*mod = (Moderation*)p;
00760       vector<string> unvoices;
00761       if (m->isPublic()) {
00762          if ( mod->hasOpPrivileges(m->getSource(),m->getSender(),m->getNickSender(),b)) {
00763             users = mod->getChanUsersList(m->getSource(),b);
00764             for (unsigned int i = 0 ; i < users.size() ; i ++ ) {
00765                if (mod->checkMode(m->getSource(),users[i][0],'v',b)) {
00766                   unvoices.push_back(users[i][0]);
00767                }
00768             }
00769             b->getSysLog()->log("UNVOICEALL on "+m->getSource()+" (by "+m->getSender()+")",INFO);
00770             b->send(IRCProtocol::unvoice(unvoices,m->getSource()));
00771          }
00772       }
00773       return true;
00774    }
00775         bool kickall (Message*m,Plugin*p,BotKernel*b)
00776    {
00777       vector<string*> users;
00778       vector<string> kickeds;
00779       Moderation*mod = (Moderation*)p;
00780       if (m->isPublic()) {
00781          if ( mod->hasOpPrivileges(m->getSource(),m->getSender(),m->getNickSender(),b)) {
00782             users = mod->getChanUsersList(m->getSource(),b);
00783             for (unsigned int i = 0 ; i < users.size() ; i ++ ) {
00784                if (users[i][0] != b->getNick()) {
00785                   kickeds.push_back(IRCProtocol::kick(users[i][0],m->getSource(),"o/"));
00786                }
00787             }
00788             b->getSysLog()->log("KICKALL on "+m->getSource()+" (by "+m->getSender()+")",INFO);
00789             b->send(kickeds);
00790          }
00791       }
00792       return true;
00793    }
00794         bool randomKick (Message*m,Plugin*p,BotKernel*b)
00795    {
00796       vector<string*> users;
00797       string nick;
00798       Moderation*mod = (Moderation*)p;
00799       if (m->isPublic()) {
00800          if ( mod->hasOpPrivileges(m->getSource(),m->getSender(),m->getNickSender(),b)) {
00801             users = mod->getChanUsersList(m->getSource(),b);
00802             b->getSysLog()->log("RANDOMKICK on "+m->getSource()+" (by "+m->getSender()+")",INFO);
00803             if (users.size() == 0 ) {
00804                b->send(IRCProtocol::sendMsg(m->getSource(),"* Unable to do it now *"));
00805                return true;
00806             }
00807             nick = users[Tools::random(0,users.size()-1)][0] ;
00808             if ( nick == b->getNick() ) {
00809                b->send(IRCProtocol::sendMsg(m->getSource(),"* It was on me !!!! *"));
00810                return true; 
00811             }
00812             b->send(IRCProtocol::kick(nick,m->getSource(),b->getCONFF()->getValue(p->getName()+".rdmkickmsg")));
00813          }
00814       }
00815       return true;
00816    }
00817         bool modeHandler (Message*m,Plugin*p,BotKernel*b)
00818    {
00819       ConfigurationFile*cff = b->getCONFF();
00820       map<string,Channel*>* users;
00821       map<string,Channel*>::iterator fter ;
00822       string*infos;
00823       string mask="";
00824       pPlugin * ppUser = b->getPlugin("usersinfos");
00825       pPlugin * ppAdm = b->getPlugin("admin");
00826       Admin*adm = NULL;
00827       UsersInfos*ui = NULL;
00828       if ((cff->getValue(p->getName()+".revenge")=="1")&&(ppAdm != NULL)&&(ppUser != NULL)&&(m->getNickSender()!=b->getNick()) ) {
00829          adm = (Admin*)ppAdm->object ;
00830          ui = (UsersInfos*)ppUser->object;
00831                    if ( (m->getSplit().size() > 4) && (adm->getUserLevel(m->getSource(),m->getSender())<2) && (!adm->isSuperAdmin(m->getSender())))
00832                    {
00833                       string modes = m->getPart(3) ;
00834                            char sign = '\0';
00835                            unsigned int nicksIndex = 4 ;
00836                            for (unsigned int i = 0 ; i < modes.length() ; i ++ ) {
00837                                 if ((modes[i]=='+')||(modes[i]=='-')) {
00838                                         sign = modes[i];
00839                                 }
00840                                 else {
00841                   users = ui->getUsers();
00842                   fter = users->find(m->getSource());
00843                   if ( fter != users->end() ) {
00844                      if ((sign=='-')&&((modes[i]=='v')||(modes[i]=='o'))) { 
00845                         infos = ((Channel*)fter->second)->getInfosByNick(m->getPart(nicksIndex));
00846                         if ( infos != NULL)
00847                         {
00848                            mask = infos[0]+"!"+infos[2]+"@"+infos[1] ;
00849                            if ( (modes[i]=='v') && (adm->isSuperAdmin(mask)||(adm->getUserLevel(m->getSource(),mask) >= 1)) ) {
00850                               b->send("MODE "+m->getSource()+" -o+v "+m->getNickSender()+" "+m->getPart(nicksIndex));
00851                            }
00852                            else if ((modes[i]=='o') && (adm->isSuperAdmin(mask)||(adm->getUserLevel(m->getSource(),mask) >= 2) )) {   
00853                               b->send("MODE "+m->getSource()+" -o+bo "+m->getNickSender()+" "+"*!*@"+m->getHostSender()+" "+m->getPart(nicksIndex));
00854                               b->send( IRCProtocol::kick(m->getNickSender(),m->getSource(),"Do not unop this user !")  );
00855                            }
00856                         }
00857                      }
00858                      else if (sign=='+'&&modes[i]=='b') {
00859                         mask = m->getPart(nicksIndex) ;
00860                         if ( adm->maskIsSuperAdmin(mask) || (adm->getMaskLevel(m->getSource(),mask) >= 2) ) {
00861                            b->send("MODE "+m->getSource()+" -ob+b "+m->getNickSender()+" "+mask+" "+"*!*@"+m->getHostSender());
00862                            b->send( IRCProtocol::kick(m->getNickSender(),m->getSource(),"Do not ban this user !")  );
00863                         }
00864                      }
00865                   }
00866                                         nicksIndex++;
00867                                 }
00868                            }
00869                    }
00870       }  
00871       return true;
00872    }
00873         bool modeHandlerProtect (Message*m,Plugin*p,BotKernel*b)
00874    {
00875       ConfigurationFile*cff = b->getCONFF();
00876                 Moderation*mod = (Moderation*)p;
00877       pPlugin * ppAdm = b->getPlugin("admin");
00878       pPlugin * ppUser = b->getPlugin("usersinfos");
00879       Admin*adm = NULL;
00880       UsersInfos*ui = NULL;
00881       string modes ;
00882       char sign;
00883                 if(Tools::isInVector(Tools::stringToVector(cff->getValue(p->getName()+".protectmodes"),",",0),m->getSource())) {
00884                 adm = (Admin*)ppAdm->object ;
00885          ui = (UsersInfos*)ppUser->object;
00886                         if ( (!adm->isSuperAdmin(m->getSender()))&&(!mod->checkAccess(m->getSource(),m->getSender(),2,b))&&(m->getNickSender()!=b->getNick()) ) {
00887             modes = m->getPart(3) ;
00888                            sign = '\0';
00889                            for (unsigned int i = 0 ; i < modes.length() ; i ++ ) {
00890                                 if ((modes[i]=='+')||(modes[i]=='-')) {
00891                                         sign = modes[i];
00892                                 }
00893                else {
00894                   if ( ((string)ui->getPrefixes()+"b").find(modes[i]) == string::npos ) {
00895                      if (sign=='+') {
00896                         b->send("MODE "+m->getSource()+" -"+modes[i]);
00897                      }
00898                      else if (sign=='-') {
00899                         b->send("MODE "+m->getSource()+" +"+modes[i]);
00900                      }
00901                   }   
00902                }
00903             }
00904                         }
00905                 }
00906       return true;
00907    }
00908         bool joinHandler (Message*m,Plugin*p,BotKernel*b)
00909    {
00910       Moderation * mod = (Moderation*)p;
00911       pPlugin * ppAdm = b->getPlugin("admin");
00912       Admin*adm = NULL;
00913       vector<string> nick;
00914       if (m->getNickSender()==b->getNick()) {
00915          mod->clearRejoinAttempts(m->getSource());
00916          return true;
00917       }
00918       if ( mod->isBanned(m->getSource(),m->getSender())) { // banned ?
00919          b->send(IRCProtocol::ban("*!*@"+m->getHostSender(),m->getSource())) ;
00920          b->send(IRCProtocol::kick(m->getNickSender(),m->getSource(),"You are banned from this channel"));
00921          return true;
00922       }
00923       if (Tools::isInVector(Tools::stringToVector(b->getCONFF()->getValue(p->getName()+".autoop"),",",0),m->getSource())) { // chan autotop ?
00924                 nick.push_back(m->getNickSender());
00925          b->send(IRCProtocol::op(nick,m->getSource()));
00926            }
00927       if (Tools::isInVector(Tools::stringToVector(b->getCONFF()->getValue(p->getName()+".autovoice"),",",0),m->getSource())) { // chan autovoice ?
00928                    nick.push_back(m->getNickSender());
00929            b->send(IRCProtocol::voice(nick,m->getSource()));
00930            }
00931       if ( ppAdm != NULL ) {
00932          adm = (Admin*)ppAdm->object ;
00933          if ( adm->getUserLevel(m->getSource(),m->getSender()) == 1 ) { // voice acces ?
00934             b->send(IRCProtocol::voice(m->getNickSender(),m->getSource()));
00935          }
00936          else if ( adm->getUserLevel(m->getSource(),m->getSender()) >= 2 ) { // op acces ?
00937             b->send(IRCProtocol::op(m->getNickSender(),m->getSource()));
00938          }
00939       }
00940       return true;
00941    }
00942         bool partHandler (Message*m,Plugin*p,BotKernel*b)
00943    {
00944       Moderation * mod = (Moderation*)p;
00945       map<string,Channel*>* users;
00946       map<string,Channel*>::iterator fter ;
00947       pPlugin * ppUser = b->getPlugin("usersinfos");
00948       UsersInfos*ui = NULL;
00949       if ( ppUser != NULL ) {
00950          ui = (UsersInfos*)ppUser->object ;
00951          users = ui->getUsers();
00952          fter = users->find(m->getSource());
00953          if ( fter != users->end() )
00954          {
00955             if ( (((Channel*)fter->second)->getUsers().size() == 1) && (!mod->checkMode(m->getSource(),b->getNick(),'o',b)))
00956             {
00957                b->send(IRCProtocol::leaveChannel(m->getSource(),"..."));
00958                b->send(IRCProtocol::joinChannel(m->getSource()));
00959             }
00960          }
00961       }
00962       return true;
00963    }
00964         bool quitHandler (Message*m,Plugin*p,BotKernel*b)
00965    {
00966       Moderation * mod = (Moderation*)p;
00967       map<string,Channel*>* users;
00968       pPlugin * ppUser = b->getPlugin("usersinfos");
00969       UsersInfos*ui = NULL;
00970       if ( ppUser != NULL ) {
00971          ui = (UsersInfos*)ppUser->object ;
00972          users = ui->getUsers();
00973          for (map<string,Channel*>::const_iterator iter = users->begin();iter!=users->end();++iter)
00974                    { 
00975             if ( (((Channel*)iter->second)->getUsers().size() == 1) && (!mod->checkMode(iter->first,b->getNick(),'o',b)))
00976             {
00977                b->send(IRCProtocol::leaveChannel(iter->first,"..."));
00978                b->send(IRCProtocol::joinChannel(iter->first));
00979             }
00980                    }
00981       }
00982       return true;
00983    }
00984         bool kickHandler (Message*m,Plugin*p,BotKernel*b)
00985    {
00986       ConfigurationFile*cff = b->getCONFF();
00987       Moderation * mod = (Moderation*)p;
00988       map<string,Channel*>* users;
00989       map<string,Channel*>::iterator fter ;
00990       string mask ="";
00991       pPlugin * ppUser = b->getPlugin("usersinfos");
00992       UsersInfos*ui = NULL;
00993       pPlugin * ppAdm = b->getPlugin("admin");
00994       Admin*adm = NULL;
00995       if( m->getPart(3) == b->getNick() )
00996       {
00997          if ( cff->getValue(p->getName()+".rejoin_when_kicked") == "1" ) {
00998             b->send(IRCProtocol::joinChannel(m->getSource()));
00999          }
01000          b->getSysLog()->log("Kicked from "+m->getSource()+" (by "+m->getSender()+")",INFO);
01001       }
01002       else
01003       {
01004          if ( ppUser != NULL ) {
01005             ui = (UsersInfos*)ppUser->object ;
01006             users = ui->getUsers();
01007             fter = users->find(m->getSource());
01008             if ( fter != users->end() )
01009             {
01010                if ( (((Channel*)fter->second)->getUsers().size() == 1) && (!mod->checkMode(m->getSource(),b->getNick(),'o',b)))
01011                {
01012                   b->send(IRCProtocol::leaveChannel(m->getSource(),"..."));
01013                   b->send(IRCProtocol::joinChannel(m->getSource()));
01014                }
01015                else if ((cff->getValue(p->getName()+".revenge")=="1")&&(ppAdm != NULL)&&( m->getNickSender() != b->getNick() )) {
01016                   adm = (Admin*)ppAdm->object ;
01017                   string*infos = ((Channel*)fter->second)->getInfosByNick(m->getPart(3));
01018                   if ((infos != NULL) && (adm->getUserLevel(m->getSource(),m->getSender())<2) && (!adm->isSuperAdmin(m->getSender())))
01019                   {
01020                      mask = infos[0]+"!"+infos[2]+"@"+infos[1] ;
01021                      if ((adm->isSuperAdmin(mask)||(adm->getUserLevel(m->getSource(),mask) >= 2))) {
01022                         b->send("MODE "+m->getSource()+" -o+b "+m->getNickSender()+" "+"*!*@"+m->getHostSender());
01023                         b->send( IRCProtocol::kick(m->getNickSender(),m->getSource(),"Do not kick this user !")  );
01024                      }
01025                   }
01026                }
01027             }
01028          }
01029       }
01030       return true;
01031    }
01032         bool autoop (Message*m,Plugin*p,BotKernel*b)
01033    {
01034       ConfigurationFile*cff = b->getCONFF();
01035       Moderation*mod = (Moderation*)p;
01036       if (m->isPublic()) {
01037          if ( mod->hasOpPrivileges(m->getSource(),m->getSender(),m->getNickSender(),b)) {
01038             if (!Tools::isInVector(Tools::stringToVector(b->getCONFF()->getValue(p->getName()+".autoop"),",",0),m->getSource())) {
01039                cff->setValue(p->getName()+".autoop",cff->getValue(p->getName()+".autoop")+","+m->getSource());
01040                b->send(IRCProtocol::sendMsg(m->getSource(),"done."));
01041             }
01042             else {
01043                b->send(IRCProtocol::sendMsg(m->getSource(),"already autoop"));
01044             }
01045          }
01046       }
01047       return true;
01048    }
01049         bool unautoop (Message*m,Plugin*p,BotKernel*b)
01050    {
01051       ConfigurationFile*cff = b->getCONFF();
01052       Moderation*mod = (Moderation*)p;
01053       vector<string> chans;
01054       if (m->isPublic()) {
01055          if ( mod->hasOpPrivileges(m->getSource(),m->getSender(),m->getNickSender(),b)) {
01056             if (Tools::isInVector(Tools::stringToVector(b->getCONFF()->getValue(p->getName()+".autoop"),",",0),m->getSource())) {
01057                chans = Tools::stringToVector(cff->getValue(p->getName()+".autoop"),",",0) ;
01058                Tools::delStrFromVector(&chans,m->getSource()) ;
01059                cff->setValue(p->getName()+".autoop",Tools::vectorToString(chans,",",0));
01060                b->send(IRCProtocol::sendMsg(m->getSource(),"done."));
01061             }
01062             else {
01063                b->send(IRCProtocol::sendMsg(m->getSource(),"not autoop"));
01064             }
01065          }
01066       }
01067       return true;
01068    }
01069         bool autovoice (Message*m,Plugin*p,BotKernel*b)
01070    {
01071       ConfigurationFile*cff = b->getCONFF();
01072       Moderation*mod = (Moderation*)p;
01073       if (m->isPublic()) {
01074          if ( mod->hasOpPrivileges(m->getSource(),m->getSender(),m->getNickSender(),b)) {
01075             if (!Tools::isInVector(Tools::stringToVector(b->getCONFF()->getValue(p->getName()+".autovoice"),",",0),m->getSource())) {
01076                cff->setValue(p->getName()+".autovoice",cff->getValue(p->getName()+".autovoice")+","+m->getSource());
01077                b->send(IRCProtocol::sendMsg(m->getSource(),"done."));
01078             }
01079             else {
01080                b->send(IRCProtocol::sendMsg(m->getSource(),"already autovoice"));
01081             }
01082          }
01083       }
01084       return true;
01085    }
01086         bool unautovoice (Message*m,Plugin*p,BotKernel*b)
01087    {
01088       ConfigurationFile*cff = b->getCONFF();
01089       Moderation*mod = (Moderation*)p;
01090       vector<string> chans;
01091       if (m->isPublic()) {
01092          if ( mod->hasOpPrivileges(m->getSource(),m->getSender(),m->getNickSender(),b)) {
01093             if (Tools::isInVector(Tools::stringToVector(b->getCONFF()->getValue(p->getName()+".autovoice"),",",0),m->getSource())) {
01094                chans = Tools::stringToVector(cff->getValue(p->getName()+".autovoice"),",",0) ;
01095                Tools::delStrFromVector(&chans,m->getSource()) ;
01096                cff->setValue(p->getName()+".autovoice",Tools::vectorToString(chans,",",0));
01097                b->send(IRCProtocol::sendMsg(m->getSource(),"done."));
01098             }
01099             else {
01100                b->send(IRCProtocol::sendMsg(m->getSource(),"not autovoice"));
01101             }
01102          }
01103       }
01104       return true;
01105    }
01106         bool protecttopic (Message*m,Plugin*p,BotKernel*b)
01107    {
01108       pPlugin * ppAdm = b->getPlugin("admin");
01109       Admin*adm = NULL;
01110       ConfigurationFile*cff = b->getCONFF();
01111       Moderation*mod = (Moderation*)p;
01112       if (m->isPublic()) {
01113                         adm = (Admin*)ppAdm->object ;
01114          if ((adm->isSuperAdmin(m->getSender()))||(mod->checkAccess(m->getSource(),m->getSender(),2,b))) {
01115             if (!Tools::isInVector(Tools::stringToVector(b->getCONFF()->getValue(p->getName()+".protecttopic"),",",0),m->getSource())) {
01116                cff->setValue(p->getName()+".protecttopic",cff->getValue(p->getName()+".protecttopic")+","+m->getSource());
01117                b->send(IRCProtocol::sendMsg(m->getSource(),"done."));
01118             }
01119             else {
01120                b->send(IRCProtocol::sendMsg(m->getSource(),"already protected"));
01121             }
01122          }
01123       }
01124       return true;
01125    }
01126         bool unprotecttopic (Message*m,Plugin*p,BotKernel*b)
01127    {
01128       pPlugin * ppAdm = b->getPlugin("admin");
01129       Admin*adm = NULL;
01130       ConfigurationFile*cff = b->getCONFF();
01131       Moderation*mod = (Moderation*)p;
01132       vector<string> chans;
01133       if (m->isPublic()) {
01134                         adm = (Admin*)ppAdm->object ;
01135          if ((adm->isSuperAdmin(m->getSender()))||(mod->checkAccess(m->getSource(),m->getSender(),2,b))) {
01136             if (Tools::isInVector(Tools::stringToVector(b->getCONFF()->getValue(p->getName()+".protecttopic"),",",0),m->getSource())) {
01137                chans = Tools::stringToVector(cff->getValue(p->getName()+".protecttopic"),",",0) ;
01138                Tools::delStrFromVector(&chans,m->getSource()) ;
01139                cff->setValue(p->getName()+".protecttopic",Tools::vectorToString(chans,",",0));
01140                b->send(IRCProtocol::sendMsg(m->getSource(),"done."));
01141             }
01142             else {
01143                b->send(IRCProtocol::sendMsg(m->getSource(),"not protected"));
01144             }
01145          }
01146       }
01147       return true;
01148    }
01150         bool protectmodes (Message*m,Plugin*p,BotKernel*b)
01151    {
01152       pPlugin * ppAdm = b->getPlugin("admin");
01153       Admin*adm = NULL;
01154       ConfigurationFile*cff = b->getCONFF();
01155       Moderation*mod = (Moderation*)p;
01156       if (m->isPublic()) {
01157                         adm = (Admin*)ppAdm->object ;
01158          if ((adm->isSuperAdmin(m->getSender()))||(mod->checkAccess(m->getSource(),m->getSender(),2,b))) {
01159             if (!Tools::isInVector(Tools::stringToVector(b->getCONFF()->getValue(p->getName()+".protectmodes"),",",0),m->getSource())) {
01160                cff->setValue(p->getName()+".protectmodes",cff->getValue(p->getName()+".protectmodes")+","+m->getSource());
01161                b->send(IRCProtocol::sendMsg(m->getSource(),"done."));
01162             }
01163             else {
01164                b->send(IRCProtocol::sendMsg(m->getSource(),"already protected"));
01165             }
01166          }
01167       }
01168       return true;
01169    }
01170         bool unprotectmodes (Message*m,Plugin*p,BotKernel*b)
01171    {
01172       pPlugin * ppAdm = b->getPlugin("admin");
01173       Admin*adm = NULL;
01174       ConfigurationFile*cff = b->getCONFF();
01175       Moderation*mod = (Moderation*)p;
01176       vector<string> chans;
01177       if (m->isPublic()) {
01178                         adm = (Admin*)ppAdm->object ;
01179          if ((adm->isSuperAdmin(m->getSender()))||(mod->checkAccess(m->getSource(),m->getSender(),2,b))) {
01180             if (Tools::isInVector(Tools::stringToVector(b->getCONFF()->getValue(p->getName()+".protectmodes"),",",0),m->getSource())) {
01181                chans = Tools::stringToVector(cff->getValue(p->getName()+".protectmodes"),",",0) ;
01182                Tools::delStrFromVector(&chans,m->getSource()) ;
01183                cff->setValue(p->getName()+".protectmodes",Tools::vectorToString(chans,",",0));
01184                b->send(IRCProtocol::sendMsg(m->getSource(),"done."));
01185             }
01186             else {
01187                b->send(IRCProtocol::sendMsg(m->getSource(),"not protected"));
01188             }
01189          }
01190       }
01191       return true;
01192    }
01194         bool clearOutBans (Message*m,Plugin*p,BotKernel*b)
01195    {
01196       pPlugin * ppUser = b->getPlugin("usersinfos");
01197       UsersInfos*ui = NULL;  
01198       Moderation*mod = (Moderation*)p;
01199       vector<string> bans,myChans;
01200       map<string,Channel*>::iterator it ;
01201       if ( ppUser != NULL ) {
01202          ui = (UsersInfos*)ppUser->object ;
01203          map<string,Channel*>* users = ui->getUsers();
01204          it = users->begin();
01205          while ( it != users->end() )
01206          {
01207             if (mod->checkMode((string)it->first,b->getNick(),'o',b)) {
01208                myChans.push_back(((string)it->first).substr(1)) ;
01209             }
01210             it++;
01211          }
01212          bans = mod->clearOutBans(myChans) ;
01213          for (unsigned int i = 0 ; i < bans.size() ; i ++ ) {
01214             b->send(bans[i]);
01215          } 
01216       }
01217       return true;
01218    }
01219         bool invite (Message*m,Plugin*p,BotKernel*b)
01220    {
01221       pPlugin * ppAdm = b->getPlugin("admin");
01222       Admin*adm = NULL;
01223       if ( (ppAdm != NULL) && m->isPrivate() && (m->nbParts() == 6) ) {
01224          adm = (Admin*)ppAdm->object ;
01225          if ( (adm->getUserLevel(m->getPart(5),m->getSender())>=2) || (adm->isSuperAdmin(m->getSender())) ) {
01226             b->send(IRCProtocol::invite(m->getPart(4),m->getPart(5))) ;
01227          }
01228       }
01229       return true;
01230    }
01231         bool rejoinChan (Message*m,Plugin*p,BotKernel*b)
01232    {
01233       Moderation*mod = (Moderation*)p;
01234                 ConfigurationFile * cf = b->getCONFF();
01235       string nbAttempts = cf->getValue(p->getName()+".rejoin_ban_attempts");
01236       if ( (nbAttempts == "") || (nbAttempts == "0") || (mod->getRejoinAttempts(m->getMessage())<Tools::strToUnsignedInt(nbAttempts)) ) {
01237          mod->bumpRejoinAttempts(m->getMessage());
01238          b->send(IRCProtocol::joinChannel(m->getMessage()));
01239       }
01240       else {
01241          b->getSysLog()->log("I'm banned from "+m->getMessage()+" and will no longer try to rejoin (did "+nbAttempts+" attempts)",WARNING); 
01242       }
01243       return true;
01244    }
01245         bool bannedHandler (Message*m,Plugin*p,BotKernel*b)
01246    {
01247       ConfigurationFile*cf = b->getCONFF();
01248       if ( cf->getValue(p->getName()+".rejoin_when_banned") == "1" ) {
01249          Message msg(m->getPart(3));
01250          if(b->addCountDown(p,rejoinChan,&msg,Tools::strToUnsignedInt(cf->getValue(p->getName()+".rejoin_ban_time")),5)==NULL) {
01251             b->getSysLog()->log("Couldn't launch chan rejoin after ban (max countdowns reached)",INFO);   
01252          }
01253       }
01254       return true;
01255    }
01256         bool topicJoin (Message*m,Plugin*p,BotKernel*b)
01257         {
01258       pPlugin * ppUser = b->getPlugin("usersinfos");
01259       UsersInfos*ui = NULL;  
01260       map<string,Channel*>::iterator it ;
01261       if ( ppUser != NULL ) {
01262          ui = (UsersInfos*)ppUser->object ;
01263          map<string,Channel*>* users = ui->getUsers();
01264         it = users->find(m->getPart(3));
01265         if ( it != users->end() ) {
01266                 ((Channel*)it->second)->setTopic(Tools::vectorToString(m->getSplit()," ",4).substr(1));
01267         }
01268       }
01269       return true;
01270         }
01271         bool topicHandler(Message*m,Plugin*p,BotKernel*b)
01272         {
01273       ConfigurationFile*cff = b->getCONFF();
01274                 Moderation*mod = (Moderation*)p;
01275       pPlugin * ppAdm = b->getPlugin("admin");
01276       Admin*adm = NULL;
01277       pPlugin * ppUser = b->getPlugin("usersinfos");
01278       UsersInfos*ui = NULL;  
01279       map<string,Channel*>::iterator it ;
01280                 if(Tools::isInVector(Tools::stringToVector(cff->getValue(p->getName()+".protecttopic"),",",0),m->getSource())) {
01281         if ( (ppUser != NULL)&&(ppAdm != NULL) ) {
01282                                 adm = (Admin*)ppAdm->object ;
01283                 ui = (UsersInfos*)ppUser->object ;
01284                                 if ( (!adm->isSuperAdmin(m->getSender()))&&(!mod->checkAccess(m->getSource(),m->getSender(),2,b))&&(m->getNickSender()!=b->getNick()) ) {
01285                         map<string,Channel*>* users = ui->getUsers();
01286                         it = users->find(m->getSource());
01287                         if ( it != users->end() ) {
01288                                                 b->send(IRCProtocol::changeTopic(m->getSource(),((Channel*)it->second)->getTopic()));
01289                         }
01290                                 }
01291                                 else {
01292                         map<string,Channel*>* users = ui->getUsers();
01293                         it = users->find(m->getSource());
01294                         if ( it != users->end() ) {
01295                                 ((Channel*)it->second)->setTopic(Tools::vectorToString(m->getSplit()," ",3).substr(1));
01296                         }
01297                                 }
01298         }
01299                 }
01300       return true;
01301         }
01302 }

Generated on Sun Aug 16 15:28:28 2009 for trustyRC by  doxygen 1.5.8