ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_whowas.c
Revision: 1178
Committed: Mon Aug 15 08:11:31 2011 UTC (15 years, 2 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-8/modules/m_whowas.c
File size: 4345 byte(s)
Log Message:
- Cleanup and restore older parts of the irc-command parser.
  Gives back ability to specify maximum amount of parameters
  that are processed within a command.

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 "irc_string.h"
32     #include "ircd.h"
33     #include "ircd_defs.h"
34     #include "numeric.h"
35     #include "s_serv.h"
36     #include "s_user.h"
37     #include "send.h"
38     #include "s_conf.h"
39     #include "msg.h"
40     #include "parse.h"
41     #include "modules.h"
42    
43    
44     static void m_whowas(struct Client *, struct Client *, int, char *[]);
45     static void mo_whowas(struct Client *, struct Client *, int, char *[]);
46     static void whowas_do(struct Client *, struct Client *, int, char *[]);
47    
48     struct Message whowas_msgtab = {
49 michael 1178 "WHOWAS", 0, 0, 0, MAXPARA, MFLG_SLOW, 0,
50 michael 143 { m_unregistered, m_whowas, mo_whowas, m_ignore, mo_whowas, m_ignore }
51 adx 30 };
52    
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
67     /*
68     ** m_whowas
69     ** parv[0] = sender prefix
70     ** parv[1] = nickname queried
71     */
72     static void
73     m_whowas(struct Client *client_p, struct Client *source_p,
74     int parc, char *parv[])
75     {
76     static time_t last_used = 0;
77    
78 michael 1121 if (parc < 2 || EmptyString(parv[1]))
79 adx 30 {
80     sendto_one(source_p, form_str(ERR_NONICKNAMEGIVEN),
81     me.name, source_p->name);
82     return;
83     }
84    
85 adx 269 if ((last_used + ConfigFileEntry.pace_wait) > CurrentTime)
86 adx 30 {
87     sendto_one(source_p,form_str(RPL_LOAD2HI),
88     me.name, source_p->name);
89     return;
90     }
91    
92 michael 1121 last_used = CurrentTime;
93    
94 adx 30 whowas_do(client_p, source_p, parc, parv);
95     }
96    
97     static void
98     mo_whowas(struct Client *client_p, struct Client *source_p,
99     int parc, char *parv[])
100     {
101 michael 1121 if (parc < 2 || EmptyString(parv[1]))
102 adx 30 {
103     sendto_one(source_p, form_str(ERR_NONICKNAMEGIVEN),
104     me.name, source_p->name);
105     return;
106     }
107    
108     whowas_do(client_p, source_p, parc, parv);
109     }
110    
111     static void
112     whowas_do(struct Client *client_p, struct Client *source_p,
113     int parc, char *parv[])
114     {
115     struct Whowas *temp = NULL;
116     int cur = 0;
117     int max = -1;
118 michael 143 char *p = NULL, *nick = NULL;
119 adx 30
120     if (parc > 2)
121 michael 145 {
122 adx 30 max = atoi(parv[2]);
123 michael 143
124 michael 145 if (!MyConnect(source_p) && max > 20)
125     max = 20;
126     }
127    
128 adx 30 if (parc > 3)
129 michael 143 if (hunt_server(client_p, source_p, ":%s WHOWAS %s %s :%s", 3,
130     parc, parv) != HUNTED_ISME)
131 adx 30 return;
132    
133     nick = parv[1];
134     while (*nick == ',')
135     nick++;
136     if ((p = strchr(nick,',')) != NULL)
137     *p = '\0';
138     if (*nick == '\0')
139     return;
140    
141     temp = WHOWASHASH[strhash(nick)];
142    
143     for (; temp; temp = temp->next)
144     {
145 michael 1121 if (!irccmp(nick, temp->name))
146 adx 30 {
147     sendto_one(source_p, form_str(RPL_WHOWASUSER),
148     me.name, source_p->name, temp->name,
149     temp->username, temp->hostname,
150     temp->realname);
151    
152     if (ConfigServerHide.hide_servers && !IsOper(source_p))
153     sendto_one(source_p, form_str(RPL_WHOISSERVER),
154     me.name, source_p->name, temp->name,
155     ServerInfo.network_name, myctime(temp->logoff));
156     else
157     sendto_one(source_p, form_str(RPL_WHOISSERVER),
158     me.name, source_p->name, temp->name,
159     temp->servername, myctime(temp->logoff));
160     cur++;
161     }
162    
163     if (max > 0 && cur >= max)
164     break;
165     }
166    
167     if (!cur)
168     sendto_one(source_p, form_str(ERR_WASNOSUCHNICK),
169     me.name, source_p->name, nick);
170    
171     sendto_one(source_p, form_str(RPL_ENDOFWHOWAS),
172     me.name, source_p->name, parv[1]);
173     }

Properties

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