]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_swhois.cpp
Merge pull request #109 from Justasic/insp20
[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
28 /* $ModDesc: Provides the SWHOIS command which allows setting of arbitary WHOIS lines */
29
30 /** Handle /SWHOIS
31  */
32 class CommandSwhois : public Command
33 {
34  public:
35         StringExtItem swhois;
36         CommandSwhois(Module* Creator) : Command(Creator,"SWHOIS", 2,2), swhois("swhois", Creator)
37         {
38                 flags_needed = 'o'; syntax = "<nick> :<swhois>";
39                 ServerInstance->Extensions.Register(&swhois);
40                 TRANSLATE3(TR_NICK, TR_TEXT, TR_END);
41         }
42
43         CmdResult Handle(const std::vector<std::string> &parameters, User* user)
44         {
45                 User* dest = ServerInstance->FindNick(parameters[0]);
46
47                 if (!dest)
48                 {
49                         user->WriteNumeric(ERR_NOSUCHNICK, "%s %s :No such nick/channel", user->nick.c_str(), parameters[0].c_str());
50                         return CMD_FAILURE;
51                 }
52
53                 std::string* text = swhois.get(dest);
54                 if (text)
55                 {
56                         // We already had it set...
57                         if (!ServerInstance->ULine(user->server))
58                                 // Ulines set SWHOISes silently
59                                 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());
60                 }
61                 else if (!ServerInstance->ULine(user->server))
62                 {
63                         // Ulines set SWHOISes silently
64                         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());
65                 }
66
67                 if (parameters[1].empty())
68                         swhois.unset(dest);
69                 else
70                         swhois.set(dest, parameters[1]);
71
72                 /* Bug #376 - feature request -
73                  * To cut down on the amount of commands services etc have to recognise, this only sends METADATA across the network now
74                  * not an actual SWHOIS command. Any SWHOIS command sent from services will be automatically translated to METADATA by this.
75                  * Sorry w00t i know this was your fix, but i got bored and wanted to clear down the tracker :)
76                  * -- Brain
77                  */
78                 ServerInstance->PI->SendMetaData(dest, "swhois", parameters[1]);
79
80                 return CMD_SUCCESS;
81         }
82
83 };
84
85 class ModuleSWhois : public Module
86 {
87         CommandSwhois cmd;
88
89  public:
90         ModuleSWhois() : cmd(this)
91         {
92                 ServerInstance->AddCommand(&cmd);
93                 Implementation eventlist[] = { I_OnWhoisLine, I_OnPostCommand };
94                 ServerInstance->Modules->Attach(eventlist, this, 2);
95         }
96
97         // :kenny.chatspike.net 320 Brain Azhrarn :is getting paid to play games.
98         ModResult OnWhoisLine(User* user, User* dest, int &numeric, std::string &text)
99         {
100                 /* We use this and not OnWhois because this triggers for remote, too */
101                 if (numeric == 312)
102                 {
103                         /* Insert our numeric before 312 */
104                         std::string* swhois = cmd.swhois.get(dest);
105                         if (swhois)
106                         {
107                                 ServerInstance->SendWhoisLine(user, dest, 320, "%s %s :%s",user->nick.c_str(), dest->nick.c_str(), swhois->c_str());
108                         }
109                 }
110
111                 /* Dont block anything */
112                 return MOD_RES_PASSTHRU;
113         }
114
115         void OnPostCommand(const std::string &command, const std::vector<std::string> &params, LocalUser *user, CmdResult result, const std::string &original_line)
116         {
117                 if ((command != "OPER") || (result != CMD_SUCCESS))
118                         return;
119                 ConfigReader Conf;
120
121                 std::string swhois = user->oper->getConfig("swhois");
122
123                 if (!swhois.length())
124                         return;
125
126                 cmd.swhois.set(user, swhois);
127                 ServerInstance->PI->SendMetaData(user, "swhois", swhois);
128         }
129
130         ~ModuleSWhois()
131         {
132         }
133
134         Version GetVersion()
135         {
136                 return Version("Provides the SWHOIS command which allows setting of arbitary WHOIS lines", VF_OPTCOMMON | VF_VENDOR);
137         }
138 };
139
140 MODULE_INIT(ModuleSWhois)