]> jfr.im git - solanum.git/blame - ircd/supported.c
Add a comment explaining match_arrange_stars
[solanum.git] / ircd / supported.c
CommitLineData
212380e3 1/*
a6f63a82 2 * Solanum: a slightly advanced ircd
212380e3
AC
3 * supported.c: isupport (005) numeric
4 *
5 * Copyright (C) 2006 Jilles Tjoelker
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
9 * met:
10 *
11 * 1.Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the following disclaimer.
13 * 2.Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3.The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
23 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
28 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
212380e3
AC
30 */
31
32/* From the old supported.h which is
33 * Copyright (C) 1996-2002 Hybrid Development Team
34 * Copyright (C) 2002-2004 ircd-ratbox development team
35 */
36/*
37 * - from mirc's versions.txt
38 *
39 * mIRC now supports the numeric 005 tokens: CHANTYPES=# and
40 * PREFIX=(ohv)@%+ and can handle a dynamic set of channel and
41 * nick prefixes.
42 *
43 * mIRC assumes that @ is supported on all networks, any mode
44 * left of @ is assumed to have at least equal power to @, and
45 * any mode right of @ has less power.
46 *
47 * mIRC has internal support for @%+ modes.
48 *
49 * $nick() can now handle all mode letters listed in PREFIX.
50 *
51 * Also added support for CHANMODES=A,B,C,D token (not currently
52 * supported by any servers), which lists all modes supported
53 * by a channel, where:
54 *
55 * A = modes that take a parameter, and add or remove nicks
56 * or addresses to a list, such as +bIe for the ban,
57 * invite, and exception lists.
58 *
59 * B = modes that change channel settings, but which take
60 * a parameter when they are set and unset, such as
61 * +k key, and -k key.
62 *
63 * C = modes that change channel settings, but which take
64 * a parameter only when they are set, such as +l N,
65 * and -l.
66 *
67 * D = modes that change channel settings, such as +imnpst
68 * and take no parameters.
69 *
70 * All unknown/unlisted modes are treated as type D.
71 */
212380e3
AC
72
73#include "stdinc.h"
212380e3 74#include "client.h"
212380e3
AC
75#include "numeric.h"
76#include "ircd.h"
77#include "s_conf.h"
294d32bf 78#include "s_user.h"
48a266e5 79#include "supported.h"
c18cb68b 80#include "chmode.h"
77d3d2db 81#include "send.h"
212380e3 82
01978a2c 83static char allowed_chantypes[BUFSIZE];
330fc5c1 84rb_dlink_list isupportlist;
212380e3
AC
85
86struct isupportitem
87{
88 const char *name;
48a266e5
JT
89 const char *(*func)(const void *);
90 const void *param;
330fc5c1 91 rb_dlink_node node;
212380e3
AC
92};
93
94void
48a266e5 95add_isupport(const char *name, const char *(*func)(const void *), const void *param)
212380e3
AC
96{
97 struct isupportitem *item;
98
eddc2ab6 99 item = rb_malloc(sizeof(struct isupportitem));
212380e3
AC
100 item->name = name;
101 item->func = func;
102 item->param = param;
330fc5c1 103 rb_dlinkAddTail(item, &item->node, &isupportlist);
212380e3
AC
104}
105
5d47bdca 106const void *
474b0d35
AC
107change_isupport(const char *name, const char *(*func)(const void *), const void *param)
108{
109 rb_dlink_node *ptr;
110 struct isupportitem *item;
eac04554 111 const void *oldvalue = NULL;
474b0d35
AC
112
113 RB_DLINK_FOREACH(ptr, isupportlist.head)
114 {
115 item = ptr->data;
116
117 if (!strcmp(item->name, name))
118 {
5d47bdca
AC
119 oldvalue = item->param;
120
41d8802e 121 // item->name = name;
474b0d35
AC
122 item->func = func;
123 item->param = param;
124
125 break;
126 }
127 }
5d47bdca
AC
128
129 return oldvalue;
474b0d35
AC
130}
131
212380e3
AC
132void
133delete_isupport(const char *name)
134{
637c4932 135 rb_dlink_node *ptr, *next_ptr;
212380e3
AC
136 struct isupportitem *item;
137
637c4932 138 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, isupportlist.head)
212380e3
AC
139 {
140 item = ptr->data;
141
142 if (!strcmp(item->name, name))
143 {
330fc5c1 144 rb_dlinkDelete(ptr, &isupportlist);
637c4932 145 rb_free(item);
212380e3
AC
146 }
147 }
148}
149
150/* XXX caching? */
151void
152show_isupport(struct Client *client_p)
153{
330fc5c1 154 rb_dlink_node *ptr;
212380e3
AC
155 struct isupportitem *item;
156 const char *value;
157 char buf[512];
158 int extra_space;
48a266e5 159 unsigned int nchars, nparams;
212380e3
AC
160 int l;
161
162 extra_space = strlen(client_p->name);
163 /* UID */
164 if (!MyClient(client_p) && extra_space < 9)
165 extra_space = 9;
166 /* :<me.name> 005 <nick> <params> :are supported by this server */
167 /* form_str(RPL_ISUPPORT) is %s :are supported by this server */
168 extra_space += strlen(me.name) + 1 + strlen(form_str(RPL_ISUPPORT));
169
170 nchars = extra_space, nparams = 0, buf[0] = '\0';
5cefa1d6 171 RB_DLINK_FOREACH(ptr, isupportlist.head)
212380e3
AC
172 {
173 item = ptr->data;
174 value = (*item->func)(item->param);
175 if (value == NULL)
176 continue;
177 l = strlen(item->name) + (EmptyString(value) ? 0 : 1 + strlen(value));
178 if (nchars + l + (nparams > 0) >= sizeof buf || nparams + 1 > 12)
179 {
180 sendto_one_numeric(client_p, RPL_ISUPPORT, form_str(RPL_ISUPPORT), buf);
181 nchars = extra_space, nparams = 0, buf[0] = '\0';
182 }
183 if (nparams > 0)
1f9de103
VY
184 rb_strlcat(buf, " ", sizeof buf), nchars++;
185 rb_strlcat(buf, item->name, sizeof buf);
212380e3
AC
186 if (!EmptyString(value))
187 {
1f9de103
VY
188 rb_strlcat(buf, "=", sizeof buf);
189 rb_strlcat(buf, value, sizeof buf);
212380e3
AC
190 }
191 nchars += l;
192 nparams++;
193 }
194 if (nparams > 0)
195 sendto_one_numeric(client_p, RPL_ISUPPORT, form_str(RPL_ISUPPORT), buf);
196}
197
198const char *
48a266e5 199isupport_intptr(const void *ptr)
212380e3
AC
200{
201 static char buf[15];
5203cba5 202 snprintf(buf, sizeof buf, "%d", *(const int *)ptr);
212380e3
AC
203 return buf;
204}
205
206const char *
48a266e5 207isupport_boolean(const void *ptr)
212380e3
AC
208{
209
48a266e5 210 return *(const int *)ptr ? "" : NULL;
212380e3
AC
211}
212
213const char *
48a266e5 214isupport_string(const void *ptr)
212380e3
AC
215{
216
217 return (const char *)ptr;
218}
219
220const char *
48a266e5 221isupport_stringptr(const void *ptr)
212380e3 222{
55abcbb2 223 return *(char * const *)ptr;
212380e3
AC
224}
225
8906ffd1 226const char *
294d32bf
JT
227isupport_umode(const void *ptr)
228{
229 const char *str;
230
231 str = ptr;
7ddd614c
JT
232 return ConfigFileEntry.oper_only_umodes &
233 user_modes[(unsigned char)*str] ? NULL : str;
294d32bf
JT
234}
235
48a266e5
JT
236static const char *
237isupport_chanmodes(const void *ptr)
212380e3 238{
e52893db 239 static char result[300];
212380e3 240
5203cba5 241 snprintf(result, sizeof result, "%s%sbq,k,%slj,%s",
212380e3
AC
242 ConfigChannel.use_except ? "e" : "",
243 ConfigChannel.use_invex ? "I" : "",
2da6f6eb 244 ConfigChannel.use_forward ? "f" : "",
c18cb68b 245 cflagsbuf);
212380e3
AC
246 return result;
247}
248
48a266e5
JT
249static const char *
250isupport_chanlimit(const void *ptr)
212380e3 251{
e52893db 252 static char result[BUFSIZE + 30];
212380e3 253
01978a2c 254 snprintf(result, sizeof result, "%s:%i", allowed_chantypes, ConfigChannel.max_chans_per_user);
212380e3
AC
255 return result;
256}
257
48a266e5
JT
258static const char *
259isupport_maxlist(const void *ptr)
212380e3
AC
260{
261 static char result[30];
262
5203cba5 263 snprintf(result, sizeof result, "bq%s%s:%i",
212380e3
AC
264 ConfigChannel.use_except ? "e" : "",
265 ConfigChannel.use_invex ? "I" : "",
266 ConfigChannel.max_bans);
267 return result;
268}
269
7f2cc0ea
AC
270static const char *
271isupport_targmax(const void *ptr)
272{
273 static char result[200];
274
5203cba5 275 snprintf(result, sizeof result, "NAMES:1,LIST:1,KICK:1,WHOIS:1,PRIVMSG:%d,NOTICE:%d,ACCEPT:,MONITOR:",
7f2cc0ea
AC
276 ConfigFileEntry.max_targets,
277 ConfigFileEntry.max_targets);
278 return result;
279}
280
48a266e5
JT
281static const char *
282isupport_extban(const void *ptr)
212380e3
AC
283{
284 const char *p;
285 static char result[200];
286
287 p = get_extban_string();
288 if (EmptyString(p))
289 return NULL;
5203cba5 290 snprintf(result, sizeof result, "$,%s", p);
212380e3
AC
291 return result;
292}
293
c68d30f7
AC
294static const char *
295isupport_nicklen(const void *ptr)
296{
297 static char result[200];
298
5203cba5 299 snprintf(result, sizeof result, "%u", ConfigFileEntry.nicklen - 1);
c68d30f7
AC
300 return result;
301}
302
212380e3
AC
303void
304init_isupport(void)
305{
306 static int maxmodes = MAXMODEPARAMS;
212380e3
AC
307 static int channellen = LOC_CHANNELLEN;
308 static int topiclen = TOPICLEN;
c68d30f7 309 static int maxnicklen = NICKLEN - 1;
212380e3 310
6e86cdd6 311 add_isupport("CHANTYPES", isupport_string, allowed_chantypes);
212380e3
AC
312 add_isupport("EXCEPTS", isupport_boolean, &ConfigChannel.use_except);
313 add_isupport("INVEX", isupport_boolean, &ConfigChannel.use_invex);
314 add_isupport("CHANMODES", isupport_chanmodes, NULL);
315 add_isupport("CHANLIMIT", isupport_chanlimit, NULL);
316 add_isupport("PREFIX", isupport_string, "(ov)@+");
317 add_isupport("MAXLIST", isupport_maxlist, NULL);
318 add_isupport("MODES", isupport_intptr, &maxmodes);
319 add_isupport("NETWORK", isupport_stringptr, &ServerInfo.network_name);
212380e3 320 add_isupport("STATUSMSG", isupport_string, "@+");
212380e3 321 add_isupport("CASEMAPPING", isupport_string, "rfc1459");
c68d30f7
AC
322 add_isupport("NICKLEN", isupport_nicklen, NULL);
323 add_isupport("MAXNICKLEN", isupport_intptr, &maxnicklen);
212380e3
AC
324 add_isupport("CHANNELLEN", isupport_intptr, &channellen);
325 add_isupport("TOPICLEN", isupport_intptr, &topiclen);
294d32bf 326 add_isupport("DEAF", isupport_umode, "D");
7f2cc0ea 327 add_isupport("TARGMAX", isupport_targmax, NULL);
212380e3 328 add_isupport("EXTBAN", isupport_extban, NULL);
bde6442c 329 add_isupport("CLIENTVER", isupport_string, "3.0");
212380e3 330}
01978a2c
AC
331
332void
333chantypes_update(void)
334{
335 unsigned char *p;
336 memset(allowed_chantypes, '\0', sizeof allowed_chantypes);
337
338 p = (unsigned char *) allowed_chantypes;
339
340 for (unsigned int i = 0; i < 256; i++)
341 {
342 if (IsChanPrefix(i))
343 *p++ = (unsigned char) i;
344 }
345}