ping.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 "ping.h"
00030 
00034 Ping::Ping(BotKernel*b)
00035 {
00036         this->author = "eponyme";
00037         this->description = "Make the bot answer \"pong\" to \"ping\" message";
00038         this->version = VERSION;
00039         this->name = "ping";
00040    time_t now;
00041    time(&now);
00042         this->bindFunction("PING",IN_FIRST_WORD,"pinged",0,10);
00043         this->bindFunction("120",IN_LOOP,"checkConnection",(now),10);
00044         this->bindFunction("PONG",IN_TYPE_HANDLER,"pongMe",0,10);
00045    this->setPonged(true);
00046 }
00047 
00052 void Ping::setPonged(bool value)
00053 {
00054    this->ponged = value;
00055 }
00056 
00061 bool Ping::getPonged()
00062 {
00063    return this->ponged ;
00064 }
00065 
00066 extern "C"
00067 {
00068         Plugin *contruct_ping(BotKernel*b)
00069         {
00070                 return new Ping(b);
00071         }
00072         void destroy_ping(Plugin*p)
00073         {
00074                 delete p;
00075         }
00076         bool pinged (Message*m,Plugin*p,BotKernel*b)
00077         {
00078         b->send(IRCProtocol::pong(m->getPart(1).substr(1))) ;
00079                 return true;
00080         }
00081         bool checkConnection(Message*m,Plugin*p,BotKernel*b)
00082         {
00083       Ping* ping = (Ping*)p;
00084       if (ping->getPonged() == false) {
00085          b->getSysLog()->log("Disconnected (ping timed out)",WARNING);
00086          ping->setPonged(true);
00087          b->setConnected(false);
00088       }  
00089       else
00090       {
00091          ping->setPonged(false);
00092          b->send( IRCProtocol::ping(b->getNick()) );
00093       }
00094                 return true;
00095         }
00096         bool pongMe(Message*m,Plugin*p,BotKernel*b)
00097         {
00098       Ping* ping = (Ping*)p;
00099       ping->setPonged(true);
00100                 return true;
00101         }
00102 }

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