]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_swhois.cpp
Remove InspIRCd* parameters and fields
[user/henk/code/inspircd.git] / src / modules / m_swhois.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15
16 /* $ModDesc: Provides the SWHOIS command which allows setting of arbitary WHOIS lines */
17
18 /** Handle /SWHOIS
19  */
20 class CommandSwhois : public Command
21 {
22  public:
23         StringExtItem swhois;
24         CommandSwhois(Module* Creator) : Command(Creator,"SWHOIS", 2,2), swhois("swhois", Creator)
25         {
26                 flags_needed = 'o'; syntax = "<nick> :<swhois>";
27                 Extensible::Register(&swhois);
28                 TRANSLATE3(TR_NICK, TR_TEXT, TR_END);
29         }
30
31         CmdResult Handle(const std::vector<std::string> &parameters, User* user)
32         {
33                 User* dest = ServerInstance->FindNick(parameters[0]);
34
35                 if (!dest)
36                 {
37                         user->WriteNumeric(ERR_NOSUCHNICK, "%s %s :No such nick/channel", user->nick.c_str(), parameters[0].c_str());
38                         return CMD_FAILURE;
39                 }
40
41                 std::string* text = swhois.get(dest);
42                 if (text)
43                 {
44                         // We already had it set...
45                         if (!ServerInstance->ULine(user->server))
46                                 // Ulines set SWHOISes silently
47                                 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());
48                 }
49                 else if (!ServerInstance->ULine(user->server))
50                 {
51                         // Ulines set SWHOISes silently
52                         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());
53                 }
54
55                 if (parameters[1].empty())
56                         swhois.unset(dest);
57                 else
58                         swhois.set(dest, parameters[1]);
59
60                 /* Bug #376 - feature request -
61                  * To cut down on the amount of commands services etc have to recognise, this only sends METADATA across the network now
62                  * not an actual SWHOIS command. Any SWHOIS command sent from services will be automatically translated to METADATA by this.
63                  * Sorry w00t i know this was your fix, but i got bored and wanted to clear down the tracker :)
64                  * -- Brain
65                  */
66                 ServerInstance->PI->SendMetaData(dest, "swhois", parameters[1]);
67
68                 return CMD_SUCCESS;
69         }
70
71 };
72
73 class ModuleSWhois : public Module
74 {
75         CommandSwhois cmd;
76
77  public:
78         ModuleSWhois() : cmd(this)
79         {
80                 ServerInstance->AddCommand(&cmd);
81                 Implementation eventlist[] = { I_OnWhoisLine, I_OnPostCommand };
82                 ServerInstance->Modules->Attach(eventlist, this, 2);
83         }
84
85         // :kenny.chatspike.net 320 Brain Azhrarn :is getting paid to play games.
86         ModResult OnWhoisLine(User* user, User* dest, int &numeric, std::string &text)
87         {
88                 /* We use this and not OnWhois because this triggers for remote, too */
89                 if (numeric == 312)
90                 {
91                         /* Insert our numeric before 312 */
92                         std::string* swhois = cmd.swhois.get(dest);
93                         if (swhois)
94                         {
95                                 ServerInstance->SendWhoisLine(user, dest, 320, "%s %s :%s",user->nick.c_str(), dest->nick.c_str(), swhois->c_str());
96                         }
97                 }
98
99                 /* Dont block anything */
100                 return MOD_RES_PASSTHRU;
101         }
102
103         void OnPostCommand(const std::string &command, const std::vector<std::string> &params, User *user, CmdResult result, const std::string &original_line)
104         {
105                 if ((command != "OPER") || (result != CMD_SUCCESS))
106                         return;
107                 ConfigReader Conf;
108
109                 std::string swhois;
110
111                 for (int i = 0; i < Conf.Enumerate("oper"); i++)
112                 {
113                         std::string name = Conf.ReadValue("oper", "name", i);
114
115                         if (name == params[0])
116                         {
117                                 swhois = Conf.ReadValue("oper", "swhois", i);
118                                 break;
119                         }
120                 }
121
122                 if (!swhois.length())
123                 {
124                         for (int i = 0; i < Conf.Enumerate("type"); i++)
125                         {
126                                 std::string type = Conf.ReadValue("type", "name", i);
127
128                                 if (type == user->oper)
129                                 {
130                                         swhois = Conf.ReadValue("type", "swhois", i);
131                                         break;
132                                 }
133                         }
134                 }
135
136                 if (!swhois.length())
137                         return;
138
139                 cmd.swhois.set(user, swhois);
140                 ServerInstance->PI->SendMetaData(user, "swhois", swhois);
141         }
142
143         ~ModuleSWhois()
144         {
145         }
146
147         Version GetVersion()
148         {
149                 return Version("Provides the SWHOIS command which allows setting of arbitary WHOIS lines", VF_COMMON | VF_VENDOR, API_VERSION);
150         }
151 };
152
153 MODULE_INIT(ModuleSWhois)