]>
Commit | Line | Data |
---|---|---|
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 | * $Id: m_names.c 254 2005-09-21 23:35:12Z nenolod $ | |
25 | */ | |
26 | ||
27 | #include "stdinc.h" | |
28 | #include "channel.h" | |
29 | #include "client.h" | |
30 | #include "common.h" | |
31 | #include "hash.h" | |
32 | #include "match.h" | |
33 | #include "ircd.h" | |
34 | #include "numeric.h" | |
35 | #include "send.h" | |
36 | #include "s_serv.h" | |
37 | #include "s_conf.h" | |
38 | #include "msg.h" | |
39 | #include "parse.h" | |
40 | #include "modules.h" | |
41 | ||
42 | static int m_names(struct MsgBuf *, struct Client *, struct Client *, int, const char **); | |
43 | ||
44 | struct Message names_msgtab = { | |
45 | "NAMES", 0, 0, 0, 0, | |
46 | {mg_unreg, {m_names, 0}, mg_ignore, mg_ignore, mg_ignore, {m_names, 0}} | |
47 | }; | |
48 | ||
49 | mapi_clist_av1 names_clist[] = { &names_msgtab, NULL }; | |
50 | DECLARE_MODULE_AV1(names, NULL, NULL, names_clist, NULL, NULL, "$Revision: 254 $"); | |
51 | ||
52 | static void names_global(struct Client *source_p); | |
53 | ||
54 | /************************************************************************ | |
55 | * m_names() - Added by Jto 27 Apr 1989 | |
56 | ************************************************************************/ | |
57 | ||
58 | /* | |
59 | * m_names | |
60 | * parv[1] = channel | |
61 | */ | |
62 | static int | |
63 | m_names(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
64 | { | |
65 | static time_t last_used = 0; | |
66 | struct Channel *chptr = NULL; | |
67 | char *s; | |
68 | ||
69 | if(parc > 1 && !EmptyString(parv[1])) | |
70 | { | |
71 | char *p = LOCAL_COPY(parv[1]); | |
72 | if((s = strchr(p, ','))) | |
73 | *s = '\0'; | |
74 | ||
75 | if(!check_channel_name(p)) | |
76 | { | |
77 | sendto_one_numeric(source_p, ERR_BADCHANNAME, | |
78 | form_str(ERR_BADCHANNAME), | |
79 | (unsigned char *) p); | |
80 | return 0; | |
81 | } | |
82 | ||
83 | if((chptr = find_channel(p)) != NULL) | |
84 | channel_member_names(chptr, source_p, 1); | |
85 | else | |
86 | sendto_one(source_p, form_str(RPL_ENDOFNAMES), | |
87 | me.name, source_p->name, p); | |
88 | } | |
89 | else | |
90 | { | |
91 | if(!IsOper(source_p)) | |
92 | { | |
93 | if((last_used + ConfigFileEntry.pace_wait) > rb_current_time()) | |
94 | { | |
95 | sendto_one(source_p, form_str(RPL_LOAD2HI), | |
96 | me.name, source_p->name, "NAMES"); | |
97 | sendto_one(source_p, form_str(RPL_ENDOFNAMES), | |
98 | me.name, source_p->name, "*"); | |
99 | return 0; | |
100 | } | |
101 | else | |
102 | last_used = rb_current_time(); | |
103 | } | |
104 | ||
105 | names_global(source_p); | |
106 | sendto_one(source_p, form_str(RPL_ENDOFNAMES), | |
107 | me.name, source_p->name, "*"); | |
108 | } | |
109 | ||
110 | return 0; | |
111 | } | |
112 | ||
113 | /* | |
114 | * names_global | |
115 | * | |
116 | * inputs - pointer to client struct requesting names | |
117 | * output - none | |
118 | * side effects - lists all non public non secret channels | |
119 | */ | |
120 | static void | |
121 | names_global(struct Client *source_p) | |
122 | { | |
123 | int mlen; | |
124 | int tlen; | |
125 | int cur_len; | |
126 | int dont_show = NO; | |
127 | rb_dlink_node *lp, *ptr; | |
128 | struct Client *target_p; | |
129 | struct Channel *chptr = NULL; | |
130 | struct membership *msptr; | |
131 | char buf[BUFSIZE]; | |
132 | char *t; | |
133 | ||
134 | /* first do all visible channels */ | |
135 | RB_DLINK_FOREACH(ptr, global_channel_list.head) | |
136 | { | |
137 | chptr = ptr->data; | |
138 | channel_member_names(chptr, source_p, 0); | |
139 | } | |
140 | cur_len = mlen = sprintf(buf, form_str(RPL_NAMREPLY), | |
141 | me.name, source_p->name, "*", "*"); | |
142 | t = buf + mlen; | |
143 | ||
144 | /* Second, do all clients in one big sweep */ | |
145 | RB_DLINK_FOREACH(ptr, global_client_list.head) | |
146 | { | |
147 | target_p = ptr->data; | |
148 | dont_show = NO; | |
149 | ||
150 | if(!IsPerson(target_p) || IsInvisible(target_p)) | |
151 | continue; | |
152 | ||
153 | /* we want to show -i clients that are either: | |
154 | * a) not on any channels | |
155 | * b) only on +p channels | |
156 | * | |
157 | * both were missed out above. if the target is on a | |
158 | * common channel with source, its already been shown. | |
159 | */ | |
160 | RB_DLINK_FOREACH(lp, target_p->user->channel.head) | |
161 | { | |
162 | msptr = lp->data; | |
163 | chptr = msptr->chptr; | |
164 | ||
165 | if(PubChannel(chptr) || IsMember(source_p, chptr) || | |
166 | SecretChannel(chptr)) | |
167 | { | |
168 | dont_show = YES; | |
169 | break; | |
170 | } | |
171 | } | |
172 | ||
173 | if(dont_show) | |
174 | continue; | |
175 | ||
176 | if((cur_len + NICKLEN + 2) > (BUFSIZE - 3)) | |
177 | { | |
178 | sendto_one(source_p, "%s", buf); | |
179 | cur_len = mlen; | |
180 | t = buf + mlen; | |
181 | } | |
182 | ||
183 | tlen = sprintf(t, "%s ", target_p->name); | |
184 | cur_len += tlen; | |
185 | t += tlen; | |
186 | } | |
187 | ||
188 | if(cur_len > mlen) | |
189 | sendto_one(source_p, "%s", buf); | |
190 | } |