ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/modules/m_whowas.c
Revision: 270
Committed: Mon Nov 14 19:39:35 2005 UTC (20 years, 9 months ago) by adx
Content type: text/x-csrc
File size: 4364 byte(s)
Log Message:
+ ported rate limiting fixes from 7.2

File Contents

# User Rev Content
1 adx 30 /*
2     * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3     * m_whois.c: Shows who a user was.
4     *
5     * Copyright (C) 2002 by the past and present ircd coders, and others.
6     *
7     * This program is free software; you can redistribute it and/or modify
8     * it under the terms of the GNU General Public License as published by
9     * the Free Software Foundation; either version 2 of the License, or
10     * (at your option) any later version.
11     *
12     * This program is distributed in the hope that it will be useful,
13     * but WITHOUT ANY WARRANTY; without even the implied warranty of
14     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     * GNU General Public License for more details.
16     *
17     * You should have received a copy of the GNU General Public License
18     * along with this program; if not, write to the Free Software
19     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20     * USA
21     *
22 knight 31 * $Id$
23 adx 30 */
24    
25     #include "stdinc.h"
26     #include "whowas.h"
27     #include "handlers.h"
28     #include "client.h"
29     #include "common.h"
30     #include "hash.h"
31     #include "ircd.h"
32     #include "ircd_defs.h"
33     #include "numeric.h"
34     #include "s_serv.h"
35     #include "s_user.h"
36     #include "send.h"
37     #include "s_conf.h"
38     #include "msg.h"
39     #include "parse.h"
40     #include "modules.h"
41    
42    
43     static void m_whowas(struct Client *, struct Client *, int, char *[]);
44     static void mo_whowas(struct Client *, struct Client *, int, char *[]);
45     static void whowas_do(struct Client *, struct Client *, int, char *[]);
46    
47     struct Message whowas_msgtab = {
48     "WHOWAS", 0, 0, 0, 0, MFLG_SLOW, 0,
49 michael 142 { m_unregistered, m_whowas, mo_whowas, m_ignore, mo_whowas, m_ignore }
50 adx 30 };
51    
52     #ifndef STATIC_MODULES
53     void
54     _modinit(void)
55     {
56     mod_add_cmd(&whowas_msgtab);
57     }
58    
59     void
60     _moddeinit(void)
61     {
62     mod_del_cmd(&whowas_msgtab);
63     }
64    
65 knight 31 const char *_version = "$Revision$";
66 adx 30 #endif
67    
68     /*
69     ** m_whowas
70     ** parv[0] = sender prefix
71     ** parv[1] = nickname queried
72     */
73     static void
74     m_whowas(struct Client *client_p, struct Client *source_p,
75     int parc, char *parv[])
76     {
77     static time_t last_used = 0;
78    
79     if (parc < 2 || *parv[1] == '\0')
80     {
81     sendto_one(source_p, form_str(ERR_NONICKNAMEGIVEN),
82     me.name, source_p->name);
83     return;
84     }
85    
86 adx 270 if ((last_used + ConfigFileEntry.pace_wait) > CurrentTime)
87 adx 30 {
88     sendto_one(source_p,form_str(RPL_LOAD2HI),
89     me.name, source_p->name);
90     return;
91     }
92    
93 michael 191 last_used = CurrentTime;
94    
95 adx 30 whowas_do(client_p, source_p, parc, parv);
96     }
97    
98     static void
99     mo_whowas(struct Client *client_p, struct Client *source_p,
100     int parc, char *parv[])
101     {
102     if (parc < 2 || *parv[1] == '\0')
103     {
104     sendto_one(source_p, form_str(ERR_NONICKNAMEGIVEN),
105     me.name, source_p->name);
106     return;
107     }
108    
109     whowas_do(client_p, source_p, parc, parv);
110     }
111    
112     static void
113     whowas_do(struct Client *client_p, struct Client *source_p,
114     int parc, char *parv[])
115     {
116 michael 191 const dlink_node *ptr = NULL;
117 adx 30 int cur = 0;
118     int max = -1;
119 michael 142 char *p = NULL, *nick = NULL;
120 adx 30
121     if (parc > 2)
122 michael 144 {
123 adx 30 max = atoi(parv[2]);
124 michael 142
125 michael 144 if (!MyConnect(source_p) && max > 20)
126     max = 20;
127     }
128    
129 adx 30 if (parc > 3)
130 michael 142 if (hunt_server(client_p, source_p, ":%s WHOWAS %s %s :%s", 3,
131     parc, parv) != HUNTED_ISME)
132 adx 30 return;
133    
134     nick = parv[1];
135     while (*nick == ',')
136     nick++;
137     if ((p = strchr(nick,',')) != NULL)
138     *p = '\0';
139     if (*nick == '\0')
140     return;
141    
142 michael 191 DLINK_FOREACH(ptr, WHOWASHASH[strhash(nick)].head)
143 adx 30 {
144 michael 191 const struct Whowas *temp = ptr->data;
145    
146     if (!irccmp(nick, temp->name))
147 adx 30 {
148     sendto_one(source_p, form_str(RPL_WHOWASUSER),
149     me.name, source_p->name, temp->name,
150     temp->username, temp->hostname,
151     temp->realname);
152    
153     if (ConfigServerHide.hide_servers && !IsOper(source_p))
154     sendto_one(source_p, form_str(RPL_WHOISSERVER),
155     me.name, source_p->name, temp->name,
156     ServerInfo.network_name, myctime(temp->logoff));
157     else
158     sendto_one(source_p, form_str(RPL_WHOISSERVER),
159     me.name, source_p->name, temp->name,
160     temp->servername, myctime(temp->logoff));
161 michael 142 ++cur;
162 adx 30 }
163    
164     if (max > 0 && cur >= max)
165     break;
166     }
167    
168     if (!cur)
169     sendto_one(source_p, form_str(ERR_WASNOSUCHNICK),
170     me.name, source_p->name, nick);
171    
172     sendto_one(source_p, form_str(RPL_ENDOFWHOWAS),
173     me.name, source_p->name, parv[1]);
174     }

Properties

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