]> jfr.im git - irc/rqf/shadowircd.git/blob - modules/m_names.c
Branch Merge
[irc/rqf/shadowircd.git] / modules / m_names.c
1 /*
2 * ircd-ratbox: A slightly useful ircd.
3 * m_names.c: Shows the users who are online.
4 *
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2005 ircd-ratbox development team
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 * USA
23 *
24 */
25
26 #include "stdinc.h"
27 #include "channel.h"
28 #include "client.h"
29 #include "common.h"
30 #include "hash.h"
31 #include "match.h"
32 #include "ircd.h"
33 #include "numeric.h"
34 #include "send.h"
35 #include "s_serv.h"
36 #include "s_conf.h"
37 #include "msg.h"
38 #include "parse.h"
39 #include "modules.h"
40
41 static int m_names(struct Client *, struct Client *, int, const char **);
42
43 struct Message names_msgtab = {
44 "NAMES", 0, 0, 0, MFLG_SLOW,
45 {mg_unreg, {m_names, 0}, mg_ignore, mg_ignore, mg_ignore, {m_names, 0}}
46 };
47
48 mapi_clist_av1 names_clist[] = { &names_msgtab, NULL };
49 DECLARE_MODULE_AV1(names, NULL, NULL, names_clist, NULL, NULL, "$Revision: 254 $");
50
51 static void names_global(struct Client *source_p);
52
53 /************************************************************************
54 * m_names() - Added by Jto 27 Apr 1989
55 ************************************************************************/
56
57 /*
58 * m_names
59 * parv[1] = channel
60 */
61 static int
62 m_names(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
63 {
64 static time_t last_used = 0;
65 struct Channel *chptr = NULL;
66 char *s;
67
68 if(parc > 1 && !EmptyString(parv[1]))
69 {
70 char *p = LOCAL_COPY(parv[1]);
71 if((s = strchr(p, ',')))
72 *s = '\0';
73
74 if(!check_channel_name(p))
75 {
76 sendto_one_numeric(source_p, ERR_BADCHANNAME,
77 form_str(ERR_BADCHANNAME),
78 (unsigned char *) p);
79 return 0;
80 }
81
82 if((chptr = find_channel(p)) != NULL)
83 channel_member_names(chptr, source_p, 1);
84 else
85 sendto_one(source_p, form_str(RPL_ENDOFNAMES),
86 me.name, source_p->name, p);
87 }
88 else
89 {
90 if(!IsOper(source_p))
91 {
92 if((last_used + ConfigFileEntry.pace_wait) > rb_current_time())
93 {
94 sendto_one(source_p, form_str(RPL_LOAD2HI),
95 me.name, source_p->name, "NAMES");
96 sendto_one(source_p, form_str(RPL_ENDOFNAMES),
97 me.name, source_p->name, "*");
98 return 0;
99 }
100 else
101 last_used = rb_current_time();
102 }
103
104 names_global(source_p);
105 sendto_one(source_p, form_str(RPL_ENDOFNAMES),
106 me.name, source_p->name, "*");
107 }
108
109 return 0;
110 }
111
112 /*
113 * names_global
114 *
115 * inputs - pointer to client struct requesting names
116 * output - none
117 * side effects - lists all non public non secret channels
118 */
119 static void
120 names_global(struct Client *source_p)
121 {
122 int mlen;
123 int tlen;
124 int cur_len;
125 int dont_show = NO;
126 rb_dlink_node *lp, *ptr;
127 struct Client *target_p;
128 struct Channel *chptr = NULL;
129 struct membership *msptr;
130 char buf[BUFSIZE];
131 char *t;
132
133 /* first do all visible channels */
134 RB_DLINK_FOREACH(ptr, global_channel_list.head)
135 {
136 chptr = ptr->data;
137 channel_member_names(chptr, source_p, 0);
138 }
139 cur_len = mlen = rb_sprintf(buf, form_str(RPL_NAMREPLY),
140 me.name, source_p->name, "*", "*");
141 t = buf + mlen;
142
143 /* Second, do all clients in one big sweep */
144 RB_DLINK_FOREACH(ptr, global_client_list.head)
145 {
146 target_p = ptr->data;
147 dont_show = NO;
148
149 if(!IsPerson(target_p) || IsInvisible(target_p))
150 continue;
151
152 /* we want to show -i clients that are either:
153 * a) not on any channels
154 * b) only on +p channels
155 *
156 * both were missed out above. if the target is on a
157 * common channel with source, its already been shown.
158 */
159 RB_DLINK_FOREACH(lp, target_p->user->channel.head)
160 {
161 msptr = lp->data;
162 chptr = msptr->chptr;
163
164 if(PubChannel(chptr) || IsMember(source_p, chptr) ||
165 SecretChannel(chptr))
166 {
167 dont_show = YES;
168 break;
169 }
170 }
171
172 if(dont_show)
173 continue;
174
175 if((cur_len + NICKLEN + 2) > (BUFSIZE - 3))
176 {
177 sendto_one(source_p, "%s", buf);
178 cur_len = mlen;
179 t = buf + mlen;
180 }
181
182 tlen = rb_sprintf(t, "%s ", target_p->name);
183 cur_len += tlen;
184 t += tlen;
185 }
186
187 if(cur_len > mlen)
188 sendto_one(source_p, "%s", buf);
189 }