]>
jfr.im git - irc/evilnet/x3.git/blob - src/proto-p10.c
1 /* proto-p10.c - IRC protocol output
2 * Copyright 2000-2004 srvx Development Team
4 * This file is part of x3.
6 * x3 is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 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_ASLL "ASLL"
33 #define CMD_AWAY "AWAY"
34 #define CMD_BURST "BURST"
35 #define CMD_CLEARMODE "CLEARMODE"
36 #define CMD_CLOSE "CLOSE"
37 #define CMD_CNOTICE "CNOTICE"
38 #define CMD_CONNECT "CONNECT"
39 #define CMD_CPRIVMSG "CPRIVMSG"
40 #define CMD_CREATE "CREATE"
41 #define CMD_DESTRUCT "DESTRUCT"
42 #define CMD_DESYNCH "DESYNCH"
45 #define CMD_EOB "END_OF_BURST"
46 #define CMD_EOB_ACK "EOB_ACK"
47 #define CMD_ERROR "ERROR"
48 #define CMD_FAKEHOST "FAKE"
50 #define CMD_GLINE "GLINE"
51 #define CMD_HASH "HASH"
52 #define CMD_HELP "HELP"
53 #define CMD_INFO "INFO"
54 #define CMD_INVITE "INVITE"
55 #define CMD_ISON "ISON"
56 #define CMD_JOIN "JOIN"
57 #define CMD_JUPE "JUPE"
58 #define CMD_KICK "KICK"
59 #define CMD_KILL "KILL"
60 #define CMD_LINKS "LINKS"
61 #define CMD_LIST "LIST"
62 #define CMD_LUSERS "LUSERS"
64 #define CMD_MARK "MARK"
65 #define CMD_MODE "MODE"
66 #define CMD_MOTD "MOTD"
67 #define CMD_NAMES "NAMES"
68 #define CMD_NICK "NICK"
69 #define CMD_NOTICE "NOTICE"
70 #define CMD_OPER "OPER"
71 #define CMD_OPMODE "OPMODE"
72 #define CMD_PART "PART"
73 #define CMD_PASS "PASS"
74 #define CMD_PING "PING"
75 #define CMD_PONG "PONG"
76 #define CMD_POST "POST"
77 #define CMD_PRIVMSG "PRIVMSG"
78 #define CMD_PRIVS "PRIVS"
79 #define CMD_PROTO "PROTO"
80 #define CMD_QUIT "QUIT"
81 #define CMD_REHASH "REHASH"
82 #define CMD_RESET "RESET"
83 #define CMD_RESTART "RESTART"
84 #define CMD_RPING "RPING"
85 #define CMD_RPONG "RPONG"
86 #define CMD_SERVER "SERVER"
87 #define CMD_SERVLIST "SERVLIST"
88 #define CMD_SERVSET "SERVSET"
90 #define CMD_SETTIME "SETTIME"
91 #define CMD_SHUN "SHUN"
92 #define CMD_SILENCE "SILENCE"
93 #define CMD_SQUERY "SQUERY"
94 #define CMD_SQUIT "SQUIT"
95 #define CMD_STATS "STATS"
96 #define CMD_SVSJOIN "SVSJOIN"
97 #define CMD_SVSNICK "SVSNICK"
98 #define CMD_SVSPART "SVSPART"
99 #define CMD_SWHOIS "SWHOIS"
100 #define CMD_TIME "TIME"
101 #define CMD_TOPIC "TOPIC"
102 #define CMD_TRACE "TRACE"
103 #define CMD_UPING "UPING"
104 #define CMD_USER "USER"
105 #define CMD_USERHOST "USERHOST"
106 #define CMD_USERIP "USERIP"
107 #define CMD_VERSION "VERSION"
108 #define CMD_WALLCHOPS "WALLCHOPS"
109 #define CMD_WALLOPS "WALLOPS"
110 #define CMD_WALLHOPS "WALLHOPS"
111 #define CMD_WALLUSERS "WALLUSERS"
112 #define CMD_WALLVOICES "WALLVOICES"
113 #define CMD_WALLHOPS "WALLHOPS"
114 #define CMD_WHO "WHO"
115 #define CMD_WHOIS "WHOIS"
116 #define CMD_WHOWAS "WHOWAS"
118 /* Tokenized commands. */
119 #define TOK_ACCOUNT "AC"
120 #define TOK_ADMIN "AD"
121 #define TOK_ASLL "LL"
123 #define TOK_BURST "B"
124 #define TOK_CLEARMODE "CM"
125 #define TOK_CLOSE "CLOSE"
126 #define TOK_CNOTICE "CN"
127 #define TOK_CONNECT "CO"
128 #define TOK_CPRIVMSG "CP"
129 #define TOK_CREATE "C"
130 #define TOK_DESTRUCT "DE"
131 #define TOK_DESYNCH "DS"
132 #define TOK_DIE "DIE"
133 #define TOK_DNS "DNS"
135 #define TOK_EOB_ACK "EA"
136 #define TOK_ERROR "Y"
137 #define TOK_EXEMPT "EX"
138 #define TOK_FAKEHOST "FA"
139 #define TOK_GET "GET"
140 #define TOK_GLINE "GL"
141 #define TOK_HASH "HASH"
142 #define TOK_HELP "HELP"
144 #define TOK_INVITE "I"
145 #define TOK_ISON "ISON"
147 #define TOK_JUPE "JU"
150 #define TOK_LINKS "LI"
151 #define TOK_LIST "LIST"
152 #define TOK_LUSERS "LU"
153 #define TOK_MAP "MAP"
154 #define TOK_MARK "MK"
156 #define TOK_MOTD "MO"
157 #define TOK_NAMES "E"
159 #define TOK_NOTICE "O"
160 #define TOK_OPER "OPER"
161 #define TOK_OPMODE "OM"
163 #define TOK_PASS "PA"
166 #define TOK_POST "POST"
167 #define TOK_PRIVMSG "P"
168 #define TOK_PRIVS "PRIVS"
169 #define TOK_PROTO "PROTO"
171 #define TOK_REHASH "REHASH"
172 #define TOK_RESET "RESET"
173 #define TOK_RESTART "RESTART"
174 #define TOK_RPING "RI"
175 #define TOK_RPONG "RO"
176 #define TOK_SERVER "S"
177 #define TOK_SERVLIST "SERVSET"
178 #define TOK_SERVSET "SERVSET"
179 #define TOK_SET "SET"
180 #define TOK_SETTIME "SE"
181 #define TOK_SHUN "SU"
182 #define TOK_SILENCE "U"
183 #define TOK_SQUERY "SQUERY"
184 #define TOK_SQUIT "SQ"
185 #define TOK_STATS "R"
186 #define TOK_SVSJOIN "SJ"
187 #define TOK_SVSNICK "SN"
188 #define TOK_SVSPART "SP"
189 #define TOK_SWHOIS "SW"
190 #define TOK_TIME "TI"
191 #define TOK_TOPIC "T"
192 #define TOK_TRACE "TR"
193 #define TOK_UPING "UP"
194 #define TOK_USER "USER"
195 #define TOK_USERHOST "USERHOST"
196 #define TOK_USERIP "USERIP"
197 #define TOK_VERSION "V"
198 #define TOK_WALLCHOPS "WC"
199 #define TOK_WALLOPS "WA"
200 #define TOK_WALLHOPS "WH"
201 #define TOK_WALLUSERS "WU"
202 #define TOK_WALLVOICES "WV"
203 #define TOK_WALLHOPS "WH"
205 #define TOK_WHOIS "W"
206 #define TOK_WHOWAS "X"
208 /* Protocol messages; aliased to full commands or tokens depending
209 on compile-time configuration. ircu prefers tokens WITH THE
210 EXCEPTION OF THE SERVER AND PASS COMMANDS, which cannot be
211 tokenized, because clients' (ie. a linking server) commands are
212 only checked against the full command list.
214 #if defined(ENABLE_TOKENS)
215 #define TYPE(NAME) TOK_ ## NAME
216 #else /* !ENABLE_TOKENS */
217 #define TYPE(NAME) CMD_ ## NAME
218 #endif /* ENABLE_TOKENS */
220 #define P10_ACCOUNT TYPE(ACCOUNT)
221 #define P10_ADMIN TYPE(ADMIN)
222 #define P10_ASLL TYPE(ASLL)
223 #define P10_AWAY TYPE(AWAY)
224 #define P10_BURST TYPE(BURST)
225 #define P10_CLEARMODE TYPE(CLEARMODE)
226 #define P10_CLOSE TYPE(CLOSE)
227 #define P10_CNOTICE TYPE(CNOTICE)
228 #define P10_CONNECT TYPE(CONNECT)
229 #define P10_CPRIVMSG TYPE(CPRIVMSG)
230 #define P10_CREATE TYPE(CREATE)
231 #define P10_DESTRUCT TYPE(DESTRUCT)
232 #define P10_DESYNCH TYPE(DESYNCH)
233 #define P10_DIE TYPE(DIE)
234 #define P10_DNS TYPE(DNS)
235 #define P10_EOB TYPE(EOB)
236 #define P10_EOB_ACK TYPE(EOB_ACK)
237 #define P10_ERROR TYPE(ERROR)
238 #define P10_FAKEHOST TYPE(FAKEHOST)
239 #define P10_GET TYPE(GET)
240 #define P10_GLINE TYPE(GLINE)
241 #define P10_HASH TYPE(HASH)
242 #define P10_HELP TYPE(HELP)
243 #define P10_INFO TYPE(INFO)
244 #define P10_INVITE TYPE(INVITE)
245 #define P10_ISON TYPE(ISON)
246 #define P10_JOIN TYPE(JOIN)
247 #define P10_JUPE TYPE(JUPE)
248 #define P10_KICK TYPE(KICK)
249 #define P10_KILL TYPE(KILL)
250 #define P10_LINKS TYPE(LINKS)
251 #define P10_LIST TYPE(LIST)
252 #define P10_LUSERS TYPE(LUSERS)
253 #define P10_MAP TYPE(MAP)
254 #define P10_MARK TYPE(MARK)
255 #define P10_MODE TYPE(MODE)
256 #define P10_MOTD TYPE(MOTD)
257 #define P10_NAMES TYPE(NAMES)
258 #define P10_NICK TYPE(NICK)
259 #define P10_NOTICE TYPE(NOTICE)
260 #define P10_OPER TYPE(OPER)
261 #define P10_OPMODE TYPE(OPMODE)
262 #define P10_PART TYPE(PART)
263 #define P10_PASS CMD_PASS
264 #define P10_PING TYPE(PING)
265 #define P10_PONG TYPE(PONG)
266 #define P10_POST TYPE(POST)
267 #define P10_PRIVMSG TYPE(PRIVMSG)
268 #define P10_PRIVS TYPE(PRIVS)
269 #define P10_PROTO TYPE(PROTO)
270 #define P10_QUIT TYPE(QUIT)
271 #define P10_REHASH TYPE(REHASH)
272 #define P10_RESET TYPE(RESET)
273 #define P10_RESTART TYPE(RESTART)
274 #define P10_RPING TYPE(RPING)
275 #define P10_RPONG TYPE(RPONG)
276 #define P10_SERVER CMD_SERVER
277 #define P10_SERVLIST TYPE(SERVLIST)
278 #define P10_SERVSET TYPE(SERVSET)
279 #define P10_SET TYPE(SET)
280 #define P10_SETTIME TYPE(SETTIME)
281 #define P10_SHUN TYPE(SHUN)
282 #define P10_SILENCE TYPE(SILENCE)
283 #define P10_SQUERY TYPE(SQUERY)
284 #define P10_SQUIT TYPE(SQUIT)
285 #define P10_STATS TYPE(STATS)
286 #define P10_SVSJOIN TYPE(SVSJOIN)
287 #define P10_SVSNICK TYPE(SVSNICK)
288 #define P10_SVSPART TYPE(SVSPART)
289 #define P10_SWHOIS TYPE(SWHOIS)
290 #define P10_TIME TYPE(TIME)
291 #define P10_TOPIC TYPE(TOPIC)
292 #define P10_TRACE TYPE(TRACE)
293 #define P10_UPING TYPE(UPING)
294 #define P10_USER TYPE(USER)
295 #define P10_USERHOST TYPE(USERHOST)
296 #define P10_USERIP TYPE(USERIP)
297 #define P10_VERSION TYPE(VERSION)
298 #define P10_WALLCHOPS TYPE(WALLCHOPS)
299 #define P10_WALLOPS TYPE(WALLOPS)
300 #define P10_WALLHOPS TYPE(WALLHOPS)
301 #define P10_WALLUSERS TYPE(WALLUSERS)
302 #define P10_WALLVOICES TYPE(WALLVOICES)
303 #define P10_WHO TYPE(WHO)
304 #define P10_WHOIS TYPE(WHOIS)
305 #define P10_WHOWAS TYPE(WHOWAS)
306 #define P10_EXEMPT TYPE(EXEMPT)
308 /* Servers claiming to have a boot or link time before PREHISTORY
309 * trigger errors to the log. We hope no server has been running
310 * constantly since September 1994. :)
312 #define PREHISTORY 780000000
314 #define MODELEN 40 + KEYLEN
316 static struct server
* servers_num
[ 64 * 64 ];
317 static privmsg_func_t
* privmsg_funcs
;
318 static unsigned int num_privmsg_funcs
;
319 static privmsg_func_t
* notice_funcs
;
320 static unsigned int num_notice_funcs
;
321 static struct dict
* unbursted_channels
;
322 static char * his_servername
;
323 static char * his_servercomment
;
324 static int extended_accounts
;
326 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
);
328 extern int off_channel
;
329 extern int DefConLevel
;
330 extern int DefConTimeOut
;
331 extern char * DefConChanModes
;
333 static int parse_oplevel ( char * str
);
335 char privbuf
[ 512 ] = "" ;
337 /* Numerics can be XYY, XYYY, or XXYYY; with X's identifying the
338 * server and Y's indentifying the client on that server. */
340 GetServerN ( const char * numeric
)
342 switch ( strlen ( numeric
)) {
344 return servers_num
[ base64toint ( numeric
, 2 )];
348 return servers_num
[ base64toint ( numeric
, 1 )];
355 GetUserN ( const char * numeric
) /* using numeric */
361 switch ( strlen ( numeric
)) {
363 log_module ( MAIN_LOG
, LOG_WARNING
, "GetUserN( %s ): numeric too long!" , numeric
);
365 case 5 : slen
= 2 ; ulen
= 3 ; break ;
366 case 4 : slen
= 1 ; ulen
= 3 ; break ;
367 case 3 : slen
= 1 ; ulen
= 2 ; break ;
368 case 2 : case 1 : case 0 :
369 log_module ( MAIN_LOG
, LOG_WARNING
, "GetUserN( %s ): numeric too short!" , numeric
);
372 if (!( s
= servers_num
[ base64toint ( numeric
, slen
)])) {
373 log_module ( MAIN_LOG
, LOG_WARNING
, "GetUserN( %s ): couldn't find server (len= %d )!" , numeric
, slen
);
376 n
= base64toint ( numeric
+ slen
, ulen
) & s
-> num_mask
;
377 if (!( un
= s
-> users
[ n
])) {
378 log_module ( MAIN_LOG
, LOG_WARNING
, "GetUserN( %s ) couldn't find user!" , numeric
);
383 extern struct userNode
* opserv
;
385 check_ctcp ( struct userNode
* user
, struct userNode
* bot
, char * text
, UNUSED_ARG ( int server_qualified
))
388 /* if its a version reply, do an alert check (only alerts with version=something) */
390 if ( text
[ 0 ] == ' \001 ' ) {
392 cmd
= mysep (& text
, " " );
393 if (! irccasecmp ( cmd
, "VERSION" )) {
394 char * version
= mysep (& text
, " \n " );
397 /* opserv_debug("Opserv got CTCP VERSION Notice from %s: %s", user->nick, version); */
398 /* TODO: setup a ctcp_funcs thing to handle this and other CTCPS properly */
399 user
-> version_reply
= strdup ( version
);
400 /* TODO: put this in the db */
401 if ( match_ircglob ( version
, "WebTV;*" ))
402 user
-> no_notice
= true ; /* webbies cant see notices */
410 privmsg_user_helper ( struct userNode
* un
, void * data
)
412 struct privmsg_desc
* pd
= data
;
413 unsigned int num
= un
-> num_local
;
414 if (! pd
-> is_notice
) {
415 if (( num
< num_privmsg_funcs
) && privmsg_funcs
[ num
]) {
416 privmsg_funcs
[ num
]( pd
-> user
, un
, pd
-> text
, pd
-> is_qualified
);
419 if (( num
< num_notice_funcs
) && notice_funcs
[ num
]) {
420 check_ctcp ( pd
-> user
, un
, pd
-> text
, pd
-> is_qualified
);
421 notice_funcs
[ num
]( pd
-> user
, un
, pd
-> text
, pd
-> is_qualified
);
426 /* equiv to user doing /connect server port target */
427 void irc_connect ( struct userNode
* user
, char * server
, unsigned int port
, struct server
* target
)
429 putsock ( " %s " P10_CONNECT
" %s %d %s " , user
-> numeric
, server
, port
, target
-> numeric
);
433 irc_squit_route ( struct server
* srv
, const char * message
, ...)
437 va_start ( arg_list
, message
);
438 vsnprintf ( buffer
, MAXLEN
- 2 , message
, arg_list
);
439 buffer
[ MAXLEN
- 1 ] = 0 ;
441 /* When would we squit ourselves exactly?? -Rubin */
442 if ( srv
== self
&& cManager
. uplink
-> state
== CONNECTED
) {
445 /* Quit all clients linked to me. */
446 for ( i
= 0 ; i
<= self
-> num_mask
; i
++) {
449 irc_quit ( self
-> users
[ i
], buffer
);
453 putsock ( " %s " P10_SQUIT
" %s %d : %s " , self
-> numeric
, srv
-> name
, 0 , buffer
);
456 /* Force a reconnect to the currently selected server. */
457 cManager
. uplink
-> tries
= 0 ;
458 log_module ( MAIN_LOG
, LOG_INFO
, "Squitting from uplink: %s " , buffer
);
464 irc_server ( struct server
* srv
)
466 char extranum
[ COMBO_NUMERIC_LEN
+ 1 ];
468 inttobase64 ( extranum
, srv
-> num_mask
, ( srv
-> numeric
[ 1 ] || ( srv
-> num_mask
>= 64 * 64 )) ? 3 : 2 );
470 putsock ( P10_SERVER
" %s %d %l i %l i J10 %s%s +s6 : %s " ,
471 srv
-> name
, srv
-> hops
+ 1 , srv
-> boot
, srv
-> link
, srv
-> numeric
, extranum
, srv
-> description
);
473 putsock ( " %s " P10_SERVER
" %s %d %l i %l i %c 10 %s%s +s6 : %s " ,
474 self
-> numeric
, srv
-> name
, srv
-> hops
+ 1 , srv
-> boot
, srv
-> link
, ( srv
-> self_burst
? 'J' : 'P' ), srv
-> numeric
, extranum
, srv
-> description
);
479 irc_p10_pton ( irc_in_addr_t
* ip
, const char * input
)
481 if ( strlen ( input
) == 6 ) {
483 memset ( ip
, 0 , 6 * sizeof ( ip
-> in6
[ 0 ]));
484 value
= base64toint ( input
, 6 );
486 ip
-> in6
[ 5 ] = htons ( 65535 );
487 ip
-> in6
[ 6 ] = htons ( value
>> 16 );
488 ip
-> in6
[ 7 ] = htons ( value
& 65535 );
490 unsigned int pos
= 0 ;
494 for ( left
= ( 25 - strlen ( input
)) / 3 ; left
; left
--)
498 ip
-> in6
[ pos
++] = ntohs ( base64toint ( input
, 3 ));
506 irc_p10_ntop ( char * output
, const irc_in_addr_t
* ip
)
508 if (! irc_in_addr_is_valid (* ip
)) {
509 strcpy ( output
, "AAAAAA" );
510 } else if ( irc_in_addr_is_ipv4 (* ip
)) {
512 in4
= ( ntohs ( ip
-> in6
[ 6 ]) << 16 ) | ntohs ( ip
-> in6
[ 7 ]);
513 inttobase64 ( output
, in4
, 6 );
515 } else if ( irc_in_addr_is_ipv6 (* ip
)) {
516 unsigned int max_start
, max_zeros
, curr_zeros
, zero
, ii
;
517 /* Can start by printing out the leading non-zero parts. */
518 for ( ii
= 0 ; ( ip
-> in6
[ ii
]) && ( ii
< 8 ); ++ ii
) {
519 inttobase64 ( output
, ntohs ( ip
-> in6
[ ii
]), 3 );
522 /* Find the longest run of zeros. */
523 for ( max_start
= zero
= ii
, max_zeros
= curr_zeros
= 0 ; ii
< 8 ; ++ ii
) {
526 else if ( curr_zeros
> max_zeros
) {
527 max_start
= ii
- curr_zeros
;
528 max_zeros
= curr_zeros
;
532 if ( curr_zeros
> max_zeros
) {
533 max_start
= ii
- curr_zeros
;
534 max_zeros
= curr_zeros
;
537 /* Print the rest of the address */
538 for ( ii
= zero
; ii
< 8 ; ) {
539 if (( ii
== max_start
) && max_zeros
) {
543 inttobase64 ( output
, ntohs ( ip
-> in6
[ ii
]), 3 );
549 strcpy ( output
, "???" );
554 irc_user ( struct userNode
* user
)
559 irc_p10_ntop ( b64ip
, & user
-> ip
);
566 modes
[ modelen
++] = 'o' ;
567 if ( IsInvisible ( user
))
568 modes
[ modelen
++] = 'i' ;
570 modes
[ modelen
++] = 'w' ;
572 modes
[ modelen
++] = 'k' ;
573 if ( IsServNotice ( user
))
574 modes
[ modelen
++] = 's' ;
576 modes
[ modelen
++] = 'd' ;
578 modes
[ modelen
++] = 'g' ;
579 // sethost - reed/apples
580 // if (IsHelperIrcu(user))
582 modes
[ modelen
++] = 'h' ;
583 if ( IsFakeHost ( user
))
584 modes
[ modelen
++] = 'f' ;
585 if ( IsHiddenHost ( user
))
586 modes
[ modelen
++] = 'x' ;
589 /* we don't need to put the + in modes because it's in the format string. */
590 putsock ( " %s " P10_NICK
" %s %d %l i %s %s + %s %s %s : %s " ,
591 user
-> uplink
-> numeric
, user
-> nick
, user
-> uplink
-> hops
+ 1 , user
-> timestamp
, user
-> ident
, user
-> hostname
, modes
, b64ip
, user
-> numeric
, user
-> info
);
593 putsock ( " %s " P10_NICK
" %s %d %l i %s %s %s %s : %s " ,
594 user
-> uplink
-> numeric
, user
-> nick
, user
-> uplink
-> hops
+ 1 , user
-> timestamp
, user
-> ident
, user
-> hostname
, b64ip
, user
-> numeric
, user
-> info
);
599 irc_rename ( struct userNode
* user
, const char * new_handle
)
601 if ( extended_accounts
)
602 putsock ( " %s " P10_ACCOUNT
" %s M %s " , self
-> numeric
, user
-> numeric
, new_handle
);
606 irc_delete ( struct userNode
* user
)
608 if ( extended_accounts
)
609 putsock ( " %s " P10_ACCOUNT
" %s U" , self
-> numeric
, user
-> numeric
);
613 irc_account ( struct userNode
* user
, const char * stamp
, time_t timestamp
)
615 if ( extended_accounts
)
616 putsock ( " %s " P10_ACCOUNT
" %s R %s %l u" , self
-> numeric
, user
-> numeric
, stamp
, timestamp
);
618 putsock ( " %s " P10_ACCOUNT
" %s %s %l u" , self
-> numeric
, user
-> numeric
, stamp
, timestamp
);
622 irc_fakehost ( struct userNode
* user
, const char * host
)
624 putsock ( " %s " P10_FAKEHOST
" %s %s " , self
-> numeric
, user
-> numeric
, host
);
628 irc_regnick ( UNUSED_ARG ( struct userNode
* user
))
630 /* no operation here */
634 irc_nick ( struct userNode
* user
, UNUSED_ARG ( const char * old_nick
))
636 putsock ( " %s " P10_NICK
" %s " FMT_TIME_T
, user
-> numeric
, user
-> nick
, now
);
640 irc_fetchtopic ( struct userNode
* from
, const char * to
)
644 putsock ( " %s " P10_TOPIC
" %s " , from
-> numeric
, to
);
648 irc_squit ( struct server
* srv
, const char * message
, const char * service_message
)
650 if (! service_message
)
651 service_message
= message
;
653 /* Are we leaving the network? */
654 if ( srv
== self
&& cManager
. uplink
-> state
== CONNECTED
) {
657 /* Quit all clients linked to me. */
658 for ( i
= 0 ; i
<= self
-> num_mask
; i
++) {
661 irc_quit ( self
-> users
[ i
], service_message
);
665 putsock ( " %s " P10_SQUIT
" %s %d : %s " , self
-> numeric
, srv
-> name
, 0 , message
);
668 /* Force a reconnect to the currently selected server. */
669 cManager
. uplink
-> tries
= 0 ;
670 log_module ( MAIN_LOG
, LOG_INFO
, "Squitting from uplink: %s " , message
);
676 irc_wallchops ( struct userNode
* from
, const char * to
, const char * message
)
678 putsock ( " %s " P10_WALLCHOPS
" %s : %s " , from
-> numeric
, to
, message
);
682 irc_wallops ( const char * format
, ...)
686 va_start ( arg_list
, format
);
687 vsnprintf ( buffer
, MAXLEN
- 2 , format
, arg_list
);
688 buffer
[ MAXLEN
- 1 ] = 0 ;
689 putsock ( " %s " P10_WALLOPS
" : %s " , self
-> numeric
, buffer
);
694 irc_notice ( struct userNode
* from
, const char * to
, const char * message
)
696 putsock ( " %s " P10_NOTICE
" %s : %s " , from
-> numeric
, to
, message
);
700 irc_notice_user ( struct userNode
* from
, struct userNode
* to
, const char * message
)
702 putsock ( " %s " P10_NOTICE
" %s : %s " , from
-> numeric
, to
-> numeric
, message
);
706 irc_privmsg ( struct userNode
* from
, const char * to
, const char * message
)
708 putsock ( " %s " P10_PRIVMSG
" %s : %s " , from
-> numeric
, to
, message
);
712 irc_privmsg_user ( struct userNode
* from
, struct userNode
* to
, const char * message
)
714 putsock ( " %s " P10_PRIVMSG
" %s : %s " , from
-> numeric
, to
-> numeric
, message
);
718 irc_version_user ( struct userNode
* from
, struct userNode
* to
)
720 irc_privmsg_user ( from
, to
, " \001 VERSION \001 " );
726 putsock ( " %s " P10_EOB
, self
-> numeric
);
732 putsock ( " %s " P10_EOB_ACK
, self
-> numeric
);
736 str
= conf_get_data ( "services/opserv/nick" , RECDB_QSTRING
);
739 if ( nick
&& ( DefConLevel
< 5 )) {
740 DefConProcess ( GetUserH ( nick
));
742 if ( DefConTimeOut
> 0 )
743 timeq_add ( now
+ DefConTimeOut
, defcon_timeout
, NULL
);
748 irc_rpong ( const char * from1
, const char * from2
, const char * pingtime
, const char * clientinfo
)
750 putsock ( " %s " P10_RPONG
" %s %s %s : %s " , self
-> numeric
, from1
, from2
, pingtime
, clientinfo
);
754 irc_ping ( const char * payload
)
756 putsock ( " %s " P10_PING
" : %s " , self
-> numeric
, payload
);
760 irc_pong ( const char * who
, const char * data
)
762 putsock ( " %s " P10_PONG
" %s : %s " , self
-> numeric
, who
, data
);
766 irc_pong_asll ( const char * who
, const char * orig_ts
)
773 orig
. tv_sec
= strtoul ( orig_ts
, & delim
, 10 );
774 orig
. tv_usec
= (* delim
== '.' ) ? strtoul ( delim
+ 1 , NULL
, 10 ) : 0 ;
775 gettimeofday (& now
, NULL
);
776 diff
= ( now
. tv_sec
- orig
. tv_sec
) * 1000 + ( now
. tv_usec
- orig
. tv_usec
) / 1000 ;
777 putsock ( " %s " P10_PONG
" %s %s %d " FMT_TIME_T
". %0 6u" , self
-> numeric
, who
, orig_ts
, diff
, now
. tv_sec
, ( unsigned ) now
. tv_usec
);
781 irc_pass ( const char * passwd
)
783 putsock ( P10_PASS
" : %s " , passwd
);
787 irc_introduce ( const char * passwd
)
789 void timed_send_ping ( void * data
);
791 self
-> self_burst
= self
-> burst
= 1 ;
795 timeq_add ( now
+ ping_freq
, timed_send_ping
, 0 );
799 irc_gline ( struct server
* srv
, struct gline
* gline
, int silent
)
801 putsock ( " %s " P10_GLINE
" %s + %s %l d : %s < %s > %s " ,
802 self
-> numeric
, ( srv
? srv
-> numeric
: "*" ), gline
-> target
, gline
-> expires
- now
, silent
? "AUTO " : "" , gline
-> issuer
, gline
-> reason
);
806 irc_shun ( struct server
* srv
, struct shun
* shun
)
808 putsock ( " %s " P10_SHUN
" %s + %s %l d :< %s > %s " ,
809 self
-> numeric
, ( srv
? srv
-> numeric
: "*" ), shun
-> target
, shun
-> expires
- now
, shun
-> issuer
, shun
-> reason
);
813 irc_settime ( const char * srv_name_mask
, time_t new_time
)
815 ioset_set_time ( new_time
);
816 if (! strcmp ( srv_name_mask
, "*" ))
818 putsock ( " %s " P10_SETTIME
" " FMT_TIME_T
" %s " , self
-> numeric
, new_time
, srv_name_mask
);
822 irc_ungline ( const char * mask
)
824 putsock ( " %s " P10_GLINE
" * - %s " , self
-> numeric
, mask
);
828 irc_unshun ( const char * mask
)
830 putsock ( " %s " P10_SHUN
" * - %s " , self
-> numeric
, mask
);
834 irc_burst ( struct chanNode
* chan
)
836 char burst_line
[ 512 ];
837 int pos
, base_len
, len
;
840 struct exemptNode
* en
;
844 base_len
= sprintf ( burst_line
, " %s " P10_BURST
" %s " FMT_TIME_T
" " ,
845 self
-> numeric
, chan
-> name
, chan
-> timestamp
);
846 len
= irc_make_chanmode ( chan
, burst_line
+ base_len
);
847 pos
= base_len
+ len
;
849 burst_line
[ pos
++] = ' ' ;
851 if ( chan
-> members
. used
< 1 )
852 return ; /* dont burst empty channels (created by discrims) */
854 for ( n
= 0 ; n
< chan
-> members
. used
; n
++) {
855 mn
= chan
-> members
. list
[ n
];
857 burst_line
[ pos
- 1 ] = 0 ; /* -1 to back up over the space or comma */
858 putsock ( " %s " , burst_line
);
863 memcpy ( burst_line
+ pos
, mn
-> user
-> numeric
, strlen ( mn
-> user
-> numeric
));
864 pos
+= strlen ( mn
-> user
-> numeric
);
865 if ( mn
-> modes
&& ( mn
-> modes
!= last_mode
)) {
866 last_mode
= mn
-> modes
;
867 burst_line
[ pos
++] = ':' ;
868 if ( last_mode
& MODE_CHANOP
)
869 burst_line
[ pos
++] = 'o' ;
870 if ( last_mode
& MODE_HALFOP
)
871 burst_line
[ pos
++] = 'h' ;
872 if ( last_mode
& MODE_VOICE
)
873 burst_line
[ pos
++] = 'v' ;
875 if (( n
+ 1 )< chan
-> members
. used
)
876 burst_line
[ pos
++] = ',' ;
878 if ( chan
-> banlist
. used
) {
880 if ( pos
+ 2 + strlen ( chan
-> banlist
. list
[ 0 ]-> ban
) > 505 ) {
881 burst_line
[ pos
- 1 ] = 0 ;
882 putsock ( " %s " , burst_line
);
885 burst_line
[ pos
++] = ' ' ;
888 burst_line
[ pos
++] = ':' ;
889 burst_line
[ pos
++] = '%' ;
891 for ( n
= 0 ; n
< chan
-> banlist
. used
; n
++) {
892 bn
= chan
-> banlist
. list
[ n
];
893 len
= strlen ( bn
-> ban
);
894 if ( pos
+ len
+ 1 > 510 ) {
895 burst_line
[ pos
- 1 ] = 0 ; /* -1 to back up over the space or comma */
896 putsock ( " %s " , burst_line
);
899 memcpy ( burst_line
+ pos
, bn
-> ban
, len
);
901 burst_line
[ pos
++] = ' ' ;
904 if ( chan
-> exemptlist
. used
) {
905 /* dump the exempt */
906 if ( pos
+ 2 + strlen ( chan
-> exemptlist
. list
[ 0 ]-> exempt
) > 505 ) {
907 burst_line
[ pos
- 1 ] = 0 ;
908 putsock ( " %s " , burst_line
);
911 burst_line
[ pos
++] = ' ' ;
914 burst_line
[ pos
++] = ' ' ;
915 burst_line
[ pos
++] = '~' ;
916 burst_line
[ pos
++] = ' ' ;
918 for ( n
= 0 ; n
< chan
-> exemptlist
. used
; n
++) {
919 en
= chan
-> exemptlist
. list
[ n
];
920 len
= strlen ( en
-> exempt
);
921 if ( pos
+ len
+ 1 > 510 ) {
922 burst_line
[ pos
- 1 ] = 0 ; /* -1 to back up over the space or comma */
923 putsock ( " %s " , burst_line
);
926 memcpy ( burst_line
+ pos
, en
-> exempt
, len
);
928 burst_line
[ pos
++] = ' ' ;
931 /* print the last line */
933 putsock ( " %s " , burst_line
);
937 irc_quit ( struct userNode
* user
, const char * message
)
939 putsock ( " %s " P10_QUIT
" : %s " , user
-> numeric
, message
);
943 irc_error ( const char * to
, const char * message
)
946 putsock ( " %s " P10_ERROR
" : %s " , to
, message
);
948 putsock ( ": %s " P10_ERROR
" : %s " , self
-> name
, message
);
953 irc_kill ( struct userNode
* from
, struct userNode
* target
, const char * message
)
956 putsock ( " %s " P10_KILL
" %s : %s ! %s ( %s )" ,
957 from
-> numeric
, target
-> numeric
, self
-> name
, from
-> nick
, message
);
959 putsock ( " %s " P10_KILL
" %s : %s ( %s )" ,
960 self
-> numeric
, target
-> numeric
, self
-> name
, message
);
965 irc_mode ( struct userNode
* from
, struct chanNode
* target
, const char * modes
)
967 call_channel_mode_funcs ( from
, target
, ( char **)& modes
, 0 );
968 putsock ( " %s " P10_MODE
" %s %s " FMT_TIME_T
,
969 ( from
? from
-> numeric
: self
-> numeric
),
970 target
-> name
, modes
, target
-> timestamp
);
973 /* Added to allow services to mode users
974 2005 - 8 - 10 by Life4Christ
977 irc_umode ( struct userNode
* target
, const char * modes
)
979 putsock ( " %s " P10_MODE
" %s %s " , self
-> numeric
, target
-> nick
, modes
);
984 irc_invite ( struct userNode
* from
, struct userNode
* who
, struct chanNode
* to
)
986 putsock ( " %s " P10_INVITE
" %s %s " , from
-> numeric
, who
-> nick
, to
-> name
);
990 irc_silence ( struct userNode
* who
, const char * mask
, int add
)
992 putsock ( " %s " P10_SILENCE
" %s %s%s " , self
-> numeric
, who
-> numeric
, add
? "+" : "-" , mask
);
996 irc_join ( struct userNode
* who
, struct chanNode
* what
)
998 if ( what
-> members
. used
== 1 ) {
999 putsock ( " %s " P10_CREATE
" %s %l u" ,
1000 who
-> numeric
, what
-> name
, what
-> timestamp
);
1002 putsock ( " %s " P10_JOIN
" %s %l u" , who
-> numeric
, what
-> name
, what
-> timestamp
);
1007 irc_svsjoin ( struct userNode
* from
, struct userNode
* who
, struct chanNode
* to
)
1009 putsock ( " %s " P10_SVSJOIN
" %s %s " FMT_TIME_T
, from
-> uplink
-> numeric
, who
-> numeric
, to
-> name
, now
);
1013 irc_svspart ( struct userNode
* from
, struct userNode
* who
, struct chanNode
* to
)
1015 putsock ( " %s " P10_SVSPART
" %s %s " , from
-> uplink
-> numeric
, who
-> numeric
, to
-> name
);
1019 irc_kick ( struct userNode
* who
, struct userNode
* target
, struct chanNode
* channel
, const char * msg
)
1021 const char * numeric
;
1022 struct modeNode
* mn
= GetUserMode ( channel
, who
);
1023 numeric
= (( mn
&& ( mn
-> modes
& MODE_CHANOP
)) || off_channel
) ? who
-> numeric
: self
-> numeric
;
1024 putsock ( " %s " P10_KICK
" %s %s : %s " ,
1025 numeric
, channel
-> name
, target
-> numeric
, msg
);
1029 irc_stats ( struct userNode
* from
, struct server
* target
, char type
)
1031 putsock ( " %s " P10_STATS
" %c : %s " , from
-> numeric
, type
, target
-> numeric
);
1035 irc_svsnick ( struct userNode
* from
, struct userNode
* target
, const char * newnick
)
1037 putsock ( " %s " P10_SVSNICK
" %s %s " FMT_TIME_T
, from
-> uplink
-> numeric
, target
-> numeric
, newnick
, now
);
1041 irc_swhois ( struct userNode
* from
, struct userNode
* target
, const char * message
)
1043 putsock ( " %s " P10_SWHOIS
" %s %s%s " , from
-> uplink
-> numeric
, target
-> numeric
, message
? ":" : "" ,
1044 message
? message
: "" );
1049 irc_part ( struct userNode
* who
, struct chanNode
* what
, const char * reason
)
1052 putsock ( " %s " P10_PART
" %s : %s " , who
-> numeric
, what
-> name
, reason
);
1054 putsock ( " %s " P10_PART
" %s " , who
-> numeric
, what
-> name
);
1059 irc_topic ( struct userNode
* service
, struct userNode
* who
, struct chanNode
* what
, const char * topic
)
1063 int host_in_topic
= 0 ;
1064 const char * hstr
, * tstr
;
1065 char * host
, * hostmask
;
1067 char sident
[ MAXLEN
];
1069 tstr
= conf_get_data ( "server/type" , RECDB_QSTRING
);
1070 hstr
= conf_get_data ( "server/host_in_topic" , RECDB_QSTRING
);
1074 type
= 4 ; /* default to 040 style topics */
1077 if ( IsFakeHost ( who
))
1078 safestrncpy ( shost
, who
-> fakehost
, sizeof ( shost
));
1079 else if ( IsSetHost ( who
)) {
1080 hostmask
= strdup ( who
-> sethost
);
1081 if (( host
= ( strrchr ( hostmask
, '@' ))))
1086 safestrncpy ( sident
, hostmask
, sizeof ( shost
));
1087 safestrncpy ( shost
, host
, sizeof ( shost
));
1089 safestrncpy ( shost
, who
-> hostname
, sizeof ( shost
));
1091 host_in_topic
= atoi ( hstr
);
1095 putsock ( " %s " P10_TOPIC
" %s %s%s%s%s%s " FMT_TIME_T
" " FMT_TIME_T
" : %s " , service
-> numeric
, what
-> name
,
1096 who
-> nick
, host_in_topic
? "!" : "" , host_in_topic
? ( IsSetHost ( who
) ? sident
: who
-> ident
) : "" ,
1097 host_in_topic
? "@" : "" , host_in_topic
? shost
: "" , what
-> timestamp
, now
, topic
);
1100 putsock ( " %s " P10_TOPIC
" %s : %s " , who
-> numeric
, what
-> name
, topic
);
1105 irc_raw ( const char * what
)
1107 putsock ( " %s " , what
);
1111 irc_numeric ( struct userNode
* user
, unsigned int num
, const char * format
, ...)
1114 char buffer
[ MAXLEN
];
1115 va_start ( arg_list
, format
);
1116 vsnprintf ( buffer
, MAXLEN
- 2 , format
, arg_list
);
1117 buffer
[ MAXLEN
- 1 ] = 0 ;
1118 putsock ( ": %s %0 3d %s %s " , self
-> name
, num
, user
-> nick
, buffer
);
1122 irc_mark ( struct userNode
* user
, char * mark
)
1124 char * host
= user
-> hostname
;
1126 /* 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 */
1130 /* if the mark will put us over the host length, clip some off the left hand side
1133 if ( strlen ( host
) + 1 + strlen ( mark
) > HOSTLEN
)
1134 host
+= 1 + ( ( strlen ( host
) + 1 + strlen ( mark
)) - HOSTLEN
);
1135 putsock ( " %s " CMD_MARK
" %s DNSBL +m %s . %s " , self
-> numeric
, user
-> nick
, mark
, host
);
1136 putsock ( " %s " CMD_MARK
" %s DNSBL_DATA %s " , self
-> numeric
, user
-> nick
, mark
);
1138 /* Save it in the user */
1139 user
-> mark
= strdup ( mark
);
1141 /* If they are not otherwise marked, mark their host with fakehost */
1142 if (! IsFakeHost ( user
) && ! IsSetHost ( user
) && !( IsHiddenHost ( user
) && user
-> handle_info
) )
1144 struct modeNode
* mn
= NULL
;
1145 char fakehost
[ HOSTLEN
];
1146 unsigned int count
= 0 ;
1149 putsock ( " %s " CMD_FAKEHOST
" %s %s . %s " , self
-> numeric
, user
-> numeric
, mark
, host
);
1150 putsock ( " %s " CMD_MODE
" %s +x" , self
-> numeric
, user
-> nick
);
1152 snprintf ( fakehost
, sizeof ( fakehost
), " %s . %s " , mark
, host
);
1153 safestrncpy ( user
-> fakehost
, fakehost
, sizeof ( user
-> fakehost
));
1155 for ( n
= count
= 0 ; n
< user
-> channels
. used
; n
++) {
1156 mn
= user
-> channels
. list
[ n
];
1157 if ( strlen ( mn
-> channel
-> name
) >= 1 ) /* Sanity */
1158 check_bans ( user
, mn
-> channel
-> name
);
1163 static void send_burst ( void );
1166 change_nicklen ( int new_nicklen
)
1169 char new_nick
[ NICKLEN
+ 1 ];
1170 struct userNode
* user
;
1172 nicklen
= new_nicklen
;
1173 /* fix up any users we have here */
1174 for ( nn
= 0 ; nn
<= self
-> num_mask
; nn
++) {
1175 if (!( user
= self
-> users
[ nn
]))
1177 safestrncpy ( new_nick
, user
-> nick
, sizeof ( new_nick
));
1178 new_nick
[ nicklen
] = 0 ;
1179 NickChange ( user
, new_nick
, 1 );
1183 static CMD_FUNC ( cmd_whois
)
1185 struct userNode
* from
;
1186 struct userNode
* who
;
1190 if (!( from
= GetUserH ( origin
))) {
1191 log_module ( MAIN_LOG
, LOG_ERROR
, "Could not find WHOIS origin user %s " , origin
);
1194 if (!( who
= GetUserH ( argv
[ 2 ]))) {
1195 irc_numeric ( from
, ERR_NOSUCHNICK
, " %s @ %s :No such nick" , argv
[ 2 ], self
-> name
);
1198 if ( IsHiddenHost ( who
) && ! IsOper ( from
)) {
1199 /* Just stay quiet. */
1202 irc_numeric ( from
, RPL_WHOISUSER
, " %s %s %s * : %s " , who
-> nick
, who
-> ident
, who
-> hostname
, who
-> info
);
1203 if ( his_servername
&& his_servercomment
)
1204 irc_numeric ( from
, RPL_WHOISSERVER
, " %s %s : %s " , who
-> nick
, his_servername
, his_servercomment
);
1206 irc_numeric ( from
, RPL_WHOISSERVER
, " %s %s : %s " , who
-> nick
, who
-> uplink
-> name
, who
-> uplink
-> description
);
1208 irc_numeric ( from
, RPL_WHOISOPERATOR
, " %s :is a megalomaniacal power hungry tyrant" , who
-> nick
);
1209 irc_numeric ( from
, RPL_ENDOFWHOIS
, " %s :End of /WHOIS list" , who
-> nick
);
1213 static CMD_FUNC ( cmd_server
)
1221 /* another server introduced us */
1222 srv
= AddServer ( GetServerH ( origin
), argv
[ 1 ], atoi ( argv
[ 2 ]), atoi ( argv
[ 3 ]), atoi ( argv
[ 4 ]), argv
[ 6 ], argv
[ argc
- 1 ]);
1225 srv
-> self_burst
= argv
[ 5 ][ 0 ] == 'J' ;
1228 /* this must be our uplink */
1229 srv
= self
-> uplink
= AddServer ( self
, argv
[ 1 ], atoi ( argv
[ 2 ]), atoi ( argv
[ 3 ]), atoi ( argv
[ 4 ]), argv
[ 6 ], argv
[ argc
- 1 ]);
1232 srv
-> self_burst
= argv
[ 5 ][ 0 ] == 'J' ;
1234 if (( argv
[ 7 ][ 0 ] == '+' ) && ! force_n2k
) {
1235 log_module ( MAIN_LOG
, LOG_WARNING
, "Got Undernet-style SERVER message but \" force_n2k \" not on." );
1240 /* Fix up our timestamps if necessary. */
1241 if ( srv
-> boot
<= PREHISTORY
) {
1242 /* Server from the mists of time.. */
1243 if ( srv
-> hops
== 1 ) {
1244 log_module ( MAIN_LOG
, LOG_ERROR
, "Server %s claims to have booted at time " FMT_TIME_T
". This is absurd." , srv
-> name
, srv
-> boot
);
1246 } else if (( str
= conf_get_data ( "server/reliable_clock" , RECDB_QSTRING
))
1247 && enabled_string ( str
)) {
1248 /* If we have a reliable clock, we just keep our current time. */
1250 if ( srv
-> boot
<= self
-> boot
) {
1251 /* The other server is older than us. Accept their timestamp.
1252 * Alternately, we are same age, but we accept their time
1253 * since we are linking to them. */
1254 self
-> boot
= srv
-> boot
;
1255 ioset_set_time ( srv
-> link
);
1258 if ( srv
== self
-> uplink
) {
1259 extern time_t burst_begin
;
1266 static CMD_FUNC ( cmd_eob
)
1268 struct server
* sender
;
1272 if (!( sender
= GetServerH ( origin
)))
1274 if ( sender
== self
-> uplink
) {
1275 cManager
. uplink
-> state
= CONNECTED
;
1276 for ( it
= dict_first ( unbursted_channels
); it
; it
= iter_next ( it
))
1277 irc_burst ( iter_data ( it
));
1278 dict_delete ( unbursted_channels
);
1279 unbursted_channels
= NULL
;
1283 /* now that we know who our uplink is,
1284 * we can center the routing map and activate auto-routing.
1286 //activate_routing(NULL, NULL, NULL);
1289 sender
-> self_burst
= 0 ;
1290 recalc_bursts ( sender
);
1291 for ( ii
= 0 ; ii
< slf_used
; ii
++)
1292 slf_list
[ ii
]( sender
);
1293 /* let auto-routing figure out if we were
1294 * wating on this server to link a child to it */
1295 /* DONT call this if uplink is _US_ */
1296 if ( sender
-> uplink
!= self
)
1297 routing_handle_connect ( sender
-> name
, sender
-> uplink
-> name
);
1301 static CMD_FUNC ( cmd_eob_ack
)
1303 extern time_t burst_begin
;
1305 if ( GetServerH ( origin
) == self
-> uplink
) {
1306 burst_length
= now
- burst_begin
;
1307 self
-> self_burst
= self
-> burst
= 0 ;
1309 cManager
. uplink
-> state
= CONNECTED
;
1313 static CMD_FUNC ( cmd_rping
)
1315 struct server
* dest
;
1317 if (!( dest
= GetServerN ( argv
[ 1 ])))
1321 irc_rpong ( argv
[ 2 ], argv
[ 3 ], argv
[ 4 ], argv
[ 5 ]);
1326 static CMD_FUNC ( cmd_ping
)
1329 struct userNode
* un
;
1332 irc_pong_asll ( argv
[ 2 ], argv
[ 3 ]);
1333 else if (( srv
= GetServerH ( origin
)))
1334 irc_pong ( self
-> name
, srv
-> numeric
);
1335 else if (( un
= GetUserH ( origin
)))
1336 irc_pong ( self
-> name
, un
-> numeric
);
1338 irc_pong ( self
-> name
, origin
);
1340 timeq_del ( 0 , timed_send_ping
, 0 , TIMEQ_IGNORE_WHEN
| TIMEQ_IGNORE_DATA
);
1341 timeq_del ( 0 , timed_ping_timeout
, 0 , TIMEQ_IGNORE_WHEN
| TIMEQ_IGNORE_DATA
);
1342 timeq_add ( now
+ ping_freq
, timed_send_ping
, 0 );
1347 static CMD_FUNC ( cmd_error_nick
)
1349 /* Go back to original IRC length .. and try to reconnect :/ */
1351 irc_squit ( self
, "Got erroneous nickname, truncating nicks." , NULL
);
1355 struct create_desc
{
1356 struct userNode
* user
;
1361 join_helper ( struct chanNode
* chan
, void * data
)
1363 struct create_desc
* cd
= data
;
1364 AddChannelUser ( cd
-> user
, chan
);
1368 create_helper ( char * name
, void * data
)
1370 struct create_desc
* cd
= data
;
1372 if (! strcmp ( name
, "0" )) {
1373 while ( cd
-> user
-> channels
. used
> 0 )
1374 DelChannelUser ( cd
-> user
, cd
-> user
-> channels
. list
[ 0 ]-> channel
, 0 , 0 );
1378 AddChannelUser ( cd
-> user
, AddChannel ( name
, cd
-> when
, NULL
, NULL
, NULL
));
1381 static CMD_FUNC ( cmd_create
)
1383 struct create_desc cd
;
1384 struct userNode
* user
;
1386 if (( argc
< 3 ) || !( user
= GetUserH ( origin
)))
1389 cd
. when
= atoi ( argv
[ 2 ]);
1390 parse_foreach ( argv
[ 1 ], join_helper
, create_helper
, NULL
, NULL
, & cd
);
1394 static CMD_FUNC ( cmd_join
)
1396 struct create_desc cd
;
1398 if (!( cd
. user
= GetUserH ( origin
)))
1405 cd
. when
= atoi ( argv
[ 2 ]);
1406 parse_foreach ( argv
[ 1 ], join_helper
, create_helper
, NULL
, NULL
, & cd
);
1410 static CMD_FUNC ( cmd_svsjoin
)
1412 struct create_desc cd
;
1414 if (!( cd
. user
= GetUserH ( argv
[ 1 ])))
1421 cd
. when
= atoi ( argv
[ 3 ]);
1422 parse_foreach ( argv
[ 2 ], join_helper
, create_helper
, NULL
, NULL
, & cd
);
1426 static CMD_FUNC ( cmd_pong
)
1430 if (! strcmp ( argv
[ 2 ], self
-> name
)) {
1431 timeq_del ( 0 , timed_send_ping
, 0 , TIMEQ_IGNORE_WHEN
| TIMEQ_IGNORE_DATA
);
1432 timeq_del ( 0 , timed_ping_timeout
, 0 , TIMEQ_IGNORE_WHEN
| TIMEQ_IGNORE_DATA
);
1433 timeq_add ( now
+ ping_freq
, timed_send_ping
, 0 );
1439 static CMD_FUNC ( cmd_nick
)
1441 struct userNode
* user
;
1442 if (( user
= GetUserH ( origin
))) {
1443 /* nick change (since the source is a user numeric) */
1446 NickChange ( user
, argv
[ 1 ], 1 );
1448 struct server
* serv
;
1449 struct userNode
* nuser
;
1454 serv
= GetServerH ( origin
);
1456 unsplit_string ( argv
+ 6 , argc
- 9 , modes
);
1459 nuser
= AddUser ( serv
, argv
[ 1 ], argv
[ 4 ], argv
[ 5 ], modes
, argv
[ argc
- 2 ], argv
[ argc
- 1 ], atoi ( argv
[ 3 ]), argv
[ argc
- 3 ]);
1464 static CMD_FUNC ( cmd_account
)
1466 struct userNode
* user
;
1467 struct server
* server
;
1468 struct handle_info
* hi
;
1470 if (( argc
< 3 ) || ! origin
|| !( server
= GetServerH ( origin
)))
1471 return 0 ; /* Origin must be server. */
1473 /* This next line appears to tremple origin.. why? */
1474 user
= GetUserN ( argv
[ 1 ]);
1476 return 1 ; /* A QUIT probably passed the ACCOUNT. */
1478 if (! extended_accounts
) /* any need for this function without? */
1481 if (! strcmp ( argv
[ 2 ], "C" ))
1483 if (( hi
= loc_auth ( argv
[ 4 ], argv
[ 5 ])))
1486 putsock ( " %s " P10_ACCOUNT
" %s A %s %l u" , self
-> numeric
, server
-> numeric
, argv
[ 3 ], hi
-> registered
);
1492 putsock ( " %s " P10_ACCOUNT
" %s D %s " , self
-> numeric
, server
-> numeric
, argv
[ 3 ]);
1496 else if (! strcmp ( argv
[ 2 ], "R" ))
1497 call_account_func ( user
, argv
[ 3 ]);
1499 call_account_func ( user
, argv
[ 2 ]); /* For backward compatability */
1503 static CMD_FUNC ( cmd_fakehost
)
1505 struct userNode
* user
;
1507 if (( argc
< 3 ) || ! origin
|| ! GetServerH ( origin
))
1509 if (!( user
= GetUserN ( argv
[ 1 ])))
1511 assign_fakehost ( user
, argv
[ 2 ], 0 );
1519 #define P(priv) { #priv, PRIV_ ## priv }
1520 P ( CHAN_LIMIT
), P ( MODE_LCHAN
), P ( WALK_LCHAN
), P ( DEOP_LCHAN
),
1521 P ( SHOW_INVIS
), P ( SHOW_ALL_INVIS
), P ( UNLIMIT_QUERY
), P ( KILL
),
1522 P ( LOCAL_KILL
), P ( REHASH
), P ( RESTART
), P ( DIE
),
1523 P ( GLINE
), P ( LOCAL_GLINE
), P ( JUPE
), P ( LOCAL_JUPE
),
1524 P ( OPMODE
), P ( LOCAL_OPMODE
), P ( SET
), P ( WHOX
),
1525 P ( BADCHAN
), P ( LOCAL_BADCHAN
), P ( SEE_CHAN
), P ( PROPAGATE
),
1526 P ( DISPLAY
), P ( SEE_OPERS
), P ( WIDE_GLINE
), P ( FORCE_OPMODE
),
1527 P ( FORCE_LOCAL_OPMODE
), P ( REMOTEREHASH
), P ( CHECK
), P ( SEE_SECRET_CHAN
),
1528 P ( SHUN
), P ( LOCAL_SHUN
), P ( WIDE_SHUN
),
1533 char * client_report_privs ( struct userNode
* client
)
1538 for ( i
= 0 ; privtab
[ i
]. name
; i
++) {
1539 if ( HasPriv ( client
, privtab
[ i
]. priv
)) {
1540 strcat ( privbuf
, privtab
[ i
]. name
);
1541 strcat ( privbuf
, " " );
1545 privbuf
[ strlen ( privbuf
)] = 0 ;
1550 int client_modify_priv_by_name ( struct userNode
* who
, char * priv
, int what
) {
1555 for ( i
= 0 ; privtab
[ i
]. name
; i
++) {
1556 if ( 0 == strcmp ( privtab
[ i
]. name
, priv
)) {
1557 if ( what
== PRIV_ADD
)
1558 GrantPriv ( who
, privtab
[ i
]. priv
);
1559 else if ( what
== PRIV_DEL
) {
1560 RevokePriv ( who
, privtab
[ i
]. priv
);
1567 int check_priv ( char * priv
)
1571 for ( i
= 0 ; privtab
[ i
]. name
; i
++) {
1572 if ( 0 == strcmp ( privtab
[ i
]. name
, priv
)) {
1580 irc_privs ( struct userNode
* target
, char * flag
, int add
)
1582 client_modify_priv_by_name ( target
, flag
, add
);
1583 putsock ( " %s " P10_PRIVS
" %s %s%s " , self
-> numeric
, target
-> numeric
, ( add
== PRIV_ADD
) ? "+" : "-" , flag
);
1586 static CMD_FUNC ( cmd_privs
)
1591 tstr
= conf_get_data ( "server/type" , RECDB_QSTRING
);
1596 return 1 ; /* silently ignore */
1598 struct userNode
* user
= argc
> 1 ? GetUserN ( argv
[ 1 ]) : NULL
;
1600 int what
= PRIV_ADD
;
1611 for ( i
= 1 ; i
< argc
; i
++) {
1612 strcat ( buf
, argv
[ i
]);
1616 for ( i
= 2 ; i
< argc
; i
++) {
1617 if (* argv
[ i
] == '+' ) { what
= PRIV_ADD
; argv
[ i
]++; }
1618 if (* argv
[ i
] == '-' ) { what
= PRIV_DEL
; argv
[ i
]++; }
1619 for ( tmp
= x3_strtok (& p
, argv
[ i
], "," ); tmp
;
1620 tmp
= x3_strtok (& p
, NULL
, "," )) {
1621 client_modify_priv_by_name ( user
, tmp
, what
);
1627 static CMD_FUNC ( cmd_burst
)
1630 char modes
[ MAXLEN
], * members
= "" ;
1631 static char exemptlist
[ MAXLEN
], banlist
[ MAXLEN
];
1632 unsigned int next
= 3 , res
= 1 ;
1633 int ctype
= 0 , echeck
= 0 , bcheck
= 0 ;
1634 struct chanNode
* cNode
;
1635 struct userNode
* un
;
1636 struct modeNode
* mNode
;
1639 char * user
, * end
, sep
;
1640 time_t in_timestamp
;
1650 while ( next
< argc
) {
1651 switch ( argv
[ next
][ 0 ]) {
1655 for ( pos
= argv
[ next
], n_modes
= 1 ; * pos
; pos
++)
1656 if ((* pos
== 'k' ) || (* pos
== 'l' ) || (* pos
== 'A' )
1659 unsplit_string ( argv
+ next
, n_modes
, modes
);
1664 for ( parm
= mysep (& argv
[ next
], " " ); /* parm = first param */
1665 parm
; /* While param is not null */
1666 parm
= mysep (& argv
[ next
], " " ) /* parm = next param */
1684 /* strip % char off start of very first ban */
1685 if ( strlen ( parm
) > 1 ) {
1686 strncat ( banlist
, strtok ( parm
, "%" ), sizeof ( banlist
) - 1 - strlen ( banlist
));
1687 strncat ( banlist
, " " , sizeof ( banlist
) - 1 - strlen ( banlist
));
1691 strncat ( banlist
, parm
, sizeof ( banlist
) - 1 - strlen ( banlist
));
1692 strncat ( banlist
, " " , sizeof ( banlist
) - 1 - strlen ( banlist
));
1694 } else if ( ctype
== 2 ) {
1698 strncat ( exemptlist
, parm
, sizeof ( exemptlist
) - 1 - strlen ( exemptlist
));
1699 strncat ( exemptlist
, " " , sizeof ( exemptlist
) - 1 - strlen ( exemptlist
));
1706 default : members
= argv
[ next
++]; break ;
1710 in_timestamp
= atoi ( argv
[ 2 ]);
1711 if (( cNode
= dict_find ( unbursted_channels
, argv
[ 1 ], NULL
))) {
1712 cNode
-> timestamp
= in_timestamp
;
1713 dict_remove ( unbursted_channels
, cNode
-> name
);
1716 cNode
= AddChannel ( argv
[ 1 ], in_timestamp
, modes
, banlist
, exemptlist
);
1718 /* Burst channel members in now. */
1719 for ( user
= members
, sep
= * members
, mode
= 0 ; sep
; user
= end
) {
1720 for ( end
= user
+ 3 ; isalnum (* end
) || * end
== '[' || * end
== ']' ; end
++) ;
1721 sep
= * end
++; end
[- 1 ] = 0 ;
1724 while (( sep
= * end
++)) {
1726 mode
|= MODE_CHANOP
;
1728 } else if ( sep
== 'h' ) {
1729 mode
|= MODE_HALFOP
;
1731 } else if ( sep
== 'v' ) {
1734 } else if ( isdigit ( sep
)) {
1735 mode
|= MODE_CHANOP
;
1737 oplevel
+= parse_oplevel ( end
);
1739 oplevel
= parse_oplevel ( end
);
1740 while ( isdigit (* end
)) end
++;
1747 if (!( un
= GetUserN ( user
))) {
1751 if (( mNode
= AddChannelUser ( un
, cNode
))) {
1752 mNode
-> modes
= mode
;
1753 mNode
-> oplevel
= oplevel
;
1761 * This is a stub that doesn't actually do anything. It should be completed
1762 * so that bans on *!*@markname.* match users as it does in nefarious
1764 static CMD_FUNC ( cmd_mark
)
1766 struct userNode
* target
;
1768 * log_module(MAIN_LOG, LOG_ERROR, "DEBUG: mark, user %s, type %s, arg %s", argv[1], argv[2], argv[3]);
1773 target
= GetUserH ( argv
[ 1 ]);
1775 log_module ( MAIN_LOG
, LOG_ERROR
, "Unable to find user %s whose mark is changing." , argv
[ 1 ]);
1778 if (! strcasecmp ( argv
[ 2 ], "DNSBL" )) {
1782 else if (! strcasecmp ( argv
[ 2 ], "DNSBL_DATA" )) {
1783 /* DNSBL_DATA name */
1784 target
-> mark
= strdup ( argv
[ 3 ]);
1788 /* unknown type of mark */
1792 static CMD_FUNC ( cmd_mode
)
1794 struct chanNode
* cn
;
1795 struct userNode
* un
;
1796 char * sethost
; // sethost - reed/apples
1797 int i
; // sethost - reed/apples
1801 if (! IsChannelName ( argv
[ 1 ])) {
1802 un
= GetUserH ( argv
[ 1 ]);
1804 log_module ( MAIN_LOG
, LOG_ERROR
, "Unable to find user %s whose mode is changing." , argv
[ 1 ]);
1807 // sethost - reed/apples
1809 mod_usermode ( un
, argv
[ 2 ]);
1811 sethost
= malloc ( strlen ( argv
[ 2 ]) + 1 + strlen ( argv
[ 3 ]) + 1 );
1813 while (( sethost
[ i
++] = * argv
[ 2 ]++));
1816 while (( sethost
[ i
++] = * argv
[ 3 ]++));
1817 mod_usermode ( un
, sethost
); // sethost - reed/apples
1823 if (!( cn
= GetChannel ( argv
[ 1 ]))) {
1824 log_module ( MAIN_LOG
, LOG_ERROR
, "Unable to find channel %s whose mode is changing." , argv
[ 1 ]);
1827 if (( un
= GetUserH ( origin
))) {
1828 struct modeNode
* mn
;
1829 /* Update idle time for person setting the mode */
1830 if (( mn
= GetUserMode ( cn
, un
)))
1831 mn
-> idle_since
= now
;
1833 /* If it came from a server, reset timestamp to re-sync. */
1834 cn
-> timestamp
= atoi ( argv
[ argc
- 1 ]);
1837 if ( checkDefCon ( DEFCON_NO_MODE_CHANGE
) && ! IsOper ( un
)) {
1839 str
= conf_get_data ( "services/opserv/nick" , RECDB_QSTRING
);
1841 char modes
[ MODELEN
];
1842 struct userNode
* opserv
= GetUserH ( str
);
1844 send_message_type ( 4 , un
, opserv
, "Channel modes cannot be changed due to DefCon level %d in effect, please try again soon" , DefConLevel
);
1845 irc_make_chanmode ( cn
, modes
);
1846 irc_mode ( opserv
, cn
, modes
);
1847 irc_mode ( opserv
, cn
, DefConChanModes
);
1853 return mod_chanmode ( un
, cn
, argv
+ 2 , argc
- 2 , MCP_ALLOW_OVB
| MCP_FROM_SERVER
|( un
? MC_NOTIFY
: 0 ));
1856 static CMD_FUNC ( cmd_opmode
)
1858 struct chanNode
* cn
;
1859 struct userNode
* un
;
1864 if (!( cn
= GetChannel ( argv
[ 1 ]))) {
1865 log_module ( MAIN_LOG
, LOG_ERROR
, "Unable to find channel %s whose mode is changing." , argv
[ 1 ]);
1868 if (!( un
= GetUserH ( origin
))) {
1869 log_module ( MAIN_LOG
, LOG_ERROR
, "Unable to find user %s requesting OPMODE." , origin
);
1873 log_module ( MAIN_LOG
, LOG_ERROR
, "Non-privileged user %s using OPMODE." , un
-> nick
);
1877 return mod_chanmode ( un
, cn
, argv
+ 2 , argc
- 2 , MCP_ALLOW_OVB
| MCP_FROM_SERVER
); /* do NOT announce opmode locally */
1880 static int clear_chanmode ( struct chanNode
* channel
, const char * modes
);
1882 static CMD_FUNC ( cmd_clearmode
)
1884 struct chanNode
* cn
;
1885 struct userNode
* un
;
1890 if (!( cn
= GetChannel ( argv
[ 1 ]))) {
1891 log_module ( MAIN_LOG
, LOG_ERROR
, "Unable to find channel %s whose mode is changing." , argv
[ 1 ]);
1894 if (!( un
= GetUserH ( origin
))) {
1895 log_module ( MAIN_LOG
, LOG_ERROR
, "Unable to find user %s requesting CLEARMODE." , origin
);
1899 log_module ( MAIN_LOG
, LOG_ERROR
, "Non-privileged user %s using CLEARMODE." , un
-> nick
);
1903 return clear_chanmode ( cn
, argv
[ 2 ]);
1906 static CMD_FUNC ( cmd_topic
)
1908 struct chanNode
* cn
;
1909 time_t chan_ts
, topic_ts
;
1910 struct userNode
* user
;
1914 if (!( cn
= GetChannel ( argv
[ 1 ]))) {
1915 log_module ( MAIN_LOG
, LOG_ERROR
, "Unable to find channel %s whose topic is being set" , argv
[ 1 ]);
1920 if ( argc
== 5 ) { /* Asuka / Topic Bursting IRCu's */
1921 user
= GetUserH ( origin
);
1922 chan_ts
= atoi ( argv
[ 2 ]);
1923 topic_ts
= atoi ( argv
[ 3 ]);
1924 } else if ( argc
>= 6 ) { /* Nefarious 0.5.0 */
1925 user
= GetUserH ( strtok ( argv
[ 2 ], "!" ));
1926 chan_ts
= atoi ( argv
[ 3 ]);
1927 topic_ts
= atoi ( argv
[ 4 ]);
1928 } else { /* Regular IRCu (No Topic Bursting)*/
1929 user
= GetUserH ( origin
);
1930 chan_ts
= cn
-> timestamp
;
1934 SetChannelTopic ( cn
, user
, user
, argv
[ argc
- 1 ], 0 );
1935 cn
-> topic_time
= topic_ts
;
1939 static CMD_FUNC ( cmd_num_topic
)
1941 struct chanNode
* cn
;
1944 return 0 ; /* huh? */
1946 cn
= GetChannel ( argv
[ 2 ]);
1948 log_module ( MAIN_LOG
, LOG_ERROR
, "Unable to find channel %s in topic reply" , argv
[ 2 ]);
1954 switch ( atoi ( argv
[ 0 ])) {
1957 break ; /* no topic */
1961 safestrncpy ( cn
-> topic
, unsplit_string ( argv
+ 3 , argc
- 3 , NULL
), sizeof ( cn
-> topic
));
1966 safestrncpy ( cn
-> topic_nick
, argv
[ 3 ], sizeof ( cn
-> topic_nick
));
1967 cn
-> topic_time
= atoi ( argv
[ 4 ]);
1970 return 0 ; /* should never happen */
1975 static CMD_FUNC ( cmd_num_gline
)
1979 gline_add ( origin
, argv
[ 3 ], atoi ( argv
[ 4 ])- now
, argv
[ 5 ], now
, 0 , 0 );
1983 static CMD_FUNC ( cmd_num_shun
)
1987 shun_add ( origin
, argv
[ 3 ], atoi ( argv
[ 4 ])- now
, argv
[ 5 ], now
, 0 );
1991 static CMD_FUNC ( cmd_quit
)
1993 struct userNode
* user
;
1996 /* Sometimes we get a KILL then a QUIT or the like, so we don't want to
1997 * call DelUser unless we have the user in our grasp. */
1998 if (( user
= GetUserH ( origin
)))
1999 DelUser ( user
, NULL
, false , argv
[ 1 ]);
2003 static CMD_FUNC ( cmd_kill
)
2005 struct userNode
* user
;
2008 user
= GetUserN ( argv
[ 1 ]);
2010 /* If we get a KILL for a non-existent user, it could be a
2011 * Ghost response to a KILL we sent out earlier. So we only
2012 * whine if the target is local.
2014 if (! strncmp ( argv
[ 1 ], self
-> numeric
, strlen ( self
-> numeric
)))
2015 log_module ( MAIN_LOG
, LOG_ERROR
, "Unable to find kill victim %s " , argv
[ 1 ]);
2019 if ( IsLocal ( user
) && IsService ( user
)) {
2020 /* TODO: rate limit this so silly things don't happen. */
2021 ReintroduceUser ( user
);
2025 DelUser ( user
, NULL
, false , argv
[ 2 ]);
2029 static CMD_FUNC ( cmd_part
)
2031 struct userNode
* user
;
2035 user
= GetUserH ( origin
);
2038 parse_foreach ( argv
[ 1 ], part_helper
, NULL
, NULL
, NULL
, user
);
2042 static CMD_FUNC ( cmd_svspart
)
2044 struct userNode
* user
;
2048 user
= GetUserN ( argv
[ 1 ]);
2051 parse_foreach ( argv
[ 2 ], part_helper
, NULL
, NULL
, NULL
, user
);
2055 static CMD_FUNC ( cmd_silence
)
2057 struct userNode
* user
;
2065 user
= GetUserN ( argv
[ 1 ]);
2067 /* Sanity, go nuts if this happens */
2071 /* We can safely ignore this if a user adding a silence is not
2072 * ignored. However this brings up a TODO. If a user logs in and
2073 * they have silences on the IRCd then we need to set them here
2076 if (! user
-> handle_info
)
2082 for ( i
= 0 ; i
< user
-> handle_info
-> ignores
-> used
; i
++) {
2083 if (! irccasecmp ( mask
+ 1 , user
-> handle_info
-> ignores
-> list
[ i
]))
2084 user
-> handle_info
-> ignores
-> list
[ i
] = user
-> handle_info
-> ignores
-> list
[-- user
-> handle_info
-> ignores
-> used
];
2087 for ( i
= 0 ; i
< user
-> handle_info
-> ignores
-> used
; i
++) {
2088 if (! strcmp ( mask
+ 1 , user
-> handle_info
-> ignores
-> list
[ i
]))
2089 return 1 ; /* Already on the users NickServ ignore list, safely ignore */
2092 new_mask
= strdup ( mask
+ 1 );
2093 string_list_append ( user
-> handle_info
-> ignores
, new_mask
);
2098 static CMD_FUNC ( cmd_kick
)
2102 ChannelUserKicked ( GetUserH ( origin
), GetUserN ( argv
[ 2 ]), GetChannel ( argv
[ 1 ]));
2106 static CMD_FUNC ( cmd_squit
)
2108 struct server
* server
;
2113 if (!( server
= GetServerH ( argv
[ 1 ])))
2116 if ( server
== self
-> uplink
) {
2117 /* Force a reconnect to the currently selected server. */
2118 cManager
. uplink
-> tries
= 0 ;
2119 log_module ( MAIN_LOG
, LOG_INFO
, "Squitting from uplink: %s " , argv
[ 3 ]);
2124 uplink
= strdup ( server
-> uplink
-> name
);
2125 DelServer ( server
, 0 , argv
[ 3 ]);
2126 /* if its a pingout and pingout connecting is enabled
2127 or its a read error and readerror connecting is enabled
2128 or were doing a "N" and i need to connect that server somewhere */
2129 routing_handle_squit ( argv
[ 1 ], uplink
, argv
[ 3 ]);
2134 static CMD_FUNC ( cmd_privmsg
)
2136 struct privmsg_desc pd
;
2139 pd
. user
= GetUserH ( origin
);
2140 if (! pd
. user
|| ( IsGagged ( pd
. user
) && ! IsOper ( pd
. user
)))
2143 if ( checkDefCon ( DEFCON_OPER_ONLY
) && ! IsOper ( pd
. user
)) {
2145 str
= conf_get_data ( "services/opserv/nick" , RECDB_QSTRING
);
2147 send_message_type ( 4 , pd
. user
, GetUserH ( str
), "Services are currently not available, please try again soon" );
2151 if ( checkDefCon ( DEFCON_SILENT_OPER_ONLY
) && ! IsOper ( pd
. user
))
2152 return 1 ; /* Silently Ignore */
2156 parse_foreach ( argv
[ 1 ], privmsg_chan_helper
, NULL
, privmsg_user_helper
, privmsg_invalid
, & pd
);
2161 static CMD_FUNC ( cmd_notice
)
2163 struct privmsg_desc pd
;
2170 pd
. user
= GetUserH ( origin
);
2173 if (! pd
. user
|| ( IsGagged ( pd
. user
) && ! IsOper ( pd
. user
))) {
2178 parse_foreach ( argv
[ 1 ], privmsg_chan_helper
, NULL
, privmsg_user_helper
, privmsg_invalid
, & pd
);
2181 srv
= GetServerH ( origin
);
2183 char * sargv
[ MAXNUMPARAMS
];
2186 sargc
= split_line ( argv
[ 2 ], true , MAXNUMPARAMS
, sargv
);
2188 if (! strcasecmp ( sargv
[ 0 ], "Connect:" )) {
2189 /* :Connect: Host shoe.loxxin.net not listed in ircd.conf */
2190 if (! strcasecmp ( sargv
[ 3 ], "not" ) && ! strcasecmp ( sargv
[ 4 ], "listed" )) {
2191 routing_handle_connect_failure ( srv
, sargv
[ 2 ], unsplit_string ( sargv
+ 3 , sargc
- 3 , NULL
));
2194 else if (! strcasecmp ( sargv
[ 0 ], "Link" )) {
2195 /* :Link with mephisto.etheria.cx cancelled: Server mephisto.etheria.cx[216.46.33.71]
2197 * :Link with laptop.afternet.org cancelled: Connection refused
2199 if (! strcasecmp ( sargv
[ 3 ], "cancelled:" )) {
2200 routing_handle_connect_failure ( srv
, sargv
[ 2 ], unsplit_string ( sargv
+ 4 , sargc
- 4 , NULL
));
2207 static CMD_FUNC ( cmd_away
)
2209 struct userNode
* uNode
;
2211 uNode
= GetUserH ( origin
);
2215 uNode
-> modes
&= ~ FLAGS_AWAY
;
2217 uNode
-> modes
|= FLAGS_AWAY
;
2221 static CMD_FUNC ( cmd_gline
)
2225 if ( argv
[ 2 ][ 0 ] == '+' ) {
2228 gline_add ( origin
, argv
[ 2 ]+ 1 , strtoul ( argv
[ 3 ], NULL
, 0 ), argv
[ argc
- 1 ], now
, 0 , 0 );
2230 } else if ( argv
[ 2 ][ 0 ] == '-' ) {
2231 gline_remove ( argv
[ 2 ]+ 1 , 0 );
2237 static CMD_FUNC ( cmd_shun
)
2241 if ( argv
[ 2 ][ 0 ] == '+' ) {
2244 shun_add ( origin
, argv
[ 2 ]+ 1 , strtoul ( argv
[ 3 ], NULL
, 0 ), argv
[ argc
- 1 ], now
, 0 );
2246 } else if ( argv
[ 2 ][ 0 ] == '-' ) {
2247 shun_remove ( argv
[ 2 ]+ 1 , 0 );
2253 static CMD_FUNC ( cmd_svsnick
)
2255 struct userNode
* target
, * dest
;
2257 || !( target
= GetUserN ( argv
[ 1 ]))
2259 || ( dest
= GetUserH ( argv
[ 2 ])))
2261 NickChange ( target
, argv
[ 2 ], 0 );
2265 static oper_func_t
* of_list
;
2266 static unsigned int of_size
= 0 , of_used
= 0 ;
2269 free_user ( struct userNode
* user
)
2280 free ( privmsg_funcs
);
2283 dict_delete ( irc_func_dict
);
2284 for ( nn
= 0 ; nn
< dead_users
. used
; nn
++)
2285 free_user ( dead_users
. list
[ nn
]);
2286 userList_clean (& dead_users
);
2290 p10_conf_reload ( void ) {
2291 hidden_host_suffix
= conf_get_data ( "server/hidden_host" , RECDB_QSTRING
);
2295 remove_unbursted_channel ( struct chanNode
* cNode
) {
2296 if ( unbursted_channels
)
2297 dict_remove ( unbursted_channels
, cNode
-> name
);
2303 const char * str
, * desc
;
2304 int numnick
, usermask
, max_users
;
2305 char numer
[ COMBO_NUMERIC_LEN
+ 1 ];
2307 /* read config items */
2308 str
= conf_get_data ( "server/extended_accounts" , RECDB_QSTRING
);
2309 extended_accounts
= str
? enabled_string ( str
) : 1 ;
2310 str
= conf_get_data ( "server/ping_freq" , RECDB_QSTRING
);
2311 ping_freq
= str
? ParseInterval ( str
) : 120 ;
2312 str
= conf_get_data ( "server/ping_timeout" , RECDB_QSTRING
);
2313 ping_timeout
= str
? ParseInterval ( str
) : 30 ;
2314 str
= conf_get_data ( "server/force_n2k" , RECDB_QSTRING
);
2315 force_n2k
= str
? enabled_string ( str
) : 1 ;
2316 str
= conf_get_data ( "server/numeric" , RECDB_QSTRING
);
2318 log_module ( MAIN_LOG
, LOG_ERROR
, "No server/numeric entry in config file." );
2321 numnick
= atoi ( str
);
2322 str
= conf_get_data ( "server/max_users" , RECDB_QSTRING
);
2323 max_users
= str
? atoi ( str
) : 4096 ;
2324 for ( usermask
= 4 ; usermask
< max_users
; usermask
<<= 1 ) ;
2326 if (( numnick
< 64 ) && ( usermask
< 4096 ) && ! force_n2k
)
2327 inttobase64 ( numer
, ( numnick
<< 12 ) + ( usermask
& 0x00fff ), 3 );
2329 inttobase64 ( numer
, ( numnick
<< 18 ) + ( usermask
& 0x3ffff ), 5 );
2331 str
= conf_get_data ( "server/his_servername" , RECDB_QSTRING
);
2332 his_servername
= str
? strdup ( str
) : NULL
;
2333 str
= conf_get_data ( "server/his_servercomment" , RECDB_QSTRING
);
2334 his_servercomment
= str
? strdup ( str
) : NULL
;
2336 str
= conf_get_data ( "server/hostname" , RECDB_QSTRING
);
2337 desc
= conf_get_data ( "server/description" , RECDB_QSTRING
);
2338 if (! str
|| ! desc
) {
2339 log_module ( MAIN_LOG
, LOG_ERROR
, "No server/hostname entry in config file." );
2342 self
= AddServer ( NULL
, str
, 0 , boot_time
, now
, numer
, desc
);
2343 conf_register_reload ( p10_conf_reload
);
2345 irc_func_dict
= dict_new ();
2346 dict_insert ( irc_func_dict
, CMD_BURST
, cmd_burst
);
2347 dict_insert ( irc_func_dict
, TOK_BURST
, cmd_burst
);
2348 dict_insert ( irc_func_dict
, CMD_CREATE
, cmd_create
);
2349 dict_insert ( irc_func_dict
, TOK_CREATE
, cmd_create
);
2350 dict_insert ( irc_func_dict
, CMD_EOB
, cmd_eob
);
2351 dict_insert ( irc_func_dict
, TOK_EOB
, cmd_eob
);
2352 dict_insert ( irc_func_dict
, CMD_EOB_ACK
, cmd_eob_ack
);
2353 dict_insert ( irc_func_dict
, TOK_EOB_ACK
, cmd_eob_ack
);
2354 dict_insert ( irc_func_dict
, CMD_MODE
, cmd_mode
);
2355 dict_insert ( irc_func_dict
, TOK_MODE
, cmd_mode
);
2356 dict_insert ( irc_func_dict
, CMD_MARK
, cmd_mark
);
2357 dict_insert ( irc_func_dict
, TOK_MARK
, cmd_mark
);
2358 dict_insert ( irc_func_dict
, CMD_NICK
, cmd_nick
);
2359 dict_insert ( irc_func_dict
, TOK_NICK
, cmd_nick
);
2360 dict_insert ( irc_func_dict
, CMD_ACCOUNT
, cmd_account
);
2361 dict_insert ( irc_func_dict
, TOK_ACCOUNT
, cmd_account
);
2362 dict_insert ( irc_func_dict
, CMD_FAKEHOST
, cmd_fakehost
);
2363 dict_insert ( irc_func_dict
, TOK_FAKEHOST
, cmd_fakehost
);
2364 dict_insert ( irc_func_dict
, CMD_PASS
, cmd_pass
);
2365 dict_insert ( irc_func_dict
, TOK_PASS
, cmd_pass
);
2366 dict_insert ( irc_func_dict
, CMD_PING
, cmd_ping
);
2367 dict_insert ( irc_func_dict
, TOK_PING
, cmd_ping
);
2368 dict_insert ( irc_func_dict
, CMD_PRIVMSG
, cmd_privmsg
);
2369 dict_insert ( irc_func_dict
, TOK_PRIVMSG
, cmd_privmsg
);
2370 dict_insert ( irc_func_dict
, CMD_PONG
, cmd_pong
);
2371 dict_insert ( irc_func_dict
, TOK_PONG
, cmd_pong
);
2372 dict_insert ( irc_func_dict
, CMD_QUIT
, cmd_quit
);
2373 dict_insert ( irc_func_dict
, TOK_QUIT
, cmd_quit
);
2374 dict_insert ( irc_func_dict
, CMD_SERVER
, cmd_server
);
2375 dict_insert ( irc_func_dict
, TOK_SERVER
, cmd_server
);
2376 dict_insert ( irc_func_dict
, CMD_JOIN
, cmd_join
);
2377 dict_insert ( irc_func_dict
, TOK_JOIN
, cmd_join
);
2378 dict_insert ( irc_func_dict
, CMD_PART
, cmd_part
);
2379 dict_insert ( irc_func_dict
, TOK_PART
, cmd_part
);
2380 dict_insert ( irc_func_dict
, CMD_ERROR
, cmd_error
);
2381 dict_insert ( irc_func_dict
, TOK_ERROR
, cmd_error
);
2382 dict_insert ( irc_func_dict
, CMD_TOPIC
, cmd_topic
);
2383 dict_insert ( irc_func_dict
, TOK_TOPIC
, cmd_topic
);
2384 dict_insert ( irc_func_dict
, CMD_AWAY
, cmd_away
);
2385 dict_insert ( irc_func_dict
, TOK_AWAY
, cmd_away
);
2386 dict_insert ( irc_func_dict
, CMD_SILENCE
, cmd_silence
);
2387 dict_insert ( irc_func_dict
, TOK_SILENCE
, cmd_silence
);
2388 dict_insert ( irc_func_dict
, CMD_KICK
, cmd_kick
);
2389 dict_insert ( irc_func_dict
, TOK_KICK
, cmd_kick
);
2390 dict_insert ( irc_func_dict
, CMD_SQUIT
, cmd_squit
);
2391 dict_insert ( irc_func_dict
, TOK_SQUIT
, cmd_squit
);
2392 dict_insert ( irc_func_dict
, CMD_KILL
, cmd_kill
);
2393 dict_insert ( irc_func_dict
, TOK_KILL
, cmd_kill
);
2394 dict_insert ( irc_func_dict
, CMD_NOTICE
, cmd_notice
);
2395 dict_insert ( irc_func_dict
, TOK_NOTICE
, cmd_notice
);
2396 dict_insert ( irc_func_dict
, CMD_STATS
, cmd_stats
);
2397 dict_insert ( irc_func_dict
, TOK_STATS
, cmd_stats
);
2398 dict_insert ( irc_func_dict
, CMD_SVSJOIN
, cmd_svsjoin
);
2399 dict_insert ( irc_func_dict
, TOK_SVSJOIN
, cmd_svsjoin
);
2400 dict_insert ( irc_func_dict
, CMD_SVSNICK
, cmd_svsnick
);
2401 dict_insert ( irc_func_dict
, TOK_SVSNICK
, cmd_svsnick
);
2402 dict_insert ( irc_func_dict
, CMD_SVSPART
, cmd_svspart
);
2403 dict_insert ( irc_func_dict
, TOK_SVSPART
, cmd_svspart
);
2404 dict_insert ( irc_func_dict
, CMD_SWHOIS
, cmd_dummy
);
2405 dict_insert ( irc_func_dict
, TOK_SWHOIS
, cmd_dummy
);
2406 dict_insert ( irc_func_dict
, CMD_WHOIS
, cmd_whois
);
2407 dict_insert ( irc_func_dict
, TOK_WHOIS
, cmd_whois
);
2408 dict_insert ( irc_func_dict
, CMD_GLINE
, cmd_gline
);
2409 dict_insert ( irc_func_dict
, TOK_GLINE
, cmd_gline
);
2410 dict_insert ( irc_func_dict
, CMD_SHUN
, cmd_shun
);
2411 dict_insert ( irc_func_dict
, TOK_SHUN
, cmd_shun
);
2412 dict_insert ( irc_func_dict
, CMD_OPMODE
, cmd_opmode
);
2413 dict_insert ( irc_func_dict
, TOK_OPMODE
, cmd_opmode
);
2414 dict_insert ( irc_func_dict
, CMD_CLEARMODE
, cmd_clearmode
);
2415 dict_insert ( irc_func_dict
, TOK_CLEARMODE
, cmd_clearmode
);
2416 dict_insert ( irc_func_dict
, CMD_VERSION
, cmd_version
);
2417 dict_insert ( irc_func_dict
, TOK_VERSION
, cmd_version
);
2418 dict_insert ( irc_func_dict
, CMD_ADMIN
, cmd_admin
);
2419 dict_insert ( irc_func_dict
, TOK_ADMIN
, cmd_admin
);
2421 dict_insert ( irc_func_dict
, CMD_RPING
, cmd_rping
);
2422 dict_insert ( irc_func_dict
, TOK_RPING
, cmd_rping
);
2423 dict_insert ( irc_func_dict
, CMD_RPONG
, cmd_dummy
);
2424 dict_insert ( irc_func_dict
, TOK_RPONG
, cmd_dummy
);
2426 /* In P10, DESTRUCT doesn't do anything except be broadcast to servers.
2427 * Apparently to obliterate channels from any servers that think they
2430 dict_insert ( irc_func_dict
, CMD_DESTRUCT
, cmd_dummy
);
2431 dict_insert ( irc_func_dict
, TOK_DESTRUCT
, cmd_dummy
);
2432 /* Ignore invites */
2433 dict_insert ( irc_func_dict
, CMD_INVITE
, cmd_dummy
);
2434 dict_insert ( irc_func_dict
, TOK_INVITE
, cmd_dummy
);
2435 /* DESYNCH is just informational, so ignore it */
2436 dict_insert ( irc_func_dict
, CMD_DESYNCH
, cmd_dummy
);
2437 dict_insert ( irc_func_dict
, TOK_DESYNCH
, cmd_dummy
);
2438 /* Ignore channel operator notices. */
2439 dict_insert ( irc_func_dict
, CMD_WALLCHOPS
, cmd_dummy
);
2440 dict_insert ( irc_func_dict
, TOK_WALLCHOPS
, cmd_dummy
);
2441 dict_insert ( irc_func_dict
, CMD_WALLVOICES
, cmd_dummy
);
2442 dict_insert ( irc_func_dict
, TOK_WALLVOICES
, cmd_dummy
);
2443 dict_insert ( irc_func_dict
, CMD_WALLHOPS
, cmd_dummy
);
2444 dict_insert ( irc_func_dict
, TOK_WALLHOPS
, cmd_dummy
);
2445 /* Ignore opers being silly. */
2446 dict_insert ( irc_func_dict
, CMD_WALLOPS
, cmd_dummy
);
2447 dict_insert ( irc_func_dict
, TOK_WALLOPS
, cmd_dummy
);
2448 dict_insert ( irc_func_dict
, CMD_WALLHOPS
, cmd_dummy
);
2449 dict_insert ( irc_func_dict
, TOK_WALLHOPS
, cmd_dummy
);
2450 dict_insert ( irc_func_dict
, TOK_WALLUSERS
, cmd_dummy
);
2451 /* Ignore dnsbl exemptions */
2452 dict_insert ( irc_func_dict
, TOK_EXEMPT
, cmd_dummy
);
2453 dict_insert ( irc_func_dict
, CMD_PRIVS
, cmd_privs
);
2454 dict_insert ( irc_func_dict
, TOK_PRIVS
, cmd_privs
);
2455 /* Ignore remote luser */
2456 dict_insert ( irc_func_dict
, TOK_LUSERS
, cmd_dummy
);
2457 /* We have reliable clock! Always! Wraaa! */
2458 dict_insert ( irc_func_dict
, CMD_SETTIME
, cmd_dummy
);
2459 dict_insert ( irc_func_dict
, TOK_SETTIME
, cmd_dummy
);
2461 /* ignore /trace and /motd commands targetted at us */
2462 dict_insert ( irc_func_dict
, TOK_TRACE
, cmd_dummy
);
2463 dict_insert ( irc_func_dict
, TOK_MOTD
, cmd_dummy
);
2466 dict_insert ( irc_func_dict
, "331" , cmd_num_topic
);
2467 dict_insert ( irc_func_dict
, "332" , cmd_num_topic
);
2468 dict_insert ( irc_func_dict
, "333" , cmd_num_topic
);
2469 dict_insert ( irc_func_dict
, "345" , cmd_dummy
); /* blah has been invited to blah */
2470 dict_insert ( irc_func_dict
, "432" , cmd_error_nick
); /* Erroneus [sic] nickname */
2471 /* ban list resetting */
2472 /* "stats g" responses */
2473 dict_insert ( irc_func_dict
, "247" , cmd_num_gline
);
2474 dict_insert ( irc_func_dict
, "542" , cmd_num_shun
);
2475 dict_insert ( irc_func_dict
, "219" , cmd_dummy
); /* "End of /STATS report" */
2476 /* other numeric responses we might get */
2477 dict_insert ( irc_func_dict
, "401" , cmd_dummy
); /* target left network */
2478 dict_insert ( irc_func_dict
, "403" , cmd_dummy
); /* no such channel */
2479 dict_insert ( irc_func_dict
, "404" , cmd_dummy
); /* cannot send to channel */
2480 dict_insert ( irc_func_dict
, "439" , cmd_dummy
); /* target change too fast */
2481 dict_insert ( irc_func_dict
, "441" , cmd_dummy
); /* target isn't on that channel */
2482 dict_insert ( irc_func_dict
, "442" , cmd_dummy
); /* you aren't on that channel */
2483 dict_insert ( irc_func_dict
, "443" , cmd_dummy
); /* is already on channel (after invite?) */
2484 dict_insert ( irc_func_dict
, "461" , cmd_dummy
); /* Not enough parameters (after TOPIC w/ 0 args) */
2485 dict_insert ( irc_func_dict
, "467" , cmd_dummy
); /* Channel key already set */
2487 num_privmsg_funcs
= 16 ;
2488 privmsg_funcs
= malloc ( sizeof ( privmsg_func_t
)* num_privmsg_funcs
);
2489 memset ( privmsg_funcs
, 0 , sizeof ( privmsg_func_t
)* num_privmsg_funcs
);
2491 num_notice_funcs
= 16 ;
2492 notice_funcs
= malloc ( sizeof ( privmsg_func_t
)* num_notice_funcs
);
2493 memset ( notice_funcs
, 0 , sizeof ( privmsg_func_t
)* num_notice_funcs
);
2495 userList_init (& dead_users
);
2496 reg_del_channel_func ( remove_unbursted_channel
);
2497 reg_exit_func ( parse_cleanup
);
2498 // reg_notice_func(opserv, check_ctcp);
2502 parse_line ( char * line
, int recursive
)
2504 char * argv
[ MAXNUMPARAMS
], * origin
;
2505 int argc
, cmd
, res
= 0 ;
2508 argc
= split_line ( line
, true , MAXNUMPARAMS
, argv
);
2509 cmd
= self
-> uplink
|| ! argv
[ 0 ][ 1 ] || ! argv
[ 0 ][ 2 ];
2512 if ( argv
[ 0 ][ 0 ] == ':' ) {
2514 } else if (! argv
[ 0 ][ 1 ] || ! argv
[ 0 ][ 2 ]) {
2515 struct server
* sNode
= GetServerN ( argv
[ 0 ]);
2516 origin
= sNode
? sNode
-> name
: 0 ;
2518 struct userNode
* uNode
= GetUserN ( argv
[ 0 ]);
2519 origin
= uNode
? uNode
-> nick
: 0 ;
2523 if (( func
= dict_find ( irc_func_dict
, argv
[ cmd
], NULL
)))
2524 res
= func ( origin
, argc
- cmd
, argv
+ cmd
);
2527 log_module ( MAIN_LOG
, LOG_ERROR
, "PARSE ERROR on line: %s " , unsplit_string ( argv
, argc
, NULL
));
2528 } else if (! recursive
) {
2530 for ( i
= 0 ; i
< dead_users
. used
; i
++)
2531 free_user ( dead_users
. list
[ i
]);
2532 dead_users
. used
= 0 ;
2538 parse_foreach ( char * target_list
, foreach_chanfunc cf
, foreach_nonchan nc
, foreach_userfunc uf
, foreach_nonuser nu
, void * data
)
2544 while (* j
!= 0 && * j
!= ',' )
2549 if ( IsChannelName ( target_list
)
2550 || ( target_list
[ 0 ] == '0' && target_list
[ 1 ] == '\0' )) {
2551 struct chanNode
* chan
= GetChannel ( target_list
);
2558 nc ( target_list
, data
);
2561 struct userNode
* user
;
2562 struct privmsg_desc
* pd
= data
;
2564 pd
-> is_qualified
= 0 ;
2565 if (* target_list
== '@' ) {
2567 } else if ( strchr ( target_list
, '@' )) {
2568 struct server
* server
;
2570 pd
-> is_qualified
= 1 ;
2571 user
= GetUserH ( strtok ( target_list
, "@" ));
2572 server
= GetServerH ( strtok ( NULL
, "@" ));
2574 if ( user
&& ( user
-> uplink
!= server
)) {
2575 /* Don't attempt to index into any arrays
2576 using a user's numeric on another server. */
2580 user
= GetUserN ( target_list
);
2588 nu ( target_list
, data
);
2592 } while ( old
== ',' );
2596 get_local_numeric ( void )
2598 static unsigned int next_numeric
= 0 ;
2599 if ( self
-> clients
> self
-> num_mask
)
2601 while ( self
-> users
[ next_numeric
])
2602 if (++ next_numeric
> self
-> num_mask
)
2604 return next_numeric
;
2608 make_numeric ( struct server
* svr
, int local_num
, char * outbuf
)
2612 if ( force_n2k
|| svr
-> numeric
[ 1 ]) {
2617 llen
= ( local_num
< 64 * 64 ) ? 2 : 3 ;
2619 strncpy ( outbuf
, svr
-> numeric
, slen
);
2620 inttobase64 ( outbuf
+ slen
, local_num
, llen
);
2621 outbuf
[ slen
+ llen
] = 0 ;
2625 AddServer ( struct server
* uplink
, const char * name
, int hops
, time_t boot
, time_t link
, const char * numeric
, const char * description
)
2627 struct server
* sNode
;
2630 if (( sNode
= GetServerN ( numeric
))) {
2631 /* This means we're trying to re-add an existant server.
2632 * To be safe, we should forget the previous incarnation.
2633 * (And all its linked servers.)
2635 * It usually only happens in replays when the original
2636 * had a ping timeout and the replay didn't (because
2637 * replaying a ping timeout invariably gets things wrong).
2639 DelServer ( sNode
, 0 , NULL
);
2642 switch ( strlen ( numeric
)) {
2643 case 5 : slen
= 2 ; mlen
= 3 ; break ;
2644 case 4 : slen
= 1 ; mlen
= 3 ; break ;
2645 case 3 : slen
= 1 ; mlen
= 2 ; break ;
2647 log_module ( MAIN_LOG
, LOG_ERROR
, "AddServer( \" %s \" , \" %s \" , ...): Numeric %s has invalid length." , uplink
-> name
, name
, numeric
);
2651 sNode
= calloc ( 1 , sizeof (* sNode
));
2652 sNode
-> uplink
= uplink
;
2653 safestrncpy ( sNode
-> name
, name
, sizeof ( sNode
-> name
));
2654 sNode
-> num_mask
= base64toint ( numeric
+ slen
, mlen
);
2658 strncpy ( sNode
-> numeric
, numeric
, slen
);
2659 safestrncpy ( sNode
-> description
, description
, sizeof ( sNode
-> description
));
2660 sNode
-> users
= calloc ( sNode
-> num_mask
+ 1 , sizeof (* sNode
-> users
));
2661 serverList_init (& sNode
-> children
);
2662 if ( sNode
-> uplink
) {
2663 /* uplink may be NULL if we're just building ourself */
2664 serverList_append (& sNode
-> uplink
-> children
, sNode
);
2666 servers_num
[ base64toint ( numeric
, slen
)] = sNode
;
2667 dict_insert ( servers
, sNode
-> name
, sNode
);
2671 void DelServer ( struct server
* serv
, int announce
, const char * message
)
2675 /* If we receive an ERROR command before the SERVER
2676 * command a NULL server can be passed */
2680 /* Hrm, what's the right way to SQUIT some other server?
2681 * (This code is only to handle killing juped servers.) */
2682 if ( announce
&& ( serv
-> uplink
== self
) && ( serv
!= self
-> uplink
))
2683 irc_squit ( serv
, message
, NULL
);
2685 /* must recursively remove servers linked to this one first */
2686 for ( i
= serv
-> children
. used
; i
> 0 ;)
2687 if ( serv
-> children
. list
[-- i
] != self
)
2688 DelServer ( serv
-> children
. list
[ i
], false , NULL
);
2690 /* clean up server's user hash tables */
2691 for ( i
= 0 ; i
<= serv
-> num_mask
; i
++)
2693 DelUser ( serv
-> users
[ i
], NULL
, false , "server delinked" );
2697 serverList_remove (& serv
-> uplink
-> children
, serv
);
2698 if ( serv
== self
-> uplink
)
2699 self
-> uplink
= NULL
;
2700 servers_num
[ base64toint ( serv
-> numeric
, strlen ( serv
-> numeric
))] = NULL
;
2701 dict_remove ( servers
, serv
-> name
);
2702 serverList_clean (& serv
-> children
);
2708 AddService ( const char * nick
, const char * modes
, const char * desc
, const char * hostname
)
2710 char numeric
[ COMBO_NUMERIC_LEN
+ 1 ];
2711 int local_num
= get_local_numeric ();
2712 time_t timestamp
= now
;
2713 struct userNode
* old_user
= GetUserH ( nick
);
2716 if ( IsLocal ( old_user
))
2718 timestamp
= old_user
-> timestamp
- 1 ;
2720 if ( local_num
== - 1 ) {
2721 log_module ( MAIN_LOG
, LOG_ERROR
, "Unable to allocate numnick for service %s " , nick
);
2725 hostname
= self
-> name
;
2726 make_numeric ( self
, local_num
, numeric
);
2727 /* TODO: Make these modes part of the conf file */
2728 return AddUser ( self
, nick
, nick
, hostname
, modes
? modes
: "+oik" , numeric
, desc
, now
, "AAAAAA" );
2732 AddClone ( const char * nick
, const char * ident
, const char * hostname
, const char * desc
)
2734 char numeric
[ COMBO_NUMERIC_LEN
+ 1 ];
2735 int local_num
= get_local_numeric ();
2736 time_t timestamp
= now
;
2737 struct userNode
* old_user
= GetUserH ( nick
);
2740 if ( IsLocal ( old_user
))
2742 timestamp
= old_user
-> timestamp
- 1 ;
2744 if ( local_num
== - 1 ) {
2745 log_module ( MAIN_LOG
, LOG_ERROR
, "Unable to allocate numnick for clone %s " , nick
);
2748 make_numeric ( self
, local_num
, numeric
);
2749 return AddUser ( self
, nick
, ident
, hostname
, "+i" , numeric
, desc
, timestamp
, "AAAAAA" );
2753 is_valid_nick ( const char * nick
) {
2755 /* IRC has some of The Most Fucked-Up ideas about character sets
2757 if (! isalpha (* nick
) && ! strchr ( "{|}~[ \\ ]^_`" , * nick
))
2759 for ( ii
= 0 ; nick
[ ii
]; ++ ii
)
2760 if (! isalnum ( nick
[ ii
]) && ! strchr ( "{|}~[ \\ ]^-_`" , nick
[ ii
]))
2762 if ( strlen ( nick
) > nicklen
)
2767 static struct userNode
*
2768 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
)
2770 struct userNode
* oldUser
, * uNode
;
2771 unsigned int n
, ignore_user
;
2773 if (( strlen ( numeric
) < 3 ) || ( strlen ( numeric
) > 5 )) {
2774 log_module ( MAIN_LOG
, LOG_WARNING
, "AddUser( %p , %s , ...): numeric %s wrong length!" , uplink
, nick
, numeric
);
2779 log_module ( MAIN_LOG
, LOG_WARNING
, "AddUser( %p , %s , ...): server for numeric %s doesn't exist!" , uplink
, nick
, numeric
);
2783 if ( uplink
!= GetServerN ( numeric
)) {
2784 log_module ( MAIN_LOG
, LOG_WARNING
, "AddUser( %p , %s , ...): server for numeric %s differs from nominal uplink %s ." , uplink
, nick
, numeric
, uplink
-> name
);
2788 if (! is_valid_nick ( nick
)) {
2789 log_module ( MAIN_LOG
, LOG_WARNING
, "AddUser( %p , %s , ...): invalid nickname detected." , uplink
, nick
);
2794 if (( oldUser
= GetUserH ( nick
))) {
2795 if ( IsLocal ( oldUser
) && ( IsService ( oldUser
) || IsPersistent ( oldUser
))) {
2796 /* The service should collide the new user off. */
2797 oldUser
-> timestamp
= timestamp
- 1 ;
2800 if ( oldUser
-> timestamp
> timestamp
) {
2801 /* "Old" user is really newer; remove them */
2802 DelUser ( oldUser
, 0 , 1 , "Overruled by older nick" );
2804 /* User being added is too new; do not add them to
2805 * clients, but do add them to the server's list, since it
2806 * will send a KILL and QUIT soon. */
2811 /* create new usernode and set all values */
2812 uNode
= calloc ( 1 , sizeof (* uNode
));
2813 uNode
-> nick
= strdup ( nick
);
2814 safestrncpy ( uNode
-> ident
, ident
, sizeof ( uNode
-> ident
));
2815 safestrncpy ( uNode
-> info
, userinfo
, sizeof ( uNode
-> info
));
2816 safestrncpy ( uNode
-> hostname
, hostname
, sizeof ( uNode
-> hostname
));
2817 safestrncpy ( uNode
-> numeric
, numeric
, sizeof ( uNode
-> numeric
));
2818 irc_p10_pton (& uNode
-> ip
, realip
);
2820 if ( irc_in_addr_is_ipv4 ( uNode
-> ip
)) {
2821 make_virtip (( char *) irc_ntoa (& uNode
-> ip
), ( char *) irc_ntoa (& uNode
-> ip
), uNode
-> cryptip
);
2822 make_virthost (( char *) irc_ntoa (& uNode
-> ip
), uNode
-> hostname
, uNode
-> crypthost
);
2823 } else if ( irc_in_addr_is_ipv6 ( uNode
-> ip
)) {
2824 make_ipv6virthost (( char *) irc_ntoa (& uNode
-> ip
), uNode
-> hostname
, uNode
-> crypthost
);
2827 if (! uNode
-> crypthost
&& uNode
-> cryptip
)
2828 snprintf ( uNode
-> crypthost
, sizeof ( uNode
-> crypthost
), " %s " , strdup ( uNode
-> cryptip
));
2830 uNode
-> timestamp
= timestamp
;
2831 modeList_init (& uNode
-> channels
);
2832 uNode
-> uplink
= uplink
;
2833 if (++ uNode
-> uplink
-> clients
> uNode
-> uplink
-> max_clients
) {
2834 uNode
-> uplink
-> max_clients
= uNode
-> uplink
-> clients
;
2836 uNode
-> num_local
= base64toint ( numeric
+ strlen ( uNode
-> uplink
-> numeric
), 3 ) & uNode
-> uplink
-> num_mask
;
2837 uNode
-> uplink
-> users
[ uNode
-> num_local
] = uNode
;
2838 mod_usermode ( uNode
, modes
);
2840 set_geoip_info ( uNode
);
2845 dict_insert ( clients
, uNode
-> nick
, uNode
);
2846 if ( dict_size ( clients
) > max_clients
) {
2847 max_clients
= dict_size ( clients
);
2848 max_clients_time
= now
;
2852 for ( n
= 0 ; n
< nuf_used
; n
++)
2853 if ( nuf_list
[ n
]( uNode
))
2856 if (( uNode
-> loc
== 1 ) && ( uNode
-> handle_info
))
2857 send_func_list ( uNode
);
2862 /* removes user from it's server's hash table and nick hash table */
2864 DelUser ( struct userNode
* user
, struct userNode
* killer
, int announce
, const char * why
)
2870 /* mark them as dead, in case anybody cares */
2873 /* remove pending adduser commands */
2874 wipe_adduser_pending ( NULL
, user
);
2876 /* remove user from all channels */
2877 while ( user
-> channels
. used
> 0 )
2878 DelChannelUser ( user
, user
-> channels
. list
[ user
-> channels
. used
- 1 ]-> channel
, false , 0 );
2880 /* Call these in reverse order so ChanServ can update presence
2881 information before NickServ nukes the handle_info. */
2882 for ( n
= duf_used
; n
> 0 ; )
2883 duf_list
[-- n
]( user
, killer
, why
);
2885 user
-> uplink
-> clients
--;
2886 user
-> uplink
-> users
[ user
-> num_local
] = NULL
;
2888 userList_remove (& curr_opers
, user
);
2889 /* remove from global dictionary, but not if after a collide */
2890 if ( user
== dict_find ( clients
, user
-> nick
, NULL
))
2891 dict_remove ( clients
, user
-> nick
);
2893 if ( IsInvisible ( user
))
2898 irc_quit ( user
, why
);
2900 irc_kill ( killer
, user
, why
);
2903 modeList_clean (& user
-> channels
);
2905 /* Clean up version data */
2906 if ( user
-> version_reply
) {
2907 free ( user
-> version_reply
);
2908 user
-> version_reply
= NULL
;
2917 /* clean up geoip data if any */
2918 if ( user
-> country_code
) free ( user
-> country_code
);
2919 if ( user
-> city
) free ( user
-> city
);
2920 if ( user
-> region
) free ( user
-> region
);
2921 if ( user
-> postal_code
) free ( user
-> postal_code
);
2923 /* We don't free them, in case we try to privmsg them or something
2924 * (like when a stupid oper kills themself). We just put them onto
2925 * a list of clients that get freed after processing each line.
2927 if ( dead_users
. size
)
2928 userList_append (& dead_users
, user
);
2933 static void call_oper_funcs ( struct userNode
* user
);
2935 void mod_usermode ( struct userNode
* user
, const char * mode_change
) {
2937 const char * word
= mode_change
;
2939 if (! user
|| ! mode_change
)
2942 call_user_mode_funcs ( user
, mode_change
);
2944 while (* word
!= ' ' && * word
) word
++;
2945 while (* word
== ' ' ) word
++;
2947 #define do_user_mode(FLAG) do { if (add) user->modes |= FLAG; else user->modes &= ~FLAG; } while (0)
2948 switch (* mode_change
++) {
2949 case 0 : case ' ' : return ;
2950 case '+' : add
= 1 ; break ;
2951 case '-' : add
= 0 ; break ;
2954 if (! IsOper ( user
)) { /* Dont re-oper an oper */
2955 userList_append (& curr_opers
, user
);
2956 call_oper_funcs ( user
);
2959 userList_remove (& curr_opers
, user
);
2961 do_user_mode ( FLAGS_OPER
);
2963 case 'O' : do_user_mode ( FLAGS_LOCOP
); break ;
2964 case 'i' : do_user_mode ( FLAGS_INVISIBLE
);
2970 case 'w' : do_user_mode ( FLAGS_WALLOP
); break ;
2971 case 's' : do_user_mode ( FLAGS_SERVNOTICE
); break ;
2972 case 'd' : do_user_mode ( FLAGS_DEAF
); break ;
2973 case 'k' : do_user_mode ( FLAGS_SERVICE
); break ;
2974 case 'g' : do_user_mode ( FLAGS_GLOBAL
); break ;
2975 // sethost - reed/apples
2976 // case 'h': do_user_mode(FLAGS_HELPER); break;
2977 // I check if there's an 'h' in the first part, and if there,
2978 // then everything after the space becomes their new host.
2979 case 'h' : do_user_mode ( FLAGS_SETHOST
);
2981 char sethost
[ MAXLEN
];
2983 for ( ii
= 0 ; (* word
!= ' ' ) && (* word
!= '\0' ); )
2984 sethost
[ ii
++] = * word
++;
2986 while (* word
== ' ' )
2988 safestrncpy ( user
-> sethost
, sethost
, sizeof ( user
-> sethost
));
2991 case 'x' : do_user_mode ( FLAGS_HIDDEN_HOST
); break ;
2996 for ( ii
= 0 ; (* word
!= ' ' ) && (* word
!= '\0' ); )
2997 tag
[ ii
++] = * word
++;
2999 while (* word
== ' ' )
3001 call_account_func ( user
, tag
);
3008 for ( ii
= 0 ; (* word
!= ' ' ) && (* word
!= '\0' ); )
3009 host
[ ii
++] = * word
++;
3011 while (* word
== ' ' )
3013 assign_fakehost ( user
, host
, 0 );
3021 struct mod_chanmode
*
3022 mod_chanmode_parse ( struct chanNode
* channel
, char ** modes
, unsigned int argc
, unsigned int flags
, short base_oplevel
)
3024 struct mod_chanmode
* change
;
3025 unsigned int ii
, in_arg
, ch_arg
, add
;
3029 if (!( change
= mod_chanmode_alloc ( argc
- 1 )))
3032 for ( ii
= ch_arg
= 0 , in_arg
= add
= 1 ;
3033 ( modes
[ 0 ][ ii
] != '\0' ) && ( modes
[ 0 ][ ii
] != ' ' );
3035 switch ( modes
[ 0 ][ ii
]) {
3042 #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)
3043 case 'C' : do_chan_mode ( MODE_NOCTCPS
); break ;
3044 case 'D' : do_chan_mode ( MODE_DELAYJOINS
); break ;
3045 case 'c' : do_chan_mode ( MODE_NOCOLORS
); break ;
3046 case 'i' : do_chan_mode ( MODE_INVITEONLY
); break ;
3047 case 'm' : do_chan_mode ( MODE_MODERATED
); break ;
3048 case 'n' : do_chan_mode ( MODE_NOPRIVMSGS
); break ;
3049 case 'p' : do_chan_mode ( MODE_PRIVATE
); break ;
3050 case 'r' : do_chan_mode ( MODE_REGONLY
); break ;
3051 case 's' : do_chan_mode ( MODE_SECRET
); break ;
3052 case 't' : do_chan_mode ( MODE_TOPICLIMIT
); break ;
3053 case 'S' : do_chan_mode ( MODE_STRIPCOLOR
); break ;
3054 case 'M' : do_chan_mode ( MODE_MODUNREG
); break ;
3055 case 'N' : do_chan_mode ( MODE_NONOTICE
); break ;
3056 case 'Q' : do_chan_mode ( MODE_NOQUITMSGS
); break ;
3057 case 'T' : do_chan_mode ( MODE_NOAMSG
); break ;
3058 case 'O' : do_chan_mode ( MODE_OPERSONLY
); break ;
3059 case 'Z' : do_chan_mode ( MODE_SSLONLY
); break ;
3060 case 'L' : do_chan_mode ( MODE_HIDEMODE
); break ;
3062 if (!( flags
& MCP_REGISTERED
)) {
3063 do_chan_mode ( MODE_REGISTERED
);
3065 mod_chanmode_free ( change
);
3074 change
-> modes_set
|= MODE_LIMIT
;
3075 change
-> new_limit
= atoi ( modes
[ in_arg
++]);
3077 change
-> modes_set
&= ~ MODE_LIMIT
;
3078 change
-> modes_clear
|= MODE_LIMIT
;
3085 change
-> modes_set
|= MODE_KEY
;
3086 safestrncpy ( change
-> new_key
, modes
[ in_arg
++], sizeof ( change
-> new_key
));
3088 change
-> modes_clear
|= MODE_KEY
;
3089 if (!( flags
& MCP_KEY_FREE
)) {
3101 change
-> modes_set
|= MODE_UPASS
;
3102 safestrncpy ( change
-> new_upass
, modes
[ in_arg
++], sizeof ( change
-> new_upass
));
3104 change
-> modes_clear
|= MODE_UPASS
;
3105 if (!( flags
& MCP_UPASS_FREE
)) {
3116 change
-> modes_set
|= MODE_APASS
;
3117 safestrncpy ( change
-> new_apass
, modes
[ in_arg
++], sizeof ( change
-> new_apass
));
3119 change
-> modes_clear
|= MODE_APASS
;
3120 if (!( flags
& MCP_APASS_FREE
)) {
3128 if (!( flags
& MCP_ALLOW_OVB
))
3132 change
-> args
[ ch_arg
]. mode
= MODE_BAN
;
3134 change
-> args
[ ch_arg
]. mode
|= MODE_REMOVE
;
3135 change
-> args
[ ch_arg
++]. u
. hostmask
= modes
[ in_arg
++];
3138 if (!( flags
& MCP_ALLOW_OVB
))
3142 change
-> args
[ ch_arg
]. mode
= MODE_EXEMPT
;
3144 change
-> args
[ ch_arg
]. mode
|= MODE_REMOVE
;
3145 change
-> args
[ ch_arg
++]. u
. hostmask
= modes
[ in_arg
++];
3147 case 'o' : case 'h' : case 'v' :
3149 struct userNode
* victim
;
3155 oplevel_str
= strchr ( modes
[ in_arg
], ':' );
3158 /* XXYYY M #channel +o XXYYY:<oplevel> */
3159 * oplevel_str
++ = '\0' ;
3160 oplevel
= parse_oplevel ( oplevel_str
);
3161 if ( oplevel
<= base_oplevel
&& !( flags
& MCP_FROM_SERVER
))
3162 oplevel
= base_oplevel
+ 1 ;
3164 else if ( channel
-> modes
& MODE_UPASS
)
3165 oplevel
= base_oplevel
+ 1 ;
3169 /* Check that oplevel is within bounds. */
3170 if ( oplevel
> MAXOPLEVEL
)
3171 oplevel
= MAXOPLEVEL
;
3173 if (!( flags
& MCP_ALLOW_OVB
))
3178 if ( modes
[ 0 ][ ii
] == 'o' )
3179 change
-> args
[ ch_arg
]. mode
= MODE_CHANOP
;
3180 else if ( modes
[ 0 ][ ii
] == 'h' )
3181 change
-> args
[ ch_arg
]. mode
= MODE_HALFOP
;
3182 else if ( modes
[ 0 ][ ii
] == 'v' )
3183 change
-> args
[ ch_arg
]. mode
= MODE_VOICE
;
3186 change
-> args
[ ch_arg
]. mode
|= MODE_REMOVE
;
3187 if ( flags
& MCP_FROM_SERVER
)
3188 victim
= GetUserN ( modes
[ in_arg
++]);
3190 victim
= GetUserH ( modes
[ in_arg
++]);
3193 if (( change
-> args
[ ch_arg
]. u
. member
= GetUserMode ( channel
, victim
)))
3195 /* Apply the oplevel change */
3196 change
-> args
[ ch_arg
]. u
. member
-> oplevel
= oplevel
;
3202 if (!( flags
& MCP_FROM_SERVER
))
3207 change
-> argc
= ch_arg
; /* in case any turned out to be ignored */
3208 if ( change
-> modes_set
& MODE_SECRET
) {
3209 change
-> modes_set
&= ~( MODE_PRIVATE
);
3210 change
-> modes_clear
|= MODE_PRIVATE
;
3211 } else if ( change
-> modes_set
& MODE_PRIVATE
) {
3212 change
-> modes_set
&= ~( MODE_SECRET
);
3213 change
-> modes_clear
|= MODE_SECRET
;
3217 mod_chanmode_free ( change
);
3221 struct chanmode_buffer
{
3224 struct chanNode
* channel
;
3225 struct userNode
* actor
;
3226 unsigned int modes_used
;
3227 unsigned int args_used
;
3229 unsigned int is_add
: 1 ;
3230 unsigned int is_chanop
: 1 ;
3234 mod_chanmode_append ( struct chanmode_buffer
* buf
, char ch
, const char * arg
)
3236 size_t arg_len
= strlen ( arg
);
3237 if ( buf
-> modes_used
> ( MAXMODEPARAMS
) ||
3238 buf
-> modes_used
+ buf
-> args_used
+ buf
-> chname_len
+ arg_len
> 450 ) {
3239 memcpy ( buf
-> modes
+ buf
-> modes_used
, buf
-> args
, buf
-> args_used
);
3240 buf
-> modes
[ buf
-> modes_used
+ buf
-> args_used
] = '\0' ;
3241 irc_mode (( buf
-> is_chanop
? buf
-> actor
: NULL
), buf
-> channel
, buf
-> modes
);
3242 buf
-> modes
[ 0 ] = buf
-> is_add
? '+' : '-' ;
3243 buf
-> modes_used
= 1 ;
3246 buf
-> modes
[ buf
-> modes_used
++] = ch
;
3247 buf
-> args
[ buf
-> args_used
++] = ' ' ;
3248 memcpy ( buf
-> args
+ buf
-> args_used
, arg
, arg_len
);
3249 buf
-> args_used
+= arg_len
;
3253 mod_chanmode_announce ( struct userNode
* who
, struct chanNode
* channel
, struct mod_chanmode
* change
)
3255 struct chanmode_buffer chbuf
;
3257 struct modeNode
* mn
;
3258 char int_buff
[ 32 ], mode
= '\0' ;
3260 assert ( change
-> argc
<= change
-> alloc_argc
);
3261 memset (& chbuf
, 0 , sizeof ( chbuf
));
3262 chbuf
. channel
= channel
;
3264 chbuf
. chname_len
= strlen ( channel
-> name
);
3266 mn
= GetUserMode ( channel
, who
);
3267 if (( mn
&& ( mn
-> modes
& MODE_CHANOP
)) || off_channel
)
3268 chbuf
. is_chanop
= 1 ;
3270 /* First remove modes */
3272 if ( change
-> modes_clear
) {
3274 chbuf
. modes
[ chbuf
. modes_used
++] = mode
= '-' ;
3275 #define DO_MODE_CHAR(BIT, CHAR) if (change->modes_clear & MODE_##BIT) chbuf.modes[chbuf.modes_used++] = CHAR
3276 DO_MODE_CHAR ( PRIVATE
, 'p' );
3277 DO_MODE_CHAR ( SECRET
, 's' );
3278 DO_MODE_CHAR ( MODERATED
, 'm' );
3279 DO_MODE_CHAR ( TOPICLIMIT
, 't' );
3280 DO_MODE_CHAR ( INVITEONLY
, 'i' );
3281 DO_MODE_CHAR ( NOPRIVMSGS
, 'n' );
3282 DO_MODE_CHAR ( LIMIT
, 'l' );
3283 DO_MODE_CHAR ( DELAYJOINS
, 'D' );
3284 DO_MODE_CHAR ( REGONLY
, 'r' );
3285 DO_MODE_CHAR ( NOCOLORS
, 'c' );
3286 DO_MODE_CHAR ( NOCTCPS
, 'C' );
3287 DO_MODE_CHAR ( STRIPCOLOR
, 'S' );
3288 DO_MODE_CHAR ( MODUNREG
, 'M' );
3289 DO_MODE_CHAR ( NONOTICE
, 'N' );
3290 DO_MODE_CHAR ( NOQUITMSGS
, 'Q' );
3291 DO_MODE_CHAR ( NOAMSG
, 'T' );
3292 DO_MODE_CHAR ( OPERSONLY
, 'O' );
3293 DO_MODE_CHAR ( REGISTERED
, 'z' );
3294 DO_MODE_CHAR ( SSLONLY
, 'Z' );
3295 DO_MODE_CHAR ( HIDEMODE
, 'L' );
3297 if ( change
-> modes_clear
& channel
-> modes
& MODE_KEY
)
3298 mod_chanmode_append (& chbuf
, 'k' , channel
-> key
);
3299 if ( change
-> modes_clear
& channel
-> modes
& MODE_UPASS
)
3300 mod_chanmode_append (& chbuf
, 'U' , channel
-> upass
);
3301 if ( change
-> modes_clear
* channel
-> modes
& MODE_APASS
)
3302 mod_chanmode_append (& chbuf
, 'A' , channel
-> apass
);
3304 for ( arg
= 0 ; arg
< change
-> argc
; ++ arg
) {
3305 if (!( change
-> args
[ arg
]. mode
& MODE_REMOVE
))
3308 chbuf
. modes
[ chbuf
. modes_used
++] = mode
= '-' ;
3309 switch ( change
-> args
[ arg
]. mode
& ~ MODE_REMOVE
) {
3311 mod_chanmode_append (& chbuf
, 'b' , change
-> args
[ arg
]. u
. hostmask
);
3314 mod_chanmode_append (& chbuf
, 'e' , change
-> args
[ arg
]. u
. hostmask
);
3317 if ( change
-> args
[ arg
]. mode
& MODE_CHANOP
)
3318 mod_chanmode_append (& chbuf
, 'o' , change
-> args
[ arg
]. u
. member
-> user
-> numeric
);
3319 if ( change
-> args
[ arg
]. mode
& MODE_HALFOP
)
3320 mod_chanmode_append (& chbuf
, 'h' , change
-> args
[ arg
]. u
. member
-> user
-> numeric
);
3321 if ( change
-> args
[ arg
]. mode
& MODE_VOICE
)
3322 mod_chanmode_append (& chbuf
, 'v' , change
-> args
[ arg
]. u
. member
-> user
-> numeric
);
3329 if ( change
-> modes_set
) {
3331 chbuf
. modes
[ chbuf
. modes_used
++] = mode
= '+' ;
3332 #define DO_MODE_CHAR(BIT, CHAR) if (change->modes_set & MODE_##BIT) chbuf.modes[chbuf.modes_used++] = CHAR
3333 DO_MODE_CHAR ( PRIVATE
, 'p' );
3334 DO_MODE_CHAR ( SECRET
, 's' );
3335 DO_MODE_CHAR ( MODERATED
, 'm' );
3336 DO_MODE_CHAR ( TOPICLIMIT
, 't' );
3337 DO_MODE_CHAR ( INVITEONLY
, 'i' );
3338 DO_MODE_CHAR ( NOPRIVMSGS
, 'n' );
3339 DO_MODE_CHAR ( DELAYJOINS
, 'D' );
3340 DO_MODE_CHAR ( REGONLY
, 'r' );
3341 DO_MODE_CHAR ( NOCOLORS
, 'c' );
3342 DO_MODE_CHAR ( NOCTCPS
, 'C' );
3343 DO_MODE_CHAR ( STRIPCOLOR
, 'S' );
3344 DO_MODE_CHAR ( MODUNREG
, 'M' );
3345 DO_MODE_CHAR ( NONOTICE
, 'N' );
3346 DO_MODE_CHAR ( NOQUITMSGS
, 'Q' );
3347 DO_MODE_CHAR ( NOAMSG
, 'T' );
3348 DO_MODE_CHAR ( OPERSONLY
, 'O' );
3349 DO_MODE_CHAR ( REGISTERED
, 'z' );
3350 DO_MODE_CHAR ( SSLONLY
, 'Z' );
3351 DO_MODE_CHAR ( HIDEMODE
, 'L' );
3353 if ( change
-> modes_set
& MODE_KEY
)
3354 mod_chanmode_append (& chbuf
, 'k' , change
-> new_key
);
3355 if ( change
-> modes_set
& MODE_UPASS
)
3356 mod_chanmode_append (& chbuf
, 'U' , change
-> new_upass
);
3357 if ( change
-> modes_set
& MODE_APASS
)
3358 mod_chanmode_append (& chbuf
, 'A' , change
-> new_apass
);
3359 if ( change
-> modes_set
& MODE_LIMIT
) {
3360 sprintf ( int_buff
, " %d " , change
-> new_limit
);
3361 mod_chanmode_append (& chbuf
, 'l' , int_buff
);
3364 for ( arg
= 0 ; arg
< change
-> argc
; ++ arg
) {
3365 if ( change
-> args
[ arg
]. mode
& MODE_REMOVE
)
3368 chbuf
. modes
[ chbuf
. modes_used
++] = mode
= '+' ;
3369 switch ( change
-> args
[ arg
]. mode
) {
3371 mod_chanmode_append (& chbuf
, 'b' , change
-> args
[ arg
]. u
. hostmask
);
3374 mod_chanmode_append (& chbuf
, 'e' , change
-> args
[ arg
]. u
. hostmask
);
3377 if ( change
-> args
[ arg
]. mode
& MODE_CHANOP
)
3378 mod_chanmode_append (& chbuf
, 'o' , change
-> args
[ arg
]. u
. member
-> user
-> numeric
);
3379 if ( change
-> args
[ arg
]. mode
& MODE_HALFOP
)
3380 mod_chanmode_append (& chbuf
, 'h' , change
-> args
[ arg
]. u
. member
-> user
-> numeric
);
3381 if ( change
-> args
[ arg
]. mode
& MODE_VOICE
)
3382 mod_chanmode_append (& chbuf
, 'v' , change
-> args
[ arg
]. u
. member
-> user
-> numeric
);
3387 /* Flush the buffer and apply changes locally */
3388 if ( chbuf
. modes_used
> 0 ) {
3389 memcpy ( chbuf
. modes
+ chbuf
. modes_used
, chbuf
. args
, chbuf
. args_used
);
3390 chbuf
. modes
[ chbuf
. modes_used
+ chbuf
. args_used
] = '\0' ;
3391 irc_mode (( chbuf
. is_chanop
? chbuf
. actor
: NULL
), chbuf
. channel
, chbuf
. modes
);
3393 mod_chanmode_apply ( who
, channel
, change
);
3397 mod_chanmode_format ( struct mod_chanmode
* change
, char * outbuff
)
3399 unsigned int used
= 0 ;
3400 assert ( change
-> argc
<= change
-> alloc_argc
);
3401 if ( change
-> modes_clear
) {
3402 outbuff
[ used
++] = '-' ;
3403 #define DO_MODE_CHAR(BIT, CHAR) if (change->modes_clear & MODE_##BIT) outbuff[used++] = CHAR
3404 DO_MODE_CHAR ( PRIVATE
, 'p' );
3405 DO_MODE_CHAR ( SECRET
, 's' );
3406 DO_MODE_CHAR ( MODERATED
, 'm' );
3407 DO_MODE_CHAR ( TOPICLIMIT
, 't' );
3408 DO_MODE_CHAR ( INVITEONLY
, 'i' );
3409 DO_MODE_CHAR ( NOPRIVMSGS
, 'n' );
3410 DO_MODE_CHAR ( LIMIT
, 'l' );
3411 DO_MODE_CHAR ( KEY
, 'k' );
3412 DO_MODE_CHAR ( UPASS
, 'U' );
3413 DO_MODE_CHAR ( APASS
, 'A' );
3414 DO_MODE_CHAR ( DELAYJOINS
, 'D' );
3415 DO_MODE_CHAR ( REGONLY
, 'r' );
3416 DO_MODE_CHAR ( NOCOLORS
, 'c' );
3417 DO_MODE_CHAR ( NOCTCPS
, 'C' );
3418 DO_MODE_CHAR ( STRIPCOLOR
, 'S' );
3419 DO_MODE_CHAR ( MODUNREG
, 'M' );
3420 DO_MODE_CHAR ( NONOTICE
, 'N' );
3421 DO_MODE_CHAR ( NOQUITMSGS
, 'Q' );
3422 DO_MODE_CHAR ( NOAMSG
, 'T' );
3423 DO_MODE_CHAR ( OPERSONLY
, 'O' );
3424 DO_MODE_CHAR ( REGISTERED
, 'z' );
3425 DO_MODE_CHAR ( SSLONLY
, 'Z' );
3426 DO_MODE_CHAR ( HIDEMODE
, 'L' );
3429 if ( change
-> modes_set
) {
3430 outbuff
[ used
++] = '+' ;
3431 #define DO_MODE_CHAR(BIT, CHAR) if (change->modes_set & MODE_##BIT) outbuff[used++] = CHAR
3432 DO_MODE_CHAR ( PRIVATE
, 'p' );
3433 DO_MODE_CHAR ( SECRET
, 's' );
3434 DO_MODE_CHAR ( MODERATED
, 'm' );
3435 DO_MODE_CHAR ( TOPICLIMIT
, 't' );
3436 DO_MODE_CHAR ( INVITEONLY
, 'i' );
3437 DO_MODE_CHAR ( NOPRIVMSGS
, 'n' );
3438 DO_MODE_CHAR ( DELAYJOINS
, 'D' );
3439 DO_MODE_CHAR ( REGONLY
, 'r' );
3440 DO_MODE_CHAR ( NOCOLORS
, 'c' );
3441 DO_MODE_CHAR ( NOCTCPS
, 'C' );
3442 DO_MODE_CHAR ( STRIPCOLOR
, 'S' );
3443 DO_MODE_CHAR ( MODUNREG
, 'M' );
3444 DO_MODE_CHAR ( NONOTICE
, 'N' );
3445 DO_MODE_CHAR ( NOQUITMSGS
, 'Q' );
3446 DO_MODE_CHAR ( NOAMSG
, 'T' );
3447 DO_MODE_CHAR ( OPERSONLY
, 'O' );
3448 DO_MODE_CHAR ( REGISTERED
, 'z' );
3449 DO_MODE_CHAR ( SSLONLY
, 'Z' );
3450 DO_MODE_CHAR ( HIDEMODE
, 'L' );
3452 switch ( change
-> modes_set
& ( MODE_KEY
| MODE_LIMIT
| MODE_APASS
| MODE_UPASS
)) {
3453 /* Doing this implementation has been a pain in the arse, I hope I didn't forget a possible combination */
3454 case MODE_KEY
| MODE_LIMIT
| MODE_APASS
| MODE_UPASS
:
3455 used
+= sprintf ( outbuff
+ used
, "lkAU %d %s %s %s " , change
-> new_limit
, change
-> new_key
, change
-> new_apass
, change
-> new_upass
);
3458 case MODE_KEY
| MODE_LIMIT
| MODE_APASS
:
3459 used
+= sprintf ( outbuff
+ used
, "lkA %d %s %s " , change
-> new_limit
, change
-> new_key
, change
-> new_apass
);
3461 case MODE_KEY
| MODE_LIMIT
| MODE_UPASS
:
3462 used
+= sprintf ( outbuff
+ used
, "lkU %d %s %s " , change
-> new_limit
, change
-> new_key
, change
-> new_upass
);
3464 case MODE_KEY
| MODE_APASS
| MODE_UPASS
:
3465 used
+= sprintf ( outbuff
+ used
, "kAU %s %s %s " , change
-> new_key
, change
-> new_apass
, change
-> new_upass
);
3468 case MODE_KEY
| MODE_APASS
:
3469 used
+= sprintf ( outbuff
+ used
, "kA %s %s " , change
-> new_key
, change
-> new_apass
);
3471 case MODE_KEY
| MODE_UPASS
:
3472 used
+= sprintf ( outbuff
+ used
, "kU %s %s " , change
-> new_key
, change
-> new_upass
);
3474 case MODE_KEY
| MODE_LIMIT
:
3475 used
+= sprintf ( outbuff
+ used
, "lk %d %s " , change
-> new_limit
, change
-> new_key
);
3478 case MODE_LIMIT
| MODE_UPASS
:
3479 used
+= sprintf ( outbuff
+ used
, "lU %d %s " , change
-> new_limit
, change
-> new_upass
);
3481 case MODE_LIMIT
| MODE_APASS
:
3482 used
+= sprintf ( outbuff
+ used
, "lA %d %s " , change
-> new_limit
, change
-> new_apass
);
3484 case MODE_APASS
| MODE_UPASS
:
3485 used
+= sprintf ( outbuff
+ used
, "AU %s %s " , change
-> new_apass
, change
-> new_upass
);
3487 case MODE_LIMIT
| MODE_APASS
| MODE_UPASS
:
3488 used
+= sprintf ( outbuff
+ used
, "lAU %d %s %s " , change
-> new_limit
, change
-> new_apass
, change
-> new_upass
);
3492 used
+= sprintf ( outbuff
+ used
, "A %s " , change
-> new_apass
);
3495 used
+= sprintf ( outbuff
+ used
, "U %s " , change
-> new_upass
);
3498 used
+= sprintf ( outbuff
+ used
, "k %s " , change
-> new_key
);
3501 used
+= sprintf ( outbuff
+ used
, "l %d " , change
-> new_limit
);
3510 clear_chanmode ( struct chanNode
* channel
, const char * modes
)
3512 unsigned int remove
;
3514 for ( remove
= 0 ; * modes
; modes
++) {
3516 case 'o' : remove
|= MODE_CHANOP
; break ;
3517 case 'h' : remove
|= MODE_HALFOP
; break ;
3518 case 'v' : remove
|= MODE_VOICE
; break ;
3519 case 'p' : remove
|= MODE_PRIVATE
; break ;
3520 case 's' : remove
|= MODE_SECRET
; break ;
3521 case 'm' : remove
|= MODE_MODERATED
; break ;
3522 case 't' : remove
|= MODE_TOPICLIMIT
; break ;
3523 case 'i' : remove
|= MODE_INVITEONLY
; break ;
3524 case 'n' : remove
|= MODE_NOPRIVMSGS
; break ;
3527 channel
-> key
[ 0 ] = '\0' ;
3530 remove
|= MODE_APASS
;
3531 channel
-> apass
[ 0 ] = '\0' ;
3534 remove
|= MODE_UPASS
;
3535 channel
-> upass
[ 0 ] = '\0' ;
3538 remove
|= MODE_LIMIT
;
3541 case 'b' : remove
|= MODE_BAN
; break ;
3542 case 'e' : remove
|= MODE_EXEMPT
; break ;
3543 case 'D' : remove
|= MODE_DELAYJOINS
; break ;
3544 case 'r' : remove
|= MODE_REGONLY
; break ;
3545 case 'c' : remove
|= MODE_NOCOLORS
; break ;
3546 case 'C' : remove
|= MODE_NOCTCPS
; break ;
3547 case 'S' : remove
|= MODE_STRIPCOLOR
; break ;
3548 case 'M' : remove
|= MODE_MODUNREG
; break ;
3549 case 'N' : remove
|= MODE_NONOTICE
; break ;
3550 case 'Q' : remove
|= MODE_NOQUITMSGS
; break ;
3551 case 'T' : remove
|= MODE_NOAMSG
; break ;
3552 case 'O' : remove
|= MODE_OPERSONLY
; break ;
3553 case 'z' : remove
|= MODE_REGISTERED
; break ;
3554 case 'Z' : remove
|= MODE_SSLONLY
; break ;
3555 case 'L' : remove
|= MODE_HIDEMODE
; break ;
3562 /* Remove simple modes. */
3563 channel
-> modes
&= ~ remove
;
3565 /* If removing bans, kill 'em all. */
3566 if (( remove
& MODE_BAN
) && channel
-> banlist
. used
) {
3568 for ( i
= 0 ; i
< channel
-> banlist
. used
; i
++)
3569 free ( channel
-> banlist
. list
[ i
]);
3570 channel
-> banlist
. used
= 0 ;
3573 /* If removing exempts, kill 'em all. */
3574 if (( remove
& MODE_EXEMPT
) && channel
-> exemptlist
. used
) {
3576 for ( i
= 0 ; i
< channel
-> exemptlist
. used
; i
++)
3577 free ( channel
-> exemptlist
. list
[ i
]);
3578 channel
-> exemptlist
. used
= 0 ;
3581 /* Remove member modes. */
3582 if (( remove
& ( MODE_CHANOP
| MODE_HALFOP
| MODE_VOICE
)) && channel
-> members
. used
) {
3583 int mask
= ~( remove
& ( MODE_CHANOP
| MODE_HALFOP
| MODE_VOICE
));
3586 for ( i
= 0 ; i
< channel
-> members
. used
; i
++)
3587 channel
-> members
. list
[ i
]-> modes
&= mask
;
3594 reg_privmsg_func ( struct userNode
* user
, privmsg_func_t handler
)
3596 unsigned int numeric
= user
-> num_local
;
3597 if ( numeric
>= num_privmsg_funcs
) {
3598 int newnum
= numeric
+ 8 ;
3599 privmsg_funcs
= realloc ( privmsg_funcs
, newnum
* sizeof ( privmsg_func_t
));
3600 memset ( privmsg_funcs
+ num_privmsg_funcs
, 0 , ( newnum
- num_privmsg_funcs
)* sizeof ( privmsg_func_t
));
3601 num_privmsg_funcs
= newnum
;
3603 if ( privmsg_funcs
[ numeric
])
3604 log_module ( MAIN_LOG
, LOG_WARNING
, "re-registering new privmsg handler for numeric %d " , numeric
);
3605 privmsg_funcs
[ numeric
] = handler
;
3609 unreg_privmsg_func ( struct userNode
* user
, privmsg_func_t handler
)
3613 if (! user
|| handler
)
3614 return ; /* this really only works with users */
3616 memset ( privmsg_funcs
+ user
-> num_local
, 0 , sizeof ( privmsg_func_t
));
3618 for ( x
= user
-> num_local
+ 1 ; x
< num_privmsg_funcs
; x
++)
3619 memmove ( privmsg_funcs
+ x
- 1 , privmsg_funcs
+ x
, sizeof ( privmsg_func_t
));
3621 privmsg_funcs
= realloc ( privmsg_funcs
, num_privmsg_funcs
* sizeof ( privmsg_func_t
));
3622 num_privmsg_funcs
--;
3627 reg_notice_func ( struct userNode
* user
, privmsg_func_t handler
)
3629 unsigned int numeric
= user
-> num_local
;
3630 if ( numeric
>= num_notice_funcs
) {
3631 int newnum
= numeric
+ 8 ;
3632 notice_funcs
= realloc ( notice_funcs
, newnum
* sizeof ( privmsg_func_t
));
3633 memset ( notice_funcs
+ num_notice_funcs
, 0 , ( newnum
- num_notice_funcs
)* sizeof ( privmsg_func_t
));
3634 num_notice_funcs
= newnum
;
3636 if ( notice_funcs
[ numeric
])
3637 log_module ( MAIN_LOG
, LOG_WARNING
, "re-registering new notice handler for numeric %d " , numeric
);
3638 notice_funcs
[ numeric
] = handler
;
3642 unreg_notice_func ( struct userNode
* user
, privmsg_func_t handler
)
3646 if (! user
|| handler
)
3647 return ; /* this really only works with users */
3649 memset ( notice_funcs
+ user
-> num_local
, 0 , sizeof ( privmsg_func_t
));
3651 for ( x
= user
-> num_local
+ 1 ; x
< num_notice_funcs
; x
++)
3652 memmove ( notice_funcs
+ x
- 1 , notice_funcs
+ x
, sizeof ( privmsg_func_t
));
3654 memset ( notice_funcs
+ user
-> num_local
, 0 , sizeof ( privmsg_func_t
));
3655 notice_funcs
= realloc ( notice_funcs
, num_notice_funcs
* sizeof ( privmsg_func_t
));
3660 reg_oper_func ( oper_func_t handler
)
3662 if ( of_used
== of_size
) {
3665 of_list
= realloc ( of_list
, of_size
* sizeof ( oper_func_t
));
3668 of_list
= malloc ( of_size
* sizeof ( oper_func_t
));
3671 of_list
[ of_used
++] = handler
;
3675 call_oper_funcs ( struct userNode
* user
)
3680 for ( n
= 0 ; n
< of_used
; n
++)
3687 unsigned int i
, hop
, max_hop
= 1 ;
3690 /* burst (juped) servers, closest first (except self, which is sent already) */
3691 for ( i
= 0 ; i
< ArrayLength ( servers_num
); i
++)
3692 if ( servers_num
[ i
] && servers_num
[ i
]-> hops
> max_hop
)
3693 max_hop
= servers_num
[ i
]-> hops
;
3694 for ( hop
= 1 ; hop
<= max_hop
; hop
++) {
3695 for ( i
= 0 ; i
< ArrayLength ( servers_num
); i
++) {
3697 && ( servers_num
[ i
]-> hops
== hop
)
3698 && ( servers_num
[ i
] != self
-> uplink
))
3699 irc_server ( servers_num
[ i
]);
3703 /* burst local nicks */
3704 for ( i
= 0 ; i
<= self
-> num_mask
; i
++)
3706 irc_user ( self
-> users
[ i
]);
3708 /* build dict of unbursted channel names (just copy existing channels) */
3709 unbursted_channels
= dict_new ();
3710 for ( it
= dict_first ( channels
); it
; it
= iter_next ( it
))
3711 dict_insert ( unbursted_channels
, iter_key ( it
), iter_data ( it
));
3718 parse_oplevel ( char * str
)
3721 while ( isdigit (* str
))
3722 oplevel
= oplevel
* 10 + * str
++ - '0' ;