]>
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 * srvx 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.
22 #include "proto-common.c"
25 #define CMD_ACCOUNT "ACCOUNT"
26 #define CMD_ADMIN "ADMIN"
27 #define CMD_ASLL "ASLL"
28 #define CMD_AWAY "AWAY"
29 #define CMD_BURST "BURST"
30 #define CMD_CLEARMODE "CLEARMODE"
31 #define CMD_CLOSE "CLOSE"
32 #define CMD_CNOTICE "CNOTICE"
33 #define CMD_CONNECT "CONNECT"
34 #define CMD_CPRIVMSG "CPRIVMSG"
35 #define CMD_CREATE "CREATE"
36 #define CMD_DESTRUCT "DESTRUCT"
37 #define CMD_DESYNCH "DESYNCH"
40 #define CMD_EOB "END_OF_BURST"
41 #define CMD_EOB_ACK "EOB_ACK"
42 #define CMD_ERROR "ERROR"
43 #define CMD_FAKEHOST "FAKE"
45 #define CMD_GLINE "GLINE"
46 #define CMD_HASH "HASH"
47 #define CMD_HELP "HELP"
48 #define CMD_INFO "INFO"
49 #define CMD_INVITE "INVITE"
50 #define CMD_ISON "ISON"
51 #define CMD_JOIN "JOIN"
52 #define CMD_JUPE "JUPE"
53 #define CMD_KICK "KICK"
54 #define CMD_KILL "KILL"
55 #define CMD_LINKS "LINKS"
56 #define CMD_LIST "LIST"
57 #define CMD_LUSERS "LUSERS"
59 #define CMD_MARK "MARK"
60 #define CMD_MODE "MODE"
61 #define CMD_MOTD "MOTD"
62 #define CMD_NAMES "NAMES"
63 #define CMD_NICK "NICK"
64 #define CMD_NOTICE "NOTICE"
65 #define CMD_OPER "OPER"
66 #define CMD_OPMODE "OPMODE"
67 #define CMD_PART "PART"
68 #define CMD_PASS "PASS"
69 #define CMD_PING "PING"
70 #define CMD_PONG "PONG"
71 #define CMD_POST "POST"
72 #define CMD_PRIVMSG "PRIVMSG"
73 #define CMD_PRIVS "PRIVS"
74 #define CMD_PROTO "PROTO"
75 #define CMD_QUIT "QUIT"
76 #define CMD_REHASH "REHASH"
77 #define CMD_RESET "RESET"
78 #define CMD_RESTART "RESTART"
79 #define CMD_RPING "RPING"
80 #define CMD_RPONG "RPONG"
81 #define CMD_SERVER "SERVER"
82 #define CMD_SERVLIST "SERVLIST"
83 #define CMD_SERVSET "SERVSET"
85 #define CMD_SETTIME "SETTIME"
86 #define CMD_SILENCE "SILENCE"
87 #define CMD_SQUERY "SQUERY"
88 #define CMD_SQUIT "SQUIT"
89 #define CMD_STATS "STATS"
90 #define CMD_SVSNICK "SVSNICK"
91 #define CMD_TIME "TIME"
92 #define CMD_TOPIC "TOPIC"
93 #define CMD_TRACE "TRACE"
94 #define CMD_UPING "UPING"
95 #define CMD_USER "USER"
96 #define CMD_USERHOST "USERHOST"
97 #define CMD_USERIP "USERIP"
98 #define CMD_VERSION "VERSION"
99 #define CMD_WALLCHOPS "WALLCHOPS"
100 #define CMD_WALLOPS "WALLOPS"
101 #define CMD_WALLHOPS "WALLHOPS"
102 #define CMD_WALLUSERS "WALLUSERS"
103 #define CMD_WALLVOICES "WALLVOICES"
104 #define CMD_WALLHOPS "WALLHOPS"
105 #define CMD_WHO "WHO"
106 #define CMD_WHOIS "WHOIS"
107 #define CMD_WHOWAS "WHOWAS"
109 /* Tokenized commands. */
110 #define TOK_ACCOUNT "AC"
111 #define TOK_ADMIN "AD"
112 #define TOK_ASLL "LL"
114 #define TOK_BURST "B"
115 #define TOK_CLEARMODE "CM"
116 #define TOK_CLOSE "CLOSE"
117 #define TOK_CNOTICE "CN"
118 #define TOK_CONNECT "CO"
119 #define TOK_CPRIVMSG "CP"
120 #define TOK_CREATE "C"
121 #define TOK_DESTRUCT "DE"
122 #define TOK_DESYNCH "DS"
123 #define TOK_DIE "DIE"
124 #define TOK_DNS "DNS"
126 #define TOK_EOB_ACK "EA"
127 #define TOK_ERROR "Y"
128 #define TOK_EXEMPT "EX"
129 #define TOK_FAKEHOST "FA"
130 #define TOK_GET "GET"
131 #define TOK_GLINE "GL"
132 #define TOK_HASH "HASH"
133 #define TOK_HELP "HELP"
135 #define TOK_INVITE "I"
136 #define TOK_ISON "ISON"
138 #define TOK_JUPE "JU"
141 #define TOK_LINKS "LI"
142 #define TOK_LIST "LIST"
143 #define TOK_LUSERS "LU"
144 #define TOK_MAP "MAP"
145 #define TOK_MARK "MK"
147 #define TOK_MOTD "MO"
148 #define TOK_NAMES "E"
150 #define TOK_NOTICE "O"
151 #define TOK_OPER "OPER"
152 #define TOK_OPMODE "OM"
154 #define TOK_PASS "PA"
157 #define TOK_POST "POST"
158 #define TOK_PRIVMSG "P"
159 #define TOK_PRIVS "PRIVS"
160 #define TOK_PROTO "PROTO"
162 #define TOK_REHASH "REHASH"
163 #define TOK_RESET "RESET"
164 #define TOK_RESTART "RESTART"
165 #define TOK_RPING "RI"
166 #define TOK_RPONG "RO"
167 #define TOK_SERVER "S"
168 #define TOK_SERVLIST "SERVSET"
169 #define TOK_SERVSET "SERVSET"
170 #define TOK_SET "SET"
171 #define TOK_SETTIME "SE"
172 #define TOK_SILENCE "U"
173 #define TOK_SQUERY "SQUERY"
174 #define TOK_SQUIT "SQ"
175 #define TOK_STATS "R"
176 #define TOK_SVSNICK "SN"
177 #define TOK_TIME "TI"
178 #define TOK_TOPIC "T"
179 #define TOK_TRACE "TR"
180 #define TOK_UPING "UP"
181 #define TOK_USER "USER"
182 #define TOK_USERHOST "USERHOST"
183 #define TOK_USERIP "USERIP"
184 #define TOK_VERSION "V"
185 #define TOK_WALLCHOPS "WC"
186 #define TOK_WALLOPS "WA"
187 #define TOK_WALLHOPS "WH"
188 #define TOK_WALLUSERS "WU"
189 #define TOK_WALLVOICES "WV"
190 #define TOK_WALLHOPS "WH"
192 #define TOK_WHOIS "W"
193 #define TOK_WHOWAS "X"
195 /* Protocol messages; aliased to full commands or tokens depending
196 on compile-time configuration. ircu prefers tokens WITH THE
197 EXCEPTION OF THE SERVER AND PASS COMMANDS, which cannot be
198 tokenized, because clients' (ie. a linking server) commands are
199 only checked against the full command list.
201 #if defined(ENABLE_TOKENS)
202 #define TYPE(NAME) TOK_ ## NAME
203 #else /* !ENABLE_TOKENS */
204 #define TYPE(NAME) CMD_ ## NAME
205 #endif /* ENABLE_TOKENS */
207 #define P10_ACCOUNT TYPE(ACCOUNT)
208 #define P10_ADMIN TYPE(ADMIN)
209 #define P10_ASLL TYPE(ASLL)
210 #define P10_AWAY TYPE(AWAY)
211 #define P10_BURST TYPE(BURST)
212 #define P10_CLEARMODE TYPE(CLEARMODE)
213 #define P10_CLOSE TYPE(CLOSE)
214 #define P10_CNOTICE TYPE(CNOTICE)
215 #define P10_CONNECT TYPE(CONNECT)
216 #define P10_CPRIVMSG TYPE(CPRIVMSG)
217 #define P10_CREATE TYPE(CREATE)
218 #define P10_DESTRUCT TYPE(DESTRUCT)
219 #define P10_DESYNCH TYPE(DESYNCH)
220 #define P10_DIE TYPE(DIE)
221 #define P10_DNS TYPE(DNS)
222 #define P10_EOB TYPE(EOB)
223 #define P10_EOB_ACK TYPE(EOB_ACK)
224 #define P10_ERROR TYPE(ERROR)
225 #define P10_FAKEHOST TYPE(FAKEHOST)
226 #define P10_GET TYPE(GET)
227 #define P10_GLINE TYPE(GLINE)
228 #define P10_HASH TYPE(HASH)
229 #define P10_HELP TYPE(HELP)
230 #define P10_INFO TYPE(INFO)
231 #define P10_INVITE TYPE(INVITE)
232 #define P10_ISON TYPE(ISON)
233 #define P10_JOIN TYPE(JOIN)
234 #define P10_JUPE TYPE(JUPE)
235 #define P10_KICK TYPE(KICK)
236 #define P10_KILL TYPE(KILL)
237 #define P10_LINKS TYPE(LINKS)
238 #define P10_LIST TYPE(LIST)
239 #define P10_LUSERS TYPE(LUSERS)
240 #define P10_MAP TYPE(MAP)
241 #define P10_MARK TYPE(MARK)
242 #define P10_MODE TYPE(MODE)
243 #define P10_MOTD TYPE(MOTD)
244 #define P10_NAMES TYPE(NAMES)
245 #define P10_NICK TYPE(NICK)
246 #define P10_NOTICE TYPE(NOTICE)
247 #define P10_OPER TYPE(OPER)
248 #define P10_OPMODE TYPE(OPMODE)
249 #define P10_PART TYPE(PART)
250 #define P10_PASS CMD_PASS
251 #define P10_PING TYPE(PING)
252 #define P10_PONG TYPE(PONG)
253 #define P10_POST TYPE(POST)
254 #define P10_PRIVMSG TYPE(PRIVMSG)
255 #define P10_PRIVS TYPE(PRIVS)
256 #define P10_PROTO TYPE(PROTO)
257 #define P10_QUIT TYPE(QUIT)
258 #define P10_REHASH TYPE(REHASH)
259 #define P10_RESET TYPE(RESET)
260 #define P10_RESTART TYPE(RESTART)
261 #define P10_RPING TYPE(RPING)
262 #define P10_RPONG TYPE(RPONG)
263 #define P10_SERVER CMD_SERVER
264 #define P10_SERVLIST TYPE(SERVLIST)
265 #define P10_SERVSET TYPE(SERVSET)
266 #define P10_SET TYPE(SET)
267 #define P10_SETTIME TYPE(SETTIME)
268 #define P10_SILENCE TYPE(SILENCE)
269 #define P10_SQUERY TYPE(SQUERY)
270 #define P10_SQUIT TYPE(SQUIT)
271 #define P10_STATS TYPE(STATS)
272 #define P10_SVSNICK TYPE(SVSNICK)
273 #define P10_TIME TYPE(TIME)
274 #define P10_TOPIC TYPE(TOPIC)
275 #define P10_TRACE TYPE(TRACE)
276 #define P10_UPING TYPE(UPING)
277 #define P10_USER TYPE(USER)
278 #define P10_USERHOST TYPE(USERHOST)
279 #define P10_USERIP TYPE(USERIP)
280 #define P10_VERSION TYPE(VERSION)
281 #define P10_WALLCHOPS TYPE(WALLCHOPS)
282 #define P10_WALLOPS TYPE(WALLOPS)
283 #define P10_WALLHOPS TYPE(WALLHOPS)
284 #define P10_WALLUSERS TYPE(WALLUSERS)
285 #define P10_WALLVOICES TYPE(WALLVOICES)
286 #define P10_WHO TYPE(WHO)
287 #define P10_WHOIS TYPE(WHOIS)
288 #define P10_WHOWAS TYPE(WHOWAS)
289 #define P10_EXEMPT TYPE(EXEMPT)
291 /* Servers claiming to have a boot or link time before PREHISTORY
292 * trigger errors to the log. We hope no server has been running
293 * constantly since September 1994. :)
295 #define PREHISTORY 780000000
297 static struct server
*servers_num
[64*64];
298 static privmsg_func_t
*privmsg_funcs
;
299 static unsigned int num_privmsg_funcs
;
300 static privmsg_func_t
*notice_funcs
;
301 static unsigned int num_notice_funcs
;
302 static struct dict
*unbursted_channels
;
303 static char *his_servername
;
304 static char *his_servercomment
;
306 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
);
308 extern int off_channel
;
310 /* Numerics can be XYY, XYYY, or XXYYY; with X's identifying the
311 * server and Y's indentifying the client on that server. */
313 GetServerN(const char *numeric
)
315 switch (strlen(numeric
)) {
317 return servers_num
[base64toint(numeric
, 2)];
321 return servers_num
[base64toint(numeric
, 1)];
328 GetUserN(const char *numeric
) /* using numeric */
334 switch (strlen(numeric
)) {
336 log_module(MAIN_LOG
, LOG_WARNING
, "GetUserN(%s): numeric too long!", numeric
);
338 case 5: slen
= 2; ulen
= 3; break;
339 case 4: slen
= 1; ulen
= 3; break;
340 case 3: slen
= 1; ulen
= 2; break;
341 case 2: case 1: case 0:
342 log_module(MAIN_LOG
, LOG_WARNING
, "GetUserN(%s): numeric too short!", numeric
);
345 if (!(s
= servers_num
[base64toint(numeric
, slen
)])) {
346 log_module(MAIN_LOG
, LOG_WARNING
, "GetUserN(%s): couldn't find server (len=%d)!", numeric
, slen
);
349 n
= base64toint(numeric
+slen
, ulen
) & s
->num_mask
;
350 if (!(un
= s
->users
[n
])) {
351 log_module(MAIN_LOG
, LOG_WARNING
, "GetUserN(%s) couldn't find user!", numeric
);
357 privmsg_user_helper(struct userNode
*un
, void *data
)
359 struct privmsg_desc
*pd
= data
;
360 unsigned int num
= un
->num_local
;
361 if (!pd
->is_notice
) {
362 if ((num
< num_privmsg_funcs
) && privmsg_funcs
[num
]) {
363 privmsg_funcs
[num
](pd
->user
, un
, pd
->text
, pd
->is_qualified
);
366 if ((num
< num_notice_funcs
) && notice_funcs
[num
]) {
367 notice_funcs
[num
](pd
->user
, un
, pd
->text
, pd
->is_qualified
);
373 irc_server(struct server
*srv
)
375 char extranum
[COMBO_NUMERIC_LEN
+1];
377 inttobase64(extranum
, srv
->num_mask
, (srv
->numeric
[1] || (srv
->num_mask
>= 64*64)) ? 3 : 2);
379 /* The +s, ignored by Run's ircu, means "service" to Undernet's ircu */
380 putsock(P10_SERVER
" %s %d %li %li J10 %s%s +s :%s",
381 srv
->name
, srv
->hops
+1, srv
->boot
, srv
->link
, srv
->numeric
, extranum
, srv
->description
);
383 putsock("%s " P10_SERVER
" %s %d %li %li %c10 %s%s +s :%s",
384 self
->numeric
, srv
->name
, srv
->hops
+1, srv
->boot
, srv
->link
, (srv
->self_burst
? 'J' : 'P'), srv
->numeric
, extranum
, srv
->description
);
389 irc_user(struct userNode
*user
)
394 inttobase64(b64ip
, ntohl(user
->ip
.s_addr
), 6);
401 modes
[modelen
++] = 'o';
402 if (IsInvisible(user
))
403 modes
[modelen
++] = 'i';
405 modes
[modelen
++] = 'w';
407 modes
[modelen
++] = 'k';
408 if (IsServNotice(user
))
409 modes
[modelen
++] = 's';
411 modes
[modelen
++] = 'd';
413 modes
[modelen
++] = 'g';
414 // sethost - reed/apples
415 // if (IsHelperIrcu(user))
417 modes
[modelen
++] = 'h';
418 if (IsFakeHost(user
))
419 modes
[modelen
++] = 'f';
420 if (IsHiddenHost(user
))
421 modes
[modelen
++] = 'x';
424 /* we don't need to put the + in modes because it's in the format string. */
425 putsock("%s " P10_NICK
" %s %d %li %s %s +%s %s %s :%s",
426 user
->uplink
->numeric
, user
->nick
, user
->uplink
->hops
+1, user
->timestamp
, user
->ident
, user
->hostname
, modes
, b64ip
, user
->numeric
, user
->info
);
428 putsock("%s " P10_NICK
" %s %d %li %s %s %s %s :%s",
429 user
->uplink
->numeric
, user
->nick
, user
->uplink
->hops
+1, user
->timestamp
, user
->ident
, user
->hostname
, b64ip
, user
->numeric
, user
->info
);
434 irc_account(struct userNode
*user
, const char *stamp
, time_t timestamp
)
436 putsock("%s " P10_ACCOUNT
" %s R %s %lu", self
->numeric
, user
->numeric
, stamp
, timestamp
);
440 irc_fakehost(struct userNode
*user
, const char *host
)
442 putsock("%s " P10_FAKEHOST
" %s %s", self
->numeric
, user
->numeric
, host
);
446 irc_regnick(UNUSED_ARG(struct userNode
*user
))
448 /* no operation here */
452 irc_nick(struct userNode
*user
, UNUSED_ARG(const char *old_nick
))
454 putsock("%s " P10_NICK
" %s "FMT_TIME_T
, user
->numeric
, user
->nick
, now
);
458 irc_fetchtopic(struct userNode
*from
, const char *to
)
462 putsock("%s " P10_TOPIC
" %s", from
->numeric
, to
);
466 irc_squit(struct server
*srv
, const char *message
, const char *service_message
)
468 if (!service_message
)
469 service_message
= message
;
471 /* Are we leaving the network? */
472 if (srv
== self
&& cManager
.uplink
->state
== CONNECTED
) {
475 /* Quit all clients linked to me. */
476 for (i
= 0; i
<= self
->num_mask
; i
++) {
479 irc_quit(self
->users
[i
], service_message
);
483 putsock("%s " P10_SQUIT
" %s %d :%s", self
->numeric
, srv
->name
, 0, message
);
486 /* Force a reconnect to the currently selected server. */
487 cManager
.uplink
->tries
= 0;
488 log_module(MAIN_LOG
, LOG_INFO
, "Squitting from uplink: %s", message
);
494 irc_wallchops(struct userNode
*from
, const char *to
, const char *message
)
496 putsock("%s " P10_WALLCHOPS
" %s :%s", from
->numeric
, to
, message
);
500 irc_notice(struct userNode
*from
, const char *to
, const char *message
)
502 putsock("%s " P10_NOTICE
" %s :%s", from
->numeric
, to
, message
);
506 irc_notice_user(struct userNode
*from
, struct userNode
*to
, const char *message
)
508 putsock("%s " P10_NOTICE
" %s :%s", from
->numeric
, to
->numeric
, message
);
512 irc_privmsg(struct userNode
*from
, const char *to
, const char *message
)
514 putsock("%s " P10_PRIVMSG
" %s :%s", from
->numeric
, to
, message
);
520 putsock("%s " P10_EOB
, self
->numeric
);
526 putsock("%s " P10_EOB_ACK
, self
->numeric
);
530 irc_ping(const char *payload
)
532 putsock("%s " P10_PING
" :%s", self
->numeric
, payload
);
536 irc_pong(const char *who
, const char *data
)
538 putsock("%s " P10_PONG
" %s :%s", self
->numeric
, who
, data
);
542 irc_pass(const char *passwd
)
544 putsock(P10_PASS
" :%s", passwd
);
548 irc_introduce(const char *passwd
)
550 void timed_send_ping(void *data
);
552 self
->self_burst
= self
->burst
= 1;
556 timeq_add(now
+ ping_freq
, timed_send_ping
, 0);
560 irc_gline(struct server
*srv
, struct gline
*gline
)
562 putsock("%s " P10_GLINE
" %s +%s %ld :<%s> %s",
563 self
->numeric
, (srv
? srv
->numeric
: "*"), gline
->target
, gline
->expires
-now
, gline
->issuer
, gline
->reason
);
567 irc_settime(const char *srv_name_mask
, time_t new_time
)
569 ioset_set_time(new_time
);
570 if (!strcmp(srv_name_mask
, "*"))
572 putsock("%s " P10_SETTIME
" " FMT_TIME_T
" %s", self
->numeric
, new_time
, srv_name_mask
);
576 irc_ungline(const char *mask
)
578 putsock("%s " P10_GLINE
" * -%s", self
->numeric
, mask
);
582 irc_burst(struct chanNode
*chan
)
584 char burst_line
[512];
585 int pos
, base_len
, len
;
588 struct exemptNode
*en
;
592 base_len
= sprintf(burst_line
, "%s " P10_BURST
" %s " FMT_TIME_T
" ",
593 self
->numeric
, chan
->name
, chan
->timestamp
);
594 len
= irc_make_chanmode(chan
, burst_line
+base_len
);
595 pos
= base_len
+ len
;
597 burst_line
[pos
++] = ' ';
600 for (n
=0; n
<chan
->members
.used
; n
++) {
601 mn
= chan
->members
.list
[n
];
603 burst_line
[pos
-1] = 0; /* -1 to back up over the space or comma */
604 putsock("%s", burst_line
);
608 memcpy(burst_line
+pos
, mn
->user
->numeric
, strlen(mn
->user
->numeric
));
609 pos
+= strlen(mn
->user
->numeric
);
610 if (mn
->modes
&& (mn
->modes
!= last_mode
)) {
611 last_mode
= mn
->modes
;
612 burst_line
[pos
++] = ':';
613 if (last_mode
& MODE_CHANOP
)
614 burst_line
[pos
++] = 'o';
615 if (last_mode
& MODE_HALFOP
)
616 burst_line
[pos
++] = 'h';
617 if (last_mode
& MODE_VOICE
)
618 burst_line
[pos
++] = 'v';
620 if ((n
+1)<chan
->members
.used
)
621 burst_line
[pos
++] = ',';
623 if (chan
->banlist
.used
) {
625 if (pos
+2+strlen(chan
->banlist
.list
[0]->ban
) > 505) {
626 burst_line
[pos
-1] = 0;
627 putsock("%s", burst_line
);
630 burst_line
[pos
++] = ' ';
633 burst_line
[pos
++] = ':';
634 burst_line
[pos
++] = '%';
636 for (n
=0; n
<chan
->banlist
.used
; n
++) {
637 bn
= chan
->banlist
.list
[n
];
638 len
= strlen(bn
->ban
);
639 if (pos
+len
+1 > 510) {
640 burst_line
[pos
-1] = 0; /* -1 to back up over the space or comma */
641 putsock("%s", burst_line
);
644 memcpy(burst_line
+pos
, bn
->ban
, len
);
646 burst_line
[pos
++] = ' ';
649 if (chan
->exemptlist
.used
) {
650 /* dump the exempt */
651 if (pos
+2+strlen(chan
->exemptlist
.list
[0]->exempt
) > 505) {
652 burst_line
[pos
-1] = 0;
653 putsock("%s", burst_line
);
656 burst_line
[pos
++] = ' ';
659 burst_line
[pos
++] = ' ';
660 burst_line
[pos
++] = '~';
661 burst_line
[pos
++] = ' ';
663 for (n
=0; n
<chan
->exemptlist
.used
; n
++) {
664 en
= chan
->exemptlist
.list
[n
];
665 len
= strlen(en
->exempt
);
666 if (pos
+len
+1 > 510) {
667 burst_line
[pos
-1] = 0; /* -1 to back up over the space or comma */
668 putsock("%s", burst_line
);
671 memcpy(burst_line
+pos
, en
->exempt
, len
);
673 burst_line
[pos
++] = ' ';
676 /* print the last line */
678 putsock("%s", burst_line
);
682 irc_quit(struct userNode
*user
, const char *message
)
684 putsock("%s " P10_QUIT
" :%s", user
->numeric
, message
);
688 irc_error(const char *to
, const char *message
)
691 putsock("%s " P10_ERROR
" :%s", to
, message
);
693 putsock(":%s " P10_ERROR
" :%s", self
->name
, message
);
698 irc_kill(struct userNode
*from
, struct userNode
*target
, const char *message
)
701 putsock("%s " P10_KILL
" %s :%s!%s (%s)",
702 from
->numeric
, target
->numeric
, self
->name
, from
->nick
, message
);
704 putsock("%s " P10_KILL
" %s :%s (%s)",
705 self
->numeric
, target
->numeric
, self
->name
, message
);
710 irc_mode(struct userNode
*from
, struct chanNode
*target
, const char *modes
)
712 putsock("%s " P10_MODE
" %s %s "FMT_TIME_T
,
713 (from
? from
->numeric
: self
->numeric
),
714 target
->name
, modes
, target
->timestamp
);
717 /* Added to allow services to mode users
718 2005 - 8 - 10 by Life4Christ
721 irc_umode(struct userNode
*target
, const char *modes
)
723 putsock("%s " P10_MODE
" %s %s ",self
->numeric
,target
->nick
, modes
);
728 irc_invite(struct userNode
*from
, struct userNode
*who
, struct chanNode
*to
)
730 putsock("%s " P10_INVITE
" %s %s", from
->numeric
, who
->nick
, to
->name
);
734 irc_join(struct userNode
*who
, struct chanNode
*what
)
736 if (what
->members
.used
== 1) {
737 putsock("%s " P10_CREATE
" %s %lu",
738 who
->numeric
, what
->name
, what
->timestamp
);
740 putsock("%s " P10_JOIN
" %s %lu", who
->numeric
, what
->name
, what
->timestamp
);
745 irc_kick(struct userNode
*who
, struct userNode
*target
, struct chanNode
*channel
, const char *msg
)
748 struct modeNode
*mn
= GetUserMode(channel
, who
);
749 numeric
= ((mn
&& (mn
->modes
& MODE_CHANOP
)) || off_channel
) ? who
->numeric
: self
->numeric
;
750 putsock("%s " P10_KICK
" %s %s :%s",
751 numeric
, channel
->name
, target
->numeric
, msg
);
755 irc_stats(struct userNode
*from
, struct server
*target
, char type
)
757 putsock("%s " P10_STATS
" %c :%s", from
->numeric
, type
, target
->numeric
);
761 irc_svsnick(struct userNode
*from
, struct userNode
*target
, const char *newnick
)
763 putsock("%s " P10_SVSNICK
" %s %s "FMT_TIME_T
, from
->uplink
->numeric
, target
->numeric
, newnick
, now
);
767 irc_part(struct userNode
*who
, struct chanNode
*what
, const char *reason
)
770 putsock("%s " P10_PART
" %s :%s", who
->numeric
, what
->name
, reason
);
772 putsock("%s " P10_PART
" %s", who
->numeric
, what
->name
);
777 irc_topic(struct userNode
*who
, struct chanNode
*what
, const char *topic
)
779 putsock("%s " P10_TOPIC
" %s :%s", who
->numeric
, what
->name
, topic
);
783 irc_raw(const char *what
)
789 irc_numeric(struct userNode
*user
, unsigned int num
, const char *format
, ...)
793 va_start(arg_list
, format
);
794 vsnprintf(buffer
, MAXLEN
-2, format
, arg_list
);
795 buffer
[MAXLEN
-1] = 0;
796 putsock(":%s %03d %s %s", self
->name
, num
, user
->nick
, buffer
);
799 static void send_burst(void);
802 change_nicklen(int new_nicklen
)
805 char new_nick
[NICKLEN
+1];
806 struct userNode
*user
;
808 nicklen
= new_nicklen
;
809 /* fix up any users we have here */
810 for (nn
=0; nn
<=self
->num_mask
; nn
++) {
811 if (!(user
= self
->users
[nn
]))
813 safestrncpy(new_nick
, user
->nick
, sizeof(new_nick
));
814 new_nick
[nicklen
] = 0;
815 NickChange(user
, new_nick
, 1);
819 static CMD_FUNC(cmd_whois
)
821 struct userNode
*from
;
822 struct userNode
*who
;
826 if (!(from
= GetUserH(origin
))) {
827 log_module(MAIN_LOG
, LOG_ERROR
, "Could not find WHOIS origin user %s", origin
);
830 if(!(who
= GetUserH(argv
[2]))) {
831 irc_numeric(from
, ERR_NOSUCHNICK
, "%s@%s :No such nick", argv
[2], self
->name
);
834 if (IsHiddenHost(who
) && !IsOper(from
)) {
835 /* Just stay quiet. */
838 irc_numeric(from
, RPL_WHOISUSER
, "%s %s %s * :%s", who
->nick
, who
->ident
, who
->hostname
, who
->info
);
839 if (his_servername
&& his_servercomment
)
840 irc_numeric(from
, RPL_WHOISSERVER
, "%s %s :%s", who
->nick
, his_servername
, his_servercomment
);
842 irc_numeric(from
, RPL_WHOISSERVER
, "%s %s :%s", who
->nick
, who
->uplink
->name
, who
->uplink
->description
);
844 irc_numeric(from
, RPL_WHOISOPERATOR
, "%s :is a megalomaniacal power hungry tyrant", who
->nick
);
845 irc_numeric(from
, RPL_ENDOFWHOIS
, "%s :End of /WHOIS list", who
->nick
);
849 static CMD_FUNC(cmd_server
)
857 /* another server introduced us */
858 srv
= AddServer(GetServerH(origin
), argv
[1], atoi(argv
[2]), atoi(argv
[3]), atoi(argv
[4]), argv
[6], argv
[argc
-1]);
861 srv
->self_burst
= argv
[5][0] == 'J';
864 /* this must be our uplink */
865 srv
= self
->uplink
= AddServer(self
, argv
[1], atoi(argv
[2]), atoi(argv
[3]), atoi(argv
[4]), argv
[6], argv
[argc
-1]);
868 srv
->self_burst
= argv
[5][0] == 'J';
870 if ((argv
[7][0] == '+') && !force_n2k
) {
871 log_module(MAIN_LOG
, LOG_WARNING
, "Got Undernet-style SERVER message but \"force_n2k\" not on.");
876 /* Fix up our timestamps if necessary. */
877 if (srv
->boot
<= PREHISTORY
) {
878 /* Server from the mists of time.. */
879 if (srv
->hops
== 1) {
880 log_module(MAIN_LOG
, LOG_ERROR
, "Server %s claims to have booted at time "FMT_TIME_T
". This is absurd.", srv
->name
, srv
->boot
);
882 } else if ((str
= conf_get_data("server/reliable_clock", RECDB_QSTRING
))
883 && enabled_string(str
)) {
884 /* If we have a reliable clock, we just keep our current time. */
886 if (srv
->boot
<= self
->boot
) {
887 /* The other server is older than us. Accept their timestamp.
888 * Alternately, we are same age, but we accept their time
889 * since we are linking to them. */
890 self
->boot
= srv
->boot
;
891 ioset_set_time(srv
->link
);
894 if (srv
== self
->uplink
) {
895 extern time_t burst_begin
;
901 static CMD_FUNC(cmd_eob
)
903 struct server
*sender
;
907 if (!(sender
= GetServerH(origin
)))
909 if (sender
== self
->uplink
) {
910 cManager
.uplink
->state
= CONNECTED
;
911 for (it
= dict_first(unbursted_channels
); it
; it
= iter_next(it
))
912 irc_burst(iter_data(it
));
913 dict_delete(unbursted_channels
);
914 unbursted_channels
= NULL
;
918 sender
->self_burst
= 0;
919 recalc_bursts(sender
);
920 for (ii
=0; ii
<slf_used
; ii
++)
921 slf_list
[ii
](sender
);
925 static CMD_FUNC(cmd_eob_ack
)
927 extern time_t burst_begin
;
929 if (GetServerH(origin
) == self
->uplink
) {
930 burst_length
= now
- burst_begin
;
931 self
->self_burst
= self
->burst
= 0;
933 cManager
.uplink
->state
= CONNECTED
;
937 static CMD_FUNC(cmd_ping
)
943 irc_pong(argv
[2], argv
[1]);
944 else if ((srv
= GetServerH(origin
)))
945 irc_pong(self
->name
, srv
->numeric
);
946 else if ((un
= GetUserH(origin
)))
947 irc_pong(self
->name
, un
->numeric
);
949 irc_pong(self
->name
, origin
);
951 timeq_del(0, timed_send_ping
, 0, TIMEQ_IGNORE_WHEN
|TIMEQ_IGNORE_DATA
);
952 timeq_del(0, timed_ping_timeout
, 0, TIMEQ_IGNORE_WHEN
|TIMEQ_IGNORE_DATA
);
953 timeq_add(now
+ ping_freq
, timed_send_ping
, 0);
958 static CMD_FUNC(cmd_error_nick
)
960 /* Go back to original IRC length .. and try to reconnect :/ */
962 irc_squit(self
, "Got erroneous nickname, truncating nicks.", NULL
);
967 struct userNode
*user
;
972 join_helper(struct chanNode
*chan
, void *data
)
974 struct create_desc
*cd
= data
;
975 AddChannelUser(cd
->user
, chan
);
979 create_helper(char *name
, void *data
)
981 struct create_desc
*cd
= data
;
983 if (!strcmp(name
, "0")) {
984 while (cd
->user
->channels
.used
> 0)
985 DelChannelUser(cd
->user
, cd
->user
->channels
.list
[0]->channel
, 0, 0);
989 AddChannelUser(cd
->user
, AddChannel(name
, cd
->when
, NULL
, NULL
, NULL
));
992 static CMD_FUNC(cmd_create
)
994 struct create_desc cd
;
995 struct userNode
*user
;
997 if ((argc
< 3) || !(user
= GetUserH(origin
)))
1000 cd
.when
= atoi(argv
[2]);
1001 parse_foreach(argv
[1], join_helper
, create_helper
, NULL
, NULL
, &cd
);
1005 static CMD_FUNC(cmd_join
)
1007 struct create_desc cd
;
1009 if (!(cd
.user
= GetUserH(origin
)))
1016 cd
.when
= atoi(argv
[2]);
1017 parse_foreach(argv
[1], join_helper
, create_helper
, NULL
, NULL
, &cd
);
1021 static CMD_FUNC(cmd_pong
)
1025 if (!strcmp(argv
[2], self
->name
)) {
1026 timeq_del(0, timed_send_ping
, 0, TIMEQ_IGNORE_WHEN
|TIMEQ_IGNORE_DATA
);
1027 timeq_del(0, timed_ping_timeout
, 0, TIMEQ_IGNORE_WHEN
|TIMEQ_IGNORE_DATA
);
1028 timeq_add(now
+ ping_freq
, timed_send_ping
, 0);
1034 static CMD_FUNC(cmd_nick
)
1036 struct userNode
*user
;
1037 if ((user
= GetUserH(origin
))) {
1038 /* nick change (since the source is a user numeric) */
1041 NickChange(user
, argv
[1], 1);
1043 struct server
*serv
;
1048 serv
= GetServerH(origin
);
1050 unsplit_string(argv
+6, argc
-9, modes
);
1053 AddUser(serv
, argv
[1], argv
[4], argv
[5], modes
, argv
[argc
-2], argv
[argc
-1], atoi(argv
[3]), argv
[argc
-3]);
1058 static CMD_FUNC(cmd_account
)
1060 struct userNode
*user
;
1061 struct server
*server
;
1062 struct handle_info
*hi
;
1064 if ((argc
< 3) || !origin
|| !(server
= GetServerH(origin
)))
1065 return 0; /* Origin must be server. */
1067 /* This next line appears to tremple origin.. why? */
1068 user
= GetUserN(argv
[1]);
1070 return 1; /* A QUIT probably passed the ACCOUNT. */
1072 if(!strcmp(argv
[2],"C"))
1074 if((hi
= loc_auth(argv
[4], argv
[5])))
1077 putsock("%s " P10_ACCOUNT
" %s A %s %lu", self
->numeric
, server
->numeric
, argv
[3], hi
->registered
);
1083 putsock("%s " P10_ACCOUNT
" %s D %s", self
->numeric
, server
->numeric
, argv
[3]);
1087 else if(!strcmp(argv
[2],"R"))
1088 call_account_func(user
, argv
[3]);
1090 call_account_func(user
, argv
[2]); /* For backward compatability */
1094 static CMD_FUNC(cmd_fakehost
)
1096 struct userNode
*user
;
1098 if ((argc
< 3) || !origin
|| !GetServerH(origin
))
1100 if (!(user
= GetUserN(argv
[1])))
1102 assign_fakehost(user
, argv
[2], 0);
1106 static CMD_FUNC(cmd_burst
)
1109 char modes
[MAXLEN
], *members
= "";
1110 static char exemptlist
[MAXLEN
], banlist
[MAXLEN
];
1111 unsigned int next
= 3, res
= 1;
1112 int ctype
= 0, echeck
= 0, bcheck
= 0;
1113 struct chanNode
*cNode
;
1114 struct userNode
*un
;
1115 struct modeNode
*mNode
;
1117 char *user
, *end
, sep
;
1118 time_t in_timestamp
;
1128 while (next
< argc
) {
1129 switch (argv
[next
][0]) {
1133 for (pos
=argv
[next
], n_modes
= 1; *pos
; pos
++)
1134 if ((*pos
== 'k') || (*pos
== 'l'))
1136 unsplit_string(argv
+next
, n_modes
, modes
);
1141 for(parm
= mysep(&argv
[next
], " "); /* parm = first param */
1142 parm
; /* While param is not null */
1143 parm
= mysep(&argv
[next
], " ") /* parm = next param */
1161 /* strip % char off start of very first ban */
1162 if (strlen(parm
) > 1) {
1163 strncat(banlist
, strtok(parm
, "%"), sizeof(banlist
) - 1 - strlen(banlist
));
1164 strncat(banlist
, " ", sizeof(banlist
) - 1 - strlen(banlist
));
1168 strncat(banlist
, parm
, sizeof(banlist
) - 1 - strlen(banlist
));
1169 strncat(banlist
, " ", sizeof(banlist
) - 1 - strlen(banlist
));
1171 } else if (ctype
== 2) {
1175 strncat(exemptlist
, parm
, sizeof(exemptlist
) - 1 - strlen(exemptlist
));
1176 strncat(exemptlist
, " ", sizeof(exemptlist
) - 1 - strlen(exemptlist
));
1183 default: members
= argv
[next
++]; break;
1187 in_timestamp
= atoi(argv
[2]);
1188 if ((cNode
= dict_find(unbursted_channels
, argv
[1], NULL
))) {
1189 cNode
->timestamp
= in_timestamp
;
1190 dict_remove(unbursted_channels
, cNode
->name
);
1193 cNode
= AddChannel(argv
[1], in_timestamp
, modes
, banlist
, exemptlist
);
1195 /* Burst channel members in now. */
1196 for (user
= members
, sep
= *members
, mode
= 0; sep
; user
= end
) {
1197 for (end
= user
+ 3; isalnum(*end
) || *end
== '[' || *end
== ']'; end
++) ;
1198 sep
= *end
++; end
[-1] = 0;
1201 while ((sep
= *end
++)) {
1203 mode
|= MODE_CHANOP
;
1204 else if (sep
== 'h')
1205 mode
|= MODE_HALFOP
;
1206 else if (sep
== 'v')
1208 else if (isdigit(sep
)) {
1209 mode
|= MODE_CHANOP
;
1210 while (isdigit(*end
)) end
++;
1217 if (!(un
= GetUserN(user
))) {
1221 if ((mNode
= AddChannelUser(un
, cNode
)))
1222 mNode
->modes
= mode
;
1228 static CMD_FUNC(cmd_mode
)
1230 struct chanNode
*cn
;
1231 struct userNode
*un
;
1232 char *sethost
; // sethost - reed/apples
1233 int i
; // sethost - reed/apples
1237 if (!IsChannelName(argv
[1])) {
1238 un
= GetUserH(argv
[1]);
1240 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to find user %s whose mode is changing.", argv
[1]);
1243 // sethost - reed/apples
1245 mod_usermode(un
, argv
[2]);
1247 sethost
= malloc(strlen(argv
[2]) + 1 + strlen(argv
[3]) + 1);
1249 while((sethost
[i
++] = *argv
[2]++));
1252 while((sethost
[i
++] = *argv
[3]++));
1253 mod_usermode(un
, sethost
); // sethost - reed/apples
1259 if (!(cn
= GetChannel(argv
[1]))) {
1260 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to find channel %s whose mode is changing.", argv
[1]);
1263 if ((un
= GetUserH(origin
))) {
1264 struct modeNode
*mn
;
1265 /* Update idle time for person setting the mode */
1266 if ((mn
= GetUserMode(cn
, un
)))
1267 mn
->idle_since
= now
;
1269 /* If it came from a server, reset timestamp to re-sync. */
1270 cn
->timestamp
= atoi(argv
[argc
-1]);
1273 return mod_chanmode(un
, cn
, argv
+2, argc
-2, MCP_ALLOW_OVB
|MCP_FROM_SERVER
|(un
? MC_NOTIFY
: 0));
1276 static CMD_FUNC(cmd_opmode
)
1278 struct chanNode
*cn
;
1279 struct userNode
*un
;
1284 if (!(cn
= GetChannel(argv
[1]))) {
1285 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to find channel %s whose mode is changing.", argv
[1]);
1288 if (!(un
= GetUserH(origin
))) {
1289 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to find user %s requesting OPMODE.", origin
);
1293 log_module(MAIN_LOG
, LOG_ERROR
, "Non-privileged user %s using OPMODE.", un
->nick
);
1297 return mod_chanmode(un
, cn
, argv
+2, argc
-2, MCP_ALLOW_OVB
|MCP_FROM_SERVER
); /* do NOT announce opmode locally */
1300 static int clear_chanmode(struct chanNode
*channel
, const char *modes
);
1302 static CMD_FUNC(cmd_clearmode
)
1304 struct chanNode
*cn
;
1305 struct userNode
*un
;
1310 if (!(cn
= GetChannel(argv
[1]))) {
1311 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to find channel %s whose mode is changing.", argv
[1]);
1314 if (!(un
= GetUserH(origin
))) {
1315 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to find user %s requesting CLEARMODE.", origin
);
1319 log_module(MAIN_LOG
, LOG_ERROR
, "Non-privileged user %s using CLEARMODE.", un
->nick
);
1323 return clear_chanmode(cn
, argv
[2]);
1326 static CMD_FUNC(cmd_topic
)
1328 struct chanNode
*cn
;
1329 time_t chan_ts
, topic_ts
;
1333 if (!(cn
= GetChannel(argv
[1]))) {
1334 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to find channel %s whose topic is being set", argv
[1]);
1338 /* Looks like an Asuka style topic burst. */
1339 chan_ts
= atoi(argv
[2]);
1340 topic_ts
= atoi(argv
[3]);
1342 chan_ts
= cn
->timestamp
;
1345 SetChannelTopic(cn
, GetUserH(origin
), argv
[argc
-1], 0);
1346 cn
->topic_time
= topic_ts
;
1350 static CMD_FUNC(cmd_num_topic
)
1352 struct chanNode
*cn
;
1355 return 0; /* huh? */
1357 cn
= GetChannel(argv
[2]);
1359 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to find channel %s in topic reply", argv
[2]);
1365 switch (atoi(argv
[0])) {
1368 break; /* no topic */
1372 safestrncpy(cn
->topic
, unsplit_string(argv
+3, argc
-3, NULL
), sizeof(cn
->topic
));
1377 safestrncpy(cn
->topic_nick
, argv
[3], sizeof(cn
->topic_nick
));
1378 cn
->topic_time
= atoi(argv
[4]);
1381 return 0; /* should never happen */
1386 static CMD_FUNC(cmd_num_gline
)
1390 gline_add(origin
, argv
[3], atoi(argv
[4])-now
, argv
[5], now
, 0);
1394 static CMD_FUNC(cmd_quit
)
1396 struct userNode
*user
;
1399 /* Sometimes we get a KILL then a QUIT or the like, so we don't want to
1400 * call DelUser unless we have the user in our grasp. */
1401 if ((user
= GetUserH(origin
)))
1402 DelUser(user
, NULL
, false, argv
[1]);
1406 static CMD_FUNC(cmd_kill
)
1408 struct userNode
*user
;
1411 user
= GetUserN(argv
[1]);
1413 /* If we get a KILL for a non-existent user, it could be a
1414 * Ghost response to a KILL we sent out earlier. So we only
1415 * whine if the target is local.
1417 if (!strncmp(argv
[1], self
->numeric
, strlen(self
->numeric
)))
1418 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to find kill victim %s", argv
[1]);
1422 if (IsLocal(user
) && IsService(user
)) {
1423 /* TODO: rate limit this so silly things don't happen. */
1424 ReintroduceUser(user
);
1428 DelUser(user
, NULL
, false, argv
[2]);
1432 static CMD_FUNC(cmd_part
)
1434 struct userNode
*user
;
1438 user
= GetUserH(origin
);
1441 parse_foreach(argv
[1], part_helper
, NULL
, NULL
, NULL
, user
);
1445 static CMD_FUNC(cmd_kick
)
1449 ChannelUserKicked(GetUserH(origin
), GetUserN(argv
[2]), GetChannel(argv
[1]));
1453 static CMD_FUNC(cmd_squit
)
1455 struct server
*server
;
1459 if (!(server
= GetServerH(argv
[1])))
1462 if (server
== self
->uplink
) {
1463 /* Force a reconnect to the currently selected server. */
1464 cManager
.uplink
->tries
= 0;
1465 log_module(MAIN_LOG
, LOG_INFO
, "Squitting from uplink: %s", argv
[3]);
1470 DelServer(server
, 0, argv
[3]);
1474 static CMD_FUNC(cmd_privmsg
)
1476 struct privmsg_desc pd
;
1479 pd
.user
= GetUserH(origin
);
1480 if (!pd
.user
|| (IsGagged(pd
.user
) && !IsOper(pd
.user
)))
1484 parse_foreach(argv
[1], privmsg_chan_helper
, NULL
, privmsg_user_helper
, privmsg_invalid
, &pd
);
1488 static CMD_FUNC(cmd_notice
)
1490 struct privmsg_desc pd
;
1493 pd
.user
= GetUserH(origin
);
1494 if (!pd
.user
|| (IsGagged(pd
.user
) && !IsOper(pd
.user
)))
1498 parse_foreach(argv
[1], privmsg_chan_helper
, NULL
, privmsg_user_helper
, privmsg_invalid
, &pd
);
1502 static CMD_FUNC(cmd_away
)
1504 struct userNode
*uNode
;
1506 uNode
= GetUserH(origin
);
1510 uNode
->modes
&= ~FLAGS_AWAY
;
1512 uNode
->modes
|= FLAGS_AWAY
;
1516 static CMD_FUNC(cmd_gline
)
1520 if (argv
[2][0] == '+') {
1523 gline_add(origin
, argv
[2]+1, strtoul(argv
[3], NULL
, 0), argv
[argc
-1], now
, 0);
1525 } else if (argv
[2][0] == '-') {
1526 gline_remove(argv
[2]+1, 0);
1532 static CMD_FUNC(cmd_svsnick
)
1534 struct userNode
*target
, *dest
;
1536 || !(target
= GetUserN(argv
[1]))
1538 || (dest
= GetUserH(argv
[2])))
1540 NickChange(target
, argv
[2], 0);
1544 static oper_func_t
*of_list
;
1545 static unsigned int of_size
= 0, of_used
= 0;
1548 free_user(struct userNode
*user
)
1559 free(privmsg_funcs
);
1562 dict_delete(irc_func_dict
);
1563 for (nn
=0; nn
<dead_users
.used
; nn
++)
1564 free_user(dead_users
.list
[nn
]);
1565 userList_clean(&dead_users
);
1569 p10_conf_reload(void) {
1570 hidden_host_suffix
= conf_get_data("server/hidden_host", RECDB_QSTRING
);
1574 remove_unbursted_channel(struct chanNode
*cNode
) {
1575 if (unbursted_channels
)
1576 dict_remove(unbursted_channels
, cNode
->name
);
1582 const char *str
, *desc
;
1583 int numnick
, usermask
, max_users
;
1584 char numer
[COMBO_NUMERIC_LEN
+1];
1586 /* read config items */
1587 str
= conf_get_data("server/ping_freq", RECDB_QSTRING
);
1588 ping_freq
= str
? ParseInterval(str
) : 120;
1589 str
= conf_get_data("server/ping_timeout", RECDB_QSTRING
);
1590 ping_timeout
= str
? ParseInterval(str
) : 30;
1591 str
= conf_get_data("server/force_n2k", RECDB_QSTRING
);
1592 force_n2k
= str
? enabled_string(str
) : 1;
1593 str
= conf_get_data("server/numeric", RECDB_QSTRING
);
1595 log_module(MAIN_LOG
, LOG_ERROR
, "No server/numeric entry in config file.");
1598 numnick
= atoi(str
);
1599 str
= conf_get_data("server/max_users", RECDB_QSTRING
);
1600 max_users
= str
? atoi(str
) : 4096;
1601 for (usermask
= 4; usermask
< max_users
; usermask
<<= 1) ;
1603 if ((numnick
< 64) && (usermask
< 4096) && !force_n2k
)
1604 inttobase64(numer
, (numnick
<< 12) + (usermask
& 0x00fff), 3);
1606 inttobase64(numer
, (numnick
<< 18) + (usermask
& 0x3ffff), 5);
1608 str
= conf_get_data("server/his_servername", RECDB_QSTRING
);
1609 his_servername
= str
? strdup(str
) : NULL
;
1610 str
= conf_get_data("server/his_servercomment", RECDB_QSTRING
);
1611 his_servercomment
= str
? strdup(str
) : NULL
;
1613 str
= conf_get_data("server/hostname", RECDB_QSTRING
);
1614 desc
= conf_get_data("server/description", RECDB_QSTRING
);
1615 if (!str
|| !desc
) {
1616 log_module(MAIN_LOG
, LOG_ERROR
, "No server/hostname entry in config file.");
1619 self
= AddServer(NULL
, str
, 0, boot_time
, now
, numer
, desc
);
1620 conf_register_reload(p10_conf_reload
);
1622 irc_func_dict
= dict_new();
1623 dict_insert(irc_func_dict
, CMD_BURST
, cmd_burst
);
1624 dict_insert(irc_func_dict
, TOK_BURST
, cmd_burst
);
1625 dict_insert(irc_func_dict
, CMD_CREATE
, cmd_create
);
1626 dict_insert(irc_func_dict
, TOK_CREATE
, cmd_create
);
1627 dict_insert(irc_func_dict
, CMD_EOB
, cmd_eob
);
1628 dict_insert(irc_func_dict
, TOK_EOB
, cmd_eob
);
1629 dict_insert(irc_func_dict
, CMD_EOB_ACK
, cmd_eob_ack
);
1630 dict_insert(irc_func_dict
, TOK_EOB_ACK
, cmd_eob_ack
);
1631 dict_insert(irc_func_dict
, CMD_MODE
, cmd_mode
);
1632 dict_insert(irc_func_dict
, TOK_MODE
, cmd_mode
);
1633 dict_insert(irc_func_dict
, CMD_NICK
, cmd_nick
);
1634 dict_insert(irc_func_dict
, TOK_NICK
, cmd_nick
);
1635 dict_insert(irc_func_dict
, CMD_ACCOUNT
, cmd_account
);
1636 dict_insert(irc_func_dict
, TOK_ACCOUNT
, cmd_account
);
1637 dict_insert(irc_func_dict
, CMD_FAKEHOST
, cmd_fakehost
);
1638 dict_insert(irc_func_dict
, TOK_FAKEHOST
, cmd_fakehost
);
1639 dict_insert(irc_func_dict
, CMD_PASS
, cmd_pass
);
1640 dict_insert(irc_func_dict
, TOK_PASS
, cmd_pass
);
1641 dict_insert(irc_func_dict
, CMD_PING
, cmd_ping
);
1642 dict_insert(irc_func_dict
, TOK_PING
, cmd_ping
);
1643 dict_insert(irc_func_dict
, CMD_PRIVMSG
, cmd_privmsg
);
1644 dict_insert(irc_func_dict
, TOK_PRIVMSG
, cmd_privmsg
);
1645 dict_insert(irc_func_dict
, CMD_PONG
, cmd_pong
);
1646 dict_insert(irc_func_dict
, TOK_PONG
, cmd_pong
);
1647 dict_insert(irc_func_dict
, CMD_QUIT
, cmd_quit
);
1648 dict_insert(irc_func_dict
, TOK_QUIT
, cmd_quit
);
1649 dict_insert(irc_func_dict
, CMD_SERVER
, cmd_server
);
1650 dict_insert(irc_func_dict
, TOK_SERVER
, cmd_server
);
1651 dict_insert(irc_func_dict
, CMD_JOIN
, cmd_join
);
1652 dict_insert(irc_func_dict
, TOK_JOIN
, cmd_join
);
1653 dict_insert(irc_func_dict
, CMD_PART
, cmd_part
);
1654 dict_insert(irc_func_dict
, TOK_PART
, cmd_part
);
1655 dict_insert(irc_func_dict
, CMD_ERROR
, cmd_error
);
1656 dict_insert(irc_func_dict
, TOK_ERROR
, cmd_error
);
1657 dict_insert(irc_func_dict
, CMD_TOPIC
, cmd_topic
);
1658 dict_insert(irc_func_dict
, TOK_TOPIC
, cmd_topic
);
1659 dict_insert(irc_func_dict
, CMD_AWAY
, cmd_away
);
1660 dict_insert(irc_func_dict
, TOK_AWAY
, cmd_away
);
1661 dict_insert(irc_func_dict
, CMD_SILENCE
, cmd_dummy
);
1662 dict_insert(irc_func_dict
, TOK_SILENCE
, cmd_dummy
);
1663 dict_insert(irc_func_dict
, CMD_KICK
, cmd_kick
);
1664 dict_insert(irc_func_dict
, TOK_KICK
, cmd_kick
);
1665 dict_insert(irc_func_dict
, CMD_SQUIT
, cmd_squit
);
1666 dict_insert(irc_func_dict
, TOK_SQUIT
, cmd_squit
);
1667 dict_insert(irc_func_dict
, CMD_KILL
, cmd_kill
);
1668 dict_insert(irc_func_dict
, TOK_KILL
, cmd_kill
);
1669 dict_insert(irc_func_dict
, CMD_NOTICE
, cmd_notice
);
1670 dict_insert(irc_func_dict
, TOK_NOTICE
, cmd_notice
);
1671 dict_insert(irc_func_dict
, CMD_STATS
, cmd_stats
);
1672 dict_insert(irc_func_dict
, TOK_STATS
, cmd_stats
);
1673 dict_insert(irc_func_dict
, CMD_SVSNICK
, cmd_svsnick
);
1674 dict_insert(irc_func_dict
, TOK_SVSNICK
, cmd_svsnick
);
1675 dict_insert(irc_func_dict
, CMD_WHOIS
, cmd_whois
);
1676 dict_insert(irc_func_dict
, TOK_WHOIS
, cmd_whois
);
1677 dict_insert(irc_func_dict
, CMD_GLINE
, cmd_gline
);
1678 dict_insert(irc_func_dict
, TOK_GLINE
, cmd_gline
);
1679 dict_insert(irc_func_dict
, CMD_OPMODE
, cmd_opmode
);
1680 dict_insert(irc_func_dict
, TOK_OPMODE
, cmd_opmode
);
1681 dict_insert(irc_func_dict
, CMD_CLEARMODE
, cmd_clearmode
);
1682 dict_insert(irc_func_dict
, TOK_CLEARMODE
, cmd_clearmode
);
1683 dict_insert(irc_func_dict
, CMD_VERSION
, cmd_version
);
1684 dict_insert(irc_func_dict
, TOK_VERSION
, cmd_version
);
1685 dict_insert(irc_func_dict
, CMD_ADMIN
, cmd_admin
);
1686 dict_insert(irc_func_dict
, TOK_ADMIN
, cmd_admin
);
1688 /* In P10, DESTRUCT doesn't do anything except be broadcast to servers.
1689 * Apparently to obliterate channels from any servers that think they
1692 dict_insert(irc_func_dict
, CMD_DESTRUCT
, cmd_dummy
);
1693 dict_insert(irc_func_dict
, TOK_DESTRUCT
, cmd_dummy
);
1694 /* Ignore invites */
1695 dict_insert(irc_func_dict
, CMD_INVITE
, cmd_dummy
);
1696 dict_insert(irc_func_dict
, TOK_INVITE
, cmd_dummy
);
1697 /* DESYNCH is just informational, so ignore it */
1698 dict_insert(irc_func_dict
, CMD_DESYNCH
, cmd_dummy
);
1699 dict_insert(irc_func_dict
, TOK_DESYNCH
, cmd_dummy
);
1700 /* Ignore channel operator notices. */
1701 dict_insert(irc_func_dict
, CMD_WALLCHOPS
, cmd_dummy
);
1702 dict_insert(irc_func_dict
, TOK_WALLCHOPS
, cmd_dummy
);
1703 dict_insert(irc_func_dict
, CMD_WALLVOICES
, cmd_dummy
);
1704 dict_insert(irc_func_dict
, TOK_WALLVOICES
, cmd_dummy
);
1705 dict_insert(irc_func_dict
, CMD_WALLHOPS
, cmd_dummy
);
1706 dict_insert(irc_func_dict
, TOK_WALLHOPS
, cmd_dummy
);
1707 /* Ignore opers being silly. */
1708 dict_insert(irc_func_dict
, CMD_WALLOPS
, cmd_dummy
);
1709 dict_insert(irc_func_dict
, TOK_WALLOPS
, cmd_dummy
);
1710 dict_insert(irc_func_dict
, CMD_WALLHOPS
, cmd_dummy
);
1711 dict_insert(irc_func_dict
, TOK_WALLHOPS
, cmd_dummy
);
1712 dict_insert(irc_func_dict
, TOK_WALLUSERS
, cmd_dummy
);
1713 /* Ignore dnsbl exemptions */
1714 dict_insert(irc_func_dict
, TOK_EXEMPT
, cmd_dummy
);
1715 dict_insert(irc_func_dict
, TOK_MARK
, cmd_dummy
);
1717 dict_insert(irc_func_dict
, TOK_PRIVS
, cmd_dummy
);
1718 /* We have reliable clock! Always! Wraaa! */
1719 dict_insert(irc_func_dict
, CMD_SETTIME
, cmd_dummy
);
1720 dict_insert(irc_func_dict
, TOK_SETTIME
, cmd_dummy
);
1722 dict_insert(irc_func_dict
, "331", cmd_num_topic
);
1723 dict_insert(irc_func_dict
, "332", cmd_num_topic
);
1724 dict_insert(irc_func_dict
, "333", cmd_num_topic
);
1725 dict_insert(irc_func_dict
, "345", cmd_dummy
); /* blah has been invited to blah */
1726 dict_insert(irc_func_dict
, "432", cmd_error_nick
); /* Erroneus [sic] nickname */
1727 /* ban list resetting */
1728 /* "stats g" responses */
1729 dict_insert(irc_func_dict
, "247", cmd_num_gline
);
1730 dict_insert(irc_func_dict
, "219", cmd_dummy
); /* "End of /STATS report" */
1731 /* other numeric responses we might get */
1732 dict_insert(irc_func_dict
, "401", cmd_dummy
); /* target left network */
1733 dict_insert(irc_func_dict
, "403", cmd_dummy
); /* no such channel */
1734 dict_insert(irc_func_dict
, "404", cmd_dummy
); /* cannot send to channel */
1735 dict_insert(irc_func_dict
, "439", cmd_dummy
); /* target change too fast */
1736 dict_insert(irc_func_dict
, "441", cmd_dummy
); /* target isn't on that channel */
1737 dict_insert(irc_func_dict
, "442", cmd_dummy
); /* you aren't on that channel */
1738 dict_insert(irc_func_dict
, "443", cmd_dummy
); /* is already on channel (after invite?) */
1739 dict_insert(irc_func_dict
, "461", cmd_dummy
); /* Not enough parameters (after TOPIC w/ 0 args) */
1740 dict_insert(irc_func_dict
, "467", cmd_dummy
); /* Channel key already set */
1742 num_privmsg_funcs
= 16;
1743 privmsg_funcs
= malloc(sizeof(privmsg_func_t
)*num_privmsg_funcs
);
1744 memset(privmsg_funcs
, 0, sizeof(privmsg_func_t
)*num_privmsg_funcs
);
1746 num_notice_funcs
= 16;
1747 notice_funcs
= malloc(sizeof(privmsg_func_t
)*num_notice_funcs
);
1748 memset(notice_funcs
, 0, sizeof(privmsg_func_t
)*num_notice_funcs
);
1750 userList_init(&dead_users
);
1751 reg_del_channel_func(remove_unbursted_channel
);
1752 reg_exit_func(parse_cleanup
);
1756 parse_line(char *line
, int recursive
)
1758 char *argv
[MAXNUMPARAMS
], *origin
;
1759 int argc
, cmd
, res
=0;
1762 argc
= split_line(line
, true, MAXNUMPARAMS
, argv
);
1763 cmd
= self
->uplink
|| !argv
[0][1] || !argv
[0][2];
1766 if (argv
[0][0] == ':') {
1768 } else if (!argv
[0][1] || !argv
[0][2]) {
1769 struct server
*sNode
= GetServerN(argv
[0]);
1770 origin
= sNode
? sNode
->name
: 0;
1772 struct userNode
*uNode
= GetUserN(argv
[0]);
1773 origin
= uNode
? uNode
->nick
: 0;
1777 if ((func
= dict_find(irc_func_dict
, argv
[cmd
], NULL
)))
1778 res
= func(origin
, argc
-cmd
, argv
+cmd
);
1781 log_module(MAIN_LOG
, LOG_ERROR
, "PARSE ERROR on line: %s", unsplit_string(argv
, argc
, NULL
));
1782 } else if (!recursive
) {
1784 for (i
=0; i
<dead_users
.used
; i
++)
1785 free_user(dead_users
.list
[i
]);
1786 dead_users
.used
= 0;
1792 parse_foreach(char *target_list
, foreach_chanfunc cf
, foreach_nonchan nc
, foreach_userfunc uf
, foreach_nonuser nu
, void *data
)
1797 while (*j
!= 0 && *j
!= ',')
1801 if (IsChannelName(target_list
)
1802 || (target_list
[0] == '0' && target_list
[1] == '\0')) {
1803 struct chanNode
*chan
= GetChannel(target_list
);
1809 nc(target_list
, data
);
1812 struct userNode
*user
;
1813 struct privmsg_desc
*pd
= data
;
1815 pd
->is_qualified
= 0;
1816 if (*target_list
== '@') {
1818 } else if (strchr(target_list
, '@')) {
1819 struct server
*server
;
1821 pd
->is_qualified
= 1;
1822 user
= GetUserH(strtok(target_list
, "@"));
1823 server
= GetServerH(strtok(NULL
, "@"));
1825 if (user
&& (user
->uplink
!= server
)) {
1826 /* Don't attempt to index into any arrays
1827 using a user's numeric on another server. */
1831 user
= GetUserN(target_list
);
1839 nu(target_list
, data
);
1843 } while (old
== ',');
1847 get_local_numeric(void)
1849 static unsigned int next_numeric
= 0;
1850 if (self
->clients
> self
->num_mask
)
1852 while (self
->users
[next_numeric
])
1853 if (++next_numeric
> self
->num_mask
)
1855 return next_numeric
;
1859 make_numeric(struct server
*svr
, int local_num
, char *outbuf
)
1863 if (force_n2k
|| svr
->numeric
[1]) {
1868 llen
= (local_num
< 64*64) ? 2 : 3;
1870 strncpy(outbuf
, svr
->numeric
, slen
);
1871 inttobase64(outbuf
+slen
, local_num
, llen
);
1872 outbuf
[slen
+llen
] = 0;
1876 AddServer(struct server
*uplink
, const char *name
, int hops
, time_t boot
, time_t link
, const char *numeric
, const char *description
)
1878 struct server
* sNode
;
1881 if ((sNode
= GetServerN(numeric
))) {
1882 /* This means we're trying to re-add an existant server.
1883 * To be safe, we should forget the previous incarnation.
1884 * (And all its linked servers.)
1886 * It usually only happens in replays when the original
1887 * had a ping timeout and the replay didn't (because
1888 * replaying a ping timeout invariably gets things wrong).
1890 DelServer(sNode
, 0, NULL
);
1893 switch (strlen(numeric
)) {
1894 case 5: slen
= 2; mlen
= 3; break;
1895 case 4: slen
= 1; mlen
= 3; break;
1896 case 3: slen
= 1; mlen
= 2; break;
1898 log_module(MAIN_LOG
, LOG_ERROR
, "AddServer(\"%s\", \"%s\", ...): Numeric %s has invalid length.", uplink
->name
, name
, numeric
);
1902 sNode
= calloc(1, sizeof(*sNode
));
1903 sNode
->uplink
= uplink
;
1904 safestrncpy(sNode
->name
, name
, sizeof(sNode
->name
));
1905 sNode
->num_mask
= base64toint(numeric
+slen
, mlen
);
1909 strncpy(sNode
->numeric
, numeric
, slen
);
1910 safestrncpy(sNode
->description
, description
, sizeof(sNode
->description
));
1911 sNode
->users
= calloc(sNode
->num_mask
+1, sizeof(*sNode
->users
));
1912 serverList_init(&sNode
->children
);
1913 if (sNode
->uplink
) {
1914 /* uplink may be NULL if we're just building ourself */
1915 serverList_append(&sNode
->uplink
->children
, sNode
);
1917 servers_num
[base64toint(numeric
, slen
)] = sNode
;
1918 dict_insert(servers
, sNode
->name
, sNode
);
1922 void DelServer(struct server
* serv
, int announce
, const char *message
)
1926 /* If we receive an ERROR command before the SERVER
1927 * command a NULL server can be passed */
1931 /* Hrm, what's the right way to SQUIT some other server?
1932 * (This code is only to handle killing juped servers.) */
1933 if (announce
&& (serv
->uplink
== self
) && (serv
!= self
->uplink
))
1934 irc_squit(serv
, message
, NULL
);
1936 /* must recursively remove servers linked to this one first */
1937 for (i
=serv
->children
.used
;i
>0;)
1938 if (serv
->children
.list
[--i
] != self
)
1939 DelServer(serv
->children
.list
[i
], false, NULL
);
1941 /* clean up server's user hash tables */
1942 for (i
=0;i
<=serv
->num_mask
;i
++)
1944 DelUser(serv
->users
[i
], NULL
, false, "server delinked");
1948 serverList_remove(&serv
->uplink
->children
, serv
);
1949 if (serv
== self
->uplink
)
1950 self
->uplink
= NULL
;
1951 servers_num
[base64toint(serv
->numeric
, strlen(serv
->numeric
))] = NULL
;
1952 dict_remove(servers
, serv
->name
);
1953 serverList_clean(&serv
->children
);
1959 AddService(const char *nick
, const char *modes
, const char *desc
, const char *hostname
)
1961 char numeric
[COMBO_NUMERIC_LEN
+1];
1962 int local_num
= get_local_numeric();
1963 time_t timestamp
= now
;
1964 struct userNode
*old_user
= GetUserH(nick
);
1967 if (IsLocal(old_user
))
1969 timestamp
= old_user
->timestamp
- 1;
1971 if (local_num
== -1) {
1972 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to allocate numnick for service %s", nick
);
1976 hostname
= self
->name
;
1977 make_numeric(self
, local_num
, numeric
);
1978 /* TODO: Make these modes part of the conf file */
1979 return AddUser(self
, nick
, nick
, hostname
, modes
? modes
: "+oik", numeric
, desc
, now
, "AAAAAA");
1983 AddClone(const char *nick
, const char *ident
, const char *hostname
, const char *desc
)
1985 char numeric
[COMBO_NUMERIC_LEN
+1];
1986 int local_num
= get_local_numeric();
1987 time_t timestamp
= now
;
1988 struct userNode
*old_user
= GetUserH(nick
);
1991 if (IsLocal(old_user
))
1993 timestamp
= old_user
->timestamp
- 1;
1995 if (local_num
== -1) {
1996 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to allocate numnick for clone %s", nick
);
1999 make_numeric(self
, local_num
, numeric
);
2000 return AddUser(self
, nick
, ident
, hostname
, "+i", numeric
, desc
, timestamp
, "AAAAAA");
2004 is_valid_nick(const char *nick
) {
2006 /* IRC has some of The Most Fucked-Up ideas about character sets
2008 if (!isalpha(*nick
) && !strchr("{|}~[\\]^_`", *nick
))
2010 for (ii
= 0; nick
[ii
]; ++ii
)
2011 if (!isalnum(nick
[ii
]) && !strchr("{|}~[\\]^-_`", nick
[ii
]))
2013 if (strlen(nick
) > nicklen
)
2018 static struct userNode
*
2019 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
)
2021 struct userNode
*oldUser
, *uNode
;
2022 unsigned int n
, ignore_user
;
2024 if ((strlen(numeric
) < 3) || (strlen(numeric
) > 5)) {
2025 log_module(MAIN_LOG
, LOG_WARNING
, "AddUser(%p, %s, ...): numeric %s wrong length!", uplink
, nick
, numeric
);
2030 log_module(MAIN_LOG
, LOG_WARNING
, "AddUser(%p, %s, ...): server for numeric %s doesn't exist!", uplink
, nick
, numeric
);
2034 if (uplink
!= GetServerN(numeric
)) {
2035 log_module(MAIN_LOG
, LOG_WARNING
, "AddUser(%p, %s, ...): server for numeric %s differs from nominal uplink %s.", uplink
, nick
, numeric
, uplink
->name
);
2039 if (!is_valid_nick(nick
)) {
2040 log_module(MAIN_LOG
, LOG_WARNING
, "AddUser(%p, %s, ...): invalid nickname detected.", uplink
, nick
);
2045 if ((oldUser
= GetUserH(nick
))) {
2046 if (IsLocal(oldUser
) && (IsService(oldUser
) || IsPersistent(oldUser
))) {
2047 /* The service should collide the new user off. */
2048 oldUser
->timestamp
= timestamp
- 1;
2051 if (oldUser
->timestamp
> timestamp
) {
2052 /* "Old" user is really newer; remove them */
2053 DelUser(oldUser
, 0, 1, "Overruled by older nick");
2055 /* User being added is too new; do not add them to
2056 * clients, but do add them to the server's list, since it
2057 * will send a KILL and QUIT soon. */
2062 /* create new usernode and set all values */
2063 uNode
= calloc(1, sizeof(*uNode
));
2064 uNode
->nick
= strdup(nick
);
2065 safestrncpy(uNode
->ident
, ident
, sizeof(uNode
->ident
));
2066 safestrncpy(uNode
->info
, userinfo
, sizeof(uNode
->info
));
2067 safestrncpy(uNode
->hostname
, hostname
, sizeof(uNode
->hostname
));
2068 safestrncpy(uNode
->numeric
, numeric
, sizeof(uNode
->numeric
));
2069 uNode
->ip
.s_addr
= htonl(base64toint(realip
, 6));
2070 uNode
->timestamp
= timestamp
;
2071 modeList_init(&uNode
->channels
);
2072 uNode
->uplink
= uplink
;
2073 if (++uNode
->uplink
->clients
> uNode
->uplink
->max_clients
) {
2074 uNode
->uplink
->max_clients
= uNode
->uplink
->clients
;
2076 uNode
->num_local
= base64toint(numeric
+strlen(uNode
->uplink
->numeric
), 3) & uNode
->uplink
->num_mask
;
2077 uNode
->uplink
->users
[uNode
->num_local
] = uNode
;
2078 mod_usermode(uNode
, modes
);
2082 dict_insert(clients
, uNode
->nick
, uNode
);
2083 if (dict_size(clients
) > max_clients
) {
2084 max_clients
= dict_size(clients
);
2085 max_clients_time
= now
;
2089 for (n
=0; n
<nuf_used
; n
++)
2090 if (nuf_list
[n
](uNode
))
2095 /* removes user from it's server's hash table and nick hash table */
2097 DelUser(struct userNode
* user
, struct userNode
*killer
, int announce
, const char *why
)
2103 /* mark them as dead, in case anybody cares */
2106 /* remove pending adduser commands */
2107 wipe_adduser_pending(NULL
, user
);
2109 /* remove user from all channels */
2110 while (user
->channels
.used
> 0)
2111 DelChannelUser(user
, user
->channels
.list
[user
->channels
.used
-1]->channel
, false, 0);
2113 /* Call these in reverse order so ChanServ can update presence
2114 information before NickServ nukes the handle_info. */
2115 for (n
= duf_used
; n
> 0; )
2116 duf_list
[--n
](user
, killer
, why
);
2118 user
->uplink
->clients
--;
2119 user
->uplink
->users
[user
->num_local
] = NULL
;
2121 userList_remove(&curr_opers
, user
);
2122 /* remove from global dictionary, but not if after a collide */
2123 if (user
== dict_find(clients
, user
->nick
, NULL
))
2124 dict_remove(clients
, user
->nick
);
2126 if (IsInvisible(user
))
2131 irc_quit(user
, why
);
2133 irc_kill(killer
, user
, why
);
2136 modeList_clean(&user
->channels
);
2137 /* We don't free them, in case we try to privmsg them or something
2138 * (like when a stupid oper kills themself). We just put them onto
2139 * a list of clients that get freed after processing each line.
2141 if (dead_users
.size
)
2142 userList_append(&dead_users
, user
);
2147 void mod_usermode(struct userNode
*user
, const char *mode_change
) {
2148 static void call_oper_funcs(struct userNode
*user
);
2150 const char *word
= mode_change
;
2152 if (!user
|| !mode_change
)
2154 while (*word
!= ' ' && *word
) word
++;
2155 while (*word
== ' ') word
++;
2157 #define do_user_mode(FLAG) do { if (add) user->modes |= FLAG; else user->modes &= ~FLAG; } while (0)
2158 switch (*mode_change
++) {
2159 case 0: case ' ': return;
2160 case '+': add
= 1; break;
2161 case '-': add
= 0; break;
2164 if(!IsOper(user
)) { /* Dont re-oper an oper */
2165 userList_append(&curr_opers
, user
);
2166 call_oper_funcs(user
);
2169 userList_remove(&curr_opers
, user
);
2171 do_user_mode(FLAGS_OPER
);
2173 case 'O': do_user_mode(FLAGS_LOCOP
); break;
2174 case 'i': do_user_mode(FLAGS_INVISIBLE
);
2180 case 'w': do_user_mode(FLAGS_WALLOP
); break;
2181 case 's': do_user_mode(FLAGS_SERVNOTICE
); break;
2182 case 'd': do_user_mode(FLAGS_DEAF
); break;
2183 case 'k': do_user_mode(FLAGS_SERVICE
); break;
2184 case 'g': do_user_mode(FLAGS_GLOBAL
); break;
2185 // sethost - reed/apples
2186 // case 'h': do_user_mode(FLAGS_HELPER); break;
2187 // I check if there's an 'h' in the first part, and if there,
2188 // then everything after the space becomes their new host.
2189 case 'h': do_user_mode(FLAGS_SETHOST
);
2191 char sethost
[MAXLEN
];
2193 for (ii
=0; (*word
!= ' ') && (*word
!= '\0'); )
2194 sethost
[ii
++] = *word
++;
2196 while (*word
== ' ')
2198 safestrncpy(user
->sethost
, sethost
, sizeof(user
->sethost
));
2201 case 'x': do_user_mode(FLAGS_HIDDEN_HOST
); break;
2206 for (ii
=0; (*word
!= ' ') && (*word
!= '\0'); )
2207 tag
[ii
++] = *word
++;
2209 while (*word
== ' ')
2211 call_account_func(user
, tag
);
2218 for (ii
=0; (*word
!= ' ') && (*word
!= '\0'); )
2219 host
[ii
++] = *word
++;
2221 while (*word
== ' ')
2223 assign_fakehost(user
, host
, 0);
2231 struct mod_chanmode
*
2232 mod_chanmode_parse(struct chanNode
*channel
, char **modes
, unsigned int argc
, unsigned int flags
)
2234 struct mod_chanmode
*change
;
2235 unsigned int ii
, in_arg
, ch_arg
, add
;
2239 if (!(change
= mod_chanmode_alloc(argc
- 1)))
2242 for (ii
= ch_arg
= 0, in_arg
= add
= 1;
2243 (modes
[0][ii
] != '\0') && (modes
[0][ii
] != ' ');
2245 switch (modes
[0][ii
]) {
2252 #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)
2253 case 'C': do_chan_mode(MODE_NOCTCPS
); break;
2254 case 'D': do_chan_mode(MODE_DELAYJOINS
); break;
2255 case 'c': do_chan_mode(MODE_NOCOLORS
); break;
2256 case 'i': do_chan_mode(MODE_INVITEONLY
); break;
2257 case 'm': do_chan_mode(MODE_MODERATED
); break;
2258 case 'n': do_chan_mode(MODE_NOPRIVMSGS
); break;
2259 case 'p': do_chan_mode(MODE_PRIVATE
); break;
2260 case 'r': do_chan_mode(MODE_REGONLY
); break;
2261 case 's': do_chan_mode(MODE_SECRET
); break;
2262 case 't': do_chan_mode(MODE_TOPICLIMIT
); break;
2263 case 'S': do_chan_mode(MODE_STRIPCOLOR
); break;
2264 case 'M': do_chan_mode(MODE_MODUNREG
); break;
2265 case 'N': do_chan_mode(MODE_NONOTICE
); break;
2266 case 'Q': do_chan_mode(MODE_NOQUITMSGS
); break;
2267 case 'T': do_chan_mode(MODE_NOAMSG
); break;
2268 case 'O': do_chan_mode(MODE_OPERSONLY
); break;
2269 case 'Z': do_chan_mode(MODE_SSLONLY
); break;
2270 case 'L': do_chan_mode(MODE_HIDEMODE
); break;
2272 if (!(flags
& MCP_REGISTERED
)) {
2273 do_chan_mode(MODE_REGISTERED
);
2275 mod_chanmode_free(change
);
2284 change
->modes_set
|= MODE_LIMIT
;
2285 change
->new_limit
= atoi(modes
[in_arg
++]);
2287 change
->modes_set
&= ~MODE_LIMIT
;
2288 change
->modes_clear
|= MODE_LIMIT
;
2295 change
->modes_set
|= MODE_KEY
;
2296 safestrncpy(change
->new_key
, modes
[in_arg
++], sizeof(change
->new_key
));
2298 change
->modes_clear
|= MODE_KEY
;
2299 if (!(flags
& MCP_KEY_FREE
)) {
2307 if (!(flags
& MCP_ALLOW_OVB
))
2311 change
->args
[ch_arg
].mode
= MODE_BAN
;
2313 change
->args
[ch_arg
].mode
|= MODE_REMOVE
;
2314 change
->args
[ch_arg
++].u
.hostmask
= modes
[in_arg
++];
2317 if (!(flags
& MCP_ALLOW_OVB
))
2321 change
->args
[ch_arg
].mode
= MODE_EXEMPT
;
2323 change
->args
[ch_arg
].mode
|= MODE_REMOVE
;
2324 change
->args
[ch_arg
++].u
.hostmask
= modes
[in_arg
++];
2326 case 'o': case 'h': case 'v':
2328 struct userNode
*victim
;
2329 if (!(flags
& MCP_ALLOW_OVB
))
2334 if (modes
[0][ii
] == 'o')
2335 change
->args
[ch_arg
].mode
= MODE_CHANOP
;
2336 else if (modes
[0][ii
] == 'h')
2337 change
->args
[ch_arg
].mode
= MODE_HALFOP
;
2338 else if (modes
[0][ii
] == 'v')
2339 change
->args
[ch_arg
].mode
= MODE_VOICE
;
2342 change
->args
[ch_arg
].mode
|= MODE_REMOVE
;
2343 if (flags
& MCP_FROM_SERVER
)
2344 victim
= GetUserN(modes
[in_arg
++]);
2346 victim
= GetUserH(modes
[in_arg
++]);
2349 if ((change
->args
[ch_arg
].u
.member
= GetUserMode(channel
, victim
)))
2354 if (!(flags
& MCP_FROM_SERVER
))
2359 change
->argc
= ch_arg
; /* in case any turned out to be ignored */
2360 if (change
->modes_set
& MODE_SECRET
) {
2361 change
->modes_set
&= ~(MODE_PRIVATE
);
2362 change
->modes_clear
|= MODE_PRIVATE
;
2363 } else if (change
->modes_set
& MODE_PRIVATE
) {
2364 change
->modes_set
&= ~(MODE_SECRET
);
2365 change
->modes_clear
|= MODE_SECRET
;
2369 mod_chanmode_free(change
);
2373 struct chanmode_buffer
{
2376 struct chanNode
*channel
;
2377 struct userNode
*actor
;
2378 unsigned int modes_used
;
2379 unsigned int args_used
;
2381 unsigned int is_add
: 1;
2382 unsigned int is_chanop
: 1;
2386 mod_chanmode_append(struct chanmode_buffer
*buf
, char ch
, const char *arg
)
2388 size_t arg_len
= strlen(arg
);
2389 if (buf
->modes_used
> (MAXMODEPARAMS
) ||
2390 buf
->modes_used
+ buf
->args_used
+ buf
->chname_len
+ arg_len
> 450) {
2391 memcpy(buf
->modes
+ buf
->modes_used
, buf
->args
, buf
->args_used
);
2392 buf
->modes
[buf
->modes_used
+ buf
->args_used
] = '\0';
2393 irc_mode((buf
->is_chanop
? buf
->actor
: NULL
), buf
->channel
, buf
->modes
);
2394 buf
->modes
[0] = buf
->is_add
? '+' : '-';
2395 buf
->modes_used
= 1;
2398 buf
->modes
[buf
->modes_used
++] = ch
;
2399 buf
->args
[buf
->args_used
++] = ' ';
2400 memcpy(buf
->args
+ buf
->args_used
, arg
, arg_len
);
2401 buf
->args_used
+= arg_len
;
2405 mod_chanmode_announce(struct userNode
*who
, struct chanNode
*channel
, struct mod_chanmode
*change
)
2407 struct chanmode_buffer chbuf
;
2409 struct modeNode
*mn
;
2410 char int_buff
[32], mode
= '\0';
2412 assert(change
->argc
<= change
->alloc_argc
);
2413 memset(&chbuf
, 0, sizeof(chbuf
));
2414 chbuf
.channel
= channel
;
2416 chbuf
.chname_len
= strlen(channel
->name
);
2418 mn
= GetUserMode(channel
, who
);
2419 if ((mn
&& (mn
->modes
& MODE_CHANOP
)) || off_channel
)
2420 chbuf
.is_chanop
= 1;
2422 /* First remove modes */
2424 if (change
->modes_clear
) {
2426 chbuf
.modes
[chbuf
.modes_used
++] = mode
= '-';
2427 #define DO_MODE_CHAR(BIT, CHAR) if (change->modes_clear & MODE_##BIT) chbuf.modes[chbuf.modes_used++] = CHAR
2428 DO_MODE_CHAR(PRIVATE
, 'p');
2429 DO_MODE_CHAR(SECRET
, 's');
2430 DO_MODE_CHAR(MODERATED
, 'm');
2431 DO_MODE_CHAR(TOPICLIMIT
, 't');
2432 DO_MODE_CHAR(INVITEONLY
, 'i');
2433 DO_MODE_CHAR(NOPRIVMSGS
, 'n');
2434 DO_MODE_CHAR(LIMIT
, 'l');
2435 DO_MODE_CHAR(DELAYJOINS
, 'D');
2436 DO_MODE_CHAR(REGONLY
, 'r');
2437 DO_MODE_CHAR(NOCOLORS
, 'c');
2438 DO_MODE_CHAR(NOCTCPS
, 'C');
2439 DO_MODE_CHAR(STRIPCOLOR
, 'S');
2440 DO_MODE_CHAR(MODUNREG
, 'M');
2441 DO_MODE_CHAR(NONOTICE
, 'N');
2442 DO_MODE_CHAR(NOQUITMSGS
, 'Q');
2443 DO_MODE_CHAR(NOAMSG
, 'T');
2444 DO_MODE_CHAR(OPERSONLY
, 'O');
2445 DO_MODE_CHAR(REGISTERED
, 'z');
2446 DO_MODE_CHAR(SSLONLY
, 'Z');
2447 DO_MODE_CHAR(HIDEMODE
, 'L');
2449 if (change
->modes_clear
& channel
->modes
& MODE_KEY
)
2450 mod_chanmode_append(&chbuf
, 'k', channel
->key
);
2452 for (arg
= 0; arg
< change
->argc
; ++arg
) {
2453 if (!(change
->args
[arg
].mode
& MODE_REMOVE
))
2456 chbuf
.modes
[chbuf
.modes_used
++] = mode
= '-';
2457 switch (change
->args
[arg
].mode
& ~MODE_REMOVE
) {
2459 mod_chanmode_append(&chbuf
, 'b', change
->args
[arg
].u
.hostmask
);
2462 mod_chanmode_append(&chbuf
, 'e', change
->args
[arg
].u
.hostmask
);
2465 if (change
->args
[arg
].mode
& MODE_CHANOP
)
2466 mod_chanmode_append(&chbuf
, 'o', change
->args
[arg
].u
.member
->user
->numeric
);
2467 if (change
->args
[arg
].mode
& MODE_HALFOP
)
2468 mod_chanmode_append(&chbuf
, 'h', change
->args
[arg
].u
.member
->user
->numeric
);
2469 if (change
->args
[arg
].mode
& MODE_VOICE
)
2470 mod_chanmode_append(&chbuf
, 'v', change
->args
[arg
].u
.member
->user
->numeric
);
2477 if (change
->modes_set
) {
2479 chbuf
.modes
[chbuf
.modes_used
++] = mode
= '+';
2480 #define DO_MODE_CHAR(BIT, CHAR) if (change->modes_set & MODE_##BIT) chbuf.modes[chbuf.modes_used++] = CHAR
2481 DO_MODE_CHAR(PRIVATE
, 'p');
2482 DO_MODE_CHAR(SECRET
, 's');
2483 DO_MODE_CHAR(MODERATED
, 'm');
2484 DO_MODE_CHAR(TOPICLIMIT
, 't');
2485 DO_MODE_CHAR(INVITEONLY
, 'i');
2486 DO_MODE_CHAR(NOPRIVMSGS
, 'n');
2487 DO_MODE_CHAR(DELAYJOINS
, 'D');
2488 DO_MODE_CHAR(REGONLY
, 'r');
2489 DO_MODE_CHAR(NOCOLORS
, 'c');
2490 DO_MODE_CHAR(NOCTCPS
, 'C');
2491 DO_MODE_CHAR(STRIPCOLOR
, 'S');
2492 DO_MODE_CHAR(MODUNREG
, 'M');
2493 DO_MODE_CHAR(NONOTICE
, 'N');
2494 DO_MODE_CHAR(NOQUITMSGS
, 'Q');
2495 DO_MODE_CHAR(NOAMSG
, 'T');
2496 DO_MODE_CHAR(OPERSONLY
, 'O');
2497 DO_MODE_CHAR(REGISTERED
, 'z');
2498 DO_MODE_CHAR(SSLONLY
, 'Z');
2499 DO_MODE_CHAR(HIDEMODE
, 'L');
2501 if(change
->modes_set
& MODE_KEY
)
2502 mod_chanmode_append(&chbuf
, 'k', change
->new_key
);
2503 if(change
->modes_set
& MODE_LIMIT
) {
2504 sprintf(int_buff
, "%d", change
->new_limit
);
2505 mod_chanmode_append(&chbuf
, 'l', int_buff
);
2508 for (arg
= 0; arg
< change
->argc
; ++arg
) {
2509 if (change
->args
[arg
].mode
& MODE_REMOVE
)
2512 chbuf
.modes
[chbuf
.modes_used
++] = mode
= '+';
2513 switch (change
->args
[arg
].mode
) {
2515 mod_chanmode_append(&chbuf
, 'b', change
->args
[arg
].u
.hostmask
);
2518 mod_chanmode_append(&chbuf
, 'e', change
->args
[arg
].u
.hostmask
);
2521 if (change
->args
[arg
].mode
& MODE_CHANOP
)
2522 mod_chanmode_append(&chbuf
, 'o', change
->args
[arg
].u
.member
->user
->numeric
);
2523 if (change
->args
[arg
].mode
& MODE_HALFOP
)
2524 mod_chanmode_append(&chbuf
, 'h', change
->args
[arg
].u
.member
->user
->numeric
);
2525 if (change
->args
[arg
].mode
& MODE_VOICE
)
2526 mod_chanmode_append(&chbuf
, 'v', change
->args
[arg
].u
.member
->user
->numeric
);
2531 /* Flush the buffer and apply changes locally */
2532 if (chbuf
.modes_used
> 0) {
2533 memcpy(chbuf
.modes
+ chbuf
.modes_used
, chbuf
.args
, chbuf
.args_used
);
2534 chbuf
.modes
[chbuf
.modes_used
+ chbuf
.args_used
] = '\0';
2535 irc_mode((chbuf
.is_chanop
? chbuf
.actor
: NULL
), chbuf
.channel
, chbuf
.modes
);
2537 mod_chanmode_apply(who
, channel
, change
);
2541 mod_chanmode_format(struct mod_chanmode
*change
, char *outbuff
)
2543 unsigned int used
= 0;
2544 assert(change
->argc
<= change
->alloc_argc
);
2545 if (change
->modes_clear
) {
2546 outbuff
[used
++] = '-';
2547 #define DO_MODE_CHAR(BIT, CHAR) if (change->modes_clear & MODE_##BIT) outbuff[used++] = CHAR
2548 DO_MODE_CHAR(PRIVATE
, 'p');
2549 DO_MODE_CHAR(SECRET
, 's');
2550 DO_MODE_CHAR(MODERATED
, 'm');
2551 DO_MODE_CHAR(TOPICLIMIT
, 't');
2552 DO_MODE_CHAR(INVITEONLY
, 'i');
2553 DO_MODE_CHAR(NOPRIVMSGS
, 'n');
2554 DO_MODE_CHAR(LIMIT
, 'l');
2555 DO_MODE_CHAR(KEY
, 'k');
2556 DO_MODE_CHAR(DELAYJOINS
, 'D');
2557 DO_MODE_CHAR(REGONLY
, 'r');
2558 DO_MODE_CHAR(NOCOLORS
, 'c');
2559 DO_MODE_CHAR(NOCTCPS
, 'C');
2560 DO_MODE_CHAR(STRIPCOLOR
, 'S');
2561 DO_MODE_CHAR(MODUNREG
, 'M');
2562 DO_MODE_CHAR(NONOTICE
, 'N');
2563 DO_MODE_CHAR(NOQUITMSGS
, 'Q');
2564 DO_MODE_CHAR(NOAMSG
, 'T');
2565 DO_MODE_CHAR(OPERSONLY
, 'O');
2566 DO_MODE_CHAR(REGISTERED
, 'z');
2567 DO_MODE_CHAR(SSLONLY
, 'Z');
2568 DO_MODE_CHAR(HIDEMODE
, 'L');
2571 if (change
->modes_set
) {
2572 outbuff
[used
++] = '+';
2573 #define DO_MODE_CHAR(BIT, CHAR) if (change->modes_set & MODE_##BIT) outbuff[used++] = CHAR
2574 DO_MODE_CHAR(PRIVATE
, 'p');
2575 DO_MODE_CHAR(SECRET
, 's');
2576 DO_MODE_CHAR(MODERATED
, 'm');
2577 DO_MODE_CHAR(TOPICLIMIT
, 't');
2578 DO_MODE_CHAR(INVITEONLY
, 'i');
2579 DO_MODE_CHAR(NOPRIVMSGS
, 'n');
2580 DO_MODE_CHAR(DELAYJOINS
, 'D');
2581 DO_MODE_CHAR(REGONLY
, 'r');
2582 DO_MODE_CHAR(NOCOLORS
, 'c');
2583 DO_MODE_CHAR(NOCTCPS
, 'C');
2584 DO_MODE_CHAR(STRIPCOLOR
, 'S');
2585 DO_MODE_CHAR(MODUNREG
, 'M');
2586 DO_MODE_CHAR(NONOTICE
, 'N');
2587 DO_MODE_CHAR(NOQUITMSGS
, 'Q');
2588 DO_MODE_CHAR(NOAMSG
, 'T');
2589 DO_MODE_CHAR(OPERSONLY
, 'O');
2590 DO_MODE_CHAR(REGISTERED
, 'z');
2591 DO_MODE_CHAR(SSLONLY
, 'Z');
2592 DO_MODE_CHAR(HIDEMODE
, 'L');
2594 switch (change
->modes_set
& (MODE_KEY
|MODE_LIMIT
)) {
2595 case MODE_KEY
|MODE_LIMIT
:
2596 used
+= sprintf(outbuff
+used
, "lk %d %s", change
->new_limit
, change
->new_key
);
2599 used
+= sprintf(outbuff
+used
, "k %s", change
->new_key
);
2602 used
+= sprintf(outbuff
+used
, "l %d", change
->new_limit
);
2611 clear_chanmode(struct chanNode
*channel
, const char *modes
)
2613 unsigned int remove
;
2615 for (remove
= 0; *modes
; modes
++) {
2617 case 'o': remove
|= MODE_CHANOP
; break;
2618 case 'h': remove
|= MODE_HALFOP
; break;
2619 case 'v': remove
|= MODE_VOICE
; break;
2620 case 'p': remove
|= MODE_PRIVATE
; break;
2621 case 's': remove
|= MODE_SECRET
; break;
2622 case 'm': remove
|= MODE_MODERATED
; break;
2623 case 't': remove
|= MODE_TOPICLIMIT
; break;
2624 case 'i': remove
|= MODE_INVITEONLY
; break;
2625 case 'n': remove
|= MODE_NOPRIVMSGS
; break;
2628 channel
->key
[0] = '\0';
2631 remove
|= MODE_LIMIT
;
2634 case 'b': remove
|= MODE_BAN
; break;
2635 case 'e': remove
|= MODE_EXEMPT
; break;
2636 case 'D': remove
|= MODE_DELAYJOINS
; break;
2637 case 'r': remove
|= MODE_REGONLY
; break;
2638 case 'c': remove
|= MODE_NOCOLORS
; break;
2639 case 'C': remove
|= MODE_NOCTCPS
; break;
2640 case 'S': remove
|= MODE_STRIPCOLOR
; break;
2641 case 'M': remove
|= MODE_MODUNREG
; break;
2642 case 'N': remove
|= MODE_NONOTICE
; break;
2643 case 'Q': remove
|= MODE_NOQUITMSGS
; break;
2644 case 'T': remove
|= MODE_NOAMSG
; break;
2645 case 'O': remove
|= MODE_OPERSONLY
; break;
2646 case 'z': remove
|= MODE_REGISTERED
; break;
2647 case 'Z': remove
|= MODE_SSLONLY
; break;
2648 case 'L': remove
|= MODE_HIDEMODE
; break;
2655 /* Remove simple modes. */
2656 channel
->modes
&= ~remove
;
2658 /* If removing bans, kill 'em all. */
2659 if ((remove
& MODE_BAN
) && channel
->banlist
.used
) {
2661 for (i
=0; i
<channel
->banlist
.used
; i
++)
2662 free(channel
->banlist
.list
[i
]);
2663 channel
->banlist
.used
= 0;
2666 /* If removing exempts, kill 'em all. */
2667 if ((remove
& MODE_EXEMPT
) && channel
->exemptlist
.used
) {
2669 for (i
=0; i
<channel
->exemptlist
.used
; i
++)
2670 free(channel
->exemptlist
.list
[i
]);
2671 channel
->exemptlist
.used
= 0;
2674 /* Remove member modes. */
2675 if ((remove
& (MODE_CHANOP
| MODE_HALFOP
| MODE_VOICE
)) && channel
->members
.used
) {
2676 int mask
= ~(remove
& (MODE_CHANOP
| MODE_HALFOP
| MODE_VOICE
));
2679 for (i
= 0; i
< channel
->members
.used
; i
++)
2680 channel
->members
.list
[i
]->modes
&= mask
;
2687 reg_privmsg_func(struct userNode
*user
, privmsg_func_t handler
)
2689 unsigned int numeric
= user
->num_local
;
2690 if (numeric
>= num_privmsg_funcs
) {
2691 int newnum
= numeric
+ 8;
2692 privmsg_funcs
= realloc(privmsg_funcs
, newnum
*sizeof(privmsg_func_t
));
2693 memset(privmsg_funcs
+num_privmsg_funcs
, 0, (newnum
-num_privmsg_funcs
)*sizeof(privmsg_func_t
));
2694 num_privmsg_funcs
= newnum
;
2696 if (privmsg_funcs
[numeric
])
2697 log_module(MAIN_LOG
, LOG_WARNING
, "re-registering new privmsg handler for numeric %d", numeric
);
2698 privmsg_funcs
[numeric
] = handler
;
2702 unreg_privmsg_func(struct userNode
*user
, privmsg_func_t handler
)
2706 if (!user
|| handler
)
2707 return; /* this really only works with users */
2709 memset(privmsg_funcs
+user
->num_local
, 0, sizeof(privmsg_func_t
));
2711 for (x
= user
->num_local
+1; x
< num_privmsg_funcs
; x
++)
2712 memmove(privmsg_funcs
+x
-1, privmsg_funcs
+x
, sizeof(privmsg_func_t
));
2714 privmsg_funcs
= realloc(privmsg_funcs
, num_privmsg_funcs
*sizeof(privmsg_func_t
));
2715 num_privmsg_funcs
--;
2720 reg_notice_func(struct userNode
*user
, privmsg_func_t handler
)
2722 unsigned int numeric
= user
->num_local
;
2723 if (numeric
>= num_notice_funcs
) {
2724 int newnum
= numeric
+ 8;
2725 notice_funcs
= realloc(notice_funcs
, newnum
*sizeof(privmsg_func_t
));
2726 memset(notice_funcs
+num_notice_funcs
, 0, (newnum
-num_notice_funcs
)*sizeof(privmsg_func_t
));
2727 num_notice_funcs
= newnum
;
2729 if (notice_funcs
[numeric
])
2730 log_module(MAIN_LOG
, LOG_WARNING
, "re-registering new notice handler for numeric %d", numeric
);
2731 notice_funcs
[numeric
] = handler
;
2735 unreg_notice_func(struct userNode
*user
, privmsg_func_t handler
)
2739 if (!user
|| handler
)
2740 return; /* this really only works with users */
2742 memset(notice_funcs
+user
->num_local
, 0, sizeof(privmsg_func_t
));
2744 for (x
= user
->num_local
+1; x
< num_notice_funcs
; x
++)
2745 memmove(notice_funcs
+x
-1, notice_funcs
+x
, sizeof(privmsg_func_t
));
2747 memset(notice_funcs
+user
->num_local
, 0, sizeof(privmsg_func_t
));
2748 notice_funcs
= realloc(notice_funcs
, num_notice_funcs
*sizeof(privmsg_func_t
));
2753 reg_oper_func(oper_func_t handler
)
2755 if (of_used
== of_size
) {
2758 of_list
= realloc(of_list
, of_size
*sizeof(oper_func_t
));
2761 of_list
= malloc(of_size
*sizeof(oper_func_t
));
2764 of_list
[of_used
++] = handler
;
2768 call_oper_funcs(struct userNode
*user
)
2773 for (n
=0; n
<of_used
; n
++)
2780 unsigned int i
, hop
, max_hop
=1;
2783 /* burst (juped) servers, closest first (except self, which is sent already) */
2784 for (i
=0; i
<ArrayLength(servers_num
); i
++)
2785 if (servers_num
[i
] && servers_num
[i
]->hops
> max_hop
)
2786 max_hop
= servers_num
[i
]->hops
;
2787 for (hop
=1; hop
<=max_hop
; hop
++) {
2788 for (i
=0;i
<ArrayLength(servers_num
);i
++) {
2790 && (servers_num
[i
]->hops
== hop
)
2791 && (servers_num
[i
] != self
->uplink
))
2792 irc_server(servers_num
[i
]);
2796 /* burst local nicks */
2797 for (i
=0; i
<=self
->num_mask
; i
++)
2799 irc_user(self
->users
[i
]);
2801 /* build dict of unbursted channel names (just copy existing channels) */
2802 unbursted_channels
= dict_new();
2803 for (it
= dict_first(channels
); it
; it
= iter_next(it
))
2804 dict_insert(unbursted_channels
, iter_key(it
), iter_data(it
));