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 "postconnect.h"
00030
00034 PostConnect::PostConnect(BotKernel*b)
00035 {
00036 this->author = "eponyme";
00037 this->description = "Auto actions performed after server connection";
00038 this->version = VERSION;
00039 this->name = "postconnect";
00040 this->bindFunction("376",IN_TYPE_HANDLER,"onEndOfMOTD",0,40);
00041 this->bindFunction("422",IN_TYPE_HANDLER,"onEndOfMOTD",0,40);
00042 this->bindFunction("433",IN_TYPE_HANDLER,"secondaryNick",0,10);
00043 this->bindFunction("NICK",IN_TYPE_HANDLER,"nick_changed",0,10);
00044 this->resetNickRetreiveAttempts();
00045 }
00046
00051 unsigned int PostConnect::getNickRetreiveAttempts()
00052 {
00053 return this->nickRetreiveAttempts;
00054 }
00055
00059 void PostConnect::bumpNickRetreiveAttempts()
00060 {
00061 this->nickRetreiveAttempts += 1 ;
00062 }
00063
00067 void PostConnect::resetNickRetreiveAttempts()
00068 {
00069 this->nickRetreiveAttempts = 0 ;
00070 }
00071
00072 extern "C"
00073 {
00074 Plugin *contruct_postconnect(BotKernel*b)
00075 {
00076 return new PostConnect(b);
00077 }
00078 void destroy_postconnect(Plugin*p)
00079 {
00080 delete p;
00081 }
00082 bool nick_changed(Message*m,Plugin*p,BotKernel*b)
00083 {
00084 PostConnect * pc = (PostConnect*) p;
00085 if ( m->getPart(2).substr(1) == b->getNick() ) {
00086 pc->resetNickRetreiveAttempts() ;
00087 }
00088 return true;
00089 }
00090 bool getMyFirstNick(Message*m,Plugin*p,BotKernel*b)
00091 {
00092 PostConnect * pc = (PostConnect*) p;
00093 pc->bumpNickRetreiveAttempts() ;
00094 ConfigurationFile * cf = b->getCONFF();
00095 string nbAttempts = cf->getValue(p->getName()+".retreive_nick_attempts");
00096 if ( (nbAttempts == "") || (nbAttempts == "0") || (pc->getNickRetreiveAttempts()<=Tools::strToUnsignedInt(nbAttempts)) ) {
00097 b->setNick(cf->getValue("kernel.nick"));
00098 b->send(IRCProtocol::changeNick(cf->getValue("kernel.nick")));
00099 }
00100 else {
00101 b->setNick(cf->getValue("kernel.nick2"));
00102 }
00103 return true;
00104 }
00105 bool secondaryNick(Message*m,Plugin*p,BotKernel*b)
00106 {
00107 ConfigurationFile * cf = b->getCONFF();
00108 b->getSysLog()->log("Nick "+cf->getValue("kernel.nick")+" already in use",INFO);
00109 b->setNick(cf->getValue("kernel.nick2"));
00110 b->send(IRCProtocol::changeNick(cf->getValue("kernel.nick2")));
00111 if ( cf->getValue(p->getName()+".retreive_nick") == "1" ) {
00112 if(b->addCountDown(p,getMyFirstNick,m,Tools::strToUnsignedInt(cf->getValue(p->getName()+".retreive_nick_time")),5)==NULL) {
00113 b->getSysLog()->log("Couldn't launch nick take back (max countdowns reached)",INFO);
00114 }
00115 }
00116 return true;
00117 }
00118 bool onEndOfMOTD(Message*m,Plugin*p,BotKernel*b)
00119 {
00120 vector<string> temp ;
00121 ConfigurationFile * cf = b->getCONFF();
00122 if ( cf->getValue(p->getName()+".qauth") != "")
00123 {
00124 temp = Tools::stringToVector(cf->getValue(p->getName()+".qauth"),",",0);
00125 if (temp.size() == 2 ) {
00126 b->getSysLog()->log("QAUTH",INFO);
00127 b->send("PRIVMSG Q@CServe.quakenet.org :AUTH "+ temp[0] +" "+ temp[1]);
00128 }
00129 else
00130 b->getSysLog()->log("Wrong QAUTH value : "+cf->getValue(p->getName()+".qauth"),WARNING);
00131 }
00132 else if ( cf->getValue(p->getName()+".qauthx") != "")
00133 {
00134 temp = Tools::stringToVector(cf->getValue(p->getName()+".qauthx"),",",0);
00135 if (temp.size() == 2 ) {
00136 b->getSysLog()->log("QAUTH, MODE +x",INFO);
00137 b->send("PRIVMSG Q@CServe.quakenet.org :AUTH "+ temp[0] +" "+ temp[1]);
00138 b->send("MODE "+ b->getNick()+ " +x");
00139 }
00140 else
00141 b->getSysLog()->log("Wrong QAUTHX value : "+cf->getValue(p->getName()+".qauthx"),WARNING);
00142 }
00143 if ( cf->getValue(p->getName()+".uauth") != "")
00144 {
00145 temp = Tools::stringToVector(cf->getValue(p->getName()+".uauth"),",",0);
00146 if (temp.size() == 2 ) {
00147 b->getSysLog()->log("UAUTH",INFO);
00148 b->send("PRIVMSG X@channels.undernet.org :LOGIN "+ temp[0] +" "+ temp[1]);
00149 }
00150 else
00151 b->getSysLog()->log("Wrong UAUTH value : "+cf->getValue(p->getName()+".uauth"),WARNING);
00152 }
00153 else if ( cf->getValue(p->getName()+".uauthx") != "")
00154 {
00155 temp = Tools::stringToVector(cf->getValue(p->getName()+".uauthx"),",",0);
00156 if (temp.size() == 2 ) {
00157 b->getSysLog()->log("UAUTH, MODE +x",INFO);
00158 b->send("PRIVMSG X@channels.undernet.org :LOGIN "+ temp[0] +" "+ temp[1]);
00159 b->send("MODE "+ b->getNick() + " +x");
00160 }
00161 else
00162 b->getSysLog()->log("Wrong UAUTHX value : "+cf->getValue(p->getName()+".uauthx"),WARNING);
00163 }
00164 if ( cf->getValue(p->getName()+".nsauth") != "")
00165 {
00166 b->getSysLog()->log("NSAUTH",INFO);
00167 b->send("PRIVMSG NickServ :IDENTIFY "+ cf->getValue(p->getName()+".nsauth"));
00168 }
00169 temp = Tools::stringToVector(cf->getValue(p->getName()+".raw"),",",0);
00170 for ( unsigned int i = 0 ; i < temp.size() ; i ++ ) {
00171 b->getSysLog()->log("Executing raw action : " + temp[i],INFO);
00172 b->send(temp[i]);
00173 }
00174 sleep(Tools::strToInt(cf->getValue(p->getName()+".sleep")));
00175 temp = Tools::gatherVectorElements(Tools::stringToVector(cf->getValue(p->getName()+".join"),",",0),",",4);
00176 for ( unsigned int i = 0 ; i < temp.size() ; i ++ ) {
00177 b->getSysLog()->log("Going to join " + temp[i],INFO);
00178 b->send(IRCProtocol::joinChannel(temp[i]));
00179 }
00180 return true;
00181 }
00182 }