antiflood.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 "antiflood.h"
00030 
00034 AntiFlood::AntiFlood(BotKernel*b)
00035 {
00036         this->author = "eponyme";
00037         this->description = "antiflood plugin";
00038         this->version = VERSION;
00039         this->name = "antiflood";
00040         this->bindFunction("",IN_BEFORE_TREATMENT,"testMsgTimestamp",0,10);
00041    this->addRequirement("admin");
00042 }
00043 
00044 extern "C"
00045 {
00046         Plugin *contruct_antiflood(BotKernel*b)
00047         {
00048                 return new AntiFlood(b);
00049         }
00050         void destroy_antiflood(Plugin*p)
00051         {
00052                 delete p;
00053         }
00054         bool testMsgTimestamp (Message*m,Plugin*p,BotKernel*b)
00055         {
00056       pPlugin * ppAdm = b->getPlugin("admin");
00057       Admin*adm = NULL;
00058       if (ppAdm!=NULL) {
00059          adm = (Admin*)ppAdm->object ;
00060          string maxtime = b->getCONFF()->getValue(p->getName()+".maxtime");
00061          if ( (m->getPart(1) == "PRIVMSG") && (maxtime != "") && (maxtime != "0") && (m->getElapsedTime()>Tools::strToInt(maxtime)) ) {
00062             if ( ( b->getCONFF()->getValue(p->getName()+".allowsa") == "1") &&  adm->isSuperAdmin(m->getSender()) ) {
00063                return true;            
00064             }
00065             else {
00066                return false;
00067             }
00068          }
00069       }
00070                 return true;
00071         }
00072 }

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