]>
jfr.im git - irc/evilnet/x3.git/blob - src/proto-p10.c
eb9e48333a75738e9e0ff62728ba53a8727b3f17
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 "hosthiding.h"
26 #include "proto-common.c"
30 #define CMD_ACCOUNT "ACCOUNT"
31 #define CMD_ADMIN "ADMIN"
32 #define CMD_ALIST "ALIST"
33 #define CMD_ASLL "ASLL"
34 #define CMD_AWAY "AWAY"
35 #define CMD_BURST "BURST"
36 #define CMD_CLEARMODE "CLEARMODE"
37 #define CMD_CLOSE "CLOSE"
38 #define CMD_CNOTICE "CNOTICE"
39 #define CMD_CONNECT "CONNECT"
40 #define CMD_CPRIVMSG "CPRIVMSG"
41 #define CMD_CREATE "CREATE"
42 #define CMD_DESTRUCT "DESTRUCT"
43 #define CMD_DESYNCH "DESYNCH"
46 #define CMD_EOB "END_OF_BURST"
47 #define CMD_EOB_ACK "EOB_ACK"
48 #define CMD_ERROR "ERROR"
49 #define CMD_FAKEHOST "FAKE"
51 #define CMD_GLINE "GLINE"
52 #define CMD_HASH "HASH"
53 #define CMD_HELP "HELP"
54 #define CMD_INFO "INFO"
55 #define CMD_INVITE "INVITE"
56 #define CMD_ISON "ISON"
57 #define CMD_JOIN "JOIN"
58 #define CMD_JUPE "JUPE"
59 #define CMD_KICK "KICK"
60 #define CMD_KILL "KILL"
61 #define CMD_LINKS "LINKS"
62 #define CMD_LIST "LIST"
63 #define CMD_LUSERS "LUSERS"
65 #define CMD_MARK "MARK"
66 #define CMD_MODE "MODE"
67 #define CMD_MOTD "MOTD"
68 #define CMD_NAMES "NAMES"
69 #define CMD_NICK "NICK"
70 #define CMD_NOTICE "NOTICE"
71 #define CMD_OPER "OPER"
72 #define CMD_OPMODE "OPMODE"
73 #define CMD_PART "PART"
74 #define CMD_PASS "PASS"
75 #define CMD_PING "PING"
76 #define CMD_PONG "PONG"
77 #define CMD_POST "POST"
78 #define CMD_PRIVMSG "PRIVMSG"
79 #define CMD_PRIVS "PRIVS"
80 #define CMD_PROTO "PROTO"
81 #define CMD_QUIT "QUIT"
82 #define CMD_REHASH "REHASH"
83 #define CMD_RESET "RESET"
84 #define CMD_RESTART "RESTART"
85 #define CMD_RPING "RPING"
86 #define CMD_RPONG "RPONG"
87 #define CMD_SERVER "SERVER"
88 #define CMD_SERVLIST "SERVLIST"
89 #define CMD_SERVSET "SERVSET"
91 #define CMD_SETTIME "SETTIME"
92 #define CMD_SGLINE "SGLINE"
93 #define CMD_SHUN "SHUN"
94 #define CMD_SILENCE "SILENCE"
97 #define CMD_SSHUN "SSHUN"
98 #define CMD_SPAMFILTER "SPAMFILTER"
99 #define CMD_SQUERY "SQUERY"
100 #define CMD_SQUIT "SQUIT"
101 #define CMD_STATS "STATS"
102 #define CMD_SVSJOIN "SVSJOIN"
103 #define CMD_SVSNICK "SVSNICK"
104 #define CMD_SVSPART "SVSPART"
105 #define CMD_SVSQUIT "SVSQUIT"
106 #define CMD_SWHOIS "SWHOIS"
107 #define CMD_TIME "TIME"
108 #define CMD_TOPIC "TOPIC"
109 #define CMD_TRACE "TRACE"
110 #define CMD_UPING "UPING"
111 #define CMD_USER "USER"
112 #define CMD_USERHOST "USERHOST"
113 #define CMD_USERIP "USERIP"
114 #define CMD_VERSION "VERSION"
115 #define CMD_WALLCHOPS "WALLCHOPS"
116 #define CMD_WALLOPS "WALLOPS"
117 #define CMD_WALLHOPS "WALLHOPS"
118 #define CMD_WALLUSERS "WALLUSERS"
119 #define CMD_WALLVOICES "WALLVOICES"
120 #define CMD_WALLHOPS "WALLHOPS"
121 #define CMD_WHO "WHO"
122 #define CMD_WHOIS "WHOIS"
123 #define CMD_WHOWAS "WHOWAS"
125 /* Tokenized commands. */
126 #define TOK_ACCOUNT "AC"
127 #define TOK_ADMIN "AD"
128 #define TOK_ALIST "AL"
129 #define TOK_ASLL "LL"
131 #define TOK_BURST "B"
132 #define TOK_CLEARMODE "CM"
133 #define TOK_CLOSE "CLOSE"
134 #define TOK_CNOTICE "CN"
135 #define TOK_CONNECT "CO"
136 #define TOK_CPRIVMSG "CP"
137 #define TOK_CREATE "C"
138 #define TOK_DESTRUCT "DE"
139 #define TOK_DESYNCH "DS"
140 #define TOK_DIE "DIE"
141 #define TOK_DNS "DNS"
143 #define TOK_EOB_ACK "EA"
144 #define TOK_ERROR "Y"
145 #define TOK_EXEMPT "EX"
146 #define TOK_FAKEHOST "FA"
147 #define TOK_GET "GET"
148 #define TOK_GLINE "GL"
149 #define TOK_HASH "HASH"
150 #define TOK_HELP "HELP"
152 #define TOK_INVITE "I"
153 #define TOK_ISON "ISON"
155 #define TOK_JUPE "JU"
158 #define TOK_LINKS "LI"
159 #define TOK_LIST "LIST"
160 #define TOK_LUSERS "LU"
161 #define TOK_MAP "MAP"
162 #define TOK_MARK "MK"
164 #define TOK_MOTD "MO"
165 #define TOK_NAMES "E"
167 #define TOK_NOTICE "O"
168 #define TOK_OPER "OPER"
169 #define TOK_OPMODE "OM"
171 #define TOK_PASS "PA"
174 #define TOK_POST "POST"
175 #define TOK_PRIVMSG "P"
176 #define TOK_PRIVS "PRIVS"
177 #define TOK_PROTO "PROTO"
179 #define TOK_REHASH "REHASH"
180 #define TOK_RESET "RESET"
181 #define TOK_RESTART "RESTART"
182 #define TOK_RPING "RI"
183 #define TOK_RPONG "RO"
184 #define TOK_SERVER "S"
185 #define TOK_SERVLIST "SERVSET"
186 #define TOK_SERVSET "SERVSET"
187 #define TOK_SET "SET"
188 #define TOK_SETTIME "SE"
189 #define TOK_SGLINE "SGL"
190 #define TOK_SHUN "SU"
191 #define TOK_SILENCE "U"
192 #define TOK_SMO "SMO"
193 #define TOK_SNO "SNO"
194 #define TOK_SSHUN "SSU"
195 #define TOK_SPAMFILTER "SF"
196 #define TOK_SQUERY "SQUERY"
197 #define TOK_SQUIT "SQ"
198 #define TOK_STATS "R"
199 #define TOK_SVSJOIN "SJ"
200 #define TOK_SVSNICK "SN"
201 #define TOK_SVSPART "SP"
202 #define TOK_SVSQUIT "SX"
203 #define TOK_SWHOIS "SW"
204 #define TOK_TIME "TI"
205 #define TOK_TOPIC "T"
206 #define TOK_TRACE "TR"
207 #define TOK_UPING "UP"
208 #define TOK_USER "USER"
209 #define TOK_USERHOST "USERHOST"
210 #define TOK_USERIP "USERIP"
211 #define TOK_VERSION "V"
212 #define TOK_WALLCHOPS "WC"
213 #define TOK_WALLOPS "WA"
214 #define TOK_WALLHOPS "WH"
215 #define TOK_WALLUSERS "WU"
216 #define TOK_WALLVOICES "WV"
217 #define TOK_WALLHOPS "WH"
219 #define TOK_WHOIS "W"
220 #define TOK_WHOWAS "X"
222 /* Protocol messages; aliased to full commands or tokens depending
223 on compile-time configuration. ircu prefers tokens WITH THE
224 EXCEPTION OF THE SERVER AND PASS COMMANDS, which cannot be
225 tokenized, because clients' (ie. a linking server) commands are
226 only checked against the full command list.
228 #if defined(ENABLE_TOKENS)
229 #define TYPE(NAME) TOK_ ## NAME
230 #else /* !ENABLE_TOKENS */
231 #define TYPE(NAME) CMD_ ## NAME
232 #endif /* ENABLE_TOKENS */
234 #define P10_ACCOUNT TYPE(ACCOUNT)
235 #define P10_ADMIN TYPE(ADMIN)
236 #define P10_ASLL TYPE(ASLL)
237 #define P10_AWAY TYPE(AWAY)
238 #define P10_BURST TYPE(BURST)
239 #define P10_CLEARMODE TYPE(CLEARMODE)
240 #define P10_CLOSE TYPE(CLOSE)
241 #define P10_CNOTICE TYPE(CNOTICE)
242 #define P10_CONNECT TYPE(CONNECT)
243 #define P10_CPRIVMSG TYPE(CPRIVMSG)
244 #define P10_CREATE TYPE(CREATE)
245 #define P10_DESTRUCT TYPE(DESTRUCT)
246 #define P10_DESYNCH TYPE(DESYNCH)
247 #define P10_DIE TYPE(DIE)
248 #define P10_DNS TYPE(DNS)
249 #define P10_EOB TYPE(EOB)
250 #define P10_EOB_ACK TYPE(EOB_ACK)
251 #define P10_ERROR TYPE(ERROR)
252 #define P10_FAKEHOST TYPE(FAKEHOST)
253 #define P10_GET TYPE(GET)
254 #define P10_GLINE TYPE(GLINE)
255 #define P10_HASH TYPE(HASH)
256 #define P10_HELP TYPE(HELP)
257 #define P10_INFO TYPE(INFO)
258 #define P10_INVITE TYPE(INVITE)
259 #define P10_ISON TYPE(ISON)
260 #define P10_JOIN TYPE(JOIN)
261 #define P10_JUPE TYPE(JUPE)
262 #define P10_KICK TYPE(KICK)
263 #define P10_KILL TYPE(KILL)
264 #define P10_LINKS TYPE(LINKS)
265 #define P10_LIST TYPE(LIST)
266 #define P10_LUSERS TYPE(LUSERS)
267 #define P10_MAP TYPE(MAP)
268 #define P10_MARK TYPE(MARK)
269 #define P10_MODE TYPE(MODE)
270 #define P10_MOTD TYPE(MOTD)
271 #define P10_NAMES TYPE(NAMES)
272 #define P10_NICK TYPE(NICK)
273 #define P10_NOTICE TYPE(NOTICE)
274 #define P10_OPER TYPE(OPER)
275 #define P10_OPMODE TYPE(OPMODE)
276 #define P10_PART TYPE(PART)
277 #define P10_PASS CMD_PASS
278 #define P10_PING TYPE(PING)
279 #define P10_PONG TYPE(PONG)
280 #define P10_POST TYPE(POST)
281 #define P10_PRIVMSG TYPE(PRIVMSG)
282 #define P10_PRIVS TYPE(PRIVS)
283 #define P10_PROTO TYPE(PROTO)
284 #define P10_QUIT TYPE(QUIT)
285 #define P10_REHASH TYPE(REHASH)
286 #define P10_RESET TYPE(RESET)
287 #define P10_RESTART TYPE(RESTART)
288 #define P10_RPING TYPE(RPING)
289 #define P10_RPONG TYPE(RPONG)
290 #define P10_SERVER CMD_SERVER
291 #define P10_SERVLIST TYPE(SERVLIST)
292 #define P10_SERVSET TYPE(SERVSET)
293 #define P10_SET TYPE(SET)
294 #define P10_SETTIME TYPE(SETTIME)
295 #define P10_SGLINE TYPE(SGLINE)
296 #define P10_SHUN TYPE(SHUN)
297 #define P10_SILENCE TYPE(SILENCE)
298 #define P10_SMO TYPE(SMO)
299 #define P10_SNO TYPE(SNO)
300 #define P10_SSHUN TYPE(SSHUN)
301 #define P10_SPAMFILTER TYPE(SPAMFILTER)
302 #define P10_SQUERY TYPE(SQUERY)
303 #define P10_SQUIT TYPE(SQUIT)
304 #define P10_STATS TYPE(STATS)
305 #define P10_SVSJOIN TYPE(SVSJOIN)
306 #define P10_SVSNICK TYPE(SVSNICK)
307 #define P10_SVSPART TYPE(SVSPART)
308 #define P10_SVSQUIT TYPE(SVSQUIT)
309 #define P10_SWHOIS TYPE(SWHOIS)
310 #define P10_TIME TYPE(TIME)
311 #define P10_TOPIC TYPE(TOPIC)
312 #define P10_TRACE TYPE(TRACE)
313 #define P10_UPING TYPE(UPING)
314 #define P10_USER TYPE(USER)
315 #define P10_USERHOST TYPE(USERHOST)
316 #define P10_USERIP TYPE(USERIP)
317 #define P10_VERSION TYPE(VERSION)
318 #define P10_WALLCHOPS TYPE(WALLCHOPS)
319 #define P10_WALLOPS TYPE(WALLOPS)
320 #define P10_WALLHOPS TYPE(WALLHOPS)
321 #define P10_WALLUSERS TYPE(WALLUSERS)
322 #define P10_WALLVOICES TYPE(WALLVOICES)
323 #define P10_WHO TYPE(WHO)
324 #define P10_WHOIS TYPE(WHOIS)
325 #define P10_WHOWAS TYPE(WHOWAS)
326 #define P10_EXEMPT TYPE(EXEMPT)
328 /* Servers claiming to have a boot or link time before PREHISTORY
329 * trigger errors to the log. We hope no server has been running
330 * constantly since September 1994. :)
332 #define PREHISTORY 780000000
334 #define MODELEN 40 + KEYLEN
336 static struct server
* servers_num
[ 64 * 64 ];
337 static privmsg_func_t
* privmsg_funcs
;
338 static unsigned int num_privmsg_funcs
;
339 static privmsg_func_t
* notice_funcs
;
340 static unsigned int num_notice_funcs
;
341 static struct dict
* unbursted_channels
;
342 static const char * his_servername
;
343 static const char * his_servercomment
;
344 static int extended_accounts
;
346 /* These correspond to 1 << X: 012345678901234567 */
347 const char irc_user_mode_chars
[] = "o iw dkgn I" ;
349 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
);
351 extern int off_channel
;
352 extern int DefConLevel
;
353 extern int DefConTimeOut
;
354 extern char * DefConChanModes
;
356 static int parse_oplevel ( char * str
);
358 char privbuf
[ 512 ] = "" ;
360 /* Numerics can be XYY, XYYY, or XXYYY; with X's identifying the
361 * server and Y's indentifying the client on that server. */
363 GetServerN ( const char * numeric
)
365 switch ( strlen ( numeric
)) {
367 return servers_num
[ base64toint ( numeric
, 2 )];
371 return servers_num
[ base64toint ( numeric
, 1 )];
378 GetUserN ( const char * numeric
) /* using numeric */
384 switch ( strlen ( numeric
)) {
386 log_module ( MAIN_LOG
, LOG_WARNING
, "GetUserN( %s ): numeric too long!" , numeric
);
388 case 5 : slen
= 2 ; ulen
= 3 ; break ;
389 case 4 : slen
= 1 ; ulen
= 3 ; break ;
390 case 3 : slen
= 1 ; ulen
= 2 ; break ;
391 case 2 : case 1 : case 0 :
392 log_module ( MAIN_LOG
, LOG_WARNING
, "GetUserN( %s ): numeric too short!" , numeric
);
395 if (!( s
= servers_num
[ base64toint ( numeric
, slen
)])) {
396 log_module ( MAIN_LOG
, LOG_WARNING
, "GetUserN( %s ): couldn't find server (len= %d )!" , numeric
, slen
);
399 n
= base64toint ( numeric
+ slen
, ulen
) & s
-> num_mask
;
400 if (!( un
= s
-> users
[ n
])) {
401 log_module ( MAIN_LOG
, LOG_WARNING
, "GetUserN( %s ) couldn't find user!" , numeric
);
406 extern struct userNode
* opserv
;
408 check_ctcp ( struct userNode
* user
, struct userNode
* bot
, char * text
, UNUSED_ARG ( int server_qualified
))
411 /* if its a version reply, do an alert check (only alerts with version=something) */
413 if ( text
[ 0 ] == ' \001 ' ) {
415 cmd
= mysep (& text
, " " );
416 if (! irccasecmp ( cmd
, "VERSION" )) {
417 char * version
= mysep (& text
, " \n " );
420 /* opserv_debug("Opserv got CTCP VERSION Notice from %s: %s", user->nick, version); */
421 /* TODO: setup a ctcp_funcs thing to handle this and other CTCPS properly */
422 user
-> version_reply
= strdup ( version
);
423 /* TODO: put this in the db */
424 if ( match_ircglob ( version
, "WebTV;*" ))
425 user
-> no_notice
= true ; /* webbies cant see notices */
433 privmsg_user_helper ( struct userNode
* un
, void * data
)
435 struct privmsg_desc
* pd
= data
;
436 unsigned int num
= un
-> num_local
;
437 if (! pd
-> is_notice
) {
438 if (( num
< num_privmsg_funcs
) && privmsg_funcs
[ num
]) {
439 privmsg_funcs
[ num
]( pd
-> user
, un
, pd
-> text
, pd
-> is_qualified
);
442 if (( num
< num_notice_funcs
) && notice_funcs
[ num
]) {
443 check_ctcp ( pd
-> user
, un
, pd
-> text
, pd
-> is_qualified
);
444 notice_funcs
[ num
]( pd
-> user
, un
, pd
-> text
, pd
-> is_qualified
);
449 /* equiv to user doing /connect server port target */
450 void irc_connect ( struct userNode
* user
, char * server
, unsigned int port
, struct server
* target
)
452 putsock ( " %s " P10_CONNECT
" %s %d %s " , user
-> numeric
, server
, port
, target
-> numeric
);
456 irc_squit_route ( struct server
* srv
, const char * message
, ...)
460 va_start ( arg_list
, message
);
461 vsnprintf ( buffer
, MAXLEN
- 2 , message
, arg_list
);
462 buffer
[ MAXLEN
- 1 ] = 0 ;
464 /* When would we squit ourselves exactly?? -Rubin */
465 if ( srv
== self
&& cManager
. uplink
-> state
== CONNECTED
) {
468 /* Quit all clients linked to me. */
469 for ( i
= 0 ; i
<= self
-> num_mask
; i
++) {
472 irc_quit ( self
-> users
[ i
], buffer
);
476 putsock ( " %s " P10_SQUIT
" %s %d : %s " , self
-> numeric
, srv
-> name
, 0 , buffer
);
479 /* Force a reconnect to the currently selected server. */
480 cManager
. uplink
-> tries
= 0 ;
481 log_module ( MAIN_LOG
, LOG_INFO
, "Squitting from uplink: %s " , buffer
);
487 irc_server ( struct server
* srv
)
489 char extranum
[ COMBO_NUMERIC_LEN
+ 1 ];
491 inttobase64 ( extranum
, srv
-> num_mask
, ( srv
-> numeric
[ 1 ] || ( srv
-> num_mask
>= 64 * 64 )) ? 3 : 2 );
493 putsock ( P10_SERVER
" %s %d " FMT_TIME_T
" " FMT_TIME_T
" J10 %s%s +s6 : %s " ,
494 srv
-> name
, srv
-> hops
+ 1 , srv
-> boot
, srv
-> link_time
, srv
-> numeric
, extranum
, srv
-> description
);
496 putsock ( " %s " P10_SERVER
" %s %d " FMT_TIME_T
" " FMT_TIME_T
" %c 10 %s%s +s6 : %s " ,
497 self
-> numeric
, srv
-> name
, srv
-> hops
+ 1 , srv
-> boot
, srv
-> link_time
, ( srv
-> self_burst
? 'J' : 'P' ), srv
-> numeric
, extranum
, srv
-> description
);
502 irc_p10_pton ( irc_in_addr_t
* ip
, const char * input
)
504 if ( strlen ( input
) == 6 ) {
506 memset ( ip
, 0 , 6 * sizeof ( ip
-> in6
[ 0 ]));
507 value
= base64toint ( input
, 6 );
509 ip
-> in6
[ 5 ] = htons ( 65535 );
510 ip
-> in6
[ 6 ] = htons ( value
>> 16 );
511 ip
-> in6
[ 7 ] = htons ( value
& 65535 );
513 unsigned int pos
= 0 ;
517 for ( left
= ( 25 - strlen ( input
)) / 3 ; left
; left
--)
521 ip
-> in6
[ pos
++] = ntohs ( base64toint ( input
, 3 ));
529 irc_p10_ntop ( char * output
, const irc_in_addr_t
* ip
)
531 if (! irc_in_addr_is_valid (* ip
)) {
532 strcpy ( output
, "AAAAAA" );
533 } else if ( irc_in_addr_is_ipv4 (* ip
)) {
535 in4
= ( ntohs ( ip
-> in6
[ 6 ]) << 16 ) | ntohs ( ip
-> in6
[ 7 ]);
536 inttobase64 ( output
, in4
, 6 );
538 } else if ( irc_in_addr_is_ipv6 (* ip
)) {
539 unsigned int max_start
, max_zeros
, curr_zeros
, zero
, ii
;
540 /* Can start by printing out the leading non-zero parts. */
541 for ( ii
= 0 ; ( ip
-> in6
[ ii
]) && ( ii
< 8 ); ++ ii
) {
542 inttobase64 ( output
, ntohs ( ip
-> in6
[ ii
]), 3 );
545 /* Find the longest run of zeros. */
546 for ( max_start
= zero
= ii
, max_zeros
= curr_zeros
= 0 ; ii
< 8 ; ++ ii
) {
549 else if ( curr_zeros
> max_zeros
) {
550 max_start
= ii
- curr_zeros
;
551 max_zeros
= curr_zeros
;
555 if ( curr_zeros
> max_zeros
) {
556 max_start
= ii
- curr_zeros
;
557 max_zeros
= curr_zeros
;
560 /* Print the rest of the address */
561 for ( ii
= zero
; ii
< 8 ; ) {
562 if (( ii
== max_start
) && max_zeros
) {
566 inttobase64 ( output
, ntohs ( ip
-> in6
[ ii
]), 3 );
572 strcpy ( output
, "???" );
577 irc_user ( struct userNode
* user
)
580 if (! user
|| IsDummy ( user
))
582 irc_p10_ntop ( b64ip
, & user
-> ip
);
586 irc_user_modes ( user
, modes
, sizeof ( modes
));
587 /* we don't need to put the + in modes because it's in the format string. */
588 putsock ( " %s " P10_NICK
" %s %d " FMT_TIME_T
" %s %s + %s %s %s : %s " ,
589 user
-> uplink
-> numeric
, user
-> nick
, user
-> uplink
-> hops
+ 1 , user
-> timestamp
, user
-> ident
, user
-> hostname
, modes
, b64ip
, user
-> numeric
, user
-> info
);
591 putsock ( " %s " P10_NICK
" %s %d " FMT_TIME_T
" %s %s %s %s : %s " ,
592 user
-> uplink
-> numeric
, user
-> nick
, user
-> uplink
-> hops
+ 1 , user
-> timestamp
, user
-> ident
, user
-> hostname
, b64ip
, user
-> numeric
, user
-> info
);
597 irc_rename ( struct userNode
* user
, const char * new_handle
)
599 if ( extended_accounts
)
600 putsock ( " %s " P10_ACCOUNT
" %s M %s " , self
-> numeric
, user
-> numeric
, new_handle
);
604 irc_delete ( struct userNode
* user
)
606 if ( extended_accounts
)
607 putsock ( " %s " P10_ACCOUNT
" %s U" , self
-> numeric
, user
-> numeric
);
611 irc_account ( struct userNode
* user
, const char * stamp
, time_t timestamp
)
613 if ( extended_accounts
)
614 putsock ( " %s " P10_ACCOUNT
" %s R %s " FMT_TIME_T
, self
-> numeric
, user
-> numeric
, stamp
, timestamp
);
616 putsock ( " %s " P10_ACCOUNT
" %s %s " FMT_TIME_T
, self
-> numeric
, user
-> numeric
, stamp
, timestamp
);
620 irc_fakehost ( struct userNode
* user
, const char * host
)
622 putsock ( " %s " P10_FAKEHOST
" %s %s " , self
-> numeric
, user
-> numeric
, host
);
626 irc_regnick ( UNUSED_ARG ( struct userNode
* user
))
628 /* no operation here */
632 irc_nick ( struct userNode
* user
, UNUSED_ARG ( const char * old_nick
))
634 putsock ( " %s " P10_NICK
" %s " FMT_TIME_T
, user
-> numeric
, user
-> nick
, now
);
638 irc_fetchtopic ( struct userNode
* from
, const char * to
)
642 putsock ( " %s " P10_TOPIC
" %s " , from
-> numeric
, to
);
646 irc_squit ( struct server
* srv
, const char * message
, const char * service_message
)
648 if (! service_message
)
649 service_message
= message
;
651 /* Are we leaving the network? */
652 if ( srv
== self
&& cManager
. uplink
-> state
== CONNECTED
) {
655 /* Quit all clients linked to me. */
656 for ( i
= 0 ; i
<= self
-> num_mask
; i
++) {
659 irc_quit ( self
-> users
[ i
], service_message
);
663 putsock ( " %s " P10_SQUIT
" %s %d : %s " , self
-> numeric
, srv
-> name
, 0 , message
);
666 /* Force a reconnect to the currently selected server. */
667 cManager
. uplink
-> tries
= 0 ;
668 log_module ( MAIN_LOG
, LOG_INFO
, "Squitting from uplink: %s " , message
);
674 irc_wallchops ( struct userNode
* from
, const char * to
, const char * message
)
676 putsock ( " %s " P10_WALLCHOPS
" %s : %s " , from
-> numeric
, to
, message
);
680 irc_wallops ( const char * format
, ...)
684 va_start ( arg_list
, format
);
685 vsnprintf ( buffer
, MAXLEN
- 2 , format
, arg_list
);
686 buffer
[ MAXLEN
- 1 ] = 0 ;
687 putsock ( " %s " P10_WALLOPS
" : %s " , self
-> numeric
, buffer
);
691 deliver_to_dummy ( struct userNode
* source
, struct userNode
* dest
, const char * message
, int type
)
695 if (! dest
|| ! IsDummy ( dest
) || ! IsLocal ( dest
))
697 num
= dest
-> num_local
;
700 if (( num
< num_notice_funcs
) && notice_funcs
[ num
])
701 notice_funcs
[ num
]( source
, dest
, message
, 0 );
704 if (( num
< num_privmsg_funcs
) && privmsg_funcs
[ num
])
705 privmsg_funcs
[ num
]( source
, dest
, message
, 0 );
712 irc_notice ( struct userNode
* from
, const char * to
, const char * message
)
714 if ( to
[ 0 ] == '#' || to
[ 0 ] == '$'
715 || ! deliver_to_dummy ( from
, GetUserN ( to
), message
, 0 ))
716 putsock ( " %s " P10_NOTICE
" %s : %s " , from
-> numeric
, to
, message
);
720 irc_notice_user ( struct userNode
* from
, struct userNode
* to
, const char * message
)
722 if (! deliver_to_dummy ( from
, to
, message
, 0 ))
723 putsock ( " %s " P10_NOTICE
" %s : %s " , from
-> numeric
, to
-> numeric
, message
);
727 irc_privmsg ( struct userNode
* from
, const char * to
, const char * message
)
729 if ( to
[ 0 ] == '#' || to
[ 0 ] == '$'
730 || ! deliver_to_dummy ( from
, GetUserN ( to
), message
, 1 ))
731 putsock ( " %s " P10_PRIVMSG
" %s : %s " , from
-> numeric
, to
, message
);
735 irc_privmsg_user ( struct userNode
* from
, struct userNode
* to
, const char * message
)
737 putsock ( " %s " P10_PRIVMSG
" %s : %s " , from
-> numeric
, to
-> numeric
, message
);
741 irc_version_user ( struct userNode
* from
, struct userNode
* to
)
743 irc_privmsg_user ( from
, to
, " \001 VERSION \001 " );
749 putsock ( " %s " P10_EOB
, self
-> numeric
);
755 putsock ( " %s " P10_EOB_ACK
, self
-> numeric
);
759 str
= conf_get_data ( "services/opserv/nick" , RECDB_QSTRING
);
762 if ( nick
&& ( DefConLevel
< 5 )) {
763 DefConProcess ( GetUserH ( nick
));
765 if ( DefConTimeOut
> 0 )
766 timeq_add ( now
+ DefConTimeOut
, defcon_timeout
, NULL
);
771 irc_rpong ( const char * from1
, const char * from2
, const char * pingtime
, const char * clientinfo
)
773 putsock ( " %s " P10_RPONG
" %s %s %s : %s " , self
-> numeric
, from1
, from2
, pingtime
, clientinfo
);
777 irc_ping ( const char * payload
)
779 putsock ( " %s " P10_PING
" : %s " , self
-> numeric
, payload
);
783 irc_pong ( const char * who
, const char * data
)
785 putsock ( " %s " P10_PONG
" %s : %s " , self
-> numeric
, who
, data
);
789 irc_pong_asll ( const char * who
, const char * orig_ts
)
793 struct timeval sys_now
;
796 orig
. tv_sec
= strtoul ( orig_ts
, & delim
, 10 );
797 orig
. tv_usec
= (* delim
== '.' ) ? strtoul ( delim
+ 1 , NULL
, 10 ) : 0 ;
798 gettimeofday (& sys_now
, NULL
);
799 diff
= ( sys_now
. tv_sec
- orig
. tv_sec
) * 1000 + ( sys_now
. tv_usec
- orig
. tv_usec
) / 1000 ;
800 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
);
804 irc_pass ( const char * passwd
)
806 putsock ( P10_PASS
" : %s " , passwd
);
810 irc_introduce ( const char * passwd
)
812 void timed_send_ping ( void * data
);
814 self
-> self_burst
= self
-> burst
= 1 ;
818 timeq_add ( now
+ ping_freq
, timed_send_ping
, 0 );
822 irc_gline ( struct server
* srv
, struct gline
* gline
, int silent
)
824 putsock ( " %s " P10_GLINE
" %s + %s " FMT_TIME_T
" " FMT_TIME_T
" : %s < %s > %s " ,
825 self
-> numeric
, ( srv
? srv
-> numeric
: "*" ), gline
-> target
, gline
-> expires
- now
, now
, silent
? "AUTO " : "" , gline
-> issuer
, gline
-> reason
);
829 irc_shun ( struct server
* srv
, struct shun
* shun
)
831 putsock ( " %s " P10_SHUN
" %s + %s " FMT_TIME_T
" :< %s > %s " ,
832 self
-> numeric
, ( srv
? srv
-> numeric
: "*" ), shun
-> target
, shun
-> expires
- now
, shun
-> issuer
, shun
-> reason
);
836 irc_settime ( const char * srv_name_mask
, time_t new_time
)
838 ioset_set_time ( new_time
);
839 if (! strcmp ( srv_name_mask
, "*" ))
841 putsock ( " %s " P10_SETTIME
" " FMT_TIME_T
" %s " , self
-> numeric
, new_time
, srv_name_mask
);
845 irc_ungline ( const char * mask
)
847 putsock ( " %s " P10_GLINE
" * - %s " , self
-> numeric
, mask
);
851 irc_unshun ( const char * mask
)
853 putsock ( " %s " P10_SHUN
" * - %s " , self
-> numeric
, mask
);
857 irc_burst ( struct chanNode
* chan
)
859 char burst_line
[ 512 ];
860 int pos
, base_len
, len
;
863 struct exemptNode
* en
;
865 unsigned int first_ban
;
866 unsigned int first_exempt
;
869 base_len
= sprintf ( burst_line
, " %s " P10_BURST
" %s " FMT_TIME_T
" " ,
870 self
-> numeric
, chan
-> name
, chan
-> timestamp
);
871 len
= irc_make_chanmode ( chan
, burst_line
+ base_len
);
872 pos
= base_len
+ len
;
873 if ( len
> 0 && chan
-> members
. used
> 0 )
874 burst_line
[ pos
++] = ' ' ;
876 if ( chan
-> members
. used
< 1 )
877 return ; /* dont burst empty channels (created by discrims) */
879 for ( n
= 0 ; n
< chan
-> members
. used
; n
++) {
880 mn
= chan
-> members
. list
[ n
];
882 burst_line
[ pos
- 1 ] = 0 ; /* -1 to back up over the space or comma */
883 putsock ( " %s " , burst_line
);
888 memcpy ( burst_line
+ pos
, mn
-> user
-> numeric
, strlen ( mn
-> user
-> numeric
));
889 pos
+= strlen ( mn
-> user
-> numeric
);
890 if ( mn
-> modes
&& ( mn
-> modes
!= last_mode
)) {
891 last_mode
= mn
-> modes
;
892 burst_line
[ pos
++] = ':' ;
893 if ( last_mode
& MODE_CHANOP
)
894 burst_line
[ pos
++] = 'o' ;
895 if ( last_mode
& MODE_HALFOP
)
896 burst_line
[ pos
++] = 'h' ;
897 if ( last_mode
& MODE_VOICE
)
898 burst_line
[ pos
++] = 'v' ;
900 if (( n
+ 1 )< chan
-> members
. used
)
901 burst_line
[ pos
++] = ',' ;
903 if ( chan
-> banlist
. used
) {
907 for ( n
= 0 ; n
< chan
-> banlist
. used
; ) {
908 if ( first_ban
&& ( pos
< 500 )) {
909 burst_line
[ pos
++] = ':' ;
910 burst_line
[ pos
++] = '%' ;
912 bn
= chan
-> banlist
. list
[ n
];
913 len
= strlen ( bn
-> ban
);
914 if ( pos
+ 2 + len
< 505 ) {
915 memcpy ( burst_line
+ pos
, bn
-> ban
, len
);
917 burst_line
[ pos
++] = ' ' ;
921 burst_line
[ pos
- 1 ] = 0 ;
922 putsock ( " %s " , burst_line
);
928 if ( chan
-> exemptlist
. used
) {
929 /* dump the exempts */
932 for ( n
= 0 ; n
< chan
-> exemptlist
. used
; ) {
933 if ( first_exempt
&& ( pos
< 500 )) {
934 burst_line
[ pos
++] = ' ' ;
935 burst_line
[ pos
++] = '~' ;
936 burst_line
[ pos
++] = ' ' ;
938 en
= chan
-> exemptlist
. list
[ n
];
939 len
= strlen ( en
-> exempt
);
940 if ( pos
+ 2 + len
< 505 ) {
941 memcpy ( burst_line
+ pos
, en
-> exempt
, len
);
943 burst_line
[ pos
++] = ' ' ;
947 burst_line
[ pos
- 1 ] = 0 ;
948 putsock ( " %s " , burst_line
);
954 /* print the last line */
956 putsock ( " %s " , burst_line
);
960 irc_quit ( struct userNode
* user
, const char * message
)
962 putsock ( " %s " P10_QUIT
" : %s " , user
-> numeric
, message
);
966 irc_error ( const char * to
, const char * message
)
969 putsock ( " %s " P10_ERROR
" : %s " , to
, message
);
971 putsock ( ": %s " P10_ERROR
" : %s " , self
-> name
, message
);
976 irc_kill ( struct userNode
* from
, struct userNode
* target
, const char * message
)
979 putsock ( " %s " P10_KILL
" %s : %s ! %s ( %s )" ,
980 from
-> numeric
, target
-> numeric
, self
-> name
, from
-> nick
, message
);
982 putsock ( " %s " P10_KILL
" %s : %s ( %s )" ,
983 self
-> numeric
, target
-> numeric
, self
-> name
, message
);
988 irc_mode ( struct userNode
* from
, struct chanNode
* target
, const char * modes
)
990 call_channel_mode_funcs ( from
, target
, ( char **)& modes
, 0 );
991 putsock ( " %s " P10_MODE
" %s %s " FMT_TIME_T
,
992 ( from
? from
-> numeric
: self
-> numeric
),
993 target
-> name
, modes
, target
-> timestamp
);
996 /* Added to allow services to mode users
997 2005 - 8 - 10 by Life4Christ
1000 irc_umode ( struct userNode
* target
, const char * modes
)
1002 putsock ( " %s " P10_MODE
" %s %s " , self
-> numeric
, target
-> nick
, modes
);
1007 irc_invite ( struct userNode
* from
, struct userNode
* who
, struct chanNode
* to
)
1009 putsock ( " %s " P10_INVITE
" %s %s " , from
-> numeric
, who
-> nick
, to
-> name
);
1013 irc_silence ( struct userNode
* who
, const char * mask
, int add
)
1015 putsock ( " %s " P10_SILENCE
" %s %s%s " , self
-> numeric
, who
-> numeric
, add
? "+" : "-" , mask
);
1019 irc_join ( struct userNode
* who
, struct chanNode
* what
)
1021 if ( what
-> members
. used
== 1 ) {
1022 putsock ( " %s " P10_CREATE
" %s " FMT_TIME_T
,
1023 who
-> numeric
, what
-> name
, what
-> timestamp
);
1025 putsock ( " %s " P10_JOIN
" %s " FMT_TIME_T
, who
-> numeric
, what
-> name
, what
-> timestamp
);
1030 irc_svsjoin ( struct userNode
* from
, struct userNode
* who
, struct chanNode
* to
)
1032 putsock ( " %s " P10_SVSJOIN
" %s %s " FMT_TIME_T
, from
-> uplink
-> numeric
, who
-> numeric
, to
-> name
, now
);
1036 irc_svspart ( struct userNode
* from
, struct userNode
* who
, struct chanNode
* to
)
1038 putsock ( " %s " P10_SVSPART
" %s %s " , from
-> uplink
-> numeric
, who
-> numeric
, to
-> name
);
1042 irc_svsquit ( struct userNode
* from
, struct userNode
* who
, char const * reason
)
1044 putsock ( " %s " P10_SVSQUIT
" %s : %s " , from
-> uplink
-> numeric
, who
-> numeric
, reason
);
1048 irc_kick ( struct userNode
* who
, struct userNode
* target
, struct chanNode
* channel
, const char * msg
)
1050 const char * numeric
;
1051 struct modeNode
* mn
= GetUserMode ( channel
, who
);
1052 numeric
= (( mn
&& ( mn
-> modes
& MODE_CHANOP
)) || off_channel
) ? who
-> numeric
: self
-> numeric
;
1053 putsock ( " %s " P10_KICK
" %s %s : %s " ,
1054 numeric
, channel
-> name
, target
-> numeric
, msg
);
1058 irc_stats ( struct userNode
* from
, struct server
* target
, char type
)
1060 putsock ( " %s " P10_STATS
" %c : %s " , from
-> numeric
, type
, target
-> numeric
);
1064 irc_svsnick ( struct userNode
* from
, struct userNode
* target
, const char * newnick
)
1066 putsock ( " %s " P10_SVSNICK
" %s %s " FMT_TIME_T
, from
-> uplink
-> numeric
, target
-> numeric
, newnick
, now
);
1070 irc_swhois ( struct userNode
* from
, struct userNode
* target
, const char * message
)
1072 putsock ( " %s " P10_SWHOIS
" %s %s%s " , from
-> uplink
-> numeric
, target
-> numeric
, message
? ":" : "" ,
1073 message
? message
: "" );
1078 irc_part ( struct userNode
* who
, struct chanNode
* what
, const char * reason
)
1081 putsock ( " %s " P10_PART
" %s : %s " , who
-> numeric
, what
-> name
, reason
);
1083 putsock ( " %s " P10_PART
" %s " , who
-> numeric
, what
-> name
);
1088 irc_topic ( struct userNode
* service
, struct userNode
* who
, struct chanNode
* what
, const char * topic
)
1091 int type
= 4 , host_in_topic
= 0 , hasident
= 0 ;
1092 const char * hstr
, * tstr
;
1093 char * host
, * hostmask
;
1095 char sident
[ MAXLEN
];
1097 tstr
= conf_get_data ( "server/type" , RECDB_QSTRING
);
1098 hstr
= conf_get_data ( "server/host_in_topic" , RECDB_QSTRING
);
1102 type
= 4 ; /* default to 040 style topics */
1105 if ( IsFakeHost ( who
))
1106 safestrncpy ( shost
, who
-> fakehost
, sizeof ( shost
));
1107 else if ( IsSetHost ( who
)) {
1108 hostmask
= strdup ( who
-> sethost
);
1109 if (( host
= ( strrchr ( hostmask
, '@' )))) {
1116 safestrncpy ( sident
, hostmask
, sizeof ( shost
));
1118 safestrncpy ( sident
, who
-> ident
, sizeof ( shost
));
1120 safestrncpy ( shost
, host
, sizeof ( shost
));
1122 safestrncpy ( shost
, who
-> hostname
, sizeof ( shost
));
1124 host_in_topic
= atoi ( hstr
);
1128 putsock ( " %s " P10_TOPIC
" %s %s%s%s%s%s " FMT_TIME_T
" " FMT_TIME_T
" : %s " , service
-> numeric
, what
-> name
,
1129 who
-> nick
, host_in_topic
? "!" : "" , host_in_topic
? ( IsSetHost ( who
) ? sident
: who
-> ident
) : "" ,
1130 host_in_topic
? "@" : "" , host_in_topic
? shost
: "" , what
-> timestamp
, now
, topic
);
1133 putsock ( " %s " P10_TOPIC
" %s : %s " , who
-> numeric
, what
-> name
, topic
);
1138 irc_raw ( const char * what
)
1140 putsock ( " %s " , what
);
1144 irc_numeric ( struct userNode
* user
, unsigned int num
, const char * format
, ...)
1147 char buffer
[ MAXLEN
];
1148 va_start ( arg_list
, format
);
1149 vsnprintf ( buffer
, MAXLEN
- 2 , format
, arg_list
);
1150 buffer
[ MAXLEN
- 1 ] = 0 ;
1151 putsock ( ": %s %0 3d %s %s " , self
-> name
, num
, user
-> nick
, buffer
);
1155 irc_mark ( struct userNode
* user
, char * mark
)
1157 char * host
= user
-> hostname
;
1159 /* 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 */
1163 /* if the mark will put us over the host length, clip some off the left hand side
1166 if ( strlen ( host
) + 1 + strlen ( mark
) > HOSTLEN
)
1167 host
+= 1 + ( ( strlen ( host
) + 1 + strlen ( mark
)) - HOSTLEN
);
1168 putsock ( " %s " CMD_MARK
" %s DNSBL +m %s . %s " , self
-> numeric
, user
-> nick
, mark
, host
);
1169 putsock ( " %s " CMD_MARK
" %s DNSBL_DATA %s " , self
-> numeric
, user
-> nick
, mark
);
1171 /* Save it in the user */
1172 user
-> mark
= strdup ( mark
);
1174 /* If they are not otherwise marked, mark their host with fakehost */
1175 if (! IsFakeHost ( user
) && ! IsSetHost ( user
) && !( IsHiddenHost ( user
) && user
-> handle_info
) )
1177 struct modeNode
* mn
= NULL
;
1178 char fakehost
[ HOSTLEN
];
1179 unsigned int count
= 0 ;
1182 putsock ( " %s " CMD_FAKEHOST
" %s %s . %s " , self
-> numeric
, user
-> numeric
, mark
, host
);
1183 putsock ( " %s " CMD_MODE
" %s +x" , self
-> numeric
, user
-> nick
);
1185 snprintf ( fakehost
, sizeof ( fakehost
), " %s . %s " , mark
, host
);
1186 safestrncpy ( user
-> fakehost
, fakehost
, sizeof ( user
-> fakehost
));
1188 for ( n
= count
= 0 ; n
< user
-> channels
. used
; n
++) {
1189 mn
= user
-> channels
. list
[ n
];
1190 if ( strlen ( mn
-> channel
-> name
) >= 1 ) /* Sanity */
1191 check_bans ( user
, mn
-> channel
-> name
);
1196 void irc_sno ( unsigned int mask
, char const * format
, ...) {
1198 char buffer
[ MAXLEN
];
1199 va_start ( arg_list
, format
);
1200 vsnprintf ( buffer
, MAXLEN
- 2 , format
, arg_list
);
1201 buffer
[ MAXLEN
- 1 ] = 0 ;
1202 putsock ( " %s " CMD_SNO
" %d : %s " , self
-> numeric
, mask
, buffer
);
1205 static void send_burst ( void );
1208 change_nicklen ( int new_nicklen
)
1211 char new_nick
[ NICKLEN
+ 1 ];
1212 struct userNode
* user
;
1214 nicklen
= new_nicklen
;
1215 /* fix up any users we have here */
1216 for ( nn
= 0 ; nn
<= self
-> num_mask
; nn
++) {
1217 if (!( user
= self
-> users
[ nn
]))
1219 safestrncpy ( new_nick
, user
-> nick
, sizeof ( new_nick
));
1220 new_nick
[ nicklen
] = 0 ;
1221 NickChange ( user
, new_nick
, 1 );
1225 static CMD_FUNC ( cmd_whois
)
1227 struct userNode
* from
;
1228 struct userNode
* who
;
1230 unsigned int i
, mlen
, len
;
1234 if (!( from
= GetUserH ( origin
))) {
1235 log_module ( MAIN_LOG
, LOG_ERROR
, "Could not find WHOIS origin user %s " , origin
);
1238 if (!( who
= GetUserH ( argv
[ 2 ]))) {
1239 irc_numeric ( from
, ERR_NOSUCHNICK
, " %s @ %s :No such nick" , argv
[ 2 ], self
-> name
);
1243 if ( IsFakeHost ( who
) && IsHiddenHost ( who
))
1244 irc_numeric ( from
, RPL_WHOISUSER
, " %s %s %s * : %s " , who
-> nick
, who
-> ident
, who
-> fakehost
, who
-> info
);
1245 else if ( IsHiddenHost ( who
) && who
-> handle_info
&& hidden_host_suffix
)
1246 irc_numeric ( from
, RPL_WHOISUSER
, " %s %s %s . %s * : %s " , who
-> nick
, who
-> ident
, who
-> handle_info
-> handle
, hidden_host_suffix
, who
-> info
);
1248 irc_numeric ( from
, RPL_WHOISUSER
, " %s %s %s * : %s " , who
-> nick
, who
-> ident
, who
-> hostname
, who
-> info
);
1250 if ( IsService ( who
) || ( from
== who
)) {
1251 struct modeNode
* mn
;
1252 mlen
= strlen ( self
-> name
) + strlen ( from
-> nick
) + 12 + strlen ( who
-> nick
);
1255 for ( i
= who
-> channels
. used
; i
> 0 ; )
1257 mn
= who
-> channels
. list
[-- i
];
1259 if (! IsOper ( from
) && ( mn
-> channel
-> modes
& ( MODE_PRIVATE
| MODE_SECRET
)) && ! GetUserMode ( mn
-> channel
, from
))
1262 if ( len
+ strlen ( mn
-> channel
-> name
) + mlen
> MAXLEN
- 5 )
1264 irc_numeric ( from
, RPL_WHOISCHANNELS
, " %s : %s " , who
-> nick
, buf
);
1270 *( buf
+ len
++) = '-' ;
1271 if (( mn
-> channel
-> modes
& ( MODE_PRIVATE
| MODE_SECRET
)) && ! GetUserMode ( mn
-> channel
, from
))
1272 *( buf
+ len
++) = '*' ;
1273 if ( mn
-> modes
& MODE_CHANOP
)
1274 *( buf
+ len
++) = '@' ;
1275 else if ( mn
-> modes
& MODE_HALFOP
)
1276 *( buf
+ len
++) = '%' ;
1277 else if ( mn
-> modes
& MODE_VOICE
)
1278 *( buf
+ len
++) = '+' ;
1281 *( buf
+ len
) = '\0' ;
1282 strcpy ( buf
+ len
, mn
-> channel
-> name
);
1283 len
+= strlen ( mn
-> channel
-> name
);
1284 strcat ( buf
+ len
, " " );
1288 irc_numeric ( from
, RPL_WHOISCHANNELS
, " %s : %s " , who
-> nick
, buf
);
1291 if ( his_servername
&& his_servercomment
&& ! IsOper ( from
) && from
!= who
)
1292 irc_numeric ( from
, RPL_WHOISSERVER
, " %s %s : %s " , who
-> nick
, his_servername
, his_servercomment
);
1294 irc_numeric ( from
, RPL_WHOISSERVER
, " %s %s : %s " , who
-> nick
, who
-> uplink
-> name
, who
-> uplink
-> description
);
1297 irc_numeric ( from
, RPL_AWAY
, " %s :Away" , who
-> nick
);
1299 irc_numeric ( from
, RPL_WHOISOPERATOR
, " %s : %s " , who
-> nick
, IsLocal ( who
) ? "is a megalomaniacal power hungry tyrant" : "is an IRC Operator" );
1300 if ( who
-> handle_info
)
1301 irc_numeric ( from
, RPL_WHOISACCOUNT
, " %s %s :is logged in as" , who
-> nick
, who
-> handle_info
-> handle
);
1302 if ( IsHiddenHost ( who
) && who
-> handle_info
&& ( IsOper ( from
) || from
== who
))
1303 irc_numeric ( from
, RPL_WHOISACTUALLY
, " %s %s @ %s %s :Actual user@host, Actual IP" , who
-> nick
, who
-> ident
, who
-> hostname
, irc_ntoa (& who
-> ip
));
1304 if ( IsLocal ( who
) && ! IsService ( who
) && ( IsOper ( from
) || from
== who
))
1305 irc_numeric ( from
, RPL_WHOISIDLE
, " %s %l d %l d :seconds idle, signon time" , who
-> nick
, now
- who
-> idle_since
, who
-> timestamp
);
1307 irc_numeric ( from
, RPL_ENDOFWHOIS
, " %s :End of /WHOIS list" , who
-> nick
);
1311 static CMD_FUNC ( cmd_server
)
1319 /* another server introduced us */
1320 srv
= AddServer ( GetServerH ( origin
), argv
[ 1 ], atoi ( argv
[ 2 ]), atoi ( argv
[ 3 ]), atoi ( argv
[ 4 ]), argv
[ 6 ], argv
[ argc
- 1 ]);
1323 srv
-> self_burst
= argv
[ 5 ][ 0 ] == 'J' ;
1326 /* this must be our uplink */
1327 srv
= self
-> uplink
= AddServer ( self
, argv
[ 1 ], atoi ( argv
[ 2 ]), atoi ( argv
[ 3 ]), atoi ( argv
[ 4 ]), argv
[ 6 ], argv
[ argc
- 1 ]);
1330 srv
-> self_burst
= argv
[ 5 ][ 0 ] == 'J' ;
1332 if (( argv
[ 7 ][ 0 ] == '+' ) && ! force_n2k
) {
1333 log_module ( MAIN_LOG
, LOG_WARNING
, "Got Undernet-style SERVER message but \" force_n2k \" not on." );
1338 /* Fix up our timestamps if necessary. */
1339 if ( srv
-> boot
<= PREHISTORY
) {
1340 /* Server from the mists of time.. */
1341 if ( srv
-> hops
== 1 ) {
1342 log_module ( MAIN_LOG
, LOG_ERROR
, "Server %s claims to have booted at time " FMT_TIME_T
". This is absurd." , srv
-> name
, srv
-> boot
);
1344 } else if (( str
= conf_get_data ( "server/reliable_clock" , RECDB_QSTRING
))
1345 && enabled_string ( str
)) {
1346 /* If we have a reliable clock, we just keep our current time. */
1348 if ( srv
-> boot
<= self
-> boot
) {
1349 /* The other server is older than us. Accept their timestamp.
1350 * Alternately, we are same age, but we accept their time
1351 * since we are linking to them. */
1352 self
-> boot
= srv
-> boot
;
1353 ioset_set_time ( srv
-> link_time
1357 if ( srv
== self
-> uplink
) {
1358 extern time_t burst_begin
;
1365 static CMD_FUNC ( cmd_eob
)
1367 struct server
* sender
;
1371 if (!( sender
= GetServerH ( origin
)))
1373 if ( sender
== self
-> uplink
) {
1374 cManager
. uplink
-> state
= CONNECTED
;
1375 for ( it
= dict_first ( unbursted_channels
); it
; it
= iter_next ( it
))
1376 irc_burst ( iter_data ( it
));
1377 dict_delete ( unbursted_channels
);
1378 unbursted_channels
= NULL
;
1382 /* now that we know who our uplink is,
1383 * we can center the routing map and activate auto-routing.
1385 //activate_routing(NULL, NULL, NULL);
1388 sender
-> self_burst
= 0 ;
1389 recalc_bursts ( sender
);
1390 for ( ii
= 0 ; ii
< slf_used
; ii
++)
1391 slf_list
[ ii
]( sender
);
1392 /* let auto-routing figure out if we were
1393 * wating on this server to link a child to it */
1394 /* DONT call this if uplink is _US_ */
1395 if ( sender
-> uplink
!= self
)
1396 routing_handle_connect ( sender
-> name
, sender
-> uplink
-> name
);
1400 static CMD_FUNC ( cmd_eob_ack
)
1402 extern time_t burst_begin
;
1404 if ( GetServerH ( origin
) == self
-> uplink
) {
1405 burst_length
= now
- burst_begin
;
1406 self
-> self_burst
= self
-> burst
= 0 ;
1408 cManager
. uplink
-> state
= CONNECTED
;
1412 static CMD_FUNC ( cmd_rping
)
1414 struct server
* dest
;
1416 if (!( dest
= GetServerN ( argv
[ 1 ])))
1417 return 1 ; /* if its a jupe or something, return 1 so its silently ignored */
1420 irc_rpong ( argv
[ 2 ], argv
[ 3 ], argv
[ 4 ], argv
[ 5 ]);
1425 static CMD_FUNC ( cmd_ping
)
1428 struct userNode
* un
;
1431 irc_pong_asll ( argv
[ 2 ], argv
[ 3 ]);
1432 else if (( srv
= GetServerH ( origin
)))
1433 irc_pong ( self
-> name
, srv
-> numeric
);
1434 else if (( un
= GetUserH ( origin
)))
1435 irc_pong ( self
-> name
, un
-> numeric
);
1437 irc_pong ( self
-> name
, origin
);
1439 timeq_del ( 0 , timed_send_ping
, 0 , TIMEQ_IGNORE_WHEN
| TIMEQ_IGNORE_DATA
);
1440 timeq_del ( 0 , timed_ping_timeout
, 0 , TIMEQ_IGNORE_WHEN
| TIMEQ_IGNORE_DATA
);
1441 timeq_add ( now
+ ping_freq
, timed_send_ping
, 0 );
1446 static CMD_FUNC ( cmd_error_nick
)
1448 /* Go back to original IRC length .. and try to reconnect :/ */
1450 irc_squit ( self
, "Got erroneous nickname, truncating nicks." , NULL
);
1454 struct create_desc
{
1455 struct userNode
* user
;
1460 join_helper ( struct chanNode
* chan
, void * data
)
1462 struct create_desc
* cd
= data
;
1463 AddChannelUser ( cd
-> user
, chan
);
1467 create_helper ( char * name
, void * data
)
1469 struct create_desc
* cd
= data
;
1471 if (! strcmp ( name
, "0" )) {
1472 while ( cd
-> user
-> channels
. used
> 0 )
1473 DelChannelUser ( cd
-> user
, cd
-> user
-> channels
. list
[ 0 ]-> channel
, 0 , 0 );
1477 AddChannelUser ( cd
-> user
, AddChannel ( name
, cd
-> when
, NULL
, NULL
, NULL
));
1480 static CMD_FUNC ( cmd_create
)
1482 struct create_desc cd
;
1483 struct userNode
* user
;
1485 if (( argc
< 3 ) || !( user
= GetUserH ( origin
)))
1488 cd
. when
= atoi ( argv
[ 2 ]);
1489 parse_foreach ( argv
[ 1 ], join_helper
, create_helper
, NULL
, NULL
, & cd
);
1493 static CMD_FUNC ( cmd_join
)
1495 struct create_desc cd
;
1497 if (!( cd
. user
= GetUserH ( origin
)))
1504 cd
. when
= atoi ( argv
[ 2 ]);
1505 parse_foreach ( argv
[ 1 ], join_helper
, create_helper
, NULL
, NULL
, & cd
);
1509 static CMD_FUNC ( cmd_svsjoin
)
1511 struct create_desc cd
;
1513 if (!( cd
. user
= GetUserH ( argv
[ 1 ])))
1520 cd
. when
= atoi ( argv
[ 3 ]);
1521 parse_foreach ( argv
[ 2 ], join_helper
, create_helper
, NULL
, NULL
, & cd
);
1525 static CMD_FUNC ( cmd_pong
)
1529 if (! strcmp ( argv
[ 2 ], self
-> name
)) {
1530 timeq_del ( 0 , timed_send_ping
, 0 , TIMEQ_IGNORE_WHEN
| TIMEQ_IGNORE_DATA
);
1531 timeq_del ( 0 , timed_ping_timeout
, 0 , TIMEQ_IGNORE_WHEN
| TIMEQ_IGNORE_DATA
);
1532 timeq_add ( now
+ ping_freq
, timed_send_ping
, 0 );
1538 static CMD_FUNC ( cmd_nick
)
1540 struct userNode
* user
;
1541 if (( user
= GetUserH ( origin
))) {
1542 /* nick change (since the source is a user numeric) */
1545 NickChange ( user
, argv
[ 1 ], 1 );
1547 struct server
* serv
;
1548 struct userNode
* nuser
;
1553 serv
= GetServerH ( origin
);
1555 unsplit_string ( argv
+ 6 , argc
- 9 , modes
);
1558 nuser
= AddUser ( serv
, argv
[ 1 ], argv
[ 4 ], argv
[ 5 ], modes
, argv
[ argc
- 2 ], argv
[ argc
- 1 ], atoi ( argv
[ 3 ]), argv
[ argc
- 3 ]);
1563 static CMD_FUNC ( cmd_account
)
1565 struct userNode
* user
;
1566 struct server
* server
;
1567 struct handle_info
* hi
;
1569 if (( argc
< 3 ) || ! origin
|| !( server
= GetServerH ( origin
)))
1570 return 0 ; /* Origin must be server. */
1572 /* This next line appears to tremple origin.. why? */
1573 user
= GetUserN ( argv
[ 1 ]);
1575 return 1 ; /* A QUIT probably passed the ACCOUNT. */
1577 if (! extended_accounts
) /* any need for this function without? */
1580 if (! strcmp ( argv
[ 2 ], "C" ))
1582 if (( hi
= loc_auth ( argv
[ 4 ], argv
[ 5 ], NULL
)))
1585 putsock ( " %s " P10_ACCOUNT
" %s A %s " FMT_TIME_T
, self
-> numeric
, server
-> numeric
, argv
[ 3 ], hi
-> registered
);
1587 log_module ( MAIN_LOG
, LOG_DEBUG
, "loc_auth: %s \n " , user
-> nick
);
1592 putsock ( " %s " P10_ACCOUNT
" %s D %s " , self
-> numeric
, server
-> numeric
, argv
[ 3 ]);
1596 else if (! strcmp ( argv
[ 2 ], "H" )) /* New enhanced (host) version of C */
1598 if (( hi
= loc_auth ( argv
[ 5 ], argv
[ 6 ], argv
[ 4 ] )))
1601 putsock ( " %s " P10_ACCOUNT
" %s A %s " FMT_TIME_T
, self
-> numeric
, server
-> numeric
, argv
[ 3 ], hi
-> registered
);
1606 putsock ( " %s " P10_ACCOUNT
" %s D %s " , self
-> numeric
, server
-> numeric
, argv
[ 3 ]);
1610 else if (! strcmp ( argv
[ 2 ], "R" ))
1611 call_account_func ( user
, argv
[ 3 ]);
1613 call_account_func ( user
, argv
[ 2 ]); /* For backward compatability */
1617 static CMD_FUNC ( cmd_fakehost
)
1619 struct userNode
* user
;
1621 if (( argc
< 3 ) || ! origin
|| ! GetServerH ( origin
))
1623 if (!( user
= GetUserN ( argv
[ 1 ])))
1625 assign_fakehost ( user
, argv
[ 2 ], 0 );
1633 #define P(priv) { #priv, PRIV_ ## priv }
1634 P ( CHAN_LIMIT
), P ( MODE_LCHAN
), P ( WALK_LCHAN
), P ( DEOP_LCHAN
),
1635 P ( SHOW_INVIS
), P ( SHOW_ALL_INVIS
), P ( UNLIMIT_QUERY
), P ( KILL
),
1636 P ( LOCAL_KILL
), P ( REHASH
), P ( RESTART
), P ( DIE
),
1637 P ( GLINE
), P ( LOCAL_GLINE
), P ( JUPE
), P ( LOCAL_JUPE
),
1638 P ( OPMODE
), P ( LOCAL_OPMODE
), P ( SET
), P ( WHOX
),
1639 P ( BADCHAN
), P ( LOCAL_BADCHAN
), P ( SEE_CHAN
), P ( PROPAGATE
),
1640 P ( DISPLAY
), P ( SEE_OPERS
), P ( WIDE_GLINE
), P ( FORCE_OPMODE
),
1641 P ( FORCE_LOCAL_OPMODE
), P ( REMOTEREHASH
), P ( CHECK
), P ( SEE_SECRET_CHAN
),
1642 P ( SHUN
), P ( LOCAL_SHUN
), P ( WIDE_SHUN
), P ( ZLINE
),
1643 P ( LOCAL_ZLINE
), P ( WIDE_ZLINE
), P ( LIST_CHAN
), P ( WHOIS_NOTICE
),
1644 P ( HIDE_IDLE
), P ( XTRAOP
), P ( HIDE_CHANNELS
), P ( DISPLAY_MODE
),
1645 P ( FREEFORM
), P ( REMOVE
), P ( SPAMFILTER
),
1650 char * client_report_privs ( struct userNode
* client
)
1655 for ( i
= 0 ; privtab
[ i
]. name
; i
++) {
1656 if ( HasPriv ( client
, privtab
[ i
]. priv
)) {
1657 strcat ( privbuf
, privtab
[ i
]. name
);
1658 strcat ( privbuf
, " " );
1662 privbuf
[ strlen ( privbuf
)] = 0 ;
1667 int clear_privs ( struct userNode
* who
) {
1671 for ( i
= 0 ; privtab
[ i
]. name
; i
++)
1672 RevokePriv ( who
, privtab
[ i
]. priv
);
1677 int client_modify_priv_by_name ( struct userNode
* who
, char * priv
, int what
) {
1682 for ( i
= 0 ; privtab
[ i
]. name
; i
++) {
1683 if ( 0 == strcmp ( privtab
[ i
]. name
, priv
)) {
1684 if ( what
== PRIV_ADD
)
1685 GrantPriv ( who
, privtab
[ i
]. priv
);
1686 else if ( what
== PRIV_DEL
) {
1687 RevokePriv ( who
, privtab
[ i
]. priv
);
1694 int check_priv ( char * priv
)
1698 for ( i
= 0 ; privtab
[ i
]. name
; i
++) {
1699 if ( 0 == strcmp ( privtab
[ i
]. name
, priv
)) {
1707 irc_privs ( struct userNode
* target
, char * flag
, int add
)
1709 client_modify_priv_by_name ( target
, flag
, add
);
1710 putsock ( " %s " P10_PRIVS
" %s %s%s " , self
-> numeric
, target
-> numeric
, ( add
== PRIV_ADD
) ? "+" : "-" , flag
);
1714 irc_raw_privs ( struct userNode
* target
, char * privs
)
1716 putsock ( " %s " P10_PRIVS
" %s %s " , self
-> numeric
, target
-> numeric
, privs
);
1719 static CMD_FUNC ( cmd_privs
)
1726 int what
= PRIV_ADD
;
1731 struct server
* sender
;
1732 struct userNode
* user
;
1735 tstr
= conf_get_data ( "server/type" , RECDB_QSTRING
);
1740 if (!( sender
= GetServerH ( origin
))) { /* from oper */
1741 return 1 ; /* ignore as no services have privs set */
1742 } else { /* from server */
1744 return 1 ; /* silently ignore */
1746 user
= argc
> 1 ? GetUserN ( argv
[ 1 ]) : NULL
;
1751 for ( i
= 1 ; i
< argc
; i
++) {
1752 strcat ( buf
, argv
[ i
]);
1756 for ( i
= 2 ; i
< argc
; i
++) {
1757 if (* argv
[ i
] == '+' ) { what
= PRIV_ADD
; argv
[ i
]++; }
1758 if (* argv
[ i
] == '-' ) { what
= PRIV_DEL
; argv
[ i
]++; }
1759 for ( tmp
= x3_strtok (& p
, argv
[ i
], "," ); tmp
;
1760 tmp
= x3_strtok (& p
, NULL
, "," )) {
1761 if (! strcmp ( tmp
, "PRIV_NONE" )) {
1765 client_modify_priv_by_name ( user
, tmp
, what
);
1772 static CMD_FUNC ( cmd_burst
)
1775 char modes
[ MAXLEN
], * members
= "" ;
1776 static char exemptlist
[ MAXLEN
], banlist
[ MAXLEN
];
1777 unsigned int next
= 3 , res
= 1 ;
1778 int ctype
= 0 , echeck
= 0 , bcheck
= 0 ;
1779 struct chanData
* cData
;
1780 struct chanNode
* cNode
;
1781 struct userNode
* un
;
1782 struct modeNode
* mNode
;
1785 char * user
, * end
, sep
;
1786 time_t in_timestamp
;
1796 while ( next
< argc
) {
1797 switch ( argv
[ next
][ 0 ]) {
1801 for ( pos
= argv
[ next
], n_modes
= 1 ; * pos
; pos
++)
1802 if ((* pos
== 'k' ) || (* pos
== 'l' ) || (* pos
== 'A' )
1805 if ( next
+ n_modes
> argc
)
1806 n_modes
= argc
- next
;
1807 unsplit_string ( argv
+ next
, n_modes
, modes
);
1812 for ( parm
= mysep (& argv
[ next
], " " ); /* parm = first param */
1813 parm
; /* While param is not null */
1814 parm
= mysep (& argv
[ next
], " " ) /* parm = next param */
1832 /* strip % char off start of very first ban */
1833 if ( strlen ( parm
) > 1 ) {
1834 strncat ( banlist
, strtok ( parm
, "%" ), sizeof ( banlist
) - 1 - strlen ( banlist
));
1835 strncat ( banlist
, " " , sizeof ( banlist
) - 1 - strlen ( banlist
));
1839 strncat ( banlist
, parm
, sizeof ( banlist
) - 1 - strlen ( banlist
));
1840 strncat ( banlist
, " " , sizeof ( banlist
) - 1 - strlen ( banlist
));
1842 } else if ( ctype
== 2 ) {
1846 strncat ( exemptlist
, parm
, sizeof ( exemptlist
) - 1 - strlen ( exemptlist
));
1847 strncat ( exemptlist
, " " , sizeof ( exemptlist
) - 1 - strlen ( exemptlist
));
1854 default : members
= argv
[ next
++]; break ;
1858 in_timestamp
= atoi ( argv
[ 2 ]);
1859 if (( cNode
= dict_find ( unbursted_channels
, argv
[ 1 ], NULL
))) {
1860 cNode
-> timestamp
= in_timestamp
;
1861 dict_remove ( unbursted_channels
, cNode
-> name
);
1864 cNode
= AddChannel ( argv
[ 1 ], in_timestamp
, modes
, banlist
, exemptlist
);
1865 cData
= cNode
-> channel_info
;
1868 if ( cNode
-> modes
& MODE_REGISTERED
) {
1869 irc_join ( opserv
, cNode
);
1870 irc_mode ( opserv
, cNode
, "-z" );
1871 irc_part ( opserv
, cNode
, "" );
1875 /* Burst channel members in now. */
1876 for ( user
= members
, sep
= * members
, mode
= 0 ; sep
; user
= end
) {
1877 for ( end
= user
+ 3 ; isalnum (* end
) || * end
== '[' || * end
== ']' ; end
++) ;
1878 sep
= * end
++; end
[- 1 ] = 0 ;
1881 while (( sep
= * end
++)) {
1883 mode
|= MODE_CHANOP
;
1885 } else if ( sep
== 'h' ) {
1886 mode
|= MODE_HALFOP
;
1888 } else if ( sep
== 'v' ) {
1891 } else if ( isdigit ( sep
)) {
1892 mode
|= MODE_CHANOP
;
1894 oplevel
+= parse_oplevel ( end
);
1896 oplevel
= parse_oplevel ( end
);
1897 while ( isdigit (* end
)) end
++;
1904 if (!( un
= GetUserN ( user
))) {
1908 if (( mNode
= AddChannelUser ( un
, cNode
))) {
1909 mNode
-> modes
= mode
;
1910 mNode
-> oplevel
= oplevel
;
1918 * This is a stub that doesn't actually do anything. It should be completed
1919 * so that bans on *!*@markname.* match users as it does in nefarious
1921 static CMD_FUNC ( cmd_mark
)
1923 struct userNode
* target
;
1925 * log_module(MAIN_LOG, LOG_ERROR, "DEBUG: mark, user %s, type %s, arg %s", argv[1], argv[2], argv[3]);
1930 if (! strcasecmp ( argv
[ 2 ], "DNSBL" )) {
1934 else if (! strcasecmp ( argv
[ 2 ], "DNSBL_DATA" )) {
1935 /* DNSBL_DATA name */
1936 target
= GetUserH ( argv
[ 1 ]);
1938 log_module ( MAIN_LOG
, LOG_ERROR
, "Unable to find user %s whose dnsbl mark is changing." , argv
[ 1 ]);
1941 target
-> mark
= strdup ( argv
[ 3 ]);
1945 else if (! strcasecmp ( argv
[ 2 ], "CVERSION" )) {
1946 /* DNSBL_DATA name */
1947 target
= GetUserH ( argv
[ 1 ]);
1949 log_module ( MAIN_LOG
, LOG_ERROR
, "Unable to find user %s whose version mark is changing." , argv
[ 1 ]);
1953 char * version
= unsplit_string ( argv
+ 3 , argc
- 3 , NULL
);
1957 target
-> version_reply
= strdup ( version
);
1959 if ( match_ircglob ( version
, "WebTV;*" ))
1960 target
-> no_notice
= true ; /* webbies cant see notices */
1964 /* unknown type of mark */
1968 static CMD_FUNC ( cmd_mode
)
1970 struct chanNode
* cn
;
1971 struct userNode
* un
;
1972 char * sethost
; // sethost - reed/apples
1973 int i
; // sethost - reed/apples
1977 if (! IsChannelName ( argv
[ 1 ])) {
1978 un
= GetUserH ( argv
[ 1 ]);
1980 log_module ( MAIN_LOG
, LOG_ERROR
, "Unable to find user %s whose mode is changing." , argv
[ 1 ]);
1983 // sethost - reed/apples
1985 mod_usermode ( un
, argv
[ 2 ]);
1987 sethost
= malloc ( strlen ( argv
[ 2 ]) + 1 + strlen ( argv
[ 3 ]) + 1 );
1989 while (( sethost
[ i
++] = * argv
[ 2 ]++));
1992 while (( sethost
[ i
++] = * argv
[ 3 ]++));
1993 mod_usermode ( un
, sethost
); // sethost - reed/apples
1999 if (!( cn
= GetChannel ( argv
[ 1 ]))) {
2000 log_module ( MAIN_LOG
, LOG_ERROR
, "Unable to find channel %s whose mode is changing." , argv
[ 1 ]);
2003 if (( un
= GetUserH ( origin
))) {
2004 struct modeNode
* mn
;
2005 /* Update idle time for person setting the mode */
2006 if (( mn
= GetUserMode ( cn
, un
)))
2007 mn
-> idle_since
= now
;
2009 /* If it came from a server, reset timestamp to re-sync. */
2010 cn
-> timestamp
= atoi ( argv
[ argc
- 1 ]);
2013 if ( checkDefCon ( DEFCON_NO_MODE_CHANGE
) && ! IsOper ( un
)) {
2015 str
= conf_get_data ( "services/opserv/nick" , RECDB_QSTRING
);
2017 char modes
[ MODELEN
];
2018 struct userNode
* opserv
= GetUserH ( str
);
2020 send_message_type ( 4 , un
, opserv
, "Channel modes cannot be changed due to DefCon level %d in effect, please try again soon" , DefConLevel
);
2021 irc_make_chanmode ( cn
, modes
);
2022 irc_mode ( opserv
, cn
, modes
);
2023 irc_mode ( opserv
, cn
, DefConChanModes
);
2029 return mod_chanmode ( un
, cn
, argv
+ 2 , argc
- 2 , MCP_ALLOW_OVB
| MCP_FROM_SERVER
|( un
? MC_NOTIFY
: 0 ));
2032 static CMD_FUNC ( cmd_opmode
)
2034 struct chanNode
* cn
;
2035 struct userNode
* un
;
2040 if (!( cn
= GetChannel ( argv
[ 1 ]))) {
2041 log_module ( MAIN_LOG
, LOG_ERROR
, "Unable to find channel %s whose mode is changing." , argv
[ 1 ]);
2044 if (!( un
= GetUserH ( origin
))) {
2045 log_module ( MAIN_LOG
, LOG_ERROR
, "Unable to find user %s requesting OPMODE." , origin
);
2049 log_module ( MAIN_LOG
, LOG_ERROR
, "Non-privileged user %s using OPMODE." , un
-> nick
);
2053 return mod_chanmode ( un
, cn
, argv
+ 2 , argc
- 2 , MCP_ALLOW_OVB
| MCP_FROM_SERVER
); /* do NOT announce opmode locally */
2056 static int clear_chanmode ( struct chanNode
* channel
, const char * modes
);
2058 static CMD_FUNC ( cmd_clearmode
)
2060 struct chanNode
* cn
;
2061 struct userNode
* un
;
2066 if (!( cn
= GetChannel ( argv
[ 1 ]))) {
2067 log_module ( MAIN_LOG
, LOG_ERROR
, "Unable to find channel %s whose mode is changing." , argv
[ 1 ]);
2070 if (!( un
= GetUserH ( origin
))) {
2071 log_module ( MAIN_LOG
, LOG_ERROR
, "Unable to find user %s requesting CLEARMODE." , origin
);
2075 log_module ( MAIN_LOG
, LOG_ERROR
, "Non-privileged user %s using CLEARMODE." , un
-> nick
);
2079 return clear_chanmode ( cn
, argv
[ 2 ]);
2082 static CMD_FUNC ( cmd_topic
)
2084 struct chanNode
* cn
;
2085 time_t chan_ts
, topic_ts
;
2086 struct userNode
* user
;
2090 if (!( cn
= GetChannel ( argv
[ 1 ]))) {
2091 log_module ( MAIN_LOG
, LOG_ERROR
, "Unable to find channel %s whose topic is being set" , argv
[ 1 ]);
2096 if ( argc
== 5 ) { /* Asuka / Topic Bursting IRCu's */
2097 user
= GetUserH ( origin
);
2098 chan_ts
= atoi ( argv
[ 2 ]);
2099 topic_ts
= atoi ( argv
[ 3 ]);
2100 } else if ( argc
>= 6 ) { /* Nefarious 0.5.0 */
2101 user
= GetUserH ( strtok ( argv
[ 2 ], "!" ));
2102 chan_ts
= atoi ( argv
[ 3 ]);
2103 topic_ts
= atoi ( argv
[ 4 ]);
2104 } else { /* Regular IRCu (No Topic Bursting)*/
2105 user
= GetUserH ( origin
);
2106 chan_ts
= cn
-> timestamp
;
2110 SetChannelTopic ( cn
, user
, user
, argv
[ argc
- 1 ], 0 );
2111 cn
-> topic_time
= topic_ts
;
2115 static CMD_FUNC ( cmd_num_topic
)
2117 struct chanNode
* cn
;
2120 return 0 ; /* huh? */
2122 cn
= GetChannel ( argv
[ 2 ]);
2124 log_module ( MAIN_LOG
, LOG_ERROR
, "Unable to find channel %s in topic reply" , argv
[ 2 ]);
2130 switch ( atoi ( argv
[ 0 ])) {
2133 break ; /* no topic */
2137 safestrncpy ( cn
-> topic
, unsplit_string ( argv
+ 3 , argc
- 3 , NULL
), sizeof ( cn
-> topic
));
2142 safestrncpy ( cn
-> topic_nick
, argv
[ 3 ], sizeof ( cn
-> topic_nick
));
2143 cn
-> topic_time
= atoi ( argv
[ 4 ]);
2146 return 0 ; /* should never happen */
2151 static CMD_FUNC ( cmd_num_gline
)
2157 gline_add ( origin
, argv
[ 3 ], atoi ( argv
[ 4 ])- now
, argv
[ 5 ], now
, 0 , 0 );
2159 if (! strcmp ( argv
[ 5 ], "+" ))
2160 gline_add ( origin
, argv
[ 3 ], atoi ( argv
[ 4 ])- now
, argv
[ 6 ], now
, 0 , 0 );
2165 static CMD_FUNC ( cmd_num_shun
)
2171 shun_add ( origin
, argv
[ 3 ], atoi ( argv
[ 4 ])- now
, argv
[ 5 ], now
, 0 );
2173 if (! strcmp ( argv
[ 5 ], "+" ))
2174 shun_add ( origin
, argv
[ 3 ], atoi ( argv
[ 4 ])- now
, argv
[ 6 ], now
, 0 );
2179 static CMD_FUNC ( cmd_quit
)
2181 struct userNode
* user
;
2184 /* Sometimes we get a KILL then a QUIT or the like, so we don't want to
2185 * call DelUser unless we have the user in our grasp. */
2186 if (( user
= GetUserH ( origin
)))
2187 DelUser ( user
, NULL
, false , argv
[ 1 ]);
2191 static CMD_FUNC ( cmd_kill
)
2193 struct userNode
* user
;
2196 user
= GetUserN ( argv
[ 1 ]);
2198 /* If we get a KILL for a non-existent user, it could be a
2199 * Ghost response to a KILL we sent out earlier. So we only
2200 * whine if the target is local.
2202 if (! strncmp ( argv
[ 1 ], self
-> numeric
, strlen ( self
-> numeric
)))
2203 log_module ( MAIN_LOG
, LOG_ERROR
, "Unable to find kill victim %s " , argv
[ 1 ]);
2207 if ( IsLocal ( user
) && IsService ( user
)) {
2208 /* TODO: rate limit this so silly things don't happen. */
2209 ReintroduceUser ( user
);
2213 DelUser ( user
, NULL
, false , argv
[ 2 ]);
2217 static CMD_FUNC ( cmd_svspart
)
2219 struct userNode
* user
;
2223 user
= GetUserN ( argv
[ 1 ]);
2226 parse_foreach ( argv
[ 2 ], part_helper
, NULL
, NULL
, NULL
, user
);
2230 static CMD_FUNC ( cmd_silence
)
2232 struct userNode
* user
;
2240 user
= GetUserN ( argv
[ 1 ]);
2242 /* Sanity, go nuts if this happens */
2246 /* We can safely ignore this if a user adding a silence is not
2247 * ignored. However this brings up a TODO. If a user logs in and
2248 * they have silences on the IRCd then we need to set them here
2251 if (! user
-> handle_info
)
2257 for ( i
= 0 ; i
< user
-> handle_info
-> ignores
-> used
; i
++) {
2258 if (! irccasecmp ( mask
+ 1 , user
-> handle_info
-> ignores
-> list
[ i
]))
2259 user
-> handle_info
-> ignores
-> list
[ i
] = user
-> handle_info
-> ignores
-> list
[-- user
-> handle_info
-> ignores
-> used
];
2262 for ( i
= 0 ; i
< user
-> handle_info
-> ignores
-> used
; i
++) {
2263 if (! strcmp ( mask
+ 1 , user
-> handle_info
-> ignores
-> list
[ i
]))
2264 return 1 ; /* Already on the users NickServ ignore list, safely ignore */
2267 new_mask
= strdup ( mask
+ 1 );
2268 string_list_append ( user
-> handle_info
-> ignores
, new_mask
);
2273 static CMD_FUNC ( cmd_kick
)
2277 ChannelUserKicked ( GetUserH ( origin
), GetUserN ( argv
[ 2 ]), GetChannel ( argv
[ 1 ]));
2281 static CMD_FUNC ( cmd_squit
)
2283 struct server
* server
;
2288 if (!( server
= GetServerH ( argv
[ 1 ])))
2291 if ( server
== self
-> uplink
) {
2292 /* Force a reconnect to the currently selected server. */
2293 cManager
. uplink
-> tries
= 0 ;
2294 log_module ( MAIN_LOG
, LOG_INFO
, "Squitting from uplink: %s " , argv
[ 3 ]);
2299 uplink
= strdup ( server
-> uplink
-> name
);
2300 DelServer ( server
, 0 , argv
[ 3 ]);
2301 /* if its a pingout and pingout connecting is enabled
2302 or its a read error and readerror connecting is enabled
2303 or were doing a "N" and i need to connect that server somewhere */
2304 routing_handle_squit ( argv
[ 1 ], uplink
, argv
[ 3 ]);
2309 static CMD_FUNC ( cmd_privmsg
)
2311 struct privmsg_desc pd
;
2314 pd
. user
= GetUserH ( origin
);
2315 if (! pd
. user
|| ( IsGagged ( pd
. user
) && ! IsOper ( pd
. user
)))
2318 if ( checkDefCon ( DEFCON_OPER_ONLY
) && ! IsOper ( pd
. user
)) {
2320 str
= conf_get_data ( "services/opserv/nick" , RECDB_QSTRING
);
2322 send_message_type ( 4 , pd
. user
, GetUserH ( str
), "Services are currently not available, please try again soon" );
2326 if ( checkDefCon ( DEFCON_SILENT_OPER_ONLY
) && ! IsOper ( pd
. user
))
2327 return 1 ; /* Silently Ignore */
2330 pd
. text
= argv
[ argc
- 1 ];
2331 parse_foreach ( argv
[ 1 ], privmsg_chan_helper
, NULL
, privmsg_user_helper
, privmsg_invalid
, & pd
);
2336 static CMD_FUNC ( cmd_notice
)
2338 struct privmsg_desc pd
;
2345 pd
. user
= GetUserH ( origin
);
2348 if (! pd
. user
|| ( IsGagged ( pd
. user
) && ! IsOper ( pd
. user
))) {
2353 parse_foreach ( argv
[ 1 ], privmsg_chan_helper
, NULL
, privmsg_user_helper
, privmsg_invalid
, & pd
);
2356 srv
= GetServerH ( origin
);
2358 char * sargv
[ MAXNUMPARAMS
];
2361 sargc
= split_line ( argv
[ 2 ], true , MAXNUMPARAMS
, sargv
);
2363 if (! strcasecmp ( sargv
[ 0 ], "Connect:" )) {
2364 /* :Connect: Host shoe.loxxin.net not listed in ircd.conf */
2365 if (! strcasecmp ( sargv
[ 3 ], "not" ) && ! strcasecmp ( sargv
[ 4 ], "listed" )) {
2366 routing_handle_connect_failure ( srv
, sargv
[ 2 ], unsplit_string ( sargv
+ 3 , sargc
- 3 , NULL
));
2369 else if (! strcasecmp ( sargv
[ 0 ], "Link" )) {
2370 /* :Link with mephisto.etheria.cx cancelled: Server mephisto.etheria.cx[216.46.33.71]
2372 * :Link with laptop.afternet.org cancelled: Connection refused
2374 if (! strcasecmp ( sargv
[ 3 ], "cancelled:" )) {
2375 routing_handle_connect_failure ( srv
, sargv
[ 2 ], unsplit_string ( sargv
+ 4 , sargc
- 4 , NULL
));
2382 static CMD_FUNC ( cmd_away
)
2384 struct userNode
* uNode
;
2386 uNode
= GetUserH ( origin
);
2390 uNode
-> modes
&= ~ FLAGS_AWAY
;
2392 uNode
-> modes
|= FLAGS_AWAY
;
2396 static CMD_FUNC ( cmd_gline
)
2400 if ( argv
[ 2 ][ 0 ] == '+' ) {
2403 gline_add ( origin
, argv
[ 2 ]+ 1 , strtoul ( argv
[ 3 ], NULL
, 0 ), argv
[ argc
- 1 ], now
, 0 , 0 );
2405 } else if ( argv
[ 2 ][ 0 ] == '-' ) {
2406 gline_remove ( argv
[ 2 ]+ 1 , 0 );
2412 static CMD_FUNC ( cmd_sgline
)
2414 struct server
* sender
;
2419 if (!( sender
= GetServerH ( origin
)))
2422 gline_add ( origin
, argv
[ 1 ], strtoul ( argv
[ 2 ], NULL
, 0 ), argv
[ argc
- 1 ], now
, 1 , 0 );
2426 static CMD_FUNC ( cmd_sshun
)
2428 struct server
* sender
;
2433 if (!( sender
= GetServerH ( origin
)))
2436 shun_add ( origin
, argv
[ 1 ], strtoul ( argv
[ 2 ], NULL
, 0 ), argv
[ argc
- 1 ], now
, 1 );
2440 static CMD_FUNC ( cmd_shun
)
2444 if ( argv
[ 2 ][ 0 ] == '+' ) {
2447 shun_add ( origin
, argv
[ 2 ]+ 1 , strtoul ( argv
[ 3 ], NULL
, 0 ), argv
[ argc
- 1 ], now
, 0 );
2449 } else if ( argv
[ 2 ][ 0 ] == '-' ) {
2450 shun_remove ( argv
[ 2 ]+ 1 , 0 );
2456 static CMD_FUNC ( cmd_svsnick
)
2458 struct userNode
* target
, * dest
;
2460 || !( target
= GetUserN ( argv
[ 1 ]))
2462 || ( dest
= GetUserH ( argv
[ 2 ])))
2464 NickChange ( target
, argv
[ 2 ], 0 );
2469 free_user ( struct userNode
* user
)
2480 free ( privmsg_funcs
);
2481 num_privmsg_funcs
= 0 ;
2483 num_notice_funcs
= 0 ;
2485 dict_delete ( irc_func_dict
);
2486 for ( nn
= 0 ; nn
< dead_users
. used
; nn
++)
2487 free_user ( dead_users
. list
[ nn
]);
2488 userList_clean (& dead_users
);
2492 p10_conf_reload ( void ) {
2493 hidden_host_suffix
= conf_get_data ( "server/hidden_host" , RECDB_QSTRING
);
2494 his_servername
= conf_get_data ( "server/his_servername" , RECDB_QSTRING
);
2495 his_servercomment
= conf_get_data ( "server/his_servercomment" , RECDB_QSTRING
);
2499 remove_unbursted_channel ( struct chanNode
* cNode
) {
2500 if ( unbursted_channels
)
2501 dict_remove ( unbursted_channels
, cNode
-> name
);
2507 const char * str
, * desc
;
2508 int numnick
, usermask
, max_users
;
2509 char numer
[ COMBO_NUMERIC_LEN
+ 1 ];
2511 /* read config items */
2512 str
= conf_get_data ( "server/extended_accounts" , RECDB_QSTRING
);
2513 extended_accounts
= str
? enabled_string ( str
) : 1 ;
2514 str
= conf_get_data ( "server/ping_freq" , RECDB_QSTRING
);
2515 ping_freq
= str
? ParseInterval ( str
) : 120 ;
2516 str
= conf_get_data ( "server/ping_timeout" , RECDB_QSTRING
);
2517 ping_timeout
= str
? ParseInterval ( str
) : 30 ;
2518 str
= conf_get_data ( "server/force_n2k" , RECDB_QSTRING
);
2519 force_n2k
= str
? enabled_string ( str
) : 1 ;
2520 str
= conf_get_data ( "server/numeric" , RECDB_QSTRING
);
2522 log_module ( MAIN_LOG
, LOG_ERROR
, "No server/numeric entry in config file." );
2525 numnick
= atoi ( str
);
2526 str
= conf_get_data ( "server/max_users" , RECDB_QSTRING
);
2527 max_users
= str
? atoi ( str
) : 4096 ;
2528 for ( usermask
= 4 ; usermask
< max_users
; usermask
<<= 1 ) ;
2530 if (( numnick
< 64 ) && ( usermask
< 4096 ) && ! force_n2k
)
2531 inttobase64 ( numer
, ( numnick
<< 12 ) + ( usermask
& 0x00fff ), 3 );
2533 inttobase64 ( numer
, ( numnick
<< 18 ) + ( usermask
& 0x3ffff ), 5 );
2535 str
= conf_get_data ( "server/hostname" , RECDB_QSTRING
);
2536 desc
= conf_get_data ( "server/description" , RECDB_QSTRING
);
2537 if (! str
|| ! desc
) {
2538 log_module ( MAIN_LOG
, LOG_ERROR
, "No server/hostname entry in config file." );
2541 self
= AddServer ( NULL
, str
, 0 , boot_time
, now
, numer
, desc
);
2542 conf_register_reload ( p10_conf_reload
);
2544 irc_func_dict
= dict_new ();
2545 dict_insert ( irc_func_dict
, CMD_BURST
, cmd_burst
);
2546 dict_insert ( irc_func_dict
, TOK_BURST
, cmd_burst
);
2547 dict_insert ( irc_func_dict
, CMD_CREATE
, cmd_create
);
2548 dict_insert ( irc_func_dict
, TOK_CREATE
, cmd_create
);
2549 dict_insert ( irc_func_dict
, CMD_EOB
, cmd_eob
);
2550 dict_insert ( irc_func_dict
, TOK_EOB
, cmd_eob
);
2551 dict_insert ( irc_func_dict
, CMD_EOB_ACK
, cmd_eob_ack
);
2552 dict_insert ( irc_func_dict
, TOK_EOB_ACK
, cmd_eob_ack
);
2553 dict_insert ( irc_func_dict
, CMD_MODE
, cmd_mode
);
2554 dict_insert ( irc_func_dict
, TOK_MODE
, cmd_mode
);
2555 dict_insert ( irc_func_dict
, CMD_MARK
, cmd_mark
);
2556 dict_insert ( irc_func_dict
, TOK_MARK
, cmd_mark
);
2557 dict_insert ( irc_func_dict
, CMD_NICK
, cmd_nick
);
2558 dict_insert ( irc_func_dict
, TOK_NICK
, cmd_nick
);
2559 dict_insert ( irc_func_dict
, CMD_ACCOUNT
, cmd_account
);
2560 dict_insert ( irc_func_dict
, TOK_ACCOUNT
, cmd_account
);
2561 dict_insert ( irc_func_dict
, CMD_FAKEHOST
, cmd_fakehost
);
2562 dict_insert ( irc_func_dict
, TOK_FAKEHOST
, cmd_fakehost
);
2563 dict_insert ( irc_func_dict
, CMD_PASS
, cmd_pass
);
2564 dict_insert ( irc_func_dict
, TOK_PASS
, cmd_pass
);
2565 dict_insert ( irc_func_dict
, CMD_PING
, cmd_ping
);
2566 dict_insert ( irc_func_dict
, TOK_PING
, cmd_ping
);
2567 dict_insert ( irc_func_dict
, CMD_PRIVMSG
, cmd_privmsg
);
2568 dict_insert ( irc_func_dict
, TOK_PRIVMSG
, cmd_privmsg
);
2569 dict_insert ( irc_func_dict
, CMD_PONG
, cmd_pong
);
2570 dict_insert ( irc_func_dict
, TOK_PONG
, cmd_pong
);
2571 dict_insert ( irc_func_dict
, CMD_QUIT
, cmd_quit
);
2572 dict_insert ( irc_func_dict
, TOK_QUIT
, cmd_quit
);
2573 dict_insert ( irc_func_dict
, CMD_SERVER
, cmd_server
);
2574 dict_insert ( irc_func_dict
, TOK_SERVER
, cmd_server
);
2575 dict_insert ( irc_func_dict
, CMD_JOIN
, cmd_join
);
2576 dict_insert ( irc_func_dict
, TOK_JOIN
, cmd_join
);
2577 dict_insert ( irc_func_dict
, CMD_PART
, cmd_part
);
2578 dict_insert ( irc_func_dict
, TOK_PART
, cmd_part
);
2579 dict_insert ( irc_func_dict
, CMD_ERROR
, cmd_error
);
2580 dict_insert ( irc_func_dict
, TOK_ERROR
, cmd_error
);
2581 dict_insert ( irc_func_dict
, CMD_TOPIC
, cmd_topic
);
2582 dict_insert ( irc_func_dict
, TOK_TOPIC
, cmd_topic
);
2583 dict_insert ( irc_func_dict
, CMD_AWAY
, cmd_away
);
2584 dict_insert ( irc_func_dict
, TOK_AWAY
, cmd_away
);
2585 dict_insert ( irc_func_dict
, CMD_SILENCE
, cmd_silence
);
2586 dict_insert ( irc_func_dict
, TOK_SILENCE
, cmd_silence
);
2587 dict_insert ( irc_func_dict
, CMD_KICK
, cmd_kick
);
2588 dict_insert ( irc_func_dict
, TOK_KICK
, cmd_kick
);
2589 dict_insert ( irc_func_dict
, CMD_SQUIT
, cmd_squit
);
2590 dict_insert ( irc_func_dict
, TOK_SQUIT
, cmd_squit
);
2591 dict_insert ( irc_func_dict
, CMD_KILL
, cmd_kill
);
2592 dict_insert ( irc_func_dict
, TOK_KILL
, cmd_kill
);
2593 dict_insert ( irc_func_dict
, CMD_NOTICE
, cmd_notice
);
2594 dict_insert ( irc_func_dict
, TOK_NOTICE
, cmd_notice
);
2595 dict_insert ( irc_func_dict
, CMD_STATS
, cmd_stats
);
2596 dict_insert ( irc_func_dict
, TOK_STATS
, cmd_stats
);
2597 dict_insert ( irc_func_dict
, CMD_SVSJOIN
, cmd_svsjoin
);
2598 dict_insert ( irc_func_dict
, TOK_SVSJOIN
, cmd_svsjoin
);
2599 dict_insert ( irc_func_dict
, CMD_SVSNICK
, cmd_svsnick
);
2600 dict_insert ( irc_func_dict
, TOK_SVSNICK
, cmd_svsnick
);
2601 dict_insert ( irc_func_dict
, CMD_SVSPART
, cmd_svspart
);
2602 dict_insert ( irc_func_dict
, TOK_SVSPART
, cmd_svspart
);
2603 dict_insert ( irc_func_dict
, CMD_SWHOIS
, cmd_dummy
);
2604 dict_insert ( irc_func_dict
, TOK_SWHOIS
, cmd_dummy
);
2605 dict_insert ( irc_func_dict
, CMD_WHOIS
, cmd_whois
);
2606 dict_insert ( irc_func_dict
, TOK_WHOIS
, cmd_whois
);
2607 dict_insert ( irc_func_dict
, CMD_GLINE
, cmd_gline
);
2608 dict_insert ( irc_func_dict
, TOK_GLINE
, cmd_gline
);
2609 dict_insert ( irc_func_dict
, CMD_SGLINE
, cmd_sgline
);
2610 dict_insert ( irc_func_dict
, TOK_SGLINE
, cmd_sgline
);
2611 dict_insert ( irc_func_dict
, CMD_SHUN
, cmd_shun
);
2612 dict_insert ( irc_func_dict
, TOK_SHUN
, cmd_shun
);
2613 dict_insert ( irc_func_dict
, CMD_SSHUN
, cmd_sshun
);
2614 dict_insert ( irc_func_dict
, TOK_SSHUN
, cmd_sshun
);
2615 dict_insert ( irc_func_dict
, CMD_OPMODE
, cmd_opmode
);
2616 dict_insert ( irc_func_dict
, TOK_OPMODE
, cmd_opmode
);
2617 dict_insert ( irc_func_dict
, CMD_CLEARMODE
, cmd_clearmode
);
2618 dict_insert ( irc_func_dict
, TOK_CLEARMODE
, cmd_clearmode
);
2619 dict_insert ( irc_func_dict
, CMD_VERSION
, cmd_version
);
2620 dict_insert ( irc_func_dict
, TOK_VERSION
, cmd_version
);
2621 dict_insert ( irc_func_dict
, CMD_ADMIN
, cmd_admin
);
2622 dict_insert ( irc_func_dict
, TOK_ADMIN
, cmd_admin
);
2623 dict_insert ( irc_func_dict
, CMD_SMO
, cmd_dummy
);
2624 dict_insert ( irc_func_dict
, TOK_SMO
, cmd_dummy
);
2625 dict_insert ( irc_func_dict
, CMD_SNO
, cmd_dummy
);
2626 dict_insert ( irc_func_dict
, TOK_SNO
, cmd_dummy
);
2628 dict_insert ( irc_func_dict
, CMD_RPING
, cmd_rping
);
2629 dict_insert ( irc_func_dict
, TOK_RPING
, cmd_rping
);
2630 dict_insert ( irc_func_dict
, CMD_RPONG
, cmd_dummy
);
2631 dict_insert ( irc_func_dict
, TOK_RPONG
, cmd_dummy
);
2633 /* In P10, DESTRUCT doesn't do anything except be broadcast to servers.
2634 * Apparently to obliterate channels from any servers that think they
2637 dict_insert ( irc_func_dict
, CMD_DESTRUCT
, cmd_dummy
);
2638 dict_insert ( irc_func_dict
, TOK_DESTRUCT
, cmd_dummy
);
2639 /* Ignore invites */
2640 dict_insert ( irc_func_dict
, CMD_INVITE
, cmd_dummy
);
2641 dict_insert ( irc_func_dict
, TOK_INVITE
, cmd_dummy
);
2642 /* DESYNCH is just informational, so ignore it */
2643 dict_insert ( irc_func_dict
, CMD_DESYNCH
, cmd_dummy
);
2644 dict_insert ( irc_func_dict
, TOK_DESYNCH
, cmd_dummy
);
2645 /* Ignore channel operator notices. */
2646 dict_insert ( irc_func_dict
, CMD_WALLCHOPS
, cmd_dummy
);
2647 dict_insert ( irc_func_dict
, TOK_WALLCHOPS
, cmd_dummy
);
2648 dict_insert ( irc_func_dict
, CMD_WALLVOICES
, cmd_dummy
);
2649 dict_insert ( irc_func_dict
, TOK_WALLVOICES
, cmd_dummy
);
2650 dict_insert ( irc_func_dict
, CMD_WALLHOPS
, cmd_dummy
);
2651 dict_insert ( irc_func_dict
, TOK_WALLHOPS
, cmd_dummy
);
2652 /* Ignore opers being silly. */
2653 dict_insert ( irc_func_dict
, CMD_WALLOPS
, cmd_dummy
);
2654 dict_insert ( irc_func_dict
, TOK_WALLOPS
, cmd_dummy
);
2655 dict_insert ( irc_func_dict
, CMD_WALLHOPS
, cmd_dummy
);
2656 dict_insert ( irc_func_dict
, TOK_WALLHOPS
, cmd_dummy
);
2657 dict_insert ( irc_func_dict
, TOK_WALLUSERS
, cmd_dummy
);
2658 /* Ignore dnsbl exemptions */
2659 dict_insert ( irc_func_dict
, TOK_EXEMPT
, cmd_dummy
);
2660 dict_insert ( irc_func_dict
, CMD_PRIVS
, cmd_privs
);
2661 dict_insert ( irc_func_dict
, TOK_PRIVS
, cmd_privs
);
2662 /* ignore ALIST for now */
2663 dict_insert ( irc_func_dict
, TOK_ALIST
, cmd_dummy
);
2664 dict_insert ( irc_func_dict
, CMD_ALIST
, cmd_dummy
);
2665 /* ignore SPAMFILTER */
2666 dict_insert ( irc_func_dict
, TOK_SPAMFILTER
, cmd_dummy
);
2667 dict_insert ( irc_func_dict
, CMD_SPAMFILTER
, cmd_dummy
);
2668 /* Ignore remote luser */
2669 dict_insert ( irc_func_dict
, TOK_LUSERS
, cmd_dummy
);
2670 /* We have reliable clock! Always! Wraaa! */
2671 dict_insert ( irc_func_dict
, CMD_SETTIME
, cmd_dummy
);
2672 dict_insert ( irc_func_dict
, TOK_SETTIME
, cmd_dummy
);
2674 /* ignore /trace and /motd commands targetted at us */
2675 dict_insert ( irc_func_dict
, TOK_TRACE
, cmd_dummy
);
2676 dict_insert ( irc_func_dict
, TOK_MOTD
, cmd_dummy
);
2677 dict_insert ( irc_func_dict
, TOK_UPING
, cmd_dummy
);
2680 dict_insert ( irc_func_dict
, "331" , cmd_num_topic
);
2681 dict_insert ( irc_func_dict
, "332" , cmd_num_topic
);
2682 dict_insert ( irc_func_dict
, "333" , cmd_num_topic
);
2683 dict_insert ( irc_func_dict
, "345" , cmd_dummy
); /* blah has been invited to blah */
2684 dict_insert ( irc_func_dict
, "432" , cmd_error_nick
); /* Erroneus [sic] nickname */
2685 /* ban list resetting */
2686 /* "stats g" responses */
2687 dict_insert ( irc_func_dict
, "230" , cmd_dummy
); /* ignore stats headers */
2688 dict_insert ( irc_func_dict
, "247" , cmd_num_gline
);
2689 dict_insert ( irc_func_dict
, "542" , cmd_num_shun
);
2690 dict_insert ( irc_func_dict
, "219" , cmd_dummy
); /* "End of /STATS report" */
2691 /* other numeric responses we might get */
2692 dict_insert ( irc_func_dict
, "401" , cmd_dummy
); /* target left network */
2693 dict_insert ( irc_func_dict
, "403" , cmd_dummy
); /* no such channel */
2694 dict_insert ( irc_func_dict
, "404" , cmd_dummy
); /* cannot send to channel */
2695 dict_insert ( irc_func_dict
, "439" , cmd_dummy
); /* target change too fast */
2696 dict_insert ( irc_func_dict
, "441" , cmd_dummy
); /* target isn't on that channel */
2697 dict_insert ( irc_func_dict
, "442" , cmd_dummy
); /* you aren't on that channel */
2698 dict_insert ( irc_func_dict
, "443" , cmd_dummy
); /* is already on channel (after invite?) */
2699 dict_insert ( irc_func_dict
, "461" , cmd_dummy
); /* Not enough parameters (after TOPIC w/ 0 args) */
2700 dict_insert ( irc_func_dict
, "467" , cmd_dummy
); /* Channel key already set */
2702 num_privmsg_funcs
= 16 ;
2703 privmsg_funcs
= malloc ( sizeof ( privmsg_func_t
)* num_privmsg_funcs
);
2704 memset ( privmsg_funcs
, 0 , sizeof ( privmsg_func_t
)* num_privmsg_funcs
);
2706 num_notice_funcs
= 16 ;
2707 notice_funcs
= malloc ( sizeof ( privmsg_func_t
)* num_notice_funcs
);
2708 memset ( notice_funcs
, 0 , sizeof ( privmsg_func_t
)* num_notice_funcs
);
2710 userList_init (& dead_users
);
2711 reg_del_channel_func ( remove_unbursted_channel
);
2712 reg_exit_func ( parse_cleanup
);
2713 // reg_notice_func(opserv, check_ctcp);
2717 parse_line ( char * line
, int recursive
)
2719 char * argv
[ MAXNUMPARAMS
], * origin
;
2720 int argc
, cmd
, res
= 0 ;
2723 argc
= split_line ( line
, true , MAXNUMPARAMS
, argv
);
2724 cmd
= self
-> uplink
|| ! argv
[ 0 ][ 1 ] || ! argv
[ 0 ][ 2 ];
2727 if ( argv
[ 0 ][ 0 ] == ':' ) {
2729 } else if (! argv
[ 0 ][ 1 ] || ! argv
[ 0 ][ 2 ]) {
2730 struct server
* sNode
= GetServerN ( argv
[ 0 ]);
2731 origin
= sNode
? sNode
-> name
: 0 ;
2733 struct userNode
* uNode
= GetUserN ( argv
[ 0 ]);
2734 origin
= uNode
? uNode
-> nick
: 0 ;
2738 if (( func
= dict_find ( irc_func_dict
, argv
[ cmd
], NULL
)))
2739 res
= func ( origin
, argc
- cmd
, argv
+ cmd
);
2742 log_module ( MAIN_LOG
, LOG_ERROR
, "PARSE ERROR on line: %s " , unsplit_string ( argv
, argc
, NULL
));
2743 } else if (! recursive
) {
2745 for ( i
= 0 ; i
< dead_users
. used
; i
++)
2746 free_user ( dead_users
. list
[ i
]);
2747 dead_users
. used
= 0 ;
2753 parse_foreach ( char * target_list
, foreach_chanfunc cf
, foreach_nonchan nc
, foreach_userfunc uf
, foreach_nonuser nu
, void * data
)
2759 while (* j
!= 0 && * j
!= ',' )
2764 if ( IsChannelName ( target_list
)
2765 || ( target_list
[ 0 ] == '0' && target_list
[ 1 ] == '\0' )) {
2766 struct chanNode
* chan
= GetChannel ( target_list
);
2773 nc ( target_list
, data
);
2776 struct userNode
* user
;
2777 struct privmsg_desc
* pd
= data
;
2779 pd
-> is_qualified
= 0 ;
2780 if (* target_list
== '@' ) {
2782 } else if ( strchr ( target_list
, '@' )) {
2783 struct server
* server
;
2785 pd
-> is_qualified
= 1 ;
2786 user
= GetUserH ( strtok ( target_list
, "@" ));
2787 server
= GetServerH ( strtok ( NULL
, "@" ));
2789 if ( user
&& ( user
-> uplink
!= server
)) {
2790 /* Don't attempt to index into any arrays
2791 using a user's numeric on another server. */
2795 user
= GetUserN ( target_list
);
2803 nu ( target_list
, data
);
2807 } while ( old
== ',' );
2811 get_local_numeric ( void )
2813 static unsigned int next_numeric
= 0 ;
2814 if ( self
-> clients
> self
-> num_mask
)
2816 while ( self
-> users
[ next_numeric
])
2817 if (++ next_numeric
> self
-> num_mask
)
2819 return next_numeric
;
2823 make_numeric ( struct server
* svr
, int local_num
, char * outbuf
)
2827 if ( force_n2k
|| svr
-> numeric
[ 1 ]) {
2832 llen
= ( local_num
< 64 * 64 ) ? 2 : 3 ;
2834 strncpy ( outbuf
, svr
-> numeric
, slen
);
2835 inttobase64 ( outbuf
+ slen
, local_num
, llen
);
2836 outbuf
[ slen
+ llen
] = 0 ;
2840 AddServer ( struct server
* uplink
, const char * name
, int hops
, time_t boot
, time_t link_time
, const char * numeric
, const char * description
)
2842 struct server
* sNode
;
2845 if (( sNode
= GetServerN ( numeric
))) {
2846 /* This means we're trying to re-add an existant server.
2847 * To be safe, we should forget the previous incarnation.
2848 * (And all its linked servers.)
2850 * It usually only happens in replays when the original
2851 * had a ping timeout and the replay didn't (because
2852 * replaying a ping timeout invariably gets things wrong).
2854 DelServer ( sNode
, 0 , NULL
);
2857 switch ( strlen ( numeric
)) {
2858 case 5 : slen
= 2 ; mlen
= 3 ; break ;
2859 case 4 : slen
= 1 ; mlen
= 3 ; break ;
2860 case 3 : slen
= 1 ; mlen
= 2 ; break ;
2862 log_module ( MAIN_LOG
, LOG_ERROR
, "AddServer( \" %s \" , \" %s \" , ...): Numeric %s has invalid length." , uplink
-> name
, name
, numeric
);
2866 sNode
= calloc ( 1 , sizeof (* sNode
));
2867 sNode
-> uplink
= uplink
;
2868 safestrncpy ( sNode
-> name
, name
, sizeof ( sNode
-> name
));
2869 sNode
-> num_mask
= base64toint ( numeric
+ slen
, mlen
);
2872 sNode
-> link_time
= link_time
;
2873 strncpy ( sNode
-> numeric
, numeric
, slen
);
2874 safestrncpy ( sNode
-> description
, description
, sizeof ( sNode
-> description
));
2875 sNode
-> users
= calloc ( sNode
-> num_mask
+ 1 , sizeof (* sNode
-> users
));
2876 serverList_init (& sNode
-> children
);
2877 if ( sNode
-> uplink
) {
2878 /* uplink may be NULL if we're just building ourself */
2879 serverList_append (& sNode
-> uplink
-> children
, sNode
);
2881 servers_num
[ base64toint ( numeric
, slen
)] = sNode
;
2882 dict_insert ( servers
, sNode
-> name
, sNode
);
2886 void DelServer ( struct server
* serv
, int announce
, const char * message
)
2890 /* If we receive an ERROR command before the SERVER
2891 * command a NULL server can be passed */
2895 /* Hrm, what's the right way to SQUIT some other server?
2896 * (This code is only to handle killing juped servers.) */
2897 if ( announce
&& ( serv
-> uplink
== self
) && ( serv
!= self
-> uplink
))
2898 irc_squit ( serv
, message
, NULL
);
2900 /* must recursively remove servers linked to this one first */
2901 for ( i
= serv
-> children
. used
; i
> 0 ;)
2902 if ( serv
-> children
. list
[-- i
] != self
)
2903 DelServer ( serv
-> children
. list
[ i
], false , NULL
);
2905 /* clean up server's user hash tables */
2906 for ( i
= 0 ; i
<= serv
-> num_mask
; i
++)
2908 DelUser ( serv
-> users
[ i
], NULL
, false , "server delinked" );
2912 serverList_remove (& serv
-> uplink
-> children
, serv
);
2913 if ( serv
== self
-> uplink
)
2914 self
-> uplink
= NULL
;
2915 servers_num
[ base64toint ( serv
-> numeric
, strlen ( serv
-> numeric
))] = NULL
;
2916 dict_remove ( servers
, serv
-> name
);
2917 serverList_clean (& serv
-> children
);
2923 AddLocalUser ( const char * nick
, const char * ident
, const char * hostname
, const char * desc
, const char * modes
)
2925 char numeric
[ COMBO_NUMERIC_LEN
+ 1 ];
2926 int local_num
= get_local_numeric ();
2927 time_t timestamp
= now
;
2928 struct userNode
* old_user
= GetUserH ( nick
);
2934 if ( IsLocal ( old_user
))
2936 timestamp
= old_user
-> timestamp
- 1 ;
2938 if ( local_num
== - 1 ) {
2939 log_module ( MAIN_LOG
, LOG_ERROR
, "Unable to allocate numnick for service %s " , nick
);
2943 hostname
= self
-> name
;
2944 make_numeric ( self
, local_num
, numeric
);
2945 return AddUser ( self
, nick
, ident
, hostname
, modes
, numeric
, desc
, now
, "AAAAAA" );
2949 AddClone ( const char * nick
, const char * ident
, const char * hostname
, const char * desc
)
2951 char numeric
[ COMBO_NUMERIC_LEN
+ 1 ];
2952 int local_num
= get_local_numeric ();
2953 time_t timestamp
= now
;
2954 struct userNode
* old_user
= GetUserH ( nick
);
2957 if ( IsLocal ( old_user
))
2959 timestamp
= old_user
-> timestamp
- 1 ;
2961 if ( local_num
== - 1 ) {
2962 log_module ( MAIN_LOG
, LOG_ERROR
, "Unable to allocate numnick for clone %s " , nick
);
2965 make_numeric ( self
, local_num
, numeric
);
2966 return AddUser ( self
, nick
, ident
, hostname
, "+i" , numeric
, desc
, timestamp
, "AAAAAA" );
2970 is_valid_nick ( const char * nick
) {
2972 /* IRC has some of The Most Fucked-Up ideas about character sets
2974 if (! isalpha (* nick
) && ! strchr ( "{|}~[ \\ ]^_`" , * nick
))
2976 for ( ii
= 0 ; nick
[ ii
]; ++ ii
)
2977 if (! isalnum ( nick
[ ii
]) && ! strchr ( "{|}~[ \\ ]^-_`" , nick
[ ii
]))
2979 if ( strlen ( nick
) > nicklen
)
2984 static struct userNode
*
2985 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
)
2987 struct userNode
* oldUser
, * uNode
;
2988 unsigned int n
, ignore_user
, dummy
;
2992 if (( strlen ( numeric
) < 3 ) || ( strlen ( numeric
) > 5 )) {
2993 log_module ( MAIN_LOG
, LOG_WARNING
, "AddUser( %p , %s , ...): numeric %s wrong length!" , ( void *) uplink
, nick
, numeric
);
2998 log_module ( MAIN_LOG
, LOG_WARNING
, "AddUser( %p , %s , ...): server for numeric %s doesn't exist!" , ( void *) uplink
, nick
, numeric
);
3002 if ( uplink
!= GetServerN ( numeric
)) {
3003 log_module ( MAIN_LOG
, LOG_WARNING
, "AddUser( %p , %s , ...): server for numeric %s differs from nominal uplink %s ." , ( void *) uplink
, nick
, numeric
, uplink
-> name
);
3007 dummy
= modes
&& modes
[ 0 ] == '*' ;
3010 } else if (! is_valid_nick ( nick
)) {
3011 log_module ( MAIN_LOG
, LOG_WARNING
, "AddUser( %p , %s , ...): invalid nickname detected." , ( void *) uplink
, nick
);
3016 if (( oldUser
= GetUserH ( nick
))) {
3017 if ( IsLocal ( oldUser
)
3018 && ( IsService ( oldUser
) || IsPersistent ( oldUser
))) {
3019 /* The service should collide the new user off - but not
3020 * if the new user is coming in during a burst. (During a
3021 * burst, the bursting server will kill either our user --
3022 * triggering a ReintroduceUser() -- or its own.)
3024 oldUser
-> timestamp
= timestamp
- 1 ;
3028 } else if ( oldUser
-> timestamp
> timestamp
) {
3029 /* "Old" user is really newer; remove them */
3030 DelUser ( oldUser
, 0 , 1 , "Overruled by older nick" );
3032 /* User being added is too new; do not add them to
3033 * clients, but do add them to the server's list, since it
3034 * will send a KILL and QUIT soon. */
3039 /* create new usernode and set all values */
3040 uNode
= calloc ( 1 , sizeof (* uNode
));
3041 uNode
-> nick
= strdup ( nick
);
3042 safestrncpy ( uNode
-> ident
, ident
, sizeof ( uNode
-> ident
));
3043 safestrncpy ( uNode
-> info
, userinfo
, sizeof ( uNode
-> info
));
3044 safestrncpy ( uNode
-> hostname
, hostname
, sizeof ( uNode
-> hostname
));
3045 safestrncpy ( uNode
-> numeric
, numeric
, sizeof ( uNode
-> numeric
));
3046 irc_p10_pton (& uNode
-> ip
, realip
);
3048 tstr
= conf_get_data ( "server/type" , RECDB_QSTRING
);
3051 if ( irc_in_addr_is_ipv4 ( uNode
-> ip
)) {
3052 make_virtip (( char *) irc_ntoa (& uNode
-> ip
), ( char *) irc_ntoa (& uNode
-> ip
), uNode
-> cryptip
);
3053 make_virthost (( char *) irc_ntoa (& uNode
-> ip
), uNode
-> hostname
, uNode
-> crypthost
);
3054 } else if ( irc_in_addr_is_ipv6 ( uNode
-> ip
)) {
3055 make_ipv6virthost (( char *) irc_ntoa (& uNode
-> ip
), uNode
-> hostname
, uNode
-> crypthost
);
3059 if (! uNode
-> crypthost
&& uNode
-> cryptip
)
3060 snprintf ( uNode
-> crypthost
, sizeof ( uNode
-> crypthost
), " %s " , strdup ( uNode
-> cryptip
));
3061 uNode
-> idle_since
= timestamp
;
3062 uNode
-> timestamp
= timestamp
;
3063 modeList_init (& uNode
-> channels
);
3064 uNode
-> uplink
= uplink
;
3065 if (++ uNode
-> uplink
-> clients
> uNode
-> uplink
-> max_clients
) {
3066 uNode
-> uplink
-> max_clients
= uNode
-> uplink
-> clients
;
3068 uNode
-> num_local
= base64toint ( numeric
+ strlen ( uNode
-> uplink
-> numeric
), 3 ) & uNode
-> uplink
-> num_mask
;
3069 uNode
-> uplink
-> users
[ uNode
-> num_local
] = uNode
;
3070 mod_usermode ( uNode
, modes
);
3072 uNode
-> modes
|= FLAGS_DUMMY
;
3074 set_geoip_info ( uNode
);
3079 dict_insert ( clients
, uNode
-> nick
, uNode
);
3080 if ( dict_size ( clients
) > max_clients
) {
3081 max_clients
= dict_size ( clients
);
3082 max_clients_time
= now
;
3086 for ( n
= 0 ; ( n
< nuf_used
) && ! uNode
-> dead
; n
++)
3089 if (( uNode
-> loc
== 1 ) && ( uNode
-> handle_info
))
3090 send_func_list ( uNode
);
3095 /* removes user from it's server's hash table and nick hash table */
3097 DelUser ( struct userNode
* user
, struct userNode
* killer
, int announce
, const char * why
)
3103 /* mark them as dead, in case anybody cares */
3106 /* remove pending adduser commands */
3107 wipe_adduser_pending ( NULL
, user
);
3109 /* remove user from all channels */
3110 while ( user
-> channels
. used
> 0 )
3111 DelChannelUser ( user
, user
-> channels
. list
[ user
-> channels
. used
- 1 ]-> channel
, NULL
, 0 );
3113 /* Call these in reverse order so ChanServ can update presence
3114 information before NickServ nukes the handle_info. */
3115 for ( n
= duf_used
; n
> 0 ; )
3116 duf_list
[-- n
]( user
, killer
, why
);
3118 user
-> uplink
-> clients
--;
3119 user
-> uplink
-> users
[ user
-> num_local
] = NULL
;
3121 userList_remove (& curr_opers
, user
);
3122 /* remove from global dictionary, but not if after a collide */
3123 if ( user
== dict_find ( clients
, user
-> nick
, NULL
))
3124 dict_remove ( clients
, user
-> nick
);
3126 if ( IsInvisible ( user
))
3131 irc_quit ( user
, why
);
3133 irc_kill ( killer
, user
, why
);
3136 if ( IsLocal ( user
)) {
3137 unsigned int num
= user
-> num_local
;
3138 if ( num
< num_privmsg_funcs
)
3139 privmsg_funcs
[ num
] = NULL
;
3140 if ( num
< num_notice_funcs
)
3141 notice_funcs
[ num
] = NULL
;
3144 modeList_clean (& user
-> channels
);
3146 /* Clean up version data */
3147 if ( user
-> version_reply
) {
3148 free ( user
-> version_reply
);
3149 user
-> version_reply
= NULL
;
3158 /* clean up geoip data if any */
3159 if ( user
-> country_code
) free ( user
-> country_code
);
3160 if ( user
-> city
) free ( user
-> city
);
3161 if ( user
-> region
) free ( user
-> region
);
3162 if ( user
-> postal_code
) free ( user
-> postal_code
);
3164 /* We don't free them, in case we try to privmsg them or something
3165 * (like when a stupid oper kills themself). We just put them onto
3166 * a list of clients that get freed after processing each line.
3168 if ( dead_users
. size
)
3169 userList_append (& dead_users
, user
);
3174 static void call_oper_funcs ( struct userNode
* user
);
3176 void mod_usermode ( struct userNode
* user
, const char * mode_change
) {
3178 const char * word
= mode_change
;
3180 if (! user
|| ! mode_change
)
3183 call_user_mode_funcs ( user
, mode_change
);
3185 while (* word
!= ' ' && * word
) word
++;
3186 while (* word
== ' ' ) word
++;
3188 #define do_user_mode(FLAG) do { if (add) user->modes |= FLAG; else user->modes &= ~FLAG; } while (0)
3189 switch (* mode_change
++) {
3190 case 0 : case ' ' : return ;
3191 case '+' : add
= 1 ; break ;
3192 case '-' : add
= 0 ; break ;
3194 do_user_mode ( FLAGS_OPER
);
3196 userList_remove (& curr_opers
, user
);
3197 } else if (! userList_contains (& curr_opers
, user
)) {
3198 userList_append (& curr_opers
, user
);
3199 call_oper_funcs ( user
);
3202 case 'O' : do_user_mode ( FLAGS_LOCOP
); break ;
3203 case 'i' : do_user_mode ( FLAGS_INVISIBLE
);
3209 case 'w' : do_user_mode ( FLAGS_WALLOP
); break ;
3210 case 'd' : do_user_mode ( FLAGS_DEAF
); break ;
3211 case 'k' : do_user_mode ( FLAGS_SERVICE
); break ;
3212 case 'g' : do_user_mode ( FLAGS_GLOBAL
); break ;
3213 case 'B' : do_user_mode ( FLAGS_BOT
); break ;
3214 case 'n' : do_user_mode ( FLAGS_HIDECHANS
); break ;
3215 case 'I' : do_user_mode ( FLAGS_HIDEIDLE
); break ;
3216 case 'X' : do_user_mode ( FLAGS_XTRAOP
); break ;
3217 case 'C' : do_user_mode ( FLAGS_CLOAKHOST
);
3219 char cloakhost
[ MAXLEN
];
3221 for ( ii
= 0 ; (* word
!= ' ' ) && (* word
!= '\0' ); )
3222 cloakhost
[ ii
++] = * word
++;
3224 while (* word
== ' ' )
3226 safestrncpy ( user
-> crypthost
, cloakhost
, sizeof ( user
-> crypthost
));
3229 case 'c' : do_user_mode ( FLAGS_CLOAKIP
);
3231 char cloakip
[ MAXLEN
];
3233 for ( ii
= 0 ; (* word
!= ' ' ) && (* word
!= '\0' ); )
3234 cloakip
[ ii
++] = * word
++;
3236 while (* word
== ' ' )
3238 safestrncpy ( user
-> cryptip
, cloakip
, sizeof ( user
-> cryptip
));
3241 // sethost - reed/apples
3242 // case 'h': do_user_mode(FLAGS_HELPER); break;
3243 // I check if there's an 'h' in the first part, and if there,
3244 // then everything after the space becomes their new host.
3245 case 'h' : do_user_mode ( FLAGS_SETHOST
);
3247 char sethost
[ MAXLEN
];
3249 for ( ii
= 0 ; (* word
!= ' ' ) && (* word
!= '\0' ); )
3250 sethost
[ ii
++] = * word
++;
3252 while (* word
== ' ' )
3254 safestrncpy ( user
-> sethost
, sethost
, sizeof ( user
-> sethost
));
3257 case 'x' : do_user_mode ( FLAGS_HIDDEN_HOST
); break ;
3262 for ( ii
= 0 ; (* word
!= ' ' ) && (* word
!= '\0' ); )
3263 tag
[ ii
++] = * word
++;
3265 while (* word
== ' ' )
3267 call_account_func ( user
, tag
);
3274 for ( ii
= 0 ; (* word
!= ' ' ) && (* word
!= '\0' ); )
3275 host
[ ii
++] = * word
++;
3277 while (* word
== ' ' )
3279 assign_fakehost ( user
, host
, 0 );
3288 keyncpy ( char output
[], char input
[], size_t output_size
)
3292 if ( input
[ 0 ] == ':' )
3298 for ( ii
= 0 ; ( ii
+ 1 < output_size
) && ( input
[ ii
] != '\0' ); ++ ii
)
3300 output
[ ii
] = input
[ ii
];
3307 struct mod_chanmode
*
3308 mod_chanmode_parse ( struct chanNode
* channel
, char ** modes
, unsigned int argc
, unsigned int flags
, short base_oplevel
)
3310 struct mod_chanmode
* change
;
3311 unsigned int ii
, in_arg
, ch_arg
, add
;
3315 if (!( change
= mod_chanmode_alloc ( argc
- 1 )))
3318 for ( ii
= ch_arg
= 0 , in_arg
= add
= 1 ;
3319 ( modes
[ 0 ][ ii
] != '\0' ) && ( modes
[ 0 ][ ii
] != ' ' );
3321 switch ( modes
[ 0 ][ ii
]) {
3328 #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)
3329 case 'C' : do_chan_mode ( MODE_NOCTCPS
); break ;
3330 case 'D' : do_chan_mode ( MODE_DELAYJOINS
); break ;
3331 case 'c' : do_chan_mode ( MODE_NOCOLORS
); break ;
3332 case 'i' : do_chan_mode ( MODE_INVITEONLY
); break ;
3333 case 'm' : do_chan_mode ( MODE_MODERATED
); break ;
3334 case 'n' : do_chan_mode ( MODE_NOPRIVMSGS
); break ;
3335 case 'p' : do_chan_mode ( MODE_PRIVATE
); break ;
3336 case 'r' : do_chan_mode ( MODE_REGONLY
); break ;
3337 case 's' : do_chan_mode ( MODE_SECRET
); break ;
3338 case 't' : do_chan_mode ( MODE_TOPICLIMIT
); break ;
3339 case 'S' : do_chan_mode ( MODE_STRIPCOLOR
); break ;
3340 case 'M' : do_chan_mode ( MODE_MODUNREG
); break ;
3341 case 'N' : do_chan_mode ( MODE_NONOTICE
); break ;
3342 case 'Q' : do_chan_mode ( MODE_NOQUITMSGS
); break ;
3343 case 'T' : do_chan_mode ( MODE_NOAMSG
); break ;
3344 case 'O' : do_chan_mode ( MODE_OPERSONLY
); break ;
3345 case 'a' : do_chan_mode ( MODE_ADMINSONLY
); break ;
3346 case 'Z' : do_chan_mode ( MODE_SSLONLY
); break ;
3347 case 'L' : do_chan_mode ( MODE_HIDEMODE
); break ;
3349 if (!( flags
& MCP_REGISTERED
)) {
3350 do_chan_mode ( MODE_REGISTERED
);
3352 mod_chanmode_free ( change
);
3361 change
-> modes_set
|= MODE_LIMIT
;
3362 change
-> new_limit
= atoi ( modes
[ in_arg
++]);
3364 change
-> modes_set
&= ~ MODE_LIMIT
;
3365 change
-> modes_clear
|= MODE_LIMIT
;
3370 if (( in_arg
>= argc
)
3371 || keyncpy ( change
-> new_key
, modes
[ in_arg
++], sizeof ( change
-> new_key
)))
3373 change
-> modes_set
|= MODE_KEY
;
3375 change
-> modes_clear
|= MODE_KEY
;
3376 if (!( flags
& MCP_KEY_FREE
)) {
3386 if (( in_arg
>= argc
)
3387 || keyncpy ( change
-> new_upass
, modes
[ in_arg
++], sizeof ( change
-> new_upass
)))
3389 change
-> modes_set
|= MODE_UPASS
;
3391 change
-> modes_clear
|= MODE_UPASS
;
3392 if (!( flags
& MCP_UPASS_FREE
)) {
3401 if (( in_arg
>= argc
)
3402 || keyncpy ( change
-> new_upass
, modes
[ in_arg
++], sizeof ( change
-> new_upass
)))
3403 change
-> modes_set
|= MODE_APASS
;
3405 change
-> modes_clear
|= MODE_APASS
;
3406 if (!( flags
& MCP_APASS_FREE
)) {
3414 if (!( flags
& MCP_ALLOW_OVB
))
3418 change
-> args
[ ch_arg
]. mode
= MODE_BAN
;
3420 change
-> args
[ ch_arg
]. mode
|= MODE_REMOVE
;
3421 change
-> args
[ ch_arg
++]. u
. hostmask
= modes
[ in_arg
++];
3424 if (!( flags
& MCP_ALLOW_OVB
))
3428 change
-> args
[ ch_arg
]. mode
= MODE_EXEMPT
;
3430 change
-> args
[ ch_arg
]. mode
|= MODE_REMOVE
;
3431 change
-> args
[ ch_arg
++]. u
. hostmask
= modes
[ in_arg
++];
3433 case 'o' : case 'h' : case 'v' :
3435 struct userNode
* victim
;
3441 oplevel_str
= strchr ( modes
[ in_arg
], ':' );
3444 /* XXYYY M #channel +o XXYYY:<oplevel> */
3445 * oplevel_str
++ = '\0' ;
3446 oplevel
= parse_oplevel ( oplevel_str
);
3447 if ( oplevel
<= base_oplevel
&& !( flags
& MCP_FROM_SERVER
))
3448 oplevel
= base_oplevel
+ 1 ;
3450 else if ( channel
-> modes
& MODE_UPASS
)
3451 oplevel
= base_oplevel
+ 1 ;
3455 /* Check that oplevel is within bounds. */
3456 if ( oplevel
> MAXOPLEVEL
)
3457 oplevel
= MAXOPLEVEL
;
3459 if (!( flags
& MCP_ALLOW_OVB
))
3464 if ( modes
[ 0 ][ ii
] == 'o' )
3465 change
-> args
[ ch_arg
]. mode
= MODE_CHANOP
;
3466 else if ( modes
[ 0 ][ ii
] == 'h' )
3467 change
-> args
[ ch_arg
]. mode
= MODE_HALFOP
;
3468 else if ( modes
[ 0 ][ ii
] == 'v' )
3469 change
-> args
[ ch_arg
]. mode
= MODE_VOICE
;
3472 change
-> args
[ ch_arg
]. mode
|= MODE_REMOVE
;
3473 if ( flags
& MCP_FROM_SERVER
)
3474 victim
= GetUserN ( modes
[ in_arg
++]);
3476 victim
= GetUserH ( modes
[ in_arg
++]);
3479 if (( change
-> args
[ ch_arg
]. u
. member
= GetUserMode ( channel
, victim
)))
3481 /* Apply the oplevel change */
3482 change
-> args
[ ch_arg
]. u
. member
-> oplevel
= oplevel
;
3488 if (!( flags
& MCP_FROM_SERVER
))
3493 change
-> argc
= ch_arg
; /* in case any turned out to be ignored */
3494 if ( change
-> modes_set
& MODE_SECRET
) {
3495 change
-> modes_set
&= ~( MODE_PRIVATE
);
3496 change
-> modes_clear
|= MODE_PRIVATE
;
3497 } else if ( change
-> modes_set
& MODE_PRIVATE
) {
3498 change
-> modes_set
&= ~( MODE_SECRET
);
3499 change
-> modes_clear
|= MODE_SECRET
;
3503 mod_chanmode_free ( change
);
3507 struct chanmode_buffer
{
3510 struct chanNode
* channel
;
3511 struct userNode
* actor
;
3512 unsigned int modes_used
;
3513 unsigned int args_used
;
3515 unsigned int is_add
: 1 ;
3516 unsigned int is_chanop
: 1 ;
3520 mod_chanmode_append ( struct chanmode_buffer
* buf
, char ch
, const char * arg
)
3522 size_t arg_len
= strlen ( arg
);
3523 if ( buf
-> modes_used
> ( MAXMODEPARAMS
) ||
3524 buf
-> modes_used
+ buf
-> args_used
+ buf
-> chname_len
+ arg_len
> 450 ) {
3525 memcpy ( buf
-> modes
+ buf
-> modes_used
, buf
-> args
, buf
-> args_used
);
3526 buf
-> modes
[ buf
-> modes_used
+ buf
-> args_used
] = '\0' ;
3527 irc_mode (( buf
-> is_chanop
? buf
-> actor
: NULL
), buf
-> channel
, buf
-> modes
);
3528 buf
-> modes
[ 0 ] = buf
-> is_add
? '+' : '-' ;
3529 buf
-> modes_used
= 1 ;
3532 buf
-> modes
[ buf
-> modes_used
++] = ch
;
3533 buf
-> args
[ buf
-> args_used
++] = ' ' ;
3534 memcpy ( buf
-> args
+ buf
-> args_used
, arg
, arg_len
);
3535 buf
-> args_used
+= arg_len
;
3539 mod_chanmode_announce ( struct userNode
* who
, struct chanNode
* channel
, struct mod_chanmode
* change
)
3541 struct chanmode_buffer chbuf
;
3543 struct modeNode
* mn
;
3544 char int_buff
[ 32 ], mode
= '\0' ;
3546 assert ( change
-> argc
<= change
-> alloc_argc
);
3547 memset (& chbuf
, 0 , sizeof ( chbuf
));
3548 chbuf
. channel
= channel
;
3550 chbuf
. chname_len
= strlen ( channel
-> name
);
3552 mn
= GetUserMode ( channel
, who
);
3553 if (( mn
&& ( mn
-> modes
& MODE_CHANOP
)) || off_channel
)
3554 chbuf
. is_chanop
= 1 ;
3556 /* First remove modes */
3558 if ( change
-> modes_clear
) {
3560 chbuf
. modes
[ chbuf
. modes_used
++] = mode
= '-' ;
3561 #define DO_MODE_CHAR(BIT, CHAR) if (change->modes_clear & MODE_##BIT) chbuf.modes[chbuf.modes_used++] = CHAR
3562 DO_MODE_CHAR ( PRIVATE
, 'p' );
3563 DO_MODE_CHAR ( SECRET
, 's' );
3564 DO_MODE_CHAR ( MODERATED
, 'm' );
3565 DO_MODE_CHAR ( TOPICLIMIT
, 't' );
3566 DO_MODE_CHAR ( INVITEONLY
, 'i' );
3567 DO_MODE_CHAR ( NOPRIVMSGS
, 'n' );
3568 DO_MODE_CHAR ( LIMIT
, 'l' );
3569 DO_MODE_CHAR ( DELAYJOINS
, 'D' );
3570 DO_MODE_CHAR ( REGONLY
, 'r' );
3571 DO_MODE_CHAR ( NOCOLORS
, 'c' );
3572 DO_MODE_CHAR ( NOCTCPS
, 'C' );
3573 DO_MODE_CHAR ( STRIPCOLOR
, 'S' );
3574 DO_MODE_CHAR ( MODUNREG
, 'M' );
3575 DO_MODE_CHAR ( NONOTICE
, 'N' );
3576 DO_MODE_CHAR ( NOQUITMSGS
, 'Q' );
3577 DO_MODE_CHAR ( NOAMSG
, 'T' );
3578 DO_MODE_CHAR ( OPERSONLY
, 'O' );
3579 DO_MODE_CHAR ( REGISTERED
, 'z' );
3580 DO_MODE_CHAR ( SSLONLY
, 'Z' );
3581 DO_MODE_CHAR ( HIDEMODE
, 'L' );
3583 if ( change
-> modes_clear
& channel
-> modes
& MODE_KEY
)
3584 mod_chanmode_append (& chbuf
, 'k' , channel
-> key
);
3585 if ( change
-> modes_clear
& channel
-> modes
& MODE_UPASS
)
3586 mod_chanmode_append (& chbuf
, 'U' , channel
-> upass
);
3587 if ( change
-> modes_clear
& channel
-> modes
& MODE_APASS
)
3588 mod_chanmode_append (& chbuf
, 'A' , channel
-> apass
);
3590 for ( arg
= 0 ; arg
< change
-> argc
; ++ arg
) {
3591 if (!( change
-> args
[ arg
]. mode
& MODE_REMOVE
))
3594 chbuf
. modes
[ chbuf
. modes_used
++] = mode
= '-' ;
3595 switch ( change
-> args
[ arg
]. mode
& ~ MODE_REMOVE
) {
3597 mod_chanmode_append (& chbuf
, 'b' , change
-> args
[ arg
]. u
. hostmask
);
3600 mod_chanmode_append (& chbuf
, 'e' , change
-> args
[ arg
]. u
. hostmask
);
3603 if ( change
-> args
[ arg
]. mode
& MODE_CHANOP
)
3604 mod_chanmode_append (& chbuf
, 'o' , change
-> args
[ arg
]. u
. member
-> user
-> numeric
);
3605 if ( change
-> args
[ arg
]. mode
& MODE_HALFOP
)
3606 mod_chanmode_append (& chbuf
, 'h' , change
-> args
[ arg
]. u
. member
-> user
-> numeric
);
3607 if ( change
-> args
[ arg
]. mode
& MODE_VOICE
)
3608 mod_chanmode_append (& chbuf
, 'v' , change
-> args
[ arg
]. u
. member
-> user
-> numeric
);
3615 if ( change
-> modes_set
) {
3617 chbuf
. modes
[ chbuf
. modes_used
++] = mode
= '+' ;
3618 #define DO_MODE_CHAR(BIT, CHAR) if (change->modes_set & MODE_##BIT) chbuf.modes[chbuf.modes_used++] = CHAR
3619 DO_MODE_CHAR ( PRIVATE
, 'p' );
3620 DO_MODE_CHAR ( SECRET
, 's' );
3621 DO_MODE_CHAR ( MODERATED
, 'm' );
3622 DO_MODE_CHAR ( TOPICLIMIT
, 't' );
3623 DO_MODE_CHAR ( INVITEONLY
, 'i' );
3624 DO_MODE_CHAR ( NOPRIVMSGS
, 'n' );
3625 DO_MODE_CHAR ( DELAYJOINS
, 'D' );
3626 DO_MODE_CHAR ( REGONLY
, 'r' );
3627 DO_MODE_CHAR ( NOCOLORS
, 'c' );
3628 DO_MODE_CHAR ( NOCTCPS
, 'C' );
3629 DO_MODE_CHAR ( STRIPCOLOR
, 'S' );
3630 DO_MODE_CHAR ( MODUNREG
, 'M' );
3631 DO_MODE_CHAR ( NONOTICE
, 'N' );
3632 DO_MODE_CHAR ( NOQUITMSGS
, 'Q' );
3633 DO_MODE_CHAR ( NOAMSG
, 'T' );
3634 DO_MODE_CHAR ( OPERSONLY
, 'O' );
3635 DO_MODE_CHAR ( REGISTERED
, 'z' );
3636 DO_MODE_CHAR ( SSLONLY
, 'Z' );
3637 DO_MODE_CHAR ( HIDEMODE
, 'L' );
3639 if ( change
-> modes_set
& MODE_KEY
)
3640 mod_chanmode_append (& chbuf
, 'k' , change
-> new_key
);
3641 if ( change
-> modes_set
& MODE_UPASS
)
3642 mod_chanmode_append (& chbuf
, 'U' , change
-> new_upass
);
3643 if ( change
-> modes_set
& MODE_APASS
)
3644 mod_chanmode_append (& chbuf
, 'A' , change
-> new_apass
);
3645 if ( change
-> modes_set
& MODE_LIMIT
) {
3646 sprintf ( int_buff
, " %d " , change
-> new_limit
);
3647 mod_chanmode_append (& chbuf
, 'l' , int_buff
);
3650 for ( arg
= 0 ; arg
< change
-> argc
; ++ arg
) {
3651 if ( change
-> args
[ arg
]. mode
& MODE_REMOVE
)
3654 chbuf
. modes
[ chbuf
. modes_used
++] = mode
= '+' ;
3655 switch ( change
-> args
[ arg
]. mode
) {
3657 mod_chanmode_append (& chbuf
, 'b' , change
-> args
[ arg
]. u
. hostmask
);
3660 mod_chanmode_append (& chbuf
, 'e' , change
-> args
[ arg
]. u
. hostmask
);
3663 if ( change
-> args
[ arg
]. mode
& MODE_CHANOP
)
3664 mod_chanmode_append (& chbuf
, 'o' , change
-> args
[ arg
]. u
. member
-> user
-> numeric
);
3665 if ( change
-> args
[ arg
]. mode
& MODE_HALFOP
)
3666 mod_chanmode_append (& chbuf
, 'h' , change
-> args
[ arg
]. u
. member
-> user
-> numeric
);
3667 if ( change
-> args
[ arg
]. mode
& MODE_VOICE
)
3668 mod_chanmode_append (& chbuf
, 'v' , change
-> args
[ arg
]. u
. member
-> user
-> numeric
);
3673 /* Flush the buffer and apply changes locally */
3674 if ( chbuf
. modes_used
> 0 ) {
3675 memcpy ( chbuf
. modes
+ chbuf
. modes_used
, chbuf
. args
, chbuf
. args_used
);
3676 chbuf
. modes
[ chbuf
. modes_used
+ chbuf
. args_used
] = '\0' ;
3677 irc_mode (( chbuf
. is_chanop
? chbuf
. actor
: NULL
), chbuf
. channel
, chbuf
. modes
);
3679 mod_chanmode_apply ( who
, channel
, change
);
3683 mod_chanmode_format ( struct mod_chanmode
* change
, char * outbuff
)
3685 unsigned int used
= 0 ;
3686 assert ( change
-> argc
<= change
-> alloc_argc
);
3687 if ( change
-> modes_clear
) {
3688 outbuff
[ used
++] = '-' ;
3689 #define DO_MODE_CHAR(BIT, CHAR) if (change->modes_clear & MODE_##BIT) outbuff[used++] = CHAR
3690 DO_MODE_CHAR ( PRIVATE
, 'p' );
3691 DO_MODE_CHAR ( SECRET
, 's' );
3692 DO_MODE_CHAR ( MODERATED
, 'm' );
3693 DO_MODE_CHAR ( TOPICLIMIT
, 't' );
3694 DO_MODE_CHAR ( INVITEONLY
, 'i' );
3695 DO_MODE_CHAR ( NOPRIVMSGS
, 'n' );
3696 DO_MODE_CHAR ( LIMIT
, 'l' );
3697 DO_MODE_CHAR ( KEY
, 'k' );
3698 DO_MODE_CHAR ( UPASS
, 'U' );
3699 DO_MODE_CHAR ( APASS
, 'A' );
3700 DO_MODE_CHAR ( DELAYJOINS
, 'D' );
3701 DO_MODE_CHAR ( REGONLY
, 'r' );
3702 DO_MODE_CHAR ( NOCOLORS
, 'c' );
3703 DO_MODE_CHAR ( NOCTCPS
, 'C' );
3704 DO_MODE_CHAR ( STRIPCOLOR
, 'S' );
3705 DO_MODE_CHAR ( MODUNREG
, 'M' );
3706 DO_MODE_CHAR ( NONOTICE
, 'N' );
3707 DO_MODE_CHAR ( NOQUITMSGS
, 'Q' );
3708 DO_MODE_CHAR ( NOAMSG
, 'T' );
3709 DO_MODE_CHAR ( OPERSONLY
, 'O' );
3710 DO_MODE_CHAR ( REGISTERED
, 'z' );
3711 DO_MODE_CHAR ( SSLONLY
, 'Z' );
3712 DO_MODE_CHAR ( HIDEMODE
, 'L' );
3715 if ( change
-> modes_set
) {
3716 outbuff
[ used
++] = '+' ;
3717 #define DO_MODE_CHAR(BIT, CHAR) if (change->modes_set & MODE_##BIT) outbuff[used++] = CHAR
3718 DO_MODE_CHAR ( PRIVATE
, 'p' );
3719 DO_MODE_CHAR ( SECRET
, 's' );
3720 DO_MODE_CHAR ( MODERATED
, 'm' );
3721 DO_MODE_CHAR ( TOPICLIMIT
, 't' );
3722 DO_MODE_CHAR ( INVITEONLY
, 'i' );
3723 DO_MODE_CHAR ( NOPRIVMSGS
, 'n' );
3724 DO_MODE_CHAR ( DELAYJOINS
, 'D' );
3725 DO_MODE_CHAR ( REGONLY
, 'r' );
3726 DO_MODE_CHAR ( NOCOLORS
, 'c' );
3727 DO_MODE_CHAR ( NOCTCPS
, 'C' );
3728 DO_MODE_CHAR ( STRIPCOLOR
, 'S' );
3729 DO_MODE_CHAR ( MODUNREG
, 'M' );
3730 DO_MODE_CHAR ( NONOTICE
, 'N' );
3731 DO_MODE_CHAR ( NOQUITMSGS
, 'Q' );
3732 DO_MODE_CHAR ( NOAMSG
, 'T' );
3733 DO_MODE_CHAR ( OPERSONLY
, 'O' );
3734 DO_MODE_CHAR ( REGISTERED
, 'z' );
3735 DO_MODE_CHAR ( SSLONLY
, 'Z' );
3736 DO_MODE_CHAR ( HIDEMODE
, 'L' );
3738 switch ( change
-> modes_set
& ( MODE_KEY
| MODE_LIMIT
| MODE_APASS
| MODE_UPASS
)) {
3739 /* Doing this implementation has been a pain in the arse, I hope I didn't forget a possible combination */
3740 case MODE_KEY
| MODE_LIMIT
| MODE_APASS
| MODE_UPASS
:
3741 used
+= sprintf ( outbuff
+ used
, "lkAU %d %s %s %s " , change
-> new_limit
, change
-> new_key
, change
-> new_apass
, change
-> new_upass
);
3744 case MODE_KEY
| MODE_LIMIT
| MODE_APASS
:
3745 used
+= sprintf ( outbuff
+ used
, "lkA %d %s %s " , change
-> new_limit
, change
-> new_key
, change
-> new_apass
);
3747 case MODE_KEY
| MODE_LIMIT
| MODE_UPASS
:
3748 used
+= sprintf ( outbuff
+ used
, "lkU %d %s %s " , change
-> new_limit
, change
-> new_key
, change
-> new_upass
);
3750 case MODE_KEY
| MODE_APASS
| MODE_UPASS
:
3751 used
+= sprintf ( outbuff
+ used
, "kAU %s %s %s " , change
-> new_key
, change
-> new_apass
, change
-> new_upass
);
3754 case MODE_KEY
| MODE_APASS
:
3755 used
+= sprintf ( outbuff
+ used
, "kA %s %s " , change
-> new_key
, change
-> new_apass
);
3757 case MODE_KEY
| MODE_UPASS
:
3758 used
+= sprintf ( outbuff
+ used
, "kU %s %s " , change
-> new_key
, change
-> new_upass
);
3760 case MODE_KEY
| MODE_LIMIT
:
3761 used
+= sprintf ( outbuff
+ used
, "lk %d %s " , change
-> new_limit
, change
-> new_key
);
3764 case MODE_LIMIT
| MODE_UPASS
:
3765 used
+= sprintf ( outbuff
+ used
, "lU %d %s " , change
-> new_limit
, change
-> new_upass
);
3767 case MODE_LIMIT
| MODE_APASS
:
3768 used
+= sprintf ( outbuff
+ used
, "lA %d %s " , change
-> new_limit
, change
-> new_apass
);
3770 case MODE_APASS
| MODE_UPASS
:
3771 used
+= sprintf ( outbuff
+ used
, "AU %s %s " , change
-> new_apass
, change
-> new_upass
);
3773 case MODE_LIMIT
| MODE_APASS
| MODE_UPASS
:
3774 used
+= sprintf ( outbuff
+ used
, "lAU %d %s %s " , change
-> new_limit
, change
-> new_apass
, change
-> new_upass
);
3778 used
+= sprintf ( outbuff
+ used
, "A %s " , change
-> new_apass
);
3781 used
+= sprintf ( outbuff
+ used
, "U %s " , change
-> new_upass
);
3784 used
+= sprintf ( outbuff
+ used
, "k %s " , change
-> new_key
);
3787 used
+= sprintf ( outbuff
+ used
, "l %d " , change
-> new_limit
);
3796 clear_chanmode ( struct chanNode
* channel
, const char * modes
)
3798 unsigned int cleared
;
3800 for ( cleared
= 0 ; * modes
; modes
++) {
3802 case 'o' : cleared
|= MODE_CHANOP
; break ;
3803 case 'h' : cleared
|= MODE_HALFOP
; break ;
3804 case 'v' : cleared
|= MODE_VOICE
; break ;
3805 case 'p' : cleared
|= MODE_PRIVATE
; break ;
3806 case 's' : cleared
|= MODE_SECRET
; break ;
3807 case 'm' : cleared
|= MODE_MODERATED
; break ;
3808 case 't' : cleared
|= MODE_TOPICLIMIT
; break ;
3809 case 'i' : cleared
|= MODE_INVITEONLY
; break ;
3810 case 'n' : cleared
|= MODE_NOPRIVMSGS
; break ;
3812 cleared
|= MODE_KEY
;
3813 channel
-> key
[ 0 ] = '\0' ;
3816 cleared
|= MODE_APASS
;
3817 channel
-> apass
[ 0 ] = '\0' ;
3820 cleared
|= MODE_UPASS
;
3821 channel
-> upass
[ 0 ] = '\0' ;
3824 cleared
|= MODE_LIMIT
;
3827 case 'b' : cleared
|= MODE_BAN
; break ;
3828 case 'e' : cleared
|= MODE_EXEMPT
; break ;
3829 case 'D' : cleared
|= MODE_DELAYJOINS
; break ;
3830 case 'r' : cleared
|= MODE_REGONLY
; break ;
3831 case 'c' : cleared
|= MODE_NOCOLORS
; break ;
3832 case 'C' : cleared
|= MODE_NOCTCPS
; break ;
3833 case 'S' : cleared
|= MODE_STRIPCOLOR
; break ;
3834 case 'M' : cleared
|= MODE_MODUNREG
; break ;
3835 case 'N' : cleared
|= MODE_NONOTICE
; break ;
3836 case 'Q' : cleared
|= MODE_NOQUITMSGS
; break ;
3837 case 'T' : cleared
|= MODE_NOAMSG
; break ;
3838 case 'O' : cleared
|= MODE_OPERSONLY
; break ;
3839 case 'a' : cleared
|= MODE_ADMINSONLY
; break ;
3840 case 'z' : cleared
|= MODE_REGISTERED
; break ;
3841 case 'Z' : cleared
|= MODE_SSLONLY
; break ;
3842 case 'L' : cleared
|= MODE_HIDEMODE
; break ;
3849 /* Remove simple modes. */
3850 channel
-> modes
&= ~ cleared
;
3852 /* If removing bans, kill 'em all. */
3853 if (( cleared
& MODE_BAN
) && channel
-> banlist
. used
) {
3855 for ( i
= 0 ; i
< channel
-> banlist
. used
; i
++)
3856 free ( channel
-> banlist
. list
[ i
]);
3857 channel
-> banlist
. used
= 0 ;
3860 /* If removing exempts, kill 'em all. */
3861 if (( cleared
& MODE_EXEMPT
) && channel
-> exemptlist
. used
) {
3863 for ( i
= 0 ; i
< channel
-> exemptlist
. used
; i
++)
3864 free ( channel
-> exemptlist
. list
[ i
]);
3865 channel
-> exemptlist
. used
= 0 ;
3868 /* Removed member modes. */
3869 if (( cleared
& ( MODE_CHANOP
| MODE_HALFOP
| MODE_VOICE
)) && channel
-> members
. used
) {
3870 int mask
= ~( cleared
& ( MODE_CHANOP
| MODE_HALFOP
| MODE_VOICE
));
3873 for ( i
= 0 ; i
< channel
-> members
. used
; i
++)
3874 channel
-> members
. list
[ i
]-> modes
&= mask
;
3881 reg_privmsg_func ( struct userNode
* user
, privmsg_func_t handler
)
3883 unsigned int numeric
= user
-> num_local
;
3884 if ( numeric
>= num_privmsg_funcs
) {
3885 int newnum
= numeric
+ 8 , ii
;
3886 privmsg_funcs
= realloc ( privmsg_funcs
, newnum
* sizeof ( privmsg_func_t
));
3887 for ( ii
= num_privmsg_funcs
; ii
< newnum
; ++ ii
)
3888 privmsg_funcs
[ ii
] = NULL
;
3889 num_privmsg_funcs
= newnum
;
3891 if ( privmsg_funcs
[ numeric
])
3892 log_module ( MAIN_LOG
, LOG_WARNING
, "re-registering new privmsg handler for numeric %d " , numeric
);
3893 privmsg_funcs
[ numeric
] = handler
;
3897 unreg_privmsg_func ( struct userNode
* user
)
3899 if (! IsLocal ( user
) || user
-> num_local
>= num_privmsg_funcs
)
3900 return ; /* this really only works with users */
3902 privmsg_funcs
[ user
-> num_local
] = NULL
;
3907 reg_notice_func ( struct userNode
* user
, privmsg_func_t handler
)
3909 unsigned int numeric
= user
-> num_local
;
3910 if ( numeric
>= num_notice_funcs
) {
3911 int newnum
= numeric
+ 8 , ii
;
3912 notice_funcs
= realloc ( notice_funcs
, newnum
* sizeof ( privmsg_func_t
));
3913 for ( ii
= num_privmsg_funcs
; ii
< newnum
; ++ ii
)
3914 privmsg_funcs
[ ii
] = NULL
;
3915 num_notice_funcs
= newnum
;
3917 if ( notice_funcs
[ numeric
])
3918 log_module ( MAIN_LOG
, LOG_WARNING
, "re-registering new notice handler for numeric %d " , numeric
);
3919 notice_funcs
[ numeric
] = handler
;
3923 unreg_notice_func ( struct userNode
* user
)
3925 if (! IsLocal ( user
) || user
-> num_local
>= num_privmsg_funcs
)
3926 return ; /* this really only works with users */
3928 notice_funcs
[ user
-> num_local
] = NULL
;
3934 unsigned int i
, hop
, max_hop
= 1 ;
3937 /* burst (juped) servers, closest first (except self, which is sent already) */
3938 for ( i
= 0 ; i
< ArrayLength ( servers_num
); i
++)
3939 if ( servers_num
[ i
] && servers_num
[ i
]-> hops
> max_hop
)
3940 max_hop
= servers_num
[ i
]-> hops
;
3941 for ( hop
= 1 ; hop
<= max_hop
; hop
++) {
3942 for ( i
= 0 ; i
< ArrayLength ( servers_num
); i
++) {
3944 && ( servers_num
[ i
]-> hops
== hop
)
3945 && ( servers_num
[ i
] != self
-> uplink
))
3946 irc_server ( servers_num
[ i
]);
3950 /* burst local nicks */
3951 for ( i
= 0 ; i
<= self
-> num_mask
; i
++)
3953 irc_user ( self
-> users
[ i
]);
3955 /* build dict of unbursted channel names (just copy existing channels) */
3956 unbursted_channels
= dict_new ();
3957 for ( it
= dict_first ( channels
); it
; it
= iter_next ( it
))
3958 dict_insert ( unbursted_channels
, iter_key ( it
), iter_data ( it
));
3965 parse_oplevel ( char * str
)
3968 while ( isdigit (* str
))
3969 oplevel
= oplevel
* 10 + * str
++ - '0' ;