ping.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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 }