]>
jfr.im git - irc/evilnet/x3.git/blob - src/proto-p10.c
1 /* proto-p10.c - IRC protocol output
2 * Copyright 2000-2004 srvx Development Team
4 * This file is part of x3.
6 * x3 is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with srvx; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
25 #include "proto-common.c"
29 #define CMD_ACCOUNT "ACCOUNT"
30 #define CMD_ADMIN "ADMIN"
31 #define CMD_ALIST "ALIST"
32 #define CMD_ASLL "ASLL"
33 #define CMD_AWAY "AWAY"
34 #define CMD_BURST "BURST"
35 #define CMD_CLEARMODE "CLEARMODE"
36 #define CMD_CLOSE "CLOSE"
37 #define CMD_CNOTICE "CNOTICE"
38 #define CMD_CONNECT "CONNECT"
39 #define CMD_CPRIVMSG "CPRIVMSG"
40 #define CMD_CREATE "CREATE"
41 #define CMD_DESTRUCT "DESTRUCT"
42 #define CMD_DESYNCH "DESYNCH"
45 #define CMD_EOB "END_OF_BURST"
46 #define CMD_EOB_ACK "EOB_ACK"
47 #define CMD_ERROR "ERROR"
48 #define CMD_FAKEHOST "FAKE"
50 #define CMD_GLINE "GLINE"
51 #define CMD_HASH "HASH"
52 #define CMD_HELP "HELP"
53 #define CMD_INFO "INFO"
54 #define CMD_INVITE "INVITE"
55 #define CMD_ISON "ISON"
56 #define CMD_JOIN "JOIN"
57 #define CMD_JUPE "JUPE"
58 #define CMD_KICK "KICK"
59 #define CMD_KILL "KILL"
60 #define CMD_LINKS "LINKS"
61 #define CMD_LIST "LIST"
62 #define CMD_LUSERS "LUSERS"
64 #define CMD_MARK "MARK"
65 #define CMD_MODE "MODE"
66 #define CMD_MOTD "MOTD"
67 #define CMD_NAMES "NAMES"
68 #define CMD_NICK "NICK"
69 #define CMD_NOTICE "NOTICE"
70 #define CMD_OPER "OPER"
71 #define CMD_OPMODE "OPMODE"
72 #define CMD_PART "PART"
73 #define CMD_PASS "PASS"
74 #define CMD_PING "PING"
75 #define CMD_PONG "PONG"
76 #define CMD_POST "POST"
77 #define CMD_PRIVMSG "PRIVMSG"
78 #define CMD_PRIVS "PRIVS"
79 #define CMD_PROTO "PROTO"
80 #define CMD_QUIT "QUIT"
81 #define CMD_REHASH "REHASH"
82 #define CMD_REMOVE "REMOVE"
83 #define CMD_RESET "RESET"
84 #define CMD_RESTART "RESTART"
85 #define CMD_RPING "RPING"
86 #define CMD_RPONG "RPONG"
87 #define CMD_SASL "SASL"
88 #define CMD_SERVER "SERVER"
89 #define CMD_SERVLIST "SERVLIST"
90 #define CMD_SERVSET "SERVSET"
92 #define CMD_SETTIME "SETTIME"
93 #define CMD_SGLINE "SGLINE"
94 #define CMD_SHUN "SHUN"
95 #define CMD_SILENCE "SILENCE"
98 #define CMD_SSHUN "SSHUN"
99 #define CMD_SPAMFILTER "SPAMFILTER"
100 #define CMD_SQUERY "SQUERY"
101 #define CMD_SQUIT "SQUIT"
102 #define CMD_STATS "STATS"
103 #define CMD_SVSJOIN "SVSJOIN"
104 #define CMD_SVSNICK "SVSNICK"
105 #define CMD_SVSPART "SVSPART"
106 #define CMD_SVSQUIT "SVSQUIT"
107 #define CMD_SWHOIS "SWHOIS"
108 #define CMD_TEMPSHUN "TEMPSHUN"
109 #define CMD_TIME "TIME"
110 #define CMD_TOPIC "TOPIC"
111 #define CMD_TRACE "TRACE"
112 #define CMD_UPING "UPING"
113 #define CMD_USER "USER"
114 #define CMD_USERHOST "USERHOST"
115 #define CMD_USERIP "USERIP"
116 #define CMD_VERSION "VERSION"
117 #define CMD_WALLCHOPS "WALLCHOPS"
118 #define CMD_WALLOPS "WALLOPS"
119 #define CMD_WALLHOPS "WALLHOPS"
120 #define CMD_WALLUSERS "WALLUSERS"
121 #define CMD_WALLVOICES "WALLVOICES"
122 #define CMD_WALLHOPS "WALLHOPS"
123 #define CMD_WHO "WHO"
124 #define CMD_WHOIS "WHOIS"
125 #define CMD_WHOWAS "WHOWAS"
126 #define CMD_ZLINE "ZLINE"
128 /* Tokenized commands. */
129 #define TOK_ACCOUNT "AC"
130 #define TOK_ADMIN "AD"
131 #define TOK_ALIST "AL"
132 #define TOK_ASLL "LL"
134 #define TOK_BURST "B"
135 #define TOK_CLEARMODE "CM"
136 #define TOK_CLOSE "CLOSE"
137 #define TOK_CNOTICE "CN"
138 #define TOK_CONNECT "CO"
139 #define TOK_CPRIVMSG "CP"
140 #define TOK_CREATE "C"
141 #define TOK_DESTRUCT "DE"
142 #define TOK_DESYNCH "DS"
143 #define TOK_DIE "DIE"
144 #define TOK_DNS "DNS"
146 #define TOK_EOB_ACK "EA"
147 #define TOK_ERROR "Y"
148 #define TOK_EXEMPT "EX"
149 #define TOK_FAKEHOST "FA"
150 #define TOK_GET "GET"
151 #define TOK_GLINE "GL"
152 #define TOK_HASH "HASH"
153 #define TOK_HELP "HELP"
155 #define TOK_INVITE "I"
156 #define TOK_ISON "ISON"
158 #define TOK_JUPE "JU"
161 #define TOK_LINKS "LI"
162 #define TOK_LIST "LIST"
163 #define TOK_LUSERS "LU"
164 #define TOK_MAP "MAP"
165 #define TOK_MARK "MK"
167 #define TOK_MOTD "MO"
168 #define TOK_NAMES "E"
170 #define TOK_NOTICE "O"
171 #define TOK_OPER "OPER"
172 #define TOK_OPMODE "OM"
174 #define TOK_PASS "PA"
177 #define TOK_POST "POST"
178 #define TOK_PRIVMSG "P"
179 #define TOK_PRIVS "PRIVS"
180 #define TOK_PROTO "PROTO"
182 #define TOK_REHASH "REHASH"
183 #define TOK_REMOVE "RM"
184 #define TOK_RESET "RESET"
185 #define TOK_RESTART "RESTART"
186 #define TOK_RPING "RI"
187 #define TOK_RPONG "RO"
188 #define TOK_SASL "SASL"
189 #define TOK_SERVER "S"
190 #define TOK_SERVLIST "SERVSET"
191 #define TOK_SERVSET "SERVSET"
192 #define TOK_SET "SET"
193 #define TOK_SETTIME "SE"
194 #define TOK_SGLINE "SGL"
195 #define TOK_SHUN "SU"
196 #define TOK_SILENCE "U"
197 #define TOK_SMO "SMO"
198 #define TOK_SNO "SNO"
199 #define TOK_SSHUN "SSU"
200 #define TOK_SPAMFILTER "SF"
201 #define TOK_SQUERY "SQUERY"
202 #define TOK_SQUIT "SQ"
203 #define TOK_STATS "R"
204 #define TOK_SVSJOIN "SJ"
205 #define TOK_SVSNICK "SN"
206 #define TOK_SVSPART "SP"
207 #define TOK_SVSQUIT "SX"
208 #define TOK_SWHOIS "SW"
209 #define TOK_TEMPSHUN "TS"
210 #define TOK_TIME "TI"
211 #define TOK_TOPIC "T"
212 #define TOK_TRACE "TR"
213 #define TOK_UPING "UP"
214 #define TOK_USER "USER"
215 #define TOK_USERHOST "USERHOST"
216 #define TOK_USERIP "USERIP"
217 #define TOK_VERSION "V"
218 #define TOK_WALLCHOPS "WC"
219 #define TOK_WALLOPS "WA"
220 #define TOK_WALLHOPS "WH"
221 #define TOK_WALLUSERS "WU"
222 #define TOK_WALLVOICES "WV"
223 #define TOK_WALLHOPS "WH"
225 #define TOK_WHOIS "W"
226 #define TOK_WHOWAS "X"
227 #define TOK_ZLINE "ZL"
229 /* Protocol messages; aliased to full commands or tokens depending
230 on compile-time configuration. ircu prefers tokens WITH THE
231 EXCEPTION OF THE SERVER AND PASS COMMANDS, which cannot be
232 tokenized, because clients' (ie. a linking server) commands are
233 only checked against the full command list.
235 #if defined(ENABLE_TOKENS)
236 #define TYPE(NAME) TOK_ ## NAME
237 #else /* !ENABLE_TOKENS */
238 #define TYPE(NAME) CMD_ ## NAME
239 #endif /* ENABLE_TOKENS */
241 #define P10_ACCOUNT TYPE(ACCOUNT)
242 #define P10_ADMIN TYPE(ADMIN)
243 #define P10_ASLL TYPE(ASLL)
244 #define P10_AWAY TYPE(AWAY)
245 #define P10_BURST TYPE(BURST)
246 #define P10_CLEARMODE TYPE(CLEARMODE)
247 #define P10_CLOSE TYPE(CLOSE)
248 #define P10_CNOTICE TYPE(CNOTICE)
249 #define P10_CONNECT TYPE(CONNECT)
250 #define P10_CPRIVMSG TYPE(CPRIVMSG)
251 #define P10_CREATE TYPE(CREATE)
252 #define P10_DESTRUCT TYPE(DESTRUCT)
253 #define P10_DESYNCH TYPE(DESYNCH)
254 #define P10_DIE TYPE(DIE)
255 #define P10_DNS TYPE(DNS)
256 #define P10_EOB TYPE(EOB)
257 #define P10_EOB_ACK TYPE(EOB_ACK)
258 #define P10_ERROR TYPE(ERROR)
259 #define P10_FAKEHOST TYPE(FAKEHOST)
260 #define P10_GET TYPE(GET)
261 #define P10_GLINE TYPE(GLINE)
262 #define P10_HASH TYPE(HASH)
263 #define P10_HELP TYPE(HELP)
264 #define P10_INFO TYPE(INFO)
265 #define P10_INVITE TYPE(INVITE)
266 #define P10_ISON TYPE(ISON)
267 #define P10_JOIN TYPE(JOIN)
268 #define P10_JUPE TYPE(JUPE)
269 #define P10_KICK TYPE(KICK)
270 #define P10_KILL TYPE(KILL)
271 #define P10_LINKS TYPE(LINKS)
272 #define P10_LIST TYPE(LIST)
273 #define P10_LUSERS TYPE(LUSERS)
274 #define P10_MAP TYPE(MAP)
275 #define P10_MARK TYPE(MARK)
276 #define P10_MODE TYPE(MODE)
277 #define P10_MOTD TYPE(MOTD)
278 #define P10_NAMES TYPE(NAMES)
279 #define P10_NICK TYPE(NICK)
280 #define P10_NOTICE TYPE(NOTICE)
281 #define P10_OPER TYPE(OPER)
282 #define P10_OPMODE TYPE(OPMODE)
283 #define P10_PART TYPE(PART)
284 #define P10_PASS CMD_PASS
285 #define P10_PING TYPE(PING)
286 #define P10_PONG TYPE(PONG)
287 #define P10_POST TYPE(POST)
288 #define P10_PRIVMSG TYPE(PRIVMSG)
289 #define P10_PRIVS TYPE(PRIVS)
290 #define P10_PROTO TYPE(PROTO)
291 #define P10_QUIT TYPE(QUIT)
292 #define P10_REHASH TYPE(REHASH)
293 #define P10_REMOVE TYPE(REMOVE)
294 #define P10_RESET TYPE(RESET)
295 #define P10_RESTART TYPE(RESTART)
296 #define P10_RPING TYPE(RPING)
297 #define P10_RPONG TYPE(RPONG)
298 #define P10_SASL TYPE(SASL)
299 #define P10_SERVER CMD_SERVER
300 #define P10_SERVLIST TYPE(SERVLIST)
301 #define P10_SERVSET TYPE(SERVSET)
302 #define P10_SET TYPE(SET)
303 #define P10_SETTIME TYPE(SETTIME)
304 #define P10_SGLINE TYPE(SGLINE)
305 #define P10_SHUN TYPE(SHUN)
306 #define P10_SILENCE TYPE(SILENCE)
307 #define P10_SMO TYPE(SMO)
308 #define P10_SNO TYPE(SNO)
309 #define P10_SSHUN TYPE(SSHUN)
310 #define P10_SPAMFILTER TYPE(SPAMFILTER)
311 #define P10_SQUERY TYPE(SQUERY)
312 #define P10_SQUIT TYPE(SQUIT)
313 #define P10_STATS TYPE(STATS)
314 #define P10_SVSJOIN TYPE(SVSJOIN)
315 #define P10_SVSNICK TYPE(SVSNICK)
316 #define P10_SVSPART TYPE(SVSPART)
317 #define P10_SVSQUIT TYPE(SVSQUIT)
318 #define P10_SWHOIS TYPE(SWHOIS)
319 #define P10_TEMPSHUN TYPE(TEMPSHUN)
320 #define P10_TIME TYPE(TIME)
321 #define P10_TOPIC TYPE(TOPIC)
322 #define P10_TRACE TYPE(TRACE)
323 #define P10_UPING TYPE(UPING)
324 #define P10_USER TYPE(USER)
325 #define P10_USERHOST TYPE(USERHOST)
326 #define P10_USERIP TYPE(USERIP)
327 #define P10_VERSION TYPE(VERSION)
328 #define P10_WALLCHOPS TYPE(WALLCHOPS)
329 #define P10_WALLOPS TYPE(WALLOPS)
330 #define P10_WALLHOPS TYPE(WALLHOPS)
331 #define P10_WALLUSERS TYPE(WALLUSERS)
332 #define P10_WALLVOICES TYPE(WALLVOICES)
333 #define P10_WHO TYPE(WHO)
334 #define P10_WHOIS TYPE(WHOIS)
335 #define P10_WHOWAS TYPE(WHOWAS)
336 #define P10_ZLINE TYPE(ZLINE)
337 #define P10_EXEMPT TYPE(EXEMPT)
339 /* Servers claiming to have a boot or link time before PREHISTORY
340 * trigger errors to the log. We hope no server has been running
341 * constantly since September 1994. :)
343 #define PREHISTORY 780000000
345 #define MODELEN 40 + KEYLEN
347 static struct server
* servers_num
[ 64 * 64 ];
348 static privmsg_func_t
* privmsg_funcs
;
349 static unsigned int num_privmsg_funcs
;
350 static privmsg_func_t
* notice_funcs
;
351 static unsigned int num_notice_funcs
;
352 static struct dict
* unbursted_channels
;
353 static const char * his_servername
;
354 static const char * his_servercomment
;
355 static int extended_accounts
;
357 /* These correspond to 1 << X: 01234567890123456789012345 */
358 const char irc_user_mode_chars
[] = "oOiw dkgh x BnIX azDRWHLq" ;
360 static struct userNode
* AddUser ( struct server
* uplink
, const char * nick
, const char * ident
, const char * hostname
, const char * modes
, const char * numeric
, const char * userinfo
, time_t timestamp
, const char * realip
);
362 extern int off_channel
;
363 extern int DefConLevel
;
364 extern int DefConTimeOut
;
365 extern char * DefConChanModes
;
367 static int parse_oplevel ( char * str
);
369 char privbuf
[ 512 ] = "" ;
371 /* Numerics can be XYY, XYYY, or XXYYY; with X's identifying the
372 * server and Y's indentifying the client on that server. */
374 GetServerN ( const char * numeric
)
376 switch ( strlen ( numeric
)) {
378 return servers_num
[ base64toint ( numeric
, 2 )];
382 return servers_num
[ base64toint ( numeric
, 1 )];
389 GetUserN ( const char * numeric
) /* using numeric */
395 switch ( strlen ( numeric
)) {
397 log_module ( MAIN_LOG
, LOG_WARNING
, "GetUserN( %s ): numeric too long!" , numeric
);
399 case 5 : slen
= 2 ; ulen
= 3 ; break ;
400 case 4 : slen
= 1 ; ulen
= 3 ; break ;
401 case 3 : slen
= 1 ; ulen
= 2 ; break ;
402 case 2 : case 1 : case 0 :
403 log_module ( MAIN_LOG
, LOG_WARNING
, "GetUserN( %s ): numeric too short!" , numeric
);
406 if (!( s
= servers_num
[ base64toint ( numeric
, slen
)])) {
407 log_module ( MAIN_LOG
, LOG_WARNING
, "GetUserN( %s ): couldn't find server (len= %d )!" , numeric
, slen
);
410 n
= base64toint ( numeric
+ slen
, ulen
) & s
-> num_mask
;
411 if (!( un
= s
-> users
[ n
])) {
412 log_module ( MAIN_LOG
, LOG_WARNING
, "GetUserN( %s ) couldn't find user!" , numeric
);
417 extern struct userNode
* opserv
;
419 check_ctcp ( struct userNode
* user
, struct userNode
* bot
, char * text
, UNUSED_ARG ( int server_qualified
))
422 /* if its a version reply, do an alert check (only alerts with version=something) */
424 if ( text
[ 0 ] == ' \001 ' ) {
426 cmd
= mysep (& text
, " " );
427 if (! irccasecmp ( cmd
, "VERSION" )) {
428 char * version
= mysep (& text
, " \n " );
431 /* opserv_debug("Opserv got CTCP VERSION Notice from %s: %s", user->nick, version); */
432 /* TODO: setup a ctcp_funcs thing to handle this and other CTCPS properly */
433 user
-> version_reply
= strdup ( version
);
434 /* TODO: put this in the db */
435 if ( match_ircglob ( version
, "WebTV;*" ))
436 user
-> no_notice
= true ; /* webbies cant see notices */
444 privmsg_user_helper ( struct userNode
* un
, void * data
)
446 struct privmsg_desc
* pd
= data
;
447 unsigned int num
= un
-> num_local
;
448 if (! pd
-> is_notice
) {
449 if (( num
< num_privmsg_funcs
) && privmsg_funcs
[ num
]) {
450 privmsg_funcs
[ num
]( pd
-> user
, un
, pd
-> text
, pd
-> is_qualified
);
453 if (( num
< num_notice_funcs
) && notice_funcs
[ num
]) {
454 check_ctcp ( pd
-> user
, un
, pd
-> text
, pd
-> is_qualified
);
455 notice_funcs
[ num
]( pd
-> user
, un
, pd
-> text
, pd
-> is_qualified
);
460 /* equiv to user doing /connect server port target */
461 void irc_connect ( struct userNode
* user
, char * server
, unsigned int port
, struct server
* target
)
463 putsock ( " %s " P10_CONNECT
" %s %d %s " , user
-> numeric
, server
, port
, target
-> numeric
);
467 irc_squit_route ( struct server
* srv
, const char * message
, ...)
471 va_start ( arg_list
, message
);
472 vsnprintf ( buffer
, MAXLEN
- 2 , message
, arg_list
);
473 buffer
[ MAXLEN
- 1 ] = 0 ;
475 /* When would we squit ourselves exactly?? -Rubin */
476 if ( srv
== self
&& cManager
. uplink
-> state
== CONNECTED
) {
479 /* Quit all clients linked to me. */
480 for ( i
= 0 ; i
<= self
-> num_mask
; i
++) {
483 irc_quit ( self
-> users
[ i
], buffer
);
487 putsock ( " %s " P10_SQUIT
" %s %d : %s " , self
-> numeric
, srv
-> name
, 0 , buffer
);
490 /* Force a reconnect to the currently selected server. */
491 cManager
. uplink
-> tries
= 0 ;
492 log_module ( MAIN_LOG
, LOG_INFO
, "Squitting from uplink: %s " , buffer
);
498 irc_server ( struct server
* srv
)
500 char extranum
[ COMBO_NUMERIC_LEN
+ 1 ];
502 inttobase64 ( extranum
, srv
-> num_mask
, ( srv
-> numeric
[ 1 ] || ( srv
-> num_mask
>= 64 * 64 )) ? 3 : 2 );
504 putsock ( P10_SERVER
" %s %d " FMT_TIME_T
" " FMT_TIME_T
" J10 %s%s +s6o : %s " ,
505 srv
-> name
, srv
-> hops
+ 1 , srv
-> boot
, srv
-> link_time
, srv
-> numeric
, extranum
, srv
-> description
);
507 putsock ( " %s " P10_SERVER
" %s %d " FMT_TIME_T
" " FMT_TIME_T
" %c 10 %s%s +s6o : %s " ,
508 self
-> numeric
, srv
-> name
, srv
-> hops
+ 1 , srv
-> boot
, srv
-> link_time
, ( srv
-> self_burst
? 'J' : 'P' ), srv
-> numeric
, extranum
, srv
-> description
);
513 irc_p10_pton ( irc_in_addr_t
* ip
, const char * input
)
515 if ( strlen ( input
) == 6 ) {
517 memset ( ip
, 0 , 6 * sizeof ( ip
-> in6
[ 0 ]));
518 value
= base64toint ( input
, 6 );
520 ip
-> in6
[ 5 ] = htons ( 65535 );
521 ip
-> in6
[ 6 ] = htons ( value
>> 16 );
522 ip
-> in6
[ 7 ] = htons ( value
& 65535 );
524 unsigned int pos
= 0 ;
528 for ( left
= ( 25 - strlen ( input
)) / 3 - pos
; left
; left
--)
532 ip
-> in6
[ pos
++] = ntohs ( base64toint ( input
, 3 ));
540 irc_p10_ntop ( char * output
, const irc_in_addr_t
* ip
)
542 if (! irc_in_addr_is_valid (* ip
)) {
543 strcpy ( output
, "AAAAAA" );
544 } else if ( irc_in_addr_is_ipv4 (* ip
)) {
546 in4
= ( ntohs ( ip
-> in6
[ 6 ]) << 16 ) | ntohs ( ip
-> in6
[ 7 ]);
547 inttobase64 ( output
, in4
, 6 );
549 } else if ( irc_in_addr_is_ipv6 (* ip
)) {
550 unsigned int max_start
, max_zeros
, curr_zeros
, zero
, ii
;
551 /* Can start by printing out the leading non-zero parts. */
552 for ( ii
= 0 ; ( ip
-> in6
[ ii
]) && ( ii
< 8 ); ++ ii
) {
553 inttobase64 ( output
, ntohs ( ip
-> in6
[ ii
]), 3 );
556 /* Find the longest run of zeros. */
557 for ( max_start
= zero
= ii
, max_zeros
= curr_zeros
= 0 ; ii
< 8 ; ++ ii
) {
560 else if ( curr_zeros
> max_zeros
) {
561 max_start
= ii
- curr_zeros
;
562 max_zeros
= curr_zeros
;
566 if ( curr_zeros
> max_zeros
) {
567 max_start
= ii
- curr_zeros
;
568 max_zeros
= curr_zeros
;
571 /* Print the rest of the address */
572 for ( ii
= zero
; ii
< 8 ; ) {
573 if (( ii
== max_start
) && max_zeros
) {
577 inttobase64 ( output
, ntohs ( ip
-> in6
[ ii
]), 3 );
583 strcpy ( output
, "???" );
588 irc_user ( struct userNode
* user
)
591 if (! user
|| IsDummy ( user
))
593 irc_p10_ntop ( b64ip
, & user
-> ip
);
597 irc_user_modes ( user
, modes
, sizeof ( modes
));
598 /* we don't need to put the + in modes because it's in the format string. */
599 putsock ( " %s " P10_NICK
" %s %d " FMT_TIME_T
" %s %s + %s %s %s : %s " ,
600 user
-> uplink
-> numeric
, user
-> nick
, user
-> uplink
-> hops
+ 1 , user
-> timestamp
, user
-> ident
, user
-> hostname
, modes
, b64ip
, user
-> numeric
, user
-> info
);
602 putsock ( " %s " P10_NICK
" %s %d " FMT_TIME_T
" %s %s %s %s : %s " ,
603 user
-> uplink
-> numeric
, user
-> nick
, user
-> uplink
-> hops
+ 1 , user
-> timestamp
, user
-> ident
, user
-> hostname
, b64ip
, user
-> numeric
, user
-> info
);
608 irc_rename ( struct userNode
* user
, const char * new_handle
)
610 if ( extended_accounts
)
611 putsock ( " %s " P10_ACCOUNT
" %s M %s " , self
-> numeric
, user
-> numeric
, new_handle
);
615 irc_delete ( struct userNode
* user
)
617 if ( extended_accounts
)
618 putsock ( " %s " P10_ACCOUNT
" %s U" , self
-> numeric
, user
-> numeric
);
622 irc_account ( struct userNode
* user
, const char * stamp
, time_t timestamp
)
624 if ( extended_accounts
)
625 putsock ( " %s " P10_ACCOUNT
" %s R %s " FMT_TIME_T
, self
-> numeric
, user
-> numeric
, stamp
, timestamp
);
627 putsock ( " %s " P10_ACCOUNT
" %s %s " FMT_TIME_T
, self
-> numeric
, user
-> numeric
, stamp
, timestamp
);
631 irc_fakehost ( struct userNode
* user
, const char * host
)
633 putsock ( " %s " P10_FAKEHOST
" %s %s " , self
-> numeric
, user
-> numeric
, host
);
637 irc_regnick ( UNUSED_ARG ( struct userNode
* user
))
639 /* no operation here */
643 irc_nick ( struct userNode
* user
, UNUSED_ARG ( const char * old_nick
))
645 putsock ( " %s " P10_NICK
" %s " FMT_TIME_T
, user
-> numeric
, user
-> nick
, now
);
649 irc_fetchtopic ( struct userNode
* from
, const char * to
)
653 putsock ( " %s " P10_TOPIC
" %s " , from
-> numeric
, to
);
657 irc_squit ( struct server
* srv
, const char * message
, const char * service_message
)
659 if (! service_message
)
660 service_message
= message
;
662 /* Are we leaving the network? */
663 if ( srv
== self
&& cManager
. uplink
-> state
== CONNECTED
) {
666 /* Quit all clients linked to me. */
667 for ( i
= 0 ; i
<= self
-> num_mask
; i
++) {
670 irc_quit ( self
-> users
[ i
], service_message
);
674 putsock ( " %s " P10_SQUIT
" %s %d : %s " , self
-> numeric
, srv
-> name
, 0 , message
);
677 /* Force a reconnect to the currently selected server. */
678 cManager
. uplink
-> tries
= 0 ;
679 log_module ( MAIN_LOG
, LOG_INFO
, "Squitting from uplink: %s " , message
);
685 irc_wallchops ( struct userNode
* from
, const char * to
, const char * message
)
687 putsock ( " %s " P10_WALLCHOPS
" %s : %s " , from
-> numeric
, to
, message
);
691 irc_wallops ( const char * format
, ...)
695 va_start ( arg_list
, format
);
696 vsnprintf ( buffer
, MAXLEN
- 2 , format
, arg_list
);
697 buffer
[ MAXLEN
- 1 ] = 0 ;
698 putsock ( " %s " P10_WALLOPS
" : %s " , self
-> numeric
, buffer
);
702 deliver_to_dummy ( struct userNode
* source
, struct userNode
* dest
, const char * message
, int type
)
706 if (! dest
|| ! IsDummy ( dest
) || ! IsLocal ( dest
))
708 num
= dest
-> num_local
;
711 if (( num
< num_notice_funcs
) && notice_funcs
[ num
])
712 notice_funcs
[ num
]( source
, dest
, message
, 0 );
715 if (( num
< num_privmsg_funcs
) && privmsg_funcs
[ num
])
716 privmsg_funcs
[ num
]( source
, dest
, message
, 0 );
723 irc_notice ( struct userNode
* from
, const char * to
, const char * message
)
725 if ( to
[ 0 ] == '#' || to
[ 0 ] == '$'
726 || ! deliver_to_dummy ( from
, GetUserN ( to
), message
, 0 ))
727 putsock ( " %s " P10_NOTICE
" %s : %s " , from
-> numeric
, to
, message
);
731 irc_notice_user ( struct userNode
* from
, struct userNode
* to
, const char * message
)
733 if (! deliver_to_dummy ( from
, to
, message
, 0 ))
734 putsock ( " %s " P10_NOTICE
" %s : %s " , from
-> numeric
, to
-> numeric
, message
);
738 irc_privmsg ( struct userNode
* from
, const char * to
, const char * message
)
740 if ( to
[ 0 ] == '#' || to
[ 0 ] == '$'
741 || ! deliver_to_dummy ( from
, GetUserN ( to
), message
, 1 ))
742 putsock ( " %s " P10_PRIVMSG
" %s : %s " , from
-> numeric
, to
, message
);
746 irc_privmsg_user ( struct userNode
* from
, struct userNode
* to
, const char * message
)
748 putsock ( " %s " P10_PRIVMSG
" %s : %s " , from
-> numeric
, to
-> numeric
, message
);
752 irc_version_user ( struct userNode
* from
, struct userNode
* to
)
754 irc_privmsg_user ( from
, to
, " \001 VERSION \001 " );
760 putsock ( " %s " P10_EOB
, self
-> numeric
);
766 putsock ( " %s " P10_EOB_ACK
, self
-> numeric
);
770 str
= conf_get_data ( "services/opserv/nick" , RECDB_QSTRING
);
773 if ( nick
&& ( DefConLevel
< 5 )) {
774 DefConProcess ( GetUserH ( nick
));
776 if ( DefConTimeOut
> 0 )
777 timeq_add ( now
+ DefConTimeOut
, defcon_timeout
, NULL
);
782 irc_rpong ( const char * from1
, const char * from2
, const char * pingtime
, const char * clientinfo
)
784 putsock ( " %s " P10_RPONG
" %s %s %s : %s " , self
-> numeric
, from1
, from2
, pingtime
, clientinfo
);
788 irc_ping ( const char * payload
)
790 putsock ( " %s " P10_PING
" : %s " , self
-> numeric
, payload
);
794 irc_pong ( const char * who
, const char * data
)
796 putsock ( " %s " P10_PONG
" %s : %s " , self
-> numeric
, who
, data
);
800 irc_pong_asll ( const char * who
, const char * orig_ts
)
804 struct timeval sys_now
;
807 orig
. tv_sec
= strtoul ( orig_ts
, & delim
, 10 );
808 orig
. tv_usec
= (* delim
== '.' ) ? strtoul ( delim
+ 1 , NULL
, 10 ) : 0 ;
809 gettimeofday (& sys_now
, NULL
);
810 diff
= ( sys_now
. tv_sec
- orig
. tv_sec
) * 1000 + ( sys_now
. tv_usec
- orig
. tv_usec
) / 1000 ;
811 putsock ( " %s " P10_PONG
" %s %s %d %l u. %0 6lu" , self
-> numeric
, who
, orig_ts
, diff
, ( unsigned long ) sys_now
. tv_sec
, ( unsigned long ) sys_now
. tv_usec
);
815 irc_pass ( const char * passwd
)
817 putsock ( P10_PASS
" : %s " , passwd
);
821 irc_introduce ( const char * passwd
)
823 void timed_send_ping ( void * data
);
825 self
-> self_burst
= self
-> burst
= 1 ;
829 timeq_add ( now
+ ping_freq
, timed_send_ping
, 0 );
833 irc_gline ( struct server
* srv
, struct gline
* gline
, int silent
)
835 putsock ( " %s " P10_GLINE
" %s + %s " FMT_TIME_T
" " FMT_TIME_T
" : %s < %s > %s " ,
836 self
-> numeric
, ( srv
? srv
-> numeric
: "*" ), gline
-> target
, gline
-> expires
- now
, now
, silent
? "AUTO " : "" , gline
-> issuer
, gline
-> reason
);
840 irc_shun ( struct server
* srv
, struct shun
* shun
)
842 putsock ( " %s " P10_SHUN
" %s + %s " FMT_TIME_T
" " FMT_TIME_T
" :< %s > %s " ,
843 self
-> numeric
, ( srv
? srv
-> numeric
: "*" ), shun
-> target
, shun
-> expires
- now
, now
, shun
-> issuer
, shun
-> reason
);
847 irc_settime ( const char * srv_name_mask
, time_t new_time
)
849 ioset_set_time ( new_time
);
850 if (! strcmp ( srv_name_mask
, "*" ))
852 putsock ( " %s " P10_SETTIME
" " FMT_TIME_T
" %s " , self
-> numeric
, new_time
, srv_name_mask
);
856 irc_ungline ( const char * mask
)
858 putsock ( " %s " P10_GLINE
" * - %s " FMT_TIME_T
, self
-> numeric
, mask
, now
);
862 irc_unshun ( const char * mask
)
864 putsock ( " %s " P10_SHUN
" * - %s " FMT_TIME_T
, self
-> numeric
, mask
, now
);
868 irc_burst ( struct chanNode
* chan
)
870 char burst_line
[ 512 ];
871 int pos
, base_len
, len
;
874 struct exemptNode
* en
;
876 unsigned int first_ban
;
877 unsigned int first_exempt
;
880 base_len
= sprintf ( burst_line
, " %s " P10_BURST
" %s " FMT_TIME_T
" " ,
881 self
-> numeric
, chan
-> name
, chan
-> timestamp
);
882 len
= irc_make_chanmode ( chan
, burst_line
+ base_len
);
883 pos
= base_len
+ len
;
884 if ( len
> 0 && chan
-> members
. used
> 0 )
885 burst_line
[ pos
++] = ' ' ;
887 if ( chan
-> members
. used
< 1 )
888 return ; /* dont burst empty channels (created by discrims) */
890 for ( n
= 0 ; n
< chan
-> members
. used
; n
++) {
891 mn
= chan
-> members
. list
[ n
];
893 burst_line
[ pos
- 1 ] = 0 ; /* -1 to back up over the space or comma */
894 putsock ( " %s " , burst_line
);
899 memcpy ( burst_line
+ pos
, mn
-> user
-> numeric
, strlen ( mn
-> user
-> numeric
));
900 pos
+= strlen ( mn
-> user
-> numeric
);
901 if ( mn
-> modes
&& ( mn
-> modes
!= last_mode
)) {
902 last_mode
= mn
-> modes
;
903 burst_line
[ pos
++] = ':' ;
904 if ( last_mode
& MODE_CHANOP
)
905 burst_line
[ pos
++] = 'o' ;
906 if ( last_mode
& MODE_HALFOP
)
907 burst_line
[ pos
++] = 'h' ;
908 if ( last_mode
& MODE_VOICE
)
909 burst_line
[ pos
++] = 'v' ;
911 if (( n
+ 1 )< chan
-> members
. used
)
912 burst_line
[ pos
++] = ',' ;
915 if ( len
> 0 && ( chan
-> banlist
. used
> 0 || chan
-> exemptlist
. used
> 0 ))
916 burst_line
[ pos
++] = ' ' ;
918 if ( chan
-> banlist
. used
) {
922 for ( n
= 0 ; n
< chan
-> banlist
. used
; ) {
923 if ( first_ban
&& ( pos
< 500 )) {
924 burst_line
[ pos
++] = ':' ;
925 burst_line
[ pos
++] = '%' ;
927 bn
= chan
-> banlist
. list
[ n
];
928 len
= strlen ( bn
-> ban
);
929 if ( pos
+ 2 + len
< 505 ) {
930 memcpy ( burst_line
+ pos
, bn
-> ban
, len
);
932 burst_line
[ pos
++] = ' ' ;
936 burst_line
[ pos
- 1 ] = 0 ;
937 putsock ( " %s " , burst_line
);
944 if ( chan
-> exemptlist
. used
) {
945 /* dump the exempts */
948 for ( n
= 0 ; n
< chan
-> exemptlist
. used
; ) {
949 if ( first_exempt
&& ( pos
< 500 )) {
950 if ( chan
-> banlist
. used
< 1 ) {
951 burst_line
[ pos
++] = ':' ;
952 burst_line
[ pos
++] = '%' ;
953 burst_line
[ pos
++] = ' ' ;
955 burst_line
[ pos
++] = '~' ;
956 burst_line
[ pos
++] = ' ' ;
958 en
= chan
-> exemptlist
. list
[ n
];
959 len
= strlen ( en
-> exempt
);
960 if ( pos
+ 2 + len
< 505 ) {
961 memcpy ( burst_line
+ pos
, en
-> exempt
, len
);
963 burst_line
[ pos
++] = ' ' ;
967 burst_line
[ pos
- 1 ] = 0 ;
968 putsock ( " %s " , burst_line
);
974 /* print the last line */
976 putsock ( " %s " , burst_line
);
980 irc_quit ( struct userNode
* user
, const char * message
)
982 putsock ( " %s " P10_QUIT
" : %s " , user
-> numeric
, message
);
986 irc_error ( const char * to
, const char * message
)
989 putsock ( " %s " P10_ERROR
" : %s " , to
, message
);
991 putsock ( ": %s " P10_ERROR
" : %s " , self
-> name
, message
);
996 irc_kill ( struct userNode
* from
, struct userNode
* target
, const char * message
)
999 putsock ( " %s " P10_KILL
" %s : %s ! %s ( %s )" ,
1000 from
-> numeric
, target
-> numeric
, self
-> name
, from
-> nick
, message
);
1002 putsock ( " %s " P10_KILL
" %s : %s ( %s )" ,
1003 self
-> numeric
, target
-> numeric
, self
-> name
, message
);
1008 irc_mode ( struct userNode
* from
, struct chanNode
* target
, const char * modes
)
1010 call_channel_mode_funcs ( from
, target
, ( char **)& modes
, 0 );
1011 putsock ( " %s " P10_MODE
" %s %s " FMT_TIME_T
,
1012 ( from
? from
-> numeric
: self
-> numeric
),
1013 target
-> name
, modes
, target
-> timestamp
);
1016 /* Added to allow services to mode users
1017 2005 - 8 - 10 by Life4Christ
1020 irc_umode ( struct userNode
* target
, const char * modes
)
1022 putsock ( " %s " P10_MODE
" %s %s " , self
-> numeric
, target
-> nick
, modes
);
1027 irc_invite ( struct userNode
* from
, struct userNode
* who
, struct chanNode
* to
)
1029 putsock ( " %s " P10_INVITE
" %s %s " , from
-> numeric
, who
-> nick
, to
-> name
);
1033 irc_silence ( struct userNode
* who
, const char * mask
, int add
)
1035 putsock ( " %s " P10_SILENCE
" %s %s%s " , self
-> numeric
, who
-> numeric
, add
? "+" : "-" , mask
);
1039 irc_join ( struct userNode
* who
, struct chanNode
* what
)
1041 if ( what
-> members
. used
== 1 ) {
1042 putsock ( " %s " P10_CREATE
" %s " FMT_TIME_T
,
1043 who
-> numeric
, what
-> name
, what
-> timestamp
);
1045 putsock ( " %s " P10_JOIN
" %s " FMT_TIME_T
, who
-> numeric
, what
-> name
, what
-> timestamp
);
1050 irc_svsjoin ( struct userNode
* from
, struct userNode
* who
, struct chanNode
* to
)
1052 putsock ( " %s " P10_SVSJOIN
" %s %s " FMT_TIME_T
, from
-> uplink
-> numeric
, who
-> numeric
, to
-> name
, now
);
1056 irc_svspart ( struct userNode
* from
, struct userNode
* who
, struct chanNode
* to
)
1058 putsock ( " %s " P10_SVSPART
" %s %s " , from
-> uplink
-> numeric
, who
-> numeric
, to
-> name
);
1062 irc_svsquit ( struct userNode
* from
, struct userNode
* who
, char const * reason
)
1064 putsock ( " %s " P10_SVSQUIT
" %s : %s " , from
-> uplink
-> numeric
, who
-> numeric
, reason
);
1068 irc_kick ( struct userNode
* who
, struct userNode
* target
, struct chanNode
* channel
, const char * msg
)
1070 const char * numeric
;
1071 struct modeNode
* mn
= GetUserMode ( channel
, who
);
1072 numeric
= (( mn
&& ( mn
-> modes
& MODE_CHANOP
)) || off_channel
) ? who
-> numeric
: self
-> numeric
;
1073 putsock ( " %s " P10_KICK
" %s %s : %s " ,
1074 numeric
, channel
-> name
, target
-> numeric
, msg
);
1078 irc_stats ( struct userNode
* from
, struct server
* target
, char type
)
1080 putsock ( " %s " P10_STATS
" %c : %s " , from
-> numeric
, type
, target
-> numeric
);
1084 irc_svsnick ( struct userNode
* from
, struct userNode
* target
, const char * newnick
)
1086 putsock ( " %s " P10_SVSNICK
" %s %s " FMT_TIME_T
, from
-> uplink
-> numeric
, target
-> numeric
, newnick
, now
);
1090 irc_swhois ( struct userNode
* from
, struct userNode
* target
, const char * message
)
1092 putsock ( " %s " P10_SWHOIS
" %s %s%s " , from
-> uplink
-> numeric
, target
-> numeric
, message
? ":" : "" ,
1093 message
? message
: "" );
1098 irc_tempshun ( struct userNode
* from
, struct userNode
* target
, int remove
, const char * reason
)
1100 putsock ( " %s " P10_TEMPSHUN
" %s %s : %s " , from
-> numeric
, ( remove
? "-" : "+" ), target
-> numeric
, reason
);
1104 irc_part ( struct userNode
* who
, struct chanNode
* what
, const char * reason
)
1107 putsock ( " %s " P10_PART
" %s : %s " , who
-> numeric
, what
-> name
, reason
);
1109 putsock ( " %s " P10_PART
" %s " , who
-> numeric
, what
-> name
);
1114 irc_topic ( struct userNode
* service
, struct userNode
* who
, struct chanNode
* what
, const char * topic
)
1117 int type
= 4 , host_in_topic
= 0 , hasident
= 0 , hhtype
= 0 ;
1118 const char * hstr
, * tstr
, * hhstr
, * htstr
;
1119 char * host
, * hostmask
;
1121 char sident
[ MAXLEN
];
1123 tstr
= conf_get_data ( "server/type" , RECDB_QSTRING
);
1124 hstr
= conf_get_data ( "server/host_in_topic" , RECDB_QSTRING
);
1125 hhstr
= conf_get_data ( "server/hidden_host" , RECDB_QSTRING
);
1126 htstr
= conf_get_data ( "server/hidden_host_type" , RECDB_QSTRING
);
1130 type
= 4 ; /* default to 040 style topics */
1132 hhtype
= atoi ( htstr
);
1135 if ( IsHiddenHost ( who
) && IsFakeHost ( who
))
1136 safestrncpy ( shost
, who
-> fakehost
, sizeof ( shost
));
1137 else if ( IsHiddenHost ( who
) && IsSetHost ( who
)) {
1138 hostmask
= strdup ( who
-> sethost
);
1139 if (( host
= ( strrchr ( hostmask
, '@' )))) {
1146 safestrncpy ( sident
, hostmask
, sizeof ( shost
));
1148 safestrncpy ( sident
, who
-> ident
, sizeof ( shost
));
1150 safestrncpy ( shost
, host
, sizeof ( shost
));
1151 } else if ( IsHiddenHost ( who
) && (( hhtype
== 1 ) || ( hhtype
== 3 )) && who
-> handle_info
&& hhstr
) {
1152 snprintf ( shost
, sizeof ( shost
), " %s . %s " , who
-> handle_info
-> handle
, hhstr
);
1153 } else if ( IsHiddenHost ( who
) && (( hhtype
== 2 ) || ( hhtype
== 3 )) && who
-> crypthost
[ 0 ]) {
1154 safestrncpy ( shost
, who
-> crypthost
, sizeof ( shost
));
1156 safestrncpy ( shost
, who
-> hostname
, sizeof ( shost
));
1158 host_in_topic
= atoi ( hstr
);
1162 putsock ( " %s " P10_TOPIC
" %s %s%s%s%s%s " FMT_TIME_T
" " FMT_TIME_T
" : %s " , service
-> numeric
, what
-> name
,
1163 who
-> nick
, host_in_topic
? "!" : "" , host_in_topic
? ( IsSetHost ( who
) ? sident
: who
-> ident
) : "" ,
1164 host_in_topic
? "@" : "" , host_in_topic
? shost
: "" , what
-> timestamp
, now
, topic
);
1167 putsock ( " %s " P10_TOPIC
" %s : %s " , who
-> numeric
, what
-> name
, topic
);
1172 irc_raw ( const char * what
)
1174 putsock ( " %s " , what
);
1178 irc_numeric ( struct userNode
* user
, unsigned int num
, const char * format
, ...)
1181 char buffer
[ MAXLEN
];
1182 va_start ( arg_list
, format
);
1183 vsnprintf ( buffer
, MAXLEN
- 2 , format
, arg_list
);
1184 buffer
[ MAXLEN
- 1 ] = 0 ;
1185 putsock ( ": %s %0 3d %s %s " , self
-> name
, num
, user
-> nick
, buffer
);
1189 irc_mark ( struct userNode
* user
, char * mark
)
1191 char * host
= user
-> hostname
;
1193 const char * tstr
= NULL
;
1194 unsigned int ii
= 0 ;
1197 tstr
= conf_get_data ( "server/type" , RECDB_QSTRING
);
1204 for ( ii
= 0 ; ii
< user
-> marks
-> used
; ii
++)
1205 if (! irccasecmp ( user
-> marks
-> list
[ ii
], mark
))
1211 user
-> marks
= alloc_string_list ( 1 );
1212 string_list_append ( user
-> marks
, strdup ( mark
));
1217 putsock ( " %s " CMD_MARK
" %s MARK %s " , self
-> numeric
, user
-> nick
, mark
);
1221 /* TODO: Allow mark overwrite. If they are marked, and their fakehost is oldmark.hostname, update it to newmark.hostname so mark can be called multiple times. Probably requires ircd modification also */
1225 /* if the mark will put us over the host length, clip some off the left hand side
1228 if ( strlen ( host
) + 1 + strlen ( mark
) > HOSTLEN
)
1229 host
+= 1 + ( ( strlen ( host
) + 1 + strlen ( mark
)) - HOSTLEN
);
1230 putsock ( " %s " CMD_MARK
" %s DNSBL +m %s . %s " , self
-> numeric
, user
-> nick
, mark
, host
);
1231 putsock ( " %s " CMD_MARK
" %s DNSBL_DATA %s " , self
-> numeric
, user
-> nick
, mark
);
1233 /* Save it in the user */
1234 user
-> mark
= strdup ( mark
);
1236 /* If they are not otherwise marked, mark their host with fakehost */
1237 if (! IsFakeHost ( user
) && ! IsSetHost ( user
) && !( IsHiddenHost ( user
) && user
-> handle_info
) )
1239 struct modeNode
* mn
= NULL
;
1240 char fakehost
[ HOSTLEN
];
1241 unsigned int count
= 0 ;
1244 putsock ( " %s " CMD_FAKEHOST
" %s %s . %s " , self
-> numeric
, user
-> numeric
, mark
, host
);
1245 putsock ( " %s " CMD_MODE
" %s +x" , self
-> numeric
, user
-> nick
);
1247 snprintf ( fakehost
, sizeof ( fakehost
), " %s . %s " , mark
, host
);
1248 safestrncpy ( user
-> fakehost
, fakehost
, sizeof ( user
-> fakehost
));
1250 for ( n
= count
= 0 ; n
< user
-> channels
. used
; n
++) {
1251 mn
= user
-> channels
. list
[ n
];
1252 if ( strlen ( mn
-> channel
-> name
) >= 1 ) /* Sanity */
1253 check_bans ( user
, mn
-> channel
-> name
);
1258 void irc_sno ( unsigned int mask
, char const * format
, ...) {
1260 char buffer
[ MAXLEN
];
1261 va_start ( arg_list
, format
);
1262 vsnprintf ( buffer
, MAXLEN
- 2 , format
, arg_list
);
1263 buffer
[ MAXLEN
- 1 ] = 0 ;
1264 putsock ( " %s " CMD_SNO
" %d : %s " , self
-> numeric
, mask
, buffer
);
1268 irc_sasl ( struct server
* dest
, const char * identifier
, const char * subcmd
, const char * data
)
1270 putsock ( " %s " P10_SASL
" %s %s %s %s " , self
-> numeric
, dest
-> numeric
, identifier
, subcmd
, data
);
1273 static void send_burst ( void );
1276 change_nicklen ( int new_nicklen
)
1279 char new_nick
[ NICKLEN
+ 1 ];
1280 struct userNode
* user
;
1282 nicklen
= new_nicklen
;
1283 /* fix up any users we have here */
1284 for ( nn
= 0 ; nn
<= self
-> num_mask
; nn
++) {
1285 if (!( user
= self
-> users
[ nn
]))
1287 safestrncpy ( new_nick
, user
-> nick
, sizeof ( new_nick
));
1288 new_nick
[ nicklen
] = 0 ;
1289 NickChange ( user
, new_nick
, 1 );
1293 static CMD_FUNC ( cmd_whois
)
1295 struct userNode
* from
;
1296 struct userNode
* who
;
1298 unsigned int i
, mlen
, len
;
1302 if (!( from
= GetUserH ( origin
))) {
1303 log_module ( MAIN_LOG
, LOG_ERROR
, "Could not find WHOIS origin user %s " , origin
);
1306 if (!( who
= GetUserH ( argv
[ 2 ]))) {
1307 irc_numeric ( from
, ERR_NOSUCHNICK
, " %s @ %s :No such nick" , argv
[ 2 ], self
-> name
);
1311 if ( IsFakeHost ( who
) && IsHiddenHost ( who
))
1312 irc_numeric ( from
, RPL_WHOISUSER
, " %s %s %s * : %s " , who
-> nick
, who
-> ident
, who
-> fakehost
, who
-> info
);
1313 else if ( IsHiddenHost ( who
) && who
-> handle_info
&& hidden_host_suffix
)
1314 irc_numeric ( from
, RPL_WHOISUSER
, " %s %s %s . %s * : %s " , who
-> nick
, who
-> ident
, who
-> handle_info
-> handle
, hidden_host_suffix
, who
-> info
);
1316 irc_numeric ( from
, RPL_WHOISUSER
, " %s %s %s * : %s " , who
-> nick
, who
-> ident
, who
-> hostname
, who
-> info
);
1318 if (! IsService ( who
) || ( from
== who
)) {
1319 struct modeNode
* mn
;
1320 mlen
= strlen ( self
-> name
) + strlen ( from
-> nick
) + 12 + strlen ( who
-> nick
);
1323 for ( i
= who
-> channels
. used
; i
> 0 ; )
1325 mn
= who
-> channels
. list
[-- i
];
1327 if (! IsOper ( from
) && ( mn
-> channel
-> modes
& ( MODE_PRIVATE
| MODE_SECRET
)) && ! GetUserMode ( mn
-> channel
, from
))
1330 if ( len
+ strlen ( mn
-> channel
-> name
) + mlen
> MAXLEN
- 5 )
1332 irc_numeric ( from
, RPL_WHOISCHANNELS
, " %s : %s " , who
-> nick
, buf
);
1338 *( buf
+ len
++) = '-' ;
1339 if (( mn
-> channel
-> modes
& ( MODE_PRIVATE
| MODE_SECRET
)) && ! GetUserMode ( mn
-> channel
, from
))
1340 *( buf
+ len
++) = '*' ;
1341 if ( mn
-> modes
& MODE_CHANOP
)
1342 *( buf
+ len
++) = '@' ;
1343 else if ( mn
-> modes
& MODE_HALFOP
)
1344 *( buf
+ len
++) = '%' ;
1345 else if ( mn
-> modes
& MODE_VOICE
)
1346 *( buf
+ len
++) = '+' ;
1349 *( buf
+ len
) = '\0' ;
1350 strcpy ( buf
+ len
, mn
-> channel
-> name
);
1351 len
+= strlen ( mn
-> channel
-> name
);
1352 strcat ( buf
+ len
, " " );
1356 irc_numeric ( from
, RPL_WHOISCHANNELS
, " %s : %s " , who
-> nick
, buf
);
1359 if ( his_servername
&& his_servercomment
&& ! IsOper ( from
) && from
!= who
)
1360 irc_numeric ( from
, RPL_WHOISSERVER
, " %s %s : %s " , who
-> nick
, his_servername
, his_servercomment
);
1362 irc_numeric ( from
, RPL_WHOISSERVER
, " %s %s : %s " , who
-> nick
, who
-> uplink
-> name
, who
-> uplink
-> description
);
1365 irc_numeric ( from
, RPL_AWAY
, " %s :Away" , who
-> nick
);
1367 irc_numeric ( from
, RPL_WHOISOPERATOR
, " %s : %s " , who
-> nick
, IsLocal ( who
) ? "is a megalomaniacal power hungry tyrant" : "is an IRC Operator" );
1368 if ( who
-> handle_info
)
1369 irc_numeric ( from
, RPL_WHOISACCOUNT
, " %s %s :is logged in as" , who
-> nick
, who
-> handle_info
-> handle
);
1370 if ( IsHiddenHost ( who
) && who
-> handle_info
&& ( IsOper ( from
) || from
== who
))
1371 irc_numeric ( from
, RPL_WHOISACTUALLY
, " %s %s @ %s %s :Actual user@host, Actual IP" , who
-> nick
, who
-> ident
, who
-> hostname
, irc_ntoa (& who
-> ip
));
1372 if ( IsLocal ( who
) && ! IsService ( who
) && ( IsOper ( from
) || from
== who
))
1373 irc_numeric ( from
, RPL_WHOISIDLE
, " %s %l d %l d :seconds idle, signon time" , who
-> nick
, now
- who
-> idle_since
, who
-> timestamp
);
1375 irc_numeric ( from
, RPL_ENDOFWHOIS
, " %s :End of /WHOIS list" , who
-> nick
);
1379 static CMD_FUNC ( cmd_server
)
1387 /* another server introduced us */
1388 srv
= AddServer ( GetServerH ( origin
), argv
[ 1 ], atoi ( argv
[ 2 ]), atoi ( argv
[ 3 ]), atoi ( argv
[ 4 ]), argv
[ 6 ], argv
[ argc
- 1 ]);
1391 srv
-> self_burst
= argv
[ 5 ][ 0 ] == 'J' ;
1394 /* this must be our uplink */
1395 srv
= self
-> uplink
= AddServer ( self
, argv
[ 1 ], atoi ( argv
[ 2 ]), atoi ( argv
[ 3 ]), atoi ( argv
[ 4 ]), argv
[ 6 ], argv
[ argc
- 1 ]);
1398 srv
-> self_burst
= argv
[ 5 ][ 0 ] == 'J' ;
1400 if (( argv
[ 7 ][ 0 ] == '+' ) && ! force_n2k
) {
1401 log_module ( MAIN_LOG
, LOG_WARNING
, "Got Undernet-style SERVER message but \" force_n2k \" not on." );
1406 /* Fix up our timestamps if necessary. */
1407 if ( srv
-> boot
<= PREHISTORY
) {
1408 /* Server from the mists of time.. */
1409 if ( srv
-> hops
== 1 ) {
1410 log_module ( MAIN_LOG
, LOG_ERROR
, "Server %s claims to have booted at time " FMT_TIME_T
". This is absurd." , srv
-> name
, srv
-> boot
);
1412 } else if (( str
= conf_get_data ( "server/reliable_clock" , RECDB_QSTRING
))
1413 && enabled_string ( str
)) {
1414 /* If we have a reliable clock, we just keep our current time. */
1416 if ( srv
-> boot
<= self
-> boot
) {
1417 /* The other server is older than us. Accept their timestamp.
1418 * Alternately, we are same age, but we accept their time
1419 * since we are linking to them. */
1420 self
-> boot
= srv
-> boot
;
1421 ioset_set_time ( srv
-> link_time
1425 if ( srv
== self
-> uplink
) {
1426 extern time_t burst_begin
;
1433 static CMD_FUNC ( cmd_eob
)
1435 struct server
* sender
;
1438 if (!( sender
= GetServerH ( origin
)))
1440 if ( sender
== self
-> uplink
) {
1441 cManager
. uplink
-> state
= CONNECTED
;
1442 for ( it
= dict_first ( unbursted_channels
); it
; it
= iter_next ( it
))
1443 irc_burst ( iter_data ( it
));
1444 dict_delete ( unbursted_channels
);
1445 unbursted_channels
= NULL
;
1449 /* now that we know who our uplink is,
1450 * we can center the routing map and activate auto-routing.
1452 //activate_routing(NULL, NULL, NULL);
1455 sender
-> self_burst
= 0 ;
1456 recalc_bursts ( sender
);
1457 call_server_link_funcs ( sender
);
1458 /* let auto-routing figure out if we were
1459 * wating on this server to link a child to it */
1460 /* DONT call this if uplink is _US_ */
1461 if ( sender
-> uplink
!= self
)
1462 routing_handle_connect ( sender
-> name
, sender
-> uplink
-> name
);
1466 static CMD_FUNC ( cmd_eob_ack
)
1468 extern time_t burst_begin
;
1470 if ( GetServerH ( origin
) == self
-> uplink
) {
1471 burst_length
= now
- burst_begin
;
1472 self
-> self_burst
= self
-> burst
= 0 ;
1474 cManager
. uplink
-> state
= CONNECTED
;
1478 static CMD_FUNC ( cmd_rping
)
1480 struct server
* dest
;
1482 if (!( dest
= GetServerN ( argv
[ 1 ])))
1483 return 1 ; /* if its a jupe or something, return 1 so its silently ignored */
1486 irc_rpong ( argv
[ 2 ], argv
[ 3 ], argv
[ 4 ], argv
[ 5 ]);
1491 static CMD_FUNC ( cmd_sasl
)
1493 struct server
* serv
;
1498 serv
= GetServerH ( origin
);
1502 call_sasl_input_func ( serv
, argv
[ 2 ], argv
[ 3 ], argv
[ 4 ], ( argc
> 5 ? argv
[ argc
- 1 ] : NULL
));
1507 static CMD_FUNC ( cmd_ping
)
1510 struct userNode
* un
;
1513 irc_pong_asll ( argv
[ 2 ], argv
[ 3 ]);
1514 else if (( srv
= GetServerH ( origin
)))
1515 irc_pong ( self
-> name
, srv
-> numeric
);
1516 else if (( un
= GetUserH ( origin
)))
1517 irc_pong ( self
-> name
, un
-> numeric
);
1519 irc_pong ( self
-> name
, origin
);
1521 timeq_del ( 0 , timed_send_ping
, 0 , TIMEQ_IGNORE_WHEN
| TIMEQ_IGNORE_DATA
);
1522 timeq_del ( 0 , timed_ping_timeout
, 0 , TIMEQ_IGNORE_WHEN
| TIMEQ_IGNORE_DATA
);
1523 timeq_add ( now
+ ping_freq
, timed_send_ping
, 0 );
1528 static CMD_FUNC ( cmd_error_nick
)
1530 /* Go back to original IRC length .. and try to reconnect :/ */
1532 irc_squit ( self
, "Got erroneous nickname, truncating nicks." , NULL
);
1536 struct create_desc
{
1537 struct userNode
* user
;
1542 join_helper ( struct chanNode
* chan
, void * data
)
1544 struct create_desc
* cd
= data
;
1545 AddChannelUser ( cd
-> user
, chan
);
1549 create_helper ( char * name
, void * data
)
1551 struct create_desc
* cd
= data
;
1553 if (! strcmp ( name
, "0" )) {
1554 while ( cd
-> user
-> channels
. used
> 0 )
1555 DelChannelUser ( cd
-> user
, cd
-> user
-> channels
. list
[ 0 ]-> channel
, 0 , 0 );
1559 AddChannelUser ( cd
-> user
, AddChannel ( name
, cd
-> when
, NULL
, NULL
, NULL
));
1562 static CMD_FUNC ( cmd_create
)
1564 struct create_desc cd
;
1565 struct userNode
* user
;
1567 if (( argc
< 3 ) || !( user
= GetUserH ( origin
)))
1570 cd
. when
= atoi ( argv
[ 2 ]);
1571 parse_foreach ( argv
[ 1 ], join_helper
, create_helper
, NULL
, NULL
, & cd
);
1575 static CMD_FUNC ( cmd_join
)
1577 struct create_desc cd
;
1579 if (!( cd
. user
= GetUserH ( origin
)))
1586 cd
. when
= atoi ( argv
[ 2 ]);
1587 parse_foreach ( argv
[ 1 ], join_helper
, create_helper
, NULL
, NULL
, & cd
);
1591 static CMD_FUNC ( cmd_svsjoin
)
1593 struct create_desc cd
;
1595 if (!( cd
. user
= GetUserH ( argv
[ 1 ])))
1602 cd
. when
= atoi ( argv
[ 3 ]);
1603 parse_foreach ( argv
[ 2 ], join_helper
, create_helper
, NULL
, NULL
, & cd
);
1607 static CMD_FUNC ( cmd_pong
)
1611 if (! strcmp ( argv
[ 2 ], self
-> name
)) {
1612 timeq_del ( 0 , timed_send_ping
, 0 , TIMEQ_IGNORE_WHEN
| TIMEQ_IGNORE_DATA
);
1613 timeq_del ( 0 , timed_ping_timeout
, 0 , TIMEQ_IGNORE_WHEN
| TIMEQ_IGNORE_DATA
);
1614 timeq_add ( now
+ ping_freq
, timed_send_ping
, 0 );
1620 static CMD_FUNC ( cmd_nick
)
1622 struct userNode
* user
;
1623 if (( user
= GetUserH ( origin
))) {
1624 /* nick change (since the source is a user numeric) */
1627 NickChange ( user
, argv
[ 1 ], 1 );
1629 struct server
* serv
;
1634 serv
= GetServerH ( origin
);
1636 unsplit_string ( argv
+ 6 , argc
- 9 , modes
);
1639 AddUser ( serv
, argv
[ 1 ], argv
[ 4 ], argv
[ 5 ], modes
, argv
[ argc
- 2 ], argv
[ argc
- 1 ], atoi ( argv
[ 3 ]), argv
[ argc
- 3 ]);
1644 static CMD_FUNC ( cmd_account
)
1646 struct userNode
* user
;
1647 struct server
* server
;
1648 struct handle_info
* hi
;
1650 if (( argc
< 3 ) || ! origin
|| !( server
= GetServerH ( origin
)))
1651 return 0 ; /* Origin must be server. */
1653 /* This next line appears to tremple origin.. why? */
1654 user
= GetUserN ( argv
[ 1 ]);
1656 return 1 ; /* A QUIT probably passed the ACCOUNT. */
1658 if (! extended_accounts
) /* any need for this function without? */
1661 if (! strcmp ( argv
[ 2 ], "C" ))
1663 if (( hi
= loc_auth ( NULL
, argv
[ 4 ], argv
[ 5 ], NULL
)))
1666 putsock ( " %s " P10_ACCOUNT
" %s A %s " FMT_TIME_T
, self
-> numeric
, server
-> numeric
, argv
[ 3 ], hi
-> registered
);
1668 log_module ( MAIN_LOG
, LOG_DEBUG
, "loc_auth: %s \n " , user
-> nick
);
1673 putsock ( " %s " P10_ACCOUNT
" %s D %s " , self
-> numeric
, server
-> numeric
, argv
[ 3 ]);
1677 else if (! strcmp ( argv
[ 2 ], "H" )) /* New enhanced (host) version of C */
1679 if (( hi
= loc_auth ( NULL
, argv
[ 5 ], argv
[ 6 ], argv
[ 4 ] )))
1682 putsock ( " %s " P10_ACCOUNT
" %s A %s " FMT_TIME_T
, self
-> numeric
, server
-> numeric
, argv
[ 3 ], hi
-> registered
);
1687 putsock ( " %s " P10_ACCOUNT
" %s D %s " , self
-> numeric
, server
-> numeric
, argv
[ 3 ]);
1691 else if (! strcmp ( argv
[ 2 ], "S" ))
1693 if (( hi
= loc_auth ( argv
[ 5 ], argv
[ 6 ], argv
[ 7 ], argv
[ 4 ])))
1696 putsock ( " %s " P10_ACCOUNT
" %s A %s " FMT_TIME_T
, self
-> numeric
, server
-> numeric
, argv
[ 3 ], hi
-> registered
);
1701 putsock ( " %s " P10_ACCOUNT
" %s D %s " , self
-> numeric
, server
-> numeric
, argv
[ 3 ]);
1705 else if (! strcmp ( argv
[ 2 ], "R" ))
1706 call_account_func ( user
, argv
[ 3 ]);
1708 call_account_func ( user
, argv
[ 2 ]); /* For backward compatability */
1712 static CMD_FUNC ( cmd_fakehost
)
1714 struct userNode
* user
;
1716 if (( argc
< 3 ) || ! origin
|| ! GetServerH ( origin
))
1718 if (!( user
= GetUserN ( argv
[ 1 ])))
1720 assign_fakehost ( user
, argv
[ 2 ], 0 );
1728 #define P(priv) { #priv, PRIV_ ## priv }
1729 P ( CHAN_LIMIT
), P ( MODE_LCHAN
), P ( WALK_LCHAN
), P ( DEOP_LCHAN
),
1730 P ( SHOW_INVIS
), P ( SHOW_ALL_INVIS
), P ( UNLIMIT_QUERY
), P ( KILL
),
1731 P ( LOCAL_KILL
), P ( REHASH
), P ( RESTART
), P ( DIE
),
1732 P ( GLINE
), P ( LOCAL_GLINE
), P ( JUPE
), P ( LOCAL_JUPE
),
1733 P ( OPMODE
), P ( LOCAL_OPMODE
), P ( SET
), P ( WHOX
),
1734 P ( BADCHAN
), P ( LOCAL_BADCHAN
), P ( SEE_CHAN
), P ( PROPAGATE
),
1735 P ( DISPLAY
), P ( SEE_OPERS
), P ( WIDE_GLINE
), P ( FORCE_OPMODE
),
1736 P ( FORCE_LOCAL_OPMODE
), P ( REMOTEREHASH
), P ( CHECK
), P ( SEE_SECRET_CHAN
),
1737 P ( SHUN
), P ( LOCAL_SHUN
), P ( WIDE_SHUN
), P ( ZLINE
),
1738 P ( LOCAL_ZLINE
), P ( WIDE_ZLINE
), P ( LIST_CHAN
), P ( WHOIS_NOTICE
),
1739 P ( HIDE_IDLE
), P ( XTRAOP
), P ( HIDE_CHANNELS
), P ( DISPLAY_MODE
),
1740 P ( FREEFORM
), P ( REMOVE
), P ( SPAMFILTER
), P ( ADMIN
),
1741 P ( APASS_OPMODE
), P ( HIDE_OPER
), P ( REMOTE
), P ( SERVICE
),
1746 char * client_report_privs ( struct userNode
* client
)
1751 for ( i
= 0 ; privtab
[ i
]. name
; i
++) {
1752 if ( HasPriv ( client
, privtab
[ i
]. priv
)) {
1753 strcat ( privbuf
, privtab
[ i
]. name
);
1754 strcat ( privbuf
, " " );
1758 privbuf
[ strlen ( privbuf
)] = 0 ;
1763 int clear_privs ( struct userNode
* who
) {
1767 for ( i
= 0 ; privtab
[ i
]. name
; i
++)
1768 RevokePriv ( who
, privtab
[ i
]. priv
);
1773 int client_modify_priv_by_name ( struct userNode
* who
, char * priv
, int what
) {
1778 for ( i
= 0 ; privtab
[ i
]. name
; i
++) {
1779 if ( 0 == strcmp ( privtab
[ i
]. name
, priv
)) {
1780 if ( what
== PRIV_ADD
)
1781 GrantPriv ( who
, privtab
[ i
]. priv
);
1782 else if ( what
== PRIV_DEL
) {
1783 RevokePriv ( who
, privtab
[ i
]. priv
);
1790 int check_priv ( char * priv
)
1794 for ( i
= 0 ; privtab
[ i
]. name
; i
++) {
1795 if ( 0 == strcmp ( privtab
[ i
]. name
, priv
)) {
1803 irc_privs ( struct userNode
* target
, char * flag
, int add
)
1805 client_modify_priv_by_name ( target
, flag
, add
);
1806 putsock ( " %s " P10_PRIVS
" %s %s%s " , self
-> numeric
, target
-> numeric
, ( add
== PRIV_ADD
) ? "+" : "-" , flag
);
1810 irc_raw_privs ( struct userNode
* target
, const char * privs
)
1812 putsock ( " %s " P10_PRIVS
" %s %s " , self
-> numeric
, target
-> numeric
, privs
);
1815 static CMD_FUNC ( cmd_privs
)
1822 int what
= PRIV_ADD
;
1827 struct server
* sender
;
1828 struct userNode
* user
;
1831 tstr
= conf_get_data ( "server/type" , RECDB_QSTRING
);
1836 if (!( sender
= GetServerH ( origin
))) { /* from oper */
1837 return 1 ; /* ignore as no services have privs set */
1838 } else { /* from server */
1840 return 1 ; /* silently ignore */
1842 user
= argc
> 1 ? GetUserN ( argv
[ 1 ]) : NULL
;
1847 for ( i
= 1 ; i
< argc
; i
++) {
1848 strcat ( buf
, argv
[ i
]);
1852 for ( i
= 2 ; i
< argc
; i
++) {
1853 if (* argv
[ i
] == '+' ) { what
= PRIV_ADD
; argv
[ i
]++; }
1854 if (* argv
[ i
] == '-' ) { what
= PRIV_DEL
; argv
[ i
]++; }
1855 for ( tmp
= x3_strtok (& p
, argv
[ i
], "," ); tmp
;
1856 tmp
= x3_strtok (& p
, NULL
, "," )) {
1857 if (! strcmp ( tmp
, "PRIV_NONE" )) {
1858 if ( now
> user
-> timestamp
+ 5 )
1862 client_modify_priv_by_name ( user
, tmp
, what
);
1869 static CMD_FUNC ( cmd_burst
)
1872 char modes
[ MAXLEN
], * members
= "" ;
1873 static char exemptlist
[ MAXLEN
], banlist
[ MAXLEN
];
1874 unsigned int next
= 3 , res
= 1 ;
1875 int ctype
= 0 , echeck
= 0 , bcheck
= 0 ;
1876 struct chanData
* cData
;
1877 struct chanNode
* cNode
;
1878 struct userNode
* un
;
1879 struct modeNode
* mNode
;
1883 char * user
, * end
, sep
;
1885 time_t in_timestamp
;
1892 tstr
= conf_get_data ( "server/type" , RECDB_QSTRING
);
1900 while ( next
< argc
) {
1901 switch ( argv
[ next
][ 0 ]) {
1905 for ( pos
= argv
[ next
], n_modes
= 1 ; * pos
; pos
++)
1906 if ((* pos
== 'k' ) || (* pos
== 'l' ) || (* pos
== 'A' )
1907 || (* pos
== 'U' ) || (( type
> 7 ) && (* pos
== 'L' )))
1909 if ( next
+ n_modes
> argc
)
1910 n_modes
= argc
- next
;
1911 unsplit_string ( argv
+ next
, n_modes
, modes
);
1917 for ( parm
= mysep (& argv
[ next
], " " ); /* parm = first param */
1918 parm
; /* While param is not null */
1919 parm
= mysep (& argv
[ next
], " " ) /* parm = next param */
1922 if ( 0 == strcmp ( "~" , parm
))
1926 /* strip % char off start of very first ban */
1927 if ( strlen ( parm
) > 1 ) {
1928 strncat ( banlist
, strtok ( parm
, "%" ), sizeof ( banlist
) - 1 - strlen ( banlist
));
1929 strncat ( banlist
, " " , sizeof ( banlist
) - 1 - strlen ( banlist
));
1933 strncat ( banlist
, parm
, sizeof ( banlist
) - 1 - strlen ( banlist
));
1934 strncat ( banlist
, " " , sizeof ( banlist
) - 1 - strlen ( banlist
));
1936 } else if ( ctype
== 2 ) {
1940 strncat ( exemptlist
, parm
, sizeof ( exemptlist
) - 1 - strlen ( exemptlist
));
1941 strncat ( exemptlist
, " " , sizeof ( exemptlist
) - 1 - strlen ( exemptlist
));
1948 default : members
= argv
[ next
++]; break ;
1952 in_timestamp
= atoi ( argv
[ 2 ]);
1953 if (( cNode
= dict_find ( unbursted_channels
, argv
[ 1 ], NULL
))) {
1954 cNode
-> timestamp
= in_timestamp
;
1955 dict_remove ( unbursted_channels
, cNode
-> name
);
1958 cNode
= AddChannel ( argv
[ 1 ], in_timestamp
, modes
, banlist
, exemptlist
);
1959 cData
= cNode
-> channel_info
;
1962 if ( cNode
-> modes
& MODE_REGISTERED
) {
1963 irc_join ( opserv
, cNode
);
1964 irc_mode ( opserv
, cNode
, "-z" );
1965 irc_part ( opserv
, cNode
, "" );
1969 /* Burst channel members in now. */
1970 for ( user
= members
, sep
= * members
, mode
= 0 ; sep
; user
= end
) {
1971 for ( end
= user
+ 3 ; isalnum (* end
) || * end
== '[' || * end
== ']' ; end
++) ;
1972 sep
= * end
++; end
[- 1 ] = 0 ;
1975 while (( sep
= * end
++)) {
1977 mode
|= MODE_CHANOP
;
1979 } else if ( sep
== 'h' ) {
1980 mode
|= MODE_HALFOP
;
1982 } else if ( sep
== 'v' ) {
1985 } else if ( isdigit ( sep
)) {
1986 mode
|= MODE_CHANOP
;
1988 oplevel
+= parse_oplevel ( end
);
1990 oplevel
= parse_oplevel ( end
);
1991 while ( isdigit (* end
)) end
++;
1998 if (!( un
= GetUserN ( user
))) {
2002 if (( mNode
= AddChannelUser ( un
, cNode
))) {
2003 mNode
-> modes
= mode
;
2004 mNode
-> oplevel
= oplevel
;
2012 * This is a stub that doesn't actually do anything. It should be completed
2013 * so that bans on *!*@markname.* match users as it does in nefarious
2015 static CMD_FUNC ( cmd_mark
)
2019 struct userNode
* target
;
2021 * log_module(MAIN_LOG, LOG_ERROR, "DEBUG: mark, user %s, type %s, arg %s", argv[1], argv[2], argv[3]);
2024 tstr
= conf_get_data ( "server/type" , RECDB_QSTRING
);
2028 type
= 4 ; /* default to 040 style topics */
2032 if (! strcasecmp ( argv
[ 2 ], "DNSBL" )) {
2036 else if (! strcasecmp ( argv
[ 2 ], "DNSBL_DATA" ) || ! strcasecmp ( argv
[ 2 ], "MARK" )) {
2038 unsigned int ii
= 0 ;
2039 /* DNSBL_DATA name */
2040 target
= GetUserH ( argv
[ 1 ]);
2042 log_module ( MAIN_LOG
, LOG_ERROR
, "Unable to find user %s whose dnsbl mark is changing." , argv
[ 1 ]);
2047 for ( ii
= 0 ; ii
< target
-> marks
-> used
; ii
++)
2048 if (! irccasecmp ( target
-> marks
-> list
[ ii
], argv
[ 3 ]))
2053 target
-> marks
= alloc_string_list ( 1 );
2054 string_list_append ( target
-> marks
, strdup ( argv
[ 3 ]));
2057 target
-> mark
= strdup ( argv
[ 3 ]);
2061 else if (! strcasecmp ( argv
[ 2 ], "CVERSION" )) {
2062 /* CTCP VERSION mark */
2063 target
= GetUserH ( argv
[ 1 ]);
2065 log_module ( MAIN_LOG
, LOG_ERROR
, "Unable to find user %s whose version mark is changing." , argv
[ 1 ]);
2069 char * version
= unsplit_string ( argv
+ 3 , argc
- 3 , NULL
);
2073 target
-> version_reply
= strdup ( version
);
2075 if ( match_ircglob ( version
, "WebTV;*" ))
2076 target
-> no_notice
= true ; /* webbies cant see notices */
2080 else if (! strcasecmp ( argv
[ 2 ], "SSLCLIFP" )) {
2081 /* SSL fingerprint mark */
2082 target
= GetUserH ( argv
[ 1 ]);
2084 log_module ( MAIN_LOG
, LOG_ERROR
, "Unable to find user %s whose SSL fingerprint mark is changing." , argv
[ 1 ]);
2088 char * sslfp
= unsplit_string ( argv
+ 3 , argc
- 3 , NULL
);
2092 target
-> sslfp
= strdup ( sslfp
);
2094 nickserv_do_autoauth ( target
);
2098 /* unknown type of mark */
2102 static CMD_FUNC ( cmd_mode
)
2104 struct chanNode
* cn
;
2105 struct userNode
* un
;
2106 char * sethost
; // sethost - reed/apples
2107 int i
; // sethost - reed/apples
2111 if (! IsChannelName ( argv
[ 1 ])) {
2112 un
= GetUserH ( argv
[ 1 ]);
2114 log_module ( MAIN_LOG
, LOG_ERROR
, "Unable to find user %s whose mode is changing." , argv
[ 1 ]);
2117 // sethost - reed/apples
2119 mod_usermode ( un
, argv
[ 2 ]);
2121 sethost
= malloc ( strlen ( argv
[ 2 ]) + 1 + strlen ( argv
[ 3 ]) + 1 );
2123 while (( sethost
[ i
++] = * argv
[ 2 ]++));
2126 while (( sethost
[ i
++] = * argv
[ 3 ]++));
2127 mod_usermode ( un
, sethost
); // sethost - reed/apples
2133 if (!( cn
= GetChannel ( argv
[ 1 ]))) {
2134 log_module ( MAIN_LOG
, LOG_ERROR
, "Unable to find channel %s whose mode is changing." , argv
[ 1 ]);
2137 if (( un
= GetUserH ( origin
))) {
2138 struct modeNode
* mn
;
2139 /* Update idle time for person setting the mode */
2140 if (( mn
= GetUserMode ( cn
, un
)))
2141 mn
-> idle_since
= now
;
2143 /* If it came from a server, reset timestamp to re-sync. */
2144 cn
-> timestamp
= atoi ( argv
[ argc
- 1 ]);
2147 if ( checkDefCon ( DEFCON_NO_MODE_CHANGE
) && ! IsOper ( un
)) {
2149 str
= conf_get_data ( "services/opserv/nick" , RECDB_QSTRING
);
2151 char modes
[ MODELEN
];
2152 struct userNode
* opserv
= GetUserH ( str
);
2154 send_message_type ( 4 , un
, opserv
, "Channel modes cannot be changed due to DefCon level %d in effect, please try again soon" , DefConLevel
);
2155 irc_make_chanmode ( cn
, modes
);
2156 irc_mode ( opserv
, cn
, modes
);
2157 irc_mode ( opserv
, cn
, DefConChanModes
);
2163 return mod_chanmode ( un
, cn
, argv
+ 2 , argc
- 2 , MCP_ALLOW_OVB
| MCP_FROM_SERVER
|( un
? MC_NOTIFY
: 0 ));
2166 static CMD_FUNC ( cmd_opmode
)
2168 struct chanNode
* cn
;
2169 struct userNode
* un
;
2174 if (!( cn
= GetChannel ( argv
[ 1 ]))) {
2175 log_module ( MAIN_LOG
, LOG_ERROR
, "Unable to find channel %s whose mode is changing." , argv
[ 1 ]);
2178 if (!( un
= GetUserH ( origin
))) {
2179 log_module ( MAIN_LOG
, LOG_ERROR
, "Unable to find user %s requesting OPMODE." , origin
);
2183 log_module ( MAIN_LOG
, LOG_ERROR
, "Non-privileged user %s using OPMODE." , un
-> nick
);
2187 return mod_chanmode ( un
, cn
, argv
+ 2 , argc
- 2 , MCP_ALLOW_OVB
| MCP_FROM_SERVER
); /* do NOT announce opmode locally */
2190 static int clear_chanmode ( struct chanNode
* channel
, const char * modes
);
2192 static CMD_FUNC ( cmd_clearmode
)
2194 struct chanNode
* cn
;
2195 struct userNode
* un
;
2200 if (!( cn
= GetChannel ( argv
[ 1 ]))) {
2201 log_module ( MAIN_LOG
, LOG_ERROR
, "Unable to find channel %s whose mode is changing." , argv
[ 1 ]);
2204 if (!( un
= GetUserH ( origin
))) {
2205 log_module ( MAIN_LOG
, LOG_ERROR
, "Unable to find user %s requesting CLEARMODE." , origin
);
2209 log_module ( MAIN_LOG
, LOG_ERROR
, "Non-privileged user %s using CLEARMODE." , un
-> nick
);
2213 return clear_chanmode ( cn
, argv
[ 2 ]);
2216 static CMD_FUNC ( cmd_topic
)
2218 struct chanNode
* cn
;
2220 struct userNode
* user
;
2224 if (!( cn
= GetChannel ( argv
[ 1 ]))) {
2225 log_module ( MAIN_LOG
, LOG_ERROR
, "Unable to find channel %s whose topic is being set" , argv
[ 1 ]);
2230 if ( argc
== 5 ) { /* Asuka / Topic Bursting IRCu's */
2231 user
= GetUserH ( origin
);
2232 topic_ts
= atoi ( argv
[ 3 ]);
2233 } else if ( argc
>= 6 ) { /* Nefarious 0.5.0 */
2234 user
= GetUserH ( strtok ( argv
[ 2 ], "!" ));
2235 topic_ts
= atoi ( argv
[ 4 ]);
2236 } else { /* Regular IRCu (No Topic Bursting)*/
2237 user
= GetUserH ( origin
);
2241 SetChannelTopic ( cn
, user
, user
, argv
[ argc
- 1 ], 0 );
2242 cn
-> topic_time
= topic_ts
;
2246 static CMD_FUNC ( cmd_num_topic
)
2248 struct chanNode
* cn
;
2251 return 0 ; /* huh? */
2253 cn
= GetChannel ( argv
[ 2 ]);
2255 log_module ( MAIN_LOG
, LOG_ERROR
, "Unable to find channel %s in topic reply" , argv
[ 2 ]);
2261 switch ( atoi ( argv
[ 0 ])) {
2264 break ; /* no topic */
2268 safestrncpy ( cn
-> topic
, unsplit_string ( argv
+ 3 , argc
- 3 , NULL
), sizeof ( cn
-> topic
));
2273 safestrncpy ( cn
-> topic_nick
, argv
[ 3 ], sizeof ( cn
-> topic_nick
));
2274 cn
-> topic_time
= atoi ( argv
[ 4 ]);
2277 return 0 ; /* should never happen */
2282 static CMD_FUNC ( cmd_num_gline
)
2288 gline_add ( origin
, argv
[ 3 ], atoi ( argv
[ 4 ])- now
, argv
[ 5 ], now
, 0 , 0 );
2290 if (! strcmp ( argv
[ 5 ], "+" ))
2291 gline_add ( origin
, argv
[ 3 ], atoi ( argv
[ 4 ])- now
, argv
[ 6 ], now
, 0 , 0 );
2296 static CMD_FUNC ( cmd_num_shun
)
2302 shun_add ( origin
, argv
[ 3 ], atoi ( argv
[ 4 ])- now
, argv
[ 5 ], now
, 0 );
2304 if (! strcmp ( argv
[ 5 ], "+" ))
2305 shun_add ( origin
, argv
[ 3 ], atoi ( argv
[ 4 ])- now
, argv
[ 6 ], now
, 0 );
2310 static CMD_FUNC ( cmd_quit
)
2312 struct userNode
* user
;
2315 /* Sometimes we get a KILL then a QUIT or the like, so we don't want to
2316 * call DelUser unless we have the user in our grasp. */
2317 if (( user
= GetUserH ( origin
)))
2318 DelUser ( user
, NULL
, false , argv
[ 1 ]);
2322 static CMD_FUNC ( cmd_kill
)
2324 struct userNode
* user
;
2327 user
= GetUserN ( argv
[ 1 ]);
2329 /* If we get a KILL for a non-existent user, it could be a
2330 * Ghost response to a KILL we sent out earlier. So we only
2331 * whine if the target is local.
2333 if (! strncmp ( argv
[ 1 ], self
-> numeric
, strlen ( self
-> numeric
))) {
2334 log_module ( MAIN_LOG
, LOG_ERROR
, "Unable to find kill victim %s " , argv
[ 1 ]);
2340 if ( IsLocal ( user
) && IsService ( user
)) {
2341 /* TODO: rate limit this so silly things don't happen. */
2342 ReintroduceUser ( user
);
2346 DelUser ( user
, NULL
, false , argv
[ 2 ]);
2350 static CMD_FUNC ( cmd_svspart
)
2352 struct userNode
* user
;
2356 user
= GetUserN ( argv
[ 1 ]);
2359 parse_foreach ( argv
[ 2 ], part_helper
, NULL
, NULL
, NULL
, user
);
2363 static CMD_FUNC ( cmd_silence
)
2365 struct userNode
* user
;
2373 if ( strncmp ( argv
[ 1 ], "*" , 2 ) == 0 )
2375 if (!( user
= GetUserH ( origin
))) {
2376 log_module ( MAIN_LOG
, LOG_ERROR
, "Could not find SILENCE origin user %s " , origin
);
2381 user
= GetUserN ( argv
[ 1 ]);
2383 /* Sanity, go nuts if this happens */
2387 /* We can safely ignore this if a user adding a silence is not
2388 * ignored. However this brings up a TODO. If a user logs in and
2389 * they have silences on the IRCd then we need to set them here
2392 if (! user
-> handle_info
)
2398 for ( i
= 0 ; i
< user
-> handle_info
-> ignores
-> used
; i
++) {
2399 if (! irccasecmp ( mask
+ 1 , user
-> handle_info
-> ignores
-> list
[ i
]))
2400 user
-> handle_info
-> ignores
-> list
[ i
] = user
-> handle_info
-> ignores
-> list
[-- user
-> handle_info
-> ignores
-> used
];
2403 for ( i
= 0 ; i
< user
-> handle_info
-> ignores
-> used
; i
++) {
2404 if (! strcmp ( mask
+ 1 , user
-> handle_info
-> ignores
-> list
[ i
]))
2405 return 1 ; /* Already on the users NickServ ignore list, safely ignore */
2408 new_mask
= strdup ( mask
+ 1 );
2409 string_list_append ( user
-> handle_info
-> ignores
, new_mask
);
2414 static CMD_FUNC ( cmd_kick
)
2418 ChannelUserKicked ( GetUserH ( origin
), GetUserN ( argv
[ 2 ]), GetChannel ( argv
[ 1 ]));
2422 static CMD_FUNC ( cmd_squit
)
2424 struct server
* server
;
2429 if (!( server
= GetServerH ( argv
[ 1 ])))
2432 if ( server
== self
-> uplink
) {
2433 /* Force a reconnect to the currently selected server. */
2434 cManager
. uplink
-> tries
= 0 ;
2435 log_module ( MAIN_LOG
, LOG_INFO
, "Squitting from uplink: %s " , argv
[ 3 ]);
2440 uplink
= strdup ( server
-> uplink
-> name
);
2441 DelServer ( server
, 0 , argv
[ 3 ]);
2442 /* if its a pingout and pingout connecting is enabled
2443 or its a read error and readerror connecting is enabled
2444 or were doing a "N" and i need to connect that server somewhere */
2445 routing_handle_squit ( argv
[ 1 ], uplink
, argv
[ 3 ]);
2450 static CMD_FUNC ( cmd_privmsg
)
2452 struct privmsg_desc pd
;
2455 pd
. user
= GetUserH ( origin
);
2456 if (! pd
. user
|| ( IsGagged ( pd
. user
) && ! IsOper ( pd
. user
)))
2459 if ( checkDefCon ( DEFCON_OPER_ONLY
) && ! IsOper ( pd
. user
)) {
2461 str
= conf_get_data ( "services/opserv/nick" , RECDB_QSTRING
);
2463 send_message_type ( 4 , pd
. user
, GetUserH ( str
), "Services are currently not available, please try again soon" );
2467 if ( checkDefCon ( DEFCON_SILENT_OPER_ONLY
) && ! IsOper ( pd
. user
))
2468 return 1 ; /* Silently Ignore */
2471 pd
. text
= argv
[ argc
- 1 ];
2472 parse_foreach ( argv
[ 1 ], privmsg_chan_helper
, NULL
, privmsg_user_helper
, privmsg_invalid
, & pd
);
2477 static CMD_FUNC ( cmd_notice
)
2479 struct privmsg_desc pd
;
2485 pd
. user
= GetUserH ( origin
);
2486 if (! pd
. user
|| ( IsGagged ( pd
. user
) && ! IsOper ( pd
. user
))) {
2491 parse_foreach ( argv
[ 1 ], privmsg_chan_helper
, NULL
, privmsg_user_helper
, privmsg_invalid
, & pd
);
2494 srv
= GetServerH ( origin
);
2496 char * sargv
[ MAXNUMPARAMS
];
2499 sargc
= split_line ( argv
[ 2 ], true , MAXNUMPARAMS
, sargv
);
2501 if (! strcasecmp ( sargv
[ 0 ], "Connect:" )) {
2502 /* :Connect: Host shoe.loxxin.net not listed in ircd.conf */
2503 if (! strcasecmp ( sargv
[ 3 ], "not" ) && ! strcasecmp ( sargv
[ 4 ], "listed" )) {
2504 routing_handle_connect_failure ( srv
, sargv
[ 2 ], unsplit_string ( sargv
+ 3 , sargc
- 3 , NULL
));
2507 else if (! strcasecmp ( sargv
[ 0 ], "Link" )) {
2508 /* :Link with mephisto.etheria.cx cancelled: Server mephisto.etheria.cx[216.46.33.71]
2510 * :Link with laptop.afternet.org cancelled: Connection refused
2512 if (! strcasecmp ( sargv
[ 3 ], "cancelled:" )) {
2513 routing_handle_connect_failure ( srv
, sargv
[ 2 ], unsplit_string ( sargv
+ 4 , sargc
- 4 , NULL
));
2520 static CMD_FUNC ( cmd_away
)
2522 struct userNode
* uNode
;
2524 uNode
= GetUserH ( origin
);
2528 uNode
-> modes
&= ~ FLAGS_AWAY
;
2530 uNode
-> modes
|= FLAGS_AWAY
;
2534 static CMD_FUNC ( cmd_gline
)
2538 if ( argv
[ 2 ][ 0 ] == '+' ) {
2541 gline_add ( origin
, argv
[ 2 ]+ 1 , strtoul ( argv
[ 3 ], NULL
, 0 ), argv
[ argc
- 1 ], now
, 0 , 0 );
2543 } else if ( argv
[ 2 ][ 0 ] == '-' ) {
2544 gline_remove ( argv
[ 2 ]+ 1 , 0 );
2550 static CMD_FUNC ( cmd_sgline
)
2552 struct server
* sender
;
2557 if (!( sender
= GetServerH ( origin
)))
2560 gline_add ( origin
, argv
[ 1 ], strtoul ( argv
[ 2 ], NULL
, 0 ), argv
[ argc
- 1 ], now
, 1 , 0 );
2564 static CMD_FUNC ( cmd_sshun
)
2566 struct server
* sender
;
2571 if (!( sender
= GetServerH ( origin
)))
2574 shun_add ( origin
, argv
[ 1 ], strtoul ( argv
[ 2 ], NULL
, 0 ), argv
[ argc
- 1 ], now
, 1 );
2578 static CMD_FUNC ( cmd_shun
)
2582 if ( argv
[ 2 ][ 0 ] == '+' ) {
2585 shun_add ( origin
, argv
[ 2 ]+ 1 , strtoul ( argv
[ 3 ], NULL
, 0 ), argv
[ argc
- 1 ], now
, 0 );
2587 } else if ( argv
[ 2 ][ 0 ] == '-' ) {
2588 shun_remove ( argv
[ 2 ]+ 1 , 0 );
2594 static CMD_FUNC ( cmd_svsnick
)
2596 struct userNode
* target
, * dest
;
2598 || !( target
= GetUserN ( argv
[ 1 ]))
2600 || ( dest
= GetUserH ( argv
[ 2 ])))
2602 NickChange ( target
, argv
[ 2 ], 0 );
2607 free_user ( struct userNode
* user
)
2614 parse_cleanup ( UNUSED_ARG ( void * extra
))
2618 free ( of_list_extra
);
2619 free ( privmsg_funcs
);
2620 num_privmsg_funcs
= 0 ;
2622 num_notice_funcs
= 0 ;
2624 dict_delete ( irc_func_dict
);
2625 for ( nn
= 0 ; nn
< dead_users
. used
; nn
++)
2626 free_user ( dead_users
. list
[ nn
]);
2627 userList_clean (& dead_users
);
2631 p10_conf_reload ( void ) {
2632 hidden_host_suffix
= conf_get_data ( "server/hidden_host" , RECDB_QSTRING
);
2633 his_servername
= conf_get_data ( "server/his_servername" , RECDB_QSTRING
);
2634 his_servercomment
= conf_get_data ( "server/his_servercomment" , RECDB_QSTRING
);
2638 remove_unbursted_channel ( struct chanNode
* cNode
, UNUSED_ARG ( void * extra
)) {
2639 if ( unbursted_channels
)
2640 dict_remove ( unbursted_channels
, cNode
-> name
);
2646 const char * str
, * desc
;
2647 int numnick
, usermask
, max_users
;
2648 char numer
[ COMBO_NUMERIC_LEN
+ 1 ];
2650 /* read config items */
2651 str
= conf_get_data ( "server/extended_accounts" , RECDB_QSTRING
);
2652 extended_accounts
= str
? enabled_string ( str
) : 1 ;
2653 str
= conf_get_data ( "server/ping_freq" , RECDB_QSTRING
);
2654 ping_freq
= str
? ParseInterval ( str
) : 120 ;
2655 str
= conf_get_data ( "server/ping_timeout" , RECDB_QSTRING
);
2656 ping_timeout
= str
? ParseInterval ( str
) : 30 ;
2657 str
= conf_get_data ( "server/force_n2k" , RECDB_QSTRING
);
2658 force_n2k
= str
? enabled_string ( str
) : 1 ;
2659 str
= conf_get_data ( "server/numeric" , RECDB_QSTRING
);
2661 log_module ( MAIN_LOG
, LOG_ERROR
, "No server/numeric entry in config file." );
2664 numnick
= atoi ( str
);
2665 str
= conf_get_data ( "server/max_users" , RECDB_QSTRING
);
2666 max_users
= str
? atoi ( str
) : 4096 ;
2667 for ( usermask
= 4 ; usermask
< max_users
; usermask
<<= 1 ) ;
2669 if (( numnick
< 64 ) && ( usermask
< 4096 ) && ! force_n2k
)
2670 inttobase64 ( numer
, ( numnick
<< 12 ) + ( usermask
& 0x00fff ), 3 );
2672 inttobase64 ( numer
, ( numnick
<< 18 ) + ( usermask
& 0x3ffff ), 5 );
2674 str
= conf_get_data ( "server/hostname" , RECDB_QSTRING
);
2675 desc
= conf_get_data ( "server/description" , RECDB_QSTRING
);
2676 if (! str
|| ! desc
) {
2677 log_module ( MAIN_LOG
, LOG_ERROR
, "No server/hostname entry in config file." );
2680 self
= AddServer ( NULL
, str
, 0 , boot_time
, now
, numer
, desc
);
2681 conf_register_reload ( p10_conf_reload
);
2683 irc_func_dict
= dict_new ();
2684 dict_insert ( irc_func_dict
, CMD_BURST
, cmd_burst
);
2685 dict_insert ( irc_func_dict
, TOK_BURST
, cmd_burst
);
2686 dict_insert ( irc_func_dict
, CMD_CREATE
, cmd_create
);
2687 dict_insert ( irc_func_dict
, TOK_CREATE
, cmd_create
);
2688 dict_insert ( irc_func_dict
, CMD_EOB
, cmd_eob
);
2689 dict_insert ( irc_func_dict
, TOK_EOB
, cmd_eob
);
2690 dict_insert ( irc_func_dict
, CMD_EOB_ACK
, cmd_eob_ack
);
2691 dict_insert ( irc_func_dict
, TOK_EOB_ACK
, cmd_eob_ack
);
2692 dict_insert ( irc_func_dict
, CMD_MODE
, cmd_mode
);
2693 dict_insert ( irc_func_dict
, TOK_MODE
, cmd_mode
);
2694 dict_insert ( irc_func_dict
, CMD_MARK
, cmd_mark
);
2695 dict_insert ( irc_func_dict
, TOK_MARK
, cmd_mark
);
2696 dict_insert ( irc_func_dict
, CMD_NICK
, cmd_nick
);
2697 dict_insert ( irc_func_dict
, TOK_NICK
, cmd_nick
);
2698 dict_insert ( irc_func_dict
, CMD_ACCOUNT
, cmd_account
);
2699 dict_insert ( irc_func_dict
, TOK_ACCOUNT
, cmd_account
);
2700 dict_insert ( irc_func_dict
, CMD_FAKEHOST
, cmd_fakehost
);
2701 dict_insert ( irc_func_dict
, TOK_FAKEHOST
, cmd_fakehost
);
2702 dict_insert ( irc_func_dict
, CMD_PASS
, cmd_pass
);
2703 dict_insert ( irc_func_dict
, TOK_PASS
, cmd_pass
);
2704 dict_insert ( irc_func_dict
, CMD_PING
, cmd_ping
);
2705 dict_insert ( irc_func_dict
, TOK_PING
, cmd_ping
);
2706 dict_insert ( irc_func_dict
, CMD_PRIVMSG
, cmd_privmsg
);
2707 dict_insert ( irc_func_dict
, TOK_PRIVMSG
, cmd_privmsg
);
2708 dict_insert ( irc_func_dict
, CMD_PONG
, cmd_pong
);
2709 dict_insert ( irc_func_dict
, TOK_PONG
, cmd_pong
);
2710 dict_insert ( irc_func_dict
, CMD_QUIT
, cmd_quit
);
2711 dict_insert ( irc_func_dict
, TOK_QUIT
, cmd_quit
);
2712 dict_insert ( irc_func_dict
, CMD_SERVER
, cmd_server
);
2713 dict_insert ( irc_func_dict
, TOK_SERVER
, cmd_server
);
2714 dict_insert ( irc_func_dict
, CMD_JOIN
, cmd_join
);
2715 dict_insert ( irc_func_dict
, TOK_JOIN
, cmd_join
);
2716 dict_insert ( irc_func_dict
, CMD_PART
, cmd_part
);
2717 dict_insert ( irc_func_dict
, TOK_PART
, cmd_part
);
2718 dict_insert ( irc_func_dict
, CMD_ERROR
, cmd_error
);
2719 dict_insert ( irc_func_dict
, TOK_ERROR
, cmd_error
);
2720 dict_insert ( irc_func_dict
, CMD_TOPIC
, cmd_topic
);
2721 dict_insert ( irc_func_dict
, TOK_TOPIC
, cmd_topic
);
2722 dict_insert ( irc_func_dict
, CMD_AWAY
, cmd_away
);
2723 dict_insert ( irc_func_dict
, TOK_AWAY
, cmd_away
);
2724 dict_insert ( irc_func_dict
, CMD_SILENCE
, cmd_silence
);
2725 dict_insert ( irc_func_dict
, TOK_SILENCE
, cmd_silence
);
2726 dict_insert ( irc_func_dict
, CMD_KICK
, cmd_kick
);
2727 dict_insert ( irc_func_dict
, TOK_KICK
, cmd_kick
);
2728 dict_insert ( irc_func_dict
, CMD_SQUIT
, cmd_squit
);
2729 dict_insert ( irc_func_dict
, TOK_SQUIT
, cmd_squit
);
2730 dict_insert ( irc_func_dict
, CMD_KILL
, cmd_kill
);
2731 dict_insert ( irc_func_dict
, TOK_KILL
, cmd_kill
);
2732 dict_insert ( irc_func_dict
, CMD_NOTICE
, cmd_notice
);
2733 dict_insert ( irc_func_dict
, TOK_NOTICE
, cmd_notice
);
2734 dict_insert ( irc_func_dict
, CMD_STATS
, cmd_stats
);
2735 dict_insert ( irc_func_dict
, TOK_STATS
, cmd_stats
);
2736 dict_insert ( irc_func_dict
, CMD_SVSJOIN
, cmd_svsjoin
);
2737 dict_insert ( irc_func_dict
, TOK_SVSJOIN
, cmd_svsjoin
);
2738 dict_insert ( irc_func_dict
, CMD_SVSNICK
, cmd_svsnick
);
2739 dict_insert ( irc_func_dict
, TOK_SVSNICK
, cmd_svsnick
);
2740 dict_insert ( irc_func_dict
, CMD_SVSPART
, cmd_svspart
);
2741 dict_insert ( irc_func_dict
, TOK_SVSPART
, cmd_svspart
);
2742 dict_insert ( irc_func_dict
, CMD_SWHOIS
, cmd_dummy
);
2743 dict_insert ( irc_func_dict
, TOK_SWHOIS
, cmd_dummy
);
2744 dict_insert ( irc_func_dict
, CMD_TEMPSHUN
, cmd_dummy
);
2745 dict_insert ( irc_func_dict
, TOK_TEMPSHUN
, cmd_dummy
);
2746 dict_insert ( irc_func_dict
, CMD_WHOIS
, cmd_whois
);
2747 dict_insert ( irc_func_dict
, TOK_WHOIS
, cmd_whois
);
2748 dict_insert ( irc_func_dict
, CMD_GLINE
, cmd_gline
);
2749 dict_insert ( irc_func_dict
, TOK_GLINE
, cmd_gline
);
2750 dict_insert ( irc_func_dict
, CMD_SGLINE
, cmd_sgline
);
2751 dict_insert ( irc_func_dict
, TOK_SGLINE
, cmd_sgline
);
2752 dict_insert ( irc_func_dict
, CMD_SHUN
, cmd_shun
);
2753 dict_insert ( irc_func_dict
, TOK_SHUN
, cmd_shun
);
2754 dict_insert ( irc_func_dict
, CMD_SSHUN
, cmd_sshun
);
2755 dict_insert ( irc_func_dict
, TOK_SSHUN
, cmd_sshun
);
2756 dict_insert ( irc_func_dict
, CMD_OPMODE
, cmd_opmode
);
2757 dict_insert ( irc_func_dict
, TOK_OPMODE
, cmd_opmode
);
2758 dict_insert ( irc_func_dict
, CMD_CLEARMODE
, cmd_clearmode
);
2759 dict_insert ( irc_func_dict
, TOK_CLEARMODE
, cmd_clearmode
);
2760 dict_insert ( irc_func_dict
, CMD_VERSION
, cmd_version
);
2761 dict_insert ( irc_func_dict
, TOK_VERSION
, cmd_version
);
2762 dict_insert ( irc_func_dict
, CMD_ADMIN
, cmd_admin
);
2763 dict_insert ( irc_func_dict
, TOK_ADMIN
, cmd_admin
);
2764 dict_insert ( irc_func_dict
, CMD_SMO
, cmd_dummy
);
2765 dict_insert ( irc_func_dict
, TOK_SMO
, cmd_dummy
);
2766 dict_insert ( irc_func_dict
, CMD_SNO
, cmd_dummy
);
2767 dict_insert ( irc_func_dict
, TOK_SNO
, cmd_dummy
);
2769 dict_insert ( irc_func_dict
, CMD_RPING
, cmd_rping
);
2770 dict_insert ( irc_func_dict
, TOK_RPING
, cmd_rping
);
2771 dict_insert ( irc_func_dict
, CMD_RPONG
, cmd_dummy
);
2772 dict_insert ( irc_func_dict
, TOK_RPONG
, cmd_dummy
);
2774 dict_insert ( irc_func_dict
, CMD_SASL
, cmd_sasl
);
2775 dict_insert ( irc_func_dict
, TOK_SASL
, cmd_sasl
);
2777 /* In P10, DESTRUCT doesn't do anything except be broadcast to servers.
2778 * Apparently to obliterate channels from any servers that think they
2781 dict_insert ( irc_func_dict
, CMD_DESTRUCT
, cmd_dummy
);
2782 dict_insert ( irc_func_dict
, TOK_DESTRUCT
, cmd_dummy
);
2783 /* Ignore invites */
2784 dict_insert ( irc_func_dict
, CMD_INVITE
, cmd_dummy
);
2785 dict_insert ( irc_func_dict
, TOK_INVITE
, cmd_dummy
);
2786 /* DESYNCH is just informational, so ignore it */
2787 dict_insert ( irc_func_dict
, CMD_DESYNCH
, cmd_dummy
);
2788 dict_insert ( irc_func_dict
, TOK_DESYNCH
, cmd_dummy
);
2789 /* Ignore channel operator notices. */
2790 dict_insert ( irc_func_dict
, CMD_WALLCHOPS
, cmd_dummy
);
2791 dict_insert ( irc_func_dict
, TOK_WALLCHOPS
, cmd_dummy
);
2792 dict_insert ( irc_func_dict
, CMD_WALLVOICES
, cmd_dummy
);
2793 dict_insert ( irc_func_dict
, TOK_WALLVOICES
, cmd_dummy
);
2794 dict_insert ( irc_func_dict
, CMD_WALLHOPS
, cmd_dummy
);
2795 dict_insert ( irc_func_dict
, TOK_WALLHOPS
, cmd_dummy
);
2796 /* Ignore opers being silly. */
2797 dict_insert ( irc_func_dict
, CMD_WALLOPS
, cmd_dummy
);
2798 dict_insert ( irc_func_dict
, TOK_WALLOPS
, cmd_dummy
);
2799 dict_insert ( irc_func_dict
, CMD_WALLHOPS
, cmd_dummy
);
2800 dict_insert ( irc_func_dict
, TOK_WALLHOPS
, cmd_dummy
);
2801 dict_insert ( irc_func_dict
, TOK_WALLUSERS
, cmd_dummy
);
2802 /* Ignore dnsbl exemptions */
2803 dict_insert ( irc_func_dict
, TOK_EXEMPT
, cmd_dummy
);
2804 dict_insert ( irc_func_dict
, CMD_PRIVS
, cmd_privs
);
2805 dict_insert ( irc_func_dict
, TOK_PRIVS
, cmd_privs
);
2806 /* ignore ALIST for now */
2807 dict_insert ( irc_func_dict
, TOK_ALIST
, cmd_dummy
);
2808 dict_insert ( irc_func_dict
, CMD_ALIST
, cmd_dummy
);
2809 /* ignore SPAMFILTER */
2810 dict_insert ( irc_func_dict
, TOK_SPAMFILTER
, cmd_dummy
);
2811 dict_insert ( irc_func_dict
, CMD_SPAMFILTER
, cmd_dummy
);
2812 /* Ignore remote luser */
2813 dict_insert ( irc_func_dict
, TOK_LUSERS
, cmd_dummy
);
2814 /* We have reliable clock! Always! Wraaa! */
2815 dict_insert ( irc_func_dict
, CMD_SETTIME
, cmd_dummy
);
2816 dict_insert ( irc_func_dict
, TOK_SETTIME
, cmd_dummy
);
2817 /* Ignore ZLINE/ZL/REMOVE/RM */
2818 dict_insert ( irc_func_dict
, CMD_ZLINE
, cmd_dummy
);
2819 dict_insert ( irc_func_dict
, TOK_ZLINE
, cmd_dummy
);
2820 dict_insert ( irc_func_dict
, CMD_REMOVE
, cmd_dummy
);
2821 dict_insert ( irc_func_dict
, TOK_REMOVE
, cmd_dummy
);
2823 /* ignore /trace and /motd commands targetted at us */
2824 dict_insert ( irc_func_dict
, TOK_TRACE
, cmd_dummy
);
2825 dict_insert ( irc_func_dict
, TOK_MOTD
, cmd_dummy
);
2826 dict_insert ( irc_func_dict
, TOK_UPING
, cmd_dummy
);
2829 dict_insert ( irc_func_dict
, "331" , cmd_num_topic
);
2830 dict_insert ( irc_func_dict
, "332" , cmd_num_topic
);
2831 dict_insert ( irc_func_dict
, "333" , cmd_num_topic
);
2832 dict_insert ( irc_func_dict
, "345" , cmd_dummy
); /* blah has been invited to blah */
2833 dict_insert ( irc_func_dict
, "432" , cmd_error_nick
); /* Erroneus [sic] nickname */
2834 /* ban list resetting */
2835 /* "stats g" responses */
2836 dict_insert ( irc_func_dict
, "230" , cmd_dummy
); /* ignore stats headers */
2837 dict_insert ( irc_func_dict
, "247" , cmd_num_gline
);
2838 dict_insert ( irc_func_dict
, "542" , cmd_num_shun
);
2839 dict_insert ( irc_func_dict
, "219" , cmd_dummy
); /* "End of /STATS report" */
2840 /* other numeric responses we might get */
2841 dict_insert ( irc_func_dict
, "401" , cmd_dummy
); /* target left network */
2842 dict_insert ( irc_func_dict
, "403" , cmd_dummy
); /* no such channel */
2843 dict_insert ( irc_func_dict
, "404" , cmd_dummy
); /* cannot send to channel */
2844 dict_insert ( irc_func_dict
, "439" , cmd_dummy
); /* target change too fast */
2845 dict_insert ( irc_func_dict
, "441" , cmd_dummy
); /* target isn't on that channel */
2846 dict_insert ( irc_func_dict
, "442" , cmd_dummy
); /* you aren't on that channel */
2847 dict_insert ( irc_func_dict
, "443" , cmd_dummy
); /* is already on channel (after invite?) */
2848 dict_insert ( irc_func_dict
, "461" , cmd_dummy
); /* Not enough parameters (after TOPIC w/ 0 args) */
2849 dict_insert ( irc_func_dict
, "467" , cmd_dummy
); /* Channel key already set */
2851 num_privmsg_funcs
= 16 ;
2852 privmsg_funcs
= malloc ( sizeof ( privmsg_func_t
)* num_privmsg_funcs
);
2853 memset ( privmsg_funcs
, 0 , sizeof ( privmsg_func_t
)* num_privmsg_funcs
);
2855 num_notice_funcs
= 16 ;
2856 notice_funcs
= malloc ( sizeof ( privmsg_func_t
)* num_notice_funcs
);
2857 memset ( notice_funcs
, 0 , sizeof ( privmsg_func_t
)* num_notice_funcs
);
2859 userList_init (& dead_users
);
2860 reg_del_channel_func ( remove_unbursted_channel
, NULL
);
2861 reg_exit_func ( parse_cleanup
, NULL
);
2862 // reg_notice_func(opserv, check_ctcp);
2866 parse_line ( char * line
, int recursive
)
2868 char * argv
[ MAXNUMPARAMS
], * origin
;
2869 int argc
, cmd
, res
= 0 ;
2872 argc
= split_line ( line
, true , MAXNUMPARAMS
, argv
);
2873 cmd
= self
-> uplink
|| ! argv
[ 0 ][ 1 ] || ! argv
[ 0 ][ 2 ];
2876 if ( argv
[ 0 ][ 0 ] == ':' ) {
2878 } else if (! argv
[ 0 ][ 1 ] || ! argv
[ 0 ][ 2 ]) {
2879 struct server
* sNode
= GetServerN ( argv
[ 0 ]);
2880 origin
= sNode
? sNode
-> name
: 0 ;
2882 struct userNode
* uNode
= GetUserN ( argv
[ 0 ]);
2883 origin
= uNode
? uNode
-> nick
: 0 ;
2887 if (( func
= dict_find ( irc_func_dict
, argv
[ cmd
], NULL
)))
2888 res
= func ( origin
, argc
- cmd
, argv
+ cmd
);
2891 log_module ( MAIN_LOG
, LOG_ERROR
, "PARSE ERROR on line: %s " , unsplit_string ( argv
, argc
, NULL
));
2892 } else if (! recursive
) {
2894 for ( i
= 0 ; i
< dead_users
. used
; i
++)
2895 free_user ( dead_users
. list
[ i
]);
2896 dead_users
. used
= 0 ;
2902 parse_foreach ( char * target_list
, foreach_chanfunc cf
, foreach_nonchan nc
, foreach_userfunc uf
, foreach_nonuser nu
, void * data
)
2908 while (* j
!= 0 && * j
!= ',' )
2913 if ( IsChannelName ( target_list
)
2914 || ( target_list
[ 0 ] == '0' && target_list
[ 1 ] == '\0' )) {
2915 struct chanNode
* chan
= GetChannel ( target_list
);
2922 nc ( target_list
, data
);
2925 struct userNode
* user
;
2926 struct privmsg_desc
* pd
= data
;
2928 pd
-> is_qualified
= 0 ;
2929 if (* target_list
== '@' ) {
2931 } else if ( strchr ( target_list
, '@' )) {
2932 struct server
* server
;
2934 pd
-> is_qualified
= 1 ;
2935 user
= GetUserH ( strtok ( target_list
, "@" ));
2936 server
= GetServerH ( strtok ( NULL
, "@" ));
2938 if ( user
&& ( user
-> uplink
!= server
)) {
2939 /* Don't attempt to index into any arrays
2940 using a user's numeric on another server. */
2944 user
= GetUserN ( target_list
);
2952 nu ( target_list
, data
);
2956 } while ( old
== ',' );
2960 get_local_numeric ( void )
2962 static unsigned int next_numeric
= 0 ;
2963 if ( self
-> clients
> self
-> num_mask
)
2965 while ( self
-> users
[ next_numeric
])
2966 if (++ next_numeric
> self
-> num_mask
)
2968 return next_numeric
;
2972 make_numeric ( struct server
* svr
, int local_num
, char * outbuf
)
2976 if ( force_n2k
|| svr
-> numeric
[ 1 ]) {
2981 llen
= ( local_num
< 64 * 64 ) ? 2 : 3 ;
2983 strncpy ( outbuf
, svr
-> numeric
, slen
);
2984 inttobase64 ( outbuf
+ slen
, local_num
, llen
);
2985 outbuf
[ slen
+ llen
] = 0 ;
2989 AddServer ( struct server
* uplink
, const char * name
, int hops
, time_t boot
, time_t link_time
, const char * numeric
, const char * description
)
2991 struct server
* sNode
;
2994 if (( sNode
= GetServerN ( numeric
))) {
2995 /* This means we're trying to re-add an existant server.
2996 * To be safe, we should forget the previous incarnation.
2997 * (And all its linked servers.)
2999 * It usually only happens in replays when the original
3000 * had a ping timeout and the replay didn't (because
3001 * replaying a ping timeout invariably gets things wrong).
3003 DelServer ( sNode
, 0 , NULL
);
3006 switch ( strlen ( numeric
)) {
3007 case 5 : slen
= 2 ; mlen
= 3 ; break ;
3008 case 4 : slen
= 1 ; mlen
= 3 ; break ;
3009 case 3 : slen
= 1 ; mlen
= 2 ; break ;
3011 log_module ( MAIN_LOG
, LOG_ERROR
, "AddServer( \" %s \" , \" %s \" , ...): Numeric %s has invalid length." , uplink
-> name
, name
, numeric
);
3015 sNode
= calloc ( 1 , sizeof (* sNode
));
3016 sNode
-> uplink
= uplink
;
3017 safestrncpy ( sNode
-> name
, name
, sizeof ( sNode
-> name
));
3018 sNode
-> num_mask
= base64toint ( numeric
+ slen
, mlen
);
3021 sNode
-> link_time
= link_time
;
3022 strncpy ( sNode
-> numeric
, numeric
, slen
);
3023 safestrncpy ( sNode
-> description
, description
, sizeof ( sNode
-> description
));
3024 sNode
-> users
= calloc ( sNode
-> num_mask
+ 1 , sizeof (* sNode
-> users
));
3025 serverList_init (& sNode
-> children
);
3026 if ( sNode
-> uplink
) {
3027 /* uplink may be NULL if we're just building ourself */
3028 serverList_append (& sNode
-> uplink
-> children
, sNode
);
3030 servers_num
[ base64toint ( numeric
, slen
)] = sNode
;
3031 dict_insert ( servers
, sNode
-> name
, sNode
);
3035 void DelServer ( struct server
* serv
, int announce
, const char * message
)
3039 /* If we receive an ERROR command before the SERVER
3040 * command a NULL server can be passed */
3044 /* Hrm, what's the right way to SQUIT some other server?
3045 * (This code is only to handle killing juped servers.) */
3046 if ( announce
&& ( serv
-> uplink
== self
) && ( serv
!= self
-> uplink
))
3047 irc_squit ( serv
, message
, NULL
);
3049 /* must recursively remove servers linked to this one first */
3050 for ( i
= serv
-> children
. used
; i
> 0 ;)
3051 if ( serv
-> children
. list
[-- i
] != self
)
3052 DelServer ( serv
-> children
. list
[ i
], false , NULL
);
3054 /* clean up server's user hash tables */
3055 for ( i
= 0 ; i
<= serv
-> num_mask
; i
++)
3057 DelUser ( serv
-> users
[ i
], NULL
, false , "server delinked" );
3061 serverList_remove (& serv
-> uplink
-> children
, serv
);
3062 if ( serv
== self
-> uplink
)
3063 self
-> uplink
= NULL
;
3064 servers_num
[ base64toint ( serv
-> numeric
, strlen ( serv
-> numeric
))] = NULL
;
3065 dict_remove ( servers
, serv
-> name
);
3066 serverList_clean (& serv
-> children
);
3072 AddLocalUser ( const char * nick
, const char * ident
, const char * hostname
, const char * desc
, const char * modes
)
3074 char numeric
[ COMBO_NUMERIC_LEN
+ 1 ];
3075 int local_num
= get_local_numeric ();
3076 time_t timestamp
= now
;
3077 struct userNode
* old_user
= GetUserH ( nick
);
3083 if ( IsLocal ( old_user
))
3085 timestamp
= old_user
-> timestamp
- 1 ;
3087 if ( local_num
== - 1 ) {
3088 log_module ( MAIN_LOG
, LOG_ERROR
, "Unable to allocate numnick for service %s " , nick
);
3092 hostname
= self
-> name
;
3093 make_numeric ( self
, local_num
, numeric
);
3094 return AddUser ( self
, nick
, ident
, hostname
, modes
, numeric
, desc
, timestamp
, "AAAAAA" );
3098 AddClone ( const char * nick
, const char * ident
, const char * hostname
, const char * desc
)
3100 char numeric
[ COMBO_NUMERIC_LEN
+ 1 ];
3101 int local_num
= get_local_numeric ();
3102 time_t timestamp
= now
;
3103 struct userNode
* old_user
= GetUserH ( nick
);
3106 if ( IsLocal ( old_user
))
3108 timestamp
= old_user
-> timestamp
- 1 ;
3110 if ( local_num
== - 1 ) {
3111 log_module ( MAIN_LOG
, LOG_ERROR
, "Unable to allocate numnick for clone %s " , nick
);
3114 make_numeric ( self
, local_num
, numeric
);
3115 return AddUser ( self
, nick
, ident
, hostname
, "+i" , numeric
, desc
, timestamp
, "AAAAAA" );
3119 is_valid_nick ( const char * nick
) {
3121 /* IRC has some of The Most Fucked-Up ideas about character sets
3123 if (! isalpha (* nick
) && ! strchr ( "{|}~[ \\ ]^_`" , * nick
))
3125 for ( ii
= 0 ; nick
[ ii
]; ++ ii
)
3126 if (! isalnum ( nick
[ ii
]) && ! strchr ( "{|}~[ \\ ]^-_`" , nick
[ ii
]))
3128 if ( strlen ( nick
) > nicklen
)
3133 static struct userNode
*
3134 AddUser ( struct server
* uplink
, const char * nick
, const char * ident
, const char * hostname
, const char * modes
, const char * numeric
, const char * userinfo
, time_t timestamp
, const char * realip
)
3136 struct userNode
* oldUser
, * uNode
;
3137 unsigned int ignore_user
, dummy
;
3139 if (( strlen ( numeric
) < 3 ) || ( strlen ( numeric
) > 5 )) {
3140 log_module ( MAIN_LOG
, LOG_WARNING
, "AddUser( %p , %s , ...): numeric %s wrong length!" , ( void *) uplink
, nick
, numeric
);
3145 log_module ( MAIN_LOG
, LOG_WARNING
, "AddUser( %p , %s , ...): server for numeric %s doesn't exist!" , ( void *) uplink
, nick
, numeric
);
3149 if ( uplink
!= GetServerN ( numeric
)) {
3150 log_module ( MAIN_LOG
, LOG_WARNING
, "AddUser( %p , %s , ...): server for numeric %s differs from nominal uplink %s ." , ( void *) uplink
, nick
, numeric
, uplink
-> name
);
3154 dummy
= modes
&& modes
[ 0 ] == '*' ;
3157 } else if (! is_valid_nick ( nick
)) {
3158 log_module ( MAIN_LOG
, LOG_WARNING
, "AddUser( %p , %s , ...): invalid nickname detected." , ( void *) uplink
, nick
);
3163 if (( oldUser
= GetUserH ( nick
))) {
3164 if ( IsLocal ( oldUser
)
3165 && ( IsService ( oldUser
) || IsPersistent ( oldUser
))) {
3166 /* The service should collide the new user off - but not
3167 * if the new user is coming in during a burst. (During a
3168 * burst, the bursting server will kill either our user --
3169 * triggering a ReintroduceUser() -- or its own.)
3171 oldUser
-> timestamp
= timestamp
- 1 ;
3175 } else if ( oldUser
-> timestamp
> timestamp
) {
3176 /* "Old" user is really newer; remove them */
3177 DelUser ( oldUser
, 0 , 1 , "Overruled by older nick" );
3179 /* User being added is too new; do not add them to
3180 * clients, but do add them to the server's list, since it
3181 * will send a KILL and QUIT soon. */
3186 /* create new usernode and set all values */
3187 uNode
= calloc ( 1 , sizeof (* uNode
));
3188 uNode
-> nick
= strdup ( nick
);
3189 safestrncpy ( uNode
-> ident
, ident
, sizeof ( uNode
-> ident
));
3190 safestrncpy ( uNode
-> info
, userinfo
, sizeof ( uNode
-> info
));
3191 safestrncpy ( uNode
-> hostname
, hostname
, sizeof ( uNode
-> hostname
));
3192 safestrncpy ( uNode
-> numeric
, numeric
, sizeof ( uNode
-> numeric
));
3193 irc_p10_pton (& uNode
-> ip
, realip
);
3195 if (! uNode
-> crypthost
&& uNode
-> cryptip
)
3196 snprintf ( uNode
-> crypthost
, sizeof ( uNode
-> crypthost
), " %s " , strdup ( uNode
-> cryptip
));
3197 uNode
-> idle_since
= timestamp
;
3198 uNode
-> timestamp
= timestamp
;
3199 modeList_init (& uNode
-> channels
);
3200 uNode
-> uplink
= uplink
;
3201 if (++ uNode
-> uplink
-> clients
> uNode
-> uplink
-> max_clients
) {
3202 uNode
-> uplink
-> max_clients
= uNode
-> uplink
-> clients
;
3204 uNode
-> num_local
= base64toint ( numeric
+ strlen ( uNode
-> uplink
-> numeric
), 3 ) & uNode
-> uplink
-> num_mask
;
3205 uNode
-> uplink
-> users
[ uNode
-> num_local
] = uNode
;
3206 mod_usermode ( uNode
, modes
);
3208 uNode
-> modes
|= FLAGS_DUMMY
;
3210 set_geoip_info ( uNode
);
3215 dict_insert ( clients
, uNode
-> nick
, uNode
);
3216 if ( dict_size ( clients
) > max_clients
) {
3217 max_clients
= dict_size ( clients
);
3218 max_clients_time
= now
;
3222 call_new_user_funcs ( uNode
);
3224 if (( uNode
-> loc
== 1 ) && ( uNode
-> handle_info
))
3225 send_func_list ( uNode
);
3230 /* removes user from it's server's hash table and nick hash table */
3232 DelUser ( struct userNode
* user
, struct userNode
* killer
, int announce
, const char * why
)
3237 /* mark them as dead, in case anybody cares */
3240 /* remove pending adduser commands */
3241 wipe_adduser_pending ( NULL
, user
);
3243 /* remove user from all channels */
3244 while ( user
-> channels
. used
> 0 )
3245 DelChannelUser ( user
, user
-> channels
. list
[ user
-> channels
. used
- 1 ]-> channel
, NULL
, 0 );
3247 /* Call these in reverse order so ChanServ can update presence
3248 information before NickServ nukes the handle_info. */
3249 call_del_user_funcs ( user
, killer
, why
);
3251 user
-> uplink
-> clients
--;
3252 user
-> uplink
-> users
[ user
-> num_local
] = NULL
;
3254 userList_remove (& curr_opers
, user
);
3255 if ( count_opers
> 0 && ! IsBotM ( user
) && ! IsService ( user
) && ! IsHideOper ( user
))
3258 /* remove from global dictionary, but not if after a collide */
3259 if ( user
== dict_find ( clients
, user
-> nick
, NULL
))
3260 dict_remove ( clients
, user
-> nick
);
3262 if ( IsInvisible ( user
))
3267 irc_quit ( user
, why
);
3269 irc_kill ( killer
, user
, why
);
3272 if ( IsLocal ( user
)) {
3273 unsigned int num
= user
-> num_local
;
3274 if ( num
< num_privmsg_funcs
)
3275 privmsg_funcs
[ num
] = NULL
;
3276 if ( num
< num_notice_funcs
)
3277 notice_funcs
[ num
] = NULL
;
3280 modeList_clean (& user
-> channels
);
3282 /* Clean up version data */
3283 if ( user
-> version_reply
) {
3284 free ( user
-> version_reply
);
3285 user
-> version_reply
= NULL
;
3288 /* Clean up SSL fingerprint data */
3299 free_string_list ( user
-> marks
);
3302 /* clean up geoip data if any */
3303 if ( user
-> country_code
) free ( user
-> country_code
);
3304 if ( user
-> city
) free ( user
-> city
);
3305 if ( user
-> region
) free ( user
-> region
);
3306 if ( user
-> postal_code
) free ( user
-> postal_code
);
3308 /* We don't free them, in case we try to privmsg them or something
3309 * (like when a stupid oper kills themself). We just put them onto
3310 * a list of clients that get freed after processing each line.
3312 if ( dead_users
. size
)
3313 userList_append (& dead_users
, user
);
3318 static void call_oper_funcs ( struct userNode
* user
);
3320 void mod_usermode ( struct userNode
* user
, const char * mode_change
) {
3324 const char * word
= mode_change
;
3326 if (! user
|| ! mode_change
)
3329 call_user_mode_funcs ( user
, mode_change
);
3331 setmodes
= user
-> modes
;
3333 while (* word
!= ' ' && * word
) word
++;
3334 while (* word
== ' ' ) word
++;
3335 while (! donemodes
) {
3336 #define do_user_mode(FLAG) do { if (add) user->modes |= FLAG; else user->modes &= ~FLAG; } while (0)
3337 switch (* mode_change
++) {
3341 case '+' : add
= 1 ; break ;
3342 case '-' : add
= 0 ; break ;
3344 do_user_mode ( FLAGS_OPER
);
3346 userList_remove (& curr_opers
, user
);
3347 } else if (! userList_contains (& curr_opers
, user
)) {
3348 userList_append (& curr_opers
, user
);
3349 call_oper_funcs ( user
);
3352 case 'O' : do_user_mode ( FLAGS_LOCOP
); break ;
3353 case 'i' : do_user_mode ( FLAGS_INVISIBLE
);
3359 case 'w' : do_user_mode ( FLAGS_WALLOP
); break ;
3360 case 'd' : do_user_mode ( FLAGS_DEAF
); break ;
3361 case 'k' : do_user_mode ( FLAGS_SERVICE
); break ;
3362 case 'g' : do_user_mode ( FLAGS_GLOBAL
); break ;
3363 case 'B' : do_user_mode ( FLAGS_BOT
); break ;
3364 case 'n' : do_user_mode ( FLAGS_HIDECHANS
); break ;
3365 case 'p' : do_user_mode ( FLAGS_HIDECHANS
); break ;
3366 case 'I' : do_user_mode ( FLAGS_HIDEIDLE
); break ;
3367 case 'X' : do_user_mode ( FLAGS_XTRAOP
); break ;
3368 case 'C' : do_user_mode ( FLAGS_CLOAKHOST
);
3370 char cloakhost
[ MAXLEN
];
3372 for ( ii
= 0 ; (* word
!= ' ' ) && (* word
!= '\0' ); )
3373 cloakhost
[ ii
++] = * word
++;
3375 while (* word
== ' ' )
3377 safestrncpy ( user
-> crypthost
, cloakhost
, sizeof ( user
-> crypthost
));
3380 case 'c' : do_user_mode ( FLAGS_CLOAKIP
);
3382 char cloakip
[ MAXLEN
];
3384 for ( ii
= 0 ; (* word
!= ' ' ) && (* word
!= '\0' ); )
3385 cloakip
[ ii
++] = * word
++;
3387 while (* word
== ' ' )
3389 safestrncpy ( user
-> cryptip
, cloakip
, sizeof ( user
-> cryptip
));
3392 // sethost - reed/apples
3393 // case 'h': do_user_mode(FLAGS_HELPER); break;
3394 // I check if there's an 'h' in the first part, and if there,
3395 // then everything after the space becomes their new host.
3396 case 'h' : do_user_mode ( FLAGS_SETHOST
);
3398 char sethost
[ MAXLEN
];
3400 for ( ii
= 0 ; (* word
!= ' ' ) && (* word
!= '\0' ); )
3401 sethost
[ ii
++] = * word
++;
3403 while (* word
== ' ' )
3405 safestrncpy ( user
-> sethost
, sethost
, sizeof ( user
-> sethost
));
3408 case 'x' : do_user_mode ( FLAGS_HIDDEN_HOST
); break ;
3413 for ( ii
= 0 ; (* word
!= ' ' ) && (* word
!= '\0' ); )
3414 tag
[ ii
++] = * word
++;
3416 while (* word
== ' ' )
3418 call_account_func ( user
, tag
);
3425 for ( ii
= 0 ; (* word
!= ' ' ) && (* word
!= '\0' ); )
3426 host
[ ii
++] = * word
++;
3428 while (* word
== ' ' )
3430 assign_fakehost ( user
, host
, 0 );
3433 case 'a' : do_user_mode ( FLAGS_ADMIN
); break ;
3434 case 'z' : do_user_mode ( FLAGS_SSL
); break ;
3435 case 'D' : do_user_mode ( FLAGS_PRIVDEAF
); break ;
3436 case 'R' : do_user_mode ( FLAGS_ACCOUNTONLY
); break ;
3437 case 'W' : do_user_mode ( FLAGS_WHOIS
); break ;
3438 case 'H' : do_user_mode ( FLAGS_HIDEOPER
); break ;
3439 case 'L' : do_user_mode ( FLAGS_NOLINK
); break ;
3440 case 'q' : do_user_mode ( FLAGS_COMMONCHANSONLY
); break ;
3446 if (!( setmodes
& FLAGS_OPER
) && IsOper ( user
)) {
3447 if (! IsBotM ( user
) && ! IsService ( user
) && ! IsHideOper ( user
))
3452 if (( setmodes
& FLAGS_OPER
) && ! IsOper ( user
)) {
3453 if ( count_opers
> 1 && !( setmodes
& FLAGS_BOT
) &&
3454 !( setmodes
& FLAGS_SERVICE
) && !( setmodes
& FLAGS_HIDEOPER
))
3459 if (!( setmodes
& FLAGS_HIDEOPER
) &&
3460 !( setmodes
& FLAGS_SERVICE
) &&
3461 !( setmodes
& FLAGS_BOT
) &&
3462 ( IsHideOper ( user
) || IsService ( user
) || IsBotM ( user
))) {
3463 if (( setmodes
& FLAGS_OPER
) && IsOper ( user
) && count_opers
> 0 )
3468 if ((( setmodes
& FLAGS_HIDEOPER
) ||
3469 ( setmodes
& FLAGS_SERVICE
) ||
3470 ( setmodes
& FLAGS_BOT
)) &&
3471 ! IsHideOper ( user
) && ! IsService ( user
) && ! IsBotM ( user
)) {
3472 if (( setmodes
& FLAGS_OPER
) && IsOper ( user
))
3478 keyncpy ( char output
[], char input
[], size_t output_size
)
3482 if ( input
[ 0 ] == ':' )
3488 for ( ii
= 0 ; ( ii
+ 1 < output_size
) && ( input
[ ii
] != '\0' ); ++ ii
)
3490 output
[ ii
] = input
[ ii
];
3497 struct mod_chanmode
*
3498 mod_chanmode_parse ( struct chanNode
* channel
, char ** modes
, unsigned int argc
, unsigned int flags
, short base_oplevel
)
3500 struct mod_chanmode
* change
;
3501 unsigned int ii
, in_arg
, ch_arg
, add
;
3505 if (!( change
= mod_chanmode_alloc ( argc
- 1 )))
3508 for ( ii
= ch_arg
= 0 , in_arg
= add
= 1 ;
3509 ( modes
[ 0 ][ ii
] != '\0' ) && ( modes
[ 0 ][ ii
] != ' ' );
3511 switch ( modes
[ 0 ][ ii
]) {
3518 #define do_chan_mode(FLAG) do { if (add) change->modes_set |= (FLAG), change->modes_clear &= ~(FLAG); else change->modes_clear |= (FLAG), change->modes_set &= ~(FLAG); } while(0)
3519 case 'C' : do_chan_mode ( MODE_NOCTCPS
); break ;
3520 case 'D' : do_chan_mode ( MODE_DELAYJOINS
); break ;
3521 case 'c' : do_chan_mode ( MODE_NOCOLORS
); break ;
3522 case 'i' : do_chan_mode ( MODE_INVITEONLY
); break ;
3523 case 'm' : do_chan_mode ( MODE_MODERATED
); break ;
3524 case 'n' : do_chan_mode ( MODE_NOPRIVMSGS
); break ;
3525 case 'p' : do_chan_mode ( MODE_PRIVATE
); break ;
3526 case 'r' : do_chan_mode ( MODE_REGONLY
); break ;
3527 case 's' : do_chan_mode ( MODE_SECRET
); break ;
3528 case 't' : do_chan_mode ( MODE_TOPICLIMIT
); break ;
3529 case 'S' : do_chan_mode ( MODE_STRIPCOLOR
); break ;
3530 case 'M' : do_chan_mode ( MODE_MODUNREG
); break ;
3531 case 'N' : do_chan_mode ( MODE_NONOTICE
); break ;
3532 case 'Q' : do_chan_mode ( MODE_NOQUITMSGS
); break ;
3533 case 'T' : do_chan_mode ( MODE_NOAMSG
); break ;
3534 case 'O' : do_chan_mode ( MODE_OPERSONLY
); break ;
3535 case 'a' : do_chan_mode ( MODE_ADMINSONLY
); break ;
3536 case 'Z' : do_chan_mode ( MODE_SSLONLY
); break ;
3537 case 'L' : do_chan_mode ( MODE_HIDEMODE
); break ;
3539 if (!( flags
& MCP_REGISTERED
)) {
3540 do_chan_mode ( MODE_REGISTERED
);
3542 mod_chanmode_free ( change
);
3551 change
-> modes_set
|= MODE_LIMIT
;
3552 change
-> new_limit
= atoi ( modes
[ in_arg
++]);
3554 change
-> modes_set
&= ~ MODE_LIMIT
;
3555 change
-> modes_clear
|= MODE_LIMIT
;
3560 if (( in_arg
>= argc
)
3561 || keyncpy ( change
-> new_key
, modes
[ in_arg
++], sizeof ( change
-> new_key
)))
3563 change
-> modes_set
|= MODE_KEY
;
3565 change
-> modes_clear
|= MODE_KEY
;
3566 if (!( flags
& MCP_KEY_FREE
)) {
3576 if (( in_arg
>= argc
)
3577 || keyncpy ( change
-> new_upass
, modes
[ in_arg
++], sizeof ( change
-> new_upass
)))
3579 change
-> modes_set
|= MODE_UPASS
;
3581 change
-> modes_clear
|= MODE_UPASS
;
3582 if (!( flags
& MCP_UPASS_FREE
)) {
3591 if (( in_arg
>= argc
)
3592 || keyncpy ( change
-> new_apass
, modes
[ in_arg
++], sizeof ( change
-> new_apass
)))
3594 change
-> modes_set
|= MODE_APASS
;
3596 change
-> modes_clear
|= MODE_APASS
;
3597 if (!( flags
& MCP_APASS_FREE
)) {
3605 if (!( flags
& MCP_ALLOW_OVB
))
3609 change
-> args
[ ch_arg
]. mode
= MODE_BAN
;
3611 change
-> args
[ ch_arg
]. mode
|= MODE_REMOVE
;
3612 change
-> args
[ ch_arg
++]. u
. hostmask
= modes
[ in_arg
++];
3615 if (!( flags
& MCP_ALLOW_OVB
))
3619 change
-> args
[ ch_arg
]. mode
= MODE_EXEMPT
;
3621 change
-> args
[ ch_arg
]. mode
|= MODE_REMOVE
;
3622 change
-> args
[ ch_arg
++]. u
. hostmask
= modes
[ in_arg
++];
3624 case 'o' : case 'h' : case 'v' :
3626 struct userNode
* victim
;
3632 oplevel_str
= strchr ( modes
[ in_arg
], ':' );
3635 /* XXYYY M #channel +o XXYYY:<oplevel> */
3636 * oplevel_str
++ = '\0' ;
3637 oplevel
= parse_oplevel ( oplevel_str
);
3638 if ( oplevel
<= base_oplevel
&& !( flags
& MCP_FROM_SERVER
))
3639 oplevel
= base_oplevel
+ 1 ;
3641 else if ( channel
-> modes
& MODE_UPASS
)
3642 oplevel
= base_oplevel
+ 1 ;
3646 /* Check that oplevel is within bounds. */
3647 if ( oplevel
> MAXOPLEVEL
)
3648 oplevel
= MAXOPLEVEL
;
3650 if (!( flags
& MCP_ALLOW_OVB
))
3655 if ( modes
[ 0 ][ ii
] == 'o' )
3656 change
-> args
[ ch_arg
]. mode
= MODE_CHANOP
;
3657 else if ( modes
[ 0 ][ ii
] == 'h' )
3658 change
-> args
[ ch_arg
]. mode
= MODE_HALFOP
;
3659 else if ( modes
[ 0 ][ ii
] == 'v' )
3660 change
-> args
[ ch_arg
]. mode
= MODE_VOICE
;
3663 change
-> args
[ ch_arg
]. mode
|= MODE_REMOVE
;
3664 if ( flags
& MCP_FROM_SERVER
)
3665 victim
= GetUserN ( modes
[ in_arg
++]);
3667 victim
= GetUserH ( modes
[ in_arg
++]);
3670 if (( change
-> args
[ ch_arg
]. u
. member
= GetUserMode ( channel
, victim
)))
3672 /* Apply the oplevel change */
3673 change
-> args
[ ch_arg
]. u
. member
-> oplevel
= oplevel
;
3679 if (!( flags
& MCP_FROM_SERVER
))
3684 change
-> argc
= ch_arg
; /* in case any turned out to be ignored */
3685 if ( change
-> modes_set
& MODE_SECRET
) {
3686 change
-> modes_set
&= ~( MODE_PRIVATE
);
3687 change
-> modes_clear
|= MODE_PRIVATE
;
3688 } else if ( change
-> modes_set
& MODE_PRIVATE
) {
3689 change
-> modes_set
&= ~( MODE_SECRET
);
3690 change
-> modes_clear
|= MODE_SECRET
;
3694 mod_chanmode_free ( change
);
3698 struct chanmode_buffer
{
3701 struct chanNode
* channel
;
3702 struct userNode
* actor
;
3703 unsigned int modes_used
;
3704 unsigned int args_used
;
3706 unsigned int is_add
: 1 ;
3707 unsigned int is_chanop
: 1 ;
3711 mod_chanmode_append ( struct chanmode_buffer
* buf
, char ch
, const char * arg
)
3713 size_t arg_len
= strlen ( arg
);
3714 if ( buf
-> modes_used
> ( MAXMODEPARAMS
) ||
3715 buf
-> modes_used
+ buf
-> args_used
+ buf
-> chname_len
+ arg_len
> 450 ) {
3716 memcpy ( buf
-> modes
+ buf
-> modes_used
, buf
-> args
, buf
-> args_used
);
3717 buf
-> modes
[ buf
-> modes_used
+ buf
-> args_used
] = '\0' ;
3718 irc_mode (( buf
-> is_chanop
? buf
-> actor
: NULL
), buf
-> channel
, buf
-> modes
);
3719 buf
-> modes
[ 0 ] = buf
-> is_add
? '+' : '-' ;
3720 buf
-> modes_used
= 1 ;
3723 buf
-> modes
[ buf
-> modes_used
++] = ch
;
3724 buf
-> args
[ buf
-> args_used
++] = ' ' ;
3725 memcpy ( buf
-> args
+ buf
-> args_used
, arg
, arg_len
);
3726 buf
-> args_used
+= arg_len
;
3730 mod_chanmode_announce ( struct userNode
* who
, struct chanNode
* channel
, struct mod_chanmode
* change
)
3732 struct chanmode_buffer chbuf
;
3734 struct modeNode
* mn
;
3735 char int_buff
[ 32 ], mode
= '\0' ;
3737 assert ( change
-> argc
<= change
-> alloc_argc
);
3738 memset (& chbuf
, 0 , sizeof ( chbuf
));
3739 chbuf
. channel
= channel
;
3741 chbuf
. chname_len
= strlen ( channel
-> name
);
3743 mn
= GetUserMode ( channel
, who
);
3744 if (( mn
&& ( mn
-> modes
& MODE_CHANOP
)) || off_channel
)
3745 chbuf
. is_chanop
= 1 ;
3747 /* First remove modes */
3749 if ( change
-> modes_clear
) {
3751 chbuf
. modes
[ chbuf
. modes_used
++] = mode
= '-' ;
3752 #define DO_MODE_CHAR(BIT, CHAR) if (change->modes_clear & MODE_##BIT) chbuf.modes[chbuf.modes_used++] = CHAR
3753 DO_MODE_CHAR ( PRIVATE
, 'p' );
3754 DO_MODE_CHAR ( SECRET
, 's' );
3755 DO_MODE_CHAR ( MODERATED
, 'm' );
3756 DO_MODE_CHAR ( TOPICLIMIT
, 't' );
3757 DO_MODE_CHAR ( INVITEONLY
, 'i' );
3758 DO_MODE_CHAR ( NOPRIVMSGS
, 'n' );
3759 DO_MODE_CHAR ( LIMIT
, 'l' );
3760 DO_MODE_CHAR ( DELAYJOINS
, 'D' );
3761 DO_MODE_CHAR ( REGONLY
, 'r' );
3762 DO_MODE_CHAR ( NOCOLORS
, 'c' );
3763 DO_MODE_CHAR ( NOCTCPS
, 'C' );
3764 DO_MODE_CHAR ( STRIPCOLOR
, 'S' );
3765 DO_MODE_CHAR ( MODUNREG
, 'M' );
3766 DO_MODE_CHAR ( NONOTICE
, 'N' );
3767 DO_MODE_CHAR ( NOQUITMSGS
, 'Q' );
3768 DO_MODE_CHAR ( NOAMSG
, 'T' );
3769 DO_MODE_CHAR ( OPERSONLY
, 'O' );
3770 DO_MODE_CHAR ( ADMINSONLY
, 'a' );
3771 DO_MODE_CHAR ( REGISTERED
, 'z' );
3772 DO_MODE_CHAR ( SSLONLY
, 'Z' );
3773 DO_MODE_CHAR ( HIDEMODE
, 'L' );
3775 if ( change
-> modes_clear
& channel
-> modes
& MODE_KEY
)
3776 mod_chanmode_append (& chbuf
, 'k' , channel
-> key
);
3777 if ( change
-> modes_clear
& channel
-> modes
& MODE_UPASS
)
3778 mod_chanmode_append (& chbuf
, 'U' , channel
-> upass
);
3779 if ( change
-> modes_clear
& channel
-> modes
& MODE_APASS
)
3780 mod_chanmode_append (& chbuf
, 'A' , channel
-> apass
);
3782 for ( arg
= 0 ; arg
< change
-> argc
; ++ arg
) {
3783 if (!( change
-> args
[ arg
]. mode
& MODE_REMOVE
))
3786 chbuf
. modes
[ chbuf
. modes_used
++] = mode
= '-' ;
3787 switch ( change
-> args
[ arg
]. mode
& ~ MODE_REMOVE
) {
3789 mod_chanmode_append (& chbuf
, 'b' , change
-> args
[ arg
]. u
. hostmask
);
3792 mod_chanmode_append (& chbuf
, 'e' , change
-> args
[ arg
]. u
. hostmask
);
3795 if ( change
-> args
[ arg
]. mode
& MODE_CHANOP
)
3796 mod_chanmode_append (& chbuf
, 'o' , change
-> args
[ arg
]. u
. member
-> user
-> numeric
);
3797 if ( change
-> args
[ arg
]. mode
& MODE_HALFOP
)
3798 mod_chanmode_append (& chbuf
, 'h' , change
-> args
[ arg
]. u
. member
-> user
-> numeric
);
3799 if ( change
-> args
[ arg
]. mode
& MODE_VOICE
)
3800 mod_chanmode_append (& chbuf
, 'v' , change
-> args
[ arg
]. u
. member
-> user
-> numeric
);
3807 if ( change
-> modes_set
) {
3809 chbuf
. modes
[ chbuf
. modes_used
++] = mode
= '+' ;
3810 #define DO_MODE_CHAR(BIT, CHAR) if (change->modes_set & MODE_##BIT) chbuf.modes[chbuf.modes_used++] = CHAR
3811 DO_MODE_CHAR ( PRIVATE
, 'p' );
3812 DO_MODE_CHAR ( SECRET
, 's' );
3813 DO_MODE_CHAR ( MODERATED
, 'm' );
3814 DO_MODE_CHAR ( TOPICLIMIT
, 't' );
3815 DO_MODE_CHAR ( INVITEONLY
, 'i' );
3816 DO_MODE_CHAR ( NOPRIVMSGS
, 'n' );
3817 DO_MODE_CHAR ( DELAYJOINS
, 'D' );
3818 DO_MODE_CHAR ( REGONLY
, 'r' );
3819 DO_MODE_CHAR ( NOCOLORS
, 'c' );
3820 DO_MODE_CHAR ( NOCTCPS
, 'C' );
3821 DO_MODE_CHAR ( STRIPCOLOR
, 'S' );
3822 DO_MODE_CHAR ( MODUNREG
, 'M' );
3823 DO_MODE_CHAR ( NONOTICE
, 'N' );
3824 DO_MODE_CHAR ( NOQUITMSGS
, 'Q' );
3825 DO_MODE_CHAR ( NOAMSG
, 'T' );
3826 DO_MODE_CHAR ( OPERSONLY
, 'O' );
3827 DO_MODE_CHAR ( ADMINSONLY
, 'a' );
3828 DO_MODE_CHAR ( REGISTERED
, 'z' );
3829 DO_MODE_CHAR ( SSLONLY
, 'Z' );
3830 DO_MODE_CHAR ( HIDEMODE
, 'L' );
3832 if ( change
-> modes_set
& MODE_KEY
)
3833 mod_chanmode_append (& chbuf
, 'k' , change
-> new_key
);
3834 if ( change
-> modes_set
& MODE_UPASS
)
3835 mod_chanmode_append (& chbuf
, 'U' , change
-> new_upass
);
3836 if ( change
-> modes_set
& MODE_APASS
)
3837 mod_chanmode_append (& chbuf
, 'A' , change
-> new_apass
);
3838 if ( change
-> modes_set
& MODE_LIMIT
) {
3839 sprintf ( int_buff
, " %d " , change
-> new_limit
);
3840 mod_chanmode_append (& chbuf
, 'l' , int_buff
);
3843 for ( arg
= 0 ; arg
< change
-> argc
; ++ arg
) {
3844 if ( change
-> args
[ arg
]. mode
& MODE_REMOVE
)
3847 chbuf
. modes
[ chbuf
. modes_used
++] = mode
= '+' ;
3848 switch ( change
-> args
[ arg
]. mode
) {
3850 mod_chanmode_append (& chbuf
, 'b' , change
-> args
[ arg
]. u
. hostmask
);
3853 mod_chanmode_append (& chbuf
, 'e' , change
-> args
[ arg
]. u
. hostmask
);
3856 if ( change
-> args
[ arg
]. mode
& MODE_CHANOP
)
3857 mod_chanmode_append (& chbuf
, 'o' , change
-> args
[ arg
]. u
. member
-> user
-> numeric
);
3858 if ( change
-> args
[ arg
]. mode
& MODE_HALFOP
)
3859 mod_chanmode_append (& chbuf
, 'h' , change
-> args
[ arg
]. u
. member
-> user
-> numeric
);
3860 if ( change
-> args
[ arg
]. mode
& MODE_VOICE
)
3861 mod_chanmode_append (& chbuf
, 'v' , change
-> args
[ arg
]. u
. member
-> user
-> numeric
);
3866 /* Flush the buffer and apply changes locally */
3867 if ( chbuf
. modes_used
> 0 ) {
3868 memcpy ( chbuf
. modes
+ chbuf
. modes_used
, chbuf
. args
, chbuf
. args_used
);
3869 chbuf
. modes
[ chbuf
. modes_used
+ chbuf
. args_used
] = '\0' ;
3870 irc_mode (( chbuf
. is_chanop
? chbuf
. actor
: NULL
), chbuf
. channel
, chbuf
. modes
);
3872 mod_chanmode_apply ( who
, channel
, change
);
3876 mod_chanmode_format ( struct mod_chanmode
* change
, char * outbuff
)
3878 unsigned int used
= 0 ;
3879 assert ( change
-> argc
<= change
-> alloc_argc
);
3880 if ( change
-> modes_clear
) {
3881 outbuff
[ used
++] = '-' ;
3882 #define DO_MODE_CHAR(BIT, CHAR) if (change->modes_clear & MODE_##BIT) outbuff[used++] = CHAR
3883 DO_MODE_CHAR ( PRIVATE
, 'p' );
3884 DO_MODE_CHAR ( SECRET
, 's' );
3885 DO_MODE_CHAR ( MODERATED
, 'm' );
3886 DO_MODE_CHAR ( TOPICLIMIT
, 't' );
3887 DO_MODE_CHAR ( INVITEONLY
, 'i' );
3888 DO_MODE_CHAR ( NOPRIVMSGS
, 'n' );
3889 DO_MODE_CHAR ( LIMIT
, 'l' );
3890 DO_MODE_CHAR ( KEY
, 'k' );
3891 DO_MODE_CHAR ( UPASS
, 'U' );
3892 DO_MODE_CHAR ( APASS
, 'A' );
3893 DO_MODE_CHAR ( DELAYJOINS
, 'D' );
3894 DO_MODE_CHAR ( REGONLY
, 'r' );
3895 DO_MODE_CHAR ( NOCOLORS
, 'c' );
3896 DO_MODE_CHAR ( NOCTCPS
, 'C' );
3897 DO_MODE_CHAR ( STRIPCOLOR
, 'S' );
3898 DO_MODE_CHAR ( MODUNREG
, 'M' );
3899 DO_MODE_CHAR ( NONOTICE
, 'N' );
3900 DO_MODE_CHAR ( NOQUITMSGS
, 'Q' );
3901 DO_MODE_CHAR ( NOAMSG
, 'T' );
3902 DO_MODE_CHAR ( OPERSONLY
, 'O' );
3903 DO_MODE_CHAR ( ADMINSONLY
, 'a' );
3904 DO_MODE_CHAR ( REGISTERED
, 'z' );
3905 DO_MODE_CHAR ( SSLONLY
, 'Z' );
3906 DO_MODE_CHAR ( HIDEMODE
, 'L' );
3909 if ( change
-> modes_set
) {
3910 outbuff
[ used
++] = '+' ;
3911 #define DO_MODE_CHAR(BIT, CHAR) if (change->modes_set & MODE_##BIT) outbuff[used++] = CHAR
3912 DO_MODE_CHAR ( PRIVATE
, 'p' );
3913 DO_MODE_CHAR ( SECRET
, 's' );
3914 DO_MODE_CHAR ( MODERATED
, 'm' );
3915 DO_MODE_CHAR ( TOPICLIMIT
, 't' );
3916 DO_MODE_CHAR ( INVITEONLY
, 'i' );
3917 DO_MODE_CHAR ( NOPRIVMSGS
, 'n' );
3918 DO_MODE_CHAR ( DELAYJOINS
, 'D' );
3919 DO_MODE_CHAR ( REGONLY
, 'r' );
3920 DO_MODE_CHAR ( NOCOLORS
, 'c' );
3921 DO_MODE_CHAR ( NOCTCPS
, 'C' );
3922 DO_MODE_CHAR ( STRIPCOLOR
, 'S' );
3923 DO_MODE_CHAR ( MODUNREG
, 'M' );
3924 DO_MODE_CHAR ( NONOTICE
, 'N' );
3925 DO_MODE_CHAR ( NOQUITMSGS
, 'Q' );
3926 DO_MODE_CHAR ( NOAMSG
, 'T' );
3927 DO_MODE_CHAR ( OPERSONLY
, 'O' );
3928 DO_MODE_CHAR ( ADMINSONLY
, 'a' );
3929 DO_MODE_CHAR ( REGISTERED
, 'z' );
3930 DO_MODE_CHAR ( SSLONLY
, 'Z' );
3931 DO_MODE_CHAR ( HIDEMODE
, 'L' );
3933 DO_MODE_CHAR ( KEY
, 'k' );
3934 DO_MODE_CHAR ( LIMIT
, 'l' );
3935 DO_MODE_CHAR ( APASS
, 'A' );
3936 DO_MODE_CHAR ( UPASS
, 'U' );
3939 #define DO_MODE_PARM(BIT, PARM) if (change->modes_set & MODE_##BIT) used += sprintf(outbuff+used, " %s " , PARM);
3940 DO_MODE_PARM ( KEY
, change
-> new_key
);
3941 if ( change
-> modes_set
& MODE_LIMIT
) used
+= sprintf ( outbuff
+ used
, " %d " , change
-> new_limit
);
3942 DO_MODE_PARM ( APASS
, change
-> new_apass
);
3943 DO_MODE_PARM ( UPASS
, change
-> new_upass
);
3951 clear_chanmode ( struct chanNode
* channel
, const char * modes
)
3953 unsigned int cleared
;
3955 for ( cleared
= 0 ; * modes
; modes
++) {
3957 case 'o' : cleared
|= MODE_CHANOP
; break ;
3958 case 'h' : cleared
|= MODE_HALFOP
; break ;
3959 case 'v' : cleared
|= MODE_VOICE
; break ;
3960 case 'p' : cleared
|= MODE_PRIVATE
; break ;
3961 case 's' : cleared
|= MODE_SECRET
; break ;
3962 case 'm' : cleared
|= MODE_MODERATED
; break ;
3963 case 't' : cleared
|= MODE_TOPICLIMIT
; break ;
3964 case 'i' : cleared
|= MODE_INVITEONLY
; break ;
3965 case 'n' : cleared
|= MODE_NOPRIVMSGS
; break ;
3967 cleared
|= MODE_KEY
;
3968 channel
-> key
[ 0 ] = '\0' ;
3971 cleared
|= MODE_APASS
;
3972 channel
-> apass
[ 0 ] = '\0' ;
3975 cleared
|= MODE_UPASS
;
3976 channel
-> upass
[ 0 ] = '\0' ;
3979 cleared
|= MODE_LIMIT
;
3982 case 'b' : cleared
|= MODE_BAN
; break ;
3983 case 'e' : cleared
|= MODE_EXEMPT
; break ;
3984 case 'D' : cleared
|= MODE_DELAYJOINS
; break ;
3985 case 'r' : cleared
|= MODE_REGONLY
; break ;
3986 case 'c' : cleared
|= MODE_NOCOLORS
; break ;
3987 case 'C' : cleared
|= MODE_NOCTCPS
; break ;
3988 case 'S' : cleared
|= MODE_STRIPCOLOR
; break ;
3989 case 'M' : cleared
|= MODE_MODUNREG
; break ;
3990 case 'N' : cleared
|= MODE_NONOTICE
; break ;
3991 case 'Q' : cleared
|= MODE_NOQUITMSGS
; break ;
3992 case 'T' : cleared
|= MODE_NOAMSG
; break ;
3993 case 'O' : cleared
|= MODE_OPERSONLY
; break ;
3994 case 'a' : cleared
|= MODE_ADMINSONLY
; break ;
3995 case 'z' : cleared
|= MODE_REGISTERED
; break ;
3996 case 'Z' : cleared
|= MODE_SSLONLY
; break ;
3997 case 'L' : cleared
|= MODE_HIDEMODE
; break ;
4004 /* Remove simple modes. */
4005 channel
-> modes
&= ~ cleared
;
4007 /* If removing bans, kill 'em all. */
4008 if (( cleared
& MODE_BAN
) && channel
-> banlist
. used
) {
4010 for ( i
= 0 ; i
< channel
-> banlist
. used
; i
++)
4011 free ( channel
-> banlist
. list
[ i
]);
4012 channel
-> banlist
. used
= 0 ;
4015 /* If removing exempts, kill 'em all. */
4016 if (( cleared
& MODE_EXEMPT
) && channel
-> exemptlist
. used
) {
4018 for ( i
= 0 ; i
< channel
-> exemptlist
. used
; i
++)
4019 free ( channel
-> exemptlist
. list
[ i
]);
4020 channel
-> exemptlist
. used
= 0 ;
4023 /* Removed member modes. */
4024 if (( cleared
& ( MODE_CHANOP
| MODE_HALFOP
| MODE_VOICE
)) && channel
-> members
. used
) {
4025 int mask
= ~( cleared
& ( MODE_CHANOP
| MODE_HALFOP
| MODE_VOICE
));
4028 for ( i
= 0 ; i
< channel
-> members
. used
; i
++)
4029 channel
-> members
. list
[ i
]-> modes
&= mask
;
4036 reg_privmsg_func ( struct userNode
* user
, privmsg_func_t handler
)
4038 unsigned int numeric
= user
-> num_local
;
4039 if ( numeric
>= num_privmsg_funcs
) {
4040 int newnum
= numeric
+ 8 , ii
;
4041 privmsg_funcs
= realloc ( privmsg_funcs
, newnum
* sizeof ( privmsg_func_t
));
4042 for ( ii
= num_privmsg_funcs
; ii
< newnum
; ++ ii
)
4043 privmsg_funcs
[ ii
] = NULL
;
4044 num_privmsg_funcs
= newnum
;
4046 if ( privmsg_funcs
[ numeric
])
4047 log_module ( MAIN_LOG
, LOG_WARNING
, "re-registering new privmsg handler for numeric %d " , numeric
);
4048 privmsg_funcs
[ numeric
] = handler
;
4052 unreg_privmsg_func ( struct userNode
* user
)
4054 if (! IsLocal ( user
) || user
-> num_local
>= num_privmsg_funcs
)
4055 return ; /* this really only works with users */
4057 privmsg_funcs
[ user
-> num_local
] = NULL
;
4062 reg_notice_func ( struct userNode
* user
, privmsg_func_t handler
)
4064 unsigned int numeric
= user
-> num_local
;
4065 if ( numeric
>= num_notice_funcs
) {
4066 int newnum
= numeric
+ 8 , ii
;
4067 notice_funcs
= realloc ( notice_funcs
, newnum
* sizeof ( privmsg_func_t
));
4068 for ( ii
= num_privmsg_funcs
; ii
< newnum
; ++ ii
)
4069 privmsg_funcs
[ ii
] = NULL
;
4070 num_notice_funcs
= newnum
;
4072 if ( notice_funcs
[ numeric
])
4073 log_module ( MAIN_LOG
, LOG_WARNING
, "re-registering new notice handler for numeric %d " , numeric
);
4074 notice_funcs
[ numeric
] = handler
;
4078 unreg_notice_func ( struct userNode
* user
)
4080 if (! IsLocal ( user
) || user
-> num_local
>= num_privmsg_funcs
)
4081 return ; /* this really only works with users */
4083 notice_funcs
[ user
-> num_local
] = NULL
;
4089 unsigned int i
, hop
, max_hop
= 1 ;
4092 /* burst (juped) servers, closest first (except self, which is sent already) */
4093 for ( i
= 0 ; i
< ArrayLength ( servers_num
); i
++)
4094 if ( servers_num
[ i
] && servers_num
[ i
]-> hops
> max_hop
)
4095 max_hop
= servers_num
[ i
]-> hops
;
4096 for ( hop
= 1 ; hop
<= max_hop
; hop
++) {
4097 for ( i
= 0 ; i
< ArrayLength ( servers_num
); i
++) {
4099 && ( servers_num
[ i
]-> hops
== hop
)
4100 && ( servers_num
[ i
] != self
-> uplink
))
4101 irc_server ( servers_num
[ i
]);
4105 /* burst local nicks */
4106 for ( i
= 0 ; i
<= self
-> num_mask
; i
++)
4108 irc_user ( self
-> users
[ i
]);
4110 /* build dict of unbursted channel names (just copy existing channels) */
4111 unbursted_channels
= dict_new ();
4112 for ( it
= dict_first ( channels
); it
; it
= iter_next ( it
))
4113 dict_insert ( unbursted_channels
, iter_key ( it
), iter_data ( it
));
4120 parse_oplevel ( char * str
)
4123 while ( isdigit (* str
))
4124 oplevel
= oplevel
* 10 + * str
++ - '0' ;