ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_whowas.c
Revision: 8653
Committed: Sun Nov 11 16:40:11 2018 UTC (7 years, 8 months ago) by michael
Content type: text/x-csrc
File size: 5582 byte(s)
Log Message:
- Use bool data type in struct Whowas

File Contents

# User Rev Content
1 adx 30 /*
2 michael 2820 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 adx 30 *
4 michael 8279 * Copyright (c) 1997-2018 ircd-hybrid development team
5 adx 30 *
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 michael 4565 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 adx 30 * USA
20     */
21    
22 michael 2820 /*! \file m_whowas.c
23     * \brief Includes required functions for processing the WHOWAS command.
24     * \version $Id$
25     */
26    
27 adx 30 #include "stdinc.h"
28 michael 1358 #include "list.h"
29 adx 30 #include "whowas.h"
30     #include "client.h"
31     #include "hash.h"
32     #include "irc_string.h"
33     #include "ircd.h"
34     #include "numeric.h"
35 michael 3347 #include "misc.h"
36     #include "server.h"
37 adx 30 #include "send.h"
38 michael 1309 #include "conf.h"
39 adx 30 #include "parse.h"
40     #include "modules.h"
41    
42    
43 michael 6350 enum { WHOWAS_MAX_REPLIES = 20 }; /* Only applies to remote clients */
44 michael 5638
45 adx 30 static void
46 michael 3338 do_whowas(struct Client *source_p, const int parc, char *parv[])
47 adx 30 {
48 michael 7989 int count = 0, max = -1;
49 michael 7687 dlink_node *node;
50 adx 30
51 michael 2076 if (parc > 2 && !EmptyString(parv[2]))
52 michael 5638 max = atoi(parv[2]);
53 adx 30
54 michael 5638 if (!MyConnect(source_p) && (max <= 0 || max > WHOWAS_MAX_REPLIES))
55     max = WHOWAS_MAX_REPLIES;
56    
57 michael 7449 DLINK_FOREACH(node, whowas_get_hash(strhash(parv[1]))->head)
58 michael 1358 {
59 michael 6652 const struct Whowas *whowas = node->data;
60 adx 30
61 michael 8603 if (irccmp(parv[1], whowas->name) == 0)
62 adx 30 {
63 michael 6652 sendto_one_numeric(source_p, &me, RPL_WHOWASUSER, whowas->name,
64     whowas->username, whowas->hostname,
65     whowas->realname);
66 adx 30
67 michael 5631 if (HasUMode(source_p, UMODE_OPER))
68 michael 6831 sendto_one_numeric(source_p, &me, RPL_WHOISACTUALLY, whowas->name,
69 michael 8214 whowas->username, whowas->realhost,
70 michael 6831 whowas->sockhost);
71 michael 5631
72 michael 6827 if (strcmp(whowas->account, "*"))
73 michael 6652 sendto_one_numeric(source_p, &me, RPL_WHOISACCOUNT, whowas->name, whowas->account, "was");
74 michael 4767
75 michael 8653 if ((whowas->server_hidden || ConfigServerHide.hide_servers) && !HasUMode(source_p, UMODE_OPER))
76 michael 6652 sendto_one_numeric(source_p, &me, RPL_WHOISSERVER, whowas->name,
77     ConfigServerInfo.network_name, date_ctime(whowas->logoff));
78 adx 30 else
79 michael 6652 sendto_one_numeric(source_p, &me, RPL_WHOISSERVER, whowas->name,
80     whowas->servername, date_ctime(whowas->logoff));
81 michael 7989 ++count;
82 adx 30 }
83    
84 michael 7989 if (max > 0 && count >= max)
85 adx 30 break;
86     }
87    
88 michael 8603 if (count == 0)
89 michael 3109 sendto_one_numeric(source_p, &me, ERR_WASNOSUCHNICK, parv[1]);
90 adx 30
91 michael 3109 sendto_one_numeric(source_p, &me, RPL_ENDOFWHOWAS, parv[1]);
92 adx 30 }
93 michael 1230
94 michael 3295 /*! \brief WHOWAS command handler
95     *
96     * \param source_p Pointer to allocated Client struct from which the message
97     * originally comes from. This can be a local or remote client.
98     * \param parc Integer holding the number of supplied arguments.
99     * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
100     * pointers.
101     * \note Valid arguments for this command are:
102     * - parv[0] = command
103     * - parv[1] = nickname
104     * - parv[2] = count
105     * - parv[3] = nickname/servername
106     */
107 michael 2820 static int
108 michael 3156 m_whowas(struct Client *source_p, int parc, char *parv[])
109 michael 1230 {
110 michael 7330 static uintmax_t last_used = 0;
111 michael 1230
112     if (parc < 2 || EmptyString(parv[1]))
113     {
114 michael 3109 sendto_one_numeric(source_p, &me, ERR_NONICKNAMEGIVEN);
115 michael 2820 return 0;
116 michael 1230 }
117    
118 michael 4340 if ((last_used + ConfigGeneral.pace_wait) > CurrentTime)
119 michael 1230 {
120 michael 4759 sendto_one_numeric(source_p, &me, RPL_LOAD2HI, "WHOWAS");
121 michael 2820 return 0;
122 michael 1230 }
123    
124     last_used = CurrentTime;
125    
126 michael 8603 if (ConfigServerHide.disable_remote_commands == 0)
127 michael 7971 if (server_hunt(source_p, ":%s WHOWAS %s %s :%s", 3, parc, parv)->ret != HUNTED_ISME)
128 michael 2986 return 0;
129    
130 michael 3338 do_whowas(source_p, parc, parv);
131 michael 2820 return 0;
132 michael 1230 }
133    
134 michael 3295 /*! \brief WHOWAS command handler
135     *
136     * \param source_p Pointer to allocated Client struct from which the message
137     * originally comes from. This can be a local or remote client.
138     * \param parc Integer holding the number of supplied arguments.
139     * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
140     * pointers.
141     * \note Valid arguments for this command are:
142     * - parv[0] = command
143     * - parv[1] = nickname
144     * - parv[2] = count
145     * - parv[3] = nickname/servername
146     */
147 michael 2820 static int
148 michael 3346 ms_whowas(struct Client *source_p, int parc, char *parv[])
149 michael 1230 {
150     if (parc < 2 || EmptyString(parv[1]))
151     {
152 michael 3109 sendto_one_numeric(source_p, &me, ERR_NONICKNAMEGIVEN);
153 michael 2820 return 0;
154 michael 1230 }
155    
156 michael 7971 if (server_hunt(source_p, ":%s WHOWAS %s %s :%s", 3, parc, parv)->ret != HUNTED_ISME)
157 michael 4720 return 0;
158 michael 2986
159 michael 3338 do_whowas(source_p, parc, parv);
160 michael 2820 return 0;
161 michael 1230 }
162    
163 michael 2820 static struct Message whowas_msgtab =
164     {
165 michael 5881 .cmd = "WHOWAS",
166     .args_max = MAXPARA,
167     .handlers[UNREGISTERED_HANDLER] = m_unregistered,
168     .handlers[CLIENT_HANDLER] = m_whowas,
169     .handlers[SERVER_HANDLER] = ms_whowas,
170     .handlers[ENCAP_HANDLER] = m_ignore,
171     .handlers[OPER_HANDLER] = ms_whowas
172 michael 1230 };
173    
174     static void
175     module_init(void)
176     {
177     mod_add_cmd(&whowas_msgtab);
178     }
179    
180     static void
181     module_exit(void)
182     {
183     mod_del_cmd(&whowas_msgtab);
184     }
185    
186 michael 2820 struct module module_entry =
187     {
188 michael 1230 .version = "$Revision$",
189     .modinit = module_init,
190     .modexit = module_exit,
191     };

Properties

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