X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_spy.cpp;h=17998b9643a87ac3047c3356c690c1cc0498e407;hb=cd7657bddc7a6dc2e7326077d173a874bf71f6bd;hp=1698b16e24fce3626c1ac274b537ff1f514dc077;hpb=a753cc1ec3af9c2d6095f313c233050585f96f98;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_spy.cpp b/src/modules/m_spy.cpp index 1698b16e2..17998b964 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,49 +16,61 @@ * 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 "inspircd_config.h" +#include "inspircd.h" #include "users.h" #include "channels.h" #include "modules.h" -#include "inspircd.h" #include "wildcard.h" 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,c->GetPrefixChar(i->second),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->first), i->first->nick); + + curlen += ptrlen; + ptr += ptrlen; + + numusers++; + + if (curlen > (480-NICKMAX)) { - /* list overflowed into - * multiple numerics */ + /* list overflowed into multiple numerics */ user->WriteServ(std::string(list)); - snprintf(list,MAXBUF,"353 %s = %s :", user->nick, c->name); + + /* 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) { 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: @@ -75,7 +84,7 @@ class cmd_spylist : public command_t { 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++) + for (chan_hash::const_iterator i = ServerInstance->chanlist->begin(); i != ServerInstance->chanlist->end(); i++) { if (pcnt && !match(i->second->name, parameters[0])) continue; @@ -88,6 +97,8 @@ class cmd_spylist : public command_t } }; +/** Handle /SPYNAMES + */ class cmd_spynames : public command_t { public: @@ -115,7 +126,6 @@ class cmd_spynames : public command_t { 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 { @@ -131,7 +141,7 @@ class ModuleSpy : public Module cmd_spylist *mycommand; cmd_spynames *mycommand2; public: - ModuleSpy(InspIRCd* Me) : Module::Module(Me) + ModuleSpy(InspIRCd* Me) : Module(Me) { mycommand = new cmd_spylist(ServerInstance); @@ -146,7 +156,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); } }; @@ -170,7 +180,7 @@ class ModuleSpyFactory : public ModuleFactory }; -extern "C" void * init_module( void ) +extern "C" DllExport void * init_module( void ) { return new ModuleSpyFactory; }