X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_swhois.cpp;h=d635654a524fd1229b02031dc35f95f05dc3d677;hb=297c720daecb7622f5eee80359987f416fa82227;hp=2b7e584131c8b1a321cf53214944f91aadec4fd5;hpb=321fdf7a641ca75b4002c3a205f3858fd985e8b1;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_swhois.cpp b/src/modules/m_swhois.cpp index 2b7e58413..d635654a5 100644 --- a/src/modules/m_swhois.cpp +++ b/src/modules/m_swhois.cpp @@ -2,110 +2,129 @@ * | Inspire Internet Relay Chat Daemon | * +------------------------------------+ * - * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev. - * E-mail: - * - * - * - * Written by Craig Edwards, Craig McLure, and others. + * InspIRCd: (C) 2002-2007 InspIRCd Development Team + * See: http://www.inspircd.org/wiki/index.php/Credits + * * This program is free but copyrighted software; see * the file COPYING for details. * * --------------------------------------------------- */ +#include "inspircd.h" #include "users.h" #include "channels.h" #include "modules.h" -#include "helperfuncs.h" /* $ModDesc: Provides the SWHOIS command which allows setting of arbitary WHOIS lines */ +/** Handle /SWHOIS + */ class cmd_swhois : public command_t { - Server* Srv; + public: - cmd_swhois(Server* server) : command_t("SWHOIS",'o',2) + cmd_swhois (InspIRCd* Instance) : command_t(Instance,"SWHOIS",'o',2) { - this->Srv = server; this->source = "m_swhois.so"; + syntax = " "; } - void Handle(char** parameters, int pcnt, userrec* user) + CmdResult Handle(const char** parameters, int pcnt, userrec* user) { - userrec* dest = Srv->FindNick(std::string(parameters[0])); - if(dest) + userrec* dest = ServerInstance->FindNick(parameters[0]); + + if (!dest) { - std::string line; - for(int i = 1; i < pcnt; i++) - { - if (i != 1) - line.append(" "); - - line.append(parameters[i]); - } - - std::string* text; - dest->GetExt("swhois", text); - - if(text) - { - // We already had it set... - - if (!Srv->IsUlined(user->server)) - // Ulines set SWHOISes silently - WriteOpers("*** %s used SWHOIS to set %s's extra whois from '%s' to '%s'", user->nick, dest->nick, text->c_str(), line.c_str()); + user->WriteServ("401 %s %s :No such nick/channel", user->nick, parameters[0]); + return CMD_FAILURE; + } + + if (!*parameters[1]) + { + user->WriteServ("NOTICE %s :*** SWHOIS: Whois line must be specified", user->nick); + return CMD_FAILURE; + } + + std::string line; + for (int i = 1; i < pcnt; i++) + { + if (i != 1) + line.append(" "); - dest->Shrink("swhois"); - DELETE(text); - } - else if(!Srv->IsUlined(user->server)) - { + line.append(parameters[i]); + } + + std::string* text; + dest->GetExt("swhois", text); + + if (text) + { + // We already had it set... + + if (!ServerInstance->ULine(user->server)) // Ulines set SWHOISes silently - WriteOpers("*** %s used SWHOIS to set %s's extra whois to '%s'", user->nick, dest->nick, line.c_str()); - } + ServerInstance->WriteOpers("*** %s used SWHOIS to set %s's extra whois from '%s' to '%s'", user->nick, dest->nick, text->c_str(), line.c_str()); - text = new std::string(line); - dest->Extend("swhois", text); + dest->Shrink("swhois"); + DELETE(text); + } + else if (!ServerInstance->ULine(user->server)) + { + // Ulines set SWHOISes silently + ServerInstance->WriteOpers("*** %s used SWHOIS to set %s's extra whois to '%s'", user->nick, dest->nick, line.c_str()); } + + text = new std::string(line); + dest->Extend("swhois", text); + + return CMD_SUCCESS; } + }; class ModuleSWhois : public Module { cmd_swhois* mycommand; - Server* Srv; + ConfigReader* Conf; public: - ModuleSWhois(Server* Me) : Module::Module(Me) + ModuleSWhois(InspIRCd* Me) : Module(Me) { - Srv = Me; - Conf = new ConfigReader(); - mycommand = new cmd_swhois(Srv); - Srv->AddCommand(mycommand); + + Conf = new ConfigReader(ServerInstance); + mycommand = new cmd_swhois(ServerInstance); + ServerInstance->AddCommand(mycommand); } - void OnRehash(const std::string ¶meter) + void OnRehash(userrec* user, const std::string ¶meter) { DELETE(Conf); - Conf = new ConfigReader(); + Conf = new ConfigReader(ServerInstance); } void Implements(char* List) { - List[I_OnWhois] = List[I_OnSyncUserMetaData] = List[I_OnUserQuit] = List[I_OnCleanup] = List[I_OnRehash] = List[I_OnOper] = 1; + List[I_OnDecodeMetaData] = List[I_OnWhoisLine] = List[I_OnSyncUserMetaData] = List[I_OnUserQuit] = List[I_OnCleanup] = List[I_OnRehash] = List[I_OnPostCommand] = 1; } // :kenny.chatspike.net 320 Brain Azhrarn :is getting paid to play games. - virtual void OnWhois(userrec* source, userrec* dest) + int OnWhoisLine(userrec* user, userrec* dest, int &numeric, std::string &text) { - std::string* swhois; - dest->GetExt("swhois", swhois); - if (swhois) + /* We use this and not OnWhois because this triggers for remote, too */ + if (numeric == 312) { - WriteServ(source->fd,"320 %s %s :%s",source->nick,dest->nick,swhois->c_str()); + /* Insert our numeric before 312 */ + std::string* swhois; + dest->GetExt("swhois", swhois); + if (swhois) + { + ServerInstance->SendWhoisLine(user, dest, 320, "%s %s :%s",user->nick,dest->nick,swhois->c_str()); + } } + /* Dont block anything */ + return 0; } // Whenever the linking module wants to send out data, but doesnt know what the data @@ -113,7 +132,7 @@ class ModuleSWhois : public Module // this method is called. We should use the ProtoSendMetaData function after we've // corrected decided how the data should look, to send the metadata on its way if // it is ours. - virtual void OnSyncUserMetaData(userrec* user, Module* proto, void* opaque, const std::string &extname) + virtual void OnSyncUserMetaData(userrec* user, Module* proto, void* opaque, const std::string &extname, bool displayable) { // check if the linking module wants to know about OUR metadata if (extname == "swhois") @@ -131,7 +150,7 @@ class ModuleSWhois : public Module } // when a user quits, tidy up their metadata - virtual void OnUserQuit(userrec* user, const std::string &message) + virtual void OnUserQuit(userrec* user, const std::string &message, const std::string &oper_message) { std::string* swhois; user->GetExt("swhois", swhois); @@ -181,34 +200,59 @@ class ModuleSWhois : public Module } } - virtual void OnOper(userrec* user, const std::string &opertype) + virtual void OnPostCommand(const std::string &command, const char **params, int pcnt, userrec *user, CmdResult result, const std::string &original_line) { - for(int i =0; i < Conf->Enumerate("type"); i++) + if ((command != "OPER") || (result != CMD_SUCCESS)) + return; + + std::string swhois; + + for (int i = 0; i < Conf->Enumerate("oper"); i++) { - std::string type = Conf->ReadValue("type", "name", i); + std::string name = Conf->ReadValue("oper", "name", i); - if(strcmp(type.c_str(), user->oper) == 0) + if (name == params[0]) + { + swhois = Conf->ReadValue("oper", "swhois", i); + break; + } + } + + if (!swhois.length()) + { + for (int i = 0; i < Conf->Enumerate("type"); i++) { - std::string swhois = Conf->ReadValue("type", "swhois", i); + std::string type = Conf->ReadValue("type", "name", i); - if(swhois.length()) + if (type == user->oper) { - std::string* old; - if(user->GetExt("swhois", old)) - { - user->Shrink("swhois"); - DELETE(old); - } - - std::string* text = new std::string(swhois); - user->Extend("swhois", text); - + swhois = Conf->ReadValue("type", "swhois", i); break; } } - } + } + + std::string *old; + if (user->GetExt("swhois", old)) + { + user->Shrink("swhois"); + DELETE(old); + } + + if (!swhois.length()) + return; + + std::string *text = new std::string(swhois); + user->Extend("swhois", text); + std::deque* metadata = new std::deque; + metadata->push_back(user->nick); + metadata->push_back("swhois"); // The metadata id + metadata->push_back(*text); // The value to send + Event event((char*)metadata,(Module*)this,"send_metadata"); + event.Send(ServerInstance); + delete metadata; } - + virtual ~ModuleSWhois() { DELETE(Conf); @@ -216,32 +260,8 @@ class ModuleSWhois : public Module virtual Version GetVersion() { - return Version(1,0,0,0,VF_VENDOR); + return Version(1,1,0,0,VF_VENDOR,API_VERSION); } }; - -class ModuleSWhoisFactory : public ModuleFactory -{ - public: - ModuleSWhoisFactory() - { - } - - ~ModuleSWhoisFactory() - { - } - - virtual Module * CreateModule(Server* Me) - { - return new ModuleSWhois(Me); - } - -}; - - -extern "C" void * init_module( void ) -{ - return new ModuleSWhoisFactory; -} - +MODULE_INIT(ModuleSWhois)