]>
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_FAKEHOST "FA"
129 #define TOK_GET "GET"
130 #define TOK_GLINE "GL"
131 #define TOK_HASH "HASH"
132 #define TOK_HELP "HELP"
134 #define TOK_INVITE "I"
135 #define TOK_ISON "ISON"
137 #define TOK_JUPE "JU"
140 #define TOK_LINKS "LI"
141 #define TOK_LIST "LIST"
142 #define TOK_LUSERS "LU"
143 #define TOK_MAP "MAP"
144 #define TOK_MARK "MK"
146 #define TOK_MOTD "MO"
147 #define TOK_NAMES "E"
149 #define TOK_NOTICE "O"
150 #define TOK_OPER "OPER"
151 #define TOK_OPMODE "OM"
153 #define TOK_PASS "PA"
156 #define TOK_POST "POST"
157 #define TOK_PRIVMSG "P"
158 #define TOK_PRIVS "PRIVS"
159 #define TOK_PROTO "PROTO"
161 #define TOK_REHASH "REHASH"
162 #define TOK_RESET "RESET"
163 #define TOK_RESTART "RESTART"
164 #define TOK_RPING "RI"
165 #define TOK_RPONG "RO"
166 #define TOK_SERVER "S"
167 #define TOK_SERVLIST "SERVSET"
168 #define TOK_SERVSET "SERVSET"
169 #define TOK_SET "SET"
170 #define TOK_SETTIME "SE"
171 #define TOK_SILENCE "U"
172 #define TOK_SQUERY "SQUERY"
173 #define TOK_SQUIT "SQ"
174 #define TOK_STATS "R"
175 #define TOK_SVSNICK "SN"
176 #define TOK_TIME "TI"
177 #define TOK_TOPIC "T"
178 #define TOK_TRACE "TR"
179 #define TOK_UPING "UP"
180 #define TOK_USER "USER"
181 #define TOK_USERHOST "USERHOST"
182 #define TOK_USERIP "USERIP"
183 #define TOK_VERSION "V"
184 #define TOK_WALLCHOPS "WC"
185 #define TOK_WALLOPS "WA"
186 #define TOK_WALLHOPS "WH"
187 #define TOK_WALLUSERS "WU"
188 #define TOK_WALLVOICES "WV"
189 #define TOK_WALLHOPS "WH"
191 #define TOK_WHOIS "W"
192 #define TOK_WHOWAS "X"
194 /* Protocol messages; aliased to full commands or tokens depending
195 on compile-time configuration. ircu prefers tokens WITH THE
196 EXCEPTION OF THE SERVER AND PASS COMMANDS, which cannot be
197 tokenized, because clients' (ie. a linking server) commands are
198 only checked against the full command list.
200 #if defined(ENABLE_TOKENS)
201 #define TYPE(NAME) TOK_ ## NAME
202 #else /* !ENABLE_TOKENS */
203 #define TYPE(NAME) CMD_ ## NAME
204 #endif /* ENABLE_TOKENS */
206 #define P10_ACCOUNT TYPE(ACCOUNT)
207 #define P10_ADMIN TYPE(ADMIN)
208 #define P10_ASLL TYPE(ASLL)
209 #define P10_AWAY TYPE(AWAY)
210 #define P10_BURST TYPE(BURST)
211 #define P10_CLEARMODE TYPE(CLEARMODE)
212 #define P10_CLOSE TYPE(CLOSE)
213 #define P10_CNOTICE TYPE(CNOTICE)
214 #define P10_CONNECT TYPE(CONNECT)
215 #define P10_CPRIVMSG TYPE(CPRIVMSG)
216 #define P10_CREATE TYPE(CREATE)
217 #define P10_DESTRUCT TYPE(DESTRUCT)
218 #define P10_DESYNCH TYPE(DESYNCH)
219 #define P10_DIE TYPE(DIE)
220 #define P10_DNS TYPE(DNS)
221 #define P10_EOB TYPE(EOB)
222 #define P10_EOB_ACK TYPE(EOB_ACK)
223 #define P10_ERROR TYPE(ERROR)
224 #define P10_FAKEHOST TYPE(FAKEHOST)
225 #define P10_GET TYPE(GET)
226 #define P10_GLINE TYPE(GLINE)
227 #define P10_HASH TYPE(HASH)
228 #define P10_HELP TYPE(HELP)
229 #define P10_INFO TYPE(INFO)
230 #define P10_INVITE TYPE(INVITE)
231 #define P10_ISON TYPE(ISON)
232 #define P10_JOIN TYPE(JOIN)
233 #define P10_JUPE TYPE(JUPE)
234 #define P10_KICK TYPE(KICK)
235 #define P10_KILL TYPE(KILL)
236 #define P10_LINKS TYPE(LINKS)
237 #define P10_LIST TYPE(LIST)
238 #define P10_LUSERS TYPE(LUSERS)
239 #define P10_MAP TYPE(MAP)
240 #define P10_MARK TYPE(MARK)
241 #define P10_MODE TYPE(MODE)
242 #define P10_MOTD TYPE(MOTD)
243 #define P10_NAMES TYPE(NAMES)
244 #define P10_NICK TYPE(NICK)
245 #define P10_NOTICE TYPE(NOTICE)
246 #define P10_OPER TYPE(OPER)
247 #define P10_OPMODE TYPE(OPMODE)
248 #define P10_PART TYPE(PART)
249 #define P10_PASS CMD_PASS
250 #define P10_PING TYPE(PING)
251 #define P10_PONG TYPE(PONG)
252 #define P10_POST TYPE(POST)
253 #define P10_PRIVMSG TYPE(PRIVMSG)
254 #define P10_PRIVS TYPE(PRIVS)
255 #define P10_PROTO TYPE(PROTO)
256 #define P10_QUIT TYPE(QUIT)
257 #define P10_REHASH TYPE(REHASH)
258 #define P10_RESET TYPE(RESET)
259 #define P10_RESTART TYPE(RESTART)
260 #define P10_RPING TYPE(RPING)
261 #define P10_RPONG TYPE(RPONG)
262 #define P10_SERVER CMD_SERVER
263 #define P10_SERVLIST TYPE(SERVLIST)
264 #define P10_SERVSET TYPE(SERVSET)
265 #define P10_SET TYPE(SET)
266 #define P10_SETTIME TYPE(SETTIME)
267 #define P10_SILENCE TYPE(SILENCE)
268 #define P10_SQUERY TYPE(SQUERY)
269 #define P10_SQUIT TYPE(SQUIT)
270 #define P10_STATS TYPE(STATS)
271 #define P10_SVSNICK TYPE(SVSNICK)
272 #define P10_TIME TYPE(TIME)
273 #define P10_TOPIC TYPE(TOPIC)
274 #define P10_TRACE TYPE(TRACE)
275 #define P10_UPING TYPE(UPING)
276 #define P10_USER TYPE(USER)
277 #define P10_USERHOST TYPE(USERHOST)
278 #define P10_USERIP TYPE(USERIP)
279 #define P10_VERSION TYPE(VERSION)
280 #define P10_WALLCHOPS TYPE(WALLCHOPS)
281 #define P10_WALLOPS TYPE(WALLOPS)
282 #define P10_WALLHOPS TYPE(WALLHOPS)
283 #define P10_WALLUSERS TYPE(WALLUSERS)
284 #define P10_WALLVOICES TYPE(WALLVOICES)
285 #define P10_WHO TYPE(WHO)
286 #define P10_WHOIS TYPE(WHOIS)
287 #define P10_WHOWAS TYPE(WHOWAS)
289 /* Servers claiming to have a boot or link time before PREHISTORY
290 * trigger errors to the log. We hope no server has been running
291 * constantly since September 1994. :)
293 #define PREHISTORY 780000000
295 static struct server
*servers_num
[64*64];
296 static privmsg_func_t
*privmsg_funcs
;
297 static unsigned int num_privmsg_funcs
;
298 static privmsg_func_t
*notice_funcs
;
299 static unsigned int num_notice_funcs
;
300 static struct dict
*unbursted_channels
;
301 static char *his_servername
;
302 static char *his_servercomment
;
304 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
);
306 extern int off_channel
;
308 /* Numerics can be XYY, XYYY, or XXYYY; with X's identifying the
309 * server and Y's indentifying the client on that server. */
311 GetServerN(const char *numeric
)
313 switch (strlen(numeric
)) {
315 return servers_num
[base64toint(numeric
, 2)];
319 return servers_num
[base64toint(numeric
, 1)];
326 GetUserN(const char *numeric
) /* using numeric */
332 switch (strlen(numeric
)) {
334 log_module(MAIN_LOG
, LOG_WARNING
, "GetUserN(%s): numeric too long!", numeric
);
336 case 5: slen
= 2; ulen
= 3; break;
337 case 4: slen
= 1; ulen
= 3; break;
338 case 3: slen
= 1; ulen
= 2; break;
339 case 2: case 1: case 0:
340 log_module(MAIN_LOG
, LOG_WARNING
, "GetUserN(%s): numeric too short!", numeric
);
343 if (!(s
= servers_num
[base64toint(numeric
, slen
)])) {
344 log_module(MAIN_LOG
, LOG_WARNING
, "GetUserN(%s): couldn't find server (len=%d)!", numeric
, slen
);
347 n
= base64toint(numeric
+slen
, ulen
) & s
->num_mask
;
348 if (!(un
= s
->users
[n
])) {
349 log_module(MAIN_LOG
, LOG_WARNING
, "GetUserN(%s) couldn't find user!", numeric
);
355 privmsg_user_helper(struct userNode
*un
, void *data
)
357 struct privmsg_desc
*pd
= data
;
358 unsigned int num
= un
->num_local
;
359 if (!pd
->is_notice
) {
360 if ((num
< num_privmsg_funcs
) && privmsg_funcs
[num
]) {
361 privmsg_funcs
[num
](pd
->user
, un
, pd
->text
, pd
->is_qualified
);
364 if ((num
< num_notice_funcs
) && notice_funcs
[num
]) {
365 notice_funcs
[num
](pd
->user
, un
, pd
->text
, pd
->is_qualified
);
371 irc_server(struct server
*srv
)
373 char extranum
[COMBO_NUMERIC_LEN
+1];
375 inttobase64(extranum
, srv
->num_mask
, (srv
->numeric
[1] || (srv
->num_mask
>= 64*64)) ? 3 : 2);
377 /* The +s, ignored by Run's ircu, means "service" to Undernet's ircu */
378 putsock(P10_SERVER
" %s %d %li %li J10 %s%s +s :%s",
379 srv
->name
, srv
->hops
+1, srv
->boot
, srv
->link
, srv
->numeric
, extranum
, srv
->description
);
381 putsock("%s " P10_SERVER
" %s %d %li %li %c10 %s%s +s :%s",
382 self
->numeric
, srv
->name
, srv
->hops
+1, srv
->boot
, srv
->link
, (srv
->self_burst
? 'J' : 'P'), srv
->numeric
, extranum
, srv
->description
);
387 irc_user(struct userNode
*user
)
392 inttobase64(b64ip
, ntohl(user
->ip
.s_addr
), 6);
399 modes
[modelen
++] = 'o';
400 if (IsInvisible(user
))
401 modes
[modelen
++] = 'i';
403 modes
[modelen
++] = 'w';
405 modes
[modelen
++] = 'k';
406 if (IsServNotice(user
))
407 modes
[modelen
++] = 's';
409 modes
[modelen
++] = 'd';
411 modes
[modelen
++] = 'g';
412 // sethost - reed/apples
413 // if (IsHelperIrcu(user))
415 modes
[modelen
++] = 'h';
416 if (IsFakeHost(user
))
417 modes
[modelen
++] = 'f';
418 if (IsHiddenHost(user
))
419 modes
[modelen
++] = 'x';
422 /* we don't need to put the + in modes because it's in the format string. */
423 putsock("%s " P10_NICK
" %s %d %li %s %s +%s %s %s :%s",
424 user
->uplink
->numeric
, user
->nick
, user
->uplink
->hops
+1, user
->timestamp
, user
->ident
, user
->hostname
, modes
, b64ip
, user
->numeric
, user
->info
);
426 putsock("%s " P10_NICK
" %s %d %li %s %s %s %s :%s",
427 user
->uplink
->numeric
, user
->nick
, user
->uplink
->hops
+1, user
->timestamp
, user
->ident
, user
->hostname
, b64ip
, user
->numeric
, user
->info
);
432 irc_account(struct userNode
*user
, const char *stamp
, time_t timestamp
)
434 putsock("%s " P10_ACCOUNT
" %s R %s %lu", self
->numeric
, user
->numeric
, stamp
, timestamp
);
438 irc_fakehost(struct userNode
*user
, const char *host
)
440 putsock("%s " P10_FAKEHOST
" %s %s", self
->numeric
, user
->numeric
, host
);
444 irc_regnick(UNUSED_ARG(struct userNode
*user
))
446 /* no operation here */
450 irc_nick(struct userNode
*user
, UNUSED_ARG(const char *old_nick
))
452 putsock("%s " P10_NICK
" %s "FMT_TIME_T
, user
->numeric
, user
->nick
, now
);
456 irc_fetchtopic(struct userNode
*from
, const char *to
)
460 putsock("%s " P10_TOPIC
" %s", from
->numeric
, to
);
464 irc_squit(struct server
*srv
, const char *message
, const char *service_message
)
466 if (!service_message
)
467 service_message
= message
;
469 /* Are we leaving the network? */
470 if (srv
== self
&& cManager
.uplink
->state
== CONNECTED
) {
473 /* Quit all clients linked to me. */
474 for (i
= 0; i
<= self
->num_mask
; i
++) {
477 irc_quit(self
->users
[i
], service_message
);
481 putsock("%s " P10_SQUIT
" %s %d :%s", self
->numeric
, srv
->name
, 0, message
);
484 /* Force a reconnect to the currently selected server. */
485 cManager
.uplink
->tries
= 0;
486 log_module(MAIN_LOG
, LOG_INFO
, "Squitting from uplink: %s", message
);
492 irc_wallchops(struct userNode
*from
, const char *to
, const char *message
)
494 putsock("%s " P10_WALLCHOPS
" %s :%s", from
->numeric
, to
, message
);
498 irc_notice(struct userNode
*from
, const char *to
, const char *message
)
500 putsock("%s " P10_NOTICE
" %s :%s", from
->numeric
, to
, message
);
504 irc_notice_user(struct userNode
*from
, struct userNode
*to
, const char *message
)
506 putsock("%s " P10_NOTICE
" %s :%s", from
->numeric
, to
->numeric
, message
);
510 irc_privmsg(struct userNode
*from
, const char *to
, const char *message
)
512 putsock("%s " P10_PRIVMSG
" %s :%s", from
->numeric
, to
, message
);
518 putsock("%s " P10_EOB
, self
->numeric
);
524 putsock("%s " P10_EOB_ACK
, self
->numeric
);
528 irc_ping(const char *payload
)
530 putsock("%s " P10_PING
" :%s", self
->numeric
, payload
);
534 irc_pong(const char *who
, const char *data
)
536 putsock("%s " P10_PONG
" %s :%s", self
->numeric
, who
, data
);
540 irc_pass(const char *passwd
)
542 putsock(P10_PASS
" :%s", passwd
);
546 irc_introduce(const char *passwd
)
548 void timed_send_ping(void *data
);
550 self
->self_burst
= self
->burst
= 1;
554 timeq_add(now
+ ping_freq
, timed_send_ping
, 0);
558 irc_gline(struct server
*srv
, struct gline
*gline
)
560 putsock("%s " P10_GLINE
" %s +%s %ld :<%s> %s",
561 self
->numeric
, (srv
? srv
->numeric
: "*"), gline
->target
, gline
->expires
-now
, gline
->issuer
, gline
->reason
);
565 irc_settime(const char *srv_name_mask
, time_t new_time
)
567 ioset_set_time(new_time
);
568 if (!strcmp(srv_name_mask
, "*"))
570 putsock("%s " P10_SETTIME
" " FMT_TIME_T
" %s", self
->numeric
, new_time
, srv_name_mask
);
574 irc_ungline(const char *mask
)
576 putsock("%s " P10_GLINE
" * -%s", self
->numeric
, mask
);
580 irc_burst(struct chanNode
*chan
)
582 char burst_line
[512];
583 int pos
, base_len
, len
;
586 struct exemptNode
*en
;
590 base_len
= sprintf(burst_line
, "%s " P10_BURST
" %s " FMT_TIME_T
" ",
591 self
->numeric
, chan
->name
, chan
->timestamp
);
592 len
= irc_make_chanmode(chan
, burst_line
+base_len
);
593 pos
= base_len
+ len
;
595 burst_line
[pos
++] = ' ';
598 for (n
=0; n
<chan
->members
.used
; n
++) {
599 mn
= chan
->members
.list
[n
];
601 burst_line
[pos
-1] = 0; /* -1 to back up over the space or comma */
602 putsock("%s", burst_line
);
606 memcpy(burst_line
+pos
, mn
->user
->numeric
, strlen(mn
->user
->numeric
));
607 pos
+= strlen(mn
->user
->numeric
);
608 if (mn
->modes
&& (mn
->modes
!= last_mode
)) {
609 last_mode
= mn
->modes
;
610 burst_line
[pos
++] = ':';
611 if (last_mode
& MODE_CHANOP
)
612 burst_line
[pos
++] = 'o';
613 if (last_mode
& MODE_HALFOP
)
614 burst_line
[pos
++] = 'h';
615 if (last_mode
& MODE_VOICE
)
616 burst_line
[pos
++] = 'v';
618 if ((n
+1)<chan
->members
.used
)
619 burst_line
[pos
++] = ',';
621 if (chan
->banlist
.used
) {
623 if (pos
+2+strlen(chan
->banlist
.list
[0]->ban
) > 505) {
624 burst_line
[pos
-1] = 0;
625 putsock("%s", burst_line
);
628 burst_line
[pos
++] = ' ';
631 burst_line
[pos
++] = ':';
632 burst_line
[pos
++] = '%';
634 for (n
=0; n
<chan
->banlist
.used
; n
++) {
635 bn
= chan
->banlist
.list
[n
];
636 len
= strlen(bn
->ban
);
637 if (pos
+len
+1 > 510) {
638 burst_line
[pos
-1] = 0; /* -1 to back up over the space or comma */
639 putsock("%s", burst_line
);
642 memcpy(burst_line
+pos
, bn
->ban
, len
);
644 burst_line
[pos
++] = ' ';
647 if (chan
->exemptlist
.used
) {
648 /* dump the exempt */
649 if (pos
+2+strlen(chan
->exemptlist
.list
[0]->exempt
) > 505) {
650 burst_line
[pos
-1] = 0;
651 putsock("%s", burst_line
);
654 burst_line
[pos
++] = ' ';
657 burst_line
[pos
++] = ' ';
658 burst_line
[pos
++] = '~';
659 burst_line
[pos
++] = ' ';
661 for (n
=0; n
<chan
->exemptlist
.used
; n
++) {
662 en
= chan
->exemptlist
.list
[n
];
663 len
= strlen(en
->exempt
);
664 if (pos
+len
+1 > 510) {
665 burst_line
[pos
-1] = 0; /* -1 to back up over the space or comma */
666 putsock("%s", burst_line
);
669 memcpy(burst_line
+pos
, en
->exempt
, len
);
671 burst_line
[pos
++] = ' ';
674 /* print the last line */
676 putsock("%s", burst_line
);
680 irc_quit(struct userNode
*user
, const char *message
)
682 putsock("%s " P10_QUIT
" :%s", user
->numeric
, message
);
686 irc_error(const char *to
, const char *message
)
689 putsock("%s " P10_ERROR
" :%s", to
, message
);
691 putsock(":%s " P10_ERROR
" :%s", self
->name
, message
);
696 irc_kill(struct userNode
*from
, struct userNode
*target
, const char *message
)
699 putsock("%s " P10_KILL
" %s :%s!%s (%s)",
700 from
->numeric
, target
->numeric
, self
->name
, from
->nick
, message
);
702 putsock("%s " P10_KILL
" %s :%s (%s)",
703 self
->numeric
, target
->numeric
, self
->name
, message
);
708 irc_mode(struct userNode
*from
, struct chanNode
*target
, const char *modes
)
710 putsock("%s " P10_MODE
" %s %s "FMT_TIME_T
,
711 (from
? from
->numeric
: self
->numeric
),
712 target
->name
, modes
, target
->timestamp
);
716 irc_invite(struct userNode
*from
, struct userNode
*who
, struct chanNode
*to
)
718 putsock("%s " P10_INVITE
" %s %s", from
->numeric
, who
->nick
, to
->name
);
722 irc_join(struct userNode
*who
, struct chanNode
*what
)
724 if (what
->members
.used
== 1) {
725 putsock("%s " P10_CREATE
" %s %lu",
726 who
->numeric
, what
->name
, what
->timestamp
);
728 putsock("%s " P10_JOIN
" %s %lu", who
->numeric
, what
->name
, what
->timestamp
);
733 irc_kick(struct userNode
*who
, struct userNode
*target
, struct chanNode
*channel
, const char *msg
)
736 struct modeNode
*mn
= GetUserMode(channel
, who
);
737 numeric
= ((mn
&& (mn
->modes
& MODE_CHANOP
)) || off_channel
) ? who
->numeric
: self
->numeric
;
738 putsock("%s " P10_KICK
" %s %s :%s",
739 numeric
, channel
->name
, target
->numeric
, msg
);
743 irc_stats(struct userNode
*from
, struct server
*target
, char type
)
745 putsock("%s " P10_STATS
" %c :%s", from
->numeric
, type
, target
->numeric
);
749 irc_svsnick(struct userNode
*from
, struct userNode
*target
, const char *newnick
)
751 putsock("%s " P10_SVSNICK
" %s %s "FMT_TIME_T
, from
->uplink
->numeric
, target
->numeric
, newnick
, now
);
755 irc_part(struct userNode
*who
, struct chanNode
*what
, const char *reason
)
758 putsock("%s " P10_PART
" %s :%s", who
->numeric
, what
->name
, reason
);
760 putsock("%s " P10_PART
" %s", who
->numeric
, what
->name
);
765 irc_topic(struct userNode
*who
, struct chanNode
*what
, const char *topic
)
767 putsock("%s " P10_TOPIC
" %s :%s", who
->numeric
, what
->name
, topic
);
771 irc_raw(const char *what
)
777 irc_numeric(struct userNode
*user
, unsigned int num
, const char *format
, ...)
781 va_start(arg_list
, format
);
782 vsnprintf(buffer
, MAXLEN
-2, format
, arg_list
);
783 buffer
[MAXLEN
-1] = 0;
784 putsock(":%s %03d %s %s", self
->name
, num
, user
->nick
, buffer
);
787 static void send_burst(void);
790 change_nicklen(int new_nicklen
)
793 char new_nick
[NICKLEN
+1];
794 struct userNode
*user
;
796 nicklen
= new_nicklen
;
797 /* fix up any users we have here */
798 for (nn
=0; nn
<=self
->num_mask
; nn
++) {
799 if (!(user
= self
->users
[nn
]))
801 safestrncpy(new_nick
, user
->nick
, sizeof(new_nick
));
802 new_nick
[nicklen
] = 0;
803 NickChange(user
, new_nick
, 1);
807 static CMD_FUNC(cmd_whois
)
809 struct userNode
*from
;
810 struct userNode
*who
;
814 if (!(from
= GetUserH(origin
))) {
815 log_module(MAIN_LOG
, LOG_ERROR
, "Could not find WHOIS origin user %s", origin
);
818 if(!(who
= GetUserH(argv
[2]))) {
819 irc_numeric(from
, ERR_NOSUCHNICK
, "%s@%s :No such nick", argv
[2], self
->name
);
822 if (IsHiddenHost(who
) && !IsOper(from
)) {
823 /* Just stay quiet. */
826 irc_numeric(from
, RPL_WHOISUSER
, "%s %s %s * :%s", who
->nick
, who
->ident
, who
->hostname
, who
->info
);
827 if (his_servername
&& his_servercomment
)
828 irc_numeric(from
, RPL_WHOISSERVER
, "%s %s :%s", who
->nick
, his_servername
, his_servercomment
);
830 irc_numeric(from
, RPL_WHOISSERVER
, "%s %s :%s", who
->nick
, who
->uplink
->name
, who
->uplink
->description
);
832 irc_numeric(from
, RPL_WHOISOPERATOR
, "%s :is a megalomaniacal power hungry tyrant", who
->nick
);
833 irc_numeric(from
, RPL_ENDOFWHOIS
, "%s :End of /WHOIS list", who
->nick
);
837 static CMD_FUNC(cmd_server
)
845 /* another server introduced us */
846 srv
= AddServer(GetServerH(origin
), argv
[1], atoi(argv
[2]), atoi(argv
[3]), atoi(argv
[4]), argv
[6], argv
[argc
-1]);
849 srv
->self_burst
= argv
[5][0] == 'J';
852 /* this must be our uplink */
853 srv
= self
->uplink
= AddServer(self
, argv
[1], atoi(argv
[2]), atoi(argv
[3]), atoi(argv
[4]), argv
[6], argv
[argc
-1]);
856 srv
->self_burst
= argv
[5][0] == 'J';
858 if ((argv
[7][0] == '+') && !force_n2k
) {
859 log_module(MAIN_LOG
, LOG_WARNING
, "Got Undernet-style SERVER message but \"force_n2k\" not on.");
864 /* Fix up our timestamps if necessary. */
865 if (srv
->boot
<= PREHISTORY
) {
866 /* Server from the mists of time.. */
867 if (srv
->hops
== 1) {
868 log_module(MAIN_LOG
, LOG_ERROR
, "Server %s claims to have booted at time "FMT_TIME_T
". This is absurd.", srv
->name
, srv
->boot
);
870 } else if ((str
= conf_get_data("server/reliable_clock", RECDB_QSTRING
))
871 && enabled_string(str
)) {
872 /* If we have a reliable clock, we just keep our current time. */
874 if (srv
->boot
<= self
->boot
) {
875 /* The other server is older than us. Accept their timestamp.
876 * Alternately, we are same age, but we accept their time
877 * since we are linking to them. */
878 self
->boot
= srv
->boot
;
879 ioset_set_time(srv
->link
);
882 if (srv
== self
->uplink
) {
883 extern time_t burst_begin
;
889 static CMD_FUNC(cmd_eob
)
891 struct server
*sender
;
895 if (!(sender
= GetServerH(origin
)))
897 if (sender
== self
->uplink
) {
898 cManager
.uplink
->state
= CONNECTED
;
899 for (it
= dict_first(unbursted_channels
); it
; it
= iter_next(it
))
900 irc_burst(iter_data(it
));
901 dict_delete(unbursted_channels
);
902 unbursted_channels
= NULL
;
906 sender
->self_burst
= 0;
907 recalc_bursts(sender
);
908 for (ii
=0; ii
<slf_used
; ii
++)
909 slf_list
[ii
](sender
);
913 static CMD_FUNC(cmd_eob_ack
)
915 extern time_t burst_begin
;
917 if (GetServerH(origin
) == self
->uplink
) {
918 burst_length
= now
- burst_begin
;
919 self
->self_burst
= self
->burst
= 0;
921 cManager
.uplink
->state
= CONNECTED
;
925 static CMD_FUNC(cmd_ping
)
931 irc_pong(argv
[2], argv
[1]);
932 else if ((srv
= GetServerH(origin
)))
933 irc_pong(self
->name
, srv
->numeric
);
934 else if ((un
= GetUserH(origin
)))
935 irc_pong(self
->name
, un
->numeric
);
937 irc_pong(self
->name
, origin
);
939 timeq_del(0, timed_send_ping
, 0, TIMEQ_IGNORE_WHEN
|TIMEQ_IGNORE_DATA
);
940 timeq_del(0, timed_ping_timeout
, 0, TIMEQ_IGNORE_WHEN
|TIMEQ_IGNORE_DATA
);
941 timeq_add(now
+ ping_freq
, timed_send_ping
, 0);
946 static CMD_FUNC(cmd_error_nick
)
948 /* Go back to original IRC length .. and try to reconnect :/ */
950 irc_squit(self
, "Got erroneous nickname, truncating nicks.", NULL
);
955 struct userNode
*user
;
960 join_helper(struct chanNode
*chan
, void *data
)
962 struct create_desc
*cd
= data
;
963 AddChannelUser(cd
->user
, chan
);
967 create_helper(char *name
, void *data
)
969 struct create_desc
*cd
= data
;
971 if (!strcmp(name
, "0")) {
972 while (cd
->user
->channels
.used
> 0)
973 DelChannelUser(cd
->user
, cd
->user
->channels
.list
[0]->channel
, 0, 0);
977 AddChannelUser(cd
->user
, AddChannel(name
, cd
->when
, NULL
, NULL
, NULL
));
980 static CMD_FUNC(cmd_create
)
982 struct create_desc cd
;
983 struct userNode
*user
;
985 if ((argc
< 3) || !(user
= GetUserH(origin
)))
988 cd
.when
= atoi(argv
[2]);
989 parse_foreach(argv
[1], join_helper
, create_helper
, NULL
, NULL
, &cd
);
993 static CMD_FUNC(cmd_join
)
995 struct create_desc cd
;
997 if (!(cd
.user
= GetUserH(origin
)))
1004 cd
.when
= atoi(argv
[2]);
1005 parse_foreach(argv
[1], join_helper
, create_helper
, NULL
, NULL
, &cd
);
1009 static CMD_FUNC(cmd_pong
)
1013 if (!strcmp(argv
[2], self
->name
)) {
1014 timeq_del(0, timed_send_ping
, 0, TIMEQ_IGNORE_WHEN
|TIMEQ_IGNORE_DATA
);
1015 timeq_del(0, timed_ping_timeout
, 0, TIMEQ_IGNORE_WHEN
|TIMEQ_IGNORE_DATA
);
1016 timeq_add(now
+ ping_freq
, timed_send_ping
, 0);
1022 static CMD_FUNC(cmd_nick
)
1024 struct userNode
*user
;
1025 if ((user
= GetUserH(origin
))) {
1026 /* nick change (since the source is a user numeric) */
1029 NickChange(user
, argv
[1], 1);
1031 struct server
*serv
;
1036 serv
= GetServerH(origin
);
1038 unsplit_string(argv
+6, argc
-9, modes
);
1041 AddUser(serv
, argv
[1], argv
[4], argv
[5], modes
, argv
[argc
-2], argv
[argc
-1], atoi(argv
[3]), argv
[argc
-3]);
1046 static CMD_FUNC(cmd_account
)
1048 struct userNode
*user
;
1049 struct server
*server
;
1050 struct handle_info
*hi
;
1052 if ((argc
< 3) || !origin
|| !(server
= GetServerH(origin
)))
1053 return 0; /* Origin must be server. */
1055 /* This next line appears to tremple origin.. why? */
1056 user
= GetUserN(argv
[1]);
1058 return 1; /* A QUIT probably passed the ACCOUNT. */
1060 if(!strcmp(argv
[2],"C"))
1062 if((hi
= loc_auth(argv
[4], argv
[5])))
1065 putsock("%s " P10_ACCOUNT
" %s A %s %lu", self
->numeric
, server
->numeric
, argv
[3], hi
->registered
);
1071 putsock("%s " P10_ACCOUNT
" %s D %s", self
->numeric
, server
->numeric
, argv
[3]);
1075 else if(!strcmp(argv
[2],"R"))
1076 call_account_func(user
, argv
[3]);
1078 call_account_func(user
, argv
[2]); /* For backward compatability */
1082 static CMD_FUNC(cmd_fakehost
)
1084 struct userNode
*user
;
1086 if ((argc
< 3) || !origin
|| !GetServerH(origin
))
1088 if (!(user
= GetUserN(argv
[1])))
1090 assign_fakehost(user
, argv
[2], 0);
1094 static CMD_FUNC(cmd_burst
)
1097 char modes
[MAXLEN
], *members
= "";
1098 static char exemptlist
[MAXLEN
], banlist
[MAXLEN
];
1099 unsigned int next
= 3, res
= 1;
1100 int ctype
= 0, echeck
= 0, bcheck
= 0;
1101 struct chanNode
*cNode
;
1102 struct userNode
*un
;
1103 struct modeNode
*mNode
;
1105 char *user
, *end
, sep
;
1106 time_t in_timestamp
;
1116 while (next
< argc
) {
1117 switch (argv
[next
][0]) {
1121 for (pos
=argv
[next
], n_modes
= 1; *pos
; pos
++)
1122 if ((*pos
== 'k') || (*pos
== 'l'))
1124 unsplit_string(argv
+next
, n_modes
, modes
);
1129 for(parm
= mysep(&argv
[next
], " "); /* parm = first param */
1130 parm
; /* While param is not null */
1131 parm
= mysep(&argv
[next
], " ") /* parm = next param */
1149 /* strip % char off start of very first ban */
1150 if (strlen(parm
) > 1) {
1151 strncat(banlist
, strtok(parm
, "%"), sizeof(banlist
) - 1 - strlen(banlist
));
1152 strncat(banlist
, " ", sizeof(banlist
) - 1 - strlen(banlist
));
1156 strncat(banlist
, parm
, sizeof(banlist
) - 1 - strlen(banlist
));
1157 strncat(banlist
, " ", sizeof(banlist
) - 1 - strlen(banlist
));
1159 } else if (ctype
== 2) {
1163 strncat(exemptlist
, parm
, sizeof(exemptlist
) - 1 - strlen(exemptlist
));
1164 strncat(exemptlist
, " ", sizeof(exemptlist
) - 1 - strlen(exemptlist
));
1171 default: members
= argv
[next
++]; break;
1175 in_timestamp
= atoi(argv
[2]);
1176 if ((cNode
= dict_find(unbursted_channels
, argv
[1], NULL
))) {
1177 cNode
->timestamp
= in_timestamp
;
1178 dict_remove(unbursted_channels
, cNode
->name
);
1181 cNode
= AddChannel(argv
[1], in_timestamp
, modes
, banlist
, exemptlist
);
1183 /* Burst channel members in now. */
1184 for (user
= members
, sep
= *members
, mode
= 0; sep
; user
= end
) {
1185 for (end
= user
+ 3; isalnum(*end
) || *end
== '[' || *end
== ']'; end
++) ;
1186 sep
= *end
++; end
[-1] = 0;
1189 while ((sep
= *end
++)) {
1191 mode
|= MODE_CHANOP
;
1192 else if (sep
== 'h')
1193 mode
|= MODE_HALFOP
;
1194 else if (sep
== 'v')
1196 else if (isdigit(sep
)) {
1197 mode
|= MODE_CHANOP
;
1198 while (isdigit(*end
)) end
++;
1205 if (!(un
= GetUserN(user
))) {
1209 if ((mNode
= AddChannelUser(un
, cNode
)))
1210 mNode
->modes
= mode
;
1216 static CMD_FUNC(cmd_mode
)
1218 struct chanNode
*cn
;
1219 struct userNode
*un
;
1220 char *sethost
; // sethost - reed/apples
1221 int i
; // sethost - reed/apples
1225 if (!IsChannelName(argv
[1])) {
1226 un
= GetUserH(argv
[1]);
1228 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to find user %s whose mode is changing.", argv
[1]);
1231 // sethost - reed/apples
1233 mod_usermode(un
, argv
[2]);
1235 sethost
= malloc(strlen(argv
[2]) + 1 + strlen(argv
[3]) + 1);
1237 while((sethost
[i
++] = *argv
[2]++));
1240 while((sethost
[i
++] = *argv
[3]++));
1241 mod_usermode(un
, sethost
); // sethost - reed/apples
1247 if (!(cn
= GetChannel(argv
[1]))) {
1248 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to find channel %s whose mode is changing.", argv
[1]);
1251 if ((un
= GetUserH(origin
))) {
1252 struct modeNode
*mn
;
1253 /* Update idle time for person setting the mode */
1254 if ((mn
= GetUserMode(cn
, un
)))
1255 mn
->idle_since
= now
;
1257 /* If it came from a server, reset timestamp to re-sync. */
1258 cn
->timestamp
= atoi(argv
[argc
-1]);
1261 return mod_chanmode(un
, cn
, argv
+2, argc
-2, MCP_ALLOW_OVB
|MCP_FROM_SERVER
|(un
? MC_NOTIFY
: 0));
1264 static CMD_FUNC(cmd_opmode
)
1266 struct chanNode
*cn
;
1267 struct userNode
*un
;
1272 if (!(cn
= GetChannel(argv
[1]))) {
1273 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to find channel %s whose mode is changing.", argv
[1]);
1276 if (!(un
= GetUserH(origin
))) {
1277 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to find user %s requesting OPMODE.", origin
);
1281 log_module(MAIN_LOG
, LOG_ERROR
, "Non-privileged user %s using OPMODE.", un
->nick
);
1285 return mod_chanmode(un
, cn
, argv
+2, argc
-2, MCP_ALLOW_OVB
|MCP_FROM_SERVER
); /* do NOT announce opmode locally */
1288 static int clear_chanmode(struct chanNode
*channel
, const char *modes
);
1290 static CMD_FUNC(cmd_clearmode
)
1292 struct chanNode
*cn
;
1293 struct userNode
*un
;
1298 if (!(cn
= GetChannel(argv
[1]))) {
1299 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to find channel %s whose mode is changing.", argv
[1]);
1302 if (!(un
= GetUserH(origin
))) {
1303 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to find user %s requesting CLEARMODE.", origin
);
1307 log_module(MAIN_LOG
, LOG_ERROR
, "Non-privileged user %s using CLEARMODE.", un
->nick
);
1311 return clear_chanmode(cn
, argv
[2]);
1314 static CMD_FUNC(cmd_topic
)
1316 struct chanNode
*cn
;
1317 time_t chan_ts
, topic_ts
;
1321 if (!(cn
= GetChannel(argv
[1]))) {
1322 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to find channel %s whose topic is being set", argv
[1]);
1326 /* Looks like an Asuka style topic burst. */
1327 chan_ts
= atoi(argv
[2]);
1328 topic_ts
= atoi(argv
[3]);
1330 chan_ts
= cn
->timestamp
;
1333 SetChannelTopic(cn
, GetUserH(origin
), argv
[argc
-1], 0);
1334 cn
->topic_time
= topic_ts
;
1338 static CMD_FUNC(cmd_num_topic
)
1340 struct chanNode
*cn
;
1343 return 0; /* huh? */
1345 cn
= GetChannel(argv
[2]);
1347 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to find channel %s in topic reply", argv
[2]);
1353 switch (atoi(argv
[0])) {
1356 break; /* no topic */
1360 safestrncpy(cn
->topic
, unsplit_string(argv
+3, argc
-3, NULL
), sizeof(cn
->topic
));
1365 safestrncpy(cn
->topic_nick
, argv
[3], sizeof(cn
->topic_nick
));
1366 cn
->topic_time
= atoi(argv
[4]);
1369 return 0; /* should never happen */
1374 static CMD_FUNC(cmd_num_gline
)
1378 gline_add(origin
, argv
[3], atoi(argv
[4])-now
, argv
[5], now
, 0);
1382 static CMD_FUNC(cmd_quit
)
1384 struct userNode
*user
;
1387 /* Sometimes we get a KILL then a QUIT or the like, so we don't want to
1388 * call DelUser unless we have the user in our grasp. */
1389 if ((user
= GetUserH(origin
)))
1390 DelUser(user
, NULL
, false, argv
[1]);
1394 static CMD_FUNC(cmd_kill
)
1396 struct userNode
*user
;
1399 user
= GetUserN(argv
[1]);
1401 /* If we get a KILL for a non-existent user, it could be a
1402 * Ghost response to a KILL we sent out earlier. So we only
1403 * whine if the target is local.
1405 if (!strncmp(argv
[1], self
->numeric
, strlen(self
->numeric
)))
1406 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to find kill victim %s", argv
[1]);
1410 if (IsLocal(user
) && IsService(user
)) {
1411 /* TODO: rate limit this so silly things don't happen. */
1412 ReintroduceUser(user
);
1416 DelUser(user
, NULL
, false, argv
[2]);
1420 static CMD_FUNC(cmd_part
)
1422 struct userNode
*user
;
1426 user
= GetUserH(origin
);
1429 parse_foreach(argv
[1], part_helper
, NULL
, NULL
, NULL
, user
);
1433 static CMD_FUNC(cmd_kick
)
1437 ChannelUserKicked(GetUserH(origin
), GetUserN(argv
[2]), GetChannel(argv
[1]));
1441 static CMD_FUNC(cmd_squit
)
1443 struct server
*server
;
1447 if (!(server
= GetServerH(argv
[1])))
1450 if (server
== self
->uplink
) {
1451 /* Force a reconnect to the currently selected server. */
1452 cManager
.uplink
->tries
= 0;
1453 log_module(MAIN_LOG
, LOG_INFO
, "Squitting from uplink: %s", argv
[3]);
1458 DelServer(server
, 0, argv
[3]);
1462 static CMD_FUNC(cmd_privmsg
)
1464 struct privmsg_desc pd
;
1467 pd
.user
= GetUserH(origin
);
1468 if (!pd
.user
|| (IsGagged(pd
.user
) && !IsOper(pd
.user
)))
1472 parse_foreach(argv
[1], privmsg_chan_helper
, NULL
, privmsg_user_helper
, privmsg_invalid
, &pd
);
1476 static CMD_FUNC(cmd_notice
)
1478 struct privmsg_desc pd
;
1481 pd
.user
= GetUserH(origin
);
1482 if (!pd
.user
|| (IsGagged(pd
.user
) && !IsOper(pd
.user
)))
1486 parse_foreach(argv
[1], privmsg_chan_helper
, NULL
, privmsg_user_helper
, privmsg_invalid
, &pd
);
1490 static CMD_FUNC(cmd_away
)
1492 struct userNode
*uNode
;
1494 uNode
= GetUserH(origin
);
1498 uNode
->modes
&= ~FLAGS_AWAY
;
1500 uNode
->modes
|= FLAGS_AWAY
;
1504 static CMD_FUNC(cmd_gline
)
1508 if (argv
[2][0] == '+') {
1511 gline_add(origin
, argv
[2]+1, strtoul(argv
[3], NULL
, 0), argv
[argc
-1], now
, 0);
1513 } else if (argv
[2][0] == '-') {
1514 gline_remove(argv
[2]+1, 0);
1520 static CMD_FUNC(cmd_svsnick
)
1522 struct userNode
*target
, *dest
;
1524 || !(target
= GetUserN(argv
[1]))
1526 || (dest
= GetUserH(argv
[2])))
1528 NickChange(target
, argv
[2], 0);
1532 static oper_func_t
*of_list
;
1533 static unsigned int of_size
= 0, of_used
= 0;
1536 free_user(struct userNode
*user
)
1547 free(privmsg_funcs
);
1550 dict_delete(irc_func_dict
);
1551 for (nn
=0; nn
<dead_users
.used
; nn
++)
1552 free_user(dead_users
.list
[nn
]);
1553 userList_clean(&dead_users
);
1557 p10_conf_reload(void) {
1558 hidden_host_suffix
= conf_get_data("server/hidden_host", RECDB_QSTRING
);
1562 remove_unbursted_channel(struct chanNode
*cNode
) {
1563 if (unbursted_channels
)
1564 dict_remove(unbursted_channels
, cNode
->name
);
1570 const char *str
, *desc
;
1571 int numnick
, usermask
, max_users
;
1572 char numer
[COMBO_NUMERIC_LEN
+1];
1574 /* read config items */
1575 str
= conf_get_data("server/ping_freq", RECDB_QSTRING
);
1576 ping_freq
= str
? ParseInterval(str
) : 120;
1577 str
= conf_get_data("server/ping_timeout", RECDB_QSTRING
);
1578 ping_timeout
= str
? ParseInterval(str
) : 30;
1579 str
= conf_get_data("server/force_n2k", RECDB_QSTRING
);
1580 force_n2k
= str
? enabled_string(str
) : 1;
1581 str
= conf_get_data("server/numeric", RECDB_QSTRING
);
1583 log_module(MAIN_LOG
, LOG_ERROR
, "No server/numeric entry in config file.");
1586 numnick
= atoi(str
);
1587 str
= conf_get_data("server/max_users", RECDB_QSTRING
);
1588 max_users
= str
? atoi(str
) : 4096;
1589 for (usermask
= 4; usermask
< max_users
; usermask
<<= 1) ;
1591 if ((numnick
< 64) && (usermask
< 4096) && !force_n2k
)
1592 inttobase64(numer
, (numnick
<< 12) + (usermask
& 0x00fff), 3);
1594 inttobase64(numer
, (numnick
<< 18) + (usermask
& 0x3ffff), 5);
1596 str
= conf_get_data("server/his_servername", RECDB_QSTRING
);
1597 his_servername
= str
? strdup(str
) : NULL
;
1598 str
= conf_get_data("server/his_servercomment", RECDB_QSTRING
);
1599 his_servercomment
= str
? strdup(str
) : NULL
;
1601 str
= conf_get_data("server/hostname", RECDB_QSTRING
);
1602 desc
= conf_get_data("server/description", RECDB_QSTRING
);
1603 if (!str
|| !desc
) {
1604 log_module(MAIN_LOG
, LOG_ERROR
, "No server/hostname entry in config file.");
1607 self
= AddServer(NULL
, str
, 0, boot_time
, now
, numer
, desc
);
1608 conf_register_reload(p10_conf_reload
);
1610 irc_func_dict
= dict_new();
1611 dict_insert(irc_func_dict
, CMD_BURST
, cmd_burst
);
1612 dict_insert(irc_func_dict
, TOK_BURST
, cmd_burst
);
1613 dict_insert(irc_func_dict
, CMD_CREATE
, cmd_create
);
1614 dict_insert(irc_func_dict
, TOK_CREATE
, cmd_create
);
1615 dict_insert(irc_func_dict
, CMD_EOB
, cmd_eob
);
1616 dict_insert(irc_func_dict
, TOK_EOB
, cmd_eob
);
1617 dict_insert(irc_func_dict
, CMD_EOB_ACK
, cmd_eob_ack
);
1618 dict_insert(irc_func_dict
, TOK_EOB_ACK
, cmd_eob_ack
);
1619 dict_insert(irc_func_dict
, CMD_MODE
, cmd_mode
);
1620 dict_insert(irc_func_dict
, TOK_MODE
, cmd_mode
);
1621 dict_insert(irc_func_dict
, CMD_NICK
, cmd_nick
);
1622 dict_insert(irc_func_dict
, TOK_NICK
, cmd_nick
);
1623 dict_insert(irc_func_dict
, CMD_ACCOUNT
, cmd_account
);
1624 dict_insert(irc_func_dict
, TOK_ACCOUNT
, cmd_account
);
1625 dict_insert(irc_func_dict
, CMD_FAKEHOST
, cmd_fakehost
);
1626 dict_insert(irc_func_dict
, TOK_FAKEHOST
, cmd_fakehost
);
1627 dict_insert(irc_func_dict
, CMD_PASS
, cmd_pass
);
1628 dict_insert(irc_func_dict
, TOK_PASS
, cmd_pass
);
1629 dict_insert(irc_func_dict
, CMD_PING
, cmd_ping
);
1630 dict_insert(irc_func_dict
, TOK_PING
, cmd_ping
);
1631 dict_insert(irc_func_dict
, CMD_PRIVMSG
, cmd_privmsg
);
1632 dict_insert(irc_func_dict
, TOK_PRIVMSG
, cmd_privmsg
);
1633 dict_insert(irc_func_dict
, CMD_PONG
, cmd_pong
);
1634 dict_insert(irc_func_dict
, TOK_PONG
, cmd_pong
);
1635 dict_insert(irc_func_dict
, CMD_QUIT
, cmd_quit
);
1636 dict_insert(irc_func_dict
, TOK_QUIT
, cmd_quit
);
1637 dict_insert(irc_func_dict
, CMD_SERVER
, cmd_server
);
1638 dict_insert(irc_func_dict
, TOK_SERVER
, cmd_server
);
1639 dict_insert(irc_func_dict
, CMD_JOIN
, cmd_join
);
1640 dict_insert(irc_func_dict
, TOK_JOIN
, cmd_join
);
1641 dict_insert(irc_func_dict
, CMD_PART
, cmd_part
);
1642 dict_insert(irc_func_dict
, TOK_PART
, cmd_part
);
1643 dict_insert(irc_func_dict
, CMD_ERROR
, cmd_error
);
1644 dict_insert(irc_func_dict
, TOK_ERROR
, cmd_error
);
1645 dict_insert(irc_func_dict
, CMD_TOPIC
, cmd_topic
);
1646 dict_insert(irc_func_dict
, TOK_TOPIC
, cmd_topic
);
1647 dict_insert(irc_func_dict
, CMD_AWAY
, cmd_away
);
1648 dict_insert(irc_func_dict
, TOK_AWAY
, cmd_away
);
1649 dict_insert(irc_func_dict
, CMD_SILENCE
, cmd_dummy
);
1650 dict_insert(irc_func_dict
, TOK_SILENCE
, cmd_dummy
);
1651 dict_insert(irc_func_dict
, CMD_KICK
, cmd_kick
);
1652 dict_insert(irc_func_dict
, TOK_KICK
, cmd_kick
);
1653 dict_insert(irc_func_dict
, CMD_SQUIT
, cmd_squit
);
1654 dict_insert(irc_func_dict
, TOK_SQUIT
, cmd_squit
);
1655 dict_insert(irc_func_dict
, CMD_KILL
, cmd_kill
);
1656 dict_insert(irc_func_dict
, TOK_KILL
, cmd_kill
);
1657 dict_insert(irc_func_dict
, CMD_NOTICE
, cmd_notice
);
1658 dict_insert(irc_func_dict
, TOK_NOTICE
, cmd_notice
);
1659 dict_insert(irc_func_dict
, CMD_STATS
, cmd_stats
);
1660 dict_insert(irc_func_dict
, TOK_STATS
, cmd_stats
);
1661 dict_insert(irc_func_dict
, CMD_SVSNICK
, cmd_svsnick
);
1662 dict_insert(irc_func_dict
, TOK_SVSNICK
, cmd_svsnick
);
1663 dict_insert(irc_func_dict
, CMD_WHOIS
, cmd_whois
);
1664 dict_insert(irc_func_dict
, TOK_WHOIS
, cmd_whois
);
1665 dict_insert(irc_func_dict
, CMD_GLINE
, cmd_gline
);
1666 dict_insert(irc_func_dict
, TOK_GLINE
, cmd_gline
);
1667 dict_insert(irc_func_dict
, CMD_OPMODE
, cmd_opmode
);
1668 dict_insert(irc_func_dict
, TOK_OPMODE
, cmd_opmode
);
1669 dict_insert(irc_func_dict
, CMD_CLEARMODE
, cmd_clearmode
);
1670 dict_insert(irc_func_dict
, TOK_CLEARMODE
, cmd_clearmode
);
1671 dict_insert(irc_func_dict
, CMD_VERSION
, cmd_version
);
1672 dict_insert(irc_func_dict
, TOK_VERSION
, cmd_version
);
1673 dict_insert(irc_func_dict
, CMD_ADMIN
, cmd_admin
);
1674 dict_insert(irc_func_dict
, TOK_ADMIN
, cmd_admin
);
1676 /* In P10, DESTRUCT doesn't do anything except be broadcast to servers.
1677 * Apparently to obliterate channels from any servers that think they
1680 dict_insert(irc_func_dict
, CMD_DESTRUCT
, cmd_dummy
);
1681 dict_insert(irc_func_dict
, TOK_DESTRUCT
, cmd_dummy
);
1682 /* Ignore invites */
1683 dict_insert(irc_func_dict
, CMD_INVITE
, cmd_dummy
);
1684 dict_insert(irc_func_dict
, TOK_INVITE
, cmd_dummy
);
1685 /* DESYNCH is just informational, so ignore it */
1686 dict_insert(irc_func_dict
, CMD_DESYNCH
, cmd_dummy
);
1687 dict_insert(irc_func_dict
, TOK_DESYNCH
, cmd_dummy
);
1688 /* Ignore channel operator notices. */
1689 dict_insert(irc_func_dict
, CMD_WALLCHOPS
, cmd_dummy
);
1690 dict_insert(irc_func_dict
, TOK_WALLCHOPS
, cmd_dummy
);
1691 dict_insert(irc_func_dict
, CMD_WALLVOICES
, cmd_dummy
);
1692 dict_insert(irc_func_dict
, TOK_WALLVOICES
, cmd_dummy
);
1693 dict_insert(irc_func_dict
, CMD_WALLHOPS
, cmd_dummy
);
1694 dict_insert(irc_func_dict
, TOK_WALLHOPS
, cmd_dummy
);
1695 /* Ignore opers being silly. */
1696 dict_insert(irc_func_dict
, CMD_WALLOPS
, cmd_dummy
);
1697 dict_insert(irc_func_dict
, TOK_WALLOPS
, cmd_dummy
);
1698 dict_insert(irc_func_dict
, CMD_WALLHOPS
, cmd_dummy
);
1699 dict_insert(irc_func_dict
, TOK_WALLHOPS
, cmd_dummy
);
1700 /* We have reliable clock! Always! Wraaa! */
1701 dict_insert(irc_func_dict
, CMD_SETTIME
, cmd_dummy
);
1702 dict_insert(irc_func_dict
, TOK_SETTIME
, cmd_dummy
);
1704 dict_insert(irc_func_dict
, "331", cmd_num_topic
);
1705 dict_insert(irc_func_dict
, "332", cmd_num_topic
);
1706 dict_insert(irc_func_dict
, "333", cmd_num_topic
);
1707 dict_insert(irc_func_dict
, "345", cmd_dummy
); /* blah has been invited to blah */
1708 dict_insert(irc_func_dict
, "432", cmd_error_nick
); /* Erroneus [sic] nickname */
1709 /* ban list resetting */
1710 /* "stats g" responses */
1711 dict_insert(irc_func_dict
, "247", cmd_num_gline
);
1712 dict_insert(irc_func_dict
, "219", cmd_dummy
); /* "End of /STATS report" */
1713 /* other numeric responses we might get */
1714 dict_insert(irc_func_dict
, "401", cmd_dummy
); /* target left network */
1715 dict_insert(irc_func_dict
, "403", cmd_dummy
); /* no such channel */
1716 dict_insert(irc_func_dict
, "404", cmd_dummy
); /* cannot send to channel */
1717 dict_insert(irc_func_dict
, "439", cmd_dummy
); /* target change too fast */
1718 dict_insert(irc_func_dict
, "441", cmd_dummy
); /* target isn't on that channel */
1719 dict_insert(irc_func_dict
, "442", cmd_dummy
); /* you aren't on that channel */
1720 dict_insert(irc_func_dict
, "443", cmd_dummy
); /* is already on channel (after invite?) */
1721 dict_insert(irc_func_dict
, "461", cmd_dummy
); /* Not enough parameters (after TOPIC w/ 0 args) */
1722 dict_insert(irc_func_dict
, "467", cmd_dummy
); /* Channel key already set */
1724 num_privmsg_funcs
= 16;
1725 privmsg_funcs
= malloc(sizeof(privmsg_func_t
)*num_privmsg_funcs
);
1726 memset(privmsg_funcs
, 0, sizeof(privmsg_func_t
)*num_privmsg_funcs
);
1728 num_notice_funcs
= 16;
1729 notice_funcs
= malloc(sizeof(privmsg_func_t
)*num_notice_funcs
);
1730 memset(notice_funcs
, 0, sizeof(privmsg_func_t
)*num_notice_funcs
);
1732 userList_init(&dead_users
);
1733 reg_del_channel_func(remove_unbursted_channel
);
1734 reg_exit_func(parse_cleanup
);
1738 parse_line(char *line
, int recursive
)
1740 char *argv
[MAXNUMPARAMS
], *origin
;
1741 int argc
, cmd
, res
=0;
1744 argc
= split_line(line
, true, MAXNUMPARAMS
, argv
);
1745 cmd
= self
->uplink
|| !argv
[0][1] || !argv
[0][2];
1748 if (argv
[0][0] == ':') {
1750 } else if (!argv
[0][1] || !argv
[0][2]) {
1751 struct server
*sNode
= GetServerN(argv
[0]);
1752 origin
= sNode
? sNode
->name
: 0;
1754 struct userNode
*uNode
= GetUserN(argv
[0]);
1755 origin
= uNode
? uNode
->nick
: 0;
1759 if ((func
= dict_find(irc_func_dict
, argv
[cmd
], NULL
)))
1760 res
= func(origin
, argc
-cmd
, argv
+cmd
);
1763 log_module(MAIN_LOG
, LOG_ERROR
, "PARSE ERROR on line: %s", unsplit_string(argv
, argc
, NULL
));
1764 } else if (!recursive
) {
1766 for (i
=0; i
<dead_users
.used
; i
++)
1767 free_user(dead_users
.list
[i
]);
1768 dead_users
.used
= 0;
1774 parse_foreach(char *target_list
, foreach_chanfunc cf
, foreach_nonchan nc
, foreach_userfunc uf
, foreach_nonuser nu
, void *data
)
1779 while (*j
!= 0 && *j
!= ',')
1783 if (IsChannelName(target_list
)
1784 || (target_list
[0] == '0' && target_list
[1] == '\0')) {
1785 struct chanNode
*chan
= GetChannel(target_list
);
1791 nc(target_list
, data
);
1794 struct userNode
*user
;
1795 struct privmsg_desc
*pd
= data
;
1797 pd
->is_qualified
= 0;
1798 if (*target_list
== '@') {
1800 } else if (strchr(target_list
, '@')) {
1801 struct server
*server
;
1803 pd
->is_qualified
= 1;
1804 user
= GetUserH(strtok(target_list
, "@"));
1805 server
= GetServerH(strtok(NULL
, "@"));
1807 if (user
&& (user
->uplink
!= server
)) {
1808 /* Don't attempt to index into any arrays
1809 using a user's numeric on another server. */
1813 user
= GetUserN(target_list
);
1821 nu(target_list
, data
);
1825 } while (old
== ',');
1829 get_local_numeric(void)
1831 static unsigned int next_numeric
= 0;
1832 if (self
->clients
> self
->num_mask
)
1834 while (self
->users
[next_numeric
])
1835 if (++next_numeric
> self
->num_mask
)
1837 return next_numeric
;
1841 make_numeric(struct server
*svr
, int local_num
, char *outbuf
)
1845 if (force_n2k
|| svr
->numeric
[1]) {
1850 llen
= (local_num
< 64*64) ? 2 : 3;
1852 strncpy(outbuf
, svr
->numeric
, slen
);
1853 inttobase64(outbuf
+slen
, local_num
, llen
);
1854 outbuf
[slen
+llen
] = 0;
1858 AddServer(struct server
*uplink
, const char *name
, int hops
, time_t boot
, time_t link
, const char *numeric
, const char *description
)
1860 struct server
* sNode
;
1863 if ((sNode
= GetServerN(numeric
))) {
1864 /* This means we're trying to re-add an existant server.
1865 * To be safe, we should forget the previous incarnation.
1866 * (And all its linked servers.)
1868 * It usually only happens in replays when the original
1869 * had a ping timeout and the replay didn't (because
1870 * replaying a ping timeout invariably gets things wrong).
1872 DelServer(sNode
, 0, NULL
);
1875 switch (strlen(numeric
)) {
1876 case 5: slen
= 2; mlen
= 3; break;
1877 case 4: slen
= 1; mlen
= 3; break;
1878 case 3: slen
= 1; mlen
= 2; break;
1880 log_module(MAIN_LOG
, LOG_ERROR
, "AddServer(\"%s\", \"%s\", ...): Numeric %s has invalid length.", uplink
->name
, name
, numeric
);
1884 sNode
= calloc(1, sizeof(*sNode
));
1885 sNode
->uplink
= uplink
;
1886 safestrncpy(sNode
->name
, name
, sizeof(sNode
->name
));
1887 sNode
->num_mask
= base64toint(numeric
+slen
, mlen
);
1891 strncpy(sNode
->numeric
, numeric
, slen
);
1892 safestrncpy(sNode
->description
, description
, sizeof(sNode
->description
));
1893 sNode
->users
= calloc(sNode
->num_mask
+1, sizeof(*sNode
->users
));
1894 serverList_init(&sNode
->children
);
1895 if (sNode
->uplink
) {
1896 /* uplink may be NULL if we're just building ourself */
1897 serverList_append(&sNode
->uplink
->children
, sNode
);
1899 servers_num
[base64toint(numeric
, slen
)] = sNode
;
1900 dict_insert(servers
, sNode
->name
, sNode
);
1904 void DelServer(struct server
* serv
, int announce
, const char *message
)
1908 /* If we receive an ERROR command before the SERVER
1909 * command a NULL server can be passed */
1913 /* Hrm, what's the right way to SQUIT some other server?
1914 * (This code is only to handle killing juped servers.) */
1915 if (announce
&& (serv
->uplink
== self
) && (serv
!= self
->uplink
))
1916 irc_squit(serv
, message
, NULL
);
1918 /* must recursively remove servers linked to this one first */
1919 for (i
=serv
->children
.used
;i
>0;)
1920 if (serv
->children
.list
[--i
] != self
)
1921 DelServer(serv
->children
.list
[i
], false, NULL
);
1923 /* clean up server's user hash tables */
1924 for (i
=0;i
<=serv
->num_mask
;i
++)
1926 DelUser(serv
->users
[i
], NULL
, false, "server delinked");
1930 serverList_remove(&serv
->uplink
->children
, serv
);
1931 if (serv
== self
->uplink
)
1932 self
->uplink
= NULL
;
1933 servers_num
[base64toint(serv
->numeric
, strlen(serv
->numeric
))] = NULL
;
1934 dict_remove(servers
, serv
->name
);
1935 serverList_clean(&serv
->children
);
1941 AddService(const char *nick
, const char *modes
, const char *desc
, const char *hostname
)
1943 char numeric
[COMBO_NUMERIC_LEN
+1];
1944 int local_num
= get_local_numeric();
1945 time_t timestamp
= now
;
1946 struct userNode
*old_user
= GetUserH(nick
);
1949 if (IsLocal(old_user
))
1951 timestamp
= old_user
->timestamp
- 1;
1953 if (local_num
== -1) {
1954 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to allocate numnick for service %s", nick
);
1958 hostname
= self
->name
;
1959 make_numeric(self
, local_num
, numeric
);
1960 /* TODO: Make these modes part of the conf file */
1961 return AddUser(self
, nick
, nick
, hostname
, modes
? modes
: "+oik", numeric
, desc
, now
, "AAAAAA");
1965 AddClone(const char *nick
, const char *ident
, const char *hostname
, const char *desc
)
1967 char numeric
[COMBO_NUMERIC_LEN
+1];
1968 int local_num
= get_local_numeric();
1969 time_t timestamp
= now
;
1970 struct userNode
*old_user
= GetUserH(nick
);
1973 if (IsLocal(old_user
))
1975 timestamp
= old_user
->timestamp
- 1;
1977 if (local_num
== -1) {
1978 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to allocate numnick for clone %s", nick
);
1981 make_numeric(self
, local_num
, numeric
);
1982 return AddUser(self
, nick
, ident
, hostname
, "+i", numeric
, desc
, timestamp
, "AAAAAA");
1986 is_valid_nick(const char *nick
) {
1988 /* IRC has some of The Most Fucked-Up ideas about character sets
1990 if (!isalpha(*nick
) && !strchr("{|}~[\\]^_`", *nick
))
1992 for (ii
= 0; nick
[ii
]; ++ii
)
1993 if (!isalnum(nick
[ii
]) && !strchr("{|}~[\\]^-_`", nick
[ii
]))
1995 if (strlen(nick
) > nicklen
)
2000 static struct userNode
*
2001 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
)
2003 struct userNode
*oldUser
, *uNode
;
2004 unsigned int n
, ignore_user
;
2006 if ((strlen(numeric
) < 3) || (strlen(numeric
) > 5)) {
2007 log_module(MAIN_LOG
, LOG_WARNING
, "AddUser(%p, %s, ...): numeric %s wrong length!", uplink
, nick
, numeric
);
2012 log_module(MAIN_LOG
, LOG_WARNING
, "AddUser(%p, %s, ...): server for numeric %s doesn't exist!", uplink
, nick
, numeric
);
2016 if (uplink
!= GetServerN(numeric
)) {
2017 log_module(MAIN_LOG
, LOG_WARNING
, "AddUser(%p, %s, ...): server for numeric %s differs from nominal uplink %s.", uplink
, nick
, numeric
, uplink
->name
);
2021 if (!is_valid_nick(nick
)) {
2022 log_module(MAIN_LOG
, LOG_WARNING
, "AddUser(%p, %s, ...): invalid nickname detected.", uplink
, nick
);
2027 if ((oldUser
= GetUserH(nick
))) {
2028 if (IsLocal(oldUser
) && (IsService(oldUser
) || IsPersistent(oldUser
))) {
2029 /* The service should collide the new user off. */
2030 oldUser
->timestamp
= timestamp
- 1;
2033 if (oldUser
->timestamp
> timestamp
) {
2034 /* "Old" user is really newer; remove them */
2035 DelUser(oldUser
, 0, 1, "Overruled by older nick");
2037 /* User being added is too new; do not add them to
2038 * clients, but do add them to the server's list, since it
2039 * will send a KILL and QUIT soon. */
2044 /* create new usernode and set all values */
2045 uNode
= calloc(1, sizeof(*uNode
));
2046 uNode
->nick
= strdup(nick
);
2047 safestrncpy(uNode
->ident
, ident
, sizeof(uNode
->ident
));
2048 safestrncpy(uNode
->info
, userinfo
, sizeof(uNode
->info
));
2049 safestrncpy(uNode
->hostname
, hostname
, sizeof(uNode
->hostname
));
2050 safestrncpy(uNode
->numeric
, numeric
, sizeof(uNode
->numeric
));
2051 uNode
->ip
.s_addr
= htonl(base64toint(realip
, 6));
2052 uNode
->timestamp
= timestamp
;
2053 modeList_init(&uNode
->channels
);
2054 uNode
->uplink
= uplink
;
2055 if (++uNode
->uplink
->clients
> uNode
->uplink
->max_clients
) {
2056 uNode
->uplink
->max_clients
= uNode
->uplink
->clients
;
2058 uNode
->num_local
= base64toint(numeric
+strlen(uNode
->uplink
->numeric
), 3) & uNode
->uplink
->num_mask
;
2059 uNode
->uplink
->users
[uNode
->num_local
] = uNode
;
2060 mod_usermode(uNode
, modes
);
2064 dict_insert(clients
, uNode
->nick
, uNode
);
2065 if (dict_size(clients
) > max_clients
) {
2066 max_clients
= dict_size(clients
);
2067 max_clients_time
= now
;
2071 for (n
=0; n
<nuf_used
; n
++)
2072 if (nuf_list
[n
](uNode
))
2077 /* removes user from it's server's hash table and nick hash table */
2079 DelUser(struct userNode
* user
, struct userNode
*killer
, int announce
, const char *why
)
2085 /* mark them as dead, in case anybody cares */
2088 /* remove pending adduser commands */
2089 wipe_adduser_pending(NULL
, user
);
2091 /* remove user from all channels */
2092 while (user
->channels
.used
> 0)
2093 DelChannelUser(user
, user
->channels
.list
[user
->channels
.used
-1]->channel
, false, 0);
2095 /* Call these in reverse order so ChanServ can update presence
2096 information before NickServ nukes the handle_info. */
2097 for (n
= duf_used
; n
> 0; )
2098 duf_list
[--n
](user
, killer
, why
);
2100 user
->uplink
->clients
--;
2101 user
->uplink
->users
[user
->num_local
] = NULL
;
2103 userList_remove(&curr_opers
, user
);
2104 /* remove from global dictionary, but not if after a collide */
2105 if (user
== dict_find(clients
, user
->nick
, NULL
))
2106 dict_remove(clients
, user
->nick
);
2108 if (IsInvisible(user
))
2113 irc_quit(user
, why
);
2115 irc_kill(killer
, user
, why
);
2118 modeList_clean(&user
->channels
);
2119 /* We don't free them, in case we try to privmsg them or something
2120 * (like when a stupid oper kills themself). We just put them onto
2121 * a list of clients that get freed after processing each line.
2123 if (dead_users
.size
)
2124 userList_append(&dead_users
, user
);
2129 void mod_usermode(struct userNode
*user
, const char *mode_change
) {
2130 static void call_oper_funcs(struct userNode
*user
);
2132 const char *word
= mode_change
;
2134 if (!user
|| !mode_change
)
2136 while (*word
!= ' ' && *word
) word
++;
2137 while (*word
== ' ') word
++;
2139 #define do_user_mode(FLAG) do { if (add) user->modes |= FLAG; else user->modes &= ~FLAG; } while (0)
2140 switch (*mode_change
++) {
2141 case 0: case ' ': return;
2142 case '+': add
= 1; break;
2143 case '-': add
= 0; break;
2145 do_user_mode(FLAGS_OPER
);
2147 userList_append(&curr_opers
, user
);
2148 call_oper_funcs(user
);
2150 userList_remove(&curr_opers
, user
);
2153 case 'O': do_user_mode(FLAGS_LOCOP
); break;
2154 case 'i': do_user_mode(FLAGS_INVISIBLE
);
2160 case 'w': do_user_mode(FLAGS_WALLOP
); break;
2161 case 's': do_user_mode(FLAGS_SERVNOTICE
); break;
2162 case 'd': do_user_mode(FLAGS_DEAF
); break;
2163 case 'k': do_user_mode(FLAGS_SERVICE
); break;
2164 case 'g': do_user_mode(FLAGS_GLOBAL
); break;
2165 // sethost - reed/apples
2166 // case 'h': do_user_mode(FLAGS_HELPER); break;
2167 // I check if there's an 'h' in the first part, and if there,
2168 // then everything after the space becomes their new host.
2169 case 'h': do_user_mode(FLAGS_SETHOST
);
2171 char sethost
[MAXLEN
];
2173 for (ii
=0; (*word
!= ' ') && (*word
!= '\0'); )
2174 sethost
[ii
++] = *word
++;
2176 while (*word
== ' ')
2178 safestrncpy(user
->sethost
, sethost
, sizeof(user
->sethost
));
2181 case 'x': do_user_mode(FLAGS_HIDDEN_HOST
); break;
2186 for (ii
=0; (*word
!= ' ') && (*word
!= '\0'); )
2187 tag
[ii
++] = *word
++;
2189 while (*word
== ' ')
2191 call_account_func(user
, tag
);
2198 for (ii
=0; (*word
!= ' ') && (*word
!= '\0'); )
2199 host
[ii
++] = *word
++;
2201 while (*word
== ' ')
2203 assign_fakehost(user
, host
, 0);
2211 struct mod_chanmode
*
2212 mod_chanmode_parse(struct chanNode
*channel
, char **modes
, unsigned int argc
, unsigned int flags
)
2214 struct mod_chanmode
*change
;
2215 unsigned int ii
, in_arg
, ch_arg
, add
;
2219 if (!(change
= mod_chanmode_alloc(argc
- 1)))
2222 for (ii
= ch_arg
= 0, in_arg
= add
= 1;
2223 (modes
[0][ii
] != '\0') && (modes
[0][ii
] != ' ');
2225 switch (modes
[0][ii
]) {
2232 #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)
2233 case 'C': do_chan_mode(MODE_NOCTCPS
); break;
2234 case 'D': do_chan_mode(MODE_DELAYJOINS
); break;
2235 case 'c': do_chan_mode(MODE_NOCOLORS
); break;
2236 case 'i': do_chan_mode(MODE_INVITEONLY
); break;
2237 case 'm': do_chan_mode(MODE_MODERATED
); break;
2238 case 'n': do_chan_mode(MODE_NOPRIVMSGS
); break;
2239 case 'p': do_chan_mode(MODE_PRIVATE
); break;
2240 case 'r': do_chan_mode(MODE_REGONLY
); break;
2241 case 's': do_chan_mode(MODE_SECRET
); break;
2242 case 't': do_chan_mode(MODE_TOPICLIMIT
); break;
2243 case 'S': do_chan_mode(MODE_STRIPCOLOR
); break;
2244 case 'M': do_chan_mode(MODE_MODUNREG
); break;
2245 case 'N': do_chan_mode(MODE_NONOTICE
); break;
2246 case 'Q': do_chan_mode(MODE_NOQUITMSGS
); break;
2247 case 'T': do_chan_mode(MODE_NOAMSG
); break;
2248 case 'O': do_chan_mode(MODE_OPERSONLY
); break;
2249 case 'Z': do_chan_mode(MODE_SSLONLY
); break;
2251 if (!(flags
& MCP_REGISTERED
)) {
2252 do_chan_mode(MODE_REGISTERED
);
2254 mod_chanmode_free(change
);
2258 // uncomment this when ssl is enabled on the network.
2259 // case 'Z': do_chan_mode(MODE_SSLONLY); break;
2265 change
->modes_set
|= MODE_LIMIT
;
2266 change
->new_limit
= atoi(modes
[in_arg
++]);
2268 change
->modes_set
&= ~MODE_LIMIT
;
2269 change
->modes_clear
|= MODE_LIMIT
;
2276 change
->modes_set
|= MODE_KEY
;
2277 safestrncpy(change
->new_key
, modes
[in_arg
++], sizeof(change
->new_key
));
2279 change
->modes_clear
|= MODE_KEY
;
2280 if (!(flags
& MCP_KEY_FREE
)) {
2288 if (!(flags
& MCP_ALLOW_OVB
))
2292 change
->args
[ch_arg
].mode
= MODE_BAN
;
2294 change
->args
[ch_arg
].mode
|= MODE_REMOVE
;
2295 change
->args
[ch_arg
++].u
.hostmask
= modes
[in_arg
++];
2298 if (!(flags
& MCP_ALLOW_OVB
))
2302 change
->args
[ch_arg
].mode
= MODE_EXEMPT
;
2304 change
->args
[ch_arg
].mode
|= MODE_REMOVE
;
2305 change
->args
[ch_arg
++].u
.hostmask
= modes
[in_arg
++];
2307 case 'o': case 'h': case 'v':
2309 struct userNode
*victim
;
2310 if (!(flags
& MCP_ALLOW_OVB
))
2315 if (modes
[0][ii
] == 'o')
2316 change
->args
[ch_arg
].mode
= MODE_CHANOP
;
2317 else if (modes
[0][ii
] == 'h')
2318 change
->args
[ch_arg
].mode
= MODE_HALFOP
;
2319 else if (modes
[0][ii
] == 'v')
2320 change
->args
[ch_arg
].mode
= MODE_VOICE
;
2323 change
->args
[ch_arg
].mode
|= MODE_REMOVE
;
2324 if (flags
& MCP_FROM_SERVER
)
2325 victim
= GetUserN(modes
[in_arg
++]);
2327 victim
= GetUserH(modes
[in_arg
++]);
2330 if ((change
->args
[ch_arg
].u
.member
= GetUserMode(channel
, victim
)))
2335 if (!(flags
& MCP_FROM_SERVER
))
2340 change
->argc
= ch_arg
; /* in case any turned out to be ignored */
2341 if (change
->modes_set
& MODE_SECRET
) {
2342 change
->modes_set
&= ~(MODE_PRIVATE
);
2343 change
->modes_clear
|= MODE_PRIVATE
;
2344 } else if (change
->modes_set
& MODE_PRIVATE
) {
2345 change
->modes_set
&= ~(MODE_SECRET
);
2346 change
->modes_clear
|= MODE_SECRET
;
2350 mod_chanmode_free(change
);
2354 struct chanmode_buffer
{
2357 struct chanNode
*channel
;
2358 struct userNode
*actor
;
2359 unsigned int modes_used
;
2360 unsigned int args_used
;
2362 unsigned int is_add
: 1;
2363 unsigned int is_chanop
: 1;
2367 mod_chanmode_append(struct chanmode_buffer
*buf
, char ch
, const char *arg
)
2369 size_t arg_len
= strlen(arg
);
2370 if (buf
->modes_used
> (MAXMODEPARAMS
) ||
2371 buf
->modes_used
+ buf
->args_used
+ buf
->chname_len
+ arg_len
> 450) {
2372 memcpy(buf
->modes
+ buf
->modes_used
, buf
->args
, buf
->args_used
);
2373 buf
->modes
[buf
->modes_used
+ buf
->args_used
] = '\0';
2374 irc_mode((buf
->is_chanop
? buf
->actor
: NULL
), buf
->channel
, buf
->modes
);
2375 buf
->modes
[0] = buf
->is_add
? '+' : '-';
2376 buf
->modes_used
= 1;
2379 buf
->modes
[buf
->modes_used
++] = ch
;
2380 buf
->args
[buf
->args_used
++] = ' ';
2381 memcpy(buf
->args
+ buf
->args_used
, arg
, arg_len
);
2382 buf
->args_used
+= arg_len
;
2386 mod_chanmode_announce(struct userNode
*who
, struct chanNode
*channel
, struct mod_chanmode
*change
)
2388 struct chanmode_buffer chbuf
;
2390 struct modeNode
*mn
;
2391 char int_buff
[32], mode
= '\0';
2393 assert(change
->argc
<= change
->alloc_argc
);
2394 memset(&chbuf
, 0, sizeof(chbuf
));
2395 chbuf
.channel
= channel
;
2397 chbuf
.chname_len
= strlen(channel
->name
);
2399 mn
= GetUserMode(channel
, who
);
2400 if ((mn
&& (mn
->modes
& MODE_CHANOP
)) || off_channel
)
2401 chbuf
.is_chanop
= 1;
2403 /* First remove modes */
2405 if (change
->modes_clear
) {
2407 chbuf
.modes
[chbuf
.modes_used
++] = mode
= '-';
2408 #define DO_MODE_CHAR(BIT, CHAR) if (change->modes_clear & MODE_##BIT) chbuf.modes[chbuf.modes_used++] = CHAR
2409 DO_MODE_CHAR(PRIVATE
, 'p');
2410 DO_MODE_CHAR(SECRET
, 's');
2411 DO_MODE_CHAR(MODERATED
, 'm');
2412 DO_MODE_CHAR(TOPICLIMIT
, 't');
2413 DO_MODE_CHAR(INVITEONLY
, 'i');
2414 DO_MODE_CHAR(NOPRIVMSGS
, 'n');
2415 DO_MODE_CHAR(LIMIT
, 'l');
2416 DO_MODE_CHAR(DELAYJOINS
, 'D');
2417 DO_MODE_CHAR(REGONLY
, 'r');
2418 DO_MODE_CHAR(NOCOLORS
, 'c');
2419 DO_MODE_CHAR(NOCTCPS
, 'C');
2420 DO_MODE_CHAR(STRIPCOLOR
, 'S');
2421 DO_MODE_CHAR(MODUNREG
, 'M');
2422 DO_MODE_CHAR(NONOTICE
, 'N');
2423 DO_MODE_CHAR(NOQUITMSGS
, 'Q');
2424 DO_MODE_CHAR(NOAMSG
, 'T');
2425 DO_MODE_CHAR(OPERSONLY
, 'O');
2426 DO_MODE_CHAR(REGISTERED
, 'z');
2427 DO_MODE_CHAR(SSLONLY
, 'Z');
2429 if (change
->modes_clear
& channel
->modes
& MODE_KEY
)
2430 mod_chanmode_append(&chbuf
, 'k', channel
->key
);
2432 for (arg
= 0; arg
< change
->argc
; ++arg
) {
2433 if (!(change
->args
[arg
].mode
& MODE_REMOVE
))
2436 chbuf
.modes
[chbuf
.modes_used
++] = mode
= '-';
2437 switch (change
->args
[arg
].mode
& ~MODE_REMOVE
) {
2439 mod_chanmode_append(&chbuf
, 'b', change
->args
[arg
].u
.hostmask
);
2442 mod_chanmode_append(&chbuf
, 'e', change
->args
[arg
].u
.hostmask
);
2445 if (change
->args
[arg
].mode
& MODE_CHANOP
)
2446 mod_chanmode_append(&chbuf
, 'o', change
->args
[arg
].u
.member
->user
->numeric
);
2447 if (change
->args
[arg
].mode
& MODE_HALFOP
)
2448 mod_chanmode_append(&chbuf
, 'h', change
->args
[arg
].u
.member
->user
->numeric
);
2449 if (change
->args
[arg
].mode
& MODE_VOICE
)
2450 mod_chanmode_append(&chbuf
, 'v', change
->args
[arg
].u
.member
->user
->numeric
);
2457 if (change
->modes_set
) {
2459 chbuf
.modes
[chbuf
.modes_used
++] = mode
= '+';
2460 #define DO_MODE_CHAR(BIT, CHAR) if (change->modes_set & MODE_##BIT) chbuf.modes[chbuf.modes_used++] = CHAR
2461 DO_MODE_CHAR(PRIVATE
, 'p');
2462 DO_MODE_CHAR(SECRET
, 's');
2463 DO_MODE_CHAR(MODERATED
, 'm');
2464 DO_MODE_CHAR(TOPICLIMIT
, 't');
2465 DO_MODE_CHAR(INVITEONLY
, 'i');
2466 DO_MODE_CHAR(NOPRIVMSGS
, 'n');
2467 DO_MODE_CHAR(DELAYJOINS
, 'D');
2468 DO_MODE_CHAR(REGONLY
, 'r');
2469 DO_MODE_CHAR(NOCOLORS
, 'c');
2470 DO_MODE_CHAR(NOCTCPS
, 'C');
2471 DO_MODE_CHAR(STRIPCOLOR
, 'S');
2472 DO_MODE_CHAR(MODUNREG
, 'M');
2473 DO_MODE_CHAR(NONOTICE
, 'N');
2474 DO_MODE_CHAR(NOQUITMSGS
, 'Q');
2475 DO_MODE_CHAR(NOAMSG
, 'T');
2476 DO_MODE_CHAR(OPERSONLY
, 'O');
2477 DO_MODE_CHAR(REGISTERED
, 'z');
2478 DO_MODE_CHAR(SSLONLY
, 'Z');
2480 if(change
->modes_set
& MODE_KEY
)
2481 mod_chanmode_append(&chbuf
, 'k', change
->new_key
);
2482 if(change
->modes_set
& MODE_LIMIT
) {
2483 sprintf(int_buff
, "%d", change
->new_limit
);
2484 mod_chanmode_append(&chbuf
, 'l', int_buff
);
2487 for (arg
= 0; arg
< change
->argc
; ++arg
) {
2488 if (change
->args
[arg
].mode
& MODE_REMOVE
)
2491 chbuf
.modes
[chbuf
.modes_used
++] = mode
= '+';
2492 switch (change
->args
[arg
].mode
) {
2494 mod_chanmode_append(&chbuf
, 'b', change
->args
[arg
].u
.hostmask
);
2497 mod_chanmode_append(&chbuf
, 'e', change
->args
[arg
].u
.hostmask
);
2500 if (change
->args
[arg
].mode
& MODE_CHANOP
)
2501 mod_chanmode_append(&chbuf
, 'o', change
->args
[arg
].u
.member
->user
->numeric
);
2502 if (change
->args
[arg
].mode
& MODE_HALFOP
)
2503 mod_chanmode_append(&chbuf
, 'h', change
->args
[arg
].u
.member
->user
->numeric
);
2504 if (change
->args
[arg
].mode
& MODE_VOICE
)
2505 mod_chanmode_append(&chbuf
, 'v', change
->args
[arg
].u
.member
->user
->numeric
);
2510 /* Flush the buffer and apply changes locally */
2511 if (chbuf
.modes_used
> 0) {
2512 memcpy(chbuf
.modes
+ chbuf
.modes_used
, chbuf
.args
, chbuf
.args_used
);
2513 chbuf
.modes
[chbuf
.modes_used
+ chbuf
.args_used
] = '\0';
2514 irc_mode((chbuf
.is_chanop
? chbuf
.actor
: NULL
), chbuf
.channel
, chbuf
.modes
);
2516 mod_chanmode_apply(who
, channel
, change
);
2520 mod_chanmode_format(struct mod_chanmode
*change
, char *outbuff
)
2522 unsigned int used
= 0;
2523 assert(change
->argc
<= change
->alloc_argc
);
2524 if (change
->modes_clear
) {
2525 outbuff
[used
++] = '-';
2526 #define DO_MODE_CHAR(BIT, CHAR) if (change->modes_clear & MODE_##BIT) outbuff[used++] = CHAR
2527 DO_MODE_CHAR(PRIVATE
, 'p');
2528 DO_MODE_CHAR(SECRET
, 's');
2529 DO_MODE_CHAR(MODERATED
, 'm');
2530 DO_MODE_CHAR(TOPICLIMIT
, 't');
2531 DO_MODE_CHAR(INVITEONLY
, 'i');
2532 DO_MODE_CHAR(NOPRIVMSGS
, 'n');
2533 DO_MODE_CHAR(LIMIT
, 'l');
2534 DO_MODE_CHAR(KEY
, 'k');
2535 DO_MODE_CHAR(DELAYJOINS
, 'D');
2536 DO_MODE_CHAR(REGONLY
, 'r');
2537 DO_MODE_CHAR(NOCOLORS
, 'c');
2538 DO_MODE_CHAR(NOCTCPS
, 'C');
2539 DO_MODE_CHAR(STRIPCOLOR
, 'S');
2540 DO_MODE_CHAR(MODUNREG
, 'M');
2541 DO_MODE_CHAR(NONOTICE
, 'N');
2542 DO_MODE_CHAR(NOQUITMSGS
, 'Q');
2543 DO_MODE_CHAR(NOAMSG
, 'T');
2544 DO_MODE_CHAR(OPERSONLY
, 'O');
2545 DO_MODE_CHAR(REGISTERED
, 'z');
2546 DO_MODE_CHAR(SSLONLY
, 'Z');
2549 if (change
->modes_set
) {
2550 outbuff
[used
++] = '+';
2551 #define DO_MODE_CHAR(BIT, CHAR) if (change->modes_set & MODE_##BIT) outbuff[used++] = CHAR
2552 DO_MODE_CHAR(PRIVATE
, 'p');
2553 DO_MODE_CHAR(SECRET
, 's');
2554 DO_MODE_CHAR(MODERATED
, 'm');
2555 DO_MODE_CHAR(TOPICLIMIT
, 't');
2556 DO_MODE_CHAR(INVITEONLY
, 'i');
2557 DO_MODE_CHAR(NOPRIVMSGS
, 'n');
2558 DO_MODE_CHAR(DELAYJOINS
, 'D');
2559 DO_MODE_CHAR(REGONLY
, 'r');
2560 DO_MODE_CHAR(NOCOLORS
, 'c');
2561 DO_MODE_CHAR(NOCTCPS
, 'C');
2562 DO_MODE_CHAR(STRIPCOLOR
, 'S');
2563 DO_MODE_CHAR(MODUNREG
, 'M');
2564 DO_MODE_CHAR(NONOTICE
, 'N');
2565 DO_MODE_CHAR(NOQUITMSGS
, 'Q');
2566 DO_MODE_CHAR(NOAMSG
, 'T');
2567 DO_MODE_CHAR(OPERSONLY
, 'O');
2568 DO_MODE_CHAR(REGISTERED
, 'z');
2569 DO_MODE_CHAR(SSLONLY
, 'Z');
2571 switch (change
->modes_set
& (MODE_KEY
|MODE_LIMIT
)) {
2572 case MODE_KEY
|MODE_LIMIT
:
2573 used
+= sprintf(outbuff
+used
, "lk %d %s", change
->new_limit
, change
->new_key
);
2576 used
+= sprintf(outbuff
+used
, "k %s", change
->new_key
);
2579 used
+= sprintf(outbuff
+used
, "l %d", change
->new_limit
);
2588 clear_chanmode(struct chanNode
*channel
, const char *modes
)
2590 unsigned int remove
;
2592 for (remove
= 0; *modes
; modes
++) {
2594 case 'o': remove
|= MODE_CHANOP
; break;
2595 case 'h': remove
|= MODE_HALFOP
; break;
2596 case 'v': remove
|= MODE_VOICE
; break;
2597 case 'p': remove
|= MODE_PRIVATE
; break;
2598 case 's': remove
|= MODE_SECRET
; break;
2599 case 'm': remove
|= MODE_MODERATED
; break;
2600 case 't': remove
|= MODE_TOPICLIMIT
; break;
2601 case 'i': remove
|= MODE_INVITEONLY
; break;
2602 case 'n': remove
|= MODE_NOPRIVMSGS
; break;
2605 channel
->key
[0] = '\0';
2608 remove
|= MODE_LIMIT
;
2611 case 'b': remove
|= MODE_BAN
; break;
2612 case 'e': remove
|= MODE_EXEMPT
; break;
2613 case 'D': remove
|= MODE_DELAYJOINS
; break;
2614 case 'r': remove
|= MODE_REGONLY
; break;
2615 case 'c': remove
|= MODE_NOCOLORS
;
2616 case 'C': remove
|= MODE_NOCTCPS
; break;
2617 case 'S': remove
|= MODE_STRIPCOLOR
; break;
2618 case 'M': remove
|= MODE_MODUNREG
; break;
2619 case 'N': remove
|= MODE_NONOTICE
; break;
2620 case 'Q': remove
|= MODE_NOQUITMSGS
; break;
2621 case 'T': remove
|= MODE_NOAMSG
; break;
2622 case 'O': remove
|= MODE_OPERSONLY
; break;
2623 case 'z': remove
|= MODE_REGISTERED
; break;
2624 case 'Z': remove
|= MODE_SSLONLY
; break;
2631 /* Remove simple modes. */
2632 channel
->modes
&= ~remove
;
2634 /* If removing bans, kill 'em all. */
2635 if ((remove
& MODE_BAN
) && channel
->banlist
.used
) {
2637 for (i
=0; i
<channel
->banlist
.used
; i
++)
2638 free(channel
->banlist
.list
[i
]);
2639 channel
->banlist
.used
= 0;
2642 /* If removing exempts, kill 'em all. */
2643 if ((remove
& MODE_EXEMPT
) && channel
->exemptlist
.used
) {
2645 for (i
=0; i
<channel
->exemptlist
.used
; i
++)
2646 free(channel
->exemptlist
.list
[i
]);
2647 channel
->exemptlist
.used
= 0;
2650 /* Remove member modes. */
2651 if ((remove
& (MODE_CHANOP
| MODE_HALFOP
| MODE_VOICE
)) && channel
->members
.used
) {
2652 int mask
= ~(remove
& (MODE_CHANOP
| MODE_HALFOP
| MODE_VOICE
));
2655 for (i
= 0; i
< channel
->members
.used
; i
++)
2656 channel
->members
.list
[i
]->modes
&= mask
;
2663 reg_privmsg_func(struct userNode
*user
, privmsg_func_t handler
)
2665 unsigned int numeric
= user
->num_local
;
2666 if (numeric
>= num_privmsg_funcs
) {
2667 int newnum
= numeric
+ 8;
2668 privmsg_funcs
= realloc(privmsg_funcs
, newnum
*sizeof(privmsg_func_t
));
2669 memset(privmsg_funcs
+num_privmsg_funcs
, 0, (newnum
-num_privmsg_funcs
)*sizeof(privmsg_func_t
));
2670 num_privmsg_funcs
= newnum
;
2672 if (privmsg_funcs
[numeric
])
2673 log_module(MAIN_LOG
, LOG_WARNING
, "re-registering new privmsg handler for numeric %d", numeric
);
2674 privmsg_funcs
[numeric
] = handler
;
2678 unreg_privmsg_func(struct userNode
*user
, privmsg_func_t handler
)
2682 if (!user
|| handler
)
2683 return; /* this really only works with users */
2685 memset(privmsg_funcs
+user
->num_local
, 0, sizeof(privmsg_func_t
));
2687 for (x
= user
->num_local
+1; x
< num_privmsg_funcs
; x
++)
2688 memmove(privmsg_funcs
+x
-1, privmsg_funcs
+x
, sizeof(privmsg_func_t
));
2690 privmsg_funcs
= realloc(privmsg_funcs
, num_privmsg_funcs
*sizeof(privmsg_func_t
));
2691 num_privmsg_funcs
--;
2696 reg_notice_func(struct userNode
*user
, privmsg_func_t handler
)
2698 unsigned int numeric
= user
->num_local
;
2699 if (numeric
>= num_notice_funcs
) {
2700 int newnum
= numeric
+ 8;
2701 notice_funcs
= realloc(notice_funcs
, newnum
*sizeof(privmsg_func_t
));
2702 memset(notice_funcs
+num_notice_funcs
, 0, (newnum
-num_notice_funcs
)*sizeof(privmsg_func_t
));
2703 num_notice_funcs
= newnum
;
2705 if (notice_funcs
[numeric
])
2706 log_module(MAIN_LOG
, LOG_WARNING
, "re-registering new notice handler for numeric %d", numeric
);
2707 notice_funcs
[numeric
] = handler
;
2711 unreg_notice_func(struct userNode
*user
, privmsg_func_t handler
)
2715 if (!user
|| handler
)
2716 return; /* this really only works with users */
2718 memset(notice_funcs
+user
->num_local
, 0, sizeof(privmsg_func_t
));
2720 for (x
= user
->num_local
+1; x
< num_notice_funcs
; x
++)
2721 memmove(notice_funcs
+x
-1, notice_funcs
+x
, sizeof(privmsg_func_t
));
2723 memset(notice_funcs
+user
->num_local
, 0, sizeof(privmsg_func_t
));
2724 notice_funcs
= realloc(notice_funcs
, num_notice_funcs
*sizeof(privmsg_func_t
));
2729 reg_oper_func(oper_func_t handler
)
2731 if (of_used
== of_size
) {
2734 of_list
= realloc(of_list
, of_size
*sizeof(oper_func_t
));
2737 of_list
= malloc(of_size
*sizeof(oper_func_t
));
2740 of_list
[of_used
++] = handler
;
2744 call_oper_funcs(struct userNode
*user
)
2749 for (n
=0; n
<of_used
; n
++)
2756 unsigned int i
, hop
, max_hop
=1;
2759 /* burst (juped) servers, closest first (except self, which is sent already) */
2760 for (i
=0; i
<ArrayLength(servers_num
); i
++)
2761 if (servers_num
[i
] && servers_num
[i
]->hops
> max_hop
)
2762 max_hop
= servers_num
[i
]->hops
;
2763 for (hop
=1; hop
<=max_hop
; hop
++) {
2764 for (i
=0;i
<ArrayLength(servers_num
);i
++) {
2766 && (servers_num
[i
]->hops
== hop
)
2767 && (servers_num
[i
] != self
->uplink
))
2768 irc_server(servers_num
[i
]);
2772 /* burst local nicks */
2773 for (i
=0; i
<=self
->num_mask
; i
++)
2775 irc_user(self
->users
[i
]);
2777 /* build dict of unbursted channel names (just copy existing channels) */
2778 unbursted_channels
= dict_new();
2779 for (it
= dict_first(channels
); it
; it
= iter_next(it
))
2780 dict_insert(unbursted_channels
, iter_key(it
), iter_data(it
));