]>
jfr.im git - irc/evilnet/x3.git/blob - src/proto-p10.c
1 /* proto-p10.c - IRC protocol output
2 * Copyright 2000-2004 srvx Development Team
4 * This file is part of x3.
6 * x3 is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with srvx; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
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
;
309 static int extended_accounts
;
311 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
);
313 extern int off_channel
;
315 static int parse_oplevel(char *str
);
317 /* Numerics can be XYY, XYYY, or XXYYY; with X's identifying the
318 * server and Y's indentifying the client on that server. */
320 GetServerN(const char *numeric
)
322 switch (strlen(numeric
)) {
324 return servers_num
[base64toint(numeric
, 2)];
328 return servers_num
[base64toint(numeric
, 1)];
335 GetUserN(const char *numeric
) /* using numeric */
341 switch (strlen(numeric
)) {
343 log_module(MAIN_LOG
, LOG_WARNING
, "GetUserN(%s): numeric too long!", numeric
);
345 case 5: slen
= 2; ulen
= 3; break;
346 case 4: slen
= 1; ulen
= 3; break;
347 case 3: slen
= 1; ulen
= 2; break;
348 case 2: case 1: case 0:
349 log_module(MAIN_LOG
, LOG_WARNING
, "GetUserN(%s): numeric too short!", numeric
);
352 if (!(s
= servers_num
[base64toint(numeric
, slen
)])) {
353 log_module(MAIN_LOG
, LOG_WARNING
, "GetUserN(%s): couldn't find server (len=%d)!", numeric
, slen
);
356 n
= base64toint(numeric
+slen
, ulen
) & s
->num_mask
;
357 if (!(un
= s
->users
[n
])) {
358 log_module(MAIN_LOG
, LOG_WARNING
, "GetUserN(%s) couldn't find user!", numeric
);
364 privmsg_user_helper(struct userNode
*un
, void *data
)
366 struct privmsg_desc
*pd
= data
;
367 unsigned int num
= un
->num_local
;
368 if (!pd
->is_notice
) {
369 if ((num
< num_privmsg_funcs
) && privmsg_funcs
[num
]) {
370 privmsg_funcs
[num
](pd
->user
, un
, pd
->text
, pd
->is_qualified
);
373 if ((num
< num_notice_funcs
) && notice_funcs
[num
]) {
374 notice_funcs
[num
](pd
->user
, un
, pd
->text
, pd
->is_qualified
);
380 irc_server(struct server
*srv
)
382 char extranum
[COMBO_NUMERIC_LEN
+1];
384 inttobase64(extranum
, srv
->num_mask
, (srv
->numeric
[1] || (srv
->num_mask
>= 64*64)) ? 3 : 2);
386 putsock(P10_SERVER
" %s %d %li %li J10 %s%s +s6 :%s",
387 srv
->name
, srv
->hops
+1, srv
->boot
, srv
->link
, srv
->numeric
, extranum
, srv
->description
);
389 putsock("%s " P10_SERVER
" %s %d %li %li %c10 %s%s +s6 :%s",
390 self
->numeric
, srv
->name
, srv
->hops
+1, srv
->boot
, srv
->link
, (srv
->self_burst
? 'J' : 'P'), srv
->numeric
, extranum
, srv
->description
);
395 irc_p10_pton(irc_in_addr_t
*ip
, const char *input
)
397 if (strlen(input
) == 6) {
399 memset(ip
, 0, 6 * sizeof(ip
->in6
[0]));
400 value
= base64toint(input
, 6);
402 ip
->in6
[5] = htons(65535);
403 ip
->in6
[6] = htons(value
>> 16);
404 ip
->in6
[7] = htons(value
& 65535);
406 unsigned int pos
= 0;
410 for (left
= (25 - strlen(input
)) / 3; left
; left
--)
414 ip
->in6
[pos
++] = ntohs(base64toint(input
, 3));
422 irc_p10_ntop(char *output
, const irc_in_addr_t
*ip
)
424 if (!irc_in_addr_is_valid(*ip
)) {
425 strcpy(output
, "AAAAAA");
426 } else if (irc_in_addr_is_ipv4(*ip
)) {
428 in4
= (ntohs(ip
->in6
[6]) << 16) | ntohs(ip
->in6
[7]);
429 inttobase64(output
, in4
, 6);
431 } else if (irc_in_addr_is_ipv6(*ip
)) {
432 unsigned int max_start
, max_zeros
, curr_zeros
, zero
, ii
;
433 /* Can start by printing out the leading non-zero parts. */
434 for (ii
= 0; (ip
->in6
[ii
]) && (ii
< 8); ++ii
) {
435 inttobase64(output
, ntohs(ip
->in6
[ii
]), 3);
438 /* Find the longest run of zeros. */
439 for (max_start
= zero
= ii
, max_zeros
= curr_zeros
= 0; ii
< 8; ++ii
) {
442 else if (curr_zeros
> max_zeros
) {
443 max_start
= ii
- curr_zeros
;
444 max_zeros
= curr_zeros
;
448 if (curr_zeros
> max_zeros
) {
449 max_start
= ii
- curr_zeros
;
450 max_zeros
= curr_zeros
;
453 /* Print the rest of the address */
454 for (ii
= zero
; ii
< 8; ) {
455 if ((ii
== max_start
) && max_zeros
) {
459 inttobase64(output
, ntohs(ip
->in6
[ii
]), 3);
465 strcpy(output
, "???");
470 irc_user(struct userNode
*user
)
475 irc_p10_ntop(b64ip
, &user
->ip
);
482 modes
[modelen
++] = 'o';
483 if (IsInvisible(user
))
484 modes
[modelen
++] = 'i';
486 modes
[modelen
++] = 'w';
488 modes
[modelen
++] = 'k';
489 if (IsServNotice(user
))
490 modes
[modelen
++] = 's';
492 modes
[modelen
++] = 'd';
494 modes
[modelen
++] = 'g';
495 // sethost - reed/apples
496 // if (IsHelperIrcu(user))
498 modes
[modelen
++] = 'h';
499 if (IsFakeHost(user
))
500 modes
[modelen
++] = 'f';
501 if (IsHiddenHost(user
))
502 modes
[modelen
++] = 'x';
505 /* we don't need to put the + in modes because it's in the format string. */
506 putsock("%s " P10_NICK
" %s %d %li %s %s +%s %s %s :%s",
507 user
->uplink
->numeric
, user
->nick
, user
->uplink
->hops
+1, user
->timestamp
, user
->ident
, user
->hostname
, modes
, b64ip
, user
->numeric
, user
->info
);
509 putsock("%s " P10_NICK
" %s %d %li %s %s %s %s :%s",
510 user
->uplink
->numeric
, user
->nick
, user
->uplink
->hops
+1, user
->timestamp
, user
->ident
, user
->hostname
, b64ip
, user
->numeric
, user
->info
);
515 irc_rename(struct userNode
*user
, const char *new_handle
)
517 if(extended_accounts
)
518 putsock("%s " P10_ACCOUNT
" %s M %s", self
->numeric
, user
->numeric
, new_handle
);
522 irc_delete(struct userNode
*user
)
524 if(extended_accounts
)
525 putsock("%s " P10_ACCOUNT
" %s U", self
->numeric
, user
->numeric
);
529 irc_account(struct userNode
*user
, const char *stamp
, time_t timestamp
)
531 if(extended_accounts
)
532 putsock("%s " P10_ACCOUNT
" %s R %s %lu", self
->numeric
, user
->numeric
, stamp
, timestamp
);
534 putsock("%s " P10_ACCOUNT
" %s %s %lu", self
->numeric
, user
->numeric
, stamp
, timestamp
);
538 irc_fakehost(struct userNode
*user
, const char *host
)
540 putsock("%s " P10_FAKEHOST
" %s %s", self
->numeric
, user
->numeric
, host
);
544 irc_regnick(UNUSED_ARG(struct userNode
*user
))
546 /* no operation here */
550 irc_nick(struct userNode
*user
, UNUSED_ARG(const char *old_nick
))
552 putsock("%s " P10_NICK
" %s "FMT_TIME_T
, user
->numeric
, user
->nick
, now
);
556 irc_fetchtopic(struct userNode
*from
, const char *to
)
560 putsock("%s " P10_TOPIC
" %s", from
->numeric
, to
);
564 irc_squit(struct server
*srv
, const char *message
, const char *service_message
)
566 if (!service_message
)
567 service_message
= message
;
569 /* Are we leaving the network? */
570 if (srv
== self
&& cManager
.uplink
->state
== CONNECTED
) {
573 /* Quit all clients linked to me. */
574 for (i
= 0; i
<= self
->num_mask
; i
++) {
577 irc_quit(self
->users
[i
], service_message
);
581 putsock("%s " P10_SQUIT
" %s %d :%s", self
->numeric
, srv
->name
, 0, message
);
584 /* Force a reconnect to the currently selected server. */
585 cManager
.uplink
->tries
= 0;
586 log_module(MAIN_LOG
, LOG_INFO
, "Squitting from uplink: %s", message
);
592 irc_wallchops(struct userNode
*from
, const char *to
, const char *message
)
594 putsock("%s " P10_WALLCHOPS
" %s :%s", from
->numeric
, to
, message
);
598 irc_notice(struct userNode
*from
, const char *to
, const char *message
)
600 putsock("%s " P10_NOTICE
" %s :%s", from
->numeric
, to
, message
);
604 irc_notice_user(struct userNode
*from
, struct userNode
*to
, const char *message
)
606 putsock("%s " P10_NOTICE
" %s :%s", from
->numeric
, to
->numeric
, message
);
610 irc_privmsg(struct userNode
*from
, const char *to
, const char *message
)
612 putsock("%s " P10_PRIVMSG
" %s :%s", from
->numeric
, to
, message
);
618 putsock("%s " P10_EOB
, self
->numeric
);
624 putsock("%s " P10_EOB_ACK
, self
->numeric
);
628 irc_ping(const char *payload
)
630 putsock("%s " P10_PING
" :%s", self
->numeric
, payload
);
634 irc_pong(const char *who
, const char *data
)
636 putsock("%s " P10_PONG
" %s :%s", self
->numeric
, who
, data
);
640 irc_pong_asll(const char *who
, const char *orig_ts
)
647 orig
.tv_sec
= strtoul(orig_ts
, &delim
, 10);
648 orig
.tv_usec
= (*delim
== '.') ? strtoul(delim
+ 1, NULL
, 10) : 0;
649 gettimeofday(&now
, NULL
);
650 diff
= (now
.tv_sec
- orig
.tv_sec
) * 1000 + (now
.tv_usec
- orig
.tv_usec
) / 1000;
651 putsock("%s " P10_PONG
" %s %s %d " FMT_TIME_T
".%06u", self
->numeric
, who
, orig_ts
, diff
, now
.tv_sec
, (unsigned)now
.tv_usec
);
655 irc_pass(const char *passwd
)
657 putsock(P10_PASS
" :%s", passwd
);
661 irc_introduce(const char *passwd
)
663 void timed_send_ping(void *data
);
665 self
->self_burst
= self
->burst
= 1;
669 timeq_add(now
+ ping_freq
, timed_send_ping
, 0);
673 irc_gline(struct server
*srv
, struct gline
*gline
, int silent
)
675 putsock("%s " P10_GLINE
" %s +%s %ld :%s<%s> %s",
676 self
->numeric
, (srv
? srv
->numeric
: "*"), gline
->target
, gline
->expires
-now
, silent
? "AUTO " : "", gline
->issuer
, gline
->reason
);
680 irc_shun(struct server
*srv
, struct shun
*shun
)
682 putsock("%s " P10_SHUN
" %s +%s %ld :<%s> %s",
683 self
->numeric
, (srv
? srv
->numeric
: "*"), shun
->target
, shun
->expires
-now
, shun
->issuer
, shun
->reason
);
687 irc_settime(const char *srv_name_mask
, time_t new_time
)
689 ioset_set_time(new_time
);
690 if (!strcmp(srv_name_mask
, "*"))
692 putsock("%s " P10_SETTIME
" " FMT_TIME_T
" %s", self
->numeric
, new_time
, srv_name_mask
);
696 irc_ungline(const char *mask
)
698 putsock("%s " P10_GLINE
" * -%s", self
->numeric
, mask
);
702 irc_unshun(const char *mask
)
704 putsock("%s " P10_SHUN
" * -%s", self
->numeric
, mask
);
708 irc_burst(struct chanNode
*chan
)
710 char burst_line
[512];
711 int pos
, base_len
, len
;
714 struct exemptNode
*en
;
718 base_len
= sprintf(burst_line
, "%s " P10_BURST
" %s " FMT_TIME_T
" ",
719 self
->numeric
, chan
->name
, chan
->timestamp
);
720 len
= irc_make_chanmode(chan
, burst_line
+base_len
);
721 pos
= base_len
+ len
;
723 burst_line
[pos
++] = ' ';
726 for (n
=0; n
<chan
->members
.used
; n
++) {
727 mn
= chan
->members
.list
[n
];
729 burst_line
[pos
-1] = 0; /* -1 to back up over the space or comma */
730 putsock("%s", burst_line
);
734 memcpy(burst_line
+pos
, mn
->user
->numeric
, strlen(mn
->user
->numeric
));
735 pos
+= strlen(mn
->user
->numeric
);
736 if (mn
->modes
&& (mn
->modes
!= last_mode
)) {
737 last_mode
= mn
->modes
;
738 burst_line
[pos
++] = ':';
739 if (last_mode
& MODE_CHANOP
)
740 burst_line
[pos
++] = 'o';
741 if (last_mode
& MODE_HALFOP
)
742 burst_line
[pos
++] = 'h';
743 if (last_mode
& MODE_VOICE
)
744 burst_line
[pos
++] = 'v';
746 if ((n
+1)<chan
->members
.used
)
747 burst_line
[pos
++] = ',';
749 if (chan
->banlist
.used
) {
751 if (pos
+2+strlen(chan
->banlist
.list
[0]->ban
) > 505) {
752 burst_line
[pos
-1] = 0;
753 putsock("%s", burst_line
);
756 burst_line
[pos
++] = ' ';
759 burst_line
[pos
++] = ':';
760 burst_line
[pos
++] = '%';
762 for (n
=0; n
<chan
->banlist
.used
; n
++) {
763 bn
= chan
->banlist
.list
[n
];
764 len
= strlen(bn
->ban
);
765 if (pos
+len
+1 > 510) {
766 burst_line
[pos
-1] = 0; /* -1 to back up over the space or comma */
767 putsock("%s", burst_line
);
770 memcpy(burst_line
+pos
, bn
->ban
, len
);
772 burst_line
[pos
++] = ' ';
775 if (chan
->exemptlist
.used
) {
776 /* dump the exempt */
777 if (pos
+2+strlen(chan
->exemptlist
.list
[0]->exempt
) > 505) {
778 burst_line
[pos
-1] = 0;
779 putsock("%s", burst_line
);
782 burst_line
[pos
++] = ' ';
785 burst_line
[pos
++] = ' ';
786 burst_line
[pos
++] = '~';
787 burst_line
[pos
++] = ' ';
789 for (n
=0; n
<chan
->exemptlist
.used
; n
++) {
790 en
= chan
->exemptlist
.list
[n
];
791 len
= strlen(en
->exempt
);
792 if (pos
+len
+1 > 510) {
793 burst_line
[pos
-1] = 0; /* -1 to back up over the space or comma */
794 putsock("%s", burst_line
);
797 memcpy(burst_line
+pos
, en
->exempt
, len
);
799 burst_line
[pos
++] = ' ';
802 /* print the last line */
804 putsock("%s", burst_line
);
808 irc_quit(struct userNode
*user
, const char *message
)
810 putsock("%s " P10_QUIT
" :%s", user
->numeric
, message
);
814 irc_error(const char *to
, const char *message
)
817 putsock("%s " P10_ERROR
" :%s", to
, message
);
819 putsock(":%s " P10_ERROR
" :%s", self
->name
, message
);
824 irc_kill(struct userNode
*from
, struct userNode
*target
, const char *message
)
827 putsock("%s " P10_KILL
" %s :%s!%s (%s)",
828 from
->numeric
, target
->numeric
, self
->name
, from
->nick
, message
);
830 putsock("%s " P10_KILL
" %s :%s (%s)",
831 self
->numeric
, target
->numeric
, self
->name
, message
);
836 irc_mode(struct userNode
*from
, struct chanNode
*target
, const char *modes
)
838 call_channel_mode_funcs(from
, target
, (char **)&modes
, 0);
839 putsock("%s " P10_MODE
" %s %s "FMT_TIME_T
,
840 (from
? from
->numeric
: self
->numeric
),
841 target
->name
, modes
, target
->timestamp
);
844 /* Added to allow services to mode users
845 2005 - 8 - 10 by Life4Christ
848 irc_umode(struct userNode
*target
, const char *modes
)
850 putsock("%s " P10_MODE
" %s %s ",self
->numeric
,target
->nick
, modes
);
855 irc_invite(struct userNode
*from
, struct userNode
*who
, struct chanNode
*to
)
857 putsock("%s " P10_INVITE
" %s %s", from
->numeric
, who
->nick
, to
->name
);
861 irc_join(struct userNode
*who
, struct chanNode
*what
)
863 if (what
->members
.used
== 1) {
864 putsock("%s " P10_CREATE
" %s %lu",
865 who
->numeric
, what
->name
, what
->timestamp
);
867 putsock("%s " P10_JOIN
" %s %lu", who
->numeric
, what
->name
, what
->timestamp
);
872 irc_kick(struct userNode
*who
, struct userNode
*target
, struct chanNode
*channel
, const char *msg
)
875 struct modeNode
*mn
= GetUserMode(channel
, who
);
876 numeric
= ((mn
&& (mn
->modes
& MODE_CHANOP
)) || off_channel
) ? who
->numeric
: self
->numeric
;
877 putsock("%s " P10_KICK
" %s %s :%s",
878 numeric
, channel
->name
, target
->numeric
, msg
);
882 irc_stats(struct userNode
*from
, struct server
*target
, char type
)
884 putsock("%s " P10_STATS
" %c :%s", from
->numeric
, type
, target
->numeric
);
888 irc_svsnick(struct userNode
*from
, struct userNode
*target
, const char *newnick
)
890 putsock("%s " P10_SVSNICK
" %s %s "FMT_TIME_T
, from
->uplink
->numeric
, target
->numeric
, newnick
, now
);
894 irc_part(struct userNode
*who
, struct chanNode
*what
, const char *reason
)
897 putsock("%s " P10_PART
" %s :%s", who
->numeric
, what
->name
, reason
);
899 putsock("%s " P10_PART
" %s", who
->numeric
, what
->name
);
904 irc_topic(struct userNode
*service
, struct userNode
*who
, struct chanNode
*what
, const char *topic
)
906 /* UNCOMMENT FOR NEFARIOUS 0.5.0 TOPIC SUPPORT
907 * putsock("%s " P10_TOPIC " %s %s " FMT_TIME_T " " FMT_TIME_T " :%s", service->numeric, what->name, who->nick, what->timestamp, now, topic);
908 * UNCOMMENT FOR NEFARIOUS 0.5.0 TOPIC SUPPORT */
910 who
= service
; /* REMOVE LINE FOR NEFARIOUS 0.5.0 */
912 putsock("%s " P10_TOPIC
" %s :%s", who
->numeric
, what
->name
, topic
);
916 irc_raw(const char *what
)
922 irc_numeric(struct userNode
*user
, unsigned int num
, const char *format
, ...)
926 va_start(arg_list
, format
);
927 vsnprintf(buffer
, MAXLEN
-2, format
, arg_list
);
928 buffer
[MAXLEN
-1] = 0;
929 putsock(":%s %03d %s %s", self
->name
, num
, user
->nick
, buffer
);
932 static void send_burst(void);
935 change_nicklen(int new_nicklen
)
938 char new_nick
[NICKLEN
+1];
939 struct userNode
*user
;
941 nicklen
= new_nicklen
;
942 /* fix up any users we have here */
943 for (nn
=0; nn
<=self
->num_mask
; nn
++) {
944 if (!(user
= self
->users
[nn
]))
946 safestrncpy(new_nick
, user
->nick
, sizeof(new_nick
));
947 new_nick
[nicklen
] = 0;
948 NickChange(user
, new_nick
, 1);
952 static CMD_FUNC(cmd_whois
)
954 struct userNode
*from
;
955 struct userNode
*who
;
959 if (!(from
= GetUserH(origin
))) {
960 log_module(MAIN_LOG
, LOG_ERROR
, "Could not find WHOIS origin user %s", origin
);
963 if(!(who
= GetUserH(argv
[2]))) {
964 irc_numeric(from
, ERR_NOSUCHNICK
, "%s@%s :No such nick", argv
[2], self
->name
);
967 if (IsHiddenHost(who
) && !IsOper(from
)) {
968 /* Just stay quiet. */
971 irc_numeric(from
, RPL_WHOISUSER
, "%s %s %s * :%s", who
->nick
, who
->ident
, who
->hostname
, who
->info
);
972 if (his_servername
&& his_servercomment
)
973 irc_numeric(from
, RPL_WHOISSERVER
, "%s %s :%s", who
->nick
, his_servername
, his_servercomment
);
975 irc_numeric(from
, RPL_WHOISSERVER
, "%s %s :%s", who
->nick
, who
->uplink
->name
, who
->uplink
->description
);
977 irc_numeric(from
, RPL_WHOISOPERATOR
, "%s :is a megalomaniacal power hungry tyrant", who
->nick
);
978 irc_numeric(from
, RPL_ENDOFWHOIS
, "%s :End of /WHOIS list", who
->nick
);
982 static CMD_FUNC(cmd_server
)
990 /* another server introduced us */
991 srv
= AddServer(GetServerH(origin
), argv
[1], atoi(argv
[2]), atoi(argv
[3]), atoi(argv
[4]), argv
[6], argv
[argc
-1]);
994 srv
->self_burst
= argv
[5][0] == 'J';
997 /* this must be our uplink */
998 srv
= self
->uplink
= AddServer(self
, argv
[1], atoi(argv
[2]), atoi(argv
[3]), atoi(argv
[4]), argv
[6], argv
[argc
-1]);
1001 srv
->self_burst
= argv
[5][0] == 'J';
1003 if ((argv
[7][0] == '+') && !force_n2k
) {
1004 log_module(MAIN_LOG
, LOG_WARNING
, "Got Undernet-style SERVER message but \"force_n2k\" not on.");
1009 /* Fix up our timestamps if necessary. */
1010 if (srv
->boot
<= PREHISTORY
) {
1011 /* Server from the mists of time.. */
1012 if (srv
->hops
== 1) {
1013 log_module(MAIN_LOG
, LOG_ERROR
, "Server %s claims to have booted at time "FMT_TIME_T
". This is absurd.", srv
->name
, srv
->boot
);
1015 } else if ((str
= conf_get_data("server/reliable_clock", RECDB_QSTRING
))
1016 && enabled_string(str
)) {
1017 /* If we have a reliable clock, we just keep our current time. */
1019 if (srv
->boot
<= self
->boot
) {
1020 /* The other server is older than us. Accept their timestamp.
1021 * Alternately, we are same age, but we accept their time
1022 * since we are linking to them. */
1023 self
->boot
= srv
->boot
;
1024 ioset_set_time(srv
->link
);
1027 if (srv
== self
->uplink
) {
1028 extern time_t burst_begin
;
1034 static CMD_FUNC(cmd_eob
)
1036 struct server
*sender
;
1040 if (!(sender
= GetServerH(origin
)))
1042 if (sender
== self
->uplink
) {
1043 cManager
.uplink
->state
= CONNECTED
;
1044 for (it
= dict_first(unbursted_channels
); it
; it
= iter_next(it
))
1045 irc_burst(iter_data(it
));
1046 dict_delete(unbursted_channels
);
1047 unbursted_channels
= NULL
;
1051 sender
->self_burst
= 0;
1052 recalc_bursts(sender
);
1053 for (ii
=0; ii
<slf_used
; ii
++)
1054 slf_list
[ii
](sender
);
1058 static CMD_FUNC(cmd_eob_ack
)
1060 extern time_t burst_begin
;
1062 if (GetServerH(origin
) == self
->uplink
) {
1063 burst_length
= now
- burst_begin
;
1064 self
->self_burst
= self
->burst
= 0;
1066 cManager
.uplink
->state
= CONNECTED
;
1070 static CMD_FUNC(cmd_ping
)
1073 struct userNode
*un
;
1076 irc_pong_asll(argv
[2], argv
[3]);
1077 else if ((srv
= GetServerH(origin
)))
1078 irc_pong(self
->name
, srv
->numeric
);
1079 else if ((un
= GetUserH(origin
)))
1080 irc_pong(self
->name
, un
->numeric
);
1082 irc_pong(self
->name
, origin
);
1084 timeq_del(0, timed_send_ping
, 0, TIMEQ_IGNORE_WHEN
|TIMEQ_IGNORE_DATA
);
1085 timeq_del(0, timed_ping_timeout
, 0, TIMEQ_IGNORE_WHEN
|TIMEQ_IGNORE_DATA
);
1086 timeq_add(now
+ ping_freq
, timed_send_ping
, 0);
1091 static CMD_FUNC(cmd_error_nick
)
1093 /* Go back to original IRC length .. and try to reconnect :/ */
1095 irc_squit(self
, "Got erroneous nickname, truncating nicks.", NULL
);
1099 struct create_desc
{
1100 struct userNode
*user
;
1105 join_helper(struct chanNode
*chan
, void *data
)
1107 struct create_desc
*cd
= data
;
1108 AddChannelUser(cd
->user
, chan
);
1112 create_helper(char *name
, void *data
)
1114 struct create_desc
*cd
= data
;
1116 if (!strcmp(name
, "0")) {
1117 while (cd
->user
->channels
.used
> 0)
1118 DelChannelUser(cd
->user
, cd
->user
->channels
.list
[0]->channel
, 0, 0);
1122 AddChannelUser(cd
->user
, AddChannel(name
, cd
->when
, NULL
, NULL
, NULL
));
1125 static CMD_FUNC(cmd_create
)
1127 struct create_desc cd
;
1128 struct userNode
*user
;
1130 if ((argc
< 3) || !(user
= GetUserH(origin
)))
1133 cd
.when
= atoi(argv
[2]);
1134 parse_foreach(argv
[1], join_helper
, create_helper
, NULL
, NULL
, &cd
);
1138 static CMD_FUNC(cmd_join
)
1140 struct create_desc cd
;
1142 if (!(cd
.user
= GetUserH(origin
)))
1149 cd
.when
= atoi(argv
[2]);
1150 parse_foreach(argv
[1], join_helper
, create_helper
, NULL
, NULL
, &cd
);
1154 static CMD_FUNC(cmd_pong
)
1158 if (!strcmp(argv
[2], self
->name
)) {
1159 timeq_del(0, timed_send_ping
, 0, TIMEQ_IGNORE_WHEN
|TIMEQ_IGNORE_DATA
);
1160 timeq_del(0, timed_ping_timeout
, 0, TIMEQ_IGNORE_WHEN
|TIMEQ_IGNORE_DATA
);
1161 timeq_add(now
+ ping_freq
, timed_send_ping
, 0);
1167 static CMD_FUNC(cmd_nick
)
1169 struct userNode
*user
;
1170 if ((user
= GetUserH(origin
))) {
1171 /* nick change (since the source is a user numeric) */
1174 NickChange(user
, argv
[1], 1);
1176 struct server
*serv
;
1181 serv
= GetServerH(origin
);
1183 unsplit_string(argv
+6, argc
-9, modes
);
1186 AddUser(serv
, argv
[1], argv
[4], argv
[5], modes
, argv
[argc
-2], argv
[argc
-1], atoi(argv
[3]), argv
[argc
-3]);
1191 static CMD_FUNC(cmd_account
)
1193 struct userNode
*user
;
1194 struct server
*server
;
1195 struct handle_info
*hi
;
1197 if ((argc
< 3) || !origin
|| !(server
= GetServerH(origin
)))
1198 return 0; /* Origin must be server. */
1200 /* This next line appears to tremple origin.. why? */
1201 user
= GetUserN(argv
[1]);
1203 return 1; /* A QUIT probably passed the ACCOUNT. */
1205 if(!extended_accounts
) /* any need for this function without? */
1208 if(!strcmp(argv
[2],"C"))
1210 if((hi
= loc_auth(argv
[4], argv
[5])))
1213 putsock("%s " P10_ACCOUNT
" %s A %s %lu", self
->numeric
, server
->numeric
, argv
[3], hi
->registered
);
1219 putsock("%s " P10_ACCOUNT
" %s D %s", self
->numeric
, server
->numeric
, argv
[3]);
1223 else if(!strcmp(argv
[2],"R"))
1224 call_account_func(user
, argv
[3]);
1226 call_account_func(user
, argv
[2]); /* For backward compatability */
1230 static CMD_FUNC(cmd_fakehost
)
1232 struct userNode
*user
;
1234 if ((argc
< 3) || !origin
|| !GetServerH(origin
))
1236 if (!(user
= GetUserN(argv
[1])))
1238 assign_fakehost(user
, argv
[2], 0);
1242 static CMD_FUNC(cmd_burst
)
1245 char modes
[MAXLEN
], *members
= "";
1246 static char exemptlist
[MAXLEN
], banlist
[MAXLEN
];
1247 unsigned int next
= 3, res
= 1;
1248 int ctype
= 0, echeck
= 0, bcheck
= 0;
1249 struct chanNode
*cNode
;
1250 struct userNode
*un
;
1251 struct modeNode
*mNode
;
1254 char *user
, *end
, sep
;
1255 time_t in_timestamp
;
1265 while (next
< argc
) {
1266 switch (argv
[next
][0]) {
1270 for (pos
=argv
[next
], n_modes
= 1; *pos
; pos
++)
1271 if ((*pos
== 'k') || (*pos
== 'l') || (*pos
== 'A')
1274 unsplit_string(argv
+next
, n_modes
, modes
);
1279 for(parm
= mysep(&argv
[next
], " "); /* parm = first param */
1280 parm
; /* While param is not null */
1281 parm
= mysep(&argv
[next
], " ") /* parm = next param */
1299 /* strip % char off start of very first ban */
1300 if (strlen(parm
) > 1) {
1301 strncat(banlist
, strtok(parm
, "%"), sizeof(banlist
) - 1 - strlen(banlist
));
1302 strncat(banlist
, " ", sizeof(banlist
) - 1 - strlen(banlist
));
1306 strncat(banlist
, parm
, sizeof(banlist
) - 1 - strlen(banlist
));
1307 strncat(banlist
, " ", sizeof(banlist
) - 1 - strlen(banlist
));
1309 } else if (ctype
== 2) {
1313 strncat(exemptlist
, parm
, sizeof(exemptlist
) - 1 - strlen(exemptlist
));
1314 strncat(exemptlist
, " ", sizeof(exemptlist
) - 1 - strlen(exemptlist
));
1321 default: members
= argv
[next
++]; break;
1325 in_timestamp
= atoi(argv
[2]);
1326 if ((cNode
= dict_find(unbursted_channels
, argv
[1], NULL
))) {
1327 cNode
->timestamp
= in_timestamp
;
1328 dict_remove(unbursted_channels
, cNode
->name
);
1331 cNode
= AddChannel(argv
[1], in_timestamp
, modes
, banlist
, exemptlist
);
1333 /* Burst channel members in now. */
1334 for (user
= members
, sep
= *members
, mode
= 0; sep
; user
= end
) {
1335 for (end
= user
+ 3; isalnum(*end
) || *end
== '[' || *end
== ']'; end
++) ;
1336 sep
= *end
++; end
[-1] = 0;
1339 while ((sep
= *end
++)) {
1341 mode
|= MODE_CHANOP
;
1343 } else if (sep
== 'h') {
1344 mode
|= MODE_HALFOP
;
1346 } else if (sep
== 'v') {
1349 } else if (isdigit(sep
)) {
1350 mode
|= MODE_CHANOP
;
1352 oplevel
+= parse_oplevel(end
);
1354 oplevel
= parse_oplevel(end
);
1355 while (isdigit(*end
)) end
++;
1362 if (!(un
= GetUserN(user
))) {
1366 if ((mNode
= AddChannelUser(un
, cNode
))) {
1367 mNode
->modes
= mode
;
1368 mNode
->oplevel
= oplevel
;
1375 static CMD_FUNC(cmd_mode
)
1377 struct chanNode
*cn
;
1378 struct userNode
*un
;
1379 char *sethost
; // sethost - reed/apples
1380 int i
; // sethost - reed/apples
1384 if (!IsChannelName(argv
[1])) {
1385 un
= GetUserH(argv
[1]);
1387 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to find user %s whose mode is changing.", argv
[1]);
1390 // sethost - reed/apples
1392 mod_usermode(un
, argv
[2]);
1394 sethost
= malloc(strlen(argv
[2]) + 1 + strlen(argv
[3]) + 1);
1396 while((sethost
[i
++] = *argv
[2]++));
1399 while((sethost
[i
++] = *argv
[3]++));
1400 mod_usermode(un
, sethost
); // sethost - reed/apples
1406 if (!(cn
= GetChannel(argv
[1]))) {
1407 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to find channel %s whose mode is changing.", argv
[1]);
1410 if ((un
= GetUserH(origin
))) {
1411 struct modeNode
*mn
;
1412 /* Update idle time for person setting the mode */
1413 if ((mn
= GetUserMode(cn
, un
)))
1414 mn
->idle_since
= now
;
1416 /* If it came from a server, reset timestamp to re-sync. */
1417 cn
->timestamp
= atoi(argv
[argc
-1]);
1420 return mod_chanmode(un
, cn
, argv
+2, argc
-2, MCP_ALLOW_OVB
|MCP_FROM_SERVER
|(un
? MC_NOTIFY
: 0));
1423 static CMD_FUNC(cmd_opmode
)
1425 struct chanNode
*cn
;
1426 struct userNode
*un
;
1431 if (!(cn
= GetChannel(argv
[1]))) {
1432 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to find channel %s whose mode is changing.", argv
[1]);
1435 if (!(un
= GetUserH(origin
))) {
1436 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to find user %s requesting OPMODE.", origin
);
1440 log_module(MAIN_LOG
, LOG_ERROR
, "Non-privileged user %s using OPMODE.", un
->nick
);
1444 return mod_chanmode(un
, cn
, argv
+2, argc
-2, MCP_ALLOW_OVB
|MCP_FROM_SERVER
); /* do NOT announce opmode locally */
1447 static int clear_chanmode(struct chanNode
*channel
, const char *modes
);
1449 static CMD_FUNC(cmd_clearmode
)
1451 struct chanNode
*cn
;
1452 struct userNode
*un
;
1457 if (!(cn
= GetChannel(argv
[1]))) {
1458 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to find channel %s whose mode is changing.", argv
[1]);
1461 if (!(un
= GetUserH(origin
))) {
1462 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to find user %s requesting CLEARMODE.", origin
);
1466 log_module(MAIN_LOG
, LOG_ERROR
, "Non-privileged user %s using CLEARMODE.", un
->nick
);
1470 return clear_chanmode(cn
, argv
[2]);
1473 static CMD_FUNC(cmd_topic
)
1475 struct chanNode
*cn
;
1476 time_t chan_ts
, topic_ts
;
1477 struct userNode
*user
;
1481 if (!(cn
= GetChannel(argv
[1]))) {
1482 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to find channel %s whose topic is being set", argv
[1]);
1487 if (argc
== 5) { /* Asuka / Topic Bursting IRCu's */
1488 user
= GetUserH(origin
);
1489 chan_ts
= atoi(argv
[2]);
1490 topic_ts
= atoi(argv
[3]);
1491 } else if (argc
>= 6) { /* Nefarious 0.5.0 */
1492 user
= GetUserH(strtok(argv
[2], "!"));
1493 chan_ts
= atoi(argv
[3]);
1494 topic_ts
= atoi(argv
[4]);
1495 } else { /* Regular IRCu (No Topic Bursting)*/
1496 user
= GetUserH(origin
);
1497 chan_ts
= cn
->timestamp
;
1501 SetChannelTopic(cn
, user
, user
, argv
[argc
-1], 0);
1502 cn
->topic_time
= topic_ts
;
1506 static CMD_FUNC(cmd_num_topic
)
1508 struct chanNode
*cn
;
1511 return 0; /* huh? */
1513 cn
= GetChannel(argv
[2]);
1515 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to find channel %s in topic reply", argv
[2]);
1521 switch (atoi(argv
[0])) {
1524 break; /* no topic */
1528 safestrncpy(cn
->topic
, unsplit_string(argv
+3, argc
-3, NULL
), sizeof(cn
->topic
));
1533 safestrncpy(cn
->topic_nick
, argv
[3], sizeof(cn
->topic_nick
));
1534 cn
->topic_time
= atoi(argv
[4]);
1537 return 0; /* should never happen */
1542 static CMD_FUNC(cmd_num_gline
)
1546 gline_add(origin
, argv
[3], atoi(argv
[4])-now
, argv
[5], now
, 0, 0);
1550 static CMD_FUNC(cmd_num_shun
)
1554 shun_add(origin
, argv
[3], atoi(argv
[4])-now
, argv
[5], now
, 0);
1558 static CMD_FUNC(cmd_quit
)
1560 struct userNode
*user
;
1563 /* Sometimes we get a KILL then a QUIT or the like, so we don't want to
1564 * call DelUser unless we have the user in our grasp. */
1565 if ((user
= GetUserH(origin
)))
1566 DelUser(user
, NULL
, false, argv
[1]);
1570 static CMD_FUNC(cmd_kill
)
1572 struct userNode
*user
;
1575 user
= GetUserN(argv
[1]);
1577 /* If we get a KILL for a non-existent user, it could be a
1578 * Ghost response to a KILL we sent out earlier. So we only
1579 * whine if the target is local.
1581 if (!strncmp(argv
[1], self
->numeric
, strlen(self
->numeric
)))
1582 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to find kill victim %s", argv
[1]);
1586 if (IsLocal(user
) && IsService(user
)) {
1587 /* TODO: rate limit this so silly things don't happen. */
1588 ReintroduceUser(user
);
1592 DelUser(user
, NULL
, false, argv
[2]);
1596 static CMD_FUNC(cmd_part
)
1598 struct userNode
*user
;
1602 user
= GetUserH(origin
);
1605 parse_foreach(argv
[1], part_helper
, NULL
, NULL
, NULL
, user
);
1609 static CMD_FUNC(cmd_kick
)
1613 ChannelUserKicked(GetUserH(origin
), GetUserN(argv
[2]), GetChannel(argv
[1]));
1617 static CMD_FUNC(cmd_squit
)
1619 struct server
*server
;
1623 if (!(server
= GetServerH(argv
[1])))
1626 if (server
== self
->uplink
) {
1627 /* Force a reconnect to the currently selected server. */
1628 cManager
.uplink
->tries
= 0;
1629 log_module(MAIN_LOG
, LOG_INFO
, "Squitting from uplink: %s", argv
[3]);
1634 DelServer(server
, 0, argv
[3]);
1638 static CMD_FUNC(cmd_privmsg
)
1640 struct privmsg_desc pd
;
1643 pd
.user
= GetUserH(origin
);
1644 if (!pd
.user
|| (IsGagged(pd
.user
) && !IsOper(pd
.user
)))
1648 parse_foreach(argv
[1], privmsg_chan_helper
, NULL
, privmsg_user_helper
, privmsg_invalid
, &pd
);
1652 static CMD_FUNC(cmd_notice
)
1654 struct privmsg_desc pd
;
1657 pd
.user
= GetUserH(origin
);
1658 if (!pd
.user
|| (IsGagged(pd
.user
) && !IsOper(pd
.user
)))
1662 parse_foreach(argv
[1], privmsg_chan_helper
, NULL
, privmsg_user_helper
, privmsg_invalid
, &pd
);
1666 static CMD_FUNC(cmd_away
)
1668 struct userNode
*uNode
;
1670 uNode
= GetUserH(origin
);
1674 uNode
->modes
&= ~FLAGS_AWAY
;
1676 uNode
->modes
|= FLAGS_AWAY
;
1680 static CMD_FUNC(cmd_gline
)
1684 if (argv
[2][0] == '+') {
1687 gline_add(origin
, argv
[2]+1, strtoul(argv
[3], NULL
, 0), argv
[argc
-1], now
, 0, 0);
1689 } else if (argv
[2][0] == '-') {
1690 gline_remove(argv
[2]+1, 0);
1696 static CMD_FUNC(cmd_shun
)
1700 if (argv
[2][0] == '+') {
1703 shun_add(origin
, argv
[2]+1, strtoul(argv
[3], NULL
, 0), argv
[argc
-1], now
, 0);
1705 } else if (argv
[2][0] == '-') {
1706 shun_remove(argv
[2]+1, 0);
1712 static CMD_FUNC(cmd_svsnick
)
1714 struct userNode
*target
, *dest
;
1716 || !(target
= GetUserN(argv
[1]))
1718 || (dest
= GetUserH(argv
[2])))
1720 NickChange(target
, argv
[2], 0);
1724 static oper_func_t
*of_list
;
1725 static unsigned int of_size
= 0, of_used
= 0;
1728 free_user(struct userNode
*user
)
1739 free(privmsg_funcs
);
1742 dict_delete(irc_func_dict
);
1743 for (nn
=0; nn
<dead_users
.used
; nn
++)
1744 free_user(dead_users
.list
[nn
]);
1745 userList_clean(&dead_users
);
1749 p10_conf_reload(void) {
1750 hidden_host_suffix
= conf_get_data("server/hidden_host", RECDB_QSTRING
);
1754 remove_unbursted_channel(struct chanNode
*cNode
) {
1755 if (unbursted_channels
)
1756 dict_remove(unbursted_channels
, cNode
->name
);
1762 const char *str
, *desc
;
1763 int numnick
, usermask
, max_users
;
1764 char numer
[COMBO_NUMERIC_LEN
+1];
1766 /* read config items */
1767 str
= conf_get_data("server/extended_accounts", RECDB_QSTRING
);
1768 extended_accounts
= str
? enabled_string(str
) : 1;
1769 str
= conf_get_data("server/ping_freq", RECDB_QSTRING
);
1770 ping_freq
= str
? ParseInterval(str
) : 120;
1771 str
= conf_get_data("server/ping_timeout", RECDB_QSTRING
);
1772 ping_timeout
= str
? ParseInterval(str
) : 30;
1773 str
= conf_get_data("server/force_n2k", RECDB_QSTRING
);
1774 force_n2k
= str
? enabled_string(str
) : 1;
1775 str
= conf_get_data("server/numeric", RECDB_QSTRING
);
1777 log_module(MAIN_LOG
, LOG_ERROR
, "No server/numeric entry in config file.");
1780 numnick
= atoi(str
);
1781 str
= conf_get_data("server/max_users", RECDB_QSTRING
);
1782 max_users
= str
? atoi(str
) : 4096;
1783 for (usermask
= 4; usermask
< max_users
; usermask
<<= 1) ;
1785 if ((numnick
< 64) && (usermask
< 4096) && !force_n2k
)
1786 inttobase64(numer
, (numnick
<< 12) + (usermask
& 0x00fff), 3);
1788 inttobase64(numer
, (numnick
<< 18) + (usermask
& 0x3ffff), 5);
1790 str
= conf_get_data("server/his_servername", RECDB_QSTRING
);
1791 his_servername
= str
? strdup(str
) : NULL
;
1792 str
= conf_get_data("server/his_servercomment", RECDB_QSTRING
);
1793 his_servercomment
= str
? strdup(str
) : NULL
;
1795 str
= conf_get_data("server/hostname", RECDB_QSTRING
);
1796 desc
= conf_get_data("server/description", RECDB_QSTRING
);
1797 if (!str
|| !desc
) {
1798 log_module(MAIN_LOG
, LOG_ERROR
, "No server/hostname entry in config file.");
1801 self
= AddServer(NULL
, str
, 0, boot_time
, now
, numer
, desc
);
1802 conf_register_reload(p10_conf_reload
);
1804 irc_func_dict
= dict_new();
1805 dict_insert(irc_func_dict
, CMD_BURST
, cmd_burst
);
1806 dict_insert(irc_func_dict
, TOK_BURST
, cmd_burst
);
1807 dict_insert(irc_func_dict
, CMD_CREATE
, cmd_create
);
1808 dict_insert(irc_func_dict
, TOK_CREATE
, cmd_create
);
1809 dict_insert(irc_func_dict
, CMD_EOB
, cmd_eob
);
1810 dict_insert(irc_func_dict
, TOK_EOB
, cmd_eob
);
1811 dict_insert(irc_func_dict
, CMD_EOB_ACK
, cmd_eob_ack
);
1812 dict_insert(irc_func_dict
, TOK_EOB_ACK
, cmd_eob_ack
);
1813 dict_insert(irc_func_dict
, CMD_MODE
, cmd_mode
);
1814 dict_insert(irc_func_dict
, TOK_MODE
, cmd_mode
);
1815 dict_insert(irc_func_dict
, CMD_NICK
, cmd_nick
);
1816 dict_insert(irc_func_dict
, TOK_NICK
, cmd_nick
);
1817 dict_insert(irc_func_dict
, CMD_ACCOUNT
, cmd_account
);
1818 dict_insert(irc_func_dict
, TOK_ACCOUNT
, cmd_account
);
1819 dict_insert(irc_func_dict
, CMD_FAKEHOST
, cmd_fakehost
);
1820 dict_insert(irc_func_dict
, TOK_FAKEHOST
, cmd_fakehost
);
1821 dict_insert(irc_func_dict
, CMD_PASS
, cmd_pass
);
1822 dict_insert(irc_func_dict
, TOK_PASS
, cmd_pass
);
1823 dict_insert(irc_func_dict
, CMD_PING
, cmd_ping
);
1824 dict_insert(irc_func_dict
, TOK_PING
, cmd_ping
);
1825 dict_insert(irc_func_dict
, CMD_PRIVMSG
, cmd_privmsg
);
1826 dict_insert(irc_func_dict
, TOK_PRIVMSG
, cmd_privmsg
);
1827 dict_insert(irc_func_dict
, CMD_PONG
, cmd_pong
);
1828 dict_insert(irc_func_dict
, TOK_PONG
, cmd_pong
);
1829 dict_insert(irc_func_dict
, CMD_QUIT
, cmd_quit
);
1830 dict_insert(irc_func_dict
, TOK_QUIT
, cmd_quit
);
1831 dict_insert(irc_func_dict
, CMD_SERVER
, cmd_server
);
1832 dict_insert(irc_func_dict
, TOK_SERVER
, cmd_server
);
1833 dict_insert(irc_func_dict
, CMD_JOIN
, cmd_join
);
1834 dict_insert(irc_func_dict
, TOK_JOIN
, cmd_join
);
1835 dict_insert(irc_func_dict
, CMD_PART
, cmd_part
);
1836 dict_insert(irc_func_dict
, TOK_PART
, cmd_part
);
1837 dict_insert(irc_func_dict
, CMD_ERROR
, cmd_error
);
1838 dict_insert(irc_func_dict
, TOK_ERROR
, cmd_error
);
1839 dict_insert(irc_func_dict
, CMD_TOPIC
, cmd_topic
);
1840 dict_insert(irc_func_dict
, TOK_TOPIC
, cmd_topic
);
1841 dict_insert(irc_func_dict
, CMD_AWAY
, cmd_away
);
1842 dict_insert(irc_func_dict
, TOK_AWAY
, cmd_away
);
1843 dict_insert(irc_func_dict
, CMD_SILENCE
, cmd_dummy
);
1844 dict_insert(irc_func_dict
, TOK_SILENCE
, cmd_dummy
);
1845 dict_insert(irc_func_dict
, CMD_KICK
, cmd_kick
);
1846 dict_insert(irc_func_dict
, TOK_KICK
, cmd_kick
);
1847 dict_insert(irc_func_dict
, CMD_SQUIT
, cmd_squit
);
1848 dict_insert(irc_func_dict
, TOK_SQUIT
, cmd_squit
);
1849 dict_insert(irc_func_dict
, CMD_KILL
, cmd_kill
);
1850 dict_insert(irc_func_dict
, TOK_KILL
, cmd_kill
);
1851 dict_insert(irc_func_dict
, CMD_NOTICE
, cmd_notice
);
1852 dict_insert(irc_func_dict
, TOK_NOTICE
, cmd_notice
);
1853 dict_insert(irc_func_dict
, CMD_STATS
, cmd_stats
);
1854 dict_insert(irc_func_dict
, TOK_STATS
, cmd_stats
);
1855 dict_insert(irc_func_dict
, CMD_SVSNICK
, cmd_svsnick
);
1856 dict_insert(irc_func_dict
, TOK_SVSNICK
, cmd_svsnick
);
1857 dict_insert(irc_func_dict
, CMD_WHOIS
, cmd_whois
);
1858 dict_insert(irc_func_dict
, TOK_WHOIS
, cmd_whois
);
1859 dict_insert(irc_func_dict
, CMD_GLINE
, cmd_gline
);
1860 dict_insert(irc_func_dict
, TOK_GLINE
, cmd_gline
);
1861 dict_insert(irc_func_dict
, CMD_SHUN
, cmd_shun
);
1862 dict_insert(irc_func_dict
, TOK_SHUN
, cmd_shun
);
1863 dict_insert(irc_func_dict
, CMD_OPMODE
, cmd_opmode
);
1864 dict_insert(irc_func_dict
, TOK_OPMODE
, cmd_opmode
);
1865 dict_insert(irc_func_dict
, CMD_CLEARMODE
, cmd_clearmode
);
1866 dict_insert(irc_func_dict
, TOK_CLEARMODE
, cmd_clearmode
);
1867 dict_insert(irc_func_dict
, CMD_VERSION
, cmd_version
);
1868 dict_insert(irc_func_dict
, TOK_VERSION
, cmd_version
);
1869 dict_insert(irc_func_dict
, CMD_ADMIN
, cmd_admin
);
1870 dict_insert(irc_func_dict
, TOK_ADMIN
, cmd_admin
);
1872 /* In P10, DESTRUCT doesn't do anything except be broadcast to servers.
1873 * Apparently to obliterate channels from any servers that think they
1876 dict_insert(irc_func_dict
, CMD_DESTRUCT
, cmd_dummy
);
1877 dict_insert(irc_func_dict
, TOK_DESTRUCT
, cmd_dummy
);
1878 /* Ignore invites */
1879 dict_insert(irc_func_dict
, CMD_INVITE
, cmd_dummy
);
1880 dict_insert(irc_func_dict
, TOK_INVITE
, cmd_dummy
);
1881 /* DESYNCH is just informational, so ignore it */
1882 dict_insert(irc_func_dict
, CMD_DESYNCH
, cmd_dummy
);
1883 dict_insert(irc_func_dict
, TOK_DESYNCH
, cmd_dummy
);
1884 /* Ignore channel operator notices. */
1885 dict_insert(irc_func_dict
, CMD_WALLCHOPS
, cmd_dummy
);
1886 dict_insert(irc_func_dict
, TOK_WALLCHOPS
, cmd_dummy
);
1887 dict_insert(irc_func_dict
, CMD_WALLVOICES
, cmd_dummy
);
1888 dict_insert(irc_func_dict
, TOK_WALLVOICES
, cmd_dummy
);
1889 dict_insert(irc_func_dict
, CMD_WALLHOPS
, cmd_dummy
);
1890 dict_insert(irc_func_dict
, TOK_WALLHOPS
, cmd_dummy
);
1891 /* Ignore opers being silly. */
1892 dict_insert(irc_func_dict
, CMD_WALLOPS
, cmd_dummy
);
1893 dict_insert(irc_func_dict
, TOK_WALLOPS
, cmd_dummy
);
1894 dict_insert(irc_func_dict
, CMD_WALLHOPS
, cmd_dummy
);
1895 dict_insert(irc_func_dict
, TOK_WALLHOPS
, cmd_dummy
);
1896 dict_insert(irc_func_dict
, TOK_WALLUSERS
, cmd_dummy
);
1897 /* Ignore dnsbl exemptions */
1898 dict_insert(irc_func_dict
, TOK_EXEMPT
, cmd_dummy
);
1899 dict_insert(irc_func_dict
, TOK_MARK
, cmd_dummy
);
1901 dict_insert(irc_func_dict
, TOK_PRIVS
, cmd_dummy
);
1902 /* Ignore remote luser */
1903 dict_insert(irc_func_dict
, TOK_LUSERS
, cmd_dummy
);
1904 /* We have reliable clock! Always! Wraaa! */
1905 dict_insert(irc_func_dict
, CMD_SETTIME
, cmd_dummy
);
1906 dict_insert(irc_func_dict
, TOK_SETTIME
, cmd_dummy
);
1908 dict_insert(irc_func_dict
, "331", cmd_num_topic
);
1909 dict_insert(irc_func_dict
, "332", cmd_num_topic
);
1910 dict_insert(irc_func_dict
, "333", cmd_num_topic
);
1911 dict_insert(irc_func_dict
, "345", cmd_dummy
); /* blah has been invited to blah */
1912 dict_insert(irc_func_dict
, "432", cmd_error_nick
); /* Erroneus [sic] nickname */
1913 /* ban list resetting */
1914 /* "stats g" responses */
1915 dict_insert(irc_func_dict
, "247", cmd_num_gline
);
1916 dict_insert(irc_func_dict
, "542", cmd_num_shun
);
1917 dict_insert(irc_func_dict
, "219", cmd_dummy
); /* "End of /STATS report" */
1918 /* other numeric responses we might get */
1919 dict_insert(irc_func_dict
, "401", cmd_dummy
); /* target left network */
1920 dict_insert(irc_func_dict
, "403", cmd_dummy
); /* no such channel */
1921 dict_insert(irc_func_dict
, "404", cmd_dummy
); /* cannot send to channel */
1922 dict_insert(irc_func_dict
, "439", cmd_dummy
); /* target change too fast */
1923 dict_insert(irc_func_dict
, "441", cmd_dummy
); /* target isn't on that channel */
1924 dict_insert(irc_func_dict
, "442", cmd_dummy
); /* you aren't on that channel */
1925 dict_insert(irc_func_dict
, "443", cmd_dummy
); /* is already on channel (after invite?) */
1926 dict_insert(irc_func_dict
, "461", cmd_dummy
); /* Not enough parameters (after TOPIC w/ 0 args) */
1927 dict_insert(irc_func_dict
, "467", cmd_dummy
); /* Channel key already set */
1929 num_privmsg_funcs
= 16;
1930 privmsg_funcs
= malloc(sizeof(privmsg_func_t
)*num_privmsg_funcs
);
1931 memset(privmsg_funcs
, 0, sizeof(privmsg_func_t
)*num_privmsg_funcs
);
1933 num_notice_funcs
= 16;
1934 notice_funcs
= malloc(sizeof(privmsg_func_t
)*num_notice_funcs
);
1935 memset(notice_funcs
, 0, sizeof(privmsg_func_t
)*num_notice_funcs
);
1937 userList_init(&dead_users
);
1938 reg_del_channel_func(remove_unbursted_channel
);
1939 reg_exit_func(parse_cleanup
);
1943 parse_line(char *line
, int recursive
)
1945 char *argv
[MAXNUMPARAMS
], *origin
;
1946 int argc
, cmd
, res
=0;
1949 argc
= split_line(line
, true, MAXNUMPARAMS
, argv
);
1950 cmd
= self
->uplink
|| !argv
[0][1] || !argv
[0][2];
1953 if (argv
[0][0] == ':') {
1955 } else if (!argv
[0][1] || !argv
[0][2]) {
1956 struct server
*sNode
= GetServerN(argv
[0]);
1957 origin
= sNode
? sNode
->name
: 0;
1959 struct userNode
*uNode
= GetUserN(argv
[0]);
1960 origin
= uNode
? uNode
->nick
: 0;
1964 if ((func
= dict_find(irc_func_dict
, argv
[cmd
], NULL
)))
1965 res
= func(origin
, argc
-cmd
, argv
+cmd
);
1968 log_module(MAIN_LOG
, LOG_ERROR
, "PARSE ERROR on line: %s", unsplit_string(argv
, argc
, NULL
));
1969 } else if (!recursive
) {
1971 for (i
=0; i
<dead_users
.used
; i
++)
1972 free_user(dead_users
.list
[i
]);
1973 dead_users
.used
= 0;
1979 parse_foreach(char *target_list
, foreach_chanfunc cf
, foreach_nonchan nc
, foreach_userfunc uf
, foreach_nonuser nu
, void *data
)
1985 while (*j
!= 0 && *j
!= ',')
1990 if (IsChannelName(target_list
)
1991 || (target_list
[0] == '0' && target_list
[1] == '\0')) {
1992 struct chanNode
*chan
= GetChannel(target_list
);
1999 nc(target_list
, data
);
2002 struct userNode
*user
;
2003 struct privmsg_desc
*pd
= data
;
2005 pd
->is_qualified
= 0;
2006 if (*target_list
== '@') {
2008 } else if (strchr(target_list
, '@')) {
2009 struct server
*server
;
2011 pd
->is_qualified
= 1;
2012 user
= GetUserH(strtok(target_list
, "@"));
2013 server
= GetServerH(strtok(NULL
, "@"));
2015 if (user
&& (user
->uplink
!= server
)) {
2016 /* Don't attempt to index into any arrays
2017 using a user's numeric on another server. */
2021 user
= GetUserN(target_list
);
2029 nu(target_list
, data
);
2033 } while (old
== ',');
2037 get_local_numeric(void)
2039 static unsigned int next_numeric
= 0;
2040 if (self
->clients
> self
->num_mask
)
2042 while (self
->users
[next_numeric
])
2043 if (++next_numeric
> self
->num_mask
)
2045 return next_numeric
;
2049 make_numeric(struct server
*svr
, int local_num
, char *outbuf
)
2053 if (force_n2k
|| svr
->numeric
[1]) {
2058 llen
= (local_num
< 64*64) ? 2 : 3;
2060 strncpy(outbuf
, svr
->numeric
, slen
);
2061 inttobase64(outbuf
+slen
, local_num
, llen
);
2062 outbuf
[slen
+llen
] = 0;
2066 AddServer(struct server
*uplink
, const char *name
, int hops
, time_t boot
, time_t link
, const char *numeric
, const char *description
)
2068 struct server
* sNode
;
2071 if ((sNode
= GetServerN(numeric
))) {
2072 /* This means we're trying to re-add an existant server.
2073 * To be safe, we should forget the previous incarnation.
2074 * (And all its linked servers.)
2076 * It usually only happens in replays when the original
2077 * had a ping timeout and the replay didn't (because
2078 * replaying a ping timeout invariably gets things wrong).
2080 DelServer(sNode
, 0, NULL
);
2083 switch (strlen(numeric
)) {
2084 case 5: slen
= 2; mlen
= 3; break;
2085 case 4: slen
= 1; mlen
= 3; break;
2086 case 3: slen
= 1; mlen
= 2; break;
2088 log_module(MAIN_LOG
, LOG_ERROR
, "AddServer(\"%s\", \"%s\", ...): Numeric %s has invalid length.", uplink
->name
, name
, numeric
);
2092 sNode
= calloc(1, sizeof(*sNode
));
2093 sNode
->uplink
= uplink
;
2094 safestrncpy(sNode
->name
, name
, sizeof(sNode
->name
));
2095 sNode
->num_mask
= base64toint(numeric
+slen
, mlen
);
2099 strncpy(sNode
->numeric
, numeric
, slen
);
2100 safestrncpy(sNode
->description
, description
, sizeof(sNode
->description
));
2101 sNode
->users
= calloc(sNode
->num_mask
+1, sizeof(*sNode
->users
));
2102 serverList_init(&sNode
->children
);
2103 if (sNode
->uplink
) {
2104 /* uplink may be NULL if we're just building ourself */
2105 serverList_append(&sNode
->uplink
->children
, sNode
);
2107 servers_num
[base64toint(numeric
, slen
)] = sNode
;
2108 dict_insert(servers
, sNode
->name
, sNode
);
2112 void DelServer(struct server
* serv
, int announce
, const char *message
)
2116 /* If we receive an ERROR command before the SERVER
2117 * command a NULL server can be passed */
2121 /* Hrm, what's the right way to SQUIT some other server?
2122 * (This code is only to handle killing juped servers.) */
2123 if (announce
&& (serv
->uplink
== self
) && (serv
!= self
->uplink
))
2124 irc_squit(serv
, message
, NULL
);
2126 /* must recursively remove servers linked to this one first */
2127 for (i
=serv
->children
.used
;i
>0;)
2128 if (serv
->children
.list
[--i
] != self
)
2129 DelServer(serv
->children
.list
[i
], false, NULL
);
2131 /* clean up server's user hash tables */
2132 for (i
=0;i
<=serv
->num_mask
;i
++)
2134 DelUser(serv
->users
[i
], NULL
, false, "server delinked");
2138 serverList_remove(&serv
->uplink
->children
, serv
);
2139 if (serv
== self
->uplink
)
2140 self
->uplink
= NULL
;
2141 servers_num
[base64toint(serv
->numeric
, strlen(serv
->numeric
))] = NULL
;
2142 dict_remove(servers
, serv
->name
);
2143 serverList_clean(&serv
->children
);
2149 AddService(const char *nick
, const char *modes
, const char *desc
, const char *hostname
)
2151 char numeric
[COMBO_NUMERIC_LEN
+1];
2152 int local_num
= get_local_numeric();
2153 time_t timestamp
= now
;
2154 struct userNode
*old_user
= GetUserH(nick
);
2157 if (IsLocal(old_user
))
2159 timestamp
= old_user
->timestamp
- 1;
2161 if (local_num
== -1) {
2162 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to allocate numnick for service %s", nick
);
2166 hostname
= self
->name
;
2167 make_numeric(self
, local_num
, numeric
);
2168 /* TODO: Make these modes part of the conf file */
2169 return AddUser(self
, nick
, nick
, hostname
, modes
? modes
: "+oik", numeric
, desc
, now
, "AAAAAA");
2173 AddClone(const char *nick
, const char *ident
, const char *hostname
, const char *desc
)
2175 char numeric
[COMBO_NUMERIC_LEN
+1];
2176 int local_num
= get_local_numeric();
2177 time_t timestamp
= now
;
2178 struct userNode
*old_user
= GetUserH(nick
);
2181 if (IsLocal(old_user
))
2183 timestamp
= old_user
->timestamp
- 1;
2185 if (local_num
== -1) {
2186 log_module(MAIN_LOG
, LOG_ERROR
, "Unable to allocate numnick for clone %s", nick
);
2189 make_numeric(self
, local_num
, numeric
);
2190 return AddUser(self
, nick
, ident
, hostname
, "+i", numeric
, desc
, timestamp
, "AAAAAA");
2194 is_valid_nick(const char *nick
) {
2196 /* IRC has some of The Most Fucked-Up ideas about character sets
2198 if (!isalpha(*nick
) && !strchr("{|}~[\\]^_`", *nick
))
2200 for (ii
= 0; nick
[ii
]; ++ii
)
2201 if (!isalnum(nick
[ii
]) && !strchr("{|}~[\\]^-_`", nick
[ii
]))
2203 if (strlen(nick
) > nicklen
)
2208 static struct userNode
*
2209 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
)
2211 struct userNode
*oldUser
, *uNode
;
2212 unsigned int n
, ignore_user
;
2214 if ((strlen(numeric
) < 3) || (strlen(numeric
) > 5)) {
2215 log_module(MAIN_LOG
, LOG_WARNING
, "AddUser(%p, %s, ...): numeric %s wrong length!", uplink
, nick
, numeric
);
2220 log_module(MAIN_LOG
, LOG_WARNING
, "AddUser(%p, %s, ...): server for numeric %s doesn't exist!", uplink
, nick
, numeric
);
2224 if (uplink
!= GetServerN(numeric
)) {
2225 log_module(MAIN_LOG
, LOG_WARNING
, "AddUser(%p, %s, ...): server for numeric %s differs from nominal uplink %s.", uplink
, nick
, numeric
, uplink
->name
);
2229 if (!is_valid_nick(nick
)) {
2230 log_module(MAIN_LOG
, LOG_WARNING
, "AddUser(%p, %s, ...): invalid nickname detected.", uplink
, nick
);
2235 if ((oldUser
= GetUserH(nick
))) {
2236 if (IsLocal(oldUser
) && (IsService(oldUser
) || IsPersistent(oldUser
))) {
2237 /* The service should collide the new user off. */
2238 oldUser
->timestamp
= timestamp
- 1;
2241 if (oldUser
->timestamp
> timestamp
) {
2242 /* "Old" user is really newer; remove them */
2243 DelUser(oldUser
, 0, 1, "Overruled by older nick");
2245 /* User being added is too new; do not add them to
2246 * clients, but do add them to the server's list, since it
2247 * will send a KILL and QUIT soon. */
2252 /* create new usernode and set all values */
2253 uNode
= calloc(1, sizeof(*uNode
));
2254 uNode
->nick
= strdup(nick
);
2255 safestrncpy(uNode
->ident
, ident
, sizeof(uNode
->ident
));
2256 safestrncpy(uNode
->info
, userinfo
, sizeof(uNode
->info
));
2257 safestrncpy(uNode
->hostname
, hostname
, sizeof(uNode
->hostname
));
2258 safestrncpy(uNode
->numeric
, numeric
, sizeof(uNode
->numeric
));
2259 irc_p10_pton(&uNode
->ip
, realip
);
2260 uNode
->timestamp
= timestamp
;
2261 modeList_init(&uNode
->channels
);
2262 uNode
->uplink
= uplink
;
2263 if (++uNode
->uplink
->clients
> uNode
->uplink
->max_clients
) {
2264 uNode
->uplink
->max_clients
= uNode
->uplink
->clients
;
2266 uNode
->num_local
= base64toint(numeric
+strlen(uNode
->uplink
->numeric
), 3) & uNode
->uplink
->num_mask
;
2267 uNode
->uplink
->users
[uNode
->num_local
] = uNode
;
2268 mod_usermode(uNode
, modes
);
2272 dict_insert(clients
, uNode
->nick
, uNode
);
2273 if (dict_size(clients
) > max_clients
) {
2274 max_clients
= dict_size(clients
);
2275 max_clients_time
= now
;
2279 for (n
=0; n
<nuf_used
; n
++)
2280 if (nuf_list
[n
](uNode
))
2283 if ((uNode
->loc
== 1) && (uNode
->handle_info
))
2284 send_func_list(uNode
);
2289 /* removes user from it's server's hash table and nick hash table */
2291 DelUser(struct userNode
* user
, struct userNode
*killer
, int announce
, const char *why
)
2297 /* mark them as dead, in case anybody cares */
2300 /* remove pending adduser commands */
2301 wipe_adduser_pending(NULL
, user
);
2303 /* remove user from all channels */
2304 while (user
->channels
.used
> 0)
2305 DelChannelUser(user
, user
->channels
.list
[user
->channels
.used
-1]->channel
, false, 0);
2307 /* Call these in reverse order so ChanServ can update presence
2308 information before NickServ nukes the handle_info. */
2309 for (n
= duf_used
; n
> 0; )
2310 duf_list
[--n
](user
, killer
, why
);
2312 user
->uplink
->clients
--;
2313 user
->uplink
->users
[user
->num_local
] = NULL
;
2315 userList_remove(&curr_opers
, user
);
2316 /* remove from global dictionary, but not if after a collide */
2317 if (user
== dict_find(clients
, user
->nick
, NULL
))
2318 dict_remove(clients
, user
->nick
);
2320 if (IsInvisible(user
))
2325 irc_quit(user
, why
);
2327 irc_kill(killer
, user
, why
);
2330 modeList_clean(&user
->channels
);
2331 /* We don't free them, in case we try to privmsg them or something
2332 * (like when a stupid oper kills themself). We just put them onto
2333 * a list of clients that get freed after processing each line.
2335 if (dead_users
.size
)
2336 userList_append(&dead_users
, user
);
2341 static void call_oper_funcs(struct userNode
*user
);
2343 void mod_usermode(struct userNode
*user
, const char *mode_change
) {
2345 const char *word
= mode_change
;
2347 if (!user
|| !mode_change
)
2350 call_user_mode_funcs(user
, mode_change
);
2352 while (*word
!= ' ' && *word
) word
++;
2353 while (*word
== ' ') word
++;
2355 #define do_user_mode(FLAG) do { if (add) user->modes |= FLAG; else user->modes &= ~FLAG; } while (0)
2356 switch (*mode_change
++) {
2357 case 0: case ' ': return;
2358 case '+': add
= 1; break;
2359 case '-': add
= 0; break;
2362 if(!IsOper(user
)) { /* Dont re-oper an oper */
2363 userList_append(&curr_opers
, user
);
2364 call_oper_funcs(user
);
2367 userList_remove(&curr_opers
, user
);
2369 do_user_mode(FLAGS_OPER
);
2371 case 'O': do_user_mode(FLAGS_LOCOP
); break;
2372 case 'i': do_user_mode(FLAGS_INVISIBLE
);
2378 case 'w': do_user_mode(FLAGS_WALLOP
); break;
2379 case 's': do_user_mode(FLAGS_SERVNOTICE
); break;
2380 case 'd': do_user_mode(FLAGS_DEAF
); break;
2381 case 'k': do_user_mode(FLAGS_SERVICE
); break;
2382 case 'g': do_user_mode(FLAGS_GLOBAL
); break;
2383 // sethost - reed/apples
2384 // case 'h': do_user_mode(FLAGS_HELPER); break;
2385 // I check if there's an 'h' in the first part, and if there,
2386 // then everything after the space becomes their new host.
2387 case 'h': do_user_mode(FLAGS_SETHOST
);
2389 char sethost
[MAXLEN
];
2391 for (ii
=0; (*word
!= ' ') && (*word
!= '\0'); )
2392 sethost
[ii
++] = *word
++;
2394 while (*word
== ' ')
2396 safestrncpy(user
->sethost
, sethost
, sizeof(user
->sethost
));
2399 case 'x': do_user_mode(FLAGS_HIDDEN_HOST
); break;
2404 for (ii
=0; (*word
!= ' ') && (*word
!= '\0'); )
2405 tag
[ii
++] = *word
++;
2407 while (*word
== ' ')
2409 call_account_func(user
, tag
);
2416 for (ii
=0; (*word
!= ' ') && (*word
!= '\0'); )
2417 host
[ii
++] = *word
++;
2419 while (*word
== ' ')
2421 assign_fakehost(user
, host
, 0);
2429 struct mod_chanmode
*
2430 mod_chanmode_parse(struct chanNode
*channel
, char **modes
, unsigned int argc
, unsigned int flags
, short base_oplevel
)
2432 struct mod_chanmode
*change
;
2433 unsigned int ii
, in_arg
, ch_arg
, add
;
2437 if (!(change
= mod_chanmode_alloc(argc
- 1)))
2440 for (ii
= ch_arg
= 0, in_arg
= add
= 1;
2441 (modes
[0][ii
] != '\0') && (modes
[0][ii
] != ' ');
2443 switch (modes
[0][ii
]) {
2450 #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)
2451 case 'C': do_chan_mode(MODE_NOCTCPS
); break;
2452 case 'D': do_chan_mode(MODE_DELAYJOINS
); break;
2453 case 'c': do_chan_mode(MODE_NOCOLORS
); break;
2454 case 'i': do_chan_mode(MODE_INVITEONLY
); break;
2455 case 'm': do_chan_mode(MODE_MODERATED
); break;
2456 case 'n': do_chan_mode(MODE_NOPRIVMSGS
); break;
2457 case 'p': do_chan_mode(MODE_PRIVATE
); break;
2458 case 'r': do_chan_mode(MODE_REGONLY
); break;
2459 case 's': do_chan_mode(MODE_SECRET
); break;
2460 case 't': do_chan_mode(MODE_TOPICLIMIT
); break;
2461 case 'S': do_chan_mode(MODE_STRIPCOLOR
); break;
2462 case 'M': do_chan_mode(MODE_MODUNREG
); break;
2463 case 'N': do_chan_mode(MODE_NONOTICE
); break;
2464 case 'Q': do_chan_mode(MODE_NOQUITMSGS
); break;
2465 case 'T': do_chan_mode(MODE_NOAMSG
); break;
2466 case 'O': do_chan_mode(MODE_OPERSONLY
); break;
2467 case 'Z': do_chan_mode(MODE_SSLONLY
); break;
2468 case 'L': do_chan_mode(MODE_HIDEMODE
); break;
2470 if (!(flags
& MCP_REGISTERED
)) {
2471 do_chan_mode(MODE_REGISTERED
);
2473 mod_chanmode_free(change
);
2482 change
->modes_set
|= MODE_LIMIT
;
2483 change
->new_limit
= atoi(modes
[in_arg
++]);
2485 change
->modes_set
&= ~MODE_LIMIT
;
2486 change
->modes_clear
|= MODE_LIMIT
;
2493 change
->modes_set
|= MODE_KEY
;
2494 safestrncpy(change
->new_key
, modes
[in_arg
++], sizeof(change
->new_key
));
2496 change
->modes_clear
|= MODE_KEY
;
2497 if (!(flags
& MCP_KEY_FREE
)) {
2509 change
->modes_set
|= MODE_UPASS
;
2510 safestrncpy(change
->new_upass
, modes
[in_arg
++], sizeof(change
->new_upass
));
2512 change
->modes_clear
|= MODE_UPASS
;
2513 if (!(flags
& MCP_UPASS_FREE
)) {
2524 change
->modes_set
|= MODE_APASS
;
2525 safestrncpy(change
->new_apass
, modes
[in_arg
++], sizeof(change
->new_apass
));
2527 change
->modes_clear
|= MODE_APASS
;
2528 if (!(flags
& MCP_APASS_FREE
)) {
2536 if (!(flags
& MCP_ALLOW_OVB
))
2540 change
->args
[ch_arg
].mode
= MODE_BAN
;
2542 change
->args
[ch_arg
].mode
|= MODE_REMOVE
;
2543 change
->args
[ch_arg
++].u
.hostmask
= modes
[in_arg
++];
2546 if (!(flags
& MCP_ALLOW_OVB
))
2550 change
->args
[ch_arg
].mode
= MODE_EXEMPT
;
2552 change
->args
[ch_arg
].mode
|= MODE_REMOVE
;
2553 change
->args
[ch_arg
++].u
.hostmask
= modes
[in_arg
++];
2555 case 'o': case 'h': case 'v':
2557 struct userNode
*victim
;
2563 oplevel_str
= strchr(modes
[in_arg
], ':');
2566 /* XXYYY M #channel +o XXYYY:<oplevel> */
2567 *oplevel_str
++ = '\0';
2568 oplevel
= parse_oplevel(oplevel_str
);
2569 if (oplevel
<= base_oplevel
&& !(flags
& MCP_FROM_SERVER
))
2570 oplevel
= base_oplevel
+ 1;
2572 else if (channel
->modes
& MODE_UPASS
)
2573 oplevel
= base_oplevel
+ 1;
2577 /* Check that oplevel is within bounds. */
2578 if (oplevel
> MAXOPLEVEL
)
2579 oplevel
= MAXOPLEVEL
;
2581 if (!(flags
& MCP_ALLOW_OVB
))
2586 if (modes
[0][ii
] == 'o')
2587 change
->args
[ch_arg
].mode
= MODE_CHANOP
;
2588 else if (modes
[0][ii
] == 'h')
2589 change
->args
[ch_arg
].mode
= MODE_HALFOP
;
2590 else if (modes
[0][ii
] == 'v')
2591 change
->args
[ch_arg
].mode
= MODE_VOICE
;
2594 change
->args
[ch_arg
].mode
|= MODE_REMOVE
;
2595 if (flags
& MCP_FROM_SERVER
)
2596 victim
= GetUserN(modes
[in_arg
++]);
2598 victim
= GetUserH(modes
[in_arg
++]);
2601 if ((change
->args
[ch_arg
].u
.member
= GetUserMode(channel
, victim
)))
2603 /* Apply the oplevel change */
2604 change
->args
[ch_arg
].u
.member
->oplevel
= oplevel
;
2610 if (!(flags
& MCP_FROM_SERVER
))
2615 change
->argc
= ch_arg
; /* in case any turned out to be ignored */
2616 if (change
->modes_set
& MODE_SECRET
) {
2617 change
->modes_set
&= ~(MODE_PRIVATE
);
2618 change
->modes_clear
|= MODE_PRIVATE
;
2619 } else if (change
->modes_set
& MODE_PRIVATE
) {
2620 change
->modes_set
&= ~(MODE_SECRET
);
2621 change
->modes_clear
|= MODE_SECRET
;
2625 mod_chanmode_free(change
);
2629 struct chanmode_buffer
{
2632 struct chanNode
*channel
;
2633 struct userNode
*actor
;
2634 unsigned int modes_used
;
2635 unsigned int args_used
;
2637 unsigned int is_add
: 1;
2638 unsigned int is_chanop
: 1;
2642 mod_chanmode_append(struct chanmode_buffer
*buf
, char ch
, const char *arg
)
2644 size_t arg_len
= strlen(arg
);
2645 if (buf
->modes_used
> (MAXMODEPARAMS
) ||
2646 buf
->modes_used
+ buf
->args_used
+ buf
->chname_len
+ arg_len
> 450) {
2647 memcpy(buf
->modes
+ buf
->modes_used
, buf
->args
, buf
->args_used
);
2648 buf
->modes
[buf
->modes_used
+ buf
->args_used
] = '\0';
2649 irc_mode((buf
->is_chanop
? buf
->actor
: NULL
), buf
->channel
, buf
->modes
);
2650 buf
->modes
[0] = buf
->is_add
? '+' : '-';
2651 buf
->modes_used
= 1;
2654 buf
->modes
[buf
->modes_used
++] = ch
;
2655 buf
->args
[buf
->args_used
++] = ' ';
2656 memcpy(buf
->args
+ buf
->args_used
, arg
, arg_len
);
2657 buf
->args_used
+= arg_len
;
2661 mod_chanmode_announce(struct userNode
*who
, struct chanNode
*channel
, struct mod_chanmode
*change
)
2663 struct chanmode_buffer chbuf
;
2665 struct modeNode
*mn
;
2666 char int_buff
[32], mode
= '\0';
2668 assert(change
->argc
<= change
->alloc_argc
);
2669 memset(&chbuf
, 0, sizeof(chbuf
));
2670 chbuf
.channel
= channel
;
2672 chbuf
.chname_len
= strlen(channel
->name
);
2674 mn
= GetUserMode(channel
, who
);
2675 if ((mn
&& (mn
->modes
& MODE_CHANOP
)) || off_channel
)
2676 chbuf
.is_chanop
= 1;
2678 /* First remove modes */
2680 if (change
->modes_clear
) {
2682 chbuf
.modes
[chbuf
.modes_used
++] = mode
= '-';
2683 #define DO_MODE_CHAR(BIT, CHAR) if (change->modes_clear & MODE_##BIT) chbuf.modes[chbuf.modes_used++] = CHAR
2684 DO_MODE_CHAR(PRIVATE
, 'p');
2685 DO_MODE_CHAR(SECRET
, 's');
2686 DO_MODE_CHAR(MODERATED
, 'm');
2687 DO_MODE_CHAR(TOPICLIMIT
, 't');
2688 DO_MODE_CHAR(INVITEONLY
, 'i');
2689 DO_MODE_CHAR(NOPRIVMSGS
, 'n');
2690 DO_MODE_CHAR(LIMIT
, 'l');
2691 DO_MODE_CHAR(DELAYJOINS
, 'D');
2692 DO_MODE_CHAR(REGONLY
, 'r');
2693 DO_MODE_CHAR(NOCOLORS
, 'c');
2694 DO_MODE_CHAR(NOCTCPS
, 'C');
2695 DO_MODE_CHAR(STRIPCOLOR
, 'S');
2696 DO_MODE_CHAR(MODUNREG
, 'M');
2697 DO_MODE_CHAR(NONOTICE
, 'N');
2698 DO_MODE_CHAR(NOQUITMSGS
, 'Q');
2699 DO_MODE_CHAR(NOAMSG
, 'T');
2700 DO_MODE_CHAR(OPERSONLY
, 'O');
2701 DO_MODE_CHAR(REGISTERED
, 'z');
2702 DO_MODE_CHAR(SSLONLY
, 'Z');
2703 DO_MODE_CHAR(HIDEMODE
, 'L');
2705 if (change
->modes_clear
& channel
->modes
& MODE_KEY
)
2706 mod_chanmode_append(&chbuf
, 'k', channel
->key
);
2707 if (change
->modes_clear
& channel
->modes
& MODE_UPASS
)
2708 mod_chanmode_append(&chbuf
, 'U', channel
->upass
);
2709 if (change
->modes_clear
* channel
->modes
& MODE_APASS
)
2710 mod_chanmode_append(&chbuf
, 'A', channel
->apass
);
2712 for (arg
= 0; arg
< change
->argc
; ++arg
) {
2713 if (!(change
->args
[arg
].mode
& MODE_REMOVE
))
2716 chbuf
.modes
[chbuf
.modes_used
++] = mode
= '-';
2717 switch (change
->args
[arg
].mode
& ~MODE_REMOVE
) {
2719 mod_chanmode_append(&chbuf
, 'b', change
->args
[arg
].u
.hostmask
);
2722 mod_chanmode_append(&chbuf
, 'e', change
->args
[arg
].u
.hostmask
);
2725 if (change
->args
[arg
].mode
& MODE_CHANOP
)
2726 mod_chanmode_append(&chbuf
, 'o', change
->args
[arg
].u
.member
->user
->numeric
);
2727 if (change
->args
[arg
].mode
& MODE_HALFOP
)
2728 mod_chanmode_append(&chbuf
, 'h', change
->args
[arg
].u
.member
->user
->numeric
);
2729 if (change
->args
[arg
].mode
& MODE_VOICE
)
2730 mod_chanmode_append(&chbuf
, 'v', change
->args
[arg
].u
.member
->user
->numeric
);
2737 if (change
->modes_set
) {
2739 chbuf
.modes
[chbuf
.modes_used
++] = mode
= '+';
2740 #define DO_MODE_CHAR(BIT, CHAR) if (change->modes_set & MODE_##BIT) chbuf.modes[chbuf.modes_used++] = CHAR
2741 DO_MODE_CHAR(PRIVATE
, 'p');
2742 DO_MODE_CHAR(SECRET
, 's');
2743 DO_MODE_CHAR(MODERATED
, 'm');
2744 DO_MODE_CHAR(TOPICLIMIT
, 't');
2745 DO_MODE_CHAR(INVITEONLY
, 'i');
2746 DO_MODE_CHAR(NOPRIVMSGS
, 'n');
2747 DO_MODE_CHAR(DELAYJOINS
, 'D');
2748 DO_MODE_CHAR(REGONLY
, 'r');
2749 DO_MODE_CHAR(NOCOLORS
, 'c');
2750 DO_MODE_CHAR(NOCTCPS
, 'C');
2751 DO_MODE_CHAR(STRIPCOLOR
, 'S');
2752 DO_MODE_CHAR(MODUNREG
, 'M');
2753 DO_MODE_CHAR(NONOTICE
, 'N');
2754 DO_MODE_CHAR(NOQUITMSGS
, 'Q');
2755 DO_MODE_CHAR(NOAMSG
, 'T');
2756 DO_MODE_CHAR(OPERSONLY
, 'O');
2757 DO_MODE_CHAR(REGISTERED
, 'z');
2758 DO_MODE_CHAR(SSLONLY
, 'Z');
2759 DO_MODE_CHAR(HIDEMODE
, 'L');
2761 if(change
->modes_set
& MODE_KEY
)
2762 mod_chanmode_append(&chbuf
, 'k', change
->new_key
);
2763 if (change
->modes_set
& MODE_UPASS
)
2764 mod_chanmode_append(&chbuf
, 'U', change
->new_upass
);
2765 if (change
->modes_set
& MODE_APASS
)
2766 mod_chanmode_append(&chbuf
, 'A', change
->new_apass
);
2767 if(change
->modes_set
& MODE_LIMIT
) {
2768 sprintf(int_buff
, "%d", change
->new_limit
);
2769 mod_chanmode_append(&chbuf
, 'l', int_buff
);
2772 for (arg
= 0; arg
< change
->argc
; ++arg
) {
2773 if (change
->args
[arg
].mode
& MODE_REMOVE
)
2776 chbuf
.modes
[chbuf
.modes_used
++] = mode
= '+';
2777 switch (change
->args
[arg
].mode
) {
2779 mod_chanmode_append(&chbuf
, 'b', change
->args
[arg
].u
.hostmask
);
2782 mod_chanmode_append(&chbuf
, 'e', change
->args
[arg
].u
.hostmask
);
2785 if (change
->args
[arg
].mode
& MODE_CHANOP
)
2786 mod_chanmode_append(&chbuf
, 'o', change
->args
[arg
].u
.member
->user
->numeric
);
2787 if (change
->args
[arg
].mode
& MODE_HALFOP
)
2788 mod_chanmode_append(&chbuf
, 'h', change
->args
[arg
].u
.member
->user
->numeric
);
2789 if (change
->args
[arg
].mode
& MODE_VOICE
)
2790 mod_chanmode_append(&chbuf
, 'v', change
->args
[arg
].u
.member
->user
->numeric
);
2795 /* Flush the buffer and apply changes locally */
2796 if (chbuf
.modes_used
> 0) {
2797 memcpy(chbuf
.modes
+ chbuf
.modes_used
, chbuf
.args
, chbuf
.args_used
);
2798 chbuf
.modes
[chbuf
.modes_used
+ chbuf
.args_used
] = '\0';
2799 irc_mode((chbuf
.is_chanop
? chbuf
.actor
: NULL
), chbuf
.channel
, chbuf
.modes
);
2801 mod_chanmode_apply(who
, channel
, change
);
2805 mod_chanmode_format(struct mod_chanmode
*change
, char *outbuff
)
2807 unsigned int used
= 0;
2808 assert(change
->argc
<= change
->alloc_argc
);
2809 if (change
->modes_clear
) {
2810 outbuff
[used
++] = '-';
2811 #define DO_MODE_CHAR(BIT, CHAR) if (change->modes_clear & MODE_##BIT) outbuff[used++] = CHAR
2812 DO_MODE_CHAR(PRIVATE
, 'p');
2813 DO_MODE_CHAR(SECRET
, 's');
2814 DO_MODE_CHAR(MODERATED
, 'm');
2815 DO_MODE_CHAR(TOPICLIMIT
, 't');
2816 DO_MODE_CHAR(INVITEONLY
, 'i');
2817 DO_MODE_CHAR(NOPRIVMSGS
, 'n');
2818 DO_MODE_CHAR(LIMIT
, 'l');
2819 DO_MODE_CHAR(KEY
, 'k');
2820 DO_MODE_CHAR(UPASS
, 'U');
2821 DO_MODE_CHAR(APASS
, 'A');
2822 DO_MODE_CHAR(DELAYJOINS
, 'D');
2823 DO_MODE_CHAR(REGONLY
, 'r');
2824 DO_MODE_CHAR(NOCOLORS
, 'c');
2825 DO_MODE_CHAR(NOCTCPS
, 'C');
2826 DO_MODE_CHAR(STRIPCOLOR
, 'S');
2827 DO_MODE_CHAR(MODUNREG
, 'M');
2828 DO_MODE_CHAR(NONOTICE
, 'N');
2829 DO_MODE_CHAR(NOQUITMSGS
, 'Q');
2830 DO_MODE_CHAR(NOAMSG
, 'T');
2831 DO_MODE_CHAR(OPERSONLY
, 'O');
2832 DO_MODE_CHAR(REGISTERED
, 'z');
2833 DO_MODE_CHAR(SSLONLY
, 'Z');
2834 DO_MODE_CHAR(HIDEMODE
, 'L');
2837 if (change
->modes_set
) {
2838 outbuff
[used
++] = '+';
2839 #define DO_MODE_CHAR(BIT, CHAR) if (change->modes_set & MODE_##BIT) outbuff[used++] = CHAR
2840 DO_MODE_CHAR(PRIVATE
, 'p');
2841 DO_MODE_CHAR(SECRET
, 's');
2842 DO_MODE_CHAR(MODERATED
, 'm');
2843 DO_MODE_CHAR(TOPICLIMIT
, 't');
2844 DO_MODE_CHAR(INVITEONLY
, 'i');
2845 DO_MODE_CHAR(NOPRIVMSGS
, 'n');
2846 DO_MODE_CHAR(DELAYJOINS
, 'D');
2847 DO_MODE_CHAR(REGONLY
, 'r');
2848 DO_MODE_CHAR(NOCOLORS
, 'c');
2849 DO_MODE_CHAR(NOCTCPS
, 'C');
2850 DO_MODE_CHAR(STRIPCOLOR
, 'S');
2851 DO_MODE_CHAR(MODUNREG
, 'M');
2852 DO_MODE_CHAR(NONOTICE
, 'N');
2853 DO_MODE_CHAR(NOQUITMSGS
, 'Q');
2854 DO_MODE_CHAR(NOAMSG
, 'T');
2855 DO_MODE_CHAR(OPERSONLY
, 'O');
2856 DO_MODE_CHAR(REGISTERED
, 'z');
2857 DO_MODE_CHAR(SSLONLY
, 'Z');
2858 DO_MODE_CHAR(HIDEMODE
, 'L');
2860 switch (change
->modes_set
& (MODE_KEY
|MODE_LIMIT
|MODE_APASS
|MODE_UPASS
)) {
2861 /* Doing this implementation has been a pain in the arse, I hope I didn't forget a possible combination */
2862 case MODE_KEY
|MODE_LIMIT
|MODE_APASS
|MODE_UPASS
:
2863 used
+= sprintf(outbuff
+used
, "lkAU %d %s %s %s", change
->new_limit
, change
->new_key
,change
->new_apass
, change
->new_upass
);
2866 case MODE_KEY
|MODE_LIMIT
|MODE_APASS
:
2867 used
+= sprintf(outbuff
+used
, "lkA %d %s %s", change
->new_limit
, change
->new_key
, change
->new_apass
);
2869 case MODE_KEY
|MODE_LIMIT
|MODE_UPASS
:
2870 used
+= sprintf(outbuff
+used
, "lkU %d %s %s", change
->new_limit
, change
->new_key
, change
->new_upass
);
2872 case MODE_KEY
|MODE_APASS
|MODE_UPASS
:
2873 used
+= sprintf(outbuff
+used
, "kAU %s %s %s", change
->new_key
, change
->new_apass
, change
->new_upass
);
2876 case MODE_KEY
|MODE_APASS
:
2877 used
+= sprintf(outbuff
+used
, "kA %s %s", change
->new_key
, change
->new_apass
);
2879 case MODE_KEY
|MODE_UPASS
:
2880 used
+= sprintf(outbuff
+used
, "kU %s %s", change
->new_key
, change
->new_upass
);
2882 case MODE_KEY
|MODE_LIMIT
:
2883 used
+= sprintf(outbuff
+used
, "lk %d %s", change
->new_limit
, change
->new_key
);
2886 case MODE_LIMIT
|MODE_UPASS
:
2887 used
+= sprintf(outbuff
+used
, "lU %d %s", change
->new_limit
, change
->new_upass
);
2889 case MODE_LIMIT
|MODE_APASS
:
2890 used
+= sprintf(outbuff
+used
, "lA %d %s", change
->new_limit
, change
->new_apass
);
2892 case MODE_APASS
|MODE_UPASS
:
2893 used
+= sprintf(outbuff
+used
, "AU %s %s", change
->new_apass
, change
->new_upass
);
2895 case MODE_LIMIT
|MODE_APASS
|MODE_UPASS
:
2896 used
+= sprintf(outbuff
+used
, "lAU %d %s %s", change
->new_limit
, change
->new_apass
, change
->new_upass
);
2900 used
+= sprintf(outbuff
+used
, "A %s", change
->new_apass
);
2903 used
+= sprintf(outbuff
+used
, "U %s", change
->new_upass
);
2906 used
+= sprintf(outbuff
+used
, "k %s", change
->new_key
);
2909 used
+= sprintf(outbuff
+used
, "l %d", change
->new_limit
);
2918 clear_chanmode(struct chanNode
*channel
, const char *modes
)
2920 unsigned int remove
;
2922 for (remove
= 0; *modes
; modes
++) {
2924 case 'o': remove
|= MODE_CHANOP
; break;
2925 case 'h': remove
|= MODE_HALFOP
; break;
2926 case 'v': remove
|= MODE_VOICE
; break;
2927 case 'p': remove
|= MODE_PRIVATE
; break;
2928 case 's': remove
|= MODE_SECRET
; break;
2929 case 'm': remove
|= MODE_MODERATED
; break;
2930 case 't': remove
|= MODE_TOPICLIMIT
; break;
2931 case 'i': remove
|= MODE_INVITEONLY
; break;
2932 case 'n': remove
|= MODE_NOPRIVMSGS
; break;
2935 channel
->key
[0] = '\0';
2938 remove
|= MODE_APASS
;
2939 channel
->apass
[0] = '\0';
2942 remove
|= MODE_UPASS
;
2943 channel
->upass
[0] = '\0';
2946 remove
|= MODE_LIMIT
;
2949 case 'b': remove
|= MODE_BAN
; break;
2950 case 'e': remove
|= MODE_EXEMPT
; break;
2951 case 'D': remove
|= MODE_DELAYJOINS
; break;
2952 case 'r': remove
|= MODE_REGONLY
; break;
2953 case 'c': remove
|= MODE_NOCOLORS
; break;
2954 case 'C': remove
|= MODE_NOCTCPS
; break;
2955 case 'S': remove
|= MODE_STRIPCOLOR
; break;
2956 case 'M': remove
|= MODE_MODUNREG
; break;
2957 case 'N': remove
|= MODE_NONOTICE
; break;
2958 case 'Q': remove
|= MODE_NOQUITMSGS
; break;
2959 case 'T': remove
|= MODE_NOAMSG
; break;
2960 case 'O': remove
|= MODE_OPERSONLY
; break;
2961 case 'z': remove
|= MODE_REGISTERED
; break;
2962 case 'Z': remove
|= MODE_SSLONLY
; break;
2963 case 'L': remove
|= MODE_HIDEMODE
; break;
2970 /* Remove simple modes. */
2971 channel
->modes
&= ~remove
;
2973 /* If removing bans, kill 'em all. */
2974 if ((remove
& MODE_BAN
) && channel
->banlist
.used
) {
2976 for (i
=0; i
<channel
->banlist
.used
; i
++)
2977 free(channel
->banlist
.list
[i
]);
2978 channel
->banlist
.used
= 0;
2981 /* If removing exempts, kill 'em all. */
2982 if ((remove
& MODE_EXEMPT
) && channel
->exemptlist
.used
) {
2984 for (i
=0; i
<channel
->exemptlist
.used
; i
++)
2985 free(channel
->exemptlist
.list
[i
]);
2986 channel
->exemptlist
.used
= 0;
2989 /* Remove member modes. */
2990 if ((remove
& (MODE_CHANOP
| MODE_HALFOP
| MODE_VOICE
)) && channel
->members
.used
) {
2991 int mask
= ~(remove
& (MODE_CHANOP
| MODE_HALFOP
| MODE_VOICE
));
2994 for (i
= 0; i
< channel
->members
.used
; i
++)
2995 channel
->members
.list
[i
]->modes
&= mask
;
3002 reg_privmsg_func(struct userNode
*user
, privmsg_func_t handler
)
3004 unsigned int numeric
= user
->num_local
;
3005 if (numeric
>= num_privmsg_funcs
) {
3006 int newnum
= numeric
+ 8;
3007 privmsg_funcs
= realloc(privmsg_funcs
, newnum
*sizeof(privmsg_func_t
));
3008 memset(privmsg_funcs
+num_privmsg_funcs
, 0, (newnum
-num_privmsg_funcs
)*sizeof(privmsg_func_t
));
3009 num_privmsg_funcs
= newnum
;
3011 if (privmsg_funcs
[numeric
])
3012 log_module(MAIN_LOG
, LOG_WARNING
, "re-registering new privmsg handler for numeric %d", numeric
);
3013 privmsg_funcs
[numeric
] = handler
;
3017 unreg_privmsg_func(struct userNode
*user
, privmsg_func_t handler
)
3021 if (!user
|| handler
)
3022 return; /* this really only works with users */
3024 memset(privmsg_funcs
+user
->num_local
, 0, sizeof(privmsg_func_t
));
3026 for (x
= user
->num_local
+1; x
< num_privmsg_funcs
; x
++)
3027 memmove(privmsg_funcs
+x
-1, privmsg_funcs
+x
, sizeof(privmsg_func_t
));
3029 privmsg_funcs
= realloc(privmsg_funcs
, num_privmsg_funcs
*sizeof(privmsg_func_t
));
3030 num_privmsg_funcs
--;
3035 reg_notice_func(struct userNode
*user
, privmsg_func_t handler
)
3037 unsigned int numeric
= user
->num_local
;
3038 if (numeric
>= num_notice_funcs
) {
3039 int newnum
= numeric
+ 8;
3040 notice_funcs
= realloc(notice_funcs
, newnum
*sizeof(privmsg_func_t
));
3041 memset(notice_funcs
+num_notice_funcs
, 0, (newnum
-num_notice_funcs
)*sizeof(privmsg_func_t
));
3042 num_notice_funcs
= newnum
;
3044 if (notice_funcs
[numeric
])
3045 log_module(MAIN_LOG
, LOG_WARNING
, "re-registering new notice handler for numeric %d", numeric
);
3046 notice_funcs
[numeric
] = handler
;
3050 unreg_notice_func(struct userNode
*user
, privmsg_func_t handler
)
3054 if (!user
|| handler
)
3055 return; /* this really only works with users */
3057 memset(notice_funcs
+user
->num_local
, 0, sizeof(privmsg_func_t
));
3059 for (x
= user
->num_local
+1; x
< num_notice_funcs
; x
++)
3060 memmove(notice_funcs
+x
-1, notice_funcs
+x
, sizeof(privmsg_func_t
));
3062 memset(notice_funcs
+user
->num_local
, 0, sizeof(privmsg_func_t
));
3063 notice_funcs
= realloc(notice_funcs
, num_notice_funcs
*sizeof(privmsg_func_t
));
3068 reg_oper_func(oper_func_t handler
)
3070 if (of_used
== of_size
) {
3073 of_list
= realloc(of_list
, of_size
*sizeof(oper_func_t
));
3076 of_list
= malloc(of_size
*sizeof(oper_func_t
));
3079 of_list
[of_used
++] = handler
;
3083 call_oper_funcs(struct userNode
*user
)
3088 for (n
=0; n
<of_used
; n
++)
3095 unsigned int i
, hop
, max_hop
=1;
3098 /* burst (juped) servers, closest first (except self, which is sent already) */
3099 for (i
=0; i
<ArrayLength(servers_num
); i
++)
3100 if (servers_num
[i
] && servers_num
[i
]->hops
> max_hop
)
3101 max_hop
= servers_num
[i
]->hops
;
3102 for (hop
=1; hop
<=max_hop
; hop
++) {
3103 for (i
=0;i
<ArrayLength(servers_num
);i
++) {
3105 && (servers_num
[i
]->hops
== hop
)
3106 && (servers_num
[i
] != self
->uplink
))
3107 irc_server(servers_num
[i
]);
3111 /* burst local nicks */
3112 for (i
=0; i
<=self
->num_mask
; i
++)
3114 irc_user(self
->users
[i
]);
3116 /* build dict of unbursted channel names (just copy existing channels) */
3117 unbursted_channels
= dict_new();
3118 for (it
= dict_first(channels
); it
; it
= iter_next(it
))
3119 dict_insert(unbursted_channels
, iter_key(it
), iter_data(it
));
3126 parse_oplevel(char *str
)
3129 while (isdigit(*str
))
3130 oplevel
= oplevel
* 10 + *str
++ - '0';