X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_userip.cpp;h=7ffeb383a1fbe4b7ab7adc5d7600e83bb1a8ef20;hb=eacd707421be4f2612df9bde4517649061bb062e;hp=4bc2155140dd58f76a494cd9ed3efac3e7855e0d;hpb=2cf348bf6bf64353350fb7df163cf0b9ecd95a13;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_userip.cpp b/src/modules/m_userip.cpp index 4bc215514..7ffeb383a 100644 --- a/src/modules/m_userip.cpp +++ b/src/modules/m_userip.cpp @@ -2,89 +2,88 @@ * | Inspire Internet Relay Chat Daemon | * +------------------------------------+ * - * Inspire is copyright (C) 2002-2004 ChatSpike-Dev. - * E-mail: - * - * - * - * Written by Craig Edwards, Craig McLure, and others. + * InspIRCd: (C) 2002-2009 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 -#include -#include "users.h" -#include "channels.h" -#include "modules.h" +#include "inspircd.h" /* $ModDesc: Provides support for USERIP command */ -Server *Srv; - -void handle_userip(char **parameters, int pcnt, userrec *user) -{ - char Return[MAXBUF],junk[MAXBUF]; - snprintf(Return,MAXBUF,"302 %s :",user->nick); - for (int i = 0; i < pcnt; i++) - { - userrec *u = Find(parameters[i]); - if (u) - { - snprintf(junk,MAXBUF,"%s%s=+%s@%s ",u->nick,strchr(u->modes,'o') ? "*" : "",u->ident,u->ip); - strlcat(Return,junk,MAXBUF); - } - } - WriteServ(user->fd,Return); -} - - -class ModuleUserIP : public Module +/** Handle /USERIP + */ +class CommandUserip : public Command { public: - ModuleUserIP() - { - Srv = new Server; - Srv->AddCommand("USERIP",handle_UserIP,'o',1,"m_Userip.so"); - } - - virtual ~ModuleUserIP() + CommandUserip (InspIRCd* Instance) : Command(Instance,"USERIP", "o", 1) { - delete Srv; + this->source = "m_userip.so"; + syntax = "{,}"; } - - virtual Version GetVersion() + + CmdResult Handle (const std::vector ¶meters, User *user) { - return Version(1,0,0,1,VF_VENDOR); + std::string retbuf = std::string("340 ") + user->nick + " :"; + int nicks = 0; + + for (int i = 0; i < (int)parameters.size(); i++) + { + User *u = ServerInstance->FindNick(parameters[i]); + if ((u) && (u->registered == REG_ALL)) + { + retbuf = retbuf + u->nick + (IS_OPER(u) ? "*" : "") + "="; + if (IS_AWAY(u)) + retbuf += "-"; + else + retbuf += "+"; + retbuf += u->ident + "@" + u->GetIPString() + " "; + nicks++; + } + } + + if (nicks != 0) + user->WriteServ(retbuf); + + /* Dont send to the network */ + return CMD_LOCALONLY; } - }; -// stuff down here is the module-factory stuff. For basic modules you can ignore this. - -class ModuleUserIPFactory : public ModuleFactory +class ModuleUserIP : public Module { + CommandUserip* mycommand; public: - ModuleUserIPFactory() + ModuleUserIP(InspIRCd* Me) + : Module(Me) + { + + mycommand = new CommandUserip(ServerInstance); + ServerInstance->AddCommand(mycommand); + Implementation eventlist[] = { I_On005Numeric }; + ServerInstance->Modules->Attach(eventlist, this, 1); + } + + + virtual void On005Numeric(std::string &output) { + output = output + std::string(" USERIP"); } - - ~ModuleUserIPFactory() + + virtual ~ModuleUserIP() { } - - virtual Module * CreateModule() + + virtual Version GetVersion() { - return new ModuleUserIP; + return Version("$Id$",VF_VENDOR,API_VERSION); } - -}; +}; -extern "C" void * init_module( void ) -{ - return new ModuleUserIPFactory; -} +MODULE_INIT(ModuleUserIP)