X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_spy.cpp;h=de48284ba64a1926242009b704fcf6dde945865d;hb=7c197db72eab03321e4f3e847054e13126520504;hp=3e0e21a96b42445298cd22efea8bdab49f7ba60f;hpb=c17d4bc92ce4482c847ebb6ddacf55df85497175;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_spy.cpp b/src/modules/m_spy.cpp index 3e0e21a96..de48284ba 100644 --- a/src/modules/m_spy.cpp +++ b/src/modules/m_spy.cpp @@ -2,12 +2,9 @@ * | 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. * @@ -19,125 +16,126 @@ * WHOIS, WHICH IS SUPPORTED BY MOST IRCDS IN CORE. */ -using namespace std; - /* $ModDesc: Provides SPYLIST and SPYNAMES capability, allowing opers to see who's in +s channels */ -#include -#include -#include -#include "globals.h" #include "inspircd_config.h" -#include #include "users.h" #include "channels.h" #include "modules.h" -#include "commands.h" -#include "socket.h" -#include "helperfuncs.h" #include "inspircd.h" -#include "inspstring.h" -#include "hashcomp.h" -#include "message.h" -#include "xline.h" -#include "typedefs.h" -#include "cull_list.h" -#include "aes.h" - -#define nspace __gnu_cxx - -static Server *Srv; - -extern ServerConfig* Config; -extern InspIRCd* ServerInstance; -extern chan_hash chanlist; +#include "wildcard.h" -void spy_userlist(userrec *user,chanrec *c) +void spy_userlist(userrec *user, chanrec *c) { - static char list[MAXBUF]; + char list[MAXBUF]; + size_t dlen, curlen; - if ((!c) || (!user)) - return; + dlen = curlen = snprintf(list,MAXBUF,"353 %s = %s :", user->nick, c->name); - snprintf(list,MAXBUF,"353 %s = %s :", user->nick, c->name); + int numusers = 0; + char* ptr = list + dlen; CUList *ulist= c->GetUsers(); + for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++) { - strlcat(list,cmode(i->second,c),MAXBUF); - strlcat(list,i->second->nick,MAXBUF); - strlcat(list," ",MAXBUF); - if (strlen(list)>(480-NICKMAX)) + size_t ptrlen = snprintf(ptr, MAXBUF, "%s%s ", c->GetPrefixChar(i->second), i->second->nick); + + curlen += ptrlen; + ptr += ptrlen; + + numusers++; + + if (curlen > (480-NICKMAX)) { - /* list overflowed into - * multiple numerics */ - WriteServ_NoFormat(user->fd,list); - snprintf(list,MAXBUF,"353 %s = %s :", user->nick, c->name); + /* list overflowed into multiple numerics */ + user->WriteServ(std::string(list)); + + /* reset our lengths */ + dlen = curlen = snprintf(list,MAXBUF,"353 %s = %s :", user->nick, c->name); + ptr = list + dlen; + + ptrlen = 0; + numusers = 0; } } + /* if whats left in the list isnt empty, send it */ - if (list[strlen(list)-1] != ':') + if (numusers) { - WriteServ_NoFormat(user->fd,list); + user->WriteServ(std::string(list)); } -} + user->WriteServ("366 %s %s :End of /NAMES list.", user->nick, c->name); +} +/** Handle /SPYLIST + */ class cmd_spylist : public command_t { public: - cmd_spylist () : command_t("SPYLIST", 'o', 0) + cmd_spylist (InspIRCd* Instance) : command_t(Instance,"SPYLIST", 'o', 0) { this->source = "m_spy.so"; + syntax = ""; } - void Handle (const char** parameters, int pcnt, userrec *user) + CmdResult Handle (const char** parameters, int pcnt, userrec *user) { - WriteOpers("*** Oper %s used SPYLIST to list +s/+p channels and keys.",user->nick); - WriteServ(user->fd,"321 %s Channel :Users Name",user->nick); - for (chan_hash::const_iterator i = chanlist.begin(); i != chanlist.end(); i++) + ServerInstance->WriteOpers("*** Oper %s used SPYLIST to list +s/+p channels and keys.",user->nick); + user->WriteServ("321 %s Channel :Users Name",user->nick); + for (chan_hash::const_iterator i = ServerInstance->chanlist->begin(); i != ServerInstance->chanlist->end(); i++) { - WriteServ(user->fd,"322 %s %s %d :[+%s] %s",user->nick,i->second->name,usercount(i->second),chanmodes(i->second,true),i->second->topic); + if (pcnt && !match(i->second->name, parameters[0])) + continue; + user->WriteServ("322 %s %s %d :[+%s] %s",user->nick,i->second->name,i->second->GetUserCounter(),i->second->ChanModes(true),i->second->topic); } - WriteServ(user->fd,"323 %s :End of channel list.",user->nick); + user->WriteServ("323 %s :End of channel list.",user->nick); + + /* Dont send out across the network */ + return CMD_FAILURE; } }; +/** Handle /SPYNAMES + */ class cmd_spynames : public command_t { public: - cmd_spynames () : command_t("SPYNAMES", 'o', 0) - { - this->source = "m_spy.so"; - } - - void Handle (const char** parameters, int pcnt, userrec *user) - { - chanrec* c; - - if (!pcnt) - { - WriteServ(user->fd,"366 %s * :End of /NAMES list.",user->nick); - return; - } - - if (ServerInstance->Parser->LoopCall(user, this, parameters, pcnt, 1)) - return; - - WriteOpers("*** Oper %s used SPYNAMES to view the users on %s",user->nick,parameters[0]); - - c = FindChan(parameters[0]); - if (c) - { - spy_userlist(user,c); - WriteServ(user->fd,"366 %s %s :End of /NAMES list.", user->nick, c->name); - } - else - { - WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]); - } - } + cmd_spynames (InspIRCd* Instance) : command_t(Instance,"SPYNAMES", 'o', 0) + { + this->source = "m_spy.so"; + syntax = "{{,}}"; + } + + CmdResult Handle (const char** parameters, int pcnt, userrec *user) + { + chanrec* c = NULL; + + if (!pcnt) + { + user->WriteServ("366 %s * :End of /NAMES list.",user->nick); + return CMD_FAILURE; + } + + if (ServerInstance->Parser->LoopCall(user, this, parameters, pcnt, 0)) + return CMD_FAILURE; + + c = ServerInstance->FindChan(parameters[0]); + if (c) + { + ServerInstance->WriteOpers("*** Oper %s used SPYNAMES to view the users on %s", user->nick, parameters[0]); + spy_userlist(user,c); + user->WriteServ("366 %s %s :End of /NAMES list.", user->nick, c->name); + } + else + { + user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]); + } + + return CMD_FAILURE; + } }; class ModuleSpy : public Module @@ -145,13 +143,13 @@ class ModuleSpy : public Module cmd_spylist *mycommand; cmd_spynames *mycommand2; public: - ModuleSpy(Server* Me) : Module::Module(Me) + ModuleSpy(InspIRCd* Me) : Module::Module(Me) { - Srv = Me; - mycommand = new cmd_spylist(); - mycommand2 = new cmd_spynames(); - Srv->AddCommand(mycommand); - Srv->AddCommand(mycommand2); + + mycommand = new cmd_spylist(ServerInstance); + mycommand2 = new cmd_spynames(ServerInstance); + ServerInstance->AddCommand(mycommand); + ServerInstance->AddCommand(mycommand2); } virtual ~ModuleSpy() @@ -160,7 +158,7 @@ class ModuleSpy : public Module virtual Version GetVersion() { - return Version(1, 0, 0, 0, VF_VENDOR); + return Version(1, 1, 0, 0, VF_VENDOR, API_VERSION); } }; @@ -176,7 +174,7 @@ class ModuleSpyFactory : public ModuleFactory { } - virtual Module * CreateModule(Server* Me) + virtual Module * CreateModule(InspIRCd* Me) { return new ModuleSpy(Me); }