]>
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_SHUN "SHUN"
88 #define CMD_SILENCE "SILENCE"
89 #define CMD_SQUERY "SQUERY"
90 #define CMD_SQUIT "SQUIT"
91 #define CMD_STATS "STATS"
92 #define CMD_SVSNICK "SVSNICK"
93 #define CMD_TIME "TIME"
94 #define CMD_TOPIC "TOPIC"
95 #define CMD_TRACE "TRACE"
96 #define CMD_UPING "UPING"
97 #define CMD_USER "USER"
98 #define CMD_USERHOST "USERHOST"
99 #define CMD_USERIP "USERIP"
100 #define CMD_VERSION "VERSION"
101 #define CMD_WALLCHOPS "WALLCHOPS"
102 #define CMD_WALLOPS "WALLOPS"
103 #define CMD_WALLHOPS "WALLHOPS"
104 #define CMD_WALLUSERS "WALLUSERS"
105 #define CMD_WALLVOICES "WALLVOICES"
106 #define CMD_WALLHOPS "WALLHOPS"
107 #define CMD_WHO "WHO"
108 #define CMD_WHOIS "WHOIS"
109 #define CMD_WHOWAS "WHOWAS"
111 /* Tokenized commands. */
112 #define TOK_ACCOUNT "AC"
113 #define TOK_ADMIN "AD"
114 #define TOK_ASLL "LL"
116 #define TOK_BURST "B"
117 #define TOK_CLEARMODE "CM"
118 #define TOK_CLOSE "CLOSE"
119 #define TOK_CNOTICE "CN"
120 #define TOK_CONNECT "CO"
121 #define TOK_CPRIVMSG "CP"
122 #define TOK_CREATE "C"
123 #define TOK_DESTRUCT "DE"
124 #define TOK_DESYNCH "DS"
125 #define TOK_DIE "DIE"
126 #define TOK_DNS "DNS"
128 #define TOK_EOB_ACK "EA"
129 #define TOK_ERROR "Y"
130 #define TOK_EXEMPT "EX"
131 #define TOK_FAKEHOST "FA"
132 #define TOK_GET "GET"
133 #define TOK_GLINE "GL"
134 #define TOK_HASH "HASH"
135 #define TOK_HELP "HELP"
137 #define TOK_INVITE "I"
138 #define TOK_ISON "ISON"
140 #define TOK_JUPE "JU"
143 #define TOK_LINKS "LI"
144 #define TOK_LIST "LIST"
145 #define TOK_LUSERS "LU"
146 #define TOK_MAP "MAP"
147 #define TOK_MARK "MK"
149 #define TOK_MOTD "MO"
150 #define TOK_NAMES "E"
152 #define TOK_NOTICE "O"
153 #define TOK_OPER "OPER"
154 #define TOK_OPMODE "OM"
156 #define TOK_PASS "PA"
159 #define TOK_POST "POST"
160 #define TOK_PRIVMSG "P"
161 #define TOK_PRIVS "PRIVS"
162 #define TOK_PROTO "PROTO"
164 #define TOK_REHASH "REHASH"
165 #define TOK_RESET "RESET"
166 #define TOK_RESTART "RESTART"
167 #define TOK_RPING "RI"
168 #define TOK_RPONG "RO"
169 #define TOK_SERVER "S"
170 #define TOK_SERVLIST "SERVSET"
171 #define TOK_SERVSET "SERVSET"
172 #define TOK_SET "SET"
173 #define TOK_SETTIME "SE"
174 #define TOK_SHUN "SU"
175 #define TOK_SILENCE "U"
176 #define TOK_SQUERY "SQUERY"
177 #define TOK_SQUIT "SQ"
178 #define TOK_STATS "R"
179 #define TOK_SVSNICK "SN"
180 #define TOK_TIME "TI"
181 #define TOK_TOPIC "T"
182 #define TOK_TRACE "TR"
183 #define TOK_UPING "UP"
184 #define TOK_USER "USER"
185 #define TOK_USERHOST "USERHOST"
186 #define TOK_USERIP "USERIP"
187 #define TOK_VERSION "V"
188 #define TOK_WALLCHOPS "WC"
189 #define TOK_WALLOPS "WA"
190 #define TOK_WALLHOPS "WH"
191 #define TOK_WALLUSERS "WU"
192 #define TOK_WALLVOICES "WV"
193 #define TOK_WALLHOPS "WH"
195 #define TOK_WHOIS "W"
196 #define TOK_WHOWAS "X"
198 /* Protocol messages; aliased to full commands or tokens depending
199 on compile-time configuration. ircu prefers tokens WITH THE
200 EXCEPTION OF THE SERVER AND PASS COMMANDS, which cannot be
201 tokenized, because clients' (ie. a linking server) commands are
202 only checked against the full command list.
204 #if defined(ENABLE_TOKENS)
205 #define TYPE(NAME) TOK_ ## NAME
206 #else /* !ENABLE_TOKENS */
207 #define TYPE(NAME) CMD_ ## NAME
208 #endif /* ENABLE_TOKENS */
210 #define P10_ACCOUNT TYPE(ACCOUNT)
211 #define P10_ADMIN TYPE(ADMIN)
212 #define P10_ASLL TYPE(ASLL)
213 #define P10_AWAY TYPE(AWAY)
214 #define P10_BURST TYPE(BURST)
215 #define P10_CLEARMODE TYPE(CLEARMODE)
216 #define P10_CLOSE TYPE(CLOSE)
217 #define P10_CNOTICE TYPE(CNOTICE)
218 #define P10_CONNECT TYPE(CONNECT)
219 #define P10_CPRIVMSG TYPE(CPRIVMSG)
220 #define P10_CREATE TYPE(CREATE)
221 #define P10_DESTRUCT TYPE(DESTRUCT)
222 #define P10_DESYNCH TYPE(DESYNCH)
223 #define P10_DIE TYPE(DIE)
224 #define P10_DNS TYPE(DNS)
225 #define P10_EOB TYPE(EOB)
226 #define P10_EOB_ACK TYPE(EOB_ACK)
227 #define P10_ERROR TYPE(ERROR)
228 #define P10_FAKEHOST TYPE(FAKEHOST)
229 #define P10_GET TYPE(GET)
230 #define P10_GLINE TYPE(GLINE)
231 #define P10_HASH TYPE(HASH)
232 #define P10_HELP TYPE(HELP)
233 #define P10_INFO TYPE(INFO)
234 #define P10_INVITE TYPE(INVITE)
235 #define P10_ISON TYPE(ISON)
236 #define P10_JOIN TYPE(JOIN)
237 #define P10_JUPE TYPE(JUPE)
238 #define P10_KICK TYPE(KICK)
239 #define P10_KILL TYPE(KILL)
240 #define P10_LINKS TYPE(LINKS)
241 #define P10_LIST TYPE(LIST)
242 #define P10_LUSERS TYPE(LUSERS)
243 #define P10_MAP TYPE(MAP)
244 #define P10_MARK TYPE(MARK)
245 #define P10_MODE TYPE(MODE)
246 #define P10_MOTD TYPE(MOTD)
247 #define P10_NAMES TYPE(NAMES)
248 #define P10_NICK TYPE(NICK)
249 #define P10_NOTICE TYPE(NOTICE)
250 #define P10_OPER TYPE(OPER)
251 #define P10_OPMODE TYPE(OPMODE)
252 #define P10_PART TYPE(PART)
253 #define P10_PASS CMD_PASS
254 #define P10_PING TYPE(PING)
255 #define P10_PONG TYPE(PONG)
256 #define P10_POST TYPE(POST)
257 #define P10_PRIVMSG TYPE(PRIVMSG)
258 #define P10_PRIVS TYPE(PRIVS)
259 #define P10_PROTO TYPE(PROTO)
260 #define P10_QUIT TYPE(QUIT)
261 #define P10_REHASH TYPE(REHASH)
262 #define P10_RESET TYPE(RESET)
263 #define P10_RESTART TYPE(RESTART)
264 #define P10_RPING TYPE(RPING)
265 #define P10_RPONG TYPE(RPONG)
266 #define P10_SERVER CMD_SERVER
267 #define P10_SERVLIST TYPE(SERVLIST)
268 #define P10_SERVSET TYPE(SERVSET)
269 #define P10_SET TYPE(SET)
270 #define P10_SETTIME TYPE(SETTIME)
271 #define P10_SHUN TYPE(SHUN)
272 #define P10_SILENCE TYPE(SILENCE)
273 #define P10_SQUERY TYPE(SQUERY)
274 #define P10_SQUIT TYPE(SQUIT)
275 #define P10_STATS TYPE(STATS)
276 #define P10_SVSNICK TYPE(SVSNICK)
277 #define P10_TIME TYPE(TIME)
278 #define P10_TOPIC TYPE(TOPIC)
279 #define P10_TRACE TYPE(TRACE)
280 #define P10_UPING TYPE(UPING)
281 #define P10_USER TYPE(USER)
282 #define P10_USERHOST TYPE(USERHOST)
283 #define P10_USERIP TYPE(USERIP)
284 #define P10_VERSION TYPE(VERSION)
285 #define P10_WALLCHOPS TYPE(WALLCHOPS)
286 #define P10_WALLOPS TYPE(WALLOPS)
287 #define P10_WALLHOPS TYPE(WALLHOPS)
288 #define P10_WALLUSERS TYPE(WALLUSERS)
289 #define P10_WALLVOICES TYPE(WALLVOICES)
290 #define P10_WHO TYPE(WHO)
291 #define P10_WHOIS TYPE(WHOIS)
292 #define P10_WHOWAS TYPE(WHOWAS)
293 #define P10_EXEMPT TYPE(EXEMPT)
295 /* Servers claiming to have a boot or link time before PREHISTORY
296 * trigger errors to the log. We hope no server has been running
297 * constantly since September 1994. :)
299 #define PREHISTORY 780000000
301 static struct server
*servers_num
[64*64];
302 static privmsg_func_t
*privmsg_funcs
;
303 static unsigned int num_privmsg_funcs
;
304 static privmsg_func_t
*notice_funcs
;
305 static unsigned int num_notice_funcs
;
306 static struct dict
*unbursted_channels
;
307 static char *his_servername
;
308 static char *his_servercomment
;
310 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
);
312 extern int off_channel
;
314 /* Numerics can be XYY, XYYY, or XXYYY; with X's identifying the
315 * server and Y's indentifying the client on that server. */
317 GetServerN(const char *numeric
)
319 switch (strlen(numeric
)) {
321 return servers_num
[base64toint(numeric
, 2)];
325 return servers_num
[base64toint(numeric
, 1)];
332 GetUserN(const char *numeric
) /* using numeric */
338 switch (strlen(numeric
)) {
340 log_module(MAIN_LOG
, LOG_WARNING
, "GetUserN(%s): numeric too long!", numeric
);
342 case 5: slen
= 2; ulen
= 3; break;
343 case 4: slen
= 1; ulen
= 3; break;
344 case 3: slen
= 1; ulen
= 2; break;
345 case 2: case 1: case 0:
346 log_module(MAIN_LOG
, LOG_WARNING
, "GetUserN(%s): numeric too short!", numeric
);
349 if (!(s
= servers_num
[base64toint(numeric
, slen
)])) {
350 log_module(MAIN_LOG
, LOG_WARNING
, "GetUserN(%s): couldn't find server (len=%d)!", numeric
, slen
);
353 n
= base64toint(numeric
+slen
, ulen
) & s
->num_mask
;
354 if (!(un
= s
->users
[n
])) {
355 log_module(MAIN_LOG
, LOG_WARNING
, "GetUserN(%s) couldn't find user!", numeric
);
361 privmsg_user_helper(struct userNode
*un
, void *data
)
363 struct privmsg_desc
*pd
= data
;
364 unsigned int num
= un
->num_local
;
365 if (!pd
->is_notice
) {
366 if ((num
< num_privmsg_funcs
) && privmsg_funcs
[num
]) {
367 privmsg_funcs
[num
](pd
->user
, un
, pd
->text
, pd
->is_qualified
);
370 if ((num
< num_notice_funcs
) && notice_funcs
[num
]) {
371 notice_funcs
[num
](pd
->user
, un
, pd
->text
, pd
->is_qualified
);
377 irc_server(struct server
*srv
)
379 char extranum
[COMBO_NUMERIC_LEN
+1];
381 inttobase64(extranum
, srv
->num_mask
, (srv
->numeric
[1] || (srv
->num_mask
>= 64*64)) ? 3 : 2);
383 /* The +s, ignored by Run's ircu, means "service" to Undernet's ircu */
384 putsock(P10_SERVER
" %s %d %li %li J10 %s%s +s :%s",
385 srv
->name
, srv
->hops
+1, srv
->boot
, srv
->link
, srv
->numeric
, extranum
, srv
->description
);
387 putsock("%s " P10_SERVER
" %s %d %li %li %c10 %s%s +s :%s",
388 self
->numeric
, srv
->name
, srv
->hops
+1, srv
->boot
, srv
->link
, (srv
->self_burst
? 'J' : 'P'), srv
->numeric
, extranum
, srv
->description
);
393 irc_user(struct userNode
*user
)
398 inttobase64(b64ip
, ntohl(user
->ip
.s_addr
), 6);
405 modes
[modelen
++] = 'o';
406 if (IsInvisible(user
))
407 modes
[modelen
++] = 'i';
409 modes
[modelen
++] = 'w';
411 modes
[modelen
++] = 'k';
412 if (IsServNotice(user
))
413 modes
[modelen
++] = 's';
415 modes
[modelen
++] = 'd';
417 modes
[modelen
++] = 'g';
418 // sethost - reed/apples
419 // if (IsHelperIrcu(user))
421 modes
[modelen
++] = 'h';
422 if (IsFakeHost(user
))
423 modes
[modelen
++] = 'f';
424 if (IsHiddenHost(user
))
425 modes
[modelen
++] = 'x';
428 /* we don't need to put the + in modes because it's in the format string. */
429 putsock("%s " P10_NICK
" %s %d %li %s %s +%s %s %s :%s",
430 user
->uplink
->numeric
, user
->nick
, user
->uplink
->hops
+1, user
->timestamp
, user
->ident
, user
->hostname
, modes
, b64ip
, user
->numeric
, user
->info
);
432 putsock("%s " P10_NICK
" %s %d %li %s %s %s %s :%s",
433 user
->uplink
->numeric
, user
->nick
, user
->uplink
->hops
+1, user
->timestamp
, user
->ident
, user
->hostname
, b64ip
, user
->numeric
, user
->info
);
438 irc_rename(struct userNode
*user
, const char *new_handle
)
440 putsock("%s " P10_ACCOUNT
" %s M %s", self
->numeric
, user
->numeric
, new_handle
);
444 irc_delete(struct userNode
*user
)
446 putsock("%s " P10_ACCOUNT
" %s U", self
->numeric
, user
->numeric
);
450 irc_account(struct userNode
*user
, const char *stamp
, time_t timestamp
)
452 putsock("%s " P10_ACCOUNT
" %s R %s %lu", self
->numeric
, user
->numeric
, stamp
, timestamp
);
456 irc_fakehost(struct userNode
*user
, const char *host
)
458 putsock("%s " P10_FAKEHOST
" %s %s", self
->numeric
, user
->numeric
, host
);
462 irc_regnick(UNUSED_ARG(struct userNode
*user
))
464 /* no operation here */
468 irc_nick(struct userNode
*user
, UNUSED_ARG(const char *old_nick
))
470 putsock("%s " P10_NICK
" %s "FMT_TIME_T
, user
->numeric
, user
->nick
, now
);
474 irc_fetchtopic(struct userNode
*from
, const char *to
)
478 putsock("%s " P10_TOPIC
" %s", from
->numeric
, to
);
482 irc_squit(struct server
*srv
, const char *message
, const char *service_message
)
484 if (!service_message
)
485 service_message
= message
;
487 /* Are we leaving the network? */
488 if (srv
== self
&& cManager
.uplink
->state
== CONNECTED
) {
491 /* Quit all clients linked to me. */
492 for (i
= 0; i
<= self
->num_mask
; i
++) {
495 irc_quit(self
->users
[i
], service_message
);
499 putsock("%s " P10_SQUIT
" %s %d :%s", self
->numeric
, srv
->name
, 0, message
);
502 /* Force a reconnect to the currently selected server. */
503 cManager
.uplink
->tries
= 0;
504 log_module(MAIN_LOG
, LOG_INFO
, "Squitting from uplink: %s", message
);
510 irc_wallchops(struct userNode
*from
, const char *to
, const char *message
)
512 putsock("%s " P10_WALLCHOPS
" %s :%s", from
->numeric
, to
, message
);
516 irc_notice(struct userNode
*from
, const char *to
, const char *message
)
518 putsock("%s " P10_NOTICE
" %s :%s", from
->numeric
, to
, message
);
522 irc_notice_user(struct userNode
*from
, struct userNode
*to
, const char *message
)
524 putsock("%s " P10_NOTICE
" %s :%s", from
->numeric
, to
->numeric
, message
);
528 irc_privmsg(struct userNode
*from
, const char *to
, const char *message
)
530 putsock("%s " P10_PRIVMSG
" %s :%s", from
->numeric
, to
, message
);
536 putsock("%s " P10_EOB
, self
->numeric
);
542 putsock("%s " P10_EOB_ACK
, self
->numeric
);
546 irc_ping(const char *payload
)
548 putsock("%s " P10_PING
" :%s", self
->numeric
, payload
);
552 irc_pong(const char *who
, const char *data
)
554 putsock("%s " P10_PONG
" %s :%s", self
->numeric
, who
, data
);
558 irc_pass(const char *passwd
)
560 putsock(P10_PASS
" :%s", passwd
);
564 irc_introduce(const char *passwd
)
566 void timed_send_ping(void *data
);
568 self
->self_burst
= self
->burst
= 1;
572 timeq_add(now
+ ping_freq
, timed_send_ping
, 0);
576 irc_gline(struct server
*srv
, struct gline
*gline
, int silent
)
578 putsock("%s " P10_GLINE
" %s +%s %ld :%s<%s> %s",
579 self
->numeric
, (srv
? srv
->numeric
: "*"), gline
->target
, gline
->expires
-now
, silent
? "AUTO " : "", gline
->issuer
, gline
->reason
);
583 irc_shun(struct server
*srv
, struct shun
*shun
)
585 putsock("%s " P10_SHUN
" %s +%s %ld :<%s> %s",
586 self
->numeric
, (srv
? srv
->numeric
: "*"), shun
->target
, shun
->expires
-now
, shun
->issuer
, shun
->reason
);
590 irc_settime(const char *srv_name_mask
, time_t new_time
)
592 ioset_set_time(new_time
);
593 if (!strcmp(srv_name_mask
, "*"))
595 putsock("%s " P10_SETTIME
" " FMT_TIME_T
" %s", self
->numeric
, new_time
, srv_name_mask
);
599 irc_ungline(const char *mask
)
601 putsock("%s " P10_GLINE
" * -%s", self
->numeric
, mask
);
605 irc_unshun(const char *mask
)
607 putsock("%s " P10_SHUN
" * -%s", self
->numeric
, mask
);
611 irc_burst(struct chanNode
*chan
)
613 char burst_line
[512];
614 int pos
, base_len
, len
;
617 struct exemptNode
*en
;
621 base_len
= sprintf(burst_line
, "%s " P10_BURST
" %s " FMT_TIME_T
" ",
622 self
->numeric
, chan
->name
, chan
->timestamp
);
623 len
= irc_make_chanmode(chan
, burst_line
+base_len
);
624 pos
= base_len
+ len
;
626 burst_line
[pos
++] = ' ';
629 for (n
=0; n
<chan
->members
.used
; n
++) {
630 mn
= chan
->members
.list
[n
];
632 burst_line
[pos
-1] = 0; /* -1 to back up over the space or comma */
633 putsock("%s", burst_line
);
637 memcpy(burst_line
+pos
, mn
->user
->numeric
, strlen(mn
->user
->numeric
));
638 pos
+= strlen(mn
->user
->numeric
);
639 if (mn
->modes
&& (mn
->modes
!= last_mode
)) {
640 last_mode
= mn
->modes
;
641 burst_line
[pos
++] = ':';
642 if (last_mode
& MODE_CHANOP
)
643 burst_line
[pos
++] = 'o';
644 if (last_mode
& MODE_HALFOP
)
645 burst_line
[pos
++] = 'h';
646 if (last_mode
& MODE_VOICE
)
647 burst_line
[pos
++] = 'v';
649 if ((n
+1)<chan
->members
.used
)
650 burst_line
[pos
++] = ',';
652 if (chan
->banlist
.used
) {
654 if (pos
+2+strlen(chan
->banlist
.list
[0]->ban
) > 505) {
655 burst_line
[pos
-1] = 0;
656 putsock("%s", burst_line
);
659 burst_line
[pos
++] = ' ';
662 burst_line
[pos
++] = ':';
663 burst_line
[pos
++] = '%';
665 for (n
=0; n
<chan
->banlist
.used
; n
++) {
666 bn
= chan
->banlist
.list
[n
];
667 len
= strlen(bn
->ban
);
668 if (pos
+len
+1 > 510) {
669 burst_line
[pos
-1] = 0; /* -1 to back up over the space or comma */
670 putsock("%s", burst_line
);
673 memcpy(burst_line
+pos
, bn
->ban
, len
);
675 burst_line
[pos
++] = ' ';
678 if (chan
->exemptlist
.used
) {
679 /* dump the exempt */
680 if (pos
+2+strlen(chan
->exemptlist
.list
[0]->exempt
) > 505) {
681 burst_line
[pos
-1] = 0;
682 putsock("%s", burst_line
);
685 burst_line
[pos
++] = ' ';
688 burst_line
[pos
++] = ' ';
689 burst_line
[pos
++] = '~';
690 burst_line
[pos
++] = ' ';
692 for (n
=0; n
<chan
->exemptlist
.used
; n
++) {
693 en
= chan
->exemptlist
.list
[n
];
694 len
= strlen(en
->exempt
);
695 if (pos
+len
+1 > 510) {
696 burst_line
[pos
-1] = 0; /* -1 to back up over the space or comma */
697 putsock("%s", burst_line
);
700 memcpy(burst_line
+pos
, en
->exempt
, len
);
702 burst_line
[pos
++] = ' ';
705 /* print the last line */
707 putsock("%s", burst_line
);
711 irc_quit(struct userNode
*user
, const char *message
)
713 putsock("%s " P10_QUIT
" :%s", user
->numeric
, message
);
717 irc_error(const char *to
, const char *message
)
720 putsock("%s " P10_ERROR
" :%s", to
, message
);
722 putsock(":%s " P10_ERROR
" :%s", self
->name
, message
);
727 irc_kill(struct userNode
*from
, struct userNode
*target
, const char *message
)
730 putsock("%s " P10_KILL
" %s :%s!%s (%s)",
731 from
->numeric
, target
->numeric
, self
->name
, from
->nick
, message
);
733 putsock("%s " P10_KILL
" %s :%s (%s)",
734 self
->numeric
, target
->numeric
, self
->name
, message
);
739 irc_mode(struct userNode
*from
, struct chanNode
*target
, const char *modes
)
741 putsock("%s " P10_MODE
" %s %s "FMT_TIME_T
,
742 (from
? from
->numeric
: self
->numeric
),
743 target
->name
, modes
, target
->timestamp
);
746 /* Added to allow services to mode users
747 2005 - 8 - 10 by Life4Christ
750 irc_umode(struct userNode
*target
, const char *modes
)
752 putsock("%s " P10_MODE
" %s %s ",self
->numeric
,target
->nick
, modes
);
757 irc_invite(struct userNode
*from
, struct userNode
*who
, struct chanNode
*to
)
759 putsock("%s " P10_INVITE
" %s %s", from
->numeric
, who
->nick
, to
->name
);
763 irc_join(struct userNode
*who
, struct chanNode
*what
)
765 if (what
->members
.used
== 1) {
766 putsock("%s " P10_CREATE
" %s %lu",
767 who
->numeric
, what
->name
, what
->timestamp
);
769 putsock("%s " P10_JOIN
" %s %lu", who
->numeric
, what
->name
, what
->timestamp
);
774 irc_kick(struct userNode
*who
, struct userNode
*target
, struct chanNode
*channel
, const char *msg
)
777 struct modeNode
*mn
= GetUserMode(channel
, who
);
778 numeric
= ((mn
&& (mn
->modes
& MODE_CHANOP
)) || off_channel
) ? who
->numeric
: self
->numeric
;
779 putsock("%s " P10_KICK
" %s %s :%s",
780 numeric
, channel
->name
, target
->numeric
, msg
);
784 irc_stats(struct userNode
*from
, struct server
*target
, char type
)
786 putsock("%s " P10_STATS
" %c :%s", from
->numeric
, type
, target
->numeric
);
790 irc_svsnick(struct userNode
*from
, struct userNode
*target
, const char *newnick
)
792 putsock("%s " P10_SVSNICK
" %s %s "FMT_TIME_T
, from
->uplink
->numeric
, target
->numeric
, newnick
, now
);
796 irc_part(struct userNode
*who
, struct chanNode
*what
, const char *reason
)
799 putsock("%s " P10_PART
" %s :%s", who
->numeric
, what
->name
, reason
);
801 putsock("%s " P10_PART
" %s", who
->numeric
, what
->name
);
806 irc_topic(struct userNode
*service
, struct userNode
*who
, struct chanNode
*what
, const char *topic
)
808 /* UNCOMMENT FOR NEFARIOUS 0.5.0 TOPIC SUPPORT
809 * putsock("%s " P10_TOPIC " %s %s " FMT_TIME_T " " FMT_TIME_T " :%s", service->numeric, what->name, who->nick, what->timestamp, now, topic);
810 * UNCOMMENT FOR NEFARIOUS 0.5.0 TOPIC SUPPORT */
812 who
= service
; /* REMOVE LINE FOR NEFARIOUS 0.5.0 */
814 putsock("%s " P10_TOPIC
" %s :%s", who
->numeric
, what
->name
, topic
);
818 irc_raw(const char *what
)
824 irc_numeric(struct userNode
*user
, unsigned int num
, const char *format
, ...)
828 va_start(arg_list
, format
);
829 vsnprintf(buffer
, MAXLEN
-2, format
, arg_list
);
830 buffer
[MAXLEN
-1] = 0;
831 putsock(":%s %03d %s %s", self
->name
, num
, user
->nick
, buffer
);
834 static void send_burst(void);
837 change_nicklen(int new_nicklen
)
840 char new_nick
[NICKLEN
+1];
841 struct userNode
*user
;
843 nicklen
= new_nicklen
;
844 /* fix up any users we have here */
845 for (nn
=0; nn
<=self
->num_mask
; nn
++) {
846 if (!(user
= self
->users
[nn
]))
848 safestrncpy(new_nick
, user
->nick
, sizeof(new_nick
));
849 new_nick
[nicklen
] = 0;
850 NickChange(user
, new_nick
, 1);
854 static CMD_FUNC(cmd_whois
)
856 struct userNode
*from
;
857 struct userNode
*who
;
861 if (!(from
= GetUserH(origin
))) {
862 log_module(MAIN_LOG
, LOG_ERROR
, "Could not find WHOIS origin user %s", origin
);
865 if(!(who
= GetUserH(argv
[2]))) {
866 irc_numeric(from
, ERR_NOSUCHNICK
, "%s@%s :No such nick", argv
[2], self
->name
);
869 if (IsHiddenHost(who
) && !IsOper(from
)) {
870 /* Just stay quiet. */
873 irc_numeric(from
, RPL_WHOISUSER
, "%s %s %s * :%s", who
->nick
, who
->ident
, who
->hostname
, who
->info
);
874 if (his_servername
&& his_servercomment
)
875 irc_numeric(from
, RPL_WHOISSERVER
, "%s %s :%s", who
->nick
, his_servername
, his_servercomment
);
877 irc_numeric(from
, RPL_WHOISSERVER
, "%s %s :%s", who
->nick
, who
->uplink
->name
, who
->uplink
->description
);
879 irc_numeric(from
, RPL_WHOISOPERATOR
, "%s :is a megalomaniacal power hungry tyrant", who
->nick
);
880 irc_numeric(from
, RPL_ENDOFWHOIS
, "%s :End of /WHOIS list", who
->nick
);
884 static CMD_FUNC(cmd_server
)
892 /* another server introduced us */
893 srv
= AddServer(GetServerH(origin
), argv
[1], atoi(argv
[2]), atoi(argv
[3]), atoi(argv
[4]), argv
[6], argv
[argc
-1]);
896 srv
->self_burst
= argv
[5][0] == 'J';
899 /* this must be our uplink */
900 srv
= self
->uplink
= AddServer(self
, argv
[1], atoi(argv
[2]), atoi(argv
[3]), atoi(argv
[4]), argv
[6], argv
[argc
-1]);
903 srv
->self_burst
= argv
[5][0] == 'J';
905 if ((argv
[7][0] == '+') && !force_n2k
) {
906 log_module(MAIN_LOG
, LOG_WARNING
, "Got Undernet-style SERVER message but \"force_n2k\" not on.");
911 /* Fix up our timestamps if necessary. */
912 if (srv
->boot
<= PREHISTORY
) {
913 /* Server from the mists of time.. */
914 if (srv
->hops
== 1) {
915 log_module(MAIN_LOG
, LOG_ERROR
, "Server %s claims to have booted at time "FMT_TIME_T
". This is absurd.", srv
->name
, srv
->boot
);
917 } else if ((str
= conf_get_data("server/reliable_clock", RECDB_QSTRING
))
918 && enabled_string(str
)) {
919 /* If we have a reliable clock, we just keep our current time. */
921 if (srv
->boot
<= self
->boot
) {
922 /* The other server is older than us. Accept their timestamp.
923 * Alternately, we are same age, but we accept their time
924 * since we are linking to them. */
925 self
->boot
= srv
->boot
;
926 ioset_set_time(srv
->link
);
929 if (srv
== self
->uplink
) {
930 extern time_t burst_begin
;
936 static CMD_FUNC(cmd_eob
)
938 struct server
*sender
;
942 if (!(sender
= GetServerH(origin
)))
944 if (sender
== self
->uplink
) {
945 cManager
.uplink
->state
= CONNECTED
;
946 for (it
= dict_first(unbursted_channels
); it
; it
= iter_next(it
))
947 irc_burst(iter_data(it
));
948 dict_delete(unbursted_channels
);
949 unbursted_channels
= NULL
;
953 sender
->self_burst
= 0;
954 recalc_bursts(sender
);
955 for (ii
=0; ii
<slf_used
; ii
++)
956 slf_list
[ii
](sender
);
960 static CMD_FUNC(cmd_eob_ack
)
962 extern time_t burst_begin
;
964 if (GetServerH(origin
) == self
->uplink
) {
965 burst_length
= now
- burst_begin
;
966 self
->self_burst
= self
->burst
= 0;
968 cManager
.uplink
->state
= CONNECTED
;
972 static CMD_FUNC(cmd_ping
)
978 irc_pong(argv
[2], argv
[1]);
979 else if ((srv
= GetServerH(origin
)))
980 irc_pong(self
->name
, srv
->numeric
);
981 else if ((un
= GetUserH(origin
)))
982 irc_pong(self
->name
, un
->numeric
);
984 irc_pong(self
->name
, origin
);
986 timeq_del(0, timed_send_ping
, 0, TIMEQ_IGNORE_WHEN
|TIMEQ_IGNORE_DATA
);
987 timeq_del(0, timed_ping_timeout
, 0, TIMEQ_IGNORE_WHEN
|TIMEQ_IGNORE_DATA
);
988 timeq_add(now
+ ping_freq
, timed_send_ping
, 0);
993 static CMD_FUNC(cmd_error_nick
)
995 /* Go back to original IRC length .. and try to reconnect :/ */
997 irc_squit(self
, "Got erroneous nickname, truncating nicks.", NULL
);
1001 struct create_desc
{
1002 struct userNode
*user
;
1007 join_helper(struct chanNode
*chan
, void *data
)
1009 struct create_desc
*cd
= data
;
1010 AddChannelUser(cd
->user
, chan
);
1014 create_helper(char *name
, void *data
)
1016 struct create_desc
*cd
= data
;
1018 if (!strcmp(name
, "0")) {
1019 while (cd
->user
->channels
.used
> 0)
1020 DelChannelUser(cd
->user
, cd
->user
->channels
.list
[0]->channel
, 0, 0);
1024 AddChannelUser(cd
->user
, AddChannel(name
, cd
->when
, NULL
, NULL
, NULL
));
1027 static CMD_FUNC(cmd_create
)
1029 struct create_desc cd
;
1030 struct userNode
*user
;
1032 if ((argc
< 3) || !(user
= GetUserH(origin
)))
1035 cd
.when
= atoi(argv
[2]);
1036 parse_foreach(argv
[1], join_helper
, create_helper
, NULL
, NULL
, &cd
);
1040 static CMD_FUNC(cmd_join
)
1042 struct create_desc cd
;
1044 if (!(cd
.user
= GetUserH(origin
)))
1051 cd
.when
= atoi(argv
[2]);
1052 parse_foreach(argv
[1], join_helper
, create_helper
, NULL
, NULL
, &cd
);
1056 static CMD_FUNC(cmd_pong
)
1060 if (!strcmp(argv
[2], self
->name
)) {
1061 timeq_del(0, timed_send_ping
, 0, TIMEQ_IGNORE_WHEN
|TIMEQ_IGNORE_DATA
);
1062 timeq_del(0, timed_ping_timeout
, 0, TIMEQ_IGNORE_WHEN
|TIMEQ_IGNORE_DATA
);
1063 timeq_add(now
+ ping_freq
, timed_send_ping
, 0);
1069 static CMD_FUNC(cmd_nick
)
1071 struct userNode
*user
;
1072 if ((user
= GetUserH(origin
))) {
1073 /* nick change (since the source is a user numeric) */
1076 NickChange(user
, argv
[1], 1);
1078 struct server
*serv
;
1083 serv
= GetServerH(origin
);
1085 unsplit_string(argv
+6, argc
-9, modes
);
1088 AddUser(serv
, argv
[1], argv
[4], argv
[5], modes
, argv
[argc
-2], argv
[argc
-1], atoi(argv
[3]), argv
[argc
-3]);
1093 static CMD_FUNC(cmd_account
)
1095 struct userNode
*user
;
1096 struct server
*server
;
1097 struct handle_info
*hi
;
1099 if ((argc
< 3) || !origin
|| !(server
= GetServerH(origin
)))
1100 return 0; /* Origin must be server. */
1102 /* This next line appears to tremple origin.. why? */
1103 user
= GetUserN(argv
[1]);
1105 return 1; /* A QUIT probably passed the ACCOUNT. */
1107 if(!strcmp(argv
[2],"C"))
1109 if((hi
= loc_auth(argv
[4], argv
[5])))
1112 putsock("%s " P10_ACCOUNT
" %s A %s %lu", self
->numeric
, server
->numeric
, argv
[3], hi
->registered
);
1118 putsock("%s " P10_ACCOUNT
" %s D %s", self
->numeric
, server
->numeric
, argv
[3]);
1122 else if(!strcmp(argv
[2],"R"))
1123 call_account_func(user
, argv
[3]);
1125 call_account_func(user
, argv
[2]); /* For backward compatability */
1129 static CMD_FUNC(cmd_fakehost
)
1131 struct userNode
*user
;
1133 if ((argc
< 3) || !origin
|| !GetServerH(origin
))
1135 if (!(user
= GetUserN(argv
[1])))
1137 assign_fakehost(user
, argv
[2], 0);
1141 static CMD_FUNC(cmd_burst
)
1144 char modes
[MAXLEN
], *members
= "";
1145 static char exemptlist
[MAXLEN
], banlist
[MAXLEN
];
1146 unsigned int next
= 3, res
= 1;
1147 int ctype
= 0, echeck
= 0, bcheck
= 0;
1148 struct chanNode
*cNode
;
1149 struct userNode
*un
;
1150 struct modeNode
*mNode
;
1152 char *user
, *end
, sep
;
1153 time_t in_timestamp
;
1163 while (next
< argc
) {
1164 switch (argv
[next
][0]) {
1168 for (pos
=argv
[next
], n_modes
= 1; *pos
; pos
++)
1169 if ((*pos
== 'k') || (*pos
== 'l'))
1171 unsplit_string(argv
+next
, n_modes
, modes
);
1176 for(parm
= mysep(&argv
[next
], " "); /* parm = first param */
1177 parm
; /* While param is not null */
1178 parm
= mysep(&argv
[next
], " ") /* parm = next param */
1196 /* strip % char off start of very first ban */
1197 if (strlen(parm
) > 1) {
1198 strncat(banlist
, strtok(parm
, "%"), sizeof(banlist
) - 1 - strlen(banlist
));
1199 strncat(banlist
, " ", sizeof(banlist
) - 1 - strlen(banlist
));
1203 strncat(banlist
, parm
, sizeof(banlist
) - 1 - strlen(banlist
));
1204 strncat(banlist
, " ", sizeof(banlist
) - 1 - strlen(banlist
));
1206 } else if (ctype
== 2) {
1210 strncat(exemptlist
, parm
, sizeof(exemptlist
) - 1 - strlen(exemptlist
));
1211 strncat(exemptlist
, " ", sizeof(exemptlist
) - 1 - strlen(exemptlist
));
1218 default: members
= argv
[next
++]; break;
1222 in_timestamp
= atoi(argv
[2]);
1223 if ((cNode
= dict_find(unbursted_channels
, argv
[1], NULL
))) {
1224 cNode
->timestamp
= in_timestamp
;
1225 dict_remove(unbursted_channels
, cNode
->name
);
1228 cNode
= AddChannel(argv
[1], in_timestamp
, modes
, banlist
, exemptlist
);
1230 /* Burst channel members in now. */
1231 for (user
= members
, sep
= *members
, mode
= 0; sep
; user
= end
) {
1232 for (end
= user
+ 3; isalnum(*end
) || *end
== '[' || *end
== ']'; end
++) ;
1233 sep
= *end
++; end
[-1] = 0;
1236 while ((sep
= *end
++)) {
1238 mode
|= MODE_CHANOP
;
1239 else if (sep
== 'h')
1240 mode
|= MODE_HALFOP
;
1241 else if (sep
== 'v')
1243 else if (isdigit(sep
)) {
1244 mode
|= MODE_CHANOP
;
1245 while (isdigit(*end
)) end
++;
1252 if (!(un
= GetUserN(user
))) {
1256 if ((mNode
= AddChannelUser(un
, cNode
)))
1257 mNode
->modes
= mode
;
1263 static CMD_FUNC(cmd_mode
)
1265 struct chanNode
*cn
;
1266 struct userNode
*un
;
1267 char *sethost
; // sethost - reed/apples
1268 int i
; // sethost - reed/apples
1272 if (!IsChannelName(argv
[1])) {
1273 un
= GetUserH(argv
[1]);
1275 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to find user %s whose mode is changing.", argv
[1]);
1278 // sethost - reed/apples
1280 mod_usermode(un
, argv
[2]);
1282 sethost
= malloc(strlen(argv
[2]) + 1 + strlen(argv
[3]) + 1);
1284 while((sethost
[i
++] = *argv
[2]++));
1287 while((sethost
[i
++] = *argv
[3]++));
1288 mod_usermode(un
, sethost
); // sethost - reed/apples
1294 if (!(cn
= GetChannel(argv
[1]))) {
1295 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to find channel %s whose mode is changing.", argv
[1]);
1298 if ((un
= GetUserH(origin
))) {
1299 struct modeNode
*mn
;
1300 /* Update idle time for person setting the mode */
1301 if ((mn
= GetUserMode(cn
, un
)))
1302 mn
->idle_since
= now
;
1304 /* If it came from a server, reset timestamp to re-sync. */
1305 cn
->timestamp
= atoi(argv
[argc
-1]);
1308 return mod_chanmode(un
, cn
, argv
+2, argc
-2, MCP_ALLOW_OVB
|MCP_FROM_SERVER
|(un
? MC_NOTIFY
: 0));
1311 static CMD_FUNC(cmd_opmode
)
1313 struct chanNode
*cn
;
1314 struct userNode
*un
;
1319 if (!(cn
= GetChannel(argv
[1]))) {
1320 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to find channel %s whose mode is changing.", argv
[1]);
1323 if (!(un
= GetUserH(origin
))) {
1324 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to find user %s requesting OPMODE.", origin
);
1328 log_module(MAIN_LOG
, LOG_ERROR
, "Non-privileged user %s using OPMODE.", un
->nick
);
1332 return mod_chanmode(un
, cn
, argv
+2, argc
-2, MCP_ALLOW_OVB
|MCP_FROM_SERVER
); /* do NOT announce opmode locally */
1335 static int clear_chanmode(struct chanNode
*channel
, const char *modes
);
1337 static CMD_FUNC(cmd_clearmode
)
1339 struct chanNode
*cn
;
1340 struct userNode
*un
;
1345 if (!(cn
= GetChannel(argv
[1]))) {
1346 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to find channel %s whose mode is changing.", argv
[1]);
1349 if (!(un
= GetUserH(origin
))) {
1350 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to find user %s requesting CLEARMODE.", origin
);
1354 log_module(MAIN_LOG
, LOG_ERROR
, "Non-privileged user %s using CLEARMODE.", un
->nick
);
1358 return clear_chanmode(cn
, argv
[2]);
1361 static CMD_FUNC(cmd_topic
)
1363 struct chanNode
*cn
;
1364 time_t chan_ts
, topic_ts
;
1365 struct userNode
*user
;
1369 if (!(cn
= GetChannel(argv
[1]))) {
1370 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to find channel %s whose topic is being set", argv
[1]);
1375 if (argc
== 5) { /* Asuka / Topic Bursting IRCu's */
1376 user
= GetUserH(origin
);
1377 chan_ts
= atoi(argv
[2]);
1378 topic_ts
= atoi(argv
[3]);
1379 } else if (argc
>= 6) { /* Nefarious 0.5.0 */
1380 user
= GetUserH(strtok(argv
[2], "!"));
1381 chan_ts
= atoi(argv
[3]);
1382 topic_ts
= atoi(argv
[4]);
1383 } else { /* Regular IRCu (No Topic Bursting)*/
1384 user
= GetUserH(origin
);
1385 chan_ts
= cn
->timestamp
;
1389 SetChannelTopic(cn
, user
, user
, argv
[argc
-1], 0);
1390 cn
->topic_time
= topic_ts
;
1394 static CMD_FUNC(cmd_num_topic
)
1396 struct chanNode
*cn
;
1399 return 0; /* huh? */
1401 cn
= GetChannel(argv
[2]);
1403 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to find channel %s in topic reply", argv
[2]);
1409 switch (atoi(argv
[0])) {
1412 break; /* no topic */
1416 safestrncpy(cn
->topic
, unsplit_string(argv
+3, argc
-3, NULL
), sizeof(cn
->topic
));
1421 safestrncpy(cn
->topic_nick
, argv
[3], sizeof(cn
->topic_nick
));
1422 cn
->topic_time
= atoi(argv
[4]);
1425 return 0; /* should never happen */
1430 static CMD_FUNC(cmd_num_gline
)
1434 gline_add(origin
, argv
[3], atoi(argv
[4])-now
, argv
[5], now
, 0, 0);
1438 static CMD_FUNC(cmd_num_shun
)
1442 shun_add(origin
, argv
[3], atoi(argv
[4])-now
, argv
[5], now
, 0);
1446 static CMD_FUNC(cmd_quit
)
1448 struct userNode
*user
;
1451 /* Sometimes we get a KILL then a QUIT or the like, so we don't want to
1452 * call DelUser unless we have the user in our grasp. */
1453 if ((user
= GetUserH(origin
)))
1454 DelUser(user
, NULL
, false, argv
[1]);
1458 static CMD_FUNC(cmd_kill
)
1460 struct userNode
*user
;
1463 user
= GetUserN(argv
[1]);
1465 /* If we get a KILL for a non-existent user, it could be a
1466 * Ghost response to a KILL we sent out earlier. So we only
1467 * whine if the target is local.
1469 if (!strncmp(argv
[1], self
->numeric
, strlen(self
->numeric
)))
1470 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to find kill victim %s", argv
[1]);
1474 if (IsLocal(user
) && IsService(user
)) {
1475 /* TODO: rate limit this so silly things don't happen. */
1476 ReintroduceUser(user
);
1480 DelUser(user
, NULL
, false, argv
[2]);
1484 static CMD_FUNC(cmd_part
)
1486 struct userNode
*user
;
1490 user
= GetUserH(origin
);
1493 parse_foreach(argv
[1], part_helper
, NULL
, NULL
, NULL
, user
);
1497 static CMD_FUNC(cmd_kick
)
1501 ChannelUserKicked(GetUserH(origin
), GetUserN(argv
[2]), GetChannel(argv
[1]));
1505 static CMD_FUNC(cmd_squit
)
1507 struct server
*server
;
1511 if (!(server
= GetServerH(argv
[1])))
1514 if (server
== self
->uplink
) {
1515 /* Force a reconnect to the currently selected server. */
1516 cManager
.uplink
->tries
= 0;
1517 log_module(MAIN_LOG
, LOG_INFO
, "Squitting from uplink: %s", argv
[3]);
1522 DelServer(server
, 0, argv
[3]);
1526 static CMD_FUNC(cmd_privmsg
)
1528 struct privmsg_desc pd
;
1531 pd
.user
= GetUserH(origin
);
1532 if (!pd
.user
|| (IsGagged(pd
.user
) && !IsOper(pd
.user
)))
1536 parse_foreach(argv
[1], privmsg_chan_helper
, NULL
, privmsg_user_helper
, privmsg_invalid
, &pd
);
1540 static CMD_FUNC(cmd_notice
)
1542 struct privmsg_desc pd
;
1545 pd
.user
= GetUserH(origin
);
1546 if (!pd
.user
|| (IsGagged(pd
.user
) && !IsOper(pd
.user
)))
1550 parse_foreach(argv
[1], privmsg_chan_helper
, NULL
, privmsg_user_helper
, privmsg_invalid
, &pd
);
1554 static CMD_FUNC(cmd_away
)
1556 struct userNode
*uNode
;
1558 uNode
= GetUserH(origin
);
1562 uNode
->modes
&= ~FLAGS_AWAY
;
1564 uNode
->modes
|= FLAGS_AWAY
;
1568 static CMD_FUNC(cmd_gline
)
1572 if (argv
[2][0] == '+') {
1575 gline_add(origin
, argv
[2]+1, strtoul(argv
[3], NULL
, 0), argv
[argc
-1], now
, 0, 0);
1577 } else if (argv
[2][0] == '-') {
1578 gline_remove(argv
[2]+1, 0);
1584 static CMD_FUNC(cmd_shun
)
1588 if (argv
[2][0] == '+') {
1591 shun_add(origin
, argv
[2]+1, strtoul(argv
[3], NULL
, 0), argv
[argc
-1], now
, 0);
1593 } else if (argv
[2][0] == '-') {
1594 shun_remove(argv
[2]+1, 0);
1600 static CMD_FUNC(cmd_svsnick
)
1602 struct userNode
*target
, *dest
;
1604 || !(target
= GetUserN(argv
[1]))
1606 || (dest
= GetUserH(argv
[2])))
1608 NickChange(target
, argv
[2], 0);
1612 static oper_func_t
*of_list
;
1613 static unsigned int of_size
= 0, of_used
= 0;
1616 free_user(struct userNode
*user
)
1627 free(privmsg_funcs
);
1630 dict_delete(irc_func_dict
);
1631 for (nn
=0; nn
<dead_users
.used
; nn
++)
1632 free_user(dead_users
.list
[nn
]);
1633 userList_clean(&dead_users
);
1637 p10_conf_reload(void) {
1638 hidden_host_suffix
= conf_get_data("server/hidden_host", RECDB_QSTRING
);
1642 remove_unbursted_channel(struct chanNode
*cNode
) {
1643 if (unbursted_channels
)
1644 dict_remove(unbursted_channels
, cNode
->name
);
1650 const char *str
, *desc
;
1651 int numnick
, usermask
, max_users
;
1652 char numer
[COMBO_NUMERIC_LEN
+1];
1654 /* read config items */
1655 str
= conf_get_data("server/ping_freq", RECDB_QSTRING
);
1656 ping_freq
= str
? ParseInterval(str
) : 120;
1657 str
= conf_get_data("server/ping_timeout", RECDB_QSTRING
);
1658 ping_timeout
= str
? ParseInterval(str
) : 30;
1659 str
= conf_get_data("server/force_n2k", RECDB_QSTRING
);
1660 force_n2k
= str
? enabled_string(str
) : 1;
1661 str
= conf_get_data("server/numeric", RECDB_QSTRING
);
1663 log_module(MAIN_LOG
, LOG_ERROR
, "No server/numeric entry in config file.");
1666 numnick
= atoi(str
);
1667 str
= conf_get_data("server/max_users", RECDB_QSTRING
);
1668 max_users
= str
? atoi(str
) : 4096;
1669 for (usermask
= 4; usermask
< max_users
; usermask
<<= 1) ;
1671 if ((numnick
< 64) && (usermask
< 4096) && !force_n2k
)
1672 inttobase64(numer
, (numnick
<< 12) + (usermask
& 0x00fff), 3);
1674 inttobase64(numer
, (numnick
<< 18) + (usermask
& 0x3ffff), 5);
1676 str
= conf_get_data("server/his_servername", RECDB_QSTRING
);
1677 his_servername
= str
? strdup(str
) : NULL
;
1678 str
= conf_get_data("server/his_servercomment", RECDB_QSTRING
);
1679 his_servercomment
= str
? strdup(str
) : NULL
;
1681 str
= conf_get_data("server/hostname", RECDB_QSTRING
);
1682 desc
= conf_get_data("server/description", RECDB_QSTRING
);
1683 if (!str
|| !desc
) {
1684 log_module(MAIN_LOG
, LOG_ERROR
, "No server/hostname entry in config file.");
1687 self
= AddServer(NULL
, str
, 0, boot_time
, now
, numer
, desc
);
1688 conf_register_reload(p10_conf_reload
);
1690 irc_func_dict
= dict_new();
1691 dict_insert(irc_func_dict
, CMD_BURST
, cmd_burst
);
1692 dict_insert(irc_func_dict
, TOK_BURST
, cmd_burst
);
1693 dict_insert(irc_func_dict
, CMD_CREATE
, cmd_create
);
1694 dict_insert(irc_func_dict
, TOK_CREATE
, cmd_create
);
1695 dict_insert(irc_func_dict
, CMD_EOB
, cmd_eob
);
1696 dict_insert(irc_func_dict
, TOK_EOB
, cmd_eob
);
1697 dict_insert(irc_func_dict
, CMD_EOB_ACK
, cmd_eob_ack
);
1698 dict_insert(irc_func_dict
, TOK_EOB_ACK
, cmd_eob_ack
);
1699 dict_insert(irc_func_dict
, CMD_MODE
, cmd_mode
);
1700 dict_insert(irc_func_dict
, TOK_MODE
, cmd_mode
);
1701 dict_insert(irc_func_dict
, CMD_NICK
, cmd_nick
);
1702 dict_insert(irc_func_dict
, TOK_NICK
, cmd_nick
);
1703 dict_insert(irc_func_dict
, CMD_ACCOUNT
, cmd_account
);
1704 dict_insert(irc_func_dict
, TOK_ACCOUNT
, cmd_account
);
1705 dict_insert(irc_func_dict
, CMD_FAKEHOST
, cmd_fakehost
);
1706 dict_insert(irc_func_dict
, TOK_FAKEHOST
, cmd_fakehost
);
1707 dict_insert(irc_func_dict
, CMD_PASS
, cmd_pass
);
1708 dict_insert(irc_func_dict
, TOK_PASS
, cmd_pass
);
1709 dict_insert(irc_func_dict
, CMD_PING
, cmd_ping
);
1710 dict_insert(irc_func_dict
, TOK_PING
, cmd_ping
);
1711 dict_insert(irc_func_dict
, CMD_PRIVMSG
, cmd_privmsg
);
1712 dict_insert(irc_func_dict
, TOK_PRIVMSG
, cmd_privmsg
);
1713 dict_insert(irc_func_dict
, CMD_PONG
, cmd_pong
);
1714 dict_insert(irc_func_dict
, TOK_PONG
, cmd_pong
);
1715 dict_insert(irc_func_dict
, CMD_QUIT
, cmd_quit
);
1716 dict_insert(irc_func_dict
, TOK_QUIT
, cmd_quit
);
1717 dict_insert(irc_func_dict
, CMD_SERVER
, cmd_server
);
1718 dict_insert(irc_func_dict
, TOK_SERVER
, cmd_server
);
1719 dict_insert(irc_func_dict
, CMD_JOIN
, cmd_join
);
1720 dict_insert(irc_func_dict
, TOK_JOIN
, cmd_join
);
1721 dict_insert(irc_func_dict
, CMD_PART
, cmd_part
);
1722 dict_insert(irc_func_dict
, TOK_PART
, cmd_part
);
1723 dict_insert(irc_func_dict
, CMD_ERROR
, cmd_error
);
1724 dict_insert(irc_func_dict
, TOK_ERROR
, cmd_error
);
1725 dict_insert(irc_func_dict
, CMD_TOPIC
, cmd_topic
);
1726 dict_insert(irc_func_dict
, TOK_TOPIC
, cmd_topic
);
1727 dict_insert(irc_func_dict
, CMD_AWAY
, cmd_away
);
1728 dict_insert(irc_func_dict
, TOK_AWAY
, cmd_away
);
1729 dict_insert(irc_func_dict
, CMD_SILENCE
, cmd_dummy
);
1730 dict_insert(irc_func_dict
, TOK_SILENCE
, cmd_dummy
);
1731 dict_insert(irc_func_dict
, CMD_KICK
, cmd_kick
);
1732 dict_insert(irc_func_dict
, TOK_KICK
, cmd_kick
);
1733 dict_insert(irc_func_dict
, CMD_SQUIT
, cmd_squit
);
1734 dict_insert(irc_func_dict
, TOK_SQUIT
, cmd_squit
);
1735 dict_insert(irc_func_dict
, CMD_KILL
, cmd_kill
);
1736 dict_insert(irc_func_dict
, TOK_KILL
, cmd_kill
);
1737 dict_insert(irc_func_dict
, CMD_NOTICE
, cmd_notice
);
1738 dict_insert(irc_func_dict
, TOK_NOTICE
, cmd_notice
);
1739 dict_insert(irc_func_dict
, CMD_STATS
, cmd_stats
);
1740 dict_insert(irc_func_dict
, TOK_STATS
, cmd_stats
);
1741 dict_insert(irc_func_dict
, CMD_SVSNICK
, cmd_svsnick
);
1742 dict_insert(irc_func_dict
, TOK_SVSNICK
, cmd_svsnick
);
1743 dict_insert(irc_func_dict
, CMD_WHOIS
, cmd_whois
);
1744 dict_insert(irc_func_dict
, TOK_WHOIS
, cmd_whois
);
1745 dict_insert(irc_func_dict
, CMD_GLINE
, cmd_gline
);
1746 dict_insert(irc_func_dict
, TOK_GLINE
, cmd_gline
);
1747 dict_insert(irc_func_dict
, CMD_SHUN
, cmd_shun
);
1748 dict_insert(irc_func_dict
, TOK_SHUN
, cmd_shun
);
1749 dict_insert(irc_func_dict
, CMD_OPMODE
, cmd_opmode
);
1750 dict_insert(irc_func_dict
, TOK_OPMODE
, cmd_opmode
);
1751 dict_insert(irc_func_dict
, CMD_CLEARMODE
, cmd_clearmode
);
1752 dict_insert(irc_func_dict
, TOK_CLEARMODE
, cmd_clearmode
);
1753 dict_insert(irc_func_dict
, CMD_VERSION
, cmd_version
);
1754 dict_insert(irc_func_dict
, TOK_VERSION
, cmd_version
);
1755 dict_insert(irc_func_dict
, CMD_ADMIN
, cmd_admin
);
1756 dict_insert(irc_func_dict
, TOK_ADMIN
, cmd_admin
);
1758 /* In P10, DESTRUCT doesn't do anything except be broadcast to servers.
1759 * Apparently to obliterate channels from any servers that think they
1762 dict_insert(irc_func_dict
, CMD_DESTRUCT
, cmd_dummy
);
1763 dict_insert(irc_func_dict
, TOK_DESTRUCT
, cmd_dummy
);
1764 /* Ignore invites */
1765 dict_insert(irc_func_dict
, CMD_INVITE
, cmd_dummy
);
1766 dict_insert(irc_func_dict
, TOK_INVITE
, cmd_dummy
);
1767 /* DESYNCH is just informational, so ignore it */
1768 dict_insert(irc_func_dict
, CMD_DESYNCH
, cmd_dummy
);
1769 dict_insert(irc_func_dict
, TOK_DESYNCH
, cmd_dummy
);
1770 /* Ignore channel operator notices. */
1771 dict_insert(irc_func_dict
, CMD_WALLCHOPS
, cmd_dummy
);
1772 dict_insert(irc_func_dict
, TOK_WALLCHOPS
, cmd_dummy
);
1773 dict_insert(irc_func_dict
, CMD_WALLVOICES
, cmd_dummy
);
1774 dict_insert(irc_func_dict
, TOK_WALLVOICES
, cmd_dummy
);
1775 dict_insert(irc_func_dict
, CMD_WALLHOPS
, cmd_dummy
);
1776 dict_insert(irc_func_dict
, TOK_WALLHOPS
, cmd_dummy
);
1777 /* Ignore opers being silly. */
1778 dict_insert(irc_func_dict
, CMD_WALLOPS
, cmd_dummy
);
1779 dict_insert(irc_func_dict
, TOK_WALLOPS
, cmd_dummy
);
1780 dict_insert(irc_func_dict
, CMD_WALLHOPS
, cmd_dummy
);
1781 dict_insert(irc_func_dict
, TOK_WALLHOPS
, cmd_dummy
);
1782 dict_insert(irc_func_dict
, TOK_WALLUSERS
, cmd_dummy
);
1783 /* Ignore dnsbl exemptions */
1784 dict_insert(irc_func_dict
, TOK_EXEMPT
, cmd_dummy
);
1785 dict_insert(irc_func_dict
, TOK_MARK
, cmd_dummy
);
1787 dict_insert(irc_func_dict
, TOK_PRIVS
, cmd_dummy
);
1788 /* Ignore remote luser */
1789 dict_insert(irc_func_dict
, TOK_LUSERS
, cmd_dummy
);
1790 /* We have reliable clock! Always! Wraaa! */
1791 dict_insert(irc_func_dict
, CMD_SETTIME
, cmd_dummy
);
1792 dict_insert(irc_func_dict
, TOK_SETTIME
, cmd_dummy
);
1794 dict_insert(irc_func_dict
, "331", cmd_num_topic
);
1795 dict_insert(irc_func_dict
, "332", cmd_num_topic
);
1796 dict_insert(irc_func_dict
, "333", cmd_num_topic
);
1797 dict_insert(irc_func_dict
, "345", cmd_dummy
); /* blah has been invited to blah */
1798 dict_insert(irc_func_dict
, "432", cmd_error_nick
); /* Erroneus [sic] nickname */
1799 /* ban list resetting */
1800 /* "stats g" responses */
1801 dict_insert(irc_func_dict
, "247", cmd_num_gline
);
1802 dict_insert(irc_func_dict
, "542", cmd_num_shun
);
1803 dict_insert(irc_func_dict
, "219", cmd_dummy
); /* "End of /STATS report" */
1804 /* other numeric responses we might get */
1805 dict_insert(irc_func_dict
, "401", cmd_dummy
); /* target left network */
1806 dict_insert(irc_func_dict
, "403", cmd_dummy
); /* no such channel */
1807 dict_insert(irc_func_dict
, "404", cmd_dummy
); /* cannot send to channel */
1808 dict_insert(irc_func_dict
, "439", cmd_dummy
); /* target change too fast */
1809 dict_insert(irc_func_dict
, "441", cmd_dummy
); /* target isn't on that channel */
1810 dict_insert(irc_func_dict
, "442", cmd_dummy
); /* you aren't on that channel */
1811 dict_insert(irc_func_dict
, "443", cmd_dummy
); /* is already on channel (after invite?) */
1812 dict_insert(irc_func_dict
, "461", cmd_dummy
); /* Not enough parameters (after TOPIC w/ 0 args) */
1813 dict_insert(irc_func_dict
, "467", cmd_dummy
); /* Channel key already set */
1815 num_privmsg_funcs
= 16;
1816 privmsg_funcs
= malloc(sizeof(privmsg_func_t
)*num_privmsg_funcs
);
1817 memset(privmsg_funcs
, 0, sizeof(privmsg_func_t
)*num_privmsg_funcs
);
1819 num_notice_funcs
= 16;
1820 notice_funcs
= malloc(sizeof(privmsg_func_t
)*num_notice_funcs
);
1821 memset(notice_funcs
, 0, sizeof(privmsg_func_t
)*num_notice_funcs
);
1823 userList_init(&dead_users
);
1824 reg_del_channel_func(remove_unbursted_channel
);
1825 reg_exit_func(parse_cleanup
);
1829 parse_line(char *line
, int recursive
)
1831 char *argv
[MAXNUMPARAMS
], *origin
;
1832 int argc
, cmd
, res
=0;
1835 argc
= split_line(line
, true, MAXNUMPARAMS
, argv
);
1836 cmd
= self
->uplink
|| !argv
[0][1] || !argv
[0][2];
1839 if (argv
[0][0] == ':') {
1841 } else if (!argv
[0][1] || !argv
[0][2]) {
1842 struct server
*sNode
= GetServerN(argv
[0]);
1843 origin
= sNode
? sNode
->name
: 0;
1845 struct userNode
*uNode
= GetUserN(argv
[0]);
1846 origin
= uNode
? uNode
->nick
: 0;
1850 if ((func
= dict_find(irc_func_dict
, argv
[cmd
], NULL
)))
1851 res
= func(origin
, argc
-cmd
, argv
+cmd
);
1854 log_module(MAIN_LOG
, LOG_ERROR
, "PARSE ERROR on line: %s", unsplit_string(argv
, argc
, NULL
));
1855 } else if (!recursive
) {
1857 for (i
=0; i
<dead_users
.used
; i
++)
1858 free_user(dead_users
.list
[i
]);
1859 dead_users
.used
= 0;
1865 parse_foreach(char *target_list
, foreach_chanfunc cf
, foreach_nonchan nc
, foreach_userfunc uf
, foreach_nonuser nu
, void *data
)
1870 while (*j
!= 0 && *j
!= ',')
1874 if (IsChannelName(target_list
)
1875 || (target_list
[0] == '0' && target_list
[1] == '\0')) {
1876 struct chanNode
*chan
= GetChannel(target_list
);
1882 nc(target_list
, data
);
1885 struct userNode
*user
;
1886 struct privmsg_desc
*pd
= data
;
1888 pd
->is_qualified
= 0;
1889 if (*target_list
== '@') {
1891 } else if (strchr(target_list
, '@')) {
1892 struct server
*server
;
1894 pd
->is_qualified
= 1;
1895 user
= GetUserH(strtok(target_list
, "@"));
1896 server
= GetServerH(strtok(NULL
, "@"));
1898 if (user
&& (user
->uplink
!= server
)) {
1899 /* Don't attempt to index into any arrays
1900 using a user's numeric on another server. */
1904 user
= GetUserN(target_list
);
1912 nu(target_list
, data
);
1916 } while (old
== ',');
1920 get_local_numeric(void)
1922 static unsigned int next_numeric
= 0;
1923 if (self
->clients
> self
->num_mask
)
1925 while (self
->users
[next_numeric
])
1926 if (++next_numeric
> self
->num_mask
)
1928 return next_numeric
;
1932 make_numeric(struct server
*svr
, int local_num
, char *outbuf
)
1936 if (force_n2k
|| svr
->numeric
[1]) {
1941 llen
= (local_num
< 64*64) ? 2 : 3;
1943 strncpy(outbuf
, svr
->numeric
, slen
);
1944 inttobase64(outbuf
+slen
, local_num
, llen
);
1945 outbuf
[slen
+llen
] = 0;
1949 AddServer(struct server
*uplink
, const char *name
, int hops
, time_t boot
, time_t link
, const char *numeric
, const char *description
)
1951 struct server
* sNode
;
1954 if ((sNode
= GetServerN(numeric
))) {
1955 /* This means we're trying to re-add an existant server.
1956 * To be safe, we should forget the previous incarnation.
1957 * (And all its linked servers.)
1959 * It usually only happens in replays when the original
1960 * had a ping timeout and the replay didn't (because
1961 * replaying a ping timeout invariably gets things wrong).
1963 DelServer(sNode
, 0, NULL
);
1966 switch (strlen(numeric
)) {
1967 case 5: slen
= 2; mlen
= 3; break;
1968 case 4: slen
= 1; mlen
= 3; break;
1969 case 3: slen
= 1; mlen
= 2; break;
1971 log_module(MAIN_LOG
, LOG_ERROR
, "AddServer(\"%s\", \"%s\", ...): Numeric %s has invalid length.", uplink
->name
, name
, numeric
);
1975 sNode
= calloc(1, sizeof(*sNode
));
1976 sNode
->uplink
= uplink
;
1977 safestrncpy(sNode
->name
, name
, sizeof(sNode
->name
));
1978 sNode
->num_mask
= base64toint(numeric
+slen
, mlen
);
1982 strncpy(sNode
->numeric
, numeric
, slen
);
1983 safestrncpy(sNode
->description
, description
, sizeof(sNode
->description
));
1984 sNode
->users
= calloc(sNode
->num_mask
+1, sizeof(*sNode
->users
));
1985 serverList_init(&sNode
->children
);
1986 if (sNode
->uplink
) {
1987 /* uplink may be NULL if we're just building ourself */
1988 serverList_append(&sNode
->uplink
->children
, sNode
);
1990 servers_num
[base64toint(numeric
, slen
)] = sNode
;
1991 dict_insert(servers
, sNode
->name
, sNode
);
1995 void DelServer(struct server
* serv
, int announce
, const char *message
)
1999 /* If we receive an ERROR command before the SERVER
2000 * command a NULL server can be passed */
2004 /* Hrm, what's the right way to SQUIT some other server?
2005 * (This code is only to handle killing juped servers.) */
2006 if (announce
&& (serv
->uplink
== self
) && (serv
!= self
->uplink
))
2007 irc_squit(serv
, message
, NULL
);
2009 /* must recursively remove servers linked to this one first */
2010 for (i
=serv
->children
.used
;i
>0;)
2011 if (serv
->children
.list
[--i
] != self
)
2012 DelServer(serv
->children
.list
[i
], false, NULL
);
2014 /* clean up server's user hash tables */
2015 for (i
=0;i
<=serv
->num_mask
;i
++)
2017 DelUser(serv
->users
[i
], NULL
, false, "server delinked");
2021 serverList_remove(&serv
->uplink
->children
, serv
);
2022 if (serv
== self
->uplink
)
2023 self
->uplink
= NULL
;
2024 servers_num
[base64toint(serv
->numeric
, strlen(serv
->numeric
))] = NULL
;
2025 dict_remove(servers
, serv
->name
);
2026 serverList_clean(&serv
->children
);
2032 AddService(const char *nick
, const char *modes
, const char *desc
, const char *hostname
)
2034 char numeric
[COMBO_NUMERIC_LEN
+1];
2035 int local_num
= get_local_numeric();
2036 time_t timestamp
= now
;
2037 struct userNode
*old_user
= GetUserH(nick
);
2040 if (IsLocal(old_user
))
2042 timestamp
= old_user
->timestamp
- 1;
2044 if (local_num
== -1) {
2045 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to allocate numnick for service %s", nick
);
2049 hostname
= self
->name
;
2050 make_numeric(self
, local_num
, numeric
);
2051 /* TODO: Make these modes part of the conf file */
2052 return AddUser(self
, nick
, nick
, hostname
, modes
? modes
: "+oik", numeric
, desc
, now
, "AAAAAA");
2056 AddClone(const char *nick
, const char *ident
, const char *hostname
, const char *desc
)
2058 char numeric
[COMBO_NUMERIC_LEN
+1];
2059 int local_num
= get_local_numeric();
2060 time_t timestamp
= now
;
2061 struct userNode
*old_user
= GetUserH(nick
);
2064 if (IsLocal(old_user
))
2066 timestamp
= old_user
->timestamp
- 1;
2068 if (local_num
== -1) {
2069 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to allocate numnick for clone %s", nick
);
2072 make_numeric(self
, local_num
, numeric
);
2073 return AddUser(self
, nick
, ident
, hostname
, "+i", numeric
, desc
, timestamp
, "AAAAAA");
2077 is_valid_nick(const char *nick
) {
2079 /* IRC has some of The Most Fucked-Up ideas about character sets
2081 if (!isalpha(*nick
) && !strchr("{|}~[\\]^_`", *nick
))
2083 for (ii
= 0; nick
[ii
]; ++ii
)
2084 if (!isalnum(nick
[ii
]) && !strchr("{|}~[\\]^-_`", nick
[ii
]))
2086 if (strlen(nick
) > nicklen
)
2091 static struct userNode
*
2092 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
)
2094 struct userNode
*oldUser
, *uNode
;
2095 unsigned int n
, ignore_user
;
2097 if ((strlen(numeric
) < 3) || (strlen(numeric
) > 5)) {
2098 log_module(MAIN_LOG
, LOG_WARNING
, "AddUser(%p, %s, ...): numeric %s wrong length!", uplink
, nick
, numeric
);
2103 log_module(MAIN_LOG
, LOG_WARNING
, "AddUser(%p, %s, ...): server for numeric %s doesn't exist!", uplink
, nick
, numeric
);
2107 if (uplink
!= GetServerN(numeric
)) {
2108 log_module(MAIN_LOG
, LOG_WARNING
, "AddUser(%p, %s, ...): server for numeric %s differs from nominal uplink %s.", uplink
, nick
, numeric
, uplink
->name
);
2112 if (!is_valid_nick(nick
)) {
2113 log_module(MAIN_LOG
, LOG_WARNING
, "AddUser(%p, %s, ...): invalid nickname detected.", uplink
, nick
);
2118 if ((oldUser
= GetUserH(nick
))) {
2119 if (IsLocal(oldUser
) && (IsService(oldUser
) || IsPersistent(oldUser
))) {
2120 /* The service should collide the new user off. */
2121 oldUser
->timestamp
= timestamp
- 1;
2124 if (oldUser
->timestamp
> timestamp
) {
2125 /* "Old" user is really newer; remove them */
2126 DelUser(oldUser
, 0, 1, "Overruled by older nick");
2128 /* User being added is too new; do not add them to
2129 * clients, but do add them to the server's list, since it
2130 * will send a KILL and QUIT soon. */
2135 /* create new usernode and set all values */
2136 uNode
= calloc(1, sizeof(*uNode
));
2137 uNode
->nick
= strdup(nick
);
2138 safestrncpy(uNode
->ident
, ident
, sizeof(uNode
->ident
));
2139 safestrncpy(uNode
->info
, userinfo
, sizeof(uNode
->info
));
2140 safestrncpy(uNode
->hostname
, hostname
, sizeof(uNode
->hostname
));
2141 safestrncpy(uNode
->numeric
, numeric
, sizeof(uNode
->numeric
));
2142 uNode
->ip
.s_addr
= htonl(base64toint(realip
, 6));
2143 uNode
->timestamp
= timestamp
;
2144 modeList_init(&uNode
->channels
);
2145 uNode
->uplink
= uplink
;
2146 if (++uNode
->uplink
->clients
> uNode
->uplink
->max_clients
) {
2147 uNode
->uplink
->max_clients
= uNode
->uplink
->clients
;
2149 uNode
->num_local
= base64toint(numeric
+strlen(uNode
->uplink
->numeric
), 3) & uNode
->uplink
->num_mask
;
2150 uNode
->uplink
->users
[uNode
->num_local
] = uNode
;
2151 mod_usermode(uNode
, modes
);
2155 dict_insert(clients
, uNode
->nick
, uNode
);
2156 if (dict_size(clients
) > max_clients
) {
2157 max_clients
= dict_size(clients
);
2158 max_clients_time
= now
;
2162 for (n
=0; n
<nuf_used
; n
++)
2163 if (nuf_list
[n
](uNode
))
2166 if ((uNode
->loc
== 1) && (uNode
->handle_info
))
2167 send_func_list(uNode
);
2172 /* removes user from it's server's hash table and nick hash table */
2174 DelUser(struct userNode
* user
, struct userNode
*killer
, int announce
, const char *why
)
2180 /* mark them as dead, in case anybody cares */
2183 /* remove pending adduser commands */
2184 wipe_adduser_pending(NULL
, user
);
2186 /* remove user from all channels */
2187 while (user
->channels
.used
> 0)
2188 DelChannelUser(user
, user
->channels
.list
[user
->channels
.used
-1]->channel
, false, 0);
2190 /* Call these in reverse order so ChanServ can update presence
2191 information before NickServ nukes the handle_info. */
2192 for (n
= duf_used
; n
> 0; )
2193 duf_list
[--n
](user
, killer
, why
);
2195 user
->uplink
->clients
--;
2196 user
->uplink
->users
[user
->num_local
] = NULL
;
2198 userList_remove(&curr_opers
, user
);
2199 /* remove from global dictionary, but not if after a collide */
2200 if (user
== dict_find(clients
, user
->nick
, NULL
))
2201 dict_remove(clients
, user
->nick
);
2203 if (IsInvisible(user
))
2208 irc_quit(user
, why
);
2210 irc_kill(killer
, user
, why
);
2213 modeList_clean(&user
->channels
);
2214 /* We don't free them, in case we try to privmsg them or something
2215 * (like when a stupid oper kills themself). We just put them onto
2216 * a list of clients that get freed after processing each line.
2218 if (dead_users
.size
)
2219 userList_append(&dead_users
, user
);
2224 static void call_oper_funcs(struct userNode
*user
);
2226 void mod_usermode(struct userNode
*user
, const char *mode_change
) {
2228 const char *word
= mode_change
;
2230 if (!user
|| !mode_change
)
2232 while (*word
!= ' ' && *word
) word
++;
2233 while (*word
== ' ') word
++;
2235 #define do_user_mode(FLAG) do { if (add) user->modes |= FLAG; else user->modes &= ~FLAG; } while (0)
2236 switch (*mode_change
++) {
2237 case 0: case ' ': return;
2238 case '+': add
= 1; break;
2239 case '-': add
= 0; break;
2242 if(!IsOper(user
)) { /* Dont re-oper an oper */
2243 userList_append(&curr_opers
, user
);
2244 call_oper_funcs(user
);
2247 userList_remove(&curr_opers
, user
);
2249 do_user_mode(FLAGS_OPER
);
2251 case 'O': do_user_mode(FLAGS_LOCOP
); break;
2252 case 'i': do_user_mode(FLAGS_INVISIBLE
);
2258 case 'w': do_user_mode(FLAGS_WALLOP
); break;
2259 case 's': do_user_mode(FLAGS_SERVNOTICE
); break;
2260 case 'd': do_user_mode(FLAGS_DEAF
); break;
2261 case 'k': do_user_mode(FLAGS_SERVICE
); break;
2262 case 'g': do_user_mode(FLAGS_GLOBAL
); break;
2263 // sethost - reed/apples
2264 // case 'h': do_user_mode(FLAGS_HELPER); break;
2265 // I check if there's an 'h' in the first part, and if there,
2266 // then everything after the space becomes their new host.
2267 case 'h': do_user_mode(FLAGS_SETHOST
);
2269 char sethost
[MAXLEN
];
2271 for (ii
=0; (*word
!= ' ') && (*word
!= '\0'); )
2272 sethost
[ii
++] = *word
++;
2274 while (*word
== ' ')
2276 safestrncpy(user
->sethost
, sethost
, sizeof(user
->sethost
));
2279 case 'x': do_user_mode(FLAGS_HIDDEN_HOST
); break;
2284 for (ii
=0; (*word
!= ' ') && (*word
!= '\0'); )
2285 tag
[ii
++] = *word
++;
2287 while (*word
== ' ')
2289 call_account_func(user
, tag
);
2296 for (ii
=0; (*word
!= ' ') && (*word
!= '\0'); )
2297 host
[ii
++] = *word
++;
2299 while (*word
== ' ')
2301 assign_fakehost(user
, host
, 0);
2309 struct mod_chanmode
*
2310 mod_chanmode_parse(struct chanNode
*channel
, char **modes
, unsigned int argc
, unsigned int flags
)
2312 struct mod_chanmode
*change
;
2313 unsigned int ii
, in_arg
, ch_arg
, add
;
2317 if (!(change
= mod_chanmode_alloc(argc
- 1)))
2320 for (ii
= ch_arg
= 0, in_arg
= add
= 1;
2321 (modes
[0][ii
] != '\0') && (modes
[0][ii
] != ' ');
2323 switch (modes
[0][ii
]) {
2330 #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)
2331 case 'C': do_chan_mode(MODE_NOCTCPS
); break;
2332 case 'D': do_chan_mode(MODE_DELAYJOINS
); break;
2333 case 'c': do_chan_mode(MODE_NOCOLORS
); break;
2334 case 'i': do_chan_mode(MODE_INVITEONLY
); break;
2335 case 'm': do_chan_mode(MODE_MODERATED
); break;
2336 case 'n': do_chan_mode(MODE_NOPRIVMSGS
); break;
2337 case 'p': do_chan_mode(MODE_PRIVATE
); break;
2338 case 'r': do_chan_mode(MODE_REGONLY
); break;
2339 case 's': do_chan_mode(MODE_SECRET
); break;
2340 case 't': do_chan_mode(MODE_TOPICLIMIT
); break;
2341 case 'S': do_chan_mode(MODE_STRIPCOLOR
); break;
2342 case 'M': do_chan_mode(MODE_MODUNREG
); break;
2343 case 'N': do_chan_mode(MODE_NONOTICE
); break;
2344 case 'Q': do_chan_mode(MODE_NOQUITMSGS
); break;
2345 case 'T': do_chan_mode(MODE_NOAMSG
); break;
2346 case 'O': do_chan_mode(MODE_OPERSONLY
); break;
2347 case 'Z': do_chan_mode(MODE_SSLONLY
); break;
2348 case 'L': do_chan_mode(MODE_HIDEMODE
); break;
2350 if (!(flags
& MCP_REGISTERED
)) {
2351 do_chan_mode(MODE_REGISTERED
);
2353 mod_chanmode_free(change
);
2362 change
->modes_set
|= MODE_LIMIT
;
2363 change
->new_limit
= atoi(modes
[in_arg
++]);
2365 change
->modes_set
&= ~MODE_LIMIT
;
2366 change
->modes_clear
|= MODE_LIMIT
;
2373 change
->modes_set
|= MODE_KEY
;
2374 safestrncpy(change
->new_key
, modes
[in_arg
++], sizeof(change
->new_key
));
2376 change
->modes_clear
|= MODE_KEY
;
2377 if (!(flags
& MCP_KEY_FREE
)) {
2385 if (!(flags
& MCP_ALLOW_OVB
))
2389 change
->args
[ch_arg
].mode
= MODE_BAN
;
2391 change
->args
[ch_arg
].mode
|= MODE_REMOVE
;
2392 change
->args
[ch_arg
++].u
.hostmask
= modes
[in_arg
++];
2395 if (!(flags
& MCP_ALLOW_OVB
))
2399 change
->args
[ch_arg
].mode
= MODE_EXEMPT
;
2401 change
->args
[ch_arg
].mode
|= MODE_REMOVE
;
2402 change
->args
[ch_arg
++].u
.hostmask
= modes
[in_arg
++];
2404 case 'o': case 'h': case 'v':
2406 struct userNode
*victim
;
2407 if (!(flags
& MCP_ALLOW_OVB
))
2412 if (modes
[0][ii
] == 'o')
2413 change
->args
[ch_arg
].mode
= MODE_CHANOP
;
2414 else if (modes
[0][ii
] == 'h')
2415 change
->args
[ch_arg
].mode
= MODE_HALFOP
;
2416 else if (modes
[0][ii
] == 'v')
2417 change
->args
[ch_arg
].mode
= MODE_VOICE
;
2420 change
->args
[ch_arg
].mode
|= MODE_REMOVE
;
2421 if (flags
& MCP_FROM_SERVER
)
2422 victim
= GetUserN(modes
[in_arg
++]);
2424 victim
= GetUserH(modes
[in_arg
++]);
2427 if ((change
->args
[ch_arg
].u
.member
= GetUserMode(channel
, victim
)))
2432 if (!(flags
& MCP_FROM_SERVER
))
2437 change
->argc
= ch_arg
; /* in case any turned out to be ignored */
2438 if (change
->modes_set
& MODE_SECRET
) {
2439 change
->modes_set
&= ~(MODE_PRIVATE
);
2440 change
->modes_clear
|= MODE_PRIVATE
;
2441 } else if (change
->modes_set
& MODE_PRIVATE
) {
2442 change
->modes_set
&= ~(MODE_SECRET
);
2443 change
->modes_clear
|= MODE_SECRET
;
2447 mod_chanmode_free(change
);
2451 struct chanmode_buffer
{
2454 struct chanNode
*channel
;
2455 struct userNode
*actor
;
2456 unsigned int modes_used
;
2457 unsigned int args_used
;
2459 unsigned int is_add
: 1;
2460 unsigned int is_chanop
: 1;
2464 mod_chanmode_append(struct chanmode_buffer
*buf
, char ch
, const char *arg
)
2466 size_t arg_len
= strlen(arg
);
2467 if (buf
->modes_used
> (MAXMODEPARAMS
) ||
2468 buf
->modes_used
+ buf
->args_used
+ buf
->chname_len
+ arg_len
> 450) {
2469 memcpy(buf
->modes
+ buf
->modes_used
, buf
->args
, buf
->args_used
);
2470 buf
->modes
[buf
->modes_used
+ buf
->args_used
] = '\0';
2471 irc_mode((buf
->is_chanop
? buf
->actor
: NULL
), buf
->channel
, buf
->modes
);
2472 buf
->modes
[0] = buf
->is_add
? '+' : '-';
2473 buf
->modes_used
= 1;
2476 buf
->modes
[buf
->modes_used
++] = ch
;
2477 buf
->args
[buf
->args_used
++] = ' ';
2478 memcpy(buf
->args
+ buf
->args_used
, arg
, arg_len
);
2479 buf
->args_used
+= arg_len
;
2483 mod_chanmode_announce(struct userNode
*who
, struct chanNode
*channel
, struct mod_chanmode
*change
)
2485 struct chanmode_buffer chbuf
;
2487 struct modeNode
*mn
;
2488 char int_buff
[32], mode
= '\0';
2490 assert(change
->argc
<= change
->alloc_argc
);
2491 memset(&chbuf
, 0, sizeof(chbuf
));
2492 chbuf
.channel
= channel
;
2494 chbuf
.chname_len
= strlen(channel
->name
);
2496 mn
= GetUserMode(channel
, who
);
2497 if ((mn
&& (mn
->modes
& MODE_CHANOP
)) || off_channel
)
2498 chbuf
.is_chanop
= 1;
2500 /* First remove modes */
2502 if (change
->modes_clear
) {
2504 chbuf
.modes
[chbuf
.modes_used
++] = mode
= '-';
2505 #define DO_MODE_CHAR(BIT, CHAR) if (change->modes_clear & MODE_##BIT) chbuf.modes[chbuf.modes_used++] = CHAR
2506 DO_MODE_CHAR(PRIVATE
, 'p');
2507 DO_MODE_CHAR(SECRET
, 's');
2508 DO_MODE_CHAR(MODERATED
, 'm');
2509 DO_MODE_CHAR(TOPICLIMIT
, 't');
2510 DO_MODE_CHAR(INVITEONLY
, 'i');
2511 DO_MODE_CHAR(NOPRIVMSGS
, 'n');
2512 DO_MODE_CHAR(LIMIT
, 'l');
2513 DO_MODE_CHAR(DELAYJOINS
, 'D');
2514 DO_MODE_CHAR(REGONLY
, 'r');
2515 DO_MODE_CHAR(NOCOLORS
, 'c');
2516 DO_MODE_CHAR(NOCTCPS
, 'C');
2517 DO_MODE_CHAR(STRIPCOLOR
, 'S');
2518 DO_MODE_CHAR(MODUNREG
, 'M');
2519 DO_MODE_CHAR(NONOTICE
, 'N');
2520 DO_MODE_CHAR(NOQUITMSGS
, 'Q');
2521 DO_MODE_CHAR(NOAMSG
, 'T');
2522 DO_MODE_CHAR(OPERSONLY
, 'O');
2523 DO_MODE_CHAR(REGISTERED
, 'z');
2524 DO_MODE_CHAR(SSLONLY
, 'Z');
2525 DO_MODE_CHAR(HIDEMODE
, 'L');
2527 if (change
->modes_clear
& channel
->modes
& MODE_KEY
)
2528 mod_chanmode_append(&chbuf
, 'k', channel
->key
);
2530 for (arg
= 0; arg
< change
->argc
; ++arg
) {
2531 if (!(change
->args
[arg
].mode
& MODE_REMOVE
))
2534 chbuf
.modes
[chbuf
.modes_used
++] = mode
= '-';
2535 switch (change
->args
[arg
].mode
& ~MODE_REMOVE
) {
2537 mod_chanmode_append(&chbuf
, 'b', change
->args
[arg
].u
.hostmask
);
2540 mod_chanmode_append(&chbuf
, 'e', change
->args
[arg
].u
.hostmask
);
2543 if (change
->args
[arg
].mode
& MODE_CHANOP
)
2544 mod_chanmode_append(&chbuf
, 'o', change
->args
[arg
].u
.member
->user
->numeric
);
2545 if (change
->args
[arg
].mode
& MODE_HALFOP
)
2546 mod_chanmode_append(&chbuf
, 'h', change
->args
[arg
].u
.member
->user
->numeric
);
2547 if (change
->args
[arg
].mode
& MODE_VOICE
)
2548 mod_chanmode_append(&chbuf
, 'v', change
->args
[arg
].u
.member
->user
->numeric
);
2555 if (change
->modes_set
) {
2557 chbuf
.modes
[chbuf
.modes_used
++] = mode
= '+';
2558 #define DO_MODE_CHAR(BIT, CHAR) if (change->modes_set & MODE_##BIT) chbuf.modes[chbuf.modes_used++] = CHAR
2559 DO_MODE_CHAR(PRIVATE
, 'p');
2560 DO_MODE_CHAR(SECRET
, 's');
2561 DO_MODE_CHAR(MODERATED
, 'm');
2562 DO_MODE_CHAR(TOPICLIMIT
, 't');
2563 DO_MODE_CHAR(INVITEONLY
, 'i');
2564 DO_MODE_CHAR(NOPRIVMSGS
, 'n');
2565 DO_MODE_CHAR(DELAYJOINS
, 'D');
2566 DO_MODE_CHAR(REGONLY
, 'r');
2567 DO_MODE_CHAR(NOCOLORS
, 'c');
2568 DO_MODE_CHAR(NOCTCPS
, 'C');
2569 DO_MODE_CHAR(STRIPCOLOR
, 'S');
2570 DO_MODE_CHAR(MODUNREG
, 'M');
2571 DO_MODE_CHAR(NONOTICE
, 'N');
2572 DO_MODE_CHAR(NOQUITMSGS
, 'Q');
2573 DO_MODE_CHAR(NOAMSG
, 'T');
2574 DO_MODE_CHAR(OPERSONLY
, 'O');
2575 DO_MODE_CHAR(REGISTERED
, 'z');
2576 DO_MODE_CHAR(SSLONLY
, 'Z');
2577 DO_MODE_CHAR(HIDEMODE
, 'L');
2579 if(change
->modes_set
& MODE_KEY
)
2580 mod_chanmode_append(&chbuf
, 'k', change
->new_key
);
2581 if(change
->modes_set
& MODE_LIMIT
) {
2582 sprintf(int_buff
, "%d", change
->new_limit
);
2583 mod_chanmode_append(&chbuf
, 'l', int_buff
);
2586 for (arg
= 0; arg
< change
->argc
; ++arg
) {
2587 if (change
->args
[arg
].mode
& MODE_REMOVE
)
2590 chbuf
.modes
[chbuf
.modes_used
++] = mode
= '+';
2591 switch (change
->args
[arg
].mode
) {
2593 mod_chanmode_append(&chbuf
, 'b', change
->args
[arg
].u
.hostmask
);
2596 mod_chanmode_append(&chbuf
, 'e', change
->args
[arg
].u
.hostmask
);
2599 if (change
->args
[arg
].mode
& MODE_CHANOP
)
2600 mod_chanmode_append(&chbuf
, 'o', change
->args
[arg
].u
.member
->user
->numeric
);
2601 if (change
->args
[arg
].mode
& MODE_HALFOP
)
2602 mod_chanmode_append(&chbuf
, 'h', change
->args
[arg
].u
.member
->user
->numeric
);
2603 if (change
->args
[arg
].mode
& MODE_VOICE
)
2604 mod_chanmode_append(&chbuf
, 'v', change
->args
[arg
].u
.member
->user
->numeric
);
2609 /* Flush the buffer and apply changes locally */
2610 if (chbuf
.modes_used
> 0) {
2611 memcpy(chbuf
.modes
+ chbuf
.modes_used
, chbuf
.args
, chbuf
.args_used
);
2612 chbuf
.modes
[chbuf
.modes_used
+ chbuf
.args_used
] = '\0';
2613 irc_mode((chbuf
.is_chanop
? chbuf
.actor
: NULL
), chbuf
.channel
, chbuf
.modes
);
2615 mod_chanmode_apply(who
, channel
, change
);
2619 mod_chanmode_format(struct mod_chanmode
*change
, char *outbuff
)
2621 unsigned int used
= 0;
2622 assert(change
->argc
<= change
->alloc_argc
);
2623 if (change
->modes_clear
) {
2624 outbuff
[used
++] = '-';
2625 #define DO_MODE_CHAR(BIT, CHAR) if (change->modes_clear & MODE_##BIT) outbuff[used++] = CHAR
2626 DO_MODE_CHAR(PRIVATE
, 'p');
2627 DO_MODE_CHAR(SECRET
, 's');
2628 DO_MODE_CHAR(MODERATED
, 'm');
2629 DO_MODE_CHAR(TOPICLIMIT
, 't');
2630 DO_MODE_CHAR(INVITEONLY
, 'i');
2631 DO_MODE_CHAR(NOPRIVMSGS
, 'n');
2632 DO_MODE_CHAR(LIMIT
, 'l');
2633 DO_MODE_CHAR(KEY
, 'k');
2634 DO_MODE_CHAR(DELAYJOINS
, 'D');
2635 DO_MODE_CHAR(REGONLY
, 'r');
2636 DO_MODE_CHAR(NOCOLORS
, 'c');
2637 DO_MODE_CHAR(NOCTCPS
, 'C');
2638 DO_MODE_CHAR(STRIPCOLOR
, 'S');
2639 DO_MODE_CHAR(MODUNREG
, 'M');
2640 DO_MODE_CHAR(NONOTICE
, 'N');
2641 DO_MODE_CHAR(NOQUITMSGS
, 'Q');
2642 DO_MODE_CHAR(NOAMSG
, 'T');
2643 DO_MODE_CHAR(OPERSONLY
, 'O');
2644 DO_MODE_CHAR(REGISTERED
, 'z');
2645 DO_MODE_CHAR(SSLONLY
, 'Z');
2646 DO_MODE_CHAR(HIDEMODE
, 'L');
2649 if (change
->modes_set
) {
2650 outbuff
[used
++] = '+';
2651 #define DO_MODE_CHAR(BIT, CHAR) if (change->modes_set & MODE_##BIT) outbuff[used++] = CHAR
2652 DO_MODE_CHAR(PRIVATE
, 'p');
2653 DO_MODE_CHAR(SECRET
, 's');
2654 DO_MODE_CHAR(MODERATED
, 'm');
2655 DO_MODE_CHAR(TOPICLIMIT
, 't');
2656 DO_MODE_CHAR(INVITEONLY
, 'i');
2657 DO_MODE_CHAR(NOPRIVMSGS
, 'n');
2658 DO_MODE_CHAR(DELAYJOINS
, 'D');
2659 DO_MODE_CHAR(REGONLY
, 'r');
2660 DO_MODE_CHAR(NOCOLORS
, 'c');
2661 DO_MODE_CHAR(NOCTCPS
, 'C');
2662 DO_MODE_CHAR(STRIPCOLOR
, 'S');
2663 DO_MODE_CHAR(MODUNREG
, 'M');
2664 DO_MODE_CHAR(NONOTICE
, 'N');
2665 DO_MODE_CHAR(NOQUITMSGS
, 'Q');
2666 DO_MODE_CHAR(NOAMSG
, 'T');
2667 DO_MODE_CHAR(OPERSONLY
, 'O');
2668 DO_MODE_CHAR(REGISTERED
, 'z');
2669 DO_MODE_CHAR(SSLONLY
, 'Z');
2670 DO_MODE_CHAR(HIDEMODE
, 'L');
2672 switch (change
->modes_set
& (MODE_KEY
|MODE_LIMIT
)) {
2673 case MODE_KEY
|MODE_LIMIT
:
2674 used
+= sprintf(outbuff
+used
, "lk %d %s", change
->new_limit
, change
->new_key
);
2677 used
+= sprintf(outbuff
+used
, "k %s", change
->new_key
);
2680 used
+= sprintf(outbuff
+used
, "l %d", change
->new_limit
);
2689 clear_chanmode(struct chanNode
*channel
, const char *modes
)
2691 unsigned int remove
;
2693 for (remove
= 0; *modes
; modes
++) {
2695 case 'o': remove
|= MODE_CHANOP
; break;
2696 case 'h': remove
|= MODE_HALFOP
; break;
2697 case 'v': remove
|= MODE_VOICE
; break;
2698 case 'p': remove
|= MODE_PRIVATE
; break;
2699 case 's': remove
|= MODE_SECRET
; break;
2700 case 'm': remove
|= MODE_MODERATED
; break;
2701 case 't': remove
|= MODE_TOPICLIMIT
; break;
2702 case 'i': remove
|= MODE_INVITEONLY
; break;
2703 case 'n': remove
|= MODE_NOPRIVMSGS
; break;
2706 channel
->key
[0] = '\0';
2709 remove
|= MODE_LIMIT
;
2712 case 'b': remove
|= MODE_BAN
; break;
2713 case 'e': remove
|= MODE_EXEMPT
; break;
2714 case 'D': remove
|= MODE_DELAYJOINS
; break;
2715 case 'r': remove
|= MODE_REGONLY
; break;
2716 case 'c': remove
|= MODE_NOCOLORS
; break;
2717 case 'C': remove
|= MODE_NOCTCPS
; break;
2718 case 'S': remove
|= MODE_STRIPCOLOR
; break;
2719 case 'M': remove
|= MODE_MODUNREG
; break;
2720 case 'N': remove
|= MODE_NONOTICE
; break;
2721 case 'Q': remove
|= MODE_NOQUITMSGS
; break;
2722 case 'T': remove
|= MODE_NOAMSG
; break;
2723 case 'O': remove
|= MODE_OPERSONLY
; break;
2724 case 'z': remove
|= MODE_REGISTERED
; break;
2725 case 'Z': remove
|= MODE_SSLONLY
; break;
2726 case 'L': remove
|= MODE_HIDEMODE
; break;
2733 /* Remove simple modes. */
2734 channel
->modes
&= ~remove
;
2736 /* If removing bans, kill 'em all. */
2737 if ((remove
& MODE_BAN
) && channel
->banlist
.used
) {
2739 for (i
=0; i
<channel
->banlist
.used
; i
++)
2740 free(channel
->banlist
.list
[i
]);
2741 channel
->banlist
.used
= 0;
2744 /* If removing exempts, kill 'em all. */
2745 if ((remove
& MODE_EXEMPT
) && channel
->exemptlist
.used
) {
2747 for (i
=0; i
<channel
->exemptlist
.used
; i
++)
2748 free(channel
->exemptlist
.list
[i
]);
2749 channel
->exemptlist
.used
= 0;
2752 /* Remove member modes. */
2753 if ((remove
& (MODE_CHANOP
| MODE_HALFOP
| MODE_VOICE
)) && channel
->members
.used
) {
2754 int mask
= ~(remove
& (MODE_CHANOP
| MODE_HALFOP
| MODE_VOICE
));
2757 for (i
= 0; i
< channel
->members
.used
; i
++)
2758 channel
->members
.list
[i
]->modes
&= mask
;
2765 reg_privmsg_func(struct userNode
*user
, privmsg_func_t handler
)
2767 unsigned int numeric
= user
->num_local
;
2768 if (numeric
>= num_privmsg_funcs
) {
2769 int newnum
= numeric
+ 8;
2770 privmsg_funcs
= realloc(privmsg_funcs
, newnum
*sizeof(privmsg_func_t
));
2771 memset(privmsg_funcs
+num_privmsg_funcs
, 0, (newnum
-num_privmsg_funcs
)*sizeof(privmsg_func_t
));
2772 num_privmsg_funcs
= newnum
;
2774 if (privmsg_funcs
[numeric
])
2775 log_module(MAIN_LOG
, LOG_WARNING
, "re-registering new privmsg handler for numeric %d", numeric
);
2776 privmsg_funcs
[numeric
] = handler
;
2780 unreg_privmsg_func(struct userNode
*user
, privmsg_func_t handler
)
2784 if (!user
|| handler
)
2785 return; /* this really only works with users */
2787 memset(privmsg_funcs
+user
->num_local
, 0, sizeof(privmsg_func_t
));
2789 for (x
= user
->num_local
+1; x
< num_privmsg_funcs
; x
++)
2790 memmove(privmsg_funcs
+x
-1, privmsg_funcs
+x
, sizeof(privmsg_func_t
));
2792 privmsg_funcs
= realloc(privmsg_funcs
, num_privmsg_funcs
*sizeof(privmsg_func_t
));
2793 num_privmsg_funcs
--;
2798 reg_notice_func(struct userNode
*user
, privmsg_func_t handler
)
2800 unsigned int numeric
= user
->num_local
;
2801 if (numeric
>= num_notice_funcs
) {
2802 int newnum
= numeric
+ 8;
2803 notice_funcs
= realloc(notice_funcs
, newnum
*sizeof(privmsg_func_t
));
2804 memset(notice_funcs
+num_notice_funcs
, 0, (newnum
-num_notice_funcs
)*sizeof(privmsg_func_t
));
2805 num_notice_funcs
= newnum
;
2807 if (notice_funcs
[numeric
])
2808 log_module(MAIN_LOG
, LOG_WARNING
, "re-registering new notice handler for numeric %d", numeric
);
2809 notice_funcs
[numeric
] = handler
;
2813 unreg_notice_func(struct userNode
*user
, privmsg_func_t handler
)
2817 if (!user
|| handler
)
2818 return; /* this really only works with users */
2820 memset(notice_funcs
+user
->num_local
, 0, sizeof(privmsg_func_t
));
2822 for (x
= user
->num_local
+1; x
< num_notice_funcs
; x
++)
2823 memmove(notice_funcs
+x
-1, notice_funcs
+x
, sizeof(privmsg_func_t
));
2825 memset(notice_funcs
+user
->num_local
, 0, sizeof(privmsg_func_t
));
2826 notice_funcs
= realloc(notice_funcs
, num_notice_funcs
*sizeof(privmsg_func_t
));
2831 reg_oper_func(oper_func_t handler
)
2833 if (of_used
== of_size
) {
2836 of_list
= realloc(of_list
, of_size
*sizeof(oper_func_t
));
2839 of_list
= malloc(of_size
*sizeof(oper_func_t
));
2842 of_list
[of_used
++] = handler
;
2846 call_oper_funcs(struct userNode
*user
)
2851 for (n
=0; n
<of_used
; n
++)
2858 unsigned int i
, hop
, max_hop
=1;
2861 /* burst (juped) servers, closest first (except self, which is sent already) */
2862 for (i
=0; i
<ArrayLength(servers_num
); i
++)
2863 if (servers_num
[i
] && servers_num
[i
]->hops
> max_hop
)
2864 max_hop
= servers_num
[i
]->hops
;
2865 for (hop
=1; hop
<=max_hop
; hop
++) {
2866 for (i
=0;i
<ArrayLength(servers_num
);i
++) {
2868 && (servers_num
[i
]->hops
== hop
)
2869 && (servers_num
[i
] != self
->uplink
))
2870 irc_server(servers_num
[i
]);
2874 /* burst local nicks */
2875 for (i
=0; i
<=self
->num_mask
; i
++)
2877 irc_user(self
->users
[i
]);
2879 /* build dict of unbursted channel names (just copy existing channels) */
2880 unbursted_channels
= dict_new();
2881 for (it
= dict_first(channels
); it
; it
= iter_next(it
))
2882 dict_insert(unbursted_channels
, iter_key(it
), iter_data(it
));