2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5 * Copyright (C) 2005, 2008 Robin Burchell <robin+git@viroteck.net>
6 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
7 * Copyright (C) 2006 Craig Edwards <craigedwards@brainbox.cc>
8 * Copyright (C) 2004 Christopher Hall <typobox43@gmail.com>
10 * This file is part of InspIRCd. InspIRCd is free software: you can
11 * redistribute it and/or modify it under the terms of the GNU General Public
12 * License as published by the Free Software Foundation, version 2.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
26 /* $ModDesc: Allows opers to set +W to see when a user uses WHOIS on them */
28 /** Handle user mode +W
30 class SeeWhois : public ModeHandler
33 SeeWhois(Module* Creator, bool IsOpersOnly) : ModeHandler(Creator, "showwhois", 'W', PARAM_NONE, MODETYPE_USER)
38 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding)
42 if (!dest->IsModeSet('W'))
44 dest->SetMode('W',true);
45 return MODEACTION_ALLOW;
50 if (dest->IsModeSet('W'))
52 dest->SetMode('W',false);
53 return MODEACTION_ALLOW;
57 return MODEACTION_DENY;
61 class WhoisNoticeCmd : public Command
64 WhoisNoticeCmd(Module* Creator) : Command(Creator,"WHOISNOTICE", 1)
66 flags_needed = FLAG_SERVERONLY;
69 void HandleFast(User* dest, User* src)
71 dest->WriteServ("NOTICE %s :*** %s (%s@%s) did a /whois on you",
72 dest->nick.c_str(), src->nick.c_str(), src->ident.c_str(),
73 dest->HasPrivPermission("users/auspex") ? src->host.c_str() : src->dhost.c_str());
76 CmdResult Handle(const std::vector<std::string> ¶meters, User *user)
78 User* dest = ServerInstance->FindNick(parameters[0]);
82 User* source = ServerInstance->FindNick(parameters[1]);
84 if (IS_LOCAL(dest) && source)
85 HandleFast(dest, source);
91 class ModuleShowwhois : public Module
93 bool ShowWhoisFromOpers;
99 ModuleShowwhois() : cmd(this)
102 bool OpersOnly = conf.ReadFlag("showwhois", "opersonly", "yes", 0);
103 ShowWhoisFromOpers = conf.ReadFlag("showwhois", "showfromopers", "yes", 0);
105 sw = new SeeWhois(this, OpersOnly);
106 if (!ServerInstance->Modes->AddMode(sw))
107 throw ModuleException("Could not add new modes!");
108 ServerInstance->AddCommand(&cmd);
109 Implementation eventlist[] = { I_OnWhois };
110 ServerInstance->Modules->Attach(eventlist, this, 1);
120 return Version("Allows opers to set +W to see when a user uses WHOIS on them",VF_OPTCOMMON|VF_VENDOR);
123 void OnWhois(User* source, User* dest)
125 if (!dest->IsModeSet('W') || source == dest)
128 if (!ShowWhoisFromOpers && IS_OPER(source))
133 cmd.HandleFast(dest, source);
137 std::vector<std::string> params;
138 params.push_back(dest->server);
139 params.push_back("WHOISNOTICE");
140 params.push_back(dest->uuid);
141 params.push_back(source->uuid);
142 ServerInstance->PI->SendEncapsulatedData(params);
148 MODULE_INIT(ModuleShowwhois)