]>
jfr.im git - solanum.git/blob - src/supported.c
2 * charybdis: A slightly useful ircd.
3 * supported.c: isupport (005) numeric
5 * Copyright (C) 2006 Jilles Tjoelker
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
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.
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.
31 * $Id: supported.c 3568 2007-09-09 18:59:08Z jilles $
34 /* From the old supported.h which is
35 * Copyright (C) 1996-2002 Hybrid Development Team
36 * Copyright (C) 2002-2004 ircd-ratbox development team
39 * - from mirc's versions.txt
41 * mIRC now supports the numeric 005 tokens: CHANTYPES=# and
42 * PREFIX=(ohv)@%+ and can handle a dynamic set of channel and
45 * mIRC assumes that @ is supported on all networks, any mode
46 * left of @ is assumed to have at least equal power to @, and
47 * any mode right of @ has less power.
49 * mIRC has internal support for @%+ modes.
51 * $nick() can now handle all mode letters listed in PREFIX.
53 * Also added support for CHANMODES=A,B,C,D token (not currently
54 * supported by any servers), which lists all modes supported
55 * by a channel, where:
57 * A = modes that take a parameter, and add or remove nicks
58 * or addresses to a list, such as +bIe for the ban,
59 * invite, and exception lists.
61 * B = modes that change channel settings, but which take
62 * a parameter when they are set and unset, such as
65 * C = modes that change channel settings, but which take
66 * a parameter only when they are set, such as +l N,
69 * D = modes that change channel settings, such as +imnpst
70 * and take no parameters.
72 * All unknown/unlisted modes are treated as type D.
78 * U = user count search (< >)
79 * C = creation time search (C> C<)
80 * T = topic search (T> T<)
91 dlink_list isupportlist
;
96 const char *(*func
)(void *);
102 add_isupport(const char *name
, const char *(*func
)(void *), void *param
)
104 struct isupportitem
*item
;
106 item
= MyMalloc(sizeof(struct isupportitem
));
110 dlinkAddTail(item
, &item
->node
, &isupportlist
);
114 delete_isupport(const char *name
)
116 dlink_node
*ptr
, *next_ptr
;
117 struct isupportitem
*item
;
119 DLINK_FOREACH_SAFE(ptr
, next_ptr
, isupportlist
.head
)
123 if (!strcmp(item
->name
, name
))
125 dlinkDelete(ptr
, &isupportlist
);
133 show_isupport(struct Client
*client_p
)
136 struct isupportitem
*item
;
143 extra_space
= strlen(client_p
->name
);
145 if (!MyClient(client_p
) && extra_space
< 9)
147 /* :<me.name> 005 <nick> <params> :are supported by this server */
148 /* form_str(RPL_ISUPPORT) is %s :are supported by this server */
149 extra_space
+= strlen(me
.name
) + 1 + strlen(form_str(RPL_ISUPPORT
));
151 nchars
= extra_space
, nparams
= 0, buf
[0] = '\0';
152 DLINK_FOREACH(ptr
, isupportlist
.head
)
155 value
= (*item
->func
)(item
->param
);
158 l
= strlen(item
->name
) + (EmptyString(value
) ? 0 : 1 + strlen(value
));
159 if (nchars
+ l
+ (nparams
> 0) >= sizeof buf
|| nparams
+ 1 > 12)
161 sendto_one_numeric(client_p
, RPL_ISUPPORT
, form_str(RPL_ISUPPORT
), buf
);
162 nchars
= extra_space
, nparams
= 0, buf
[0] = '\0';
165 strlcat(buf
, " ", sizeof buf
), nchars
++;
166 strlcat(buf
, item
->name
, sizeof buf
);
167 if (!EmptyString(value
))
169 strlcat(buf
, "=", sizeof buf
);
170 strlcat(buf
, value
, sizeof buf
);
176 sendto_one_numeric(client_p
, RPL_ISUPPORT
, form_str(RPL_ISUPPORT
), buf
);
180 isupport_intptr(void *ptr
)
184 ircsnprintf(buf
, sizeof buf
, "%d", *(int *)ptr
);
189 isupport_boolean(void *ptr
)
192 return *(int *)ptr
? "" : NULL
;
196 isupport_string(void *ptr
)
199 return (const char *)ptr
;
203 isupport_stringptr(void *ptr
)
206 return *(const char **)ptr
;
210 isupport_chanmodes(void *ptr
)
212 static char result
[80];
214 ircsnprintf(result
, sizeof result
, "%s%sbq,k,%slj,imnpst%scgzLP%s",
215 ConfigChannel
.use_except
? "e" : "",
216 ConfigChannel
.use_invex
? "I" : "",
217 ConfigChannel
.use_forward
? "f" : "",
218 dlink_list_length(&service_list
) ? "r" : "",
219 ConfigChannel
.use_forward
? "QF" : "");
224 isupport_chanlimit(void *ptr
)
226 static char result
[30];
228 ircsnprintf(result
, sizeof result
, "&#:%i", ConfigChannel
.max_chans_per_user
);
233 isupport_maxlist(void *ptr
)
235 static char result
[30];
237 ircsnprintf(result
, sizeof result
, "bq%s%s:%i",
238 ConfigChannel
.use_except
? "e" : "",
239 ConfigChannel
.use_invex
? "I" : "",
240 ConfigChannel
.max_bans
);
245 isupport_targmax(void *ptr
)
247 static char result
[200];
249 ircsnprintf(result
, sizeof result
, "NAMES:1,LIST:1,KICK:1,WHOIS:1,PRIVMSG:%d,NOTICE:%d,ACCEPT:,MONITOR:",
250 ConfigFileEntry
.max_targets
,
251 ConfigFileEntry
.max_targets
);
256 isupport_extban(void *ptr
)
259 static char result
[200];
261 p
= get_extban_string();
264 ircsnprintf(result
, sizeof result
, "$,%s", p
);
271 static int maxmodes
= MAXMODEPARAMS
;
272 static int nicklen
= NICKLEN
-1;
273 static int channellen
= LOC_CHANNELLEN
;
274 static int topiclen
= TOPICLEN
;
276 add_isupport("CHANTYPES", isupport_string
, "&#");
277 add_isupport("EXCEPTS", isupport_boolean
, &ConfigChannel
.use_except
);
278 add_isupport("INVEX", isupport_boolean
, &ConfigChannel
.use_invex
);
279 add_isupport("CHANMODES", isupport_chanmodes
, NULL
);
280 add_isupport("CHANLIMIT", isupport_chanlimit
, NULL
);
281 add_isupport("PREFIX", isupport_string
, "(ov)@+");
282 add_isupport("MAXLIST", isupport_maxlist
, NULL
);
283 add_isupport("MODES", isupport_intptr
, &maxmodes
);
284 add_isupport("NETWORK", isupport_stringptr
, &ServerInfo
.network_name
);
285 add_isupport("KNOCK", isupport_boolean
, &ConfigChannel
.use_knock
);
286 add_isupport("STATUSMSG", isupport_string
, "@+");
287 add_isupport("CALLERID", isupport_string
, "g");
288 add_isupport("SAFELIST", isupport_string
, "");
289 add_isupport("ELIST", isupport_string
, "U");
290 add_isupport("CASEMAPPING", isupport_string
, "rfc1459");
291 add_isupport("CHARSET", isupport_string
, "ascii");
292 add_isupport("NICKLEN", isupport_intptr
, &nicklen
);
293 add_isupport("CHANNELLEN", isupport_intptr
, &channellen
);
294 add_isupport("TOPICLEN", isupport_intptr
, &topiclen
);
295 add_isupport("ETRACE", isupport_string
, "");
296 add_isupport("CPRIVMSG", isupport_string
, "");
297 add_isupport("CNOTICE", isupport_string
, "");
298 add_isupport("DEAF", isupport_string
, "D");
299 add_isupport("MONITOR", isupport_intptr
, &ConfigFileEntry
.max_monitor
);
300 add_isupport("FNC", isupport_string
, "");
301 add_isupport("TARGMAX", isupport_targmax
, NULL
);
302 add_isupport("EXTBAN", isupport_extban
, NULL
);