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 "module.h"
00030
00034 Module::Module(BotKernel*b)
00035 {
00036 this->author = "eponyme";
00037 this->description = "bot modules management";
00038 this->version = VERSION;
00039 this->name = "module";
00040 this->bindFunction("load",IN_COMMAND_HANDLER,"load",0,10);
00041 this->bindFunction("unload",IN_COMMAND_HANDLER,"unload",0,10);
00042 this->bindFunction("loadnocheck",IN_COMMAND_HANDLER,"loadnocheck",0,10);
00043 this->bindFunction("unloadnocheck",IN_COMMAND_HANDLER,"unloadnocheck",0,10);
00044 this->bindFunction("listmodules",IN_COMMAND_HANDLER,"listmodules",0,10);
00045 this->bindFunction("listlibs",IN_COMMAND_HANDLER,"listlibs",0,10);
00046 this->bindFunction("moduleinfos",IN_COMMAND_HANDLER,"moduleinfos",0,10);
00047 this->addRequirement("admin");
00048 }
00049
00050 extern "C"
00051 {
00052 Plugin *contruct_module(BotKernel*b)
00053 {
00054 return new Module(b);
00055 }
00056 void destroy_module(Plugin*p)
00057 {
00058 delete p;
00059 }
00060 bool load (Message*m,Plugin*p,BotKernel*b)
00061 {
00062 Admin * adm ;
00063 pPlugin * pp = b->getPlugin("admin");
00064 if ( pp != NULL ) {
00065 adm = (Admin*) pp->object;
00066 if ( (adm!=NULL) && m->isPrivate() && ( m->nbParts() == 5 ) && adm->isSuperAdmin( m->getSender()) ) {
00067 if(b->loadPlugin(m->getPart(4),true)) {
00068 b->send(IRCProtocol::sendNotice(m->getNickSender(),m->getPart(4)+" loaded"));
00069 b->getSysLog()->log(m->getPart(4)+" loaded by "+m->getSender(),INFO);
00070 }
00071 else {
00072 b->send(IRCProtocol::sendNotice(m->getNickSender(),m->getPart(4)+" loading failed."));
00073 b->getSysLog()->log(m->getPart(4)+" loading failed (by "+m->getSender()+")",WARNING);
00074 }
00075 }
00076 }
00077 return true;
00078 }
00079 bool unload (Message*m,Plugin*p,BotKernel*b)
00080 {
00081 Admin * adm ;
00082 pPlugin * pp = b->getPlugin("admin");
00083 if ( pp != NULL ) {
00084 adm = (Admin*) pp->object;
00085 if ( (adm!=NULL) && m->isPrivate() && ( m->nbParts() == 5 ) && adm->isSuperAdmin( m->getSender()) ) {
00086 if(b->unloadPlugin(m->getPart(4),true)) {
00087 b->send(IRCProtocol::sendNotice(m->getNickSender(),m->getPart(4)+" unloaded"));
00088 b->getSysLog()->log(m->getPart(4)+" unloaded by "+m->getSender(),INFO);
00089 }
00090 else {
00091 b->send(IRCProtocol::sendNotice(m->getNickSender(),m->getPart(4)+" unloading failed."));
00092 b->getSysLog()->log(m->getPart(4)+" unloading failed (by "+m->getSender()+")",WARNING);
00093 }
00094 }
00095 }
00096 return true;
00097 }
00098 bool loadnocheck (Message*m,Plugin*p,BotKernel*b)
00099 {
00100 Admin * adm ;
00101 pPlugin * pp = b->getPlugin("admin");
00102 if ( pp != NULL ) {
00103 adm = (Admin*) pp->object;
00104 if ( (adm!=NULL) && m->isPrivate() && ( m->nbParts() == 5 ) && adm->isSuperAdmin( m->getSender()) ) {
00105 if(b->loadPlugin(m->getPart(4),false)) {
00106 b->send(IRCProtocol::sendNotice(m->getNickSender(),m->getPart(4)+" loaded"));
00107 b->getSysLog()->log(m->getPart(4)+" loaded by "+m->getSender(),INFO);
00108 }
00109 else {
00110 b->send(IRCProtocol::sendNotice(m->getNickSender(),m->getPart(4)+" loading failed."));
00111 b->getSysLog()->log(m->getPart(4)+" loading failed (by "+m->getSender()+")",WARNING);
00112 }
00113 }
00114 }
00115 return true;
00116 }
00117 bool unloadnocheck (Message*m,Plugin*p,BotKernel*b)
00118 {
00119 Admin * adm ;
00120 pPlugin * pp = b->getPlugin("admin");
00121 if ( pp != NULL ) {
00122 adm = (Admin*) pp->object;
00123 if ( (adm!=NULL) && m->isPrivate() && ( m->nbParts() == 5 ) && adm->isSuperAdmin( m->getSender()) ) {
00124 if(b->unloadPlugin(m->getPart(4),false)) {
00125 b->send(IRCProtocol::sendNotice(m->getNickSender(),m->getPart(4)+" unloaded"));
00126 b->getSysLog()->log(m->getPart(4)+" unloaded by "+m->getSender(),INFO);
00127 }
00128 else {
00129 b->send(IRCProtocol::sendNotice(m->getNickSender(),m->getPart(4)+" unloading failed."));
00130 b->getSysLog()->log(m->getPart(4)+" unloading failed (by "+m->getSender()+")",WARNING);
00131 }
00132 }
00133 }
00134 return true;
00135 }
00136 bool listmodules (Message*m,Plugin*p,BotKernel*b)
00137 {
00138 Admin * adm ;
00139 pPlugin * pp = b->getPlugin("admin");
00140 if ( pp != NULL )
00141 {
00142 adm = (Admin*) pp->object;
00143 if( (adm!=NULL) && m->isPrivate() && adm->isSuperAdmin( m->getSender()) ) {
00144 b->send(IRCProtocol::sendNotices(m->getNickSender(),Tools::gatherVectorElements(b->getPluginsList()," ",4)));
00145 }
00146 }
00147 return true;
00148 }
00149 bool listlibs (Message*m,Plugin*p,BotKernel*b) {
00150 DIR *dp;
00151 struct dirent *ep;
00152 const unsigned int NBPATHS = 3;
00153 string paths[NBPATHS] = {b->getDatasDir()+"../plugins",PLUGINSDIR,"plugins"};
00154 vector<string> plugins;
00155 pPlugin * ppAdm = b->getPlugin("admin");
00156 Admin*adm = NULL;
00157 if ((ppAdm!=NULL) && m->isPrivate() ) {
00158 adm = (Admin*)ppAdm->object ;
00159 if (adm->isSuperAdmin(m->getSender()) ) {
00160 for(unsigned int i = 0 ; i < NBPATHS ; i ++ ) {
00161 plugins.clear();
00162 dp = opendir (paths[i].c_str());
00163 if (dp != NULL) {
00164 while ((ep = readdir(dp))) {
00165 if ( ((string)ep->d_name != ".") && ((string)ep->d_name !="..")) {
00166 plugins.push_back(ep->d_name);
00167 }
00168 }
00169 closedir (dp);
00170 }
00171 else {
00172 plugins.push_back("* Couldn't open the directory ("+paths[i]+") *");
00173 }
00174 b->send(IRCProtocol::sendNotices(m->getNickSender(),Tools::gatherVectorElements(plugins," ",4)));
00175 }
00176 }
00177 }
00178 return true;
00179 }
00180 bool moduleinfos (Message*m,Plugin*p,BotKernel*b) {
00181 pPlugin * pp = NULL;
00182 pPlugin * ppAdm = b->getPlugin("admin");
00183 Admin*adm = NULL;
00184 Plugin * plug;
00185 if ((ppAdm!=NULL) && m->isPrivate() && (m->nbParts() == 5)) {
00186 adm = (Admin*)ppAdm->object ;
00187 if (adm->isSuperAdmin(m->getSender()) ) {
00188 pp = b->getPlugin(m->getPart(4) ) ;
00189 if ( pp != NULL ) {
00190 plug = pp->object;
00191 b->send(IRCProtocol::sendNotice(m->getNickSender(),m->getPart(4) +" ("+plug->getVersion()+") by "+plug->getAuthor()+" : "+plug->getDescription()));
00192 }
00193 else {
00194 b->send(IRCProtocol::sendNotice(m->getNickSender(),m->getPart(4) +" not loaded"));
00195 }
00196 }
00197 }
00198 return true;
00199 }
00200 }