]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_userhost.cpp
Merge pull request #70 from Shawn-Smith/insp20+chancreatefix
[user/henk/code/inspircd.git] / src / commands / cmd_userhost.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2010 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 #ifndef CMD_USERHOST_H
17 #define CMD_USERHOST_H
18
19 // include the common header files
20
21 #include "users.h"
22 #include "channels.h"
23
24 /** Handle /USERHOST. These command handlers can be reloaded by the core,
25  * and handle basic RFC1459 commands. Commands within modules work
26  * the same way, however, they can be fully unloaded, where these
27  * may not.
28  */
29 class CommandUserhost : public Command
30 {
31  public:
32         /** Constructor for userhost.
33          */
34         CommandUserhost ( Module* parent) : Command(parent,"USERHOST",0,1) { syntax = "<nick>{,<nick>}"; }
35         /** Handle command.
36          * @param parameters The parameters to the comamnd
37          * @param pcnt The number of parameters passed to teh command
38          * @param user The user issuing the command
39          * @return A value from CmdResult to indicate command success or failure.
40          */
41         CmdResult Handle(const std::vector<std::string>& parameters, User *user);
42 };
43
44 #endif
45
46
47 CmdResult CommandUserhost::Handle (const std::vector<std::string>& parameters, User *user)
48 {
49         std::string retbuf = std::string("302 ") + user->nick + " :";
50
51         for (unsigned int i = 0; i < parameters.size(); i++)
52         {
53                 User *u = ServerInstance->FindNickOnly(parameters[i]);
54
55                 if ((u) && (u->registered == REG_ALL))
56                 {
57                         retbuf = retbuf + u->nick;
58
59                         if (IS_OPER(u))
60                         {
61                                 retbuf = retbuf + "*=";
62                         }
63                         else
64                         {
65                                 retbuf = retbuf + "=";
66                         }
67
68                         if (IS_AWAY(u))
69                                 retbuf += "-";
70                         else
71                                 retbuf += "+";
72
73                         retbuf = retbuf + u->ident + "@";
74
75                         if (user->HasPrivPermission("users/auspex"))
76                         {
77                                 retbuf = retbuf + u->host;
78                         }
79                         else
80                         {
81                                 retbuf = retbuf + u->dhost;
82                         }
83
84                         retbuf = retbuf + " ";
85                 }
86         }
87
88         user->WriteServ(retbuf);
89
90         return CMD_SUCCESS;
91 }
92
93 COMMAND_INIT(CommandUserhost)