]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_swhois.cpp
Use an oper priv instead of a config flag for overriding nonicks.
[user/henk/code/inspircd.git] / src / modules / m_swhois.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5  *   Copyright (C) 2008 Pippijn van Steenhoven <pip88nl@gmail.com>
6  *   Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
7  *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
8  *   Copyright (C) 2006-2007 John Brooks <john.brooks@dereferenced.net>
9  *   Copyright (C) 2005-2006 Craig Edwards <craigedwards@brainbox.cc>
10  *   Copyright (C) 2006 Oliver Lupton <oliverlupton@gmail.com>
11  *
12  * This file is part of InspIRCd.  InspIRCd is free software: you can
13  * redistribute it and/or modify it under the terms of the GNU General Public
14  * License as published by the Free Software Foundation, version 2.
15  *
16  * This program is distributed in the hope that it will be useful, but WITHOUT
17  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
19  * details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23  */
24
25
26 #include "inspircd.h"
27 #include "modules/whois.h"
28
29 enum
30 {
31         // From UnrealIRCd.
32         RPL_WHOISSPECIAL = 320
33 };
34
35 /** Handle /SWHOIS
36  */
37 class CommandSwhois : public Command
38 {
39  public:
40         StringExtItem swhois;
41         CommandSwhois(Module* Creator)
42                 : Command(Creator, "SWHOIS", 2, 2)
43                 , swhois("swhois", ExtensionItem::EXT_USER, Creator)
44         {
45                 flags_needed = 'o'; syntax = "<nick> :<swhois>";
46                 TRANSLATE2(TR_NICK, TR_TEXT);
47         }
48
49         CmdResult Handle(const std::vector<std::string>& parameters, User* user) CXX11_OVERRIDE
50         {
51                 User* dest = ServerInstance->FindNick(parameters[0]);
52
53                 if (!dest) // allow setting swhois using SWHOIS before reg
54                 {
55                         user->WriteNumeric(Numerics::NoSuchNick(parameters[0]));
56                         return CMD_FAILURE;
57                 }
58
59                 std::string* text = swhois.get(dest);
60                 if (text)
61                 {
62                         // We already had it set...
63                         if (!user->server->IsULine())
64                                 // Ulines set SWHOISes silently
65                                 ServerInstance->SNO->WriteGlobalSno('a', "%s used SWHOIS to set %s's extra whois from '%s' to '%s'", user->nick.c_str(), dest->nick.c_str(), text->c_str(), parameters[1].c_str());
66                 }
67                 else if (!user->server->IsULine())
68                 {
69                         // Ulines set SWHOISes silently
70                         ServerInstance->SNO->WriteGlobalSno('a', "%s used SWHOIS to set %s's extra whois to '%s'", user->nick.c_str(), dest->nick.c_str(), parameters[1].c_str());
71                 }
72
73                 if (parameters[1].empty())
74                         swhois.unset(dest);
75                 else
76                         swhois.set(dest, parameters[1]);
77
78                 /* Bug #376 - feature request -
79                  * To cut down on the amount of commands services etc have to recognise, this only sends METADATA across the network now
80                  * not an actual SWHOIS command. Any SWHOIS command sent from services will be automatically translated to METADATA by this.
81                  * Sorry w00t i know this was your fix, but i got bored and wanted to clear down the tracker :)
82                  * -- Brain
83                  */
84                 ServerInstance->PI->SendMetaData(dest, "swhois", parameters[1]);
85
86                 return CMD_SUCCESS;
87         }
88
89 };
90
91 class ModuleSWhois : public Module, public Whois::LineEventListener
92 {
93         CommandSwhois cmd;
94
95  public:
96         ModuleSWhois()
97                 : Whois::LineEventListener(this)
98                 , cmd(this)
99         {
100         }
101
102         // :kenny.chatspike.net 320 Brain Azhrarn :is getting paid to play games.
103         ModResult OnWhoisLine(Whois::Context& whois, Numeric::Numeric& numeric) CXX11_OVERRIDE
104         {
105                 /* We use this and not OnWhois because this triggers for remote, too */
106                 if (numeric.GetNumeric() == 312)
107                 {
108                         /* Insert our numeric before 312 */
109                         std::string* swhois = cmd.swhois.get(whois.GetTarget());
110                         if (swhois)
111                         {
112                                 whois.SendLine(RPL_WHOISSPECIAL, *swhois);
113                         }
114                 }
115
116                 /* Dont block anything */
117                 return MOD_RES_PASSTHRU;
118         }
119
120         void OnPostOper(User* user, const std::string &opertype, const std::string &opername) CXX11_OVERRIDE
121         {
122                 if (!IS_LOCAL(user))
123                         return;
124
125                 std::string swhois = user->oper->getConfig("swhois");
126
127                 if (!swhois.length())
128                         return;
129
130                 cmd.swhois.set(user, swhois);
131                 ServerInstance->PI->SendMetaData(user, "swhois", swhois);
132         }
133
134         Version GetVersion() CXX11_OVERRIDE
135         {
136                 return Version("Provides the SWHOIS command which allows setting of arbitrary WHOIS lines", VF_OPTCOMMON | VF_VENDOR);
137         }
138 };
139
140 MODULE_INIT(ModuleSWhois)