]>
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.
23 #include "proto-common.c"
26 #define CMD_ACCOUNT "ACCOUNT"
27 #define CMD_ADMIN "ADMIN"
28 #define CMD_ASLL "ASLL"
29 #define CMD_AWAY "AWAY"
30 #define CMD_BURST "BURST"
31 #define CMD_CLEARMODE "CLEARMODE"
32 #define CMD_CLOSE "CLOSE"
33 #define CMD_CNOTICE "CNOTICE"
34 #define CMD_CONNECT "CONNECT"
35 #define CMD_CPRIVMSG "CPRIVMSG"
36 #define CMD_CREATE "CREATE"
37 #define CMD_DESTRUCT "DESTRUCT"
38 #define CMD_DESYNCH "DESYNCH"
41 #define CMD_EOB "END_OF_BURST"
42 #define CMD_EOB_ACK "EOB_ACK"
43 #define CMD_ERROR "ERROR"
44 #define CMD_FAKEHOST "FAKE"
46 #define CMD_GLINE "GLINE"
47 #define CMD_HASH "HASH"
48 #define CMD_HELP "HELP"
49 #define CMD_INFO "INFO"
50 #define CMD_INVITE "INVITE"
51 #define CMD_ISON "ISON"
52 #define CMD_JOIN "JOIN"
53 #define CMD_JUPE "JUPE"
54 #define CMD_KICK "KICK"
55 #define CMD_KILL "KILL"
56 #define CMD_LINKS "LINKS"
57 #define CMD_LIST "LIST"
58 #define CMD_LUSERS "LUSERS"
60 #define CMD_MARK "MARK"
61 #define CMD_MODE "MODE"
62 #define CMD_MOTD "MOTD"
63 #define CMD_NAMES "NAMES"
64 #define CMD_NICK "NICK"
65 #define CMD_NOTICE "NOTICE"
66 #define CMD_OPER "OPER"
67 #define CMD_OPMODE "OPMODE"
68 #define CMD_PART "PART"
69 #define CMD_PASS "PASS"
70 #define CMD_PING "PING"
71 #define CMD_PONG "PONG"
72 #define CMD_POST "POST"
73 #define CMD_PRIVMSG "PRIVMSG"
74 #define CMD_PRIVS "PRIVS"
75 #define CMD_PROTO "PROTO"
76 #define CMD_QUIT "QUIT"
77 #define CMD_REHASH "REHASH"
78 #define CMD_RESET "RESET"
79 #define CMD_RESTART "RESTART"
80 #define CMD_RPING "RPING"
81 #define CMD_RPONG "RPONG"
82 #define CMD_SERVER "SERVER"
83 #define CMD_SERVLIST "SERVLIST"
84 #define CMD_SERVSET "SERVSET"
86 #define CMD_SETTIME "SETTIME"
87 #define CMD_SILENCE "SILENCE"
88 #define CMD_SQUERY "SQUERY"
89 #define CMD_SQUIT "SQUIT"
90 #define CMD_STATS "STATS"
91 #define CMD_SVSNICK "SVSNICK"
92 #define CMD_TIME "TIME"
93 #define CMD_TOPIC "TOPIC"
94 #define CMD_TRACE "TRACE"
95 #define CMD_UPING "UPING"
96 #define CMD_USER "USER"
97 #define CMD_USERHOST "USERHOST"
98 #define CMD_USERIP "USERIP"
99 #define CMD_VERSION "VERSION"
100 #define CMD_WALLCHOPS "WALLCHOPS"
101 #define CMD_WALLOPS "WALLOPS"
102 #define CMD_WALLHOPS "WALLHOPS"
103 #define CMD_WALLUSERS "WALLUSERS"
104 #define CMD_WALLVOICES "WALLVOICES"
105 #define CMD_WALLHOPS "WALLHOPS"
106 #define CMD_WHO "WHO"
107 #define CMD_WHOIS "WHOIS"
108 #define CMD_WHOWAS "WHOWAS"
110 /* Tokenized commands. */
111 #define TOK_ACCOUNT "AC"
112 #define TOK_ADMIN "AD"
113 #define TOK_ASLL "LL"
115 #define TOK_BURST "B"
116 #define TOK_CLEARMODE "CM"
117 #define TOK_CLOSE "CLOSE"
118 #define TOK_CNOTICE "CN"
119 #define TOK_CONNECT "CO"
120 #define TOK_CPRIVMSG "CP"
121 #define TOK_CREATE "C"
122 #define TOK_DESTRUCT "DE"
123 #define TOK_DESYNCH "DS"
124 #define TOK_DIE "DIE"
125 #define TOK_DNS "DNS"
127 #define TOK_EOB_ACK "EA"
128 #define TOK_ERROR "Y"
129 #define TOK_EXEMPT "EX"
130 #define TOK_FAKEHOST "FA"
131 #define TOK_GET "GET"
132 #define TOK_GLINE "GL"
133 #define TOK_HASH "HASH"
134 #define TOK_HELP "HELP"
136 #define TOK_INVITE "I"
137 #define TOK_ISON "ISON"
139 #define TOK_JUPE "JU"
142 #define TOK_LINKS "LI"
143 #define TOK_LIST "LIST"
144 #define TOK_LUSERS "LU"
145 #define TOK_MAP "MAP"
146 #define TOK_MARK "MK"
148 #define TOK_MOTD "MO"
149 #define TOK_NAMES "E"
151 #define TOK_NOTICE "O"
152 #define TOK_OPER "OPER"
153 #define TOK_OPMODE "OM"
155 #define TOK_PASS "PA"
158 #define TOK_POST "POST"
159 #define TOK_PRIVMSG "P"
160 #define TOK_PRIVS "PRIVS"
161 #define TOK_PROTO "PROTO"
163 #define TOK_REHASH "REHASH"
164 #define TOK_RESET "RESET"
165 #define TOK_RESTART "RESTART"
166 #define TOK_RPING "RI"
167 #define TOK_RPONG "RO"
168 #define TOK_SERVER "S"
169 #define TOK_SERVLIST "SERVSET"
170 #define TOK_SERVSET "SERVSET"
171 #define TOK_SET "SET"
172 #define TOK_SETTIME "SE"
173 #define TOK_SILENCE "U"
174 #define TOK_SQUERY "SQUERY"
175 #define TOK_SQUIT "SQ"
176 #define TOK_STATS "R"
177 #define TOK_SVSNICK "SN"
178 #define TOK_TIME "TI"
179 #define TOK_TOPIC "T"
180 #define TOK_TRACE "TR"
181 #define TOK_UPING "UP"
182 #define TOK_USER "USER"
183 #define TOK_USERHOST "USERHOST"
184 #define TOK_USERIP "USERIP"
185 #define TOK_VERSION "V"
186 #define TOK_WALLCHOPS "WC"
187 #define TOK_WALLOPS "WA"
188 #define TOK_WALLHOPS "WH"
189 #define TOK_WALLUSERS "WU"
190 #define TOK_WALLVOICES "WV"
191 #define TOK_WALLHOPS "WH"
193 #define TOK_WHOIS "W"
194 #define TOK_WHOWAS "X"
196 /* Protocol messages; aliased to full commands or tokens depending
197 on compile-time configuration. ircu prefers tokens WITH THE
198 EXCEPTION OF THE SERVER AND PASS COMMANDS, which cannot be
199 tokenized, because clients' (ie. a linking server) commands are
200 only checked against the full command list.
202 #if defined(ENABLE_TOKENS)
203 #define TYPE(NAME) TOK_ ## NAME
204 #else /* !ENABLE_TOKENS */
205 #define TYPE(NAME) CMD_ ## NAME
206 #endif /* ENABLE_TOKENS */
208 #define P10_ACCOUNT TYPE(ACCOUNT)
209 #define P10_ADMIN TYPE(ADMIN)
210 #define P10_ASLL TYPE(ASLL)
211 #define P10_AWAY TYPE(AWAY)
212 #define P10_BURST TYPE(BURST)
213 #define P10_CLEARMODE TYPE(CLEARMODE)
214 #define P10_CLOSE TYPE(CLOSE)
215 #define P10_CNOTICE TYPE(CNOTICE)
216 #define P10_CONNECT TYPE(CONNECT)
217 #define P10_CPRIVMSG TYPE(CPRIVMSG)
218 #define P10_CREATE TYPE(CREATE)
219 #define P10_DESTRUCT TYPE(DESTRUCT)
220 #define P10_DESYNCH TYPE(DESYNCH)
221 #define P10_DIE TYPE(DIE)
222 #define P10_DNS TYPE(DNS)
223 #define P10_EOB TYPE(EOB)
224 #define P10_EOB_ACK TYPE(EOB_ACK)
225 #define P10_ERROR TYPE(ERROR)
226 #define P10_FAKEHOST TYPE(FAKEHOST)
227 #define P10_GET TYPE(GET)
228 #define P10_GLINE TYPE(GLINE)
229 #define P10_HASH TYPE(HASH)
230 #define P10_HELP TYPE(HELP)
231 #define P10_INFO TYPE(INFO)
232 #define P10_INVITE TYPE(INVITE)
233 #define P10_ISON TYPE(ISON)
234 #define P10_JOIN TYPE(JOIN)
235 #define P10_JUPE TYPE(JUPE)
236 #define P10_KICK TYPE(KICK)
237 #define P10_KILL TYPE(KILL)
238 #define P10_LINKS TYPE(LINKS)
239 #define P10_LIST TYPE(LIST)
240 #define P10_LUSERS TYPE(LUSERS)
241 #define P10_MAP TYPE(MAP)
242 #define P10_MARK TYPE(MARK)
243 #define P10_MODE TYPE(MODE)
244 #define P10_MOTD TYPE(MOTD)
245 #define P10_NAMES TYPE(NAMES)
246 #define P10_NICK TYPE(NICK)
247 #define P10_NOTICE TYPE(NOTICE)
248 #define P10_OPER TYPE(OPER)
249 #define P10_OPMODE TYPE(OPMODE)
250 #define P10_PART TYPE(PART)
251 #define P10_PASS CMD_PASS
252 #define P10_PING TYPE(PING)
253 #define P10_PONG TYPE(PONG)
254 #define P10_POST TYPE(POST)
255 #define P10_PRIVMSG TYPE(PRIVMSG)
256 #define P10_PRIVS TYPE(PRIVS)
257 #define P10_PROTO TYPE(PROTO)
258 #define P10_QUIT TYPE(QUIT)
259 #define P10_REHASH TYPE(REHASH)
260 #define P10_RESET TYPE(RESET)
261 #define P10_RESTART TYPE(RESTART)
262 #define P10_RPING TYPE(RPING)
263 #define P10_RPONG TYPE(RPONG)
264 #define P10_SERVER CMD_SERVER
265 #define P10_SERVLIST TYPE(SERVLIST)
266 #define P10_SERVSET TYPE(SERVSET)
267 #define P10_SET TYPE(SET)
268 #define P10_SETTIME TYPE(SETTIME)
269 #define P10_SILENCE TYPE(SILENCE)
270 #define P10_SQUERY TYPE(SQUERY)
271 #define P10_SQUIT TYPE(SQUIT)
272 #define P10_STATS TYPE(STATS)
273 #define P10_SVSNICK TYPE(SVSNICK)
274 #define P10_TIME TYPE(TIME)
275 #define P10_TOPIC TYPE(TOPIC)
276 #define P10_TRACE TYPE(TRACE)
277 #define P10_UPING TYPE(UPING)
278 #define P10_USER TYPE(USER)
279 #define P10_USERHOST TYPE(USERHOST)
280 #define P10_USERIP TYPE(USERIP)
281 #define P10_VERSION TYPE(VERSION)
282 #define P10_WALLCHOPS TYPE(WALLCHOPS)
283 #define P10_WALLOPS TYPE(WALLOPS)
284 #define P10_WALLHOPS TYPE(WALLHOPS)
285 #define P10_WALLUSERS TYPE(WALLUSERS)
286 #define P10_WALLVOICES TYPE(WALLVOICES)
287 #define P10_WHO TYPE(WHO)
288 #define P10_WHOIS TYPE(WHOIS)
289 #define P10_WHOWAS TYPE(WHOWAS)
290 #define P10_EXEMPT TYPE(EXEMPT)
292 /* Servers claiming to have a boot or link time before PREHISTORY
293 * trigger errors to the log. We hope no server has been running
294 * constantly since September 1994. :)
296 #define PREHISTORY 780000000
298 static struct server
*servers_num
[64*64];
299 static privmsg_func_t
*privmsg_funcs
;
300 static unsigned int num_privmsg_funcs
;
301 static privmsg_func_t
*notice_funcs
;
302 static unsigned int num_notice_funcs
;
303 static struct dict
*unbursted_channels
;
304 static char *his_servername
;
305 static char *his_servercomment
;
307 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
);
309 extern int off_channel
;
311 /* Numerics can be XYY, XYYY, or XXYYY; with X's identifying the
312 * server and Y's indentifying the client on that server. */
314 GetServerN(const char *numeric
)
316 switch (strlen(numeric
)) {
318 return servers_num
[base64toint(numeric
, 2)];
322 return servers_num
[base64toint(numeric
, 1)];
329 GetUserN(const char *numeric
) /* using numeric */
335 switch (strlen(numeric
)) {
337 log_module(MAIN_LOG
, LOG_WARNING
, "GetUserN(%s): numeric too long!", numeric
);
339 case 5: slen
= 2; ulen
= 3; break;
340 case 4: slen
= 1; ulen
= 3; break;
341 case 3: slen
= 1; ulen
= 2; break;
342 case 2: case 1: case 0:
343 log_module(MAIN_LOG
, LOG_WARNING
, "GetUserN(%s): numeric too short!", numeric
);
346 if (!(s
= servers_num
[base64toint(numeric
, slen
)])) {
347 log_module(MAIN_LOG
, LOG_WARNING
, "GetUserN(%s): couldn't find server (len=%d)!", numeric
, slen
);
350 n
= base64toint(numeric
+slen
, ulen
) & s
->num_mask
;
351 if (!(un
= s
->users
[n
])) {
352 log_module(MAIN_LOG
, LOG_WARNING
, "GetUserN(%s) couldn't find user!", numeric
);
358 privmsg_user_helper(struct userNode
*un
, void *data
)
360 struct privmsg_desc
*pd
= data
;
361 unsigned int num
= un
->num_local
;
362 if (!pd
->is_notice
) {
363 if ((num
< num_privmsg_funcs
) && privmsg_funcs
[num
]) {
364 privmsg_funcs
[num
](pd
->user
, un
, pd
->text
, pd
->is_qualified
);
367 if ((num
< num_notice_funcs
) && notice_funcs
[num
]) {
368 notice_funcs
[num
](pd
->user
, un
, pd
->text
, pd
->is_qualified
);
374 irc_server(struct server
*srv
)
376 char extranum
[COMBO_NUMERIC_LEN
+1];
378 inttobase64(extranum
, srv
->num_mask
, (srv
->numeric
[1] || (srv
->num_mask
>= 64*64)) ? 3 : 2);
380 /* The +s, ignored by Run's ircu, means "service" to Undernet's ircu */
381 putsock(P10_SERVER
" %s %d %li %li J10 %s%s +s :%s",
382 srv
->name
, srv
->hops
+1, srv
->boot
, srv
->link
, srv
->numeric
, extranum
, srv
->description
);
384 putsock("%s " P10_SERVER
" %s %d %li %li %c10 %s%s +s :%s",
385 self
->numeric
, srv
->name
, srv
->hops
+1, srv
->boot
, srv
->link
, (srv
->self_burst
? 'J' : 'P'), srv
->numeric
, extranum
, srv
->description
);
390 irc_user(struct userNode
*user
)
395 inttobase64(b64ip
, ntohl(user
->ip
.s_addr
), 6);
402 modes
[modelen
++] = 'o';
403 if (IsInvisible(user
))
404 modes
[modelen
++] = 'i';
406 modes
[modelen
++] = 'w';
408 modes
[modelen
++] = 'k';
409 if (IsServNotice(user
))
410 modes
[modelen
++] = 's';
412 modes
[modelen
++] = 'd';
414 modes
[modelen
++] = 'g';
415 // sethost - reed/apples
416 // if (IsHelperIrcu(user))
418 modes
[modelen
++] = 'h';
419 if (IsFakeHost(user
))
420 modes
[modelen
++] = 'f';
421 if (IsHiddenHost(user
))
422 modes
[modelen
++] = 'x';
425 /* we don't need to put the + in modes because it's in the format string. */
426 putsock("%s " P10_NICK
" %s %d %li %s %s +%s %s %s :%s",
427 user
->uplink
->numeric
, user
->nick
, user
->uplink
->hops
+1, user
->timestamp
, user
->ident
, user
->hostname
, modes
, b64ip
, user
->numeric
, user
->info
);
429 putsock("%s " P10_NICK
" %s %d %li %s %s %s %s :%s",
430 user
->uplink
->numeric
, user
->nick
, user
->uplink
->hops
+1, user
->timestamp
, user
->ident
, user
->hostname
, b64ip
, user
->numeric
, user
->info
);
435 irc_rename(struct userNode
*user
, const char *new_handle
)
437 putsock("%s " P10_ACCOUNT
" %s M %s", self
->numeric
, user
->numeric
, new_handle
);
441 irc_delete(struct userNode
*user
)
443 putsock("%s " P10_ACCOUNT
" %s U", self
->numeric
, user
->numeric
);
447 irc_account(struct userNode
*user
, const char *stamp
, time_t timestamp
)
449 putsock("%s " P10_ACCOUNT
" %s R %s %lu", self
->numeric
, user
->numeric
, stamp
, timestamp
);
453 irc_fakehost(struct userNode
*user
, const char *host
)
455 putsock("%s " P10_FAKEHOST
" %s %s", self
->numeric
, user
->numeric
, host
);
459 irc_regnick(UNUSED_ARG(struct userNode
*user
))
461 /* no operation here */
465 irc_nick(struct userNode
*user
, UNUSED_ARG(const char *old_nick
))
467 putsock("%s " P10_NICK
" %s "FMT_TIME_T
, user
->numeric
, user
->nick
, now
);
471 irc_fetchtopic(struct userNode
*from
, const char *to
)
475 putsock("%s " P10_TOPIC
" %s", from
->numeric
, to
);
479 irc_squit(struct server
*srv
, const char *message
, const char *service_message
)
481 if (!service_message
)
482 service_message
= message
;
484 /* Are we leaving the network? */
485 if (srv
== self
&& cManager
.uplink
->state
== CONNECTED
) {
488 /* Quit all clients linked to me. */
489 for (i
= 0; i
<= self
->num_mask
; i
++) {
492 irc_quit(self
->users
[i
], service_message
);
496 putsock("%s " P10_SQUIT
" %s %d :%s", self
->numeric
, srv
->name
, 0, message
);
499 /* Force a reconnect to the currently selected server. */
500 cManager
.uplink
->tries
= 0;
501 log_module(MAIN_LOG
, LOG_INFO
, "Squitting from uplink: %s", message
);
507 irc_wallchops(struct userNode
*from
, const char *to
, const char *message
)
509 putsock("%s " P10_WALLCHOPS
" %s :%s", from
->numeric
, to
, message
);
513 irc_notice(struct userNode
*from
, const char *to
, const char *message
)
515 putsock("%s " P10_NOTICE
" %s :%s", from
->numeric
, to
, message
);
519 irc_notice_user(struct userNode
*from
, struct userNode
*to
, const char *message
)
521 putsock("%s " P10_NOTICE
" %s :%s", from
->numeric
, to
->numeric
, message
);
525 irc_privmsg(struct userNode
*from
, const char *to
, const char *message
)
527 putsock("%s " P10_PRIVMSG
" %s :%s", from
->numeric
, to
, message
);
533 putsock("%s " P10_EOB
, self
->numeric
);
539 putsock("%s " P10_EOB_ACK
, self
->numeric
);
543 irc_ping(const char *payload
)
545 putsock("%s " P10_PING
" :%s", self
->numeric
, payload
);
549 irc_pong(const char *who
, const char *data
)
551 putsock("%s " P10_PONG
" %s :%s", self
->numeric
, who
, data
);
555 irc_pass(const char *passwd
)
557 putsock(P10_PASS
" :%s", passwd
);
561 irc_introduce(const char *passwd
)
563 void timed_send_ping(void *data
);
565 self
->self_burst
= self
->burst
= 1;
569 timeq_add(now
+ ping_freq
, timed_send_ping
, 0);
573 irc_gline(struct server
*srv
, struct gline
*gline
)
575 putsock("%s " P10_GLINE
" %s +%s %ld :<%s> %s",
576 self
->numeric
, (srv
? srv
->numeric
: "*"), gline
->target
, gline
->expires
-now
, gline
->issuer
, gline
->reason
);
580 irc_settime(const char *srv_name_mask
, time_t new_time
)
582 ioset_set_time(new_time
);
583 if (!strcmp(srv_name_mask
, "*"))
585 putsock("%s " P10_SETTIME
" " FMT_TIME_T
" %s", self
->numeric
, new_time
, srv_name_mask
);
589 irc_ungline(const char *mask
)
591 putsock("%s " P10_GLINE
" * -%s", self
->numeric
, mask
);
595 irc_burst(struct chanNode
*chan
)
597 char burst_line
[512];
598 int pos
, base_len
, len
;
601 struct exemptNode
*en
;
605 base_len
= sprintf(burst_line
, "%s " P10_BURST
" %s " FMT_TIME_T
" ",
606 self
->numeric
, chan
->name
, chan
->timestamp
);
607 len
= irc_make_chanmode(chan
, burst_line
+base_len
);
608 pos
= base_len
+ len
;
610 burst_line
[pos
++] = ' ';
613 for (n
=0; n
<chan
->members
.used
; n
++) {
614 mn
= chan
->members
.list
[n
];
616 burst_line
[pos
-1] = 0; /* -1 to back up over the space or comma */
617 putsock("%s", burst_line
);
621 memcpy(burst_line
+pos
, mn
->user
->numeric
, strlen(mn
->user
->numeric
));
622 pos
+= strlen(mn
->user
->numeric
);
623 if (mn
->modes
&& (mn
->modes
!= last_mode
)) {
624 last_mode
= mn
->modes
;
625 burst_line
[pos
++] = ':';
626 if (last_mode
& MODE_CHANOP
)
627 burst_line
[pos
++] = 'o';
628 if (last_mode
& MODE_HALFOP
)
629 burst_line
[pos
++] = 'h';
630 if (last_mode
& MODE_VOICE
)
631 burst_line
[pos
++] = 'v';
633 if ((n
+1)<chan
->members
.used
)
634 burst_line
[pos
++] = ',';
636 if (chan
->banlist
.used
) {
638 if (pos
+2+strlen(chan
->banlist
.list
[0]->ban
) > 505) {
639 burst_line
[pos
-1] = 0;
640 putsock("%s", burst_line
);
643 burst_line
[pos
++] = ' ';
646 burst_line
[pos
++] = ':';
647 burst_line
[pos
++] = '%';
649 for (n
=0; n
<chan
->banlist
.used
; n
++) {
650 bn
= chan
->banlist
.list
[n
];
651 len
= strlen(bn
->ban
);
652 if (pos
+len
+1 > 510) {
653 burst_line
[pos
-1] = 0; /* -1 to back up over the space or comma */
654 putsock("%s", burst_line
);
657 memcpy(burst_line
+pos
, bn
->ban
, len
);
659 burst_line
[pos
++] = ' ';
662 if (chan
->exemptlist
.used
) {
663 /* dump the exempt */
664 if (pos
+2+strlen(chan
->exemptlist
.list
[0]->exempt
) > 505) {
665 burst_line
[pos
-1] = 0;
666 putsock("%s", burst_line
);
669 burst_line
[pos
++] = ' ';
672 burst_line
[pos
++] = ' ';
673 burst_line
[pos
++] = '~';
674 burst_line
[pos
++] = ' ';
676 for (n
=0; n
<chan
->exemptlist
.used
; n
++) {
677 en
= chan
->exemptlist
.list
[n
];
678 len
= strlen(en
->exempt
);
679 if (pos
+len
+1 > 510) {
680 burst_line
[pos
-1] = 0; /* -1 to back up over the space or comma */
681 putsock("%s", burst_line
);
684 memcpy(burst_line
+pos
, en
->exempt
, len
);
686 burst_line
[pos
++] = ' ';
689 /* print the last line */
691 putsock("%s", burst_line
);
695 irc_quit(struct userNode
*user
, const char *message
)
697 putsock("%s " P10_QUIT
" :%s", user
->numeric
, message
);
701 irc_error(const char *to
, const char *message
)
704 putsock("%s " P10_ERROR
" :%s", to
, message
);
706 putsock(":%s " P10_ERROR
" :%s", self
->name
, message
);
711 irc_kill(struct userNode
*from
, struct userNode
*target
, const char *message
)
714 putsock("%s " P10_KILL
" %s :%s!%s (%s)",
715 from
->numeric
, target
->numeric
, self
->name
, from
->nick
, message
);
717 putsock("%s " P10_KILL
" %s :%s (%s)",
718 self
->numeric
, target
->numeric
, self
->name
, message
);
723 irc_mode(struct userNode
*from
, struct chanNode
*target
, const char *modes
)
725 putsock("%s " P10_MODE
" %s %s "FMT_TIME_T
,
726 (from
? from
->numeric
: self
->numeric
),
727 target
->name
, modes
, target
->timestamp
);
730 /* Added to allow services to mode users
731 2005 - 8 - 10 by Life4Christ
734 irc_umode(struct userNode
*target
, const char *modes
)
736 putsock("%s " P10_MODE
" %s %s ",self
->numeric
,target
->nick
, modes
);
741 irc_invite(struct userNode
*from
, struct userNode
*who
, struct chanNode
*to
)
743 putsock("%s " P10_INVITE
" %s %s", from
->numeric
, who
->nick
, to
->name
);
747 irc_join(struct userNode
*who
, struct chanNode
*what
)
749 if (what
->members
.used
== 1) {
750 putsock("%s " P10_CREATE
" %s %lu",
751 who
->numeric
, what
->name
, what
->timestamp
);
753 putsock("%s " P10_JOIN
" %s %lu", who
->numeric
, what
->name
, what
->timestamp
);
758 irc_kick(struct userNode
*who
, struct userNode
*target
, struct chanNode
*channel
, const char *msg
)
761 struct modeNode
*mn
= GetUserMode(channel
, who
);
762 numeric
= ((mn
&& (mn
->modes
& MODE_CHANOP
)) || off_channel
) ? who
->numeric
: self
->numeric
;
763 putsock("%s " P10_KICK
" %s %s :%s",
764 numeric
, channel
->name
, target
->numeric
, msg
);
768 irc_stats(struct userNode
*from
, struct server
*target
, char type
)
770 putsock("%s " P10_STATS
" %c :%s", from
->numeric
, type
, target
->numeric
);
774 irc_svsnick(struct userNode
*from
, struct userNode
*target
, const char *newnick
)
776 putsock("%s " P10_SVSNICK
" %s %s "FMT_TIME_T
, from
->uplink
->numeric
, target
->numeric
, newnick
, now
);
780 irc_part(struct userNode
*who
, struct chanNode
*what
, const char *reason
)
783 putsock("%s " P10_PART
" %s :%s", who
->numeric
, what
->name
, reason
);
785 putsock("%s " P10_PART
" %s", who
->numeric
, what
->name
);
790 irc_topic(struct userNode
*who
, struct chanNode
*what
, const char *topic
)
792 putsock("%s " P10_TOPIC
" %s :%s", who
->numeric
, what
->name
, topic
);
796 irc_raw(const char *what
)
802 irc_numeric(struct userNode
*user
, unsigned int num
, const char *format
, ...)
806 va_start(arg_list
, format
);
807 vsnprintf(buffer
, MAXLEN
-2, format
, arg_list
);
808 buffer
[MAXLEN
-1] = 0;
809 putsock(":%s %03d %s %s", self
->name
, num
, user
->nick
, buffer
);
812 static void send_burst(void);
815 change_nicklen(int new_nicklen
)
818 char new_nick
[NICKLEN
+1];
819 struct userNode
*user
;
821 nicklen
= new_nicklen
;
822 /* fix up any users we have here */
823 for (nn
=0; nn
<=self
->num_mask
; nn
++) {
824 if (!(user
= self
->users
[nn
]))
826 safestrncpy(new_nick
, user
->nick
, sizeof(new_nick
));
827 new_nick
[nicklen
] = 0;
828 NickChange(user
, new_nick
, 1);
832 static CMD_FUNC(cmd_whois
)
834 struct userNode
*from
;
835 struct userNode
*who
;
839 if (!(from
= GetUserH(origin
))) {
840 log_module(MAIN_LOG
, LOG_ERROR
, "Could not find WHOIS origin user %s", origin
);
843 if(!(who
= GetUserH(argv
[2]))) {
844 irc_numeric(from
, ERR_NOSUCHNICK
, "%s@%s :No such nick", argv
[2], self
->name
);
847 if (IsHiddenHost(who
) && !IsOper(from
)) {
848 /* Just stay quiet. */
851 irc_numeric(from
, RPL_WHOISUSER
, "%s %s %s * :%s", who
->nick
, who
->ident
, who
->hostname
, who
->info
);
852 if (his_servername
&& his_servercomment
)
853 irc_numeric(from
, RPL_WHOISSERVER
, "%s %s :%s", who
->nick
, his_servername
, his_servercomment
);
855 irc_numeric(from
, RPL_WHOISSERVER
, "%s %s :%s", who
->nick
, who
->uplink
->name
, who
->uplink
->description
);
857 irc_numeric(from
, RPL_WHOISOPERATOR
, "%s :is a megalomaniacal power hungry tyrant", who
->nick
);
858 irc_numeric(from
, RPL_ENDOFWHOIS
, "%s :End of /WHOIS list", who
->nick
);
862 static CMD_FUNC(cmd_server
)
870 /* another server introduced us */
871 srv
= AddServer(GetServerH(origin
), argv
[1], atoi(argv
[2]), atoi(argv
[3]), atoi(argv
[4]), argv
[6], argv
[argc
-1]);
874 srv
->self_burst
= argv
[5][0] == 'J';
877 /* this must be our uplink */
878 srv
= self
->uplink
= AddServer(self
, argv
[1], atoi(argv
[2]), atoi(argv
[3]), atoi(argv
[4]), argv
[6], argv
[argc
-1]);
881 srv
->self_burst
= argv
[5][0] == 'J';
883 if ((argv
[7][0] == '+') && !force_n2k
) {
884 log_module(MAIN_LOG
, LOG_WARNING
, "Got Undernet-style SERVER message but \"force_n2k\" not on.");
889 /* Fix up our timestamps if necessary. */
890 if (srv
->boot
<= PREHISTORY
) {
891 /* Server from the mists of time.. */
892 if (srv
->hops
== 1) {
893 log_module(MAIN_LOG
, LOG_ERROR
, "Server %s claims to have booted at time "FMT_TIME_T
". This is absurd.", srv
->name
, srv
->boot
);
895 } else if ((str
= conf_get_data("server/reliable_clock", RECDB_QSTRING
))
896 && enabled_string(str
)) {
897 /* If we have a reliable clock, we just keep our current time. */
899 if (srv
->boot
<= self
->boot
) {
900 /* The other server is older than us. Accept their timestamp.
901 * Alternately, we are same age, but we accept their time
902 * since we are linking to them. */
903 self
->boot
= srv
->boot
;
904 ioset_set_time(srv
->link
);
907 if (srv
== self
->uplink
) {
908 extern time_t burst_begin
;
914 static CMD_FUNC(cmd_eob
)
916 struct server
*sender
;
920 if (!(sender
= GetServerH(origin
)))
922 if (sender
== self
->uplink
) {
923 cManager
.uplink
->state
= CONNECTED
;
924 for (it
= dict_first(unbursted_channels
); it
; it
= iter_next(it
))
925 irc_burst(iter_data(it
));
926 dict_delete(unbursted_channels
);
927 unbursted_channels
= NULL
;
931 sender
->self_burst
= 0;
932 recalc_bursts(sender
);
933 for (ii
=0; ii
<slf_used
; ii
++)
934 slf_list
[ii
](sender
);
938 static CMD_FUNC(cmd_eob_ack
)
940 extern time_t burst_begin
;
942 if (GetServerH(origin
) == self
->uplink
) {
943 burst_length
= now
- burst_begin
;
944 self
->self_burst
= self
->burst
= 0;
946 cManager
.uplink
->state
= CONNECTED
;
950 static CMD_FUNC(cmd_ping
)
956 irc_pong(argv
[2], argv
[1]);
957 else if ((srv
= GetServerH(origin
)))
958 irc_pong(self
->name
, srv
->numeric
);
959 else if ((un
= GetUserH(origin
)))
960 irc_pong(self
->name
, un
->numeric
);
962 irc_pong(self
->name
, origin
);
964 timeq_del(0, timed_send_ping
, 0, TIMEQ_IGNORE_WHEN
|TIMEQ_IGNORE_DATA
);
965 timeq_del(0, timed_ping_timeout
, 0, TIMEQ_IGNORE_WHEN
|TIMEQ_IGNORE_DATA
);
966 timeq_add(now
+ ping_freq
, timed_send_ping
, 0);
971 static CMD_FUNC(cmd_error_nick
)
973 /* Go back to original IRC length .. and try to reconnect :/ */
975 irc_squit(self
, "Got erroneous nickname, truncating nicks.", NULL
);
980 struct userNode
*user
;
985 join_helper(struct chanNode
*chan
, void *data
)
987 struct create_desc
*cd
= data
;
988 AddChannelUser(cd
->user
, chan
);
992 create_helper(char *name
, void *data
)
994 struct create_desc
*cd
= data
;
996 if (!strcmp(name
, "0")) {
997 while (cd
->user
->channels
.used
> 0)
998 DelChannelUser(cd
->user
, cd
->user
->channels
.list
[0]->channel
, 0, 0);
1002 AddChannelUser(cd
->user
, AddChannel(name
, cd
->when
, NULL
, NULL
, NULL
));
1005 static CMD_FUNC(cmd_create
)
1007 struct create_desc cd
;
1008 struct userNode
*user
;
1010 if ((argc
< 3) || !(user
= GetUserH(origin
)))
1013 cd
.when
= atoi(argv
[2]);
1014 parse_foreach(argv
[1], join_helper
, create_helper
, NULL
, NULL
, &cd
);
1018 static CMD_FUNC(cmd_join
)
1020 struct create_desc cd
;
1022 if (!(cd
.user
= GetUserH(origin
)))
1029 cd
.when
= atoi(argv
[2]);
1030 parse_foreach(argv
[1], join_helper
, create_helper
, NULL
, NULL
, &cd
);
1034 static CMD_FUNC(cmd_pong
)
1038 if (!strcmp(argv
[2], self
->name
)) {
1039 timeq_del(0, timed_send_ping
, 0, TIMEQ_IGNORE_WHEN
|TIMEQ_IGNORE_DATA
);
1040 timeq_del(0, timed_ping_timeout
, 0, TIMEQ_IGNORE_WHEN
|TIMEQ_IGNORE_DATA
);
1041 timeq_add(now
+ ping_freq
, timed_send_ping
, 0);
1047 static CMD_FUNC(cmd_nick
)
1049 struct userNode
*user
;
1050 if ((user
= GetUserH(origin
))) {
1051 /* nick change (since the source is a user numeric) */
1054 NickChange(user
, argv
[1], 1);
1056 struct server
*serv
;
1061 serv
= GetServerH(origin
);
1063 unsplit_string(argv
+6, argc
-9, modes
);
1066 AddUser(serv
, argv
[1], argv
[4], argv
[5], modes
, argv
[argc
-2], argv
[argc
-1], atoi(argv
[3]), argv
[argc
-3]);
1071 static CMD_FUNC(cmd_account
)
1073 struct userNode
*user
;
1074 struct server
*server
;
1075 struct handle_info
*hi
;
1077 if ((argc
< 3) || !origin
|| !(server
= GetServerH(origin
)))
1078 return 0; /* Origin must be server. */
1080 /* This next line appears to tremple origin.. why? */
1081 user
= GetUserN(argv
[1]);
1083 return 1; /* A QUIT probably passed the ACCOUNT. */
1085 if(!strcmp(argv
[2],"C"))
1087 if((hi
= loc_auth(argv
[4], argv
[5])))
1090 putsock("%s " P10_ACCOUNT
" %s A %s %lu", self
->numeric
, server
->numeric
, argv
[3], hi
->registered
);
1096 putsock("%s " P10_ACCOUNT
" %s D %s", self
->numeric
, server
->numeric
, argv
[3]);
1100 else if(!strcmp(argv
[2],"R"))
1101 call_account_func(user
, argv
[3]);
1103 call_account_func(user
, argv
[2]); /* For backward compatability */
1107 static CMD_FUNC(cmd_fakehost
)
1109 struct userNode
*user
;
1111 if ((argc
< 3) || !origin
|| !GetServerH(origin
))
1113 if (!(user
= GetUserN(argv
[1])))
1115 assign_fakehost(user
, argv
[2], 0);
1119 static CMD_FUNC(cmd_burst
)
1122 char modes
[MAXLEN
], *members
= "";
1123 static char exemptlist
[MAXLEN
], banlist
[MAXLEN
];
1124 unsigned int next
= 3, res
= 1;
1125 int ctype
= 0, echeck
= 0, bcheck
= 0;
1126 struct chanNode
*cNode
;
1127 struct userNode
*un
;
1128 struct modeNode
*mNode
;
1130 char *user
, *end
, sep
;
1131 time_t in_timestamp
;
1141 while (next
< argc
) {
1142 switch (argv
[next
][0]) {
1146 for (pos
=argv
[next
], n_modes
= 1; *pos
; pos
++)
1147 if ((*pos
== 'k') || (*pos
== 'l'))
1149 unsplit_string(argv
+next
, n_modes
, modes
);
1154 for(parm
= mysep(&argv
[next
], " "); /* parm = first param */
1155 parm
; /* While param is not null */
1156 parm
= mysep(&argv
[next
], " ") /* parm = next param */
1174 /* strip % char off start of very first ban */
1175 if (strlen(parm
) > 1) {
1176 strncat(banlist
, strtok(parm
, "%"), sizeof(banlist
) - 1 - strlen(banlist
));
1177 strncat(banlist
, " ", sizeof(banlist
) - 1 - strlen(banlist
));
1181 strncat(banlist
, parm
, sizeof(banlist
) - 1 - strlen(banlist
));
1182 strncat(banlist
, " ", sizeof(banlist
) - 1 - strlen(banlist
));
1184 } else if (ctype
== 2) {
1188 strncat(exemptlist
, parm
, sizeof(exemptlist
) - 1 - strlen(exemptlist
));
1189 strncat(exemptlist
, " ", sizeof(exemptlist
) - 1 - strlen(exemptlist
));
1196 default: members
= argv
[next
++]; break;
1200 in_timestamp
= atoi(argv
[2]);
1201 if ((cNode
= dict_find(unbursted_channels
, argv
[1], NULL
))) {
1202 cNode
->timestamp
= in_timestamp
;
1203 dict_remove(unbursted_channels
, cNode
->name
);
1206 cNode
= AddChannel(argv
[1], in_timestamp
, modes
, banlist
, exemptlist
);
1208 /* Burst channel members in now. */
1209 for (user
= members
, sep
= *members
, mode
= 0; sep
; user
= end
) {
1210 for (end
= user
+ 3; isalnum(*end
) || *end
== '[' || *end
== ']'; end
++) ;
1211 sep
= *end
++; end
[-1] = 0;
1214 while ((sep
= *end
++)) {
1216 mode
|= MODE_CHANOP
;
1217 else if (sep
== 'h')
1218 mode
|= MODE_HALFOP
;
1219 else if (sep
== 'v')
1221 else if (isdigit(sep
)) {
1222 mode
|= MODE_CHANOP
;
1223 while (isdigit(*end
)) end
++;
1230 if (!(un
= GetUserN(user
))) {
1234 if ((mNode
= AddChannelUser(un
, cNode
)))
1235 mNode
->modes
= mode
;
1241 static CMD_FUNC(cmd_mode
)
1243 struct chanNode
*cn
;
1244 struct userNode
*un
;
1245 char *sethost
; // sethost - reed/apples
1246 int i
; // sethost - reed/apples
1250 if (!IsChannelName(argv
[1])) {
1251 un
= GetUserH(argv
[1]);
1253 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to find user %s whose mode is changing.", argv
[1]);
1256 // sethost - reed/apples
1258 mod_usermode(un
, argv
[2]);
1260 sethost
= malloc(strlen(argv
[2]) + 1 + strlen(argv
[3]) + 1);
1262 while((sethost
[i
++] = *argv
[2]++));
1265 while((sethost
[i
++] = *argv
[3]++));
1266 mod_usermode(un
, sethost
); // sethost - reed/apples
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 struct modeNode
*mn
;
1278 /* Update idle time for person setting the mode */
1279 if ((mn
= GetUserMode(cn
, un
)))
1280 mn
->idle_since
= now
;
1282 /* If it came from a server, reset timestamp to re-sync. */
1283 cn
->timestamp
= atoi(argv
[argc
-1]);
1286 return mod_chanmode(un
, cn
, argv
+2, argc
-2, MCP_ALLOW_OVB
|MCP_FROM_SERVER
|(un
? MC_NOTIFY
: 0));
1289 static CMD_FUNC(cmd_opmode
)
1291 struct chanNode
*cn
;
1292 struct userNode
*un
;
1297 if (!(cn
= GetChannel(argv
[1]))) {
1298 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to find channel %s whose mode is changing.", argv
[1]);
1301 if (!(un
= GetUserH(origin
))) {
1302 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to find user %s requesting OPMODE.", origin
);
1306 log_module(MAIN_LOG
, LOG_ERROR
, "Non-privileged user %s using OPMODE.", un
->nick
);
1310 return mod_chanmode(un
, cn
, argv
+2, argc
-2, MCP_ALLOW_OVB
|MCP_FROM_SERVER
); /* do NOT announce opmode locally */
1313 static int clear_chanmode(struct chanNode
*channel
, const char *modes
);
1315 static CMD_FUNC(cmd_clearmode
)
1317 struct chanNode
*cn
;
1318 struct userNode
*un
;
1323 if (!(cn
= GetChannel(argv
[1]))) {
1324 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to find channel %s whose mode is changing.", argv
[1]);
1327 if (!(un
= GetUserH(origin
))) {
1328 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to find user %s requesting CLEARMODE.", origin
);
1332 log_module(MAIN_LOG
, LOG_ERROR
, "Non-privileged user %s using CLEARMODE.", un
->nick
);
1336 return clear_chanmode(cn
, argv
[2]);
1339 static CMD_FUNC(cmd_topic
)
1341 struct chanNode
*cn
;
1342 time_t chan_ts
, topic_ts
;
1346 if (!(cn
= GetChannel(argv
[1]))) {
1347 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to find channel %s whose topic is being set", argv
[1]);
1351 /* Looks like an Asuka style topic burst. */
1352 chan_ts
= atoi(argv
[2]);
1353 topic_ts
= atoi(argv
[3]);
1355 chan_ts
= cn
->timestamp
;
1358 SetChannelTopic(cn
, GetUserH(origin
), argv
[argc
-1], 0);
1359 cn
->topic_time
= topic_ts
;
1363 static CMD_FUNC(cmd_num_topic
)
1365 struct chanNode
*cn
;
1368 return 0; /* huh? */
1370 cn
= GetChannel(argv
[2]);
1372 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to find channel %s in topic reply", argv
[2]);
1378 switch (atoi(argv
[0])) {
1381 break; /* no topic */
1385 safestrncpy(cn
->topic
, unsplit_string(argv
+3, argc
-3, NULL
), sizeof(cn
->topic
));
1390 safestrncpy(cn
->topic_nick
, argv
[3], sizeof(cn
->topic_nick
));
1391 cn
->topic_time
= atoi(argv
[4]);
1394 return 0; /* should never happen */
1399 static CMD_FUNC(cmd_num_gline
)
1403 gline_add(origin
, argv
[3], atoi(argv
[4])-now
, argv
[5], now
, 0);
1407 static CMD_FUNC(cmd_quit
)
1409 struct userNode
*user
;
1412 /* Sometimes we get a KILL then a QUIT or the like, so we don't want to
1413 * call DelUser unless we have the user in our grasp. */
1414 if ((user
= GetUserH(origin
)))
1415 DelUser(user
, NULL
, false, argv
[1]);
1419 static CMD_FUNC(cmd_kill
)
1421 struct userNode
*user
;
1424 user
= GetUserN(argv
[1]);
1426 /* If we get a KILL for a non-existent user, it could be a
1427 * Ghost response to a KILL we sent out earlier. So we only
1428 * whine if the target is local.
1430 if (!strncmp(argv
[1], self
->numeric
, strlen(self
->numeric
)))
1431 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to find kill victim %s", argv
[1]);
1435 if (IsLocal(user
) && IsService(user
)) {
1436 /* TODO: rate limit this so silly things don't happen. */
1437 ReintroduceUser(user
);
1441 DelUser(user
, NULL
, false, argv
[2]);
1445 static CMD_FUNC(cmd_part
)
1447 struct userNode
*user
;
1451 user
= GetUserH(origin
);
1454 parse_foreach(argv
[1], part_helper
, NULL
, NULL
, NULL
, user
);
1458 static CMD_FUNC(cmd_kick
)
1462 ChannelUserKicked(GetUserH(origin
), GetUserN(argv
[2]), GetChannel(argv
[1]));
1466 static CMD_FUNC(cmd_squit
)
1468 struct server
*server
;
1472 if (!(server
= GetServerH(argv
[1])))
1475 if (server
== self
->uplink
) {
1476 /* Force a reconnect to the currently selected server. */
1477 cManager
.uplink
->tries
= 0;
1478 log_module(MAIN_LOG
, LOG_INFO
, "Squitting from uplink: %s", argv
[3]);
1483 DelServer(server
, 0, argv
[3]);
1487 static CMD_FUNC(cmd_privmsg
)
1489 struct privmsg_desc pd
;
1492 pd
.user
= GetUserH(origin
);
1493 if (!pd
.user
|| (IsGagged(pd
.user
) && !IsOper(pd
.user
)))
1497 parse_foreach(argv
[1], privmsg_chan_helper
, NULL
, privmsg_user_helper
, privmsg_invalid
, &pd
);
1501 static CMD_FUNC(cmd_notice
)
1503 struct privmsg_desc pd
;
1506 pd
.user
= GetUserH(origin
);
1507 if (!pd
.user
|| (IsGagged(pd
.user
) && !IsOper(pd
.user
)))
1511 parse_foreach(argv
[1], privmsg_chan_helper
, NULL
, privmsg_user_helper
, privmsg_invalid
, &pd
);
1515 static CMD_FUNC(cmd_away
)
1517 struct userNode
*uNode
;
1519 uNode
= GetUserH(origin
);
1523 uNode
->modes
&= ~FLAGS_AWAY
;
1525 uNode
->modes
|= FLAGS_AWAY
;
1529 static CMD_FUNC(cmd_gline
)
1533 if (argv
[2][0] == '+') {
1536 gline_add(origin
, argv
[2]+1, strtoul(argv
[3], NULL
, 0), argv
[argc
-1], now
, 0);
1538 } else if (argv
[2][0] == '-') {
1539 gline_remove(argv
[2]+1, 0);
1545 static CMD_FUNC(cmd_svsnick
)
1547 struct userNode
*target
, *dest
;
1549 || !(target
= GetUserN(argv
[1]))
1551 || (dest
= GetUserH(argv
[2])))
1553 NickChange(target
, argv
[2], 0);
1557 static oper_func_t
*of_list
;
1558 static unsigned int of_size
= 0, of_used
= 0;
1561 free_user(struct userNode
*user
)
1572 free(privmsg_funcs
);
1575 dict_delete(irc_func_dict
);
1576 for (nn
=0; nn
<dead_users
.used
; nn
++)
1577 free_user(dead_users
.list
[nn
]);
1578 userList_clean(&dead_users
);
1582 p10_conf_reload(void) {
1583 hidden_host_suffix
= conf_get_data("server/hidden_host", RECDB_QSTRING
);
1587 remove_unbursted_channel(struct chanNode
*cNode
) {
1588 if (unbursted_channels
)
1589 dict_remove(unbursted_channels
, cNode
->name
);
1595 const char *str
, *desc
;
1596 int numnick
, usermask
, max_users
;
1597 char numer
[COMBO_NUMERIC_LEN
+1];
1599 /* read config items */
1600 str
= conf_get_data("server/ping_freq", RECDB_QSTRING
);
1601 ping_freq
= str
? ParseInterval(str
) : 120;
1602 str
= conf_get_data("server/ping_timeout", RECDB_QSTRING
);
1603 ping_timeout
= str
? ParseInterval(str
) : 30;
1604 str
= conf_get_data("server/force_n2k", RECDB_QSTRING
);
1605 force_n2k
= str
? enabled_string(str
) : 1;
1606 str
= conf_get_data("server/numeric", RECDB_QSTRING
);
1608 log_module(MAIN_LOG
, LOG_ERROR
, "No server/numeric entry in config file.");
1611 numnick
= atoi(str
);
1612 str
= conf_get_data("server/max_users", RECDB_QSTRING
);
1613 max_users
= str
? atoi(str
) : 4096;
1614 for (usermask
= 4; usermask
< max_users
; usermask
<<= 1) ;
1616 if ((numnick
< 64) && (usermask
< 4096) && !force_n2k
)
1617 inttobase64(numer
, (numnick
<< 12) + (usermask
& 0x00fff), 3);
1619 inttobase64(numer
, (numnick
<< 18) + (usermask
& 0x3ffff), 5);
1621 str
= conf_get_data("server/his_servername", RECDB_QSTRING
);
1622 his_servername
= str
? strdup(str
) : NULL
;
1623 str
= conf_get_data("server/his_servercomment", RECDB_QSTRING
);
1624 his_servercomment
= str
? strdup(str
) : NULL
;
1626 str
= conf_get_data("server/hostname", RECDB_QSTRING
);
1627 desc
= conf_get_data("server/description", RECDB_QSTRING
);
1628 if (!str
|| !desc
) {
1629 log_module(MAIN_LOG
, LOG_ERROR
, "No server/hostname entry in config file.");
1632 self
= AddServer(NULL
, str
, 0, boot_time
, now
, numer
, desc
);
1633 conf_register_reload(p10_conf_reload
);
1635 irc_func_dict
= dict_new();
1636 dict_insert(irc_func_dict
, CMD_BURST
, cmd_burst
);
1637 dict_insert(irc_func_dict
, TOK_BURST
, cmd_burst
);
1638 dict_insert(irc_func_dict
, CMD_CREATE
, cmd_create
);
1639 dict_insert(irc_func_dict
, TOK_CREATE
, cmd_create
);
1640 dict_insert(irc_func_dict
, CMD_EOB
, cmd_eob
);
1641 dict_insert(irc_func_dict
, TOK_EOB
, cmd_eob
);
1642 dict_insert(irc_func_dict
, CMD_EOB_ACK
, cmd_eob_ack
);
1643 dict_insert(irc_func_dict
, TOK_EOB_ACK
, cmd_eob_ack
);
1644 dict_insert(irc_func_dict
, CMD_MODE
, cmd_mode
);
1645 dict_insert(irc_func_dict
, TOK_MODE
, cmd_mode
);
1646 dict_insert(irc_func_dict
, CMD_NICK
, cmd_nick
);
1647 dict_insert(irc_func_dict
, TOK_NICK
, cmd_nick
);
1648 dict_insert(irc_func_dict
, CMD_ACCOUNT
, cmd_account
);
1649 dict_insert(irc_func_dict
, TOK_ACCOUNT
, cmd_account
);
1650 dict_insert(irc_func_dict
, CMD_FAKEHOST
, cmd_fakehost
);
1651 dict_insert(irc_func_dict
, TOK_FAKEHOST
, cmd_fakehost
);
1652 dict_insert(irc_func_dict
, CMD_PASS
, cmd_pass
);
1653 dict_insert(irc_func_dict
, TOK_PASS
, cmd_pass
);
1654 dict_insert(irc_func_dict
, CMD_PING
, cmd_ping
);
1655 dict_insert(irc_func_dict
, TOK_PING
, cmd_ping
);
1656 dict_insert(irc_func_dict
, CMD_PRIVMSG
, cmd_privmsg
);
1657 dict_insert(irc_func_dict
, TOK_PRIVMSG
, cmd_privmsg
);
1658 dict_insert(irc_func_dict
, CMD_PONG
, cmd_pong
);
1659 dict_insert(irc_func_dict
, TOK_PONG
, cmd_pong
);
1660 dict_insert(irc_func_dict
, CMD_QUIT
, cmd_quit
);
1661 dict_insert(irc_func_dict
, TOK_QUIT
, cmd_quit
);
1662 dict_insert(irc_func_dict
, CMD_SERVER
, cmd_server
);
1663 dict_insert(irc_func_dict
, TOK_SERVER
, cmd_server
);
1664 dict_insert(irc_func_dict
, CMD_JOIN
, cmd_join
);
1665 dict_insert(irc_func_dict
, TOK_JOIN
, cmd_join
);
1666 dict_insert(irc_func_dict
, CMD_PART
, cmd_part
);
1667 dict_insert(irc_func_dict
, TOK_PART
, cmd_part
);
1668 dict_insert(irc_func_dict
, CMD_ERROR
, cmd_error
);
1669 dict_insert(irc_func_dict
, TOK_ERROR
, cmd_error
);
1670 dict_insert(irc_func_dict
, CMD_TOPIC
, cmd_topic
);
1671 dict_insert(irc_func_dict
, TOK_TOPIC
, cmd_topic
);
1672 dict_insert(irc_func_dict
, CMD_AWAY
, cmd_away
);
1673 dict_insert(irc_func_dict
, TOK_AWAY
, cmd_away
);
1674 dict_insert(irc_func_dict
, CMD_SILENCE
, cmd_dummy
);
1675 dict_insert(irc_func_dict
, TOK_SILENCE
, cmd_dummy
);
1676 dict_insert(irc_func_dict
, CMD_KICK
, cmd_kick
);
1677 dict_insert(irc_func_dict
, TOK_KICK
, cmd_kick
);
1678 dict_insert(irc_func_dict
, CMD_SQUIT
, cmd_squit
);
1679 dict_insert(irc_func_dict
, TOK_SQUIT
, cmd_squit
);
1680 dict_insert(irc_func_dict
, CMD_KILL
, cmd_kill
);
1681 dict_insert(irc_func_dict
, TOK_KILL
, cmd_kill
);
1682 dict_insert(irc_func_dict
, CMD_NOTICE
, cmd_notice
);
1683 dict_insert(irc_func_dict
, TOK_NOTICE
, cmd_notice
);
1684 dict_insert(irc_func_dict
, CMD_STATS
, cmd_stats
);
1685 dict_insert(irc_func_dict
, TOK_STATS
, cmd_stats
);
1686 dict_insert(irc_func_dict
, CMD_SVSNICK
, cmd_svsnick
);
1687 dict_insert(irc_func_dict
, TOK_SVSNICK
, cmd_svsnick
);
1688 dict_insert(irc_func_dict
, CMD_WHOIS
, cmd_whois
);
1689 dict_insert(irc_func_dict
, TOK_WHOIS
, cmd_whois
);
1690 dict_insert(irc_func_dict
, CMD_GLINE
, cmd_gline
);
1691 dict_insert(irc_func_dict
, TOK_GLINE
, cmd_gline
);
1692 dict_insert(irc_func_dict
, CMD_OPMODE
, cmd_opmode
);
1693 dict_insert(irc_func_dict
, TOK_OPMODE
, cmd_opmode
);
1694 dict_insert(irc_func_dict
, CMD_CLEARMODE
, cmd_clearmode
);
1695 dict_insert(irc_func_dict
, TOK_CLEARMODE
, cmd_clearmode
);
1696 dict_insert(irc_func_dict
, CMD_VERSION
, cmd_version
);
1697 dict_insert(irc_func_dict
, TOK_VERSION
, cmd_version
);
1698 dict_insert(irc_func_dict
, CMD_ADMIN
, cmd_admin
);
1699 dict_insert(irc_func_dict
, TOK_ADMIN
, cmd_admin
);
1701 /* In P10, DESTRUCT doesn't do anything except be broadcast to servers.
1702 * Apparently to obliterate channels from any servers that think they
1705 dict_insert(irc_func_dict
, CMD_DESTRUCT
, cmd_dummy
);
1706 dict_insert(irc_func_dict
, TOK_DESTRUCT
, cmd_dummy
);
1707 /* Ignore invites */
1708 dict_insert(irc_func_dict
, CMD_INVITE
, cmd_dummy
);
1709 dict_insert(irc_func_dict
, TOK_INVITE
, cmd_dummy
);
1710 /* DESYNCH is just informational, so ignore it */
1711 dict_insert(irc_func_dict
, CMD_DESYNCH
, cmd_dummy
);
1712 dict_insert(irc_func_dict
, TOK_DESYNCH
, cmd_dummy
);
1713 /* Ignore channel operator notices. */
1714 dict_insert(irc_func_dict
, CMD_WALLCHOPS
, cmd_dummy
);
1715 dict_insert(irc_func_dict
, TOK_WALLCHOPS
, cmd_dummy
);
1716 dict_insert(irc_func_dict
, CMD_WALLVOICES
, cmd_dummy
);
1717 dict_insert(irc_func_dict
, TOK_WALLVOICES
, cmd_dummy
);
1718 dict_insert(irc_func_dict
, CMD_WALLHOPS
, cmd_dummy
);
1719 dict_insert(irc_func_dict
, TOK_WALLHOPS
, cmd_dummy
);
1720 /* Ignore opers being silly. */
1721 dict_insert(irc_func_dict
, CMD_WALLOPS
, cmd_dummy
);
1722 dict_insert(irc_func_dict
, TOK_WALLOPS
, cmd_dummy
);
1723 dict_insert(irc_func_dict
, CMD_WALLHOPS
, cmd_dummy
);
1724 dict_insert(irc_func_dict
, TOK_WALLHOPS
, cmd_dummy
);
1725 dict_insert(irc_func_dict
, TOK_WALLUSERS
, cmd_dummy
);
1726 /* Ignore dnsbl exemptions */
1727 dict_insert(irc_func_dict
, TOK_EXEMPT
, cmd_dummy
);
1728 dict_insert(irc_func_dict
, TOK_MARK
, cmd_dummy
);
1730 dict_insert(irc_func_dict
, TOK_PRIVS
, cmd_dummy
);
1731 /* Ignore remote luser */
1732 dict_insert(irc_func_dict
, TOK_LUSERS
, cmd_dummy
);
1733 /* We have reliable clock! Always! Wraaa! */
1734 dict_insert(irc_func_dict
, CMD_SETTIME
, cmd_dummy
);
1735 dict_insert(irc_func_dict
, TOK_SETTIME
, cmd_dummy
);
1737 dict_insert(irc_func_dict
, "331", cmd_num_topic
);
1738 dict_insert(irc_func_dict
, "332", cmd_num_topic
);
1739 dict_insert(irc_func_dict
, "333", cmd_num_topic
);
1740 dict_insert(irc_func_dict
, "345", cmd_dummy
); /* blah has been invited to blah */
1741 dict_insert(irc_func_dict
, "432", cmd_error_nick
); /* Erroneus [sic] nickname */
1742 /* ban list resetting */
1743 /* "stats g" responses */
1744 dict_insert(irc_func_dict
, "247", cmd_num_gline
);
1745 dict_insert(irc_func_dict
, "219", cmd_dummy
); /* "End of /STATS report" */
1746 /* other numeric responses we might get */
1747 dict_insert(irc_func_dict
, "401", cmd_dummy
); /* target left network */
1748 dict_insert(irc_func_dict
, "403", cmd_dummy
); /* no such channel */
1749 dict_insert(irc_func_dict
, "404", cmd_dummy
); /* cannot send to channel */
1750 dict_insert(irc_func_dict
, "439", cmd_dummy
); /* target change too fast */
1751 dict_insert(irc_func_dict
, "441", cmd_dummy
); /* target isn't on that channel */
1752 dict_insert(irc_func_dict
, "442", cmd_dummy
); /* you aren't on that channel */
1753 dict_insert(irc_func_dict
, "443", cmd_dummy
); /* is already on channel (after invite?) */
1754 dict_insert(irc_func_dict
, "461", cmd_dummy
); /* Not enough parameters (after TOPIC w/ 0 args) */
1755 dict_insert(irc_func_dict
, "467", cmd_dummy
); /* Channel key already set */
1757 num_privmsg_funcs
= 16;
1758 privmsg_funcs
= malloc(sizeof(privmsg_func_t
)*num_privmsg_funcs
);
1759 memset(privmsg_funcs
, 0, sizeof(privmsg_func_t
)*num_privmsg_funcs
);
1761 num_notice_funcs
= 16;
1762 notice_funcs
= malloc(sizeof(privmsg_func_t
)*num_notice_funcs
);
1763 memset(notice_funcs
, 0, sizeof(privmsg_func_t
)*num_notice_funcs
);
1765 userList_init(&dead_users
);
1766 reg_del_channel_func(remove_unbursted_channel
);
1767 reg_exit_func(parse_cleanup
);
1771 parse_line(char *line
, int recursive
)
1773 char *argv
[MAXNUMPARAMS
], *origin
;
1774 int argc
, cmd
, res
=0;
1777 argc
= split_line(line
, true, MAXNUMPARAMS
, argv
);
1778 cmd
= self
->uplink
|| !argv
[0][1] || !argv
[0][2];
1781 if (argv
[0][0] == ':') {
1783 } else if (!argv
[0][1] || !argv
[0][2]) {
1784 struct server
*sNode
= GetServerN(argv
[0]);
1785 origin
= sNode
? sNode
->name
: 0;
1787 struct userNode
*uNode
= GetUserN(argv
[0]);
1788 origin
= uNode
? uNode
->nick
: 0;
1792 if ((func
= dict_find(irc_func_dict
, argv
[cmd
], NULL
)))
1793 res
= func(origin
, argc
-cmd
, argv
+cmd
);
1796 log_module(MAIN_LOG
, LOG_ERROR
, "PARSE ERROR on line: %s", unsplit_string(argv
, argc
, NULL
));
1797 } else if (!recursive
) {
1799 for (i
=0; i
<dead_users
.used
; i
++)
1800 free_user(dead_users
.list
[i
]);
1801 dead_users
.used
= 0;
1807 parse_foreach(char *target_list
, foreach_chanfunc cf
, foreach_nonchan nc
, foreach_userfunc uf
, foreach_nonuser nu
, void *data
)
1812 while (*j
!= 0 && *j
!= ',')
1816 if (IsChannelName(target_list
)
1817 || (target_list
[0] == '0' && target_list
[1] == '\0')) {
1818 struct chanNode
*chan
= GetChannel(target_list
);
1824 nc(target_list
, data
);
1827 struct userNode
*user
;
1828 struct privmsg_desc
*pd
= data
;
1830 pd
->is_qualified
= 0;
1831 if (*target_list
== '@') {
1833 } else if (strchr(target_list
, '@')) {
1834 struct server
*server
;
1836 pd
->is_qualified
= 1;
1837 user
= GetUserH(strtok(target_list
, "@"));
1838 server
= GetServerH(strtok(NULL
, "@"));
1840 if (user
&& (user
->uplink
!= server
)) {
1841 /* Don't attempt to index into any arrays
1842 using a user's numeric on another server. */
1846 user
= GetUserN(target_list
);
1854 nu(target_list
, data
);
1858 } while (old
== ',');
1862 get_local_numeric(void)
1864 static unsigned int next_numeric
= 0;
1865 if (self
->clients
> self
->num_mask
)
1867 while (self
->users
[next_numeric
])
1868 if (++next_numeric
> self
->num_mask
)
1870 return next_numeric
;
1874 make_numeric(struct server
*svr
, int local_num
, char *outbuf
)
1878 if (force_n2k
|| svr
->numeric
[1]) {
1883 llen
= (local_num
< 64*64) ? 2 : 3;
1885 strncpy(outbuf
, svr
->numeric
, slen
);
1886 inttobase64(outbuf
+slen
, local_num
, llen
);
1887 outbuf
[slen
+llen
] = 0;
1891 AddServer(struct server
*uplink
, const char *name
, int hops
, time_t boot
, time_t link
, const char *numeric
, const char *description
)
1893 struct server
* sNode
;
1896 if ((sNode
= GetServerN(numeric
))) {
1897 /* This means we're trying to re-add an existant server.
1898 * To be safe, we should forget the previous incarnation.
1899 * (And all its linked servers.)
1901 * It usually only happens in replays when the original
1902 * had a ping timeout and the replay didn't (because
1903 * replaying a ping timeout invariably gets things wrong).
1905 DelServer(sNode
, 0, NULL
);
1908 switch (strlen(numeric
)) {
1909 case 5: slen
= 2; mlen
= 3; break;
1910 case 4: slen
= 1; mlen
= 3; break;
1911 case 3: slen
= 1; mlen
= 2; break;
1913 log_module(MAIN_LOG
, LOG_ERROR
, "AddServer(\"%s\", \"%s\", ...): Numeric %s has invalid length.", uplink
->name
, name
, numeric
);
1917 sNode
= calloc(1, sizeof(*sNode
));
1918 sNode
->uplink
= uplink
;
1919 safestrncpy(sNode
->name
, name
, sizeof(sNode
->name
));
1920 sNode
->num_mask
= base64toint(numeric
+slen
, mlen
);
1924 strncpy(sNode
->numeric
, numeric
, slen
);
1925 safestrncpy(sNode
->description
, description
, sizeof(sNode
->description
));
1926 sNode
->users
= calloc(sNode
->num_mask
+1, sizeof(*sNode
->users
));
1927 serverList_init(&sNode
->children
);
1928 if (sNode
->uplink
) {
1929 /* uplink may be NULL if we're just building ourself */
1930 serverList_append(&sNode
->uplink
->children
, sNode
);
1932 servers_num
[base64toint(numeric
, slen
)] = sNode
;
1933 dict_insert(servers
, sNode
->name
, sNode
);
1937 void DelServer(struct server
* serv
, int announce
, const char *message
)
1941 /* If we receive an ERROR command before the SERVER
1942 * command a NULL server can be passed */
1946 /* Hrm, what's the right way to SQUIT some other server?
1947 * (This code is only to handle killing juped servers.) */
1948 if (announce
&& (serv
->uplink
== self
) && (serv
!= self
->uplink
))
1949 irc_squit(serv
, message
, NULL
);
1951 /* must recursively remove servers linked to this one first */
1952 for (i
=serv
->children
.used
;i
>0;)
1953 if (serv
->children
.list
[--i
] != self
)
1954 DelServer(serv
->children
.list
[i
], false, NULL
);
1956 /* clean up server's user hash tables */
1957 for (i
=0;i
<=serv
->num_mask
;i
++)
1959 DelUser(serv
->users
[i
], NULL
, false, "server delinked");
1963 serverList_remove(&serv
->uplink
->children
, serv
);
1964 if (serv
== self
->uplink
)
1965 self
->uplink
= NULL
;
1966 servers_num
[base64toint(serv
->numeric
, strlen(serv
->numeric
))] = NULL
;
1967 dict_remove(servers
, serv
->name
);
1968 serverList_clean(&serv
->children
);
1974 AddService(const char *nick
, const char *modes
, const char *desc
, const char *hostname
)
1976 char numeric
[COMBO_NUMERIC_LEN
+1];
1977 int local_num
= get_local_numeric();
1978 time_t timestamp
= now
;
1979 struct userNode
*old_user
= GetUserH(nick
);
1982 if (IsLocal(old_user
))
1984 timestamp
= old_user
->timestamp
- 1;
1986 if (local_num
== -1) {
1987 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to allocate numnick for service %s", nick
);
1991 hostname
= self
->name
;
1992 make_numeric(self
, local_num
, numeric
);
1993 /* TODO: Make these modes part of the conf file */
1994 return AddUser(self
, nick
, nick
, hostname
, modes
? modes
: "+oik", numeric
, desc
, now
, "AAAAAA");
1998 AddClone(const char *nick
, const char *ident
, const char *hostname
, const char *desc
)
2000 char numeric
[COMBO_NUMERIC_LEN
+1];
2001 int local_num
= get_local_numeric();
2002 time_t timestamp
= now
;
2003 struct userNode
*old_user
= GetUserH(nick
);
2006 if (IsLocal(old_user
))
2008 timestamp
= old_user
->timestamp
- 1;
2010 if (local_num
== -1) {
2011 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to allocate numnick for clone %s", nick
);
2014 make_numeric(self
, local_num
, numeric
);
2015 return AddUser(self
, nick
, ident
, hostname
, "+i", numeric
, desc
, timestamp
, "AAAAAA");
2019 is_valid_nick(const char *nick
) {
2021 /* IRC has some of The Most Fucked-Up ideas about character sets
2023 if (!isalpha(*nick
) && !strchr("{|}~[\\]^_`", *nick
))
2025 for (ii
= 0; nick
[ii
]; ++ii
)
2026 if (!isalnum(nick
[ii
]) && !strchr("{|}~[\\]^-_`", nick
[ii
]))
2028 if (strlen(nick
) > nicklen
)
2033 static struct userNode
*
2034 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
)
2036 struct userNode
*oldUser
, *uNode
;
2037 unsigned int n
, ignore_user
;
2039 if ((strlen(numeric
) < 3) || (strlen(numeric
) > 5)) {
2040 log_module(MAIN_LOG
, LOG_WARNING
, "AddUser(%p, %s, ...): numeric %s wrong length!", uplink
, nick
, numeric
);
2045 log_module(MAIN_LOG
, LOG_WARNING
, "AddUser(%p, %s, ...): server for numeric %s doesn't exist!", uplink
, nick
, numeric
);
2049 if (uplink
!= GetServerN(numeric
)) {
2050 log_module(MAIN_LOG
, LOG_WARNING
, "AddUser(%p, %s, ...): server for numeric %s differs from nominal uplink %s.", uplink
, nick
, numeric
, uplink
->name
);
2054 if (!is_valid_nick(nick
)) {
2055 log_module(MAIN_LOG
, LOG_WARNING
, "AddUser(%p, %s, ...): invalid nickname detected.", uplink
, nick
);
2060 if ((oldUser
= GetUserH(nick
))) {
2061 if (IsLocal(oldUser
) && (IsService(oldUser
) || IsPersistent(oldUser
))) {
2062 /* The service should collide the new user off. */
2063 oldUser
->timestamp
= timestamp
- 1;
2066 if (oldUser
->timestamp
> timestamp
) {
2067 /* "Old" user is really newer; remove them */
2068 DelUser(oldUser
, 0, 1, "Overruled by older nick");
2070 /* User being added is too new; do not add them to
2071 * clients, but do add them to the server's list, since it
2072 * will send a KILL and QUIT soon. */
2077 /* create new usernode and set all values */
2078 uNode
= calloc(1, sizeof(*uNode
));
2079 uNode
->nick
= strdup(nick
);
2080 safestrncpy(uNode
->ident
, ident
, sizeof(uNode
->ident
));
2081 safestrncpy(uNode
->info
, userinfo
, sizeof(uNode
->info
));
2082 safestrncpy(uNode
->hostname
, hostname
, sizeof(uNode
->hostname
));
2083 safestrncpy(uNode
->numeric
, numeric
, sizeof(uNode
->numeric
));
2084 uNode
->ip
.s_addr
= htonl(base64toint(realip
, 6));
2085 uNode
->timestamp
= timestamp
;
2086 modeList_init(&uNode
->channels
);
2087 uNode
->uplink
= uplink
;
2088 if (++uNode
->uplink
->clients
> uNode
->uplink
->max_clients
) {
2089 uNode
->uplink
->max_clients
= uNode
->uplink
->clients
;
2091 uNode
->num_local
= base64toint(numeric
+strlen(uNode
->uplink
->numeric
), 3) & uNode
->uplink
->num_mask
;
2092 uNode
->uplink
->users
[uNode
->num_local
] = uNode
;
2093 mod_usermode(uNode
, modes
);
2097 dict_insert(clients
, uNode
->nick
, uNode
);
2098 if (dict_size(clients
) > max_clients
) {
2099 max_clients
= dict_size(clients
);
2100 max_clients_time
= now
;
2104 for (n
=0; n
<nuf_used
; n
++)
2105 if (nuf_list
[n
](uNode
))
2108 if ((uNode
->loc
== 1) && (uNode
->handle_info
))
2109 send_func_list(uNode
);
2114 /* removes user from it's server's hash table and nick hash table */
2116 DelUser(struct userNode
* user
, struct userNode
*killer
, int announce
, const char *why
)
2122 /* mark them as dead, in case anybody cares */
2125 /* remove pending adduser commands */
2126 wipe_adduser_pending(NULL
, user
);
2128 /* remove user from all channels */
2129 while (user
->channels
.used
> 0)
2130 DelChannelUser(user
, user
->channels
.list
[user
->channels
.used
-1]->channel
, false, 0);
2132 /* Call these in reverse order so ChanServ can update presence
2133 information before NickServ nukes the handle_info. */
2134 for (n
= duf_used
; n
> 0; )
2135 duf_list
[--n
](user
, killer
, why
);
2137 user
->uplink
->clients
--;
2138 user
->uplink
->users
[user
->num_local
] = NULL
;
2140 userList_remove(&curr_opers
, user
);
2141 /* remove from global dictionary, but not if after a collide */
2142 if (user
== dict_find(clients
, user
->nick
, NULL
))
2143 dict_remove(clients
, user
->nick
);
2145 if (IsInvisible(user
))
2150 irc_quit(user
, why
);
2152 irc_kill(killer
, user
, why
);
2155 modeList_clean(&user
->channels
);
2156 /* We don't free them, in case we try to privmsg them or something
2157 * (like when a stupid oper kills themself). We just put them onto
2158 * a list of clients that get freed after processing each line.
2160 if (dead_users
.size
)
2161 userList_append(&dead_users
, user
);
2166 static void call_oper_funcs(struct userNode
*user
);
2168 void mod_usermode(struct userNode
*user
, const char *mode_change
) {
2170 const char *word
= mode_change
;
2172 if (!user
|| !mode_change
)
2174 while (*word
!= ' ' && *word
) word
++;
2175 while (*word
== ' ') word
++;
2177 #define do_user_mode(FLAG) do { if (add) user->modes |= FLAG; else user->modes &= ~FLAG; } while (0)
2178 switch (*mode_change
++) {
2179 case 0: case ' ': return;
2180 case '+': add
= 1; break;
2181 case '-': add
= 0; break;
2184 if(!IsOper(user
)) { /* Dont re-oper an oper */
2185 userList_append(&curr_opers
, user
);
2186 call_oper_funcs(user
);
2189 userList_remove(&curr_opers
, user
);
2191 do_user_mode(FLAGS_OPER
);
2193 case 'O': do_user_mode(FLAGS_LOCOP
); break;
2194 case 'i': do_user_mode(FLAGS_INVISIBLE
);
2200 case 'w': do_user_mode(FLAGS_WALLOP
); break;
2201 case 's': do_user_mode(FLAGS_SERVNOTICE
); break;
2202 case 'd': do_user_mode(FLAGS_DEAF
); break;
2203 case 'k': do_user_mode(FLAGS_SERVICE
); break;
2204 case 'g': do_user_mode(FLAGS_GLOBAL
); break;
2205 // sethost - reed/apples
2206 // case 'h': do_user_mode(FLAGS_HELPER); break;
2207 // I check if there's an 'h' in the first part, and if there,
2208 // then everything after the space becomes their new host.
2209 case 'h': do_user_mode(FLAGS_SETHOST
);
2211 char sethost
[MAXLEN
];
2213 for (ii
=0; (*word
!= ' ') && (*word
!= '\0'); )
2214 sethost
[ii
++] = *word
++;
2216 while (*word
== ' ')
2218 safestrncpy(user
->sethost
, sethost
, sizeof(user
->sethost
));
2221 case 'x': do_user_mode(FLAGS_HIDDEN_HOST
); break;
2226 for (ii
=0; (*word
!= ' ') && (*word
!= '\0'); )
2227 tag
[ii
++] = *word
++;
2229 while (*word
== ' ')
2231 call_account_func(user
, tag
);
2238 for (ii
=0; (*word
!= ' ') && (*word
!= '\0'); )
2239 host
[ii
++] = *word
++;
2241 while (*word
== ' ')
2243 assign_fakehost(user
, host
, 0);
2251 struct mod_chanmode
*
2252 mod_chanmode_parse(struct chanNode
*channel
, char **modes
, unsigned int argc
, unsigned int flags
)
2254 struct mod_chanmode
*change
;
2255 unsigned int ii
, in_arg
, ch_arg
, add
;
2259 if (!(change
= mod_chanmode_alloc(argc
- 1)))
2262 for (ii
= ch_arg
= 0, in_arg
= add
= 1;
2263 (modes
[0][ii
] != '\0') && (modes
[0][ii
] != ' ');
2265 switch (modes
[0][ii
]) {
2272 #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)
2273 case 'C': do_chan_mode(MODE_NOCTCPS
); break;
2274 case 'D': do_chan_mode(MODE_DELAYJOINS
); break;
2275 case 'c': do_chan_mode(MODE_NOCOLORS
); break;
2276 case 'i': do_chan_mode(MODE_INVITEONLY
); break;
2277 case 'm': do_chan_mode(MODE_MODERATED
); break;
2278 case 'n': do_chan_mode(MODE_NOPRIVMSGS
); break;
2279 case 'p': do_chan_mode(MODE_PRIVATE
); break;
2280 case 'r': do_chan_mode(MODE_REGONLY
); break;
2281 case 's': do_chan_mode(MODE_SECRET
); break;
2282 case 't': do_chan_mode(MODE_TOPICLIMIT
); break;
2283 case 'S': do_chan_mode(MODE_STRIPCOLOR
); break;
2284 case 'M': do_chan_mode(MODE_MODUNREG
); break;
2285 case 'N': do_chan_mode(MODE_NONOTICE
); break;
2286 case 'Q': do_chan_mode(MODE_NOQUITMSGS
); break;
2287 case 'T': do_chan_mode(MODE_NOAMSG
); break;
2288 case 'O': do_chan_mode(MODE_OPERSONLY
); break;
2289 case 'Z': do_chan_mode(MODE_SSLONLY
); break;
2290 case 'L': do_chan_mode(MODE_HIDEMODE
); break;
2292 if (!(flags
& MCP_REGISTERED
)) {
2293 do_chan_mode(MODE_REGISTERED
);
2295 mod_chanmode_free(change
);
2304 change
->modes_set
|= MODE_LIMIT
;
2305 change
->new_limit
= atoi(modes
[in_arg
++]);
2307 change
->modes_set
&= ~MODE_LIMIT
;
2308 change
->modes_clear
|= MODE_LIMIT
;
2315 change
->modes_set
|= MODE_KEY
;
2316 safestrncpy(change
->new_key
, modes
[in_arg
++], sizeof(change
->new_key
));
2318 change
->modes_clear
|= MODE_KEY
;
2319 if (!(flags
& MCP_KEY_FREE
)) {
2327 if (!(flags
& MCP_ALLOW_OVB
))
2331 change
->args
[ch_arg
].mode
= MODE_BAN
;
2333 change
->args
[ch_arg
].mode
|= MODE_REMOVE
;
2334 change
->args
[ch_arg
++].u
.hostmask
= modes
[in_arg
++];
2337 if (!(flags
& MCP_ALLOW_OVB
))
2341 change
->args
[ch_arg
].mode
= MODE_EXEMPT
;
2343 change
->args
[ch_arg
].mode
|= MODE_REMOVE
;
2344 change
->args
[ch_arg
++].u
.hostmask
= modes
[in_arg
++];
2346 case 'o': case 'h': case 'v':
2348 struct userNode
*victim
;
2349 if (!(flags
& MCP_ALLOW_OVB
))
2354 if (modes
[0][ii
] == 'o')
2355 change
->args
[ch_arg
].mode
= MODE_CHANOP
;
2356 else if (modes
[0][ii
] == 'h')
2357 change
->args
[ch_arg
].mode
= MODE_HALFOP
;
2358 else if (modes
[0][ii
] == 'v')
2359 change
->args
[ch_arg
].mode
= MODE_VOICE
;
2362 change
->args
[ch_arg
].mode
|= MODE_REMOVE
;
2363 if (flags
& MCP_FROM_SERVER
)
2364 victim
= GetUserN(modes
[in_arg
++]);
2366 victim
= GetUserH(modes
[in_arg
++]);
2369 if ((change
->args
[ch_arg
].u
.member
= GetUserMode(channel
, victim
)))
2374 if (!(flags
& MCP_FROM_SERVER
))
2379 change
->argc
= ch_arg
; /* in case any turned out to be ignored */
2380 if (change
->modes_set
& MODE_SECRET
) {
2381 change
->modes_set
&= ~(MODE_PRIVATE
);
2382 change
->modes_clear
|= MODE_PRIVATE
;
2383 } else if (change
->modes_set
& MODE_PRIVATE
) {
2384 change
->modes_set
&= ~(MODE_SECRET
);
2385 change
->modes_clear
|= MODE_SECRET
;
2389 mod_chanmode_free(change
);
2393 struct chanmode_buffer
{
2396 struct chanNode
*channel
;
2397 struct userNode
*actor
;
2398 unsigned int modes_used
;
2399 unsigned int args_used
;
2401 unsigned int is_add
: 1;
2402 unsigned int is_chanop
: 1;
2406 mod_chanmode_append(struct chanmode_buffer
*buf
, char ch
, const char *arg
)
2408 size_t arg_len
= strlen(arg
);
2409 if (buf
->modes_used
> (MAXMODEPARAMS
) ||
2410 buf
->modes_used
+ buf
->args_used
+ buf
->chname_len
+ arg_len
> 450) {
2411 memcpy(buf
->modes
+ buf
->modes_used
, buf
->args
, buf
->args_used
);
2412 buf
->modes
[buf
->modes_used
+ buf
->args_used
] = '\0';
2413 irc_mode((buf
->is_chanop
? buf
->actor
: NULL
), buf
->channel
, buf
->modes
);
2414 buf
->modes
[0] = buf
->is_add
? '+' : '-';
2415 buf
->modes_used
= 1;
2418 buf
->modes
[buf
->modes_used
++] = ch
;
2419 buf
->args
[buf
->args_used
++] = ' ';
2420 memcpy(buf
->args
+ buf
->args_used
, arg
, arg_len
);
2421 buf
->args_used
+= arg_len
;
2425 mod_chanmode_announce(struct userNode
*who
, struct chanNode
*channel
, struct mod_chanmode
*change
)
2427 struct chanmode_buffer chbuf
;
2429 struct modeNode
*mn
;
2430 char int_buff
[32], mode
= '\0';
2432 assert(change
->argc
<= change
->alloc_argc
);
2433 memset(&chbuf
, 0, sizeof(chbuf
));
2434 chbuf
.channel
= channel
;
2436 chbuf
.chname_len
= strlen(channel
->name
);
2438 mn
= GetUserMode(channel
, who
);
2439 if ((mn
&& (mn
->modes
& MODE_CHANOP
)) || off_channel
)
2440 chbuf
.is_chanop
= 1;
2442 /* First remove modes */
2444 if (change
->modes_clear
) {
2446 chbuf
.modes
[chbuf
.modes_used
++] = mode
= '-';
2447 #define DO_MODE_CHAR(BIT, CHAR) if (change->modes_clear & MODE_##BIT) chbuf.modes[chbuf.modes_used++] = CHAR
2448 DO_MODE_CHAR(PRIVATE
, 'p');
2449 DO_MODE_CHAR(SECRET
, 's');
2450 DO_MODE_CHAR(MODERATED
, 'm');
2451 DO_MODE_CHAR(TOPICLIMIT
, 't');
2452 DO_MODE_CHAR(INVITEONLY
, 'i');
2453 DO_MODE_CHAR(NOPRIVMSGS
, 'n');
2454 DO_MODE_CHAR(LIMIT
, 'l');
2455 DO_MODE_CHAR(DELAYJOINS
, 'D');
2456 DO_MODE_CHAR(REGONLY
, 'r');
2457 DO_MODE_CHAR(NOCOLORS
, 'c');
2458 DO_MODE_CHAR(NOCTCPS
, 'C');
2459 DO_MODE_CHAR(STRIPCOLOR
, 'S');
2460 DO_MODE_CHAR(MODUNREG
, 'M');
2461 DO_MODE_CHAR(NONOTICE
, 'N');
2462 DO_MODE_CHAR(NOQUITMSGS
, 'Q');
2463 DO_MODE_CHAR(NOAMSG
, 'T');
2464 DO_MODE_CHAR(OPERSONLY
, 'O');
2465 DO_MODE_CHAR(REGISTERED
, 'z');
2466 DO_MODE_CHAR(SSLONLY
, 'Z');
2467 DO_MODE_CHAR(HIDEMODE
, 'L');
2469 if (change
->modes_clear
& channel
->modes
& MODE_KEY
)
2470 mod_chanmode_append(&chbuf
, 'k', channel
->key
);
2472 for (arg
= 0; arg
< change
->argc
; ++arg
) {
2473 if (!(change
->args
[arg
].mode
& MODE_REMOVE
))
2476 chbuf
.modes
[chbuf
.modes_used
++] = mode
= '-';
2477 switch (change
->args
[arg
].mode
& ~MODE_REMOVE
) {
2479 mod_chanmode_append(&chbuf
, 'b', change
->args
[arg
].u
.hostmask
);
2482 mod_chanmode_append(&chbuf
, 'e', change
->args
[arg
].u
.hostmask
);
2485 if (change
->args
[arg
].mode
& MODE_CHANOP
)
2486 mod_chanmode_append(&chbuf
, 'o', change
->args
[arg
].u
.member
->user
->numeric
);
2487 if (change
->args
[arg
].mode
& MODE_HALFOP
)
2488 mod_chanmode_append(&chbuf
, 'h', change
->args
[arg
].u
.member
->user
->numeric
);
2489 if (change
->args
[arg
].mode
& MODE_VOICE
)
2490 mod_chanmode_append(&chbuf
, 'v', change
->args
[arg
].u
.member
->user
->numeric
);
2497 if (change
->modes_set
) {
2499 chbuf
.modes
[chbuf
.modes_used
++] = mode
= '+';
2500 #define DO_MODE_CHAR(BIT, CHAR) if (change->modes_set & MODE_##BIT) chbuf.modes[chbuf.modes_used++] = CHAR
2501 DO_MODE_CHAR(PRIVATE
, 'p');
2502 DO_MODE_CHAR(SECRET
, 's');
2503 DO_MODE_CHAR(MODERATED
, 'm');
2504 DO_MODE_CHAR(TOPICLIMIT
, 't');
2505 DO_MODE_CHAR(INVITEONLY
, 'i');
2506 DO_MODE_CHAR(NOPRIVMSGS
, 'n');
2507 DO_MODE_CHAR(DELAYJOINS
, 'D');
2508 DO_MODE_CHAR(REGONLY
, 'r');
2509 DO_MODE_CHAR(NOCOLORS
, 'c');
2510 DO_MODE_CHAR(NOCTCPS
, 'C');
2511 DO_MODE_CHAR(STRIPCOLOR
, 'S');
2512 DO_MODE_CHAR(MODUNREG
, 'M');
2513 DO_MODE_CHAR(NONOTICE
, 'N');
2514 DO_MODE_CHAR(NOQUITMSGS
, 'Q');
2515 DO_MODE_CHAR(NOAMSG
, 'T');
2516 DO_MODE_CHAR(OPERSONLY
, 'O');
2517 DO_MODE_CHAR(REGISTERED
, 'z');
2518 DO_MODE_CHAR(SSLONLY
, 'Z');
2519 DO_MODE_CHAR(HIDEMODE
, 'L');
2521 if(change
->modes_set
& MODE_KEY
)
2522 mod_chanmode_append(&chbuf
, 'k', change
->new_key
);
2523 if(change
->modes_set
& MODE_LIMIT
) {
2524 sprintf(int_buff
, "%d", change
->new_limit
);
2525 mod_chanmode_append(&chbuf
, 'l', int_buff
);
2528 for (arg
= 0; arg
< change
->argc
; ++arg
) {
2529 if (change
->args
[arg
].mode
& MODE_REMOVE
)
2532 chbuf
.modes
[chbuf
.modes_used
++] = mode
= '+';
2533 switch (change
->args
[arg
].mode
) {
2535 mod_chanmode_append(&chbuf
, 'b', change
->args
[arg
].u
.hostmask
);
2538 mod_chanmode_append(&chbuf
, 'e', change
->args
[arg
].u
.hostmask
);
2541 if (change
->args
[arg
].mode
& MODE_CHANOP
)
2542 mod_chanmode_append(&chbuf
, 'o', change
->args
[arg
].u
.member
->user
->numeric
);
2543 if (change
->args
[arg
].mode
& MODE_HALFOP
)
2544 mod_chanmode_append(&chbuf
, 'h', change
->args
[arg
].u
.member
->user
->numeric
);
2545 if (change
->args
[arg
].mode
& MODE_VOICE
)
2546 mod_chanmode_append(&chbuf
, 'v', change
->args
[arg
].u
.member
->user
->numeric
);
2551 /* Flush the buffer and apply changes locally */
2552 if (chbuf
.modes_used
> 0) {
2553 memcpy(chbuf
.modes
+ chbuf
.modes_used
, chbuf
.args
, chbuf
.args_used
);
2554 chbuf
.modes
[chbuf
.modes_used
+ chbuf
.args_used
] = '\0';
2555 irc_mode((chbuf
.is_chanop
? chbuf
.actor
: NULL
), chbuf
.channel
, chbuf
.modes
);
2557 mod_chanmode_apply(who
, channel
, change
);
2561 mod_chanmode_format(struct mod_chanmode
*change
, char *outbuff
)
2563 unsigned int used
= 0;
2564 assert(change
->argc
<= change
->alloc_argc
);
2565 if (change
->modes_clear
) {
2566 outbuff
[used
++] = '-';
2567 #define DO_MODE_CHAR(BIT, CHAR) if (change->modes_clear & MODE_##BIT) outbuff[used++] = CHAR
2568 DO_MODE_CHAR(PRIVATE
, 'p');
2569 DO_MODE_CHAR(SECRET
, 's');
2570 DO_MODE_CHAR(MODERATED
, 'm');
2571 DO_MODE_CHAR(TOPICLIMIT
, 't');
2572 DO_MODE_CHAR(INVITEONLY
, 'i');
2573 DO_MODE_CHAR(NOPRIVMSGS
, 'n');
2574 DO_MODE_CHAR(LIMIT
, 'l');
2575 DO_MODE_CHAR(KEY
, 'k');
2576 DO_MODE_CHAR(DELAYJOINS
, 'D');
2577 DO_MODE_CHAR(REGONLY
, 'r');
2578 DO_MODE_CHAR(NOCOLORS
, 'c');
2579 DO_MODE_CHAR(NOCTCPS
, 'C');
2580 DO_MODE_CHAR(STRIPCOLOR
, 'S');
2581 DO_MODE_CHAR(MODUNREG
, 'M');
2582 DO_MODE_CHAR(NONOTICE
, 'N');
2583 DO_MODE_CHAR(NOQUITMSGS
, 'Q');
2584 DO_MODE_CHAR(NOAMSG
, 'T');
2585 DO_MODE_CHAR(OPERSONLY
, 'O');
2586 DO_MODE_CHAR(REGISTERED
, 'z');
2587 DO_MODE_CHAR(SSLONLY
, 'Z');
2588 DO_MODE_CHAR(HIDEMODE
, 'L');
2591 if (change
->modes_set
) {
2592 outbuff
[used
++] = '+';
2593 #define DO_MODE_CHAR(BIT, CHAR) if (change->modes_set & MODE_##BIT) outbuff[used++] = CHAR
2594 DO_MODE_CHAR(PRIVATE
, 'p');
2595 DO_MODE_CHAR(SECRET
, 's');
2596 DO_MODE_CHAR(MODERATED
, 'm');
2597 DO_MODE_CHAR(TOPICLIMIT
, 't');
2598 DO_MODE_CHAR(INVITEONLY
, 'i');
2599 DO_MODE_CHAR(NOPRIVMSGS
, 'n');
2600 DO_MODE_CHAR(DELAYJOINS
, 'D');
2601 DO_MODE_CHAR(REGONLY
, 'r');
2602 DO_MODE_CHAR(NOCOLORS
, 'c');
2603 DO_MODE_CHAR(NOCTCPS
, 'C');
2604 DO_MODE_CHAR(STRIPCOLOR
, 'S');
2605 DO_MODE_CHAR(MODUNREG
, 'M');
2606 DO_MODE_CHAR(NONOTICE
, 'N');
2607 DO_MODE_CHAR(NOQUITMSGS
, 'Q');
2608 DO_MODE_CHAR(NOAMSG
, 'T');
2609 DO_MODE_CHAR(OPERSONLY
, 'O');
2610 DO_MODE_CHAR(REGISTERED
, 'z');
2611 DO_MODE_CHAR(SSLONLY
, 'Z');
2612 DO_MODE_CHAR(HIDEMODE
, 'L');
2614 switch (change
->modes_set
& (MODE_KEY
|MODE_LIMIT
)) {
2615 case MODE_KEY
|MODE_LIMIT
:
2616 used
+= sprintf(outbuff
+used
, "lk %d %s", change
->new_limit
, change
->new_key
);
2619 used
+= sprintf(outbuff
+used
, "k %s", change
->new_key
);
2622 used
+= sprintf(outbuff
+used
, "l %d", change
->new_limit
);
2631 clear_chanmode(struct chanNode
*channel
, const char *modes
)
2633 unsigned int remove
;
2635 for (remove
= 0; *modes
; modes
++) {
2637 case 'o': remove
|= MODE_CHANOP
; break;
2638 case 'h': remove
|= MODE_HALFOP
; break;
2639 case 'v': remove
|= MODE_VOICE
; break;
2640 case 'p': remove
|= MODE_PRIVATE
; break;
2641 case 's': remove
|= MODE_SECRET
; break;
2642 case 'm': remove
|= MODE_MODERATED
; break;
2643 case 't': remove
|= MODE_TOPICLIMIT
; break;
2644 case 'i': remove
|= MODE_INVITEONLY
; break;
2645 case 'n': remove
|= MODE_NOPRIVMSGS
; break;
2648 channel
->key
[0] = '\0';
2651 remove
|= MODE_LIMIT
;
2654 case 'b': remove
|= MODE_BAN
; break;
2655 case 'e': remove
|= MODE_EXEMPT
; break;
2656 case 'D': remove
|= MODE_DELAYJOINS
; break;
2657 case 'r': remove
|= MODE_REGONLY
; break;
2658 case 'c': remove
|= MODE_NOCOLORS
; break;
2659 case 'C': remove
|= MODE_NOCTCPS
; break;
2660 case 'S': remove
|= MODE_STRIPCOLOR
; break;
2661 case 'M': remove
|= MODE_MODUNREG
; break;
2662 case 'N': remove
|= MODE_NONOTICE
; break;
2663 case 'Q': remove
|= MODE_NOQUITMSGS
; break;
2664 case 'T': remove
|= MODE_NOAMSG
; break;
2665 case 'O': remove
|= MODE_OPERSONLY
; break;
2666 case 'z': remove
|= MODE_REGISTERED
; break;
2667 case 'Z': remove
|= MODE_SSLONLY
; break;
2668 case 'L': remove
|= MODE_HIDEMODE
; break;
2675 /* Remove simple modes. */
2676 channel
->modes
&= ~remove
;
2678 /* If removing bans, kill 'em all. */
2679 if ((remove
& MODE_BAN
) && channel
->banlist
.used
) {
2681 for (i
=0; i
<channel
->banlist
.used
; i
++)
2682 free(channel
->banlist
.list
[i
]);
2683 channel
->banlist
.used
= 0;
2686 /* If removing exempts, kill 'em all. */
2687 if ((remove
& MODE_EXEMPT
) && channel
->exemptlist
.used
) {
2689 for (i
=0; i
<channel
->exemptlist
.used
; i
++)
2690 free(channel
->exemptlist
.list
[i
]);
2691 channel
->exemptlist
.used
= 0;
2694 /* Remove member modes. */
2695 if ((remove
& (MODE_CHANOP
| MODE_HALFOP
| MODE_VOICE
)) && channel
->members
.used
) {
2696 int mask
= ~(remove
& (MODE_CHANOP
| MODE_HALFOP
| MODE_VOICE
));
2699 for (i
= 0; i
< channel
->members
.used
; i
++)
2700 channel
->members
.list
[i
]->modes
&= mask
;
2707 reg_privmsg_func(struct userNode
*user
, privmsg_func_t handler
)
2709 unsigned int numeric
= user
->num_local
;
2710 if (numeric
>= num_privmsg_funcs
) {
2711 int newnum
= numeric
+ 8;
2712 privmsg_funcs
= realloc(privmsg_funcs
, newnum
*sizeof(privmsg_func_t
));
2713 memset(privmsg_funcs
+num_privmsg_funcs
, 0, (newnum
-num_privmsg_funcs
)*sizeof(privmsg_func_t
));
2714 num_privmsg_funcs
= newnum
;
2716 if (privmsg_funcs
[numeric
])
2717 log_module(MAIN_LOG
, LOG_WARNING
, "re-registering new privmsg handler for numeric %d", numeric
);
2718 privmsg_funcs
[numeric
] = handler
;
2722 unreg_privmsg_func(struct userNode
*user
, privmsg_func_t handler
)
2726 if (!user
|| handler
)
2727 return; /* this really only works with users */
2729 memset(privmsg_funcs
+user
->num_local
, 0, sizeof(privmsg_func_t
));
2731 for (x
= user
->num_local
+1; x
< num_privmsg_funcs
; x
++)
2732 memmove(privmsg_funcs
+x
-1, privmsg_funcs
+x
, sizeof(privmsg_func_t
));
2734 privmsg_funcs
= realloc(privmsg_funcs
, num_privmsg_funcs
*sizeof(privmsg_func_t
));
2735 num_privmsg_funcs
--;
2740 reg_notice_func(struct userNode
*user
, privmsg_func_t handler
)
2742 unsigned int numeric
= user
->num_local
;
2743 if (numeric
>= num_notice_funcs
) {
2744 int newnum
= numeric
+ 8;
2745 notice_funcs
= realloc(notice_funcs
, newnum
*sizeof(privmsg_func_t
));
2746 memset(notice_funcs
+num_notice_funcs
, 0, (newnum
-num_notice_funcs
)*sizeof(privmsg_func_t
));
2747 num_notice_funcs
= newnum
;
2749 if (notice_funcs
[numeric
])
2750 log_module(MAIN_LOG
, LOG_WARNING
, "re-registering new notice handler for numeric %d", numeric
);
2751 notice_funcs
[numeric
] = handler
;
2755 unreg_notice_func(struct userNode
*user
, privmsg_func_t handler
)
2759 if (!user
|| handler
)
2760 return; /* this really only works with users */
2762 memset(notice_funcs
+user
->num_local
, 0, sizeof(privmsg_func_t
));
2764 for (x
= user
->num_local
+1; x
< num_notice_funcs
; x
++)
2765 memmove(notice_funcs
+x
-1, notice_funcs
+x
, sizeof(privmsg_func_t
));
2767 memset(notice_funcs
+user
->num_local
, 0, sizeof(privmsg_func_t
));
2768 notice_funcs
= realloc(notice_funcs
, num_notice_funcs
*sizeof(privmsg_func_t
));
2773 reg_oper_func(oper_func_t handler
)
2775 if (of_used
== of_size
) {
2778 of_list
= realloc(of_list
, of_size
*sizeof(oper_func_t
));
2781 of_list
= malloc(of_size
*sizeof(oper_func_t
));
2784 of_list
[of_used
++] = handler
;
2788 call_oper_funcs(struct userNode
*user
)
2793 for (n
=0; n
<of_used
; n
++)
2800 unsigned int i
, hop
, max_hop
=1;
2803 /* burst (juped) servers, closest first (except self, which is sent already) */
2804 for (i
=0; i
<ArrayLength(servers_num
); i
++)
2805 if (servers_num
[i
] && servers_num
[i
]->hops
> max_hop
)
2806 max_hop
= servers_num
[i
]->hops
;
2807 for (hop
=1; hop
<=max_hop
; hop
++) {
2808 for (i
=0;i
<ArrayLength(servers_num
);i
++) {
2810 && (servers_num
[i
]->hops
== hop
)
2811 && (servers_num
[i
] != self
->uplink
))
2812 irc_server(servers_num
[i
]);
2816 /* burst local nicks */
2817 for (i
=0; i
<=self
->num_mask
; i
++)
2819 irc_user(self
->users
[i
]);
2821 /* build dict of unbursted channel names (just copy existing channels) */
2822 unbursted_channels
= dict_new();
2823 for (it
= dict_first(channels
); it
; it
= iter_next(it
))
2824 dict_insert(unbursted_channels
, iter_key(it
), iter_data(it
));