]>
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
);
384 privmsg_user_helper(struct userNode
*un
, void *data
)
386 struct privmsg_desc
*pd
= data
;
387 unsigned int num
= un
->num_local
;
388 if (!pd
->is_notice
) {
389 if ((num
< num_privmsg_funcs
) && privmsg_funcs
[num
]) {
390 privmsg_funcs
[num
](pd
->user
, un
, pd
->text
, pd
->is_qualified
);
393 if ((num
< num_notice_funcs
) && notice_funcs
[num
]) {
394 notice_funcs
[num
](pd
->user
, un
, pd
->text
, pd
->is_qualified
);
399 /* equiv to user doing /connect server port target */
400 void irc_connect(struct userNode
*user
, char *server
, unsigned int port
, struct server
*target
)
402 putsock("%s " P10_CONNECT
" %s %d %s", user
->numeric
, server
, port
, target
->numeric
);
406 irc_squit_route(struct server
*srv
, const char *message
, ...)
410 va_start(arg_list
, message
);
411 vsnprintf(buffer
, MAXLEN
-2, message
, arg_list
);
412 buffer
[MAXLEN
-1] = 0;
414 /* When would we squit ourselves exactly?? -Rubin */
415 if(srv
== self
&& cManager
.uplink
->state
== CONNECTED
) {
418 /* Quit all clients linked to me. */
419 for(i
= 0; i
<= self
->num_mask
; i
++) {
422 irc_quit(self
->users
[i
], buffer
);
426 putsock("%s " P10_SQUIT
" %s %d :%s", self
->numeric
, srv
->name
, 0, buffer
);
429 /* Force a reconnect to the currently selected server. */
430 cManager
.uplink
->tries
= 0;
431 log_module(MAIN_LOG
, LOG_INFO
, "Squitting from uplink: %s", buffer
);
437 irc_server(struct server
*srv
)
439 char extranum
[COMBO_NUMERIC_LEN
+1];
441 inttobase64(extranum
, srv
->num_mask
, (srv
->numeric
[1] || (srv
->num_mask
>= 64*64)) ? 3 : 2);
443 putsock(P10_SERVER
" %s %d %li %li J10 %s%s +s6 :%s",
444 srv
->name
, srv
->hops
+1, srv
->boot
, srv
->link
, srv
->numeric
, extranum
, srv
->description
);
446 putsock("%s " P10_SERVER
" %s %d %li %li %c10 %s%s +s6 :%s",
447 self
->numeric
, srv
->name
, srv
->hops
+1, srv
->boot
, srv
->link
, (srv
->self_burst
? 'J' : 'P'), srv
->numeric
, extranum
, srv
->description
);
452 irc_p10_pton(irc_in_addr_t
*ip
, const char *input
)
454 if (strlen(input
) == 6) {
456 memset(ip
, 0, 6 * sizeof(ip
->in6
[0]));
457 value
= base64toint(input
, 6);
459 ip
->in6
[5] = htons(65535);
460 ip
->in6
[6] = htons(value
>> 16);
461 ip
->in6
[7] = htons(value
& 65535);
463 unsigned int pos
= 0;
467 for (left
= (25 - strlen(input
)) / 3; left
; left
--)
471 ip
->in6
[pos
++] = ntohs(base64toint(input
, 3));
479 irc_p10_ntop(char *output
, const irc_in_addr_t
*ip
)
481 if (!irc_in_addr_is_valid(*ip
)) {
482 strcpy(output
, "AAAAAA");
483 } else if (irc_in_addr_is_ipv4(*ip
)) {
485 in4
= (ntohs(ip
->in6
[6]) << 16) | ntohs(ip
->in6
[7]);
486 inttobase64(output
, in4
, 6);
488 } else if (irc_in_addr_is_ipv6(*ip
)) {
489 unsigned int max_start
, max_zeros
, curr_zeros
, zero
, ii
;
490 /* Can start by printing out the leading non-zero parts. */
491 for (ii
= 0; (ip
->in6
[ii
]) && (ii
< 8); ++ii
) {
492 inttobase64(output
, ntohs(ip
->in6
[ii
]), 3);
495 /* Find the longest run of zeros. */
496 for (max_start
= zero
= ii
, max_zeros
= curr_zeros
= 0; ii
< 8; ++ii
) {
499 else if (curr_zeros
> max_zeros
) {
500 max_start
= ii
- curr_zeros
;
501 max_zeros
= curr_zeros
;
505 if (curr_zeros
> max_zeros
) {
506 max_start
= ii
- curr_zeros
;
507 max_zeros
= curr_zeros
;
510 /* Print the rest of the address */
511 for (ii
= zero
; ii
< 8; ) {
512 if ((ii
== max_start
) && max_zeros
) {
516 inttobase64(output
, ntohs(ip
->in6
[ii
]), 3);
522 strcpy(output
, "???");
527 irc_user(struct userNode
*user
)
532 irc_p10_ntop(b64ip
, &user
->ip
);
539 modes
[modelen
++] = 'o';
540 if (IsInvisible(user
))
541 modes
[modelen
++] = 'i';
543 modes
[modelen
++] = 'w';
545 modes
[modelen
++] = 'k';
546 if (IsServNotice(user
))
547 modes
[modelen
++] = 's';
549 modes
[modelen
++] = 'd';
551 modes
[modelen
++] = 'g';
552 // sethost - reed/apples
553 // if (IsHelperIrcu(user))
555 modes
[modelen
++] = 'h';
556 if (IsFakeHost(user
))
557 modes
[modelen
++] = 'f';
558 if (IsHiddenHost(user
))
559 modes
[modelen
++] = 'x';
562 /* we don't need to put the + in modes because it's in the format string. */
563 putsock("%s " P10_NICK
" %s %d %li %s %s +%s %s %s :%s",
564 user
->uplink
->numeric
, user
->nick
, user
->uplink
->hops
+1, user
->timestamp
, user
->ident
, user
->hostname
, modes
, b64ip
, user
->numeric
, user
->info
);
566 putsock("%s " P10_NICK
" %s %d %li %s %s %s %s :%s",
567 user
->uplink
->numeric
, user
->nick
, user
->uplink
->hops
+1, user
->timestamp
, user
->ident
, user
->hostname
, b64ip
, user
->numeric
, user
->info
);
572 irc_rename(struct userNode
*user
, const char *new_handle
)
574 if(extended_accounts
)
575 putsock("%s " P10_ACCOUNT
" %s M %s", self
->numeric
, user
->numeric
, new_handle
);
579 irc_delete(struct userNode
*user
)
581 if(extended_accounts
)
582 putsock("%s " P10_ACCOUNT
" %s U", self
->numeric
, user
->numeric
);
586 irc_account(struct userNode
*user
, const char *stamp
, time_t timestamp
)
588 if(extended_accounts
)
589 putsock("%s " P10_ACCOUNT
" %s R %s %lu", self
->numeric
, user
->numeric
, stamp
, timestamp
);
591 putsock("%s " P10_ACCOUNT
" %s %s %lu", self
->numeric
, user
->numeric
, stamp
, timestamp
);
595 irc_fakehost(struct userNode
*user
, const char *host
)
597 putsock("%s " P10_FAKEHOST
" %s %s", self
->numeric
, user
->numeric
, host
);
601 irc_regnick(UNUSED_ARG(struct userNode
*user
))
603 /* no operation here */
607 irc_nick(struct userNode
*user
, UNUSED_ARG(const char *old_nick
))
609 putsock("%s " P10_NICK
" %s "FMT_TIME_T
, user
->numeric
, user
->nick
, now
);
613 irc_fetchtopic(struct userNode
*from
, const char *to
)
617 putsock("%s " P10_TOPIC
" %s", from
->numeric
, to
);
621 irc_squit(struct server
*srv
, const char *message
, const char *service_message
)
623 if (!service_message
)
624 service_message
= message
;
626 /* Are we leaving the network? */
627 if (srv
== self
&& cManager
.uplink
->state
== CONNECTED
) {
630 /* Quit all clients linked to me. */
631 for (i
= 0; i
<= self
->num_mask
; i
++) {
634 irc_quit(self
->users
[i
], service_message
);
638 putsock("%s " P10_SQUIT
" %s %d :%s", self
->numeric
, srv
->name
, 0, message
);
641 /* Force a reconnect to the currently selected server. */
642 cManager
.uplink
->tries
= 0;
643 log_module(MAIN_LOG
, LOG_INFO
, "Squitting from uplink: %s", message
);
649 irc_wallchops(struct userNode
*from
, const char *to
, const char *message
)
651 putsock("%s " P10_WALLCHOPS
" %s :%s", from
->numeric
, to
, message
);
655 irc_wallops(const char *format
, ...)
659 va_start(arg_list
, format
);
660 vsnprintf(buffer
, MAXLEN
-2, format
, arg_list
);
661 buffer
[MAXLEN
-1] = 0;
662 putsock("%s " P10_WALLOPS
" :%s", self
->numeric
, buffer
);
666 irc_notice(struct userNode
*from
, const char *to
, const char *message
)
668 putsock("%s " P10_NOTICE
" %s :%s", from
->numeric
, to
, message
);
672 irc_notice_user(struct userNode
*from
, struct userNode
*to
, const char *message
)
674 putsock("%s " P10_NOTICE
" %s :%s", from
->numeric
, to
->numeric
, message
);
678 irc_privmsg(struct userNode
*from
, const char *to
, const char *message
)
680 putsock("%s " P10_PRIVMSG
" %s :%s", from
->numeric
, to
, message
);
686 putsock("%s " P10_EOB
, self
->numeric
);
692 putsock("%s " P10_EOB_ACK
, self
->numeric
);
696 str
= conf_get_data("services/opserv/nick", RECDB_QSTRING
);
699 if (nick
&& (DefConLevel
< 5)) {
700 DefConProcess(GetUserH(nick
));
702 if (DefConTimeOut
> 0)
703 timeq_add(now
+ DefConTimeOut
, defcon_timeout
, NULL
);
708 irc_ping(const char *payload
)
710 putsock("%s " P10_PING
" :%s", self
->numeric
, payload
);
714 irc_pong(const char *who
, const char *data
)
716 putsock("%s " P10_PONG
" %s :%s", self
->numeric
, who
, data
);
720 irc_pong_asll(const char *who
, const char *orig_ts
)
727 orig
.tv_sec
= strtoul(orig_ts
, &delim
, 10);
728 orig
.tv_usec
= (*delim
== '.') ? strtoul(delim
+ 1, NULL
, 10) : 0;
729 gettimeofday(&now
, NULL
);
730 diff
= (now
.tv_sec
- orig
.tv_sec
) * 1000 + (now
.tv_usec
- orig
.tv_usec
) / 1000;
731 putsock("%s " P10_PONG
" %s %s %d " FMT_TIME_T
".%06u", self
->numeric
, who
, orig_ts
, diff
, now
.tv_sec
, (unsigned)now
.tv_usec
);
735 irc_pass(const char *passwd
)
737 putsock(P10_PASS
" :%s", passwd
);
741 irc_introduce(const char *passwd
)
743 void timed_send_ping(void *data
);
745 self
->self_burst
= self
->burst
= 1;
749 timeq_add(now
+ ping_freq
, timed_send_ping
, 0);
753 irc_gline(struct server
*srv
, struct gline
*gline
, int silent
)
755 putsock("%s " P10_GLINE
" %s +%s %ld :%s<%s> %s",
756 self
->numeric
, (srv
? srv
->numeric
: "*"), gline
->target
, gline
->expires
-now
, silent
? "AUTO " : "", gline
->issuer
, gline
->reason
);
760 irc_shun(struct server
*srv
, struct shun
*shun
)
762 putsock("%s " P10_SHUN
" %s +%s %ld :<%s> %s",
763 self
->numeric
, (srv
? srv
->numeric
: "*"), shun
->target
, shun
->expires
-now
, shun
->issuer
, shun
->reason
);
767 irc_settime(const char *srv_name_mask
, time_t new_time
)
769 ioset_set_time(new_time
);
770 if (!strcmp(srv_name_mask
, "*"))
772 putsock("%s " P10_SETTIME
" " FMT_TIME_T
" %s", self
->numeric
, new_time
, srv_name_mask
);
776 irc_ungline(const char *mask
)
778 putsock("%s " P10_GLINE
" * -%s", self
->numeric
, mask
);
782 irc_unshun(const char *mask
)
784 putsock("%s " P10_SHUN
" * -%s", self
->numeric
, mask
);
788 irc_burst(struct chanNode
*chan
)
790 char burst_line
[512];
791 int pos
, base_len
, len
;
794 struct exemptNode
*en
;
798 base_len
= sprintf(burst_line
, "%s " P10_BURST
" %s " FMT_TIME_T
" ",
799 self
->numeric
, chan
->name
, chan
->timestamp
);
800 len
= irc_make_chanmode(chan
, burst_line
+base_len
);
801 pos
= base_len
+ len
;
803 burst_line
[pos
++] = ' ';
805 if(chan
->members
.used
< 1)
806 return; /* dont burst empty channels (created by discrims) */
808 for (n
=0; n
<chan
->members
.used
; n
++) {
809 mn
= chan
->members
.list
[n
];
811 burst_line
[pos
-1] = 0; /* -1 to back up over the space or comma */
812 putsock("%s", burst_line
);
816 memcpy(burst_line
+pos
, mn
->user
->numeric
, strlen(mn
->user
->numeric
));
817 pos
+= strlen(mn
->user
->numeric
);
818 if (mn
->modes
&& (mn
->modes
!= last_mode
)) {
819 last_mode
= mn
->modes
;
820 burst_line
[pos
++] = ':';
821 if (last_mode
& MODE_CHANOP
)
822 burst_line
[pos
++] = 'o';
823 if (last_mode
& MODE_HALFOP
)
824 burst_line
[pos
++] = 'h';
825 if (last_mode
& MODE_VOICE
)
826 burst_line
[pos
++] = 'v';
828 if ((n
+1)<chan
->members
.used
)
829 burst_line
[pos
++] = ',';
831 if (chan
->banlist
.used
) {
833 if (pos
+2+strlen(chan
->banlist
.list
[0]->ban
) > 505) {
834 burst_line
[pos
-1] = 0;
835 putsock("%s", burst_line
);
838 burst_line
[pos
++] = ' ';
841 burst_line
[pos
++] = ':';
842 burst_line
[pos
++] = '%';
844 for (n
=0; n
<chan
->banlist
.used
; n
++) {
845 bn
= chan
->banlist
.list
[n
];
846 len
= strlen(bn
->ban
);
847 if (pos
+len
+1 > 510) {
848 burst_line
[pos
-1] = 0; /* -1 to back up over the space or comma */
849 putsock("%s", burst_line
);
852 memcpy(burst_line
+pos
, bn
->ban
, len
);
854 burst_line
[pos
++] = ' ';
857 if (chan
->exemptlist
.used
) {
858 /* dump the exempt */
859 if (pos
+2+strlen(chan
->exemptlist
.list
[0]->exempt
) > 505) {
860 burst_line
[pos
-1] = 0;
861 putsock("%s", burst_line
);
864 burst_line
[pos
++] = ' ';
867 burst_line
[pos
++] = ' ';
868 burst_line
[pos
++] = '~';
869 burst_line
[pos
++] = ' ';
871 for (n
=0; n
<chan
->exemptlist
.used
; n
++) {
872 en
= chan
->exemptlist
.list
[n
];
873 len
= strlen(en
->exempt
);
874 if (pos
+len
+1 > 510) {
875 burst_line
[pos
-1] = 0; /* -1 to back up over the space or comma */
876 putsock("%s", burst_line
);
879 memcpy(burst_line
+pos
, en
->exempt
, len
);
881 burst_line
[pos
++] = ' ';
884 /* print the last line */
886 putsock("%s", burst_line
);
890 irc_quit(struct userNode
*user
, const char *message
)
892 putsock("%s " P10_QUIT
" :%s", user
->numeric
, message
);
896 irc_error(const char *to
, const char *message
)
899 putsock("%s " P10_ERROR
" :%s", to
, message
);
901 putsock(":%s " P10_ERROR
" :%s", self
->name
, message
);
906 irc_kill(struct userNode
*from
, struct userNode
*target
, const char *message
)
909 putsock("%s " P10_KILL
" %s :%s!%s (%s)",
910 from
->numeric
, target
->numeric
, self
->name
, from
->nick
, message
);
912 putsock("%s " P10_KILL
" %s :%s (%s)",
913 self
->numeric
, target
->numeric
, self
->name
, message
);
918 irc_mode(struct userNode
*from
, struct chanNode
*target
, const char *modes
)
920 call_channel_mode_funcs(from
, target
, (char **)&modes
, 0);
921 putsock("%s " P10_MODE
" %s %s "FMT_TIME_T
,
922 (from
? from
->numeric
: self
->numeric
),
923 target
->name
, modes
, target
->timestamp
);
926 /* Added to allow services to mode users
927 2005 - 8 - 10 by Life4Christ
930 irc_umode(struct userNode
*target
, const char *modes
)
932 putsock("%s " P10_MODE
" %s %s ",self
->numeric
,target
->nick
, modes
);
937 irc_invite(struct userNode
*from
, struct userNode
*who
, struct chanNode
*to
)
939 putsock("%s " P10_INVITE
" %s %s", from
->numeric
, who
->nick
, to
->name
);
943 irc_silence(struct userNode
*who
, const char *mask
, int add
)
945 putsock("%s " P10_SILENCE
" %s %s%s", self
->numeric
, who
->numeric
, add
? "+" : "-", mask
);
949 irc_join(struct userNode
*who
, struct chanNode
*what
)
951 if (what
->members
.used
== 1) {
952 putsock("%s " P10_CREATE
" %s %lu",
953 who
->numeric
, what
->name
, what
->timestamp
);
955 putsock("%s " P10_JOIN
" %s %lu", who
->numeric
, what
->name
, what
->timestamp
);
960 irc_svsjoin(struct userNode
*from
, struct userNode
*who
, struct chanNode
*to
)
962 putsock("%s " P10_SVSJOIN
" %s %s "FMT_TIME_T
, from
->uplink
->numeric
, who
->numeric
, to
->name
, now
);
966 irc_kick(struct userNode
*who
, struct userNode
*target
, struct chanNode
*channel
, const char *msg
)
969 struct modeNode
*mn
= GetUserMode(channel
, who
);
970 numeric
= ((mn
&& (mn
->modes
& MODE_CHANOP
)) || off_channel
) ? who
->numeric
: self
->numeric
;
971 putsock("%s " P10_KICK
" %s %s :%s",
972 numeric
, channel
->name
, target
->numeric
, msg
);
976 irc_stats(struct userNode
*from
, struct server
*target
, char type
)
978 putsock("%s " P10_STATS
" %c :%s", from
->numeric
, type
, target
->numeric
);
982 irc_svsnick(struct userNode
*from
, struct userNode
*target
, const char *newnick
)
984 putsock("%s " P10_SVSNICK
" %s %s "FMT_TIME_T
, from
->uplink
->numeric
, target
->numeric
, newnick
, now
);
988 irc_swhois(struct userNode
*from
, struct userNode
*target
, const char *message
)
990 putsock("%s " P10_SWHOIS
" %s %s%s", from
->uplink
->numeric
, target
->numeric
, message
? ":" : "",
991 message
? message
: "");
996 irc_part(struct userNode
*who
, struct chanNode
*what
, const char *reason
)
999 putsock("%s " P10_PART
" %s :%s", who
->numeric
, what
->name
, reason
);
1001 putsock("%s " P10_PART
" %s", who
->numeric
, what
->name
);
1006 irc_topic(struct userNode
*service
, struct userNode
*who
, struct chanNode
*what
, const char *topic
)
1010 int host_in_topic
= 0;
1011 const char *hstr
, *tstr
;
1012 char *host
, *hostmask
;
1014 char sident
[MAXLEN
];
1016 tstr
= conf_get_data("server/type", RECDB_QSTRING
);
1017 hstr
= conf_get_data("server/host_in_topic", RECDB_QSTRING
);
1021 type
= 4;/* default to 040 style topics */
1024 if (IsFakeHost(who
))
1025 safestrncpy(shost
, who
->fakehost
, sizeof(shost
));
1026 else if (IsSetHost(who
)) {
1027 hostmask
= strdup(who
->sethost
);
1028 if ((host
= (strrchr(hostmask
, '@'))))
1033 safestrncpy(sident
, hostmask
, sizeof(shost
));
1034 safestrncpy(shost
, host
, sizeof(shost
));
1036 safestrncpy(shost
, who
->hostname
, sizeof(shost
));
1038 host_in_topic
= atoi(hstr
);
1042 putsock("%s " P10_TOPIC
" %s %s%s%s%s%s " FMT_TIME_T
" " FMT_TIME_T
" :%s", service
->numeric
, what
->name
,
1043 who
->nick
, host_in_topic
? "!" : "", host_in_topic
? (IsSetHost(who
) ? sident
: who
->ident
) : "",
1044 host_in_topic
? "@" : "", host_in_topic
? shost
: "", what
->timestamp
, now
, topic
);
1047 putsock("%s " P10_TOPIC
" %s :%s", who
->numeric
, what
->name
, topic
);
1052 irc_raw(const char *what
)
1054 putsock("%s", what
);
1058 irc_numeric(struct userNode
*user
, unsigned int num
, const char *format
, ...)
1061 char buffer
[MAXLEN
];
1062 va_start(arg_list
, format
);
1063 vsnprintf(buffer
, MAXLEN
-2, format
, arg_list
);
1064 buffer
[MAXLEN
-1] = 0;
1065 putsock(":%s %03d %s %s", self
->name
, num
, user
->nick
, buffer
);
1068 static void send_burst(void);
1071 change_nicklen(int new_nicklen
)
1074 char new_nick
[NICKLEN
+1];
1075 struct userNode
*user
;
1077 nicklen
= new_nicklen
;
1078 /* fix up any users we have here */
1079 for (nn
=0; nn
<=self
->num_mask
; nn
++) {
1080 if (!(user
= self
->users
[nn
]))
1082 safestrncpy(new_nick
, user
->nick
, sizeof(new_nick
));
1083 new_nick
[nicklen
] = 0;
1084 NickChange(user
, new_nick
, 1);
1088 static CMD_FUNC(cmd_whois
)
1090 struct userNode
*from
;
1091 struct userNode
*who
;
1095 if (!(from
= GetUserH(origin
))) {
1096 log_module(MAIN_LOG
, LOG_ERROR
, "Could not find WHOIS origin user %s", origin
);
1099 if(!(who
= GetUserH(argv
[2]))) {
1100 irc_numeric(from
, ERR_NOSUCHNICK
, "%s@%s :No such nick", argv
[2], self
->name
);
1103 if (IsHiddenHost(who
) && !IsOper(from
)) {
1104 /* Just stay quiet. */
1107 irc_numeric(from
, RPL_WHOISUSER
, "%s %s %s * :%s", who
->nick
, who
->ident
, who
->hostname
, who
->info
);
1108 if (his_servername
&& his_servercomment
)
1109 irc_numeric(from
, RPL_WHOISSERVER
, "%s %s :%s", who
->nick
, his_servername
, his_servercomment
);
1111 irc_numeric(from
, RPL_WHOISSERVER
, "%s %s :%s", who
->nick
, who
->uplink
->name
, who
->uplink
->description
);
1113 irc_numeric(from
, RPL_WHOISOPERATOR
, "%s :is a megalomaniacal power hungry tyrant", who
->nick
);
1114 irc_numeric(from
, RPL_ENDOFWHOIS
, "%s :End of /WHOIS list", who
->nick
);
1118 static CMD_FUNC(cmd_server
)
1126 /* another server introduced us */
1127 srv
= AddServer(GetServerH(origin
), argv
[1], atoi(argv
[2]), atoi(argv
[3]), atoi(argv
[4]), argv
[6], argv
[argc
-1]);
1130 srv
->self_burst
= argv
[5][0] == 'J';
1133 /* this must be our uplink */
1134 srv
= self
->uplink
= AddServer(self
, argv
[1], atoi(argv
[2]), atoi(argv
[3]), atoi(argv
[4]), argv
[6], argv
[argc
-1]);
1137 srv
->self_burst
= argv
[5][0] == 'J';
1139 if ((argv
[7][0] == '+') && !force_n2k
) {
1140 log_module(MAIN_LOG
, LOG_WARNING
, "Got Undernet-style SERVER message but \"force_n2k\" not on.");
1145 /* Fix up our timestamps if necessary. */
1146 if (srv
->boot
<= PREHISTORY
) {
1147 /* Server from the mists of time.. */
1148 if (srv
->hops
== 1) {
1149 log_module(MAIN_LOG
, LOG_ERROR
, "Server %s claims to have booted at time "FMT_TIME_T
". This is absurd.", srv
->name
, srv
->boot
);
1151 } else if ((str
= conf_get_data("server/reliable_clock", RECDB_QSTRING
))
1152 && enabled_string(str
)) {
1153 /* If we have a reliable clock, we just keep our current time. */
1155 if (srv
->boot
<= self
->boot
) {
1156 /* The other server is older than us. Accept their timestamp.
1157 * Alternately, we are same age, but we accept their time
1158 * since we are linking to them. */
1159 self
->boot
= srv
->boot
;
1160 ioset_set_time(srv
->link
);
1163 if (srv
== self
->uplink
) {
1164 extern time_t burst_begin
;
1171 static CMD_FUNC(cmd_eob
)
1173 struct server
*sender
;
1177 if (!(sender
= GetServerH(origin
)))
1179 if (sender
== self
->uplink
) {
1180 cManager
.uplink
->state
= CONNECTED
;
1181 for (it
= dict_first(unbursted_channels
); it
; it
= iter_next(it
))
1182 irc_burst(iter_data(it
));
1183 dict_delete(unbursted_channels
);
1184 unbursted_channels
= NULL
;
1188 /* now that we know who our uplink is,
1189 * we can center the routing map and activate auto-routing.
1191 activate_routing(NULL
, NULL
, NULL
);
1193 sender
->self_burst
= 0;
1194 recalc_bursts(sender
);
1195 for (ii
=0; ii
<slf_used
; ii
++)
1196 slf_list
[ii
](sender
);
1197 /* let auto-routing figure out if we were
1198 * wating on this server to link a child to it */
1199 /* DONT call this if uplink is _US_ */
1200 if(sender
->uplink
!= self
)
1201 routing_handle_connect(sender
->name
, sender
->uplink
->name
);
1205 static CMD_FUNC(cmd_eob_ack
)
1207 extern time_t burst_begin
;
1209 if (GetServerH(origin
) == self
->uplink
) {
1210 burst_length
= now
- burst_begin
;
1211 self
->self_burst
= self
->burst
= 0;
1213 cManager
.uplink
->state
= CONNECTED
;
1217 static CMD_FUNC(cmd_ping
)
1220 struct userNode
*un
;
1223 irc_pong_asll(argv
[2], argv
[3]);
1224 else if ((srv
= GetServerH(origin
)))
1225 irc_pong(self
->name
, srv
->numeric
);
1226 else if ((un
= GetUserH(origin
)))
1227 irc_pong(self
->name
, un
->numeric
);
1229 irc_pong(self
->name
, origin
);
1231 timeq_del(0, timed_send_ping
, 0, TIMEQ_IGNORE_WHEN
|TIMEQ_IGNORE_DATA
);
1232 timeq_del(0, timed_ping_timeout
, 0, TIMEQ_IGNORE_WHEN
|TIMEQ_IGNORE_DATA
);
1233 timeq_add(now
+ ping_freq
, timed_send_ping
, 0);
1238 static CMD_FUNC(cmd_error_nick
)
1240 /* Go back to original IRC length .. and try to reconnect :/ */
1242 irc_squit(self
, "Got erroneous nickname, truncating nicks.", NULL
);
1246 struct create_desc
{
1247 struct userNode
*user
;
1252 join_helper(struct chanNode
*chan
, void *data
)
1254 struct create_desc
*cd
= data
;
1255 AddChannelUser(cd
->user
, chan
);
1259 create_helper(char *name
, void *data
)
1261 struct create_desc
*cd
= data
;
1263 if (!strcmp(name
, "0")) {
1264 while (cd
->user
->channels
.used
> 0)
1265 DelChannelUser(cd
->user
, cd
->user
->channels
.list
[0]->channel
, 0, 0);
1269 AddChannelUser(cd
->user
, AddChannel(name
, cd
->when
, NULL
, NULL
, NULL
));
1272 static CMD_FUNC(cmd_create
)
1274 struct create_desc cd
;
1275 struct userNode
*user
;
1277 if ((argc
< 3) || !(user
= GetUserH(origin
)))
1280 cd
.when
= atoi(argv
[2]);
1281 parse_foreach(argv
[1], join_helper
, create_helper
, NULL
, NULL
, &cd
);
1285 static CMD_FUNC(cmd_join
)
1287 struct create_desc cd
;
1289 if (!(cd
.user
= GetUserH(origin
)))
1296 cd
.when
= atoi(argv
[2]);
1297 parse_foreach(argv
[1], join_helper
, create_helper
, NULL
, NULL
, &cd
);
1301 static CMD_FUNC(cmd_svsjoin
)
1303 struct create_desc cd
;
1305 if (!(cd
.user
= GetUserH(argv
[1])))
1312 cd
.when
= atoi(argv
[3]);
1313 parse_foreach(argv
[2], join_helper
, create_helper
, NULL
, NULL
, &cd
);
1317 static CMD_FUNC(cmd_pong
)
1321 if (!strcmp(argv
[2], self
->name
)) {
1322 timeq_del(0, timed_send_ping
, 0, TIMEQ_IGNORE_WHEN
|TIMEQ_IGNORE_DATA
);
1323 timeq_del(0, timed_ping_timeout
, 0, TIMEQ_IGNORE_WHEN
|TIMEQ_IGNORE_DATA
);
1324 timeq_add(now
+ ping_freq
, timed_send_ping
, 0);
1330 static CMD_FUNC(cmd_nick
)
1332 struct userNode
*user
;
1333 if ((user
= GetUserH(origin
))) {
1334 /* nick change (since the source is a user numeric) */
1337 NickChange(user
, argv
[1], 1);
1339 struct server
*serv
;
1340 struct userNode
*nuser
;
1345 serv
= GetServerH(origin
);
1347 unsplit_string(argv
+6, argc
-9, modes
);
1350 nuser
= AddUser(serv
, argv
[1], argv
[4], argv
[5], modes
, argv
[argc
-2], argv
[argc
-1], atoi(argv
[3]), argv
[argc
-3]);
1355 static CMD_FUNC(cmd_account
)
1357 struct userNode
*user
;
1358 struct server
*server
;
1359 struct handle_info
*hi
;
1361 if ((argc
< 3) || !origin
|| !(server
= GetServerH(origin
)))
1362 return 0; /* Origin must be server. */
1364 /* This next line appears to tremple origin.. why? */
1365 user
= GetUserN(argv
[1]);
1367 return 1; /* A QUIT probably passed the ACCOUNT. */
1369 if(!extended_accounts
) /* any need for this function without? */
1372 if(!strcmp(argv
[2],"C"))
1374 if((hi
= loc_auth(argv
[4], argv
[5])))
1377 putsock("%s " P10_ACCOUNT
" %s A %s %lu", self
->numeric
, server
->numeric
, argv
[3], hi
->registered
);
1383 putsock("%s " P10_ACCOUNT
" %s D %s", self
->numeric
, server
->numeric
, argv
[3]);
1387 else if(!strcmp(argv
[2],"R"))
1388 call_account_func(user
, argv
[3]);
1390 call_account_func(user
, argv
[2]); /* For backward compatability */
1394 static CMD_FUNC(cmd_fakehost
)
1396 struct userNode
*user
;
1398 if ((argc
< 3) || !origin
|| !GetServerH(origin
))
1400 if (!(user
= GetUserN(argv
[1])))
1402 assign_fakehost(user
, argv
[2], 0);
1410 #define P(priv) { #priv, PRIV_ ## priv }
1411 P(CHAN_LIMIT
), P(MODE_LCHAN
), P(WALK_LCHAN
), P(DEOP_LCHAN
),
1412 P(SHOW_INVIS
), P(SHOW_ALL_INVIS
), P(UNLIMIT_QUERY
), P(KILL
),
1413 P(LOCAL_KILL
), P(REHASH
), P(RESTART
), P(DIE
),
1414 P(GLINE
), P(LOCAL_GLINE
), P(JUPE
), P(LOCAL_JUPE
),
1415 P(OPMODE
), P(LOCAL_OPMODE
), P(SET
), P(WHOX
),
1416 P(BADCHAN
), P(LOCAL_BADCHAN
), P(SEE_CHAN
), P(PROPAGATE
),
1417 P(DISPLAY
), P(SEE_OPERS
), P(WIDE_GLINE
), P(FORCE_OPMODE
),
1418 P(FORCE_LOCAL_OPMODE
), P(REMOTEREHASH
), P(CHECK
), P(SEE_SECRET_CHAN
),
1419 P(SHUN
), P(LOCAL_SHUN
), P(WIDE_SHUN
),
1424 char *client_report_privs(struct userNode
*client
)
1429 for (i
= 0; privtab
[i
].name
; i
++) {
1430 if (HasPriv(client
, privtab
[i
].priv
)) {
1431 strcat(privbuf
, privtab
[i
].name
);
1432 strcat(privbuf
, " ");
1436 privbuf
[strlen(privbuf
)] = 0;
1441 int client_modify_priv_by_name(struct userNode
*who
, char *priv
, int what
) {
1446 for (i
= 0; privtab
[i
].name
; i
++) {
1447 if (0 == strcmp(privtab
[i
].name
, priv
)) {
1448 if (what
== PRIV_ADD
)
1449 GrantPriv(who
, privtab
[i
].priv
);
1450 else if (what
== PRIV_DEL
) {
1451 RevokePriv(who
, privtab
[i
].priv
);
1458 int check_priv(char *priv
)
1462 for (i
= 0; privtab
[i
].name
; i
++) {
1463 if (0 == strcmp(privtab
[i
].name
, priv
)) {
1471 irc_privs(struct userNode
*target
, char *flag
, int add
)
1473 client_modify_priv_by_name(target
, flag
, add
);
1474 putsock("%s " P10_PRIVS
" %s %s%s", self
->numeric
, target
->numeric
, (add
== PRIV_ADD
) ? "+" : "-", flag
);
1477 static CMD_FUNC(cmd_privs
)
1482 tstr
= conf_get_data("server/type", RECDB_QSTRING
);
1487 return 1; /* silently ignore */
1489 struct userNode
*user
= argc
> 1 ? GetUserN(argv
[1]) : NULL
;
1491 int what
= PRIV_ADD
;
1502 for (i
=1; i
<argc
; i
++) {
1503 strcat(buf
, argv
[i
]);
1507 for (i
= 2; i
< argc
; i
++) {
1508 if (*argv
[i
] == '+') { what
= PRIV_ADD
; argv
[i
]++; }
1509 if (*argv
[i
] == '-') { what
= PRIV_DEL
; argv
[i
]++; }
1510 for (tmp
= x3_strtok(&p
, argv
[i
], ","); tmp
;
1511 tmp
= x3_strtok(&p
, NULL
, ",")) {
1512 client_modify_priv_by_name(user
, tmp
, what
);
1518 static CMD_FUNC(cmd_burst
)
1521 char modes
[MAXLEN
], *members
= "";
1522 static char exemptlist
[MAXLEN
], banlist
[MAXLEN
];
1523 unsigned int next
= 3, res
= 1;
1524 int ctype
= 0, echeck
= 0, bcheck
= 0;
1525 struct chanNode
*cNode
;
1526 struct userNode
*un
;
1527 struct modeNode
*mNode
;
1530 char *user
, *end
, sep
;
1531 time_t in_timestamp
;
1541 while (next
< argc
) {
1542 switch (argv
[next
][0]) {
1546 for (pos
=argv
[next
], n_modes
= 1; *pos
; pos
++)
1547 if ((*pos
== 'k') || (*pos
== 'l') || (*pos
== 'A')
1550 unsplit_string(argv
+next
, n_modes
, modes
);
1555 for(parm
= mysep(&argv
[next
], " "); /* parm = first param */
1556 parm
; /* While param is not null */
1557 parm
= mysep(&argv
[next
], " ") /* parm = next param */
1575 /* strip % char off start of very first ban */
1576 if (strlen(parm
) > 1) {
1577 strncat(banlist
, strtok(parm
, "%"), sizeof(banlist
) - 1 - strlen(banlist
));
1578 strncat(banlist
, " ", sizeof(banlist
) - 1 - strlen(banlist
));
1582 strncat(banlist
, parm
, sizeof(banlist
) - 1 - strlen(banlist
));
1583 strncat(banlist
, " ", sizeof(banlist
) - 1 - strlen(banlist
));
1585 } else if (ctype
== 2) {
1589 strncat(exemptlist
, parm
, sizeof(exemptlist
) - 1 - strlen(exemptlist
));
1590 strncat(exemptlist
, " ", sizeof(exemptlist
) - 1 - strlen(exemptlist
));
1597 default: members
= argv
[next
++]; break;
1601 in_timestamp
= atoi(argv
[2]);
1602 if ((cNode
= dict_find(unbursted_channels
, argv
[1], NULL
))) {
1603 cNode
->timestamp
= in_timestamp
;
1604 dict_remove(unbursted_channels
, cNode
->name
);
1607 cNode
= AddChannel(argv
[1], in_timestamp
, modes
, banlist
, exemptlist
);
1609 /* Burst channel members in now. */
1610 for (user
= members
, sep
= *members
, mode
= 0; sep
; user
= end
) {
1611 for (end
= user
+ 3; isalnum(*end
) || *end
== '[' || *end
== ']'; end
++) ;
1612 sep
= *end
++; end
[-1] = 0;
1615 while ((sep
= *end
++)) {
1617 mode
|= MODE_CHANOP
;
1619 } else if (sep
== 'h') {
1620 mode
|= MODE_HALFOP
;
1622 } else if (sep
== 'v') {
1625 } else if (isdigit(sep
)) {
1626 mode
|= MODE_CHANOP
;
1628 oplevel
+= parse_oplevel(end
);
1630 oplevel
= parse_oplevel(end
);
1631 while (isdigit(*end
)) end
++;
1638 if (!(un
= GetUserN(user
))) {
1642 if ((mNode
= AddChannelUser(un
, cNode
))) {
1643 mNode
->modes
= mode
;
1644 mNode
->oplevel
= oplevel
;
1651 static CMD_FUNC(cmd_mode
)
1653 struct chanNode
*cn
;
1654 struct userNode
*un
;
1655 char *sethost
; // sethost - reed/apples
1656 int i
; // sethost - reed/apples
1660 if (!IsChannelName(argv
[1])) {
1661 un
= GetUserH(argv
[1]);
1663 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to find user %s whose mode is changing.", argv
[1]);
1666 // sethost - reed/apples
1668 mod_usermode(un
, argv
[2]);
1670 sethost
= malloc(strlen(argv
[2]) + 1 + strlen(argv
[3]) + 1);
1672 while((sethost
[i
++] = *argv
[2]++));
1675 while((sethost
[i
++] = *argv
[3]++));
1676 mod_usermode(un
, sethost
); // sethost - reed/apples
1682 if (!(cn
= GetChannel(argv
[1]))) {
1683 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to find channel %s whose mode is changing.", argv
[1]);
1686 if ((un
= GetUserH(origin
))) {
1687 struct modeNode
*mn
;
1688 /* Update idle time for person setting the mode */
1689 if ((mn
= GetUserMode(cn
, un
)))
1690 mn
->idle_since
= now
;
1692 /* If it came from a server, reset timestamp to re-sync. */
1693 cn
->timestamp
= atoi(argv
[argc
-1]);
1696 if (checkDefCon(DEFCON_NO_MODE_CHANGE
) && !IsOper(un
)) {
1698 str
= conf_get_data("services/opserv/nick", RECDB_QSTRING
);
1700 char modes
[MODELEN
];
1701 struct userNode
*opserv
= GetUserH(str
);
1703 send_message_type(4, un
, opserv
, "Channel modes cannot be changed due to DefCon level %d in effect, please try again soon", DefConLevel
);
1704 irc_make_chanmode(cn
, modes
);
1705 irc_mode(opserv
, cn
, modes
);
1706 irc_mode(opserv
, cn
, DefConChanModes
);
1712 return mod_chanmode(un
, cn
, argv
+2, argc
-2, MCP_ALLOW_OVB
|MCP_FROM_SERVER
|(un
? MC_NOTIFY
: 0));
1715 static CMD_FUNC(cmd_opmode
)
1717 struct chanNode
*cn
;
1718 struct userNode
*un
;
1723 if (!(cn
= GetChannel(argv
[1]))) {
1724 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to find channel %s whose mode is changing.", argv
[1]);
1727 if (!(un
= GetUserH(origin
))) {
1728 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to find user %s requesting OPMODE.", origin
);
1732 log_module(MAIN_LOG
, LOG_ERROR
, "Non-privileged user %s using OPMODE.", un
->nick
);
1736 return mod_chanmode(un
, cn
, argv
+2, argc
-2, MCP_ALLOW_OVB
|MCP_FROM_SERVER
); /* do NOT announce opmode locally */
1739 static int clear_chanmode(struct chanNode
*channel
, const char *modes
);
1741 static CMD_FUNC(cmd_clearmode
)
1743 struct chanNode
*cn
;
1744 struct userNode
*un
;
1749 if (!(cn
= GetChannel(argv
[1]))) {
1750 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to find channel %s whose mode is changing.", argv
[1]);
1753 if (!(un
= GetUserH(origin
))) {
1754 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to find user %s requesting CLEARMODE.", origin
);
1758 log_module(MAIN_LOG
, LOG_ERROR
, "Non-privileged user %s using CLEARMODE.", un
->nick
);
1762 return clear_chanmode(cn
, argv
[2]);
1765 static CMD_FUNC(cmd_topic
)
1767 struct chanNode
*cn
;
1768 time_t chan_ts
, topic_ts
;
1769 struct userNode
*user
;
1773 if (!(cn
= GetChannel(argv
[1]))) {
1774 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to find channel %s whose topic is being set", argv
[1]);
1779 if (argc
== 5) { /* Asuka / Topic Bursting IRCu's */
1780 user
= GetUserH(origin
);
1781 chan_ts
= atoi(argv
[2]);
1782 topic_ts
= atoi(argv
[3]);
1783 } else if (argc
>= 6) { /* Nefarious 0.5.0 */
1784 user
= GetUserH(strtok(argv
[2], "!"));
1785 chan_ts
= atoi(argv
[3]);
1786 topic_ts
= atoi(argv
[4]);
1787 } else { /* Regular IRCu (No Topic Bursting)*/
1788 user
= GetUserH(origin
);
1789 chan_ts
= cn
->timestamp
;
1793 SetChannelTopic(cn
, user
, user
, argv
[argc
-1], 0);
1794 cn
->topic_time
= topic_ts
;
1798 static CMD_FUNC(cmd_num_topic
)
1800 struct chanNode
*cn
;
1803 return 0; /* huh? */
1805 cn
= GetChannel(argv
[2]);
1807 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to find channel %s in topic reply", argv
[2]);
1813 switch (atoi(argv
[0])) {
1816 break; /* no topic */
1820 safestrncpy(cn
->topic
, unsplit_string(argv
+3, argc
-3, NULL
), sizeof(cn
->topic
));
1825 safestrncpy(cn
->topic_nick
, argv
[3], sizeof(cn
->topic_nick
));
1826 cn
->topic_time
= atoi(argv
[4]);
1829 return 0; /* should never happen */
1834 static CMD_FUNC(cmd_num_gline
)
1838 gline_add(origin
, argv
[3], atoi(argv
[4])-now
, argv
[5], now
, 0, 0);
1842 static CMD_FUNC(cmd_num_shun
)
1846 shun_add(origin
, argv
[3], atoi(argv
[4])-now
, argv
[5], now
, 0);
1850 static CMD_FUNC(cmd_quit
)
1852 struct userNode
*user
;
1855 /* Sometimes we get a KILL then a QUIT or the like, so we don't want to
1856 * call DelUser unless we have the user in our grasp. */
1857 if ((user
= GetUserH(origin
)))
1858 DelUser(user
, NULL
, false, argv
[1]);
1862 static CMD_FUNC(cmd_kill
)
1864 struct userNode
*user
;
1867 user
= GetUserN(argv
[1]);
1869 /* If we get a KILL for a non-existent user, it could be a
1870 * Ghost response to a KILL we sent out earlier. So we only
1871 * whine if the target is local.
1873 if (!strncmp(argv
[1], self
->numeric
, strlen(self
->numeric
)))
1874 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to find kill victim %s", argv
[1]);
1878 if (IsLocal(user
) && IsService(user
)) {
1879 /* TODO: rate limit this so silly things don't happen. */
1880 ReintroduceUser(user
);
1884 DelUser(user
, NULL
, false, argv
[2]);
1888 static CMD_FUNC(cmd_part
)
1890 struct userNode
*user
;
1894 user
= GetUserH(origin
);
1897 parse_foreach(argv
[1], part_helper
, NULL
, NULL
, NULL
, user
);
1901 static CMD_FUNC(cmd_svspart
)
1903 struct userNode
*user
;
1907 user
= GetUserH(argv
[1]);
1910 parse_foreach(argv
[2], part_helper
, NULL
, NULL
, NULL
, user
);
1914 static CMD_FUNC(cmd_silence
)
1916 struct userNode
*user
;
1924 user
= GetUserN(argv
[1]);
1926 /* Sanity, go nuts if this happens */
1930 /* We can safely ignore this if a user adding a silence is not
1931 * ignored. However this brings up a TODO. If a user logs in and
1932 * they have silences on the IRCd then we need to set them here
1935 if (!user
->handle_info
)
1941 for (i
=0; i
<user
->handle_info
->ignores
->used
; i
++) {
1942 if (!irccasecmp(mask
+1, user
->handle_info
->ignores
->list
[i
]))
1943 user
->handle_info
->ignores
->list
[i
] = user
->handle_info
->ignores
->list
[--user
->handle_info
->ignores
->used
];
1946 for (i
=0; i
<user
->handle_info
->ignores
->used
; i
++) {
1947 if (!strcmp(mask
+1, user
->handle_info
->ignores
->list
[i
]))
1948 return 1; /* Already on the users NickServ ignore list, safely ignore */
1951 new_mask
= strdup(mask
+1);
1952 string_list_append(user
->handle_info
->ignores
, new_mask
);
1957 static CMD_FUNC(cmd_kick
)
1961 ChannelUserKicked(GetUserH(origin
), GetUserN(argv
[2]), GetChannel(argv
[1]));
1965 static CMD_FUNC(cmd_squit
)
1967 struct server
*server
;
1972 if (!(server
= GetServerH(argv
[1])))
1975 if (server
== self
->uplink
) {
1976 /* Force a reconnect to the currently selected server. */
1977 cManager
.uplink
->tries
= 0;
1978 log_module(MAIN_LOG
, LOG_INFO
, "Squitting from uplink: %s", argv
[3]);
1983 uplink
= strdup(server
->uplink
->name
);
1984 DelServer(server
, 0, argv
[3]);
1985 /* if its a pingout and pingout connecting is enabled
1986 or its a read error and readerror connecting is enabled
1987 or were doing a "N" and i need to connect that server somewhere */
1988 routing_handle_squit(argv
[1], uplink
, argv
[3]);
1993 static CMD_FUNC(cmd_privmsg
)
1995 struct privmsg_desc pd
;
1998 pd
.user
= GetUserH(origin
);
1999 if (!pd
.user
|| (IsGagged(pd
.user
) && !IsOper(pd
.user
)))
2002 if (checkDefCon(DEFCON_OPER_ONLY
) && !IsOper(pd
.user
)) {
2004 str
= conf_get_data("services/opserv/nick", RECDB_QSTRING
);
2006 send_message_type(4, pd
.user
, GetUserH(str
), "Services are currently not available, please try again soon");
2010 if (checkDefCon(DEFCON_SILENT_OPER_ONLY
) && !IsOper(pd
.user
))
2011 return 1; /* Silently Ignore */
2015 parse_foreach(argv
[1], privmsg_chan_helper
, NULL
, privmsg_user_helper
, privmsg_invalid
, &pd
);
2019 static CMD_FUNC(cmd_notice
)
2021 struct privmsg_desc pd
;
2028 pd
.user
= GetUserH(origin
);
2031 if (!pd
.user
|| (IsGagged(pd
.user
) && !IsOper(pd
.user
))) {
2036 parse_foreach(argv
[1], privmsg_chan_helper
, NULL
, privmsg_user_helper
, privmsg_invalid
, &pd
);
2039 srv
= GetServerH(origin
);
2041 char *sargv
[MAXNUMPARAMS
];
2044 sargc
= split_line(argv
[2], true, MAXNUMPARAMS
, sargv
);
2046 if(!strcasecmp(sargv
[0], "Connect:")) {
2047 /* :Connect: Host shoe.loxxin.net not listed in ircd.conf */
2048 if(!strcasecmp(sargv
[3], "not") && !strcasecmp(sargv
[4], "listed")) {
2049 routing_handle_connect_failure(srv
, sargv
[2], unsplit_string(sargv
+3, sargc
-3, NULL
));
2052 else if(!strcasecmp(sargv
[0], "Link")) {
2053 /* :Link with mephisto.etheria.cx cancelled: Server mephisto.etheria.cx[216.46.33.71]
2055 * :Link with laptop.afternet.org cancelled: Connection refused
2057 if(!strcasecmp(sargv
[3], "cancelled:")) {
2058 routing_handle_connect_failure(srv
, sargv
[2], unsplit_string(sargv
+4, sargc
-4, NULL
));
2065 static CMD_FUNC(cmd_away
)
2067 struct userNode
*uNode
;
2069 uNode
= GetUserH(origin
);
2073 uNode
->modes
&= ~FLAGS_AWAY
;
2075 uNode
->modes
|= FLAGS_AWAY
;
2079 static CMD_FUNC(cmd_gline
)
2083 if (argv
[2][0] == '+') {
2086 gline_add(origin
, argv
[2]+1, strtoul(argv
[3], NULL
, 0), argv
[argc
-1], now
, 0, 0);
2088 } else if (argv
[2][0] == '-') {
2089 gline_remove(argv
[2]+1, 0);
2095 static CMD_FUNC(cmd_shun
)
2099 if (argv
[2][0] == '+') {
2102 shun_add(origin
, argv
[2]+1, strtoul(argv
[3], NULL
, 0), argv
[argc
-1], now
, 0);
2104 } else if (argv
[2][0] == '-') {
2105 shun_remove(argv
[2]+1, 0);
2111 static CMD_FUNC(cmd_svsnick
)
2113 struct userNode
*target
, *dest
;
2115 || !(target
= GetUserN(argv
[1]))
2117 || (dest
= GetUserH(argv
[2])))
2119 NickChange(target
, argv
[2], 0);
2123 static oper_func_t
*of_list
;
2124 static unsigned int of_size
= 0, of_used
= 0;
2127 free_user(struct userNode
*user
)
2138 free(privmsg_funcs
);
2141 dict_delete(irc_func_dict
);
2142 for (nn
=0; nn
<dead_users
.used
; nn
++)
2143 free_user(dead_users
.list
[nn
]);
2144 userList_clean(&dead_users
);
2148 p10_conf_reload(void) {
2149 hidden_host_suffix
= conf_get_data("server/hidden_host", RECDB_QSTRING
);
2153 remove_unbursted_channel(struct chanNode
*cNode
) {
2154 if (unbursted_channels
)
2155 dict_remove(unbursted_channels
, cNode
->name
);
2161 const char *str
, *desc
;
2162 int numnick
, usermask
, max_users
;
2163 char numer
[COMBO_NUMERIC_LEN
+1];
2165 /* read config items */
2166 str
= conf_get_data("server/extended_accounts", RECDB_QSTRING
);
2167 extended_accounts
= str
? enabled_string(str
) : 1;
2168 str
= conf_get_data("server/ping_freq", RECDB_QSTRING
);
2169 ping_freq
= str
? ParseInterval(str
) : 120;
2170 str
= conf_get_data("server/ping_timeout", RECDB_QSTRING
);
2171 ping_timeout
= str
? ParseInterval(str
) : 30;
2172 str
= conf_get_data("server/force_n2k", RECDB_QSTRING
);
2173 force_n2k
= str
? enabled_string(str
) : 1;
2174 str
= conf_get_data("server/numeric", RECDB_QSTRING
);
2176 log_module(MAIN_LOG
, LOG_ERROR
, "No server/numeric entry in config file.");
2179 numnick
= atoi(str
);
2180 str
= conf_get_data("server/max_users", RECDB_QSTRING
);
2181 max_users
= str
? atoi(str
) : 4096;
2182 for (usermask
= 4; usermask
< max_users
; usermask
<<= 1) ;
2184 if ((numnick
< 64) && (usermask
< 4096) && !force_n2k
)
2185 inttobase64(numer
, (numnick
<< 12) + (usermask
& 0x00fff), 3);
2187 inttobase64(numer
, (numnick
<< 18) + (usermask
& 0x3ffff), 5);
2189 str
= conf_get_data("server/his_servername", RECDB_QSTRING
);
2190 his_servername
= str
? strdup(str
) : NULL
;
2191 str
= conf_get_data("server/his_servercomment", RECDB_QSTRING
);
2192 his_servercomment
= str
? strdup(str
) : NULL
;
2194 str
= conf_get_data("server/hostname", RECDB_QSTRING
);
2195 desc
= conf_get_data("server/description", RECDB_QSTRING
);
2196 if (!str
|| !desc
) {
2197 log_module(MAIN_LOG
, LOG_ERROR
, "No server/hostname entry in config file.");
2200 self
= AddServer(NULL
, str
, 0, boot_time
, now
, numer
, desc
);
2201 conf_register_reload(p10_conf_reload
);
2203 irc_func_dict
= dict_new();
2204 dict_insert(irc_func_dict
, CMD_BURST
, cmd_burst
);
2205 dict_insert(irc_func_dict
, TOK_BURST
, cmd_burst
);
2206 dict_insert(irc_func_dict
, CMD_CREATE
, cmd_create
);
2207 dict_insert(irc_func_dict
, TOK_CREATE
, cmd_create
);
2208 dict_insert(irc_func_dict
, CMD_EOB
, cmd_eob
);
2209 dict_insert(irc_func_dict
, TOK_EOB
, cmd_eob
);
2210 dict_insert(irc_func_dict
, CMD_EOB_ACK
, cmd_eob_ack
);
2211 dict_insert(irc_func_dict
, TOK_EOB_ACK
, cmd_eob_ack
);
2212 dict_insert(irc_func_dict
, CMD_MODE
, cmd_mode
);
2213 dict_insert(irc_func_dict
, TOK_MODE
, cmd_mode
);
2214 dict_insert(irc_func_dict
, CMD_NICK
, cmd_nick
);
2215 dict_insert(irc_func_dict
, TOK_NICK
, cmd_nick
);
2216 dict_insert(irc_func_dict
, CMD_ACCOUNT
, cmd_account
);
2217 dict_insert(irc_func_dict
, TOK_ACCOUNT
, cmd_account
);
2218 dict_insert(irc_func_dict
, CMD_FAKEHOST
, cmd_fakehost
);
2219 dict_insert(irc_func_dict
, TOK_FAKEHOST
, cmd_fakehost
);
2220 dict_insert(irc_func_dict
, CMD_PASS
, cmd_pass
);
2221 dict_insert(irc_func_dict
, TOK_PASS
, cmd_pass
);
2222 dict_insert(irc_func_dict
, CMD_PING
, cmd_ping
);
2223 dict_insert(irc_func_dict
, TOK_PING
, cmd_ping
);
2224 dict_insert(irc_func_dict
, CMD_PRIVMSG
, cmd_privmsg
);
2225 dict_insert(irc_func_dict
, TOK_PRIVMSG
, cmd_privmsg
);
2226 dict_insert(irc_func_dict
, CMD_PONG
, cmd_pong
);
2227 dict_insert(irc_func_dict
, TOK_PONG
, cmd_pong
);
2228 dict_insert(irc_func_dict
, CMD_QUIT
, cmd_quit
);
2229 dict_insert(irc_func_dict
, TOK_QUIT
, cmd_quit
);
2230 dict_insert(irc_func_dict
, CMD_SERVER
, cmd_server
);
2231 dict_insert(irc_func_dict
, TOK_SERVER
, cmd_server
);
2232 dict_insert(irc_func_dict
, CMD_JOIN
, cmd_join
);
2233 dict_insert(irc_func_dict
, TOK_JOIN
, cmd_join
);
2234 dict_insert(irc_func_dict
, CMD_PART
, cmd_part
);
2235 dict_insert(irc_func_dict
, TOK_PART
, cmd_part
);
2236 dict_insert(irc_func_dict
, CMD_ERROR
, cmd_error
);
2237 dict_insert(irc_func_dict
, TOK_ERROR
, cmd_error
);
2238 dict_insert(irc_func_dict
, CMD_TOPIC
, cmd_topic
);
2239 dict_insert(irc_func_dict
, TOK_TOPIC
, cmd_topic
);
2240 dict_insert(irc_func_dict
, CMD_AWAY
, cmd_away
);
2241 dict_insert(irc_func_dict
, TOK_AWAY
, cmd_away
);
2242 dict_insert(irc_func_dict
, CMD_SILENCE
, cmd_silence
);
2243 dict_insert(irc_func_dict
, TOK_SILENCE
, cmd_silence
);
2244 dict_insert(irc_func_dict
, CMD_KICK
, cmd_kick
);
2245 dict_insert(irc_func_dict
, TOK_KICK
, cmd_kick
);
2246 dict_insert(irc_func_dict
, CMD_SQUIT
, cmd_squit
);
2247 dict_insert(irc_func_dict
, TOK_SQUIT
, cmd_squit
);
2248 dict_insert(irc_func_dict
, CMD_KILL
, cmd_kill
);
2249 dict_insert(irc_func_dict
, TOK_KILL
, cmd_kill
);
2250 dict_insert(irc_func_dict
, CMD_NOTICE
, cmd_notice
);
2251 dict_insert(irc_func_dict
, TOK_NOTICE
, cmd_notice
);
2252 dict_insert(irc_func_dict
, CMD_STATS
, cmd_stats
);
2253 dict_insert(irc_func_dict
, TOK_STATS
, cmd_stats
);
2254 dict_insert(irc_func_dict
, CMD_SVSJOIN
, cmd_svsjoin
);
2255 dict_insert(irc_func_dict
, TOK_SVSJOIN
, cmd_svsjoin
);
2256 dict_insert(irc_func_dict
, CMD_SVSNICK
, cmd_svsnick
);
2257 dict_insert(irc_func_dict
, TOK_SVSNICK
, cmd_svsnick
);
2258 dict_insert(irc_func_dict
, CMD_SVSPART
, cmd_svspart
);
2259 dict_insert(irc_func_dict
, TOK_SVSPART
, cmd_svspart
);
2260 dict_insert(irc_func_dict
, CMD_SWHOIS
, cmd_dummy
);
2261 dict_insert(irc_func_dict
, TOK_SWHOIS
, cmd_dummy
);
2262 dict_insert(irc_func_dict
, CMD_WHOIS
, cmd_whois
);
2263 dict_insert(irc_func_dict
, TOK_WHOIS
, cmd_whois
);
2264 dict_insert(irc_func_dict
, CMD_GLINE
, cmd_gline
);
2265 dict_insert(irc_func_dict
, TOK_GLINE
, cmd_gline
);
2266 dict_insert(irc_func_dict
, CMD_SHUN
, cmd_shun
);
2267 dict_insert(irc_func_dict
, TOK_SHUN
, cmd_shun
);
2268 dict_insert(irc_func_dict
, CMD_OPMODE
, cmd_opmode
);
2269 dict_insert(irc_func_dict
, TOK_OPMODE
, cmd_opmode
);
2270 dict_insert(irc_func_dict
, CMD_CLEARMODE
, cmd_clearmode
);
2271 dict_insert(irc_func_dict
, TOK_CLEARMODE
, cmd_clearmode
);
2272 dict_insert(irc_func_dict
, CMD_VERSION
, cmd_version
);
2273 dict_insert(irc_func_dict
, TOK_VERSION
, cmd_version
);
2274 dict_insert(irc_func_dict
, CMD_ADMIN
, cmd_admin
);
2275 dict_insert(irc_func_dict
, TOK_ADMIN
, cmd_admin
);
2277 /* In P10, DESTRUCT doesn't do anything except be broadcast to servers.
2278 * Apparently to obliterate channels from any servers that think they
2281 dict_insert(irc_func_dict
, CMD_DESTRUCT
, cmd_dummy
);
2282 dict_insert(irc_func_dict
, TOK_DESTRUCT
, cmd_dummy
);
2283 /* Ignore invites */
2284 dict_insert(irc_func_dict
, CMD_INVITE
, cmd_dummy
);
2285 dict_insert(irc_func_dict
, TOK_INVITE
, cmd_dummy
);
2286 /* DESYNCH is just informational, so ignore it */
2287 dict_insert(irc_func_dict
, CMD_DESYNCH
, cmd_dummy
);
2288 dict_insert(irc_func_dict
, TOK_DESYNCH
, cmd_dummy
);
2289 /* Ignore channel operator notices. */
2290 dict_insert(irc_func_dict
, CMD_WALLCHOPS
, cmd_dummy
);
2291 dict_insert(irc_func_dict
, TOK_WALLCHOPS
, cmd_dummy
);
2292 dict_insert(irc_func_dict
, CMD_WALLVOICES
, cmd_dummy
);
2293 dict_insert(irc_func_dict
, TOK_WALLVOICES
, cmd_dummy
);
2294 dict_insert(irc_func_dict
, CMD_WALLHOPS
, cmd_dummy
);
2295 dict_insert(irc_func_dict
, TOK_WALLHOPS
, cmd_dummy
);
2296 /* Ignore opers being silly. */
2297 dict_insert(irc_func_dict
, CMD_WALLOPS
, cmd_dummy
);
2298 dict_insert(irc_func_dict
, TOK_WALLOPS
, cmd_dummy
);
2299 dict_insert(irc_func_dict
, CMD_WALLHOPS
, cmd_dummy
);
2300 dict_insert(irc_func_dict
, TOK_WALLHOPS
, cmd_dummy
);
2301 dict_insert(irc_func_dict
, TOK_WALLUSERS
, cmd_dummy
);
2302 /* Ignore dnsbl exemptions */
2303 dict_insert(irc_func_dict
, TOK_EXEMPT
, cmd_dummy
);
2304 dict_insert(irc_func_dict
, TOK_MARK
, cmd_dummy
);
2305 dict_insert(irc_func_dict
, CMD_PRIVS
, cmd_privs
);
2306 dict_insert(irc_func_dict
, TOK_PRIVS
, cmd_privs
);
2307 /* Ignore remote luser */
2308 dict_insert(irc_func_dict
, TOK_LUSERS
, cmd_dummy
);
2309 /* We have reliable clock! Always! Wraaa! */
2310 dict_insert(irc_func_dict
, CMD_SETTIME
, cmd_dummy
);
2311 dict_insert(irc_func_dict
, TOK_SETTIME
, cmd_dummy
);
2313 /* ignore /trace and /motd commands targetted at us */
2314 dict_insert(irc_func_dict
, TOK_TRACE
, cmd_dummy
);
2315 dict_insert(irc_func_dict
, TOK_MOTD
, cmd_dummy
);
2318 dict_insert(irc_func_dict
, "331", cmd_num_topic
);
2319 dict_insert(irc_func_dict
, "332", cmd_num_topic
);
2320 dict_insert(irc_func_dict
, "333", cmd_num_topic
);
2321 dict_insert(irc_func_dict
, "345", cmd_dummy
); /* blah has been invited to blah */
2322 dict_insert(irc_func_dict
, "432", cmd_error_nick
); /* Erroneus [sic] nickname */
2323 /* ban list resetting */
2324 /* "stats g" responses */
2325 dict_insert(irc_func_dict
, "247", cmd_num_gline
);
2326 dict_insert(irc_func_dict
, "542", cmd_num_shun
);
2327 dict_insert(irc_func_dict
, "219", cmd_dummy
); /* "End of /STATS report" */
2328 /* other numeric responses we might get */
2329 dict_insert(irc_func_dict
, "401", cmd_dummy
); /* target left network */
2330 dict_insert(irc_func_dict
, "403", cmd_dummy
); /* no such channel */
2331 dict_insert(irc_func_dict
, "404", cmd_dummy
); /* cannot send to channel */
2332 dict_insert(irc_func_dict
, "439", cmd_dummy
); /* target change too fast */
2333 dict_insert(irc_func_dict
, "441", cmd_dummy
); /* target isn't on that channel */
2334 dict_insert(irc_func_dict
, "442", cmd_dummy
); /* you aren't on that channel */
2335 dict_insert(irc_func_dict
, "443", cmd_dummy
); /* is already on channel (after invite?) */
2336 dict_insert(irc_func_dict
, "461", cmd_dummy
); /* Not enough parameters (after TOPIC w/ 0 args) */
2337 dict_insert(irc_func_dict
, "467", cmd_dummy
); /* Channel key already set */
2339 num_privmsg_funcs
= 16;
2340 privmsg_funcs
= malloc(sizeof(privmsg_func_t
)*num_privmsg_funcs
);
2341 memset(privmsg_funcs
, 0, sizeof(privmsg_func_t
)*num_privmsg_funcs
);
2343 num_notice_funcs
= 16;
2344 notice_funcs
= malloc(sizeof(privmsg_func_t
)*num_notice_funcs
);
2345 memset(notice_funcs
, 0, sizeof(privmsg_func_t
)*num_notice_funcs
);
2347 userList_init(&dead_users
);
2348 reg_del_channel_func(remove_unbursted_channel
);
2349 reg_exit_func(parse_cleanup
);
2353 parse_line(char *line
, int recursive
)
2355 char *argv
[MAXNUMPARAMS
], *origin
;
2356 int argc
, cmd
, res
=0;
2359 argc
= split_line(line
, true, MAXNUMPARAMS
, argv
);
2360 cmd
= self
->uplink
|| !argv
[0][1] || !argv
[0][2];
2363 if (argv
[0][0] == ':') {
2365 } else if (!argv
[0][1] || !argv
[0][2]) {
2366 struct server
*sNode
= GetServerN(argv
[0]);
2367 origin
= sNode
? sNode
->name
: 0;
2369 struct userNode
*uNode
= GetUserN(argv
[0]);
2370 origin
= uNode
? uNode
->nick
: 0;
2374 if ((func
= dict_find(irc_func_dict
, argv
[cmd
], NULL
)))
2375 res
= func(origin
, argc
-cmd
, argv
+cmd
);
2378 log_module(MAIN_LOG
, LOG_ERROR
, "PARSE ERROR on line: %s", unsplit_string(argv
, argc
, NULL
));
2379 } else if (!recursive
) {
2381 for (i
=0; i
<dead_users
.used
; i
++)
2382 free_user(dead_users
.list
[i
]);
2383 dead_users
.used
= 0;
2389 parse_foreach(char *target_list
, foreach_chanfunc cf
, foreach_nonchan nc
, foreach_userfunc uf
, foreach_nonuser nu
, void *data
)
2395 while (*j
!= 0 && *j
!= ',')
2400 if (IsChannelName(target_list
)
2401 || (target_list
[0] == '0' && target_list
[1] == '\0')) {
2402 struct chanNode
*chan
= GetChannel(target_list
);
2409 nc(target_list
, data
);
2412 struct userNode
*user
;
2413 struct privmsg_desc
*pd
= data
;
2415 pd
->is_qualified
= 0;
2416 if (*target_list
== '@') {
2418 } else if (strchr(target_list
, '@')) {
2419 struct server
*server
;
2421 pd
->is_qualified
= 1;
2422 user
= GetUserH(strtok(target_list
, "@"));
2423 server
= GetServerH(strtok(NULL
, "@"));
2425 if (user
&& (user
->uplink
!= server
)) {
2426 /* Don't attempt to index into any arrays
2427 using a user's numeric on another server. */
2431 user
= GetUserN(target_list
);
2439 nu(target_list
, data
);
2443 } while (old
== ',');
2447 get_local_numeric(void)
2449 static unsigned int next_numeric
= 0;
2450 if (self
->clients
> self
->num_mask
)
2452 while (self
->users
[next_numeric
])
2453 if (++next_numeric
> self
->num_mask
)
2455 return next_numeric
;
2459 make_numeric(struct server
*svr
, int local_num
, char *outbuf
)
2463 if (force_n2k
|| svr
->numeric
[1]) {
2468 llen
= (local_num
< 64*64) ? 2 : 3;
2470 strncpy(outbuf
, svr
->numeric
, slen
);
2471 inttobase64(outbuf
+slen
, local_num
, llen
);
2472 outbuf
[slen
+llen
] = 0;
2476 AddServer(struct server
*uplink
, const char *name
, int hops
, time_t boot
, time_t link
, const char *numeric
, const char *description
)
2478 struct server
* sNode
;
2481 if ((sNode
= GetServerN(numeric
))) {
2482 /* This means we're trying to re-add an existant server.
2483 * To be safe, we should forget the previous incarnation.
2484 * (And all its linked servers.)
2486 * It usually only happens in replays when the original
2487 * had a ping timeout and the replay didn't (because
2488 * replaying a ping timeout invariably gets things wrong).
2490 DelServer(sNode
, 0, NULL
);
2493 switch (strlen(numeric
)) {
2494 case 5: slen
= 2; mlen
= 3; break;
2495 case 4: slen
= 1; mlen
= 3; break;
2496 case 3: slen
= 1; mlen
= 2; break;
2498 log_module(MAIN_LOG
, LOG_ERROR
, "AddServer(\"%s\", \"%s\", ...): Numeric %s has invalid length.", uplink
->name
, name
, numeric
);
2502 sNode
= calloc(1, sizeof(*sNode
));
2503 sNode
->uplink
= uplink
;
2504 safestrncpy(sNode
->name
, name
, sizeof(sNode
->name
));
2505 sNode
->num_mask
= base64toint(numeric
+slen
, mlen
);
2509 strncpy(sNode
->numeric
, numeric
, slen
);
2510 safestrncpy(sNode
->description
, description
, sizeof(sNode
->description
));
2511 sNode
->users
= calloc(sNode
->num_mask
+1, sizeof(*sNode
->users
));
2512 serverList_init(&sNode
->children
);
2513 if (sNode
->uplink
) {
2514 /* uplink may be NULL if we're just building ourself */
2515 serverList_append(&sNode
->uplink
->children
, sNode
);
2517 servers_num
[base64toint(numeric
, slen
)] = sNode
;
2518 dict_insert(servers
, sNode
->name
, sNode
);
2522 void DelServer(struct server
* serv
, int announce
, const char *message
)
2526 /* If we receive an ERROR command before the SERVER
2527 * command a NULL server can be passed */
2531 /* Hrm, what's the right way to SQUIT some other server?
2532 * (This code is only to handle killing juped servers.) */
2533 if (announce
&& (serv
->uplink
== self
) && (serv
!= self
->uplink
))
2534 irc_squit(serv
, message
, NULL
);
2536 /* must recursively remove servers linked to this one first */
2537 for (i
=serv
->children
.used
;i
>0;)
2538 if (serv
->children
.list
[--i
] != self
)
2539 DelServer(serv
->children
.list
[i
], false, NULL
);
2541 /* clean up server's user hash tables */
2542 for (i
=0;i
<=serv
->num_mask
;i
++)
2544 DelUser(serv
->users
[i
], NULL
, false, "server delinked");
2548 serverList_remove(&serv
->uplink
->children
, serv
);
2549 if (serv
== self
->uplink
)
2550 self
->uplink
= NULL
;
2551 servers_num
[base64toint(serv
->numeric
, strlen(serv
->numeric
))] = NULL
;
2552 dict_remove(servers
, serv
->name
);
2553 serverList_clean(&serv
->children
);
2559 AddService(const char *nick
, const char *modes
, const char *desc
, const char *hostname
)
2561 char numeric
[COMBO_NUMERIC_LEN
+1];
2562 int local_num
= get_local_numeric();
2563 time_t timestamp
= now
;
2564 struct userNode
*old_user
= GetUserH(nick
);
2567 if (IsLocal(old_user
))
2569 timestamp
= old_user
->timestamp
- 1;
2571 if (local_num
== -1) {
2572 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to allocate numnick for service %s", nick
);
2576 hostname
= self
->name
;
2577 make_numeric(self
, local_num
, numeric
);
2578 /* TODO: Make these modes part of the conf file */
2579 return AddUser(self
, nick
, nick
, hostname
, modes
? modes
: "+oik", numeric
, desc
, now
, "AAAAAA");
2583 AddClone(const char *nick
, const char *ident
, const char *hostname
, const char *desc
)
2585 char numeric
[COMBO_NUMERIC_LEN
+1];
2586 int local_num
= get_local_numeric();
2587 time_t timestamp
= now
;
2588 struct userNode
*old_user
= GetUserH(nick
);
2591 if (IsLocal(old_user
))
2593 timestamp
= old_user
->timestamp
- 1;
2595 if (local_num
== -1) {
2596 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to allocate numnick for clone %s", nick
);
2599 make_numeric(self
, local_num
, numeric
);
2600 return AddUser(self
, nick
, ident
, hostname
, "+i", numeric
, desc
, timestamp
, "AAAAAA");
2604 is_valid_nick(const char *nick
) {
2606 /* IRC has some of The Most Fucked-Up ideas about character sets
2608 if (!isalpha(*nick
) && !strchr("{|}~[\\]^_`", *nick
))
2610 for (ii
= 0; nick
[ii
]; ++ii
)
2611 if (!isalnum(nick
[ii
]) && !strchr("{|}~[\\]^-_`", nick
[ii
]))
2613 if (strlen(nick
) > nicklen
)
2618 static struct userNode
*
2619 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
)
2621 struct userNode
*oldUser
, *uNode
;
2622 unsigned int n
, ignore_user
;
2624 if ((strlen(numeric
) < 3) || (strlen(numeric
) > 5)) {
2625 log_module(MAIN_LOG
, LOG_WARNING
, "AddUser(%p, %s, ...): numeric %s wrong length!", uplink
, nick
, numeric
);
2630 log_module(MAIN_LOG
, LOG_WARNING
, "AddUser(%p, %s, ...): server for numeric %s doesn't exist!", uplink
, nick
, numeric
);
2634 if (uplink
!= GetServerN(numeric
)) {
2635 log_module(MAIN_LOG
, LOG_WARNING
, "AddUser(%p, %s, ...): server for numeric %s differs from nominal uplink %s.", uplink
, nick
, numeric
, uplink
->name
);
2639 if (!is_valid_nick(nick
)) {
2640 log_module(MAIN_LOG
, LOG_WARNING
, "AddUser(%p, %s, ...): invalid nickname detected.", uplink
, nick
);
2645 if ((oldUser
= GetUserH(nick
))) {
2646 if (IsLocal(oldUser
) && (IsService(oldUser
) || IsPersistent(oldUser
))) {
2647 /* The service should collide the new user off. */
2648 oldUser
->timestamp
= timestamp
- 1;
2651 if (oldUser
->timestamp
> timestamp
) {
2652 /* "Old" user is really newer; remove them */
2653 DelUser(oldUser
, 0, 1, "Overruled by older nick");
2655 /* User being added is too new; do not add them to
2656 * clients, but do add them to the server's list, since it
2657 * will send a KILL and QUIT soon. */
2662 /* create new usernode and set all values */
2663 uNode
= calloc(1, sizeof(*uNode
));
2664 uNode
->nick
= strdup(nick
);
2665 safestrncpy(uNode
->ident
, ident
, sizeof(uNode
->ident
));
2666 safestrncpy(uNode
->info
, userinfo
, sizeof(uNode
->info
));
2667 safestrncpy(uNode
->hostname
, hostname
, sizeof(uNode
->hostname
));
2668 safestrncpy(uNode
->numeric
, numeric
, sizeof(uNode
->numeric
));
2669 irc_p10_pton(&uNode
->ip
, realip
);
2671 if (irc_in_addr_is_ipv4(uNode
->ip
)) {
2672 make_virtip((char*)irc_ntoa(&uNode
->ip
), (char*)irc_ntoa(&uNode
->ip
), uNode
->cryptip
);
2673 make_virthost((char*)irc_ntoa(&uNode
->ip
), uNode
->hostname
, uNode
->crypthost
);
2674 } else if (irc_in_addr_is_ipv6(uNode
->ip
)) {
2675 make_ipv6virthost((char*)irc_ntoa(&uNode
->ip
), uNode
->hostname
, uNode
->crypthost
);
2678 if (!uNode
->crypthost
&& uNode
->cryptip
)
2679 snprintf(uNode
->crypthost
, sizeof(uNode
->crypthost
), "%s", strdup(uNode
->cryptip
));
2681 uNode
->timestamp
= timestamp
;
2682 modeList_init(&uNode
->channels
);
2683 uNode
->uplink
= uplink
;
2684 if (++uNode
->uplink
->clients
> uNode
->uplink
->max_clients
) {
2685 uNode
->uplink
->max_clients
= uNode
->uplink
->clients
;
2687 uNode
->num_local
= base64toint(numeric
+strlen(uNode
->uplink
->numeric
), 3) & uNode
->uplink
->num_mask
;
2688 uNode
->uplink
->users
[uNode
->num_local
] = uNode
;
2689 mod_usermode(uNode
, modes
);
2691 set_geoip_info(uNode
);
2696 dict_insert(clients
, uNode
->nick
, uNode
);
2697 if (dict_size(clients
) > max_clients
) {
2698 max_clients
= dict_size(clients
);
2699 max_clients_time
= now
;
2703 for (n
=0; n
<nuf_used
; n
++)
2704 if (nuf_list
[n
](uNode
))
2707 if ((uNode
->loc
== 1) && (uNode
->handle_info
))
2708 send_func_list(uNode
);
2713 /* removes user from it's server's hash table and nick hash table */
2715 DelUser(struct userNode
* user
, struct userNode
*killer
, int announce
, const char *why
)
2721 /* mark them as dead, in case anybody cares */
2724 /* remove pending adduser commands */
2725 wipe_adduser_pending(NULL
, user
);
2727 /* remove user from all channels */
2728 while (user
->channels
.used
> 0)
2729 DelChannelUser(user
, user
->channels
.list
[user
->channels
.used
-1]->channel
, false, 0);
2731 /* Call these in reverse order so ChanServ can update presence
2732 information before NickServ nukes the handle_info. */
2733 for (n
= duf_used
; n
> 0; )
2734 duf_list
[--n
](user
, killer
, why
);
2736 user
->uplink
->clients
--;
2737 user
->uplink
->users
[user
->num_local
] = NULL
;
2739 userList_remove(&curr_opers
, user
);
2740 /* remove from global dictionary, but not if after a collide */
2741 if (user
== dict_find(clients
, user
->nick
, NULL
))
2742 dict_remove(clients
, user
->nick
);
2744 if (IsInvisible(user
))
2749 irc_quit(user
, why
);
2751 irc_kill(killer
, user
, why
);
2754 modeList_clean(&user
->channels
);
2755 /* We don't free them, in case we try to privmsg them or something
2756 * (like when a stupid oper kills themself). We just put them onto
2757 * a list of clients that get freed after processing each line.
2759 if (dead_users
.size
)
2760 userList_append(&dead_users
, user
);
2765 static void call_oper_funcs(struct userNode
*user
);
2767 void mod_usermode(struct userNode
*user
, const char *mode_change
) {
2769 const char *word
= mode_change
;
2771 if (!user
|| !mode_change
)
2774 call_user_mode_funcs(user
, mode_change
);
2776 while (*word
!= ' ' && *word
) word
++;
2777 while (*word
== ' ') word
++;
2779 #define do_user_mode(FLAG) do { if (add) user->modes |= FLAG; else user->modes &= ~FLAG; } while (0)
2780 switch (*mode_change
++) {
2781 case 0: case ' ': return;
2782 case '+': add
= 1; break;
2783 case '-': add
= 0; break;
2786 if(!IsOper(user
)) { /* Dont re-oper an oper */
2787 userList_append(&curr_opers
, user
);
2788 call_oper_funcs(user
);
2791 userList_remove(&curr_opers
, user
);
2793 do_user_mode(FLAGS_OPER
);
2795 case 'O': do_user_mode(FLAGS_LOCOP
); break;
2796 case 'i': do_user_mode(FLAGS_INVISIBLE
);
2802 case 'w': do_user_mode(FLAGS_WALLOP
); break;
2803 case 's': do_user_mode(FLAGS_SERVNOTICE
); break;
2804 case 'd': do_user_mode(FLAGS_DEAF
); break;
2805 case 'k': do_user_mode(FLAGS_SERVICE
); break;
2806 case 'g': do_user_mode(FLAGS_GLOBAL
); break;
2807 // sethost - reed/apples
2808 // case 'h': do_user_mode(FLAGS_HELPER); break;
2809 // I check if there's an 'h' in the first part, and if there,
2810 // then everything after the space becomes their new host.
2811 case 'h': do_user_mode(FLAGS_SETHOST
);
2813 char sethost
[MAXLEN
];
2815 for (ii
=0; (*word
!= ' ') && (*word
!= '\0'); )
2816 sethost
[ii
++] = *word
++;
2818 while (*word
== ' ')
2820 safestrncpy(user
->sethost
, sethost
, sizeof(user
->sethost
));
2823 case 'x': do_user_mode(FLAGS_HIDDEN_HOST
); break;
2828 for (ii
=0; (*word
!= ' ') && (*word
!= '\0'); )
2829 tag
[ii
++] = *word
++;
2831 while (*word
== ' ')
2833 call_account_func(user
, tag
);
2840 for (ii
=0; (*word
!= ' ') && (*word
!= '\0'); )
2841 host
[ii
++] = *word
++;
2843 while (*word
== ' ')
2845 assign_fakehost(user
, host
, 0);
2853 struct mod_chanmode
*
2854 mod_chanmode_parse(struct chanNode
*channel
, char **modes
, unsigned int argc
, unsigned int flags
, short base_oplevel
)
2856 struct mod_chanmode
*change
;
2857 unsigned int ii
, in_arg
, ch_arg
, add
;
2861 if (!(change
= mod_chanmode_alloc(argc
- 1)))
2864 for (ii
= ch_arg
= 0, in_arg
= add
= 1;
2865 (modes
[0][ii
] != '\0') && (modes
[0][ii
] != ' ');
2867 switch (modes
[0][ii
]) {
2874 #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)
2875 case 'C': do_chan_mode(MODE_NOCTCPS
); break;
2876 case 'D': do_chan_mode(MODE_DELAYJOINS
); break;
2877 case 'c': do_chan_mode(MODE_NOCOLORS
); break;
2878 case 'i': do_chan_mode(MODE_INVITEONLY
); break;
2879 case 'm': do_chan_mode(MODE_MODERATED
); break;
2880 case 'n': do_chan_mode(MODE_NOPRIVMSGS
); break;
2881 case 'p': do_chan_mode(MODE_PRIVATE
); break;
2882 case 'r': do_chan_mode(MODE_REGONLY
); break;
2883 case 's': do_chan_mode(MODE_SECRET
); break;
2884 case 't': do_chan_mode(MODE_TOPICLIMIT
); break;
2885 case 'S': do_chan_mode(MODE_STRIPCOLOR
); break;
2886 case 'M': do_chan_mode(MODE_MODUNREG
); break;
2887 case 'N': do_chan_mode(MODE_NONOTICE
); break;
2888 case 'Q': do_chan_mode(MODE_NOQUITMSGS
); break;
2889 case 'T': do_chan_mode(MODE_NOAMSG
); break;
2890 case 'O': do_chan_mode(MODE_OPERSONLY
); break;
2891 case 'Z': do_chan_mode(MODE_SSLONLY
); break;
2892 case 'L': do_chan_mode(MODE_HIDEMODE
); break;
2894 if (!(flags
& MCP_REGISTERED
)) {
2895 do_chan_mode(MODE_REGISTERED
);
2897 mod_chanmode_free(change
);
2906 change
->modes_set
|= MODE_LIMIT
;
2907 change
->new_limit
= atoi(modes
[in_arg
++]);
2909 change
->modes_set
&= ~MODE_LIMIT
;
2910 change
->modes_clear
|= MODE_LIMIT
;
2917 change
->modes_set
|= MODE_KEY
;
2918 safestrncpy(change
->new_key
, modes
[in_arg
++], sizeof(change
->new_key
));
2920 change
->modes_clear
|= MODE_KEY
;
2921 if (!(flags
& MCP_KEY_FREE
)) {
2933 change
->modes_set
|= MODE_UPASS
;
2934 safestrncpy(change
->new_upass
, modes
[in_arg
++], sizeof(change
->new_upass
));
2936 change
->modes_clear
|= MODE_UPASS
;
2937 if (!(flags
& MCP_UPASS_FREE
)) {
2948 change
->modes_set
|= MODE_APASS
;
2949 safestrncpy(change
->new_apass
, modes
[in_arg
++], sizeof(change
->new_apass
));
2951 change
->modes_clear
|= MODE_APASS
;
2952 if (!(flags
& MCP_APASS_FREE
)) {
2960 if (!(flags
& MCP_ALLOW_OVB
))
2964 change
->args
[ch_arg
].mode
= MODE_BAN
;
2966 change
->args
[ch_arg
].mode
|= MODE_REMOVE
;
2967 change
->args
[ch_arg
++].u
.hostmask
= modes
[in_arg
++];
2970 if (!(flags
& MCP_ALLOW_OVB
))
2974 change
->args
[ch_arg
].mode
= MODE_EXEMPT
;
2976 change
->args
[ch_arg
].mode
|= MODE_REMOVE
;
2977 change
->args
[ch_arg
++].u
.hostmask
= modes
[in_arg
++];
2979 case 'o': case 'h': case 'v':
2981 struct userNode
*victim
;
2987 oplevel_str
= strchr(modes
[in_arg
], ':');
2990 /* XXYYY M #channel +o XXYYY:<oplevel> */
2991 *oplevel_str
++ = '\0';
2992 oplevel
= parse_oplevel(oplevel_str
);
2993 if (oplevel
<= base_oplevel
&& !(flags
& MCP_FROM_SERVER
))
2994 oplevel
= base_oplevel
+ 1;
2996 else if (channel
->modes
& MODE_UPASS
)
2997 oplevel
= base_oplevel
+ 1;
3001 /* Check that oplevel is within bounds. */
3002 if (oplevel
> MAXOPLEVEL
)
3003 oplevel
= MAXOPLEVEL
;
3005 if (!(flags
& MCP_ALLOW_OVB
))
3010 if (modes
[0][ii
] == 'o')
3011 change
->args
[ch_arg
].mode
= MODE_CHANOP
;
3012 else if (modes
[0][ii
] == 'h')
3013 change
->args
[ch_arg
].mode
= MODE_HALFOP
;
3014 else if (modes
[0][ii
] == 'v')
3015 change
->args
[ch_arg
].mode
= MODE_VOICE
;
3018 change
->args
[ch_arg
].mode
|= MODE_REMOVE
;
3019 if (flags
& MCP_FROM_SERVER
)
3020 victim
= GetUserN(modes
[in_arg
++]);
3022 victim
= GetUserH(modes
[in_arg
++]);
3025 if ((change
->args
[ch_arg
].u
.member
= GetUserMode(channel
, victim
)))
3027 /* Apply the oplevel change */
3028 change
->args
[ch_arg
].u
.member
->oplevel
= oplevel
;
3034 if (!(flags
& MCP_FROM_SERVER
))
3039 change
->argc
= ch_arg
; /* in case any turned out to be ignored */
3040 if (change
->modes_set
& MODE_SECRET
) {
3041 change
->modes_set
&= ~(MODE_PRIVATE
);
3042 change
->modes_clear
|= MODE_PRIVATE
;
3043 } else if (change
->modes_set
& MODE_PRIVATE
) {
3044 change
->modes_set
&= ~(MODE_SECRET
);
3045 change
->modes_clear
|= MODE_SECRET
;
3049 mod_chanmode_free(change
);
3053 struct chanmode_buffer
{
3056 struct chanNode
*channel
;
3057 struct userNode
*actor
;
3058 unsigned int modes_used
;
3059 unsigned int args_used
;
3061 unsigned int is_add
: 1;
3062 unsigned int is_chanop
: 1;
3066 mod_chanmode_append(struct chanmode_buffer
*buf
, char ch
, const char *arg
)
3068 size_t arg_len
= strlen(arg
);
3069 if (buf
->modes_used
> (MAXMODEPARAMS
) ||
3070 buf
->modes_used
+ buf
->args_used
+ buf
->chname_len
+ arg_len
> 450) {
3071 memcpy(buf
->modes
+ buf
->modes_used
, buf
->args
, buf
->args_used
);
3072 buf
->modes
[buf
->modes_used
+ buf
->args_used
] = '\0';
3073 irc_mode((buf
->is_chanop
? buf
->actor
: NULL
), buf
->channel
, buf
->modes
);
3074 buf
->modes
[0] = buf
->is_add
? '+' : '-';
3075 buf
->modes_used
= 1;
3078 buf
->modes
[buf
->modes_used
++] = ch
;
3079 buf
->args
[buf
->args_used
++] = ' ';
3080 memcpy(buf
->args
+ buf
->args_used
, arg
, arg_len
);
3081 buf
->args_used
+= arg_len
;
3085 mod_chanmode_announce(struct userNode
*who
, struct chanNode
*channel
, struct mod_chanmode
*change
)
3087 struct chanmode_buffer chbuf
;
3089 struct modeNode
*mn
;
3090 char int_buff
[32], mode
= '\0';
3092 assert(change
->argc
<= change
->alloc_argc
);
3093 memset(&chbuf
, 0, sizeof(chbuf
));
3094 chbuf
.channel
= channel
;
3096 chbuf
.chname_len
= strlen(channel
->name
);
3098 mn
= GetUserMode(channel
, who
);
3099 if ((mn
&& (mn
->modes
& MODE_CHANOP
)) || off_channel
)
3100 chbuf
.is_chanop
= 1;
3102 /* First remove modes */
3104 if (change
->modes_clear
) {
3106 chbuf
.modes
[chbuf
.modes_used
++] = mode
= '-';
3107 #define DO_MODE_CHAR(BIT, CHAR) if (change->modes_clear & MODE_##BIT) chbuf.modes[chbuf.modes_used++] = CHAR
3108 DO_MODE_CHAR(PRIVATE
, 'p');
3109 DO_MODE_CHAR(SECRET
, 's');
3110 DO_MODE_CHAR(MODERATED
, 'm');
3111 DO_MODE_CHAR(TOPICLIMIT
, 't');
3112 DO_MODE_CHAR(INVITEONLY
, 'i');
3113 DO_MODE_CHAR(NOPRIVMSGS
, 'n');
3114 DO_MODE_CHAR(LIMIT
, 'l');
3115 DO_MODE_CHAR(DELAYJOINS
, 'D');
3116 DO_MODE_CHAR(REGONLY
, 'r');
3117 DO_MODE_CHAR(NOCOLORS
, 'c');
3118 DO_MODE_CHAR(NOCTCPS
, 'C');
3119 DO_MODE_CHAR(STRIPCOLOR
, 'S');
3120 DO_MODE_CHAR(MODUNREG
, 'M');
3121 DO_MODE_CHAR(NONOTICE
, 'N');
3122 DO_MODE_CHAR(NOQUITMSGS
, 'Q');
3123 DO_MODE_CHAR(NOAMSG
, 'T');
3124 DO_MODE_CHAR(OPERSONLY
, 'O');
3125 DO_MODE_CHAR(REGISTERED
, 'z');
3126 DO_MODE_CHAR(SSLONLY
, 'Z');
3127 DO_MODE_CHAR(HIDEMODE
, 'L');
3129 if (change
->modes_clear
& channel
->modes
& MODE_KEY
)
3130 mod_chanmode_append(&chbuf
, 'k', channel
->key
);
3131 if (change
->modes_clear
& channel
->modes
& MODE_UPASS
)
3132 mod_chanmode_append(&chbuf
, 'U', channel
->upass
);
3133 if (change
->modes_clear
* channel
->modes
& MODE_APASS
)
3134 mod_chanmode_append(&chbuf
, 'A', channel
->apass
);
3136 for (arg
= 0; arg
< change
->argc
; ++arg
) {
3137 if (!(change
->args
[arg
].mode
& MODE_REMOVE
))
3140 chbuf
.modes
[chbuf
.modes_used
++] = mode
= '-';
3141 switch (change
->args
[arg
].mode
& ~MODE_REMOVE
) {
3143 mod_chanmode_append(&chbuf
, 'b', change
->args
[arg
].u
.hostmask
);
3146 mod_chanmode_append(&chbuf
, 'e', change
->args
[arg
].u
.hostmask
);
3149 if (change
->args
[arg
].mode
& MODE_CHANOP
)
3150 mod_chanmode_append(&chbuf
, 'o', change
->args
[arg
].u
.member
->user
->numeric
);
3151 if (change
->args
[arg
].mode
& MODE_HALFOP
)
3152 mod_chanmode_append(&chbuf
, 'h', change
->args
[arg
].u
.member
->user
->numeric
);
3153 if (change
->args
[arg
].mode
& MODE_VOICE
)
3154 mod_chanmode_append(&chbuf
, 'v', change
->args
[arg
].u
.member
->user
->numeric
);
3161 if (change
->modes_set
) {
3163 chbuf
.modes
[chbuf
.modes_used
++] = mode
= '+';
3164 #define DO_MODE_CHAR(BIT, CHAR) if (change->modes_set & MODE_##BIT) chbuf.modes[chbuf.modes_used++] = CHAR
3165 DO_MODE_CHAR(PRIVATE
, 'p');
3166 DO_MODE_CHAR(SECRET
, 's');
3167 DO_MODE_CHAR(MODERATED
, 'm');
3168 DO_MODE_CHAR(TOPICLIMIT
, 't');
3169 DO_MODE_CHAR(INVITEONLY
, 'i');
3170 DO_MODE_CHAR(NOPRIVMSGS
, 'n');
3171 DO_MODE_CHAR(DELAYJOINS
, 'D');
3172 DO_MODE_CHAR(REGONLY
, 'r');
3173 DO_MODE_CHAR(NOCOLORS
, 'c');
3174 DO_MODE_CHAR(NOCTCPS
, 'C');
3175 DO_MODE_CHAR(STRIPCOLOR
, 'S');
3176 DO_MODE_CHAR(MODUNREG
, 'M');
3177 DO_MODE_CHAR(NONOTICE
, 'N');
3178 DO_MODE_CHAR(NOQUITMSGS
, 'Q');
3179 DO_MODE_CHAR(NOAMSG
, 'T');
3180 DO_MODE_CHAR(OPERSONLY
, 'O');
3181 DO_MODE_CHAR(REGISTERED
, 'z');
3182 DO_MODE_CHAR(SSLONLY
, 'Z');
3183 DO_MODE_CHAR(HIDEMODE
, 'L');
3185 if(change
->modes_set
& MODE_KEY
)
3186 mod_chanmode_append(&chbuf
, 'k', change
->new_key
);
3187 if (change
->modes_set
& MODE_UPASS
)
3188 mod_chanmode_append(&chbuf
, 'U', change
->new_upass
);
3189 if (change
->modes_set
& MODE_APASS
)
3190 mod_chanmode_append(&chbuf
, 'A', change
->new_apass
);
3191 if(change
->modes_set
& MODE_LIMIT
) {
3192 sprintf(int_buff
, "%d", change
->new_limit
);
3193 mod_chanmode_append(&chbuf
, 'l', int_buff
);
3196 for (arg
= 0; arg
< change
->argc
; ++arg
) {
3197 if (change
->args
[arg
].mode
& MODE_REMOVE
)
3200 chbuf
.modes
[chbuf
.modes_used
++] = mode
= '+';
3201 switch (change
->args
[arg
].mode
) {
3203 mod_chanmode_append(&chbuf
, 'b', change
->args
[arg
].u
.hostmask
);
3206 mod_chanmode_append(&chbuf
, 'e', change
->args
[arg
].u
.hostmask
);
3209 if (change
->args
[arg
].mode
& MODE_CHANOP
)
3210 mod_chanmode_append(&chbuf
, 'o', change
->args
[arg
].u
.member
->user
->numeric
);
3211 if (change
->args
[arg
].mode
& MODE_HALFOP
)
3212 mod_chanmode_append(&chbuf
, 'h', change
->args
[arg
].u
.member
->user
->numeric
);
3213 if (change
->args
[arg
].mode
& MODE_VOICE
)
3214 mod_chanmode_append(&chbuf
, 'v', change
->args
[arg
].u
.member
->user
->numeric
);
3219 /* Flush the buffer and apply changes locally */
3220 if (chbuf
.modes_used
> 0) {
3221 memcpy(chbuf
.modes
+ chbuf
.modes_used
, chbuf
.args
, chbuf
.args_used
);
3222 chbuf
.modes
[chbuf
.modes_used
+ chbuf
.args_used
] = '\0';
3223 irc_mode((chbuf
.is_chanop
? chbuf
.actor
: NULL
), chbuf
.channel
, chbuf
.modes
);
3225 mod_chanmode_apply(who
, channel
, change
);
3229 mod_chanmode_format(struct mod_chanmode
*change
, char *outbuff
)
3231 unsigned int used
= 0;
3232 assert(change
->argc
<= change
->alloc_argc
);
3233 if (change
->modes_clear
) {
3234 outbuff
[used
++] = '-';
3235 #define DO_MODE_CHAR(BIT, CHAR) if (change->modes_clear & MODE_##BIT) outbuff[used++] = CHAR
3236 DO_MODE_CHAR(PRIVATE
, 'p');
3237 DO_MODE_CHAR(SECRET
, 's');
3238 DO_MODE_CHAR(MODERATED
, 'm');
3239 DO_MODE_CHAR(TOPICLIMIT
, 't');
3240 DO_MODE_CHAR(INVITEONLY
, 'i');
3241 DO_MODE_CHAR(NOPRIVMSGS
, 'n');
3242 DO_MODE_CHAR(LIMIT
, 'l');
3243 DO_MODE_CHAR(KEY
, 'k');
3244 DO_MODE_CHAR(UPASS
, 'U');
3245 DO_MODE_CHAR(APASS
, 'A');
3246 DO_MODE_CHAR(DELAYJOINS
, 'D');
3247 DO_MODE_CHAR(REGONLY
, 'r');
3248 DO_MODE_CHAR(NOCOLORS
, 'c');
3249 DO_MODE_CHAR(NOCTCPS
, 'C');
3250 DO_MODE_CHAR(STRIPCOLOR
, 'S');
3251 DO_MODE_CHAR(MODUNREG
, 'M');
3252 DO_MODE_CHAR(NONOTICE
, 'N');
3253 DO_MODE_CHAR(NOQUITMSGS
, 'Q');
3254 DO_MODE_CHAR(NOAMSG
, 'T');
3255 DO_MODE_CHAR(OPERSONLY
, 'O');
3256 DO_MODE_CHAR(REGISTERED
, 'z');
3257 DO_MODE_CHAR(SSLONLY
, 'Z');
3258 DO_MODE_CHAR(HIDEMODE
, 'L');
3261 if (change
->modes_set
) {
3262 outbuff
[used
++] = '+';
3263 #define DO_MODE_CHAR(BIT, CHAR) if (change->modes_set & MODE_##BIT) outbuff[used++] = CHAR
3264 DO_MODE_CHAR(PRIVATE
, 'p');
3265 DO_MODE_CHAR(SECRET
, 's');
3266 DO_MODE_CHAR(MODERATED
, 'm');
3267 DO_MODE_CHAR(TOPICLIMIT
, 't');
3268 DO_MODE_CHAR(INVITEONLY
, 'i');
3269 DO_MODE_CHAR(NOPRIVMSGS
, 'n');
3270 DO_MODE_CHAR(DELAYJOINS
, 'D');
3271 DO_MODE_CHAR(REGONLY
, 'r');
3272 DO_MODE_CHAR(NOCOLORS
, 'c');
3273 DO_MODE_CHAR(NOCTCPS
, 'C');
3274 DO_MODE_CHAR(STRIPCOLOR
, 'S');
3275 DO_MODE_CHAR(MODUNREG
, 'M');
3276 DO_MODE_CHAR(NONOTICE
, 'N');
3277 DO_MODE_CHAR(NOQUITMSGS
, 'Q');
3278 DO_MODE_CHAR(NOAMSG
, 'T');
3279 DO_MODE_CHAR(OPERSONLY
, 'O');
3280 DO_MODE_CHAR(REGISTERED
, 'z');
3281 DO_MODE_CHAR(SSLONLY
, 'Z');
3282 DO_MODE_CHAR(HIDEMODE
, 'L');
3284 switch (change
->modes_set
& (MODE_KEY
|MODE_LIMIT
|MODE_APASS
|MODE_UPASS
)) {
3285 /* Doing this implementation has been a pain in the arse, I hope I didn't forget a possible combination */
3286 case MODE_KEY
|MODE_LIMIT
|MODE_APASS
|MODE_UPASS
:
3287 used
+= sprintf(outbuff
+used
, "lkAU %d %s %s %s", change
->new_limit
, change
->new_key
,change
->new_apass
, change
->new_upass
);
3290 case MODE_KEY
|MODE_LIMIT
|MODE_APASS
:
3291 used
+= sprintf(outbuff
+used
, "lkA %d %s %s", change
->new_limit
, change
->new_key
, change
->new_apass
);
3293 case MODE_KEY
|MODE_LIMIT
|MODE_UPASS
:
3294 used
+= sprintf(outbuff
+used
, "lkU %d %s %s", change
->new_limit
, change
->new_key
, change
->new_upass
);
3296 case MODE_KEY
|MODE_APASS
|MODE_UPASS
:
3297 used
+= sprintf(outbuff
+used
, "kAU %s %s %s", change
->new_key
, change
->new_apass
, change
->new_upass
);
3300 case MODE_KEY
|MODE_APASS
:
3301 used
+= sprintf(outbuff
+used
, "kA %s %s", change
->new_key
, change
->new_apass
);
3303 case MODE_KEY
|MODE_UPASS
:
3304 used
+= sprintf(outbuff
+used
, "kU %s %s", change
->new_key
, change
->new_upass
);
3306 case MODE_KEY
|MODE_LIMIT
:
3307 used
+= sprintf(outbuff
+used
, "lk %d %s", change
->new_limit
, change
->new_key
);
3310 case MODE_LIMIT
|MODE_UPASS
:
3311 used
+= sprintf(outbuff
+used
, "lU %d %s", change
->new_limit
, change
->new_upass
);
3313 case MODE_LIMIT
|MODE_APASS
:
3314 used
+= sprintf(outbuff
+used
, "lA %d %s", change
->new_limit
, change
->new_apass
);
3316 case MODE_APASS
|MODE_UPASS
:
3317 used
+= sprintf(outbuff
+used
, "AU %s %s", change
->new_apass
, change
->new_upass
);
3319 case MODE_LIMIT
|MODE_APASS
|MODE_UPASS
:
3320 used
+= sprintf(outbuff
+used
, "lAU %d %s %s", change
->new_limit
, change
->new_apass
, change
->new_upass
);
3324 used
+= sprintf(outbuff
+used
, "A %s", change
->new_apass
);
3327 used
+= sprintf(outbuff
+used
, "U %s", change
->new_upass
);
3330 used
+= sprintf(outbuff
+used
, "k %s", change
->new_key
);
3333 used
+= sprintf(outbuff
+used
, "l %d", change
->new_limit
);
3342 clear_chanmode(struct chanNode
*channel
, const char *modes
)
3344 unsigned int remove
;
3346 for (remove
= 0; *modes
; modes
++) {
3348 case 'o': remove
|= MODE_CHANOP
; break;
3349 case 'h': remove
|= MODE_HALFOP
; break;
3350 case 'v': remove
|= MODE_VOICE
; break;
3351 case 'p': remove
|= MODE_PRIVATE
; break;
3352 case 's': remove
|= MODE_SECRET
; break;
3353 case 'm': remove
|= MODE_MODERATED
; break;
3354 case 't': remove
|= MODE_TOPICLIMIT
; break;
3355 case 'i': remove
|= MODE_INVITEONLY
; break;
3356 case 'n': remove
|= MODE_NOPRIVMSGS
; break;
3359 channel
->key
[0] = '\0';
3362 remove
|= MODE_APASS
;
3363 channel
->apass
[0] = '\0';
3366 remove
|= MODE_UPASS
;
3367 channel
->upass
[0] = '\0';
3370 remove
|= MODE_LIMIT
;
3373 case 'b': remove
|= MODE_BAN
; break;
3374 case 'e': remove
|= MODE_EXEMPT
; break;
3375 case 'D': remove
|= MODE_DELAYJOINS
; break;
3376 case 'r': remove
|= MODE_REGONLY
; break;
3377 case 'c': remove
|= MODE_NOCOLORS
; break;
3378 case 'C': remove
|= MODE_NOCTCPS
; break;
3379 case 'S': remove
|= MODE_STRIPCOLOR
; break;
3380 case 'M': remove
|= MODE_MODUNREG
; break;
3381 case 'N': remove
|= MODE_NONOTICE
; break;
3382 case 'Q': remove
|= MODE_NOQUITMSGS
; break;
3383 case 'T': remove
|= MODE_NOAMSG
; break;
3384 case 'O': remove
|= MODE_OPERSONLY
; break;
3385 case 'z': remove
|= MODE_REGISTERED
; break;
3386 case 'Z': remove
|= MODE_SSLONLY
; break;
3387 case 'L': remove
|= MODE_HIDEMODE
; break;
3394 /* Remove simple modes. */
3395 channel
->modes
&= ~remove
;
3397 /* If removing bans, kill 'em all. */
3398 if ((remove
& MODE_BAN
) && channel
->banlist
.used
) {
3400 for (i
=0; i
<channel
->banlist
.used
; i
++)
3401 free(channel
->banlist
.list
[i
]);
3402 channel
->banlist
.used
= 0;
3405 /* If removing exempts, kill 'em all. */
3406 if ((remove
& MODE_EXEMPT
) && channel
->exemptlist
.used
) {
3408 for (i
=0; i
<channel
->exemptlist
.used
; i
++)
3409 free(channel
->exemptlist
.list
[i
]);
3410 channel
->exemptlist
.used
= 0;
3413 /* Remove member modes. */
3414 if ((remove
& (MODE_CHANOP
| MODE_HALFOP
| MODE_VOICE
)) && channel
->members
.used
) {
3415 int mask
= ~(remove
& (MODE_CHANOP
| MODE_HALFOP
| MODE_VOICE
));
3418 for (i
= 0; i
< channel
->members
.used
; i
++)
3419 channel
->members
.list
[i
]->modes
&= mask
;
3426 reg_privmsg_func(struct userNode
*user
, privmsg_func_t handler
)
3428 unsigned int numeric
= user
->num_local
;
3429 if (numeric
>= num_privmsg_funcs
) {
3430 int newnum
= numeric
+ 8;
3431 privmsg_funcs
= realloc(privmsg_funcs
, newnum
*sizeof(privmsg_func_t
));
3432 memset(privmsg_funcs
+num_privmsg_funcs
, 0, (newnum
-num_privmsg_funcs
)*sizeof(privmsg_func_t
));
3433 num_privmsg_funcs
= newnum
;
3435 if (privmsg_funcs
[numeric
])
3436 log_module(MAIN_LOG
, LOG_WARNING
, "re-registering new privmsg handler for numeric %d", numeric
);
3437 privmsg_funcs
[numeric
] = handler
;
3441 unreg_privmsg_func(struct userNode
*user
, privmsg_func_t handler
)
3445 if (!user
|| handler
)
3446 return; /* this really only works with users */
3448 memset(privmsg_funcs
+user
->num_local
, 0, sizeof(privmsg_func_t
));
3450 for (x
= user
->num_local
+1; x
< num_privmsg_funcs
; x
++)
3451 memmove(privmsg_funcs
+x
-1, privmsg_funcs
+x
, sizeof(privmsg_func_t
));
3453 privmsg_funcs
= realloc(privmsg_funcs
, num_privmsg_funcs
*sizeof(privmsg_func_t
));
3454 num_privmsg_funcs
--;
3459 reg_notice_func(struct userNode
*user
, privmsg_func_t handler
)
3461 unsigned int numeric
= user
->num_local
;
3462 if (numeric
>= num_notice_funcs
) {
3463 int newnum
= numeric
+ 8;
3464 notice_funcs
= realloc(notice_funcs
, newnum
*sizeof(privmsg_func_t
));
3465 memset(notice_funcs
+num_notice_funcs
, 0, (newnum
-num_notice_funcs
)*sizeof(privmsg_func_t
));
3466 num_notice_funcs
= newnum
;
3468 if (notice_funcs
[numeric
])
3469 log_module(MAIN_LOG
, LOG_WARNING
, "re-registering new notice handler for numeric %d", numeric
);
3470 notice_funcs
[numeric
] = handler
;
3474 unreg_notice_func(struct userNode
*user
, privmsg_func_t handler
)
3478 if (!user
|| handler
)
3479 return; /* this really only works with users */
3481 memset(notice_funcs
+user
->num_local
, 0, sizeof(privmsg_func_t
));
3483 for (x
= user
->num_local
+1; x
< num_notice_funcs
; x
++)
3484 memmove(notice_funcs
+x
-1, notice_funcs
+x
, sizeof(privmsg_func_t
));
3486 memset(notice_funcs
+user
->num_local
, 0, sizeof(privmsg_func_t
));
3487 notice_funcs
= realloc(notice_funcs
, num_notice_funcs
*sizeof(privmsg_func_t
));
3492 reg_oper_func(oper_func_t handler
)
3494 if (of_used
== of_size
) {
3497 of_list
= realloc(of_list
, of_size
*sizeof(oper_func_t
));
3500 of_list
= malloc(of_size
*sizeof(oper_func_t
));
3503 of_list
[of_used
++] = handler
;
3507 call_oper_funcs(struct userNode
*user
)
3512 for (n
=0; n
<of_used
; n
++)
3519 unsigned int i
, hop
, max_hop
=1;
3522 /* burst (juped) servers, closest first (except self, which is sent already) */
3523 for (i
=0; i
<ArrayLength(servers_num
); i
++)
3524 if (servers_num
[i
] && servers_num
[i
]->hops
> max_hop
)
3525 max_hop
= servers_num
[i
]->hops
;
3526 for (hop
=1; hop
<=max_hop
; hop
++) {
3527 for (i
=0;i
<ArrayLength(servers_num
);i
++) {
3529 && (servers_num
[i
]->hops
== hop
)
3530 && (servers_num
[i
] != self
->uplink
))
3531 irc_server(servers_num
[i
]);
3535 /* burst local nicks */
3536 for (i
=0; i
<=self
->num_mask
; i
++)
3538 irc_user(self
->users
[i
]);
3540 /* build dict of unbursted channel names (just copy existing channels) */
3541 unbursted_channels
= dict_new();
3542 for (it
= dict_first(channels
); it
; it
= iter_next(it
))
3543 dict_insert(unbursted_channels
, iter_key(it
), iter_data(it
));
3550 parse_oplevel(char *str
)
3553 while (isdigit(*str
))
3554 oplevel
= oplevel
* 10 + *str
++ - '0';