]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_userip.cpp
Merge pull request #1018 from SaberUK/insp20+hidekills
[user/henk/code/inspircd.git] / src / modules / m_userip.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
5  *   Copyright (C) 2005, 2007 Craig Edwards <craigedwards@brainbox.cc>
6  *   Copyright (C) 2006 Robin Burchell <robin+git@viroteck.net>
7  *
8  * This file is part of InspIRCd.  InspIRCd is free software: you can
9  * redistribute it and/or modify it under the terms of the GNU General Public
10  * License as published by the Free Software Foundation, version 2.
11  *
12  * This program is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
15  * details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19  */
20
21
22 #include "inspircd.h"
23
24 /* $ModDesc: Provides support for USERIP command */
25
26 /** Handle /USERIP
27  */
28 class CommandUserip : public Command
29 {
30  public:
31         CommandUserip(Module* Creator) : Command(Creator,"USERIP", 1)
32         {
33                 syntax = "<nick> [<nick> ...]";
34         }
35
36         CmdResult Handle (const std::vector<std::string> &parameters, User *user)
37         {
38                 std::string retbuf = "340 " + user->nick + " :";
39                 int nicks = 0;
40                 bool checked_privs = false;
41                 bool has_privs = false;
42
43                 for (int i = 0; i < (int)parameters.size(); i++)
44                 {
45                         User *u = ServerInstance->FindNickOnly(parameters[i]);
46                         if ((u) && (u->registered == REG_ALL))
47                         {
48                                 // Anyone may query their own IP
49                                 if (u != user)
50                                 {
51                                         if (!checked_privs)
52                                         {
53                                                 // Do not trigger the insufficient priviliges message more than once
54                                                 checked_privs = true;
55                                                 has_privs = user->HasPrivPermission("users/auspex");
56                                                 if (!has_privs)
57                                                         user->WriteNumeric(ERR_NOPRIVILEGES, "%s :Permission Denied - You do not have the required operator privileges",user->nick.c_str());
58                                         }
59
60                                         if (!has_privs)
61                                                 continue;
62                                 }
63
64                                 retbuf = retbuf + u->nick + (IS_OPER(u) ? "*" : "") + "=";
65                                 if (IS_AWAY(u))
66                                         retbuf += "-";
67                                 else
68                                         retbuf += "+";
69                                 retbuf += u->ident + "@" + u->GetIPString() + " ";
70                                 nicks++;
71                         }
72                 }
73
74                 if (nicks != 0)
75                         user->WriteServ(retbuf);
76
77                 return CMD_SUCCESS;
78         }
79 };
80
81 class ModuleUserIP : public Module
82 {
83         CommandUserip cmd;
84  public:
85         ModuleUserIP()
86                 : cmd(this)
87         {
88         }
89
90         void init()
91         {
92                 ServerInstance->Modules->AddService(cmd);
93                 Implementation eventlist[] = { I_On005Numeric };
94                 ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
95         }
96
97         virtual void On005Numeric(std::string &output)
98         {
99                 output = output + " USERIP";
100         }
101
102         virtual ~ModuleUserIP()
103         {
104         }
105
106         virtual Version GetVersion()
107         {
108                 return Version("Provides support for USERIP command",VF_VENDOR);
109         }
110
111 };
112
113 MODULE_INIT(ModuleUserIP)
114