1 |
adx |
30 |
/* |
2 |
|
|
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
3 |
|
|
* m_list.c: List channel given or all channels. |
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 |
michael |
1011 |
#include "list.h" |
27 |
adx |
30 |
#include "channel.h" |
28 |
|
|
#include "channel_mode.h" |
29 |
|
|
#include "client.h" |
30 |
|
|
#include "hash.h" |
31 |
|
|
#include "irc_string.h" |
32 |
|
|
#include "ircd.h" |
33 |
|
|
#include "numeric.h" |
34 |
michael |
1309 |
#include "conf.h" |
35 |
adx |
30 |
#include "s_serv.h" |
36 |
|
|
#include "send.h" |
37 |
|
|
#include "parse.h" |
38 |
|
|
#include "modules.h" |
39 |
|
|
#include "s_user.h" |
40 |
|
|
|
41 |
|
|
|
42 |
|
|
static int |
43 |
|
|
has_wildcards(const char *s) |
44 |
|
|
{ |
45 |
|
|
char c; |
46 |
|
|
|
47 |
|
|
while ((c = *s++)) |
48 |
|
|
if (IsMWildChar(c)) |
49 |
|
|
return 1; |
50 |
|
|
|
51 |
|
|
return 0; |
52 |
|
|
} |
53 |
|
|
|
54 |
|
|
static void |
55 |
|
|
do_list(struct Client *source_p, int parc, char *parv[]) |
56 |
|
|
{ |
57 |
|
|
struct ListTask *lt; |
58 |
|
|
int no_masked_channels; |
59 |
|
|
|
60 |
michael |
885 |
if (source_p->localClient->list_task != NULL) |
61 |
adx |
30 |
{ |
62 |
michael |
885 |
free_list_task(source_p->localClient->list_task, source_p); |
63 |
|
|
sendto_one(source_p, form_str(RPL_LISTEND), me.name, source_p->name); |
64 |
|
|
return; |
65 |
adx |
30 |
} |
66 |
|
|
|
67 |
michael |
885 |
lt = MyMalloc(sizeof(struct ListTask)); |
68 |
adx |
30 |
lt->users_max = UINT_MAX; |
69 |
|
|
lt->created_max = UINT_MAX; |
70 |
|
|
lt->topicts_max = UINT_MAX; |
71 |
michael |
885 |
source_p->localClient->list_task = lt; |
72 |
|
|
|
73 |
adx |
30 |
no_masked_channels = 1; |
74 |
|
|
|
75 |
|
|
if (parc > 1) |
76 |
|
|
{ |
77 |
michael |
968 |
char *opt, *save = NULL; |
78 |
adx |
30 |
dlink_list *list; |
79 |
|
|
int i, errors = 0; |
80 |
|
|
|
81 |
|
|
for (opt = strtoken(&save, parv[1], ","); opt != NULL; |
82 |
|
|
opt = strtoken(&save, NULL, ",")) |
83 |
|
|
switch (*opt) |
84 |
|
|
{ |
85 |
|
|
case '<': if ((i = atoi(opt + 1)) > 0) |
86 |
michael |
1121 |
lt->users_max = (unsigned int) i - 1; |
87 |
adx |
30 |
else |
88 |
michael |
1121 |
errors = 1; |
89 |
|
|
break; |
90 |
adx |
30 |
case '>': if ((i = atoi(opt + 1)) >= 0) |
91 |
michael |
1121 |
lt->users_min = (unsigned int) i + 1; |
92 |
|
|
else |
93 |
|
|
errors = 1; |
94 |
|
|
break; |
95 |
adx |
30 |
case '-': break; |
96 |
|
|
case 'C': |
97 |
michael |
1121 |
case 'c': switch (*++opt) |
98 |
|
|
{ |
99 |
adx |
30 |
case '<': if ((i = atoi(opt + 1)) >= 0) |
100 |
|
|
lt->created_max = (unsigned int) (CurrentTime |
101 |
|
|
- 60 * i); |
102 |
|
|
else |
103 |
|
|
errors = 1; |
104 |
|
|
break; |
105 |
|
|
case '>': if ((i = atoi(opt + 1)) >= 0) |
106 |
|
|
lt->created_min = (unsigned int) (CurrentTime |
107 |
|
|
- 60 * i); |
108 |
|
|
else |
109 |
|
|
errors = 1; |
110 |
|
|
break; |
111 |
|
|
default: errors = 1; |
112 |
|
|
} |
113 |
|
|
break; |
114 |
|
|
case 'T': |
115 |
|
|
case 't': switch (*++opt) |
116 |
|
|
{ |
117 |
|
|
case '<': if ((i = atoi(opt + 1)) >= 0) |
118 |
|
|
lt->topicts_min = (unsigned int) (CurrentTime |
119 |
|
|
- 60 * i); |
120 |
|
|
else |
121 |
|
|
errors = 1; |
122 |
|
|
break; |
123 |
|
|
case '>': if ((i = atoi(opt + 1)) >= 0) |
124 |
|
|
lt->topicts_max = (unsigned int) (CurrentTime |
125 |
|
|
- 60 * i); |
126 |
|
|
else |
127 |
|
|
errors = 1; |
128 |
|
|
break; |
129 |
|
|
default: errors = 1; |
130 |
|
|
} |
131 |
|
|
break; |
132 |
|
|
default: if (*opt == '!') |
133 |
|
|
{ |
134 |
|
|
list = <->hide_mask; |
135 |
|
|
opt++; |
136 |
|
|
} |
137 |
|
|
else list = <->show_mask; |
138 |
|
|
|
139 |
|
|
if (has_wildcards(opt + !!IsChanPrefix(*opt))) |
140 |
|
|
{ |
141 |
|
|
if (list == <->show_mask) |
142 |
|
|
no_masked_channels = 0; |
143 |
|
|
} |
144 |
|
|
else if (!IsChanPrefix(*opt)) |
145 |
|
|
errors = 1; |
146 |
|
|
if (!errors) |
147 |
|
|
{ |
148 |
|
|
char *s; |
149 |
|
|
DupString(s, opt); |
150 |
|
|
dlinkAdd(s, make_dlink_node(), list); |
151 |
|
|
} |
152 |
|
|
} |
153 |
|
|
if (errors) |
154 |
|
|
{ |
155 |
|
|
free_list_task(lt, source_p); |
156 |
|
|
sendto_one(source_p, form_str(ERR_LISTSYNTAX), |
157 |
michael |
896 |
me.name, source_p->name); |
158 |
adx |
30 |
return; |
159 |
|
|
} |
160 |
|
|
} |
161 |
|
|
|
162 |
|
|
|
163 |
michael |
885 |
dlinkAdd(source_p, make_dlink_node(), &listing_client_list); |
164 |
|
|
|
165 |
adx |
30 |
sendto_one(source_p, form_str(RPL_LISTSTART), |
166 |
michael |
896 |
me.name, source_p->name); |
167 |
adx |
30 |
safe_list_channels(source_p, lt, no_masked_channels && |
168 |
michael |
896 |
lt->show_mask.head != NULL); |
169 |
adx |
30 |
} |
170 |
|
|
|
171 |
|
|
/* |
172 |
|
|
** m_list |
173 |
|
|
** parv[0] = sender prefix |
174 |
|
|
** parv[1] = channel |
175 |
|
|
*/ |
176 |
|
|
static void |
177 |
|
|
m_list(struct Client *client_p, struct Client *source_p, |
178 |
|
|
int parc, char *parv[]) |
179 |
|
|
{ |
180 |
|
|
static time_t last_used = 0; |
181 |
|
|
|
182 |
|
|
if (((last_used + ConfigFileEntry.pace_wait) > CurrentTime)) |
183 |
|
|
{ |
184 |
michael |
1230 |
sendto_one(source_p, form_str(RPL_LOAD2HI), |
185 |
|
|
me.name, source_p->name); |
186 |
adx |
30 |
return; |
187 |
|
|
} |
188 |
|
|
|
189 |
michael |
885 |
last_used = CurrentTime; |
190 |
adx |
30 |
|
191 |
|
|
do_list(source_p, parc, parv); |
192 |
|
|
} |
193 |
|
|
|
194 |
|
|
/* |
195 |
|
|
** mo_list |
196 |
|
|
** parv[0] = sender prefix |
197 |
|
|
** parv[1] = channel |
198 |
|
|
*/ |
199 |
|
|
static void |
200 |
|
|
mo_list(struct Client *client_p, struct Client *source_p, |
201 |
|
|
int parc, char *parv[]) |
202 |
|
|
{ |
203 |
|
|
do_list(source_p, parc, parv); |
204 |
|
|
} |
205 |
michael |
1230 |
|
206 |
|
|
static struct Message list_msgtab = { |
207 |
|
|
"LIST", 0, 0, 0, MAXPARA, MFLG_SLOW, 0, |
208 |
|
|
{m_unregistered, m_list, m_ignore, m_ignore, mo_list, m_ignore} |
209 |
|
|
}; |
210 |
|
|
|
211 |
|
|
static void |
212 |
|
|
module_init(void) |
213 |
|
|
{ |
214 |
|
|
mod_add_cmd(&list_msgtab); |
215 |
|
|
add_isupport("ELIST", "CMNTU", -1); |
216 |
|
|
add_isupport("SAFELIST", NULL, -1); |
217 |
|
|
} |
218 |
|
|
|
219 |
|
|
static void |
220 |
|
|
module_exit(void) |
221 |
|
|
{ |
222 |
|
|
mod_del_cmd(&list_msgtab); |
223 |
|
|
delete_isupport("ELIST"); |
224 |
|
|
delete_isupport("SAFELIST"); |
225 |
|
|
} |
226 |
|
|
|
227 |
|
|
struct module module_entry = { |
228 |
|
|
.node = { NULL, NULL, NULL }, |
229 |
|
|
.name = NULL, |
230 |
|
|
.version = "$Revision$", |
231 |
|
|
.handle = NULL, |
232 |
|
|
.modinit = module_init, |
233 |
|
|
.modexit = module_exit, |
234 |
|
|
.flags = 0 |
235 |
|
|
}; |