]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_showwhois.cpp
bf3028c122e233febc6664b1a6596bd45ee57625
[user/henk/code/inspircd.git] / src / modules / m_showwhois.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
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>
9  *
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.
13  *
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
17  * details.
18  *
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/>.
21  */
22
23
24 #include "inspircd.h"
25
26 /** Handle user mode +W
27  */
28 class SeeWhois : public SimpleUserModeHandler
29 {
30  public:
31         SeeWhois(Module* Creator, bool IsOpersOnly) : SimpleUserModeHandler(Creator, "showwhois", 'W')
32         {
33                 oper = IsOpersOnly;
34         }
35 };
36
37 class WhoisNoticeCmd : public Command
38 {
39  public:
40         WhoisNoticeCmd(Module* Creator) : Command(Creator,"WHOISNOTICE", 1)
41         {
42                 flags_needed = FLAG_SERVERONLY;
43         }
44
45         void HandleFast(User* dest, User* src)
46         {
47                 dest->WriteNotice("*** " + src->nick + " (" + src->ident + "@" +
48                         (dest->HasPrivPermission("users/auspex") ? src->host : src->dhost) +
49                         ") did a /whois on you");
50         }
51
52         CmdResult Handle(const std::vector<std::string> &parameters, User *user)
53         {
54                 User* dest = ServerInstance->FindNick(parameters[0]);
55                 if (!dest)
56                         return CMD_FAILURE;
57
58                 User* source = ServerInstance->FindNick(parameters[1]);
59
60                 if (IS_LOCAL(dest) && source)
61                         HandleFast(dest, source);
62
63                 return CMD_SUCCESS;
64         }
65 };
66
67 class ModuleShowwhois : public Module
68 {
69         bool ShowWhoisFromOpers;
70         SeeWhois* sw;
71         WhoisNoticeCmd cmd;
72
73  public:
74
75         ModuleShowwhois()
76                 : sw(NULL), cmd(this)
77         {
78         }
79
80         void init() CXX11_OVERRIDE
81         {
82                 ConfigTag* tag = ServerInstance->Config->ConfValue("showwhois");
83
84                 bool OpersOnly = tag->getBool("opersonly", true);
85                 ShowWhoisFromOpers = tag->getBool("showfromopers", true);
86
87                 sw = new SeeWhois(this, OpersOnly);
88                 ServerInstance->Modules->AddService(*sw);
89                 ServerInstance->Modules->AddService(cmd);
90         }
91
92         ~ModuleShowwhois()
93         {
94                 delete sw;
95         }
96
97         Version GetVersion() CXX11_OVERRIDE
98         {
99                 return Version("Allows opers to set +W to see when a user uses WHOIS on them",VF_OPTCOMMON|VF_VENDOR);
100         }
101
102         void OnWhois(User* source, User* dest) CXX11_OVERRIDE
103         {
104                 if (!dest->IsModeSet(*sw) || source == dest)
105                         return;
106
107                 if (!ShowWhoisFromOpers && source->IsOper())
108                         return;
109
110                 if (IS_LOCAL(dest))
111                 {
112                         cmd.HandleFast(dest, source);
113                 }
114                 else
115                 {
116                         std::vector<std::string> params;
117                         params.push_back(dest->server);
118                         params.push_back("WHOISNOTICE");
119                         params.push_back(dest->uuid);
120                         params.push_back(source->uuid);
121                         ServerInstance->PI->SendEncapsulatedData(params);
122                 }
123         }
124 };
125
126 MODULE_INIT(ModuleShowwhois)
127