]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_userip.cpp
Merge pull request #514 from SaberUK/master+virtual-cleanup
[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                 flags_needed = 'o'; 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
41                 for (int i = 0; i < (int)parameters.size(); i++)
42                 {
43                         User *u = ServerInstance->FindNick(parameters[i]);
44                         if ((u) && (u->registered == REG_ALL))
45                         {
46                                 retbuf = retbuf + u->nick + (u->IsOper() ? "*" : "") + "=";
47                                 if (u->IsAway())
48                                         retbuf += "-";
49                                 else
50                                         retbuf += "+";
51                                 retbuf += u->ident + "@" + u->GetIPString() + " ";
52                                 nicks++;
53                         }
54                 }
55
56                 if (nicks != 0)
57                         user->WriteServ(retbuf);
58
59                 /* Dont send to the network */
60                 return CMD_SUCCESS;
61         }
62 };
63
64 class ModuleUserIP : public Module
65 {
66         CommandUserip cmd;
67  public:
68         ModuleUserIP()
69                 : cmd(this)
70         {
71         }
72
73         void init() CXX11_OVERRIDE
74         {
75                 ServerInstance->Modules->AddService(cmd);
76                 Implementation eventlist[] = { I_On005Numeric };
77                 ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
78         }
79
80         void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
81         {
82                 tokens["USERIP"];
83         }
84
85         Version GetVersion() CXX11_OVERRIDE
86         {
87                 return Version("Provides support for USERIP command",VF_VENDOR);
88         }
89 };
90
91 MODULE_INIT(ModuleUserIP)