]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_showwhois.cpp
Remove "servermode" parameter, replace with IS_FAKE() which is more reliable
[user/henk/code/inspircd.git] / src / modules / m_showwhois.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: Allows opers to set +W to see when a user uses WHOIS on them */
17
18 /** Handle user mode +W
19  */
20 class SeeWhois : public ModeHandler
21 {
22  public:
23         SeeWhois(InspIRCd* Instance, Module* Creator, bool IsOpersOnly) : ModeHandler(Instance, Creator, 'W', 0, 0, false, MODETYPE_USER, IsOpersOnly) { }
24
25         ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding)
26         {
27                 if (adding)
28                 {
29                         if (!dest->IsModeSet('W'))
30                         {
31                                 dest->SetMode('W',true);
32                                 return MODEACTION_ALLOW;
33                         }
34                 }
35                 else
36                 {
37                         if (dest->IsModeSet('W'))
38                         {
39                                 dest->SetMode('W',false);
40                                 return MODEACTION_ALLOW;
41                         }
42                 }
43
44                 return MODEACTION_DENY;
45         }
46 };
47
48 class WhoisNoticeCmd : public Command
49 {
50  public:
51         WhoisNoticeCmd(InspIRCd* Instance, Module* Creator) : Command(Instance, Creator,"WHOISNOTICE", 0, 1)
52         {
53         }
54
55         void HandleFast(User* dest, User* src)
56         {
57                 dest->WriteServ("NOTICE %s :*** %s (%s@%s) did a /whois on you",
58                         dest->nick.c_str(), src->nick.c_str(), src->ident.c_str(),
59                         dest->HasPrivPermission("users/auspex") ? src->host.c_str() : src->dhost.c_str());
60         }
61
62         CmdResult Handle(const std::vector<std::string> &parameters, User *user)
63         {
64                 User* dest = ServerInstance->FindNick(parameters[0]);
65
66                 if (IS_LOCAL(dest))
67                         HandleFast(dest, user);
68
69                 return CMD_SUCCESS;
70         }
71 };
72
73 class ModuleShowwhois : public Module
74 {
75         bool ShowWhoisFromOpers;
76         SeeWhois* sw;
77         WhoisNoticeCmd cmd;
78
79  public:
80
81         ModuleShowwhois(InspIRCd* Me) : Module(Me), cmd(Me, this)
82         {
83                 ConfigReader conf(ServerInstance);
84                 bool OpersOnly = conf.ReadFlag("showwhois", "opersonly", "yes", 0);
85                 ShowWhoisFromOpers = conf.ReadFlag("showwhois", "showfromopers", "yes", 0);
86
87                 sw = new SeeWhois(ServerInstance, this, OpersOnly);
88                 if (!ServerInstance->Modes->AddMode(sw))
89                         throw ModuleException("Could not add new modes!");
90                 ServerInstance->AddCommand(&cmd);
91                 Implementation eventlist[] = { I_OnWhois };
92                 ServerInstance->Modules->Attach(eventlist, this, 1);
93         }
94
95         ~ModuleShowwhois()
96         {
97                 ServerInstance->Modes->DelMode(sw);
98                 delete sw;
99         }
100
101         virtual Version GetVersion()
102         {
103                 return Version("$Id$",VF_COMMON|VF_VENDOR,API_VERSION);
104         }
105
106         virtual void OnWhois(User* source, User* dest)
107         {
108                 if (!dest->IsModeSet('W') || source == dest)
109                         return;
110
111                 if (!ShowWhoisFromOpers && (IS_OPER(source) != IS_OPER(dest)))
112                         return;
113
114                 if (IS_LOCAL(dest))
115                 {
116                         cmd.HandleFast(dest, source);
117                 }
118                 else
119                 {
120                         std::vector<std::string> params;
121                         params.push_back(dest->server);
122                         params.push_back("WHOISNOTICE");
123                         params.push_back(dest->uuid);
124                         ServerInstance->PI->SendEncapsulatedData(params);
125                 }
126         }
127
128 };
129
130 MODULE_INIT(ModuleShowwhois)