ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_whowas.c
Revision: 6513
Committed: Sun Sep 6 18:32:38 2015 UTC (8 years, 6 months ago) by michael
Content type: text/x-csrc
File size: 5629 byte(s)
Log Message:
- Change myctime() to use strftime() instead of ctime(); rename myctime() to date_ctime()

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 1997-2015 ircd-hybrid development team
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 * USA
20 */
21
22 /*! \file m_whowas.c
23 * \brief Includes required functions for processing the WHOWAS command.
24 * \version $Id$
25 */
26
27 #include "stdinc.h"
28 #include "list.h"
29 #include "whowas.h"
30 #include "client.h"
31 #include "hash.h"
32 #include "irc_string.h"
33 #include "ircd.h"
34 #include "ircd_defs.h"
35 #include "numeric.h"
36 #include "misc.h"
37 #include "server.h"
38 #include "send.h"
39 #include "conf.h"
40 #include "parse.h"
41 #include "modules.h"
42
43
44 enum { WHOWAS_MAX_REPLIES = 20 }; /* Only applies to remote clients */
45
46 static void
47 do_whowas(struct Client *source_p, const int parc, char *parv[])
48 {
49 int cur = 0;
50 int max = -1;
51 const dlink_node *node = NULL;
52
53 if (parc > 2 && !EmptyString(parv[2]))
54 max = atoi(parv[2]);
55
56 if (!MyConnect(source_p) && (max <= 0 || max > WHOWAS_MAX_REPLIES))
57 max = WHOWAS_MAX_REPLIES;
58
59 DLINK_FOREACH(node, WHOWASHASH[strhash(parv[1])].head)
60 {
61 const struct Whowas *temp = node->data;
62
63 if (!irccmp(parv[1], temp->name))
64 {
65 sendto_one_numeric(source_p, &me, RPL_WHOWASUSER, temp->name,
66 temp->username, temp->hostname,
67 temp->realname);
68
69 if (HasUMode(source_p, UMODE_OPER))
70 if (strcmp(temp->sockhost, "0")) /* XXX: TBR */
71 sendto_one_numeric(source_p, &me, RPL_WHOISACTUALLY, temp->name,
72 temp->username, temp->hostname,
73 temp->sockhost);
74
75 if (!IsDigit(temp->account[0]) && temp->account[0] != '*')
76 sendto_one_numeric(source_p, &me, RPL_WHOISACCOUNT, temp->name, temp->account, "was");
77
78 if ((temp->shide || ConfigServerHide.hide_servers) && !HasUMode(source_p, UMODE_OPER))
79 sendto_one_numeric(source_p, &me, RPL_WHOISSERVER, temp->name,
80 ConfigServerInfo.network_name, date_ctime(temp->logoff));
81 else
82 sendto_one_numeric(source_p, &me, RPL_WHOISSERVER, temp->name,
83 temp->servername, date_ctime(temp->logoff));
84 ++cur;
85 }
86
87 if (max > 0 && cur >= max)
88 break;
89 }
90
91 if (!cur)
92 sendto_one_numeric(source_p, &me, ERR_WASNOSUCHNICK, parv[1]);
93
94 sendto_one_numeric(source_p, &me, RPL_ENDOFWHOWAS, parv[1]);
95 }
96
97 /*! \brief WHOWAS command handler
98 *
99 * \param source_p Pointer to allocated Client struct from which the message
100 * originally comes from. This can be a local or remote client.
101 * \param parc Integer holding the number of supplied arguments.
102 * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
103 * pointers.
104 * \note Valid arguments for this command are:
105 * - parv[0] = command
106 * - parv[1] = nickname
107 * - parv[2] = count
108 * - parv[3] = nickname/servername
109 */
110 static int
111 m_whowas(struct Client *source_p, int parc, char *parv[])
112 {
113 static time_t last_used = 0;
114
115 if (parc < 2 || EmptyString(parv[1]))
116 {
117 sendto_one_numeric(source_p, &me, ERR_NONICKNAMEGIVEN);
118 return 0;
119 }
120
121 if ((last_used + ConfigGeneral.pace_wait) > CurrentTime)
122 {
123 sendto_one_numeric(source_p, &me, RPL_LOAD2HI, "WHOWAS");
124 return 0;
125 }
126
127 last_used = CurrentTime;
128
129 if (!ConfigServerHide.disable_remote_commands)
130 if (hunt_server(source_p, ":%s WHOWAS %s %s :%s", 3, parc, parv) != HUNTED_ISME)
131 return 0;
132
133 do_whowas(source_p, parc, parv);
134 return 0;
135 }
136
137 /*! \brief WHOWAS command handler
138 *
139 * \param source_p Pointer to allocated Client struct from which the message
140 * originally comes from. This can be a local or remote client.
141 * \param parc Integer holding the number of supplied arguments.
142 * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
143 * pointers.
144 * \note Valid arguments for this command are:
145 * - parv[0] = command
146 * - parv[1] = nickname
147 * - parv[2] = count
148 * - parv[3] = nickname/servername
149 */
150 static int
151 ms_whowas(struct Client *source_p, int parc, char *parv[])
152 {
153 if (parc < 2 || EmptyString(parv[1]))
154 {
155 sendto_one_numeric(source_p, &me, ERR_NONICKNAMEGIVEN);
156 return 0;
157 }
158
159 if (hunt_server(source_p, ":%s WHOWAS %s %s :%s", 3, parc, parv) != HUNTED_ISME)
160 return 0;
161
162 do_whowas(source_p, parc, parv);
163 return 0;
164 }
165
166 static struct Message whowas_msgtab =
167 {
168 .cmd = "WHOWAS",
169 .args_max = MAXPARA,
170 .handlers[UNREGISTERED_HANDLER] = m_unregistered,
171 .handlers[CLIENT_HANDLER] = m_whowas,
172 .handlers[SERVER_HANDLER] = ms_whowas,
173 .handlers[ENCAP_HANDLER] = m_ignore,
174 .handlers[OPER_HANDLER] = ms_whowas
175 };
176
177 static void
178 module_init(void)
179 {
180 mod_add_cmd(&whowas_msgtab);
181 }
182
183 static void
184 module_exit(void)
185 {
186 mod_del_cmd(&whowas_msgtab);
187 }
188
189 struct module module_entry =
190 {
191 .version = "$Revision$",
192 .modinit = module_init,
193 .modexit = module_exit,
194 };

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision