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