1 /* proto-p10.c - IRC protocol output
2 * Copyright 2000-2004 srvx Development Team
4 * This file is part of srvx.
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.
21 #include "proto-common.c"
24 #define CMD_ACCOUNT "ACCOUNT"
25 #define CMD_ADMIN "ADMIN"
26 #define CMD_ASLL "ASLL"
27 #define CMD_AWAY "AWAY"
28 #define CMD_BURST "BURST"
29 #define CMD_CLEARMODE "CLEARMODE"
30 #define CMD_CLOSE "CLOSE"
31 #define CMD_CNOTICE "CNOTICE"
32 #define CMD_CONNECT "CONNECT"
33 #define CMD_CPRIVMSG "CPRIVMSG"
34 #define CMD_CREATE "CREATE"
35 #define CMD_DESTRUCT "DESTRUCT"
36 #define CMD_DESYNCH "DESYNCH"
39 #define CMD_EOB "END_OF_BURST"
40 #define CMD_EOB_ACK "EOB_ACK"
41 #define CMD_ERROR "ERROR"
43 #define CMD_GLINE "GLINE"
44 #define CMD_HASH "HASH"
45 #define CMD_HELP "HELP"
46 #define CMD_INFO "INFO"
47 #define CMD_INVITE "INVITE"
48 #define CMD_ISON "ISON"
49 #define CMD_JOIN "JOIN"
50 #define CMD_JUPE "JUPE"
51 #define CMD_KICK "KICK"
52 #define CMD_KILL "KILL"
53 #define CMD_LINKS "LINKS"
54 #define CMD_LIST "LIST"
55 #define CMD_LUSERS "LUSERS"
57 #define CMD_MODE "MODE"
58 #define CMD_MOTD "MOTD"
59 #define CMD_NAMES "NAMES"
60 #define CMD_NICK "NICK"
61 #define CMD_NOTICE "NOTICE"
62 #define CMD_OPER "OPER"
63 #define CMD_OPMODE "OPMODE"
64 #define CMD_PART "PART"
65 #define CMD_PASS "PASS"
66 #define CMD_PING "PING"
67 #define CMD_PONG "PONG"
68 #define CMD_POST "POST"
69 #define CMD_PRIVMSG "PRIVMSG"
70 #define CMD_PRIVS "PRIVS"
71 #define CMD_PROTO "PROTO"
72 #define CMD_QUIT "QUIT"
73 #define CMD_REHASH "REHASH"
74 #define CMD_RESET "RESET"
75 #define CMD_RESTART "RESTART"
76 #define CMD_RPING "RPING"
77 #define CMD_RPONG "RPONG"
78 #define CMD_SERVER "SERVER"
79 #define CMD_SERVLIST "SERVLIST"
80 #define CMD_SERVSET "SERVSET"
82 #define CMD_SETTIME "SETTIME"
83 #define CMD_SILENCE "SILENCE"
84 #define CMD_SQUERY "SQUERY"
85 #define CMD_SQUIT "SQUIT"
86 #define CMD_STATS "STATS"
87 #define CMD_SVSNICK "SVSNICK"
88 #define CMD_TIME "TIME"
89 #define CMD_TOPIC "TOPIC"
90 #define CMD_TRACE "TRACE"
91 #define CMD_UPING "UPING"
92 #define CMD_USER "USER"
93 #define CMD_USERHOST "USERHOST"
94 #define CMD_USERIP "USERIP"
95 #define CMD_VERSION "VERSION"
96 #define CMD_WALLCHOPS "WALLCHOPS"
97 #define CMD_WALLOPS "WALLOPS"
98 #define CMD_WALLUSERS "WALLUSERS"
99 #define CMD_WALLVOICES "WALLVOICES"
100 #define CMD_WHO "WHO"
101 #define CMD_WHOIS "WHOIS"
102 #define CMD_WHOWAS "WHOWAS"
104 /* Tokenized commands. */
105 #define TOK_ACCOUNT "AC"
106 #define TOK_ADMIN "AD"
107 #define TOK_ASLL "LL"
109 #define TOK_BURST "B"
110 #define TOK_CLEARMODE "CM"
111 #define TOK_CLOSE "CLOSE"
112 #define TOK_CNOTICE "CN"
113 #define TOK_CONNECT "CO"
114 #define TOK_CPRIVMSG "CP"
115 #define TOK_CREATE "C"
116 #define TOK_DESTRUCT "DE"
117 #define TOK_DESYNCH "DS"
118 #define TOK_DIE "DIE"
119 #define TOK_DNS "DNS"
121 #define TOK_EOB_ACK "EA"
122 #define TOK_ERROR "Y"
123 #define TOK_GET "GET"
124 #define TOK_GLINE "GL"
125 #define TOK_HASH "HASH"
126 #define TOK_HELP "HELP"
128 #define TOK_INVITE "I"
129 #define TOK_ISON "ISON"
131 #define TOK_JUPE "JU"
134 #define TOK_LINKS "LI"
135 #define TOK_LIST "LIST"
136 #define TOK_LUSERS "LU"
137 #define TOK_MAP "MAP"
139 #define TOK_MOTD "MO"
140 #define TOK_NAMES "E"
142 #define TOK_NOTICE "O"
143 #define TOK_OPER "OPER"
144 #define TOK_OPMODE "OM"
146 #define TOK_PASS "PA"
149 #define TOK_POST "POST"
150 #define TOK_PRIVMSG "P"
151 #define TOK_PRIVS "PRIVS"
152 #define TOK_PROTO "PROTO"
154 #define TOK_REHASH "REHASH"
155 #define TOK_RESET "RESET"
156 #define TOK_RESTART "RESTART"
157 #define TOK_RPING "RI"
158 #define TOK_RPONG "RO"
159 #define TOK_SERVER "S"
160 #define TOK_SERVLIST "SERVSET"
161 #define TOK_SERVSET "SERVSET"
162 #define TOK_SET "SET"
163 #define TOK_SETTIME "SE"
164 #define TOK_SILENCE "U"
165 #define TOK_SQUERY "SQUERY"
166 #define TOK_SQUIT "SQ"
167 #define TOK_STATS "R"
168 #define TOK_SVSNICK "SN"
169 #define TOK_TIME "TI"
170 #define TOK_TOPIC "T"
171 #define TOK_TRACE "TR"
172 #define TOK_UPING "UP"
173 #define TOK_USER "USER"
174 #define TOK_USERHOST "USERHOST"
175 #define TOK_USERIP "USERIP"
176 #define TOK_VERSION "V"
177 #define TOK_WALLCHOPS "WC"
178 #define TOK_WALLOPS "WA"
179 #define TOK_WALLUSERS "WU"
180 #define TOK_WALLVOICES "WV"
182 #define TOK_WHOIS "W"
183 #define TOK_WHOWAS "X"
185 /* Protocol messages; aliased to full commands or tokens depending
186 on compile-time configuration. ircu prefers tokens WITH THE
187 EXCEPTION OF THE SERVER AND PASS COMMANDS, which cannot be
188 tokenized, because clients' (ie. a linking server) commands are
189 only checked against the full command list.
191 #if defined(ENABLE_TOKENS)
192 #define TYPE(NAME) TOK_ ## NAME
193 #else /* !ENABLE_TOKENS */
194 #define TYPE(NAME) CMD_ ## NAME
195 #endif /* ENABLE_TOKENS */
197 #define P10_ACCOUNT TYPE(ACCOUNT)
198 #define P10_ADMIN TYPE(ADMIN)
199 #define P10_ASLL TYPE(ASLL)
200 #define P10_AWAY TYPE(AWAY)
201 #define P10_BURST TYPE(BURST)
202 #define P10_CLEARMODE TYPE(CLEARMODE)
203 #define P10_CLOSE TYPE(CLOSE)
204 #define P10_CNOTICE TYPE(CNOTICE)
205 #define P10_CONNECT TYPE(CONNECT)
206 #define P10_CPRIVMSG TYPE(CPRIVMSG)
207 #define P10_CREATE TYPE(CREATE)
208 #define P10_DESTRUCT TYPE(DESTRUCT)
209 #define P10_DESYNCH TYPE(DESYNCH)
210 #define P10_DIE TYPE(DIE)
211 #define P10_DNS TYPE(DNS)
212 #define P10_EOB TYPE(EOB)
213 #define P10_EOB_ACK TYPE(EOB_ACK)
214 #define P10_ERROR TYPE(ERROR)
215 #define P10_GET TYPE(GET)
216 #define P10_GLINE TYPE(GLINE)
217 #define P10_HASH TYPE(HASH)
218 #define P10_HELP TYPE(HELP)
219 #define P10_INFO TYPE(INFO)
220 #define P10_INVITE TYPE(INVITE)
221 #define P10_ISON TYPE(ISON)
222 #define P10_JOIN TYPE(JOIN)
223 #define P10_JUPE TYPE(JUPE)
224 #define P10_KICK TYPE(KICK)
225 #define P10_KILL TYPE(KILL)
226 #define P10_LINKS TYPE(LINKS)
227 #define P10_LIST TYPE(LIST)
228 #define P10_LUSERS TYPE(LUSERS)
229 #define P10_MAP TYPE(MAP)
230 #define P10_MODE TYPE(MODE)
231 #define P10_MOTD TYPE(MOTD)
232 #define P10_NAMES TYPE(NAMES)
233 #define P10_NICK TYPE(NICK)
234 #define P10_NOTICE TYPE(NOTICE)
235 #define P10_OPER TYPE(OPER)
236 #define P10_OPMODE TYPE(OPMODE)
237 #define P10_PART TYPE(PART)
238 #define P10_PASS CMD_PASS
239 #define P10_PING TYPE(PING)
240 #define P10_PONG TYPE(PONG)
241 #define P10_POST TYPE(POST)
242 #define P10_PRIVMSG TYPE(PRIVMSG)
243 #define P10_PRIVS TYPE(PRIVS)
244 #define P10_PROTO TYPE(PROTO)
245 #define P10_QUIT TYPE(QUIT)
246 #define P10_REHASH TYPE(REHASH)
247 #define P10_RESET TYPE(RESET)
248 #define P10_RESTART TYPE(RESTART)
249 #define P10_RPING TYPE(RPING)
250 #define P10_RPONG TYPE(RPONG)
251 #define P10_SERVER CMD_SERVER
252 #define P10_SERVLIST TYPE(SERVLIST)
253 #define P10_SERVSET TYPE(SERVSET)
254 #define P10_SET TYPE(SET)
255 #define P10_SETTIME TYPE(SETTIME)
256 #define P10_SILENCE TYPE(SILENCE)
257 #define P10_SQUERY TYPE(SQUERY)
258 #define P10_SQUIT TYPE(SQUIT)
259 #define P10_STATS TYPE(STATS)
260 #define P10_SVSNICK TYPE(SVSNICK)
261 #define P10_TIME TYPE(TIME)
262 #define P10_TOPIC TYPE(TOPIC)
263 #define P10_TRACE TYPE(TRACE)
264 #define P10_UPING TYPE(UPING)
265 #define P10_USER TYPE(USER)
266 #define P10_USERHOST TYPE(USERHOST)
267 #define P10_USERIP TYPE(USERIP)
268 #define P10_VERSION TYPE(VERSION)
269 #define P10_WALLCHOPS TYPE(WALLCHOPS)
270 #define P10_WALLOPS TYPE(WALLOPS)
271 #define P10_WALLUSERS TYPE(WALLUSERS)
272 #define P10_WALLVOICES TYPE(WALLVOICES)
273 #define P10_WHO TYPE(WHO)
274 #define P10_WHOIS TYPE(WHOIS)
275 #define P10_WHOWAS TYPE(WHOWAS)
277 /* Servers claiming to have a boot or link time before PREHISTORY
278 * trigger errors to the log. We hope no server has been running
279 * constantly since September 1994. :)
281 #define PREHISTORY 780000000
283 static struct server *servers_num[64*64];
284 static privmsg_func_t *privmsg_funcs;
285 static unsigned int num_privmsg_funcs;
286 static privmsg_func_t *notice_funcs;
287 static unsigned int num_notice_funcs;
288 static struct dict *unbursted_channels;
290 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);
292 /* Numerics can be XYY, XYYY, or XXYYY; with X's identifying the
293 * server and Y's indentifying the client on that server. */
295 GetServerN(const char *numeric)
297 switch (strlen(numeric)) {
299 return servers_num[base64toint(numeric, 2)];
303 return servers_num[base64toint(numeric, 1)];
310 GetUserN(const char *numeric) /* using numeric */
316 switch (strlen(numeric)) {
318 log_module(MAIN_LOG, LOG_WARNING, "GetUserN(%s): numeric too long!", numeric);
320 case 5: slen = 2; ulen = 3; break;
321 case 4: slen = 1; ulen = 3; break;
322 case 3: slen = 1; ulen = 2; break;
323 case 2: case 1: case 0:
324 log_module(MAIN_LOG, LOG_WARNING, "GetUserN(%s): numeric too short!", numeric);
327 if (!(s = servers_num[base64toint(numeric, slen)])) {
328 log_module(MAIN_LOG, LOG_WARNING, "GetUserN(%s): couldn't find server (len=%d)!", numeric, slen);
331 n = base64toint(numeric+slen, ulen) & s->num_mask;
332 if (!(un = s->users[n])) {
333 log_module(MAIN_LOG, LOG_WARNING, "GetUserN(%s) couldn't find user!", numeric);
339 privmsg_user_helper(struct userNode *un, void *data)
341 struct privmsg_desc *pd = data;
342 unsigned int num = un->num_local;
343 if (!pd->is_notice) {
344 if ((num < num_privmsg_funcs) && privmsg_funcs[num]) {
345 privmsg_funcs[num](pd->user, un, pd->text, pd->is_qualified);
348 if ((num < num_notice_funcs) && notice_funcs[num]) {
349 notice_funcs[num](pd->user, un, pd->text, pd->is_qualified);
355 irc_server(struct server *srv)
357 char extranum[COMBO_NUMERIC_LEN+1];
359 inttobase64(extranum, srv->num_mask, (srv->numeric[1] || (srv->num_mask >= 64*64)) ? 3 : 2);
361 /* The +s, ignored by Run's ircu, means "service" to Undernet's ircu */
362 putsock(P10_SERVER " %s %d %li %li J10 %s%s +s :%s",
363 srv->name, srv->hops+1, srv->boot, srv->link, srv->numeric, extranum, srv->description);
365 putsock("%s " P10_SERVER " %s %d %li %li %c10 %s%s +s :%s",
366 self->numeric, srv->name, srv->hops+1, srv->boot, srv->link, (srv->self_burst ? 'J' : 'P'), srv->numeric, extranum, srv->description);
371 irc_user(struct userNode *user)
376 inttobase64(b64ip, ntohl(user->ip.s_addr), 6);
383 modes[modelen++] = 'o';
384 if (IsInvisible(user))
385 modes[modelen++] = 'i';
387 modes[modelen++] = 'w';
389 modes[modelen++] = 'k';
390 if (IsServNotice(user))
391 modes[modelen++] = 's';
393 modes[modelen++] = 'd';
395 modes[modelen++] = 'g';
396 if (IsHelperIrcu(user))
397 modes[modelen++] = 'h';
398 if (IsHiddenHost(user))
399 modes[modelen++] = 'x';
402 /* we don't need to put the + in modes because it's in the format string. */
403 putsock("%s " P10_NICK " %s %d %li %s %s +%s %s %s :%s",
404 user->uplink->numeric, user->nick, user->uplink->hops+1, user->timestamp, user->ident, user->hostname, modes, b64ip, user->numeric, user->info);
406 putsock("%s " P10_NICK " %s %d %li %s %s %s %s :%s",
407 user->uplink->numeric, user->nick, user->uplink->hops+1, user->timestamp, user->ident, user->hostname, b64ip, user->numeric, user->info);
412 irc_account(struct userNode *user, const char *stamp)
414 putsock("%s " P10_ACCOUNT " %s %s", self->numeric, user->numeric, stamp);
418 irc_regnick(UNUSED_ARG(struct userNode *user))
420 /* no operation here */
424 irc_nick(struct userNode *user, UNUSED_ARG(const char *old_nick))
426 putsock("%s " P10_NICK " %s "FMT_TIME_T, user->numeric, user->nick, now);
430 irc_fetchtopic(struct userNode *from, const char *to)
434 putsock("%s " P10_TOPIC " %s", from->numeric, to);
438 irc_squit(struct server *srv, const char *message, const char *service_message)
440 if (!service_message)
441 service_message = message;
443 /* Are we leaving the network? */
444 if (srv == self && cManager.uplink->state == CONNECTED) {
447 /* Quit all clients linked to me. */
448 for (i = 0; i <= self->num_mask; i++) {
451 irc_quit(self->users[i], service_message);
455 putsock("%s " P10_SQUIT " %s %d :%s", self->numeric, srv->name, 0, message);
458 /* Force a reconnect to the currently selected server. */
459 cManager.uplink->tries = 0;
460 log_module(MAIN_LOG, LOG_INFO, "Squitting from uplink: %s", message);
466 irc_wallchops(struct userNode *from, const char *to, const char *message)
468 putsock("%s " P10_WALLCHOPS " %s :%s", from->numeric, to, message);
472 irc_notice(struct userNode *from, const char *to, const char *message)
474 putsock("%s " P10_NOTICE " %s :%s", from->numeric, to, message);
478 irc_notice_user(struct userNode *from, struct userNode *to, const char *message)
480 putsock("%s " P10_NOTICE " %s :%s", from->numeric, to->numeric, message);
484 irc_privmsg(struct userNode *from, const char *to, const char *message)
486 putsock("%s " P10_PRIVMSG " %s :%s", from->numeric, to, message);
492 putsock("%s " P10_EOB, self->numeric);
498 putsock("%s " P10_EOB_ACK, self->numeric);
502 irc_ping(const char *payload)
504 putsock("%s " P10_PING " :%s", self->numeric, payload);
508 irc_pong(const char *who, const char *data)
510 putsock("%s " P10_PONG " %s :%s", self->numeric, who, data);
514 irc_pass(const char *passwd)
516 putsock(P10_PASS " :%s", passwd);
520 irc_introduce(const char *passwd)
522 void timed_send_ping(void *data);
524 self->self_burst = self->burst = 1;
528 timeq_add(now + ping_freq, timed_send_ping, 0);
532 irc_gline(struct server *srv, struct gline *gline)
534 putsock("%s " P10_GLINE " %s +%s %ld :%s",
535 self->numeric, (srv ? srv->numeric : "*"), gline->target, gline->expires-now, gline->reason);
539 irc_settime(const char *srv_name_mask, time_t new_time)
541 ioset_set_time(new_time);
542 if (!strcmp(srv_name_mask, "*"))
544 putsock("%s " P10_SETTIME " " FMT_TIME_T " %s", self->numeric, new_time, srv_name_mask);
548 irc_ungline(const char *mask)
550 putsock("%s " P10_GLINE " * -%s", self->numeric, mask);
554 irc_burst(struct chanNode *chan)
556 char burst_line[512];
557 int pos, base_len, len;
563 if (!chan->members.used)
565 base_len = sprintf(burst_line, "%s " P10_BURST " %s " FMT_TIME_T " ",
566 self->numeric, chan->name, chan->timestamp);
567 len = irc_make_chanmode(chan, burst_line+base_len);
568 pos = base_len + len;
570 burst_line[pos++] = ' ';
573 for (n=0; n<chan->members.used; n++) {
574 mn = chan->members.list[n];
576 burst_line[pos-1] = 0; /* -1 to back up over the space or comma */
577 putsock("%s", burst_line);
581 memcpy(burst_line+pos, mn->user->numeric, strlen(mn->user->numeric));
582 pos += strlen(mn->user->numeric);
583 if (mn->modes && (mn->modes != last_mode)) {
584 last_mode = mn->modes;
585 burst_line[pos++] = ':';
586 if (last_mode & MODE_CHANOP)
587 burst_line[pos++] = 'o';
588 if (last_mode & MODE_VOICE)
589 burst_line[pos++] = 'v';
591 if ((n+1)<chan->members.used)
592 burst_line[pos++] = ',';
594 if (chan->banlist.used) {
596 if (pos+2+strlen(chan->banlist.list[0]->ban) > 505) {
597 burst_line[pos-1] = 0;
598 putsock("%s", burst_line);
601 burst_line[pos++] = ' ';
604 burst_line[pos++] = ':';
605 burst_line[pos++] = '%';
607 for (n=0; n<chan->banlist.used; n++) {
608 bn = chan->banlist.list[n];
609 len = strlen(bn->ban);
610 if (pos+len+1 > 510) {
611 burst_line[pos-1] = 0; /* -1 to back up over the space or comma */
612 putsock("%s", burst_line);
615 memcpy(burst_line+pos, bn->ban, len);
617 burst_line[pos++] = ' ';
620 /* print the last line */
622 putsock("%s", burst_line);
626 irc_quit(struct userNode *user, const char *message)
628 putsock("%s " P10_QUIT " :%s", user->numeric, message);
632 irc_error(const char *to, const char *message)
635 putsock("%s " P10_ERROR " :%s", to, message);
637 putsock(":%s " P10_ERROR " :%s", self->name, message);
642 irc_kill(struct userNode *from, struct userNode *target, const char *message)
645 putsock("%s " P10_KILL " %s :%s!%s (%s)",
646 from->numeric, target->numeric, self->name, from->nick, message);
648 putsock("%s " P10_KILL " %s :%s (%s)",
649 self->numeric, target->numeric, self->name, message);
654 irc_mode(struct userNode *from, struct chanNode *target, const char *modes)
656 putsock("%s " P10_MODE " %s %s "FMT_TIME_T,
657 (from ? from->numeric : self->numeric),
658 target->name, modes, target->timestamp);
662 irc_invite(struct userNode *from, struct userNode *who, struct chanNode *to)
664 putsock("%s " P10_INVITE " %s %s", from->numeric, who->nick, to->name);
668 irc_join(struct userNode *who, struct chanNode *what)
670 if (what->members.used == 1) {
671 putsock("%s " P10_CREATE " %s %lu",
672 who->numeric, what->name, what->timestamp);
674 putsock("%s " P10_JOIN " %s %lu", who->numeric, what->name, what->timestamp);
679 irc_kick(struct userNode *who, struct userNode *target, struct chanNode *channel, const char *msg)
682 struct modeNode *mn = GetUserMode(channel, who);
683 numeric = (mn && (mn->modes & MODE_CHANOP)) ? who->numeric : self->numeric;
684 putsock("%s " P10_KICK " %s %s :%s",
685 numeric, channel->name, target->numeric, msg);
689 irc_stats(struct userNode *from, struct server *target, char type)
691 putsock("%s " P10_STATS " %c :%s", from->numeric, type, target->numeric);
695 irc_svsnick(struct userNode *from, struct userNode *target, const char *newnick)
697 putsock("%s " P10_SVSNICK " %s %s "FMT_TIME_T, from->uplink->numeric, target->numeric, newnick, now);
701 irc_part(struct userNode *who, struct chanNode *what, const char *reason)
704 putsock("%s " P10_PART " %s :%s", who->numeric, what->name, reason);
706 putsock("%s " P10_PART " %s", who->numeric, what->name);
711 irc_topic(struct userNode *who, struct chanNode *what, const char *topic)
713 putsock("%s " P10_TOPIC " %s :%s", who->numeric, what->name, topic);
717 irc_raw(const char *what)
723 irc_numeric(struct userNode *user, unsigned int num, const char *format, ...)
727 va_start(arg_list, format);
728 vsnprintf(buffer, MAXLEN-2, format, arg_list);
729 buffer[MAXLEN-1] = 0;
730 putsock(":%s %03d %s %s", self->name, num, user->nick, buffer);
733 static void send_burst(void);
736 change_nicklen(int new_nicklen)
739 char new_nick[NICKLEN+1];
740 struct userNode *user;
742 nicklen = new_nicklen;
743 /* fix up any users we have here */
744 for (nn=0; nn<=self->num_mask; nn++) {
745 if (!(user = self->users[nn]))
747 safestrncpy(new_nick, user->nick, sizeof(new_nick));
748 new_nick[nicklen] = 0;
749 NickChange(user, new_nick, 1);
753 static CMD_FUNC(cmd_server)
761 /* another server introduced us */
762 srv = AddServer(GetServerH(origin), argv[1], atoi(argv[2]), atoi(argv[3]), atoi(argv[4]), argv[6], argv[argc-1]);
765 srv->self_burst = argv[5][0] == 'J';
768 /* this must be our uplink */
769 srv = self->uplink = AddServer(self, argv[1], atoi(argv[2]), atoi(argv[3]), atoi(argv[4]), argv[6], argv[argc-1]);
772 srv->self_burst = argv[5][0] == 'J';
774 if ((argv[7][0] == '+') && !force_n2k) {
775 log_module(MAIN_LOG, LOG_WARNING, "Got Undernet-style SERVER message but \"force_n2k\" not on.");
780 /* Fix up our timestamps if necessary. */
781 if (srv->boot <= PREHISTORY) {
782 /* Server from the mists of time.. */
783 if (srv->hops == 1) {
784 log_module(MAIN_LOG, LOG_ERROR, "Server %s claims to have booted at time "FMT_TIME_T". This is absurd.", srv->name, srv->boot);
786 } else if ((str = conf_get_data("server/reliable_clock", RECDB_QSTRING))
787 && enabled_string(str)) {
788 /* If we have a reliable clock, we just keep our current time. */
790 if (srv->boot <= self->boot) {
791 /* The other server is older than us. Accept their timestamp.
792 * Alternately, we are same age, but we accept their time
793 * since we are linking to them. */
794 self->boot = srv->boot;
795 ioset_set_time(srv->link);
798 if (srv == self->uplink) {
799 extern time_t burst_begin;
805 static CMD_FUNC(cmd_eob)
807 struct server *sender;
811 if (!(sender = GetServerH(origin)))
813 if (sender == self->uplink) {
814 cManager.uplink->state = CONNECTED;
815 for (it = dict_first(unbursted_channels); it; it = iter_next(it))
816 irc_burst(iter_data(it));
817 dict_delete(unbursted_channels);
818 unbursted_channels = NULL;
822 sender->self_burst = 0;
823 recalc_bursts(sender);
824 for (ii=0; ii<slf_used; ii++)
825 slf_list[ii](sender);
829 static CMD_FUNC(cmd_eob_ack)
831 extern time_t burst_begin;
833 if (GetServerH(origin) == self->uplink) {
834 burst_length = now - burst_begin;
835 self->self_burst = self->burst = 0;
837 cManager.uplink->state = CONNECTED;
841 static CMD_FUNC(cmd_ping)
847 irc_pong(argv[2], argv[1]);
848 else if ((srv = GetServerH(origin)))
849 irc_pong(self->name, srv->numeric);
850 else if ((un = GetUserH(origin)))
851 irc_pong(self->name, un->numeric);
853 irc_pong(self->name, origin);
855 timeq_del(0, timed_send_ping, 0, TIMEQ_IGNORE_WHEN|TIMEQ_IGNORE_DATA);
856 timeq_del(0, timed_ping_timeout, 0, TIMEQ_IGNORE_WHEN|TIMEQ_IGNORE_DATA);
857 timeq_add(now + ping_freq, timed_send_ping, 0);
862 static CMD_FUNC(cmd_error_nick)
864 /* Go back to original IRC length .. and try to reconnect :/ */
866 irc_squit(self, "Got erroneous nickname, truncating nicks.", NULL);
871 struct userNode *user;
876 join_helper(struct chanNode *chan, void *data)
878 struct create_desc *cd = data;
879 AddChannelUser(cd->user, chan);
883 create_helper(char *name, void *data)
885 struct create_desc *cd = data;
887 if (!strcmp(name, "0")) {
888 while (cd->user->channels.used > 0)
889 DelChannelUser(cd->user, cd->user->channels.list[0]->channel, 0, 0);
893 AddChannelUser(cd->user, AddChannel(name, cd->when, NULL, NULL));
896 static CMD_FUNC(cmd_create)
898 struct create_desc cd;
899 struct userNode *user;
901 if ((argc < 3) || !(user = GetUserH(origin)))
904 cd.when = atoi(argv[2]);
905 parse_foreach(argv[1], join_helper, create_helper, NULL, NULL, &cd);
909 static CMD_FUNC(cmd_join)
911 struct create_desc cd;
913 if (!(cd.user = GetUserH(origin)))
920 cd.when = atoi(argv[2]);
921 parse_foreach(argv[1], join_helper, create_helper, NULL, NULL, &cd);
925 static CMD_FUNC(cmd_pong)
929 if (!strcmp(argv[2], self->name)) {
930 timeq_del(0, timed_send_ping, 0, TIMEQ_IGNORE_WHEN|TIMEQ_IGNORE_DATA);
931 timeq_del(0, timed_ping_timeout, 0, TIMEQ_IGNORE_WHEN|TIMEQ_IGNORE_DATA);
932 timeq_add(now + ping_freq, timed_send_ping, 0);
938 static CMD_FUNC(cmd_nick)
940 struct userNode *user;
941 if ((user = GetUserH(origin))) {
942 /* nick change (since the source is a user numeric) */
945 NickChange(user, argv[1], 1);
952 serv = GetServerH(origin);
954 unsplit_string(argv+6, argc-9, modes);
957 AddUser(serv, argv[1], argv[4], argv[5], modes, argv[argc-2], argv[argc-1], atoi(argv[3]), argv[argc-3]);
962 static CMD_FUNC(cmd_account)
964 struct userNode *user;
966 if ((argc < 3) || !origin || !GetServerH(origin))
967 return 0; /* Origin must be server. */
968 user = GetUserN(argv[1]);
970 return 1; /* A QUIT probably passed the ACCOUNT. */
971 call_account_func(user, argv[2]);
975 static CMD_FUNC(cmd_burst)
978 char modes[MAXLEN], *members = "", *banlist = NULL;
979 unsigned int next = 3, res = 1;
980 struct chanNode *cNode;
982 struct modeNode *mNode;
984 char *user, *end, sep;
990 while (next < argc) {
991 switch (argv[next][0]) {
995 for (pos=argv[next], n_modes = 1; *pos; pos++)
996 if ((*pos == 'k') || (*pos == 'l'))
998 unsplit_string(argv+next, n_modes, modes);
1002 case '%': banlist = argv[next++]+1; break;
1003 default: members = argv[next++]; break;
1007 in_timestamp = atoi(argv[2]);
1008 if ((cNode = dict_find(unbursted_channels, argv[1], NULL))) {
1009 cNode->timestamp = in_timestamp;
1010 dict_remove(unbursted_channels, cNode->name);
1013 cNode = AddChannel(argv[1], in_timestamp, modes, banlist);
1015 /* Burst channel members in now. */
1016 for (user = members, sep = *members, mode = 0; sep; user = end) {
1017 for (end = user + 3; isalnum(*end) || *end == '[' || *end == ']'; end++) ;
1018 sep = *end++; end[-1] = 0;
1021 while ((sep = *end++)) {
1023 mode |= MODE_CHANOP;
1024 else if (sep == 'v')
1032 if (!(un = GetUserN(user))) {
1036 if ((mNode = AddChannelUser(un, cNode)))
1037 mNode->modes = mode;
1043 static CMD_FUNC(cmd_mode)
1045 struct chanNode *cn;
1046 struct userNode *un;
1050 if (!IsChannelName(argv[1])) {
1051 un = GetUserH(argv[1]);
1053 log_module(MAIN_LOG, LOG_ERROR, "Unable to find user %s whose mode is changing.", argv[1]);
1056 mod_usermode(un, argv[2]);
1060 if (!(cn = GetChannel(argv[1]))) {
1061 log_module(MAIN_LOG, LOG_ERROR, "Unable to find channel %s whose mode is changing.", argv[1]);
1064 if ((un = GetUserH(origin))) {
1065 struct modeNode *mn;
1066 /* Update idle time for person setting the mode */
1067 if ((mn = GetUserMode(cn, un)))
1068 mn->idle_since = now;
1070 /* If it came from a server, reset timestamp to re-sync. */
1071 cn->timestamp = atoi(argv[argc-1]);
1074 return mod_chanmode(un, cn, argv+2, argc-2, MCP_ALLOW_OVB|MCP_FROM_SERVER|(un ? MC_NOTIFY : 0));
1077 static CMD_FUNC(cmd_opmode)
1079 struct chanNode *cn;
1080 struct userNode *un;
1085 if (!(cn = GetChannel(argv[1]))) {
1086 log_module(MAIN_LOG, LOG_ERROR, "Unable to find channel %s whose mode is changing.", argv[1]);
1089 if (!(un = GetUserH(origin))) {
1090 log_module(MAIN_LOG, LOG_ERROR, "Unable to find user %s requesting OPMODE.", origin);
1094 log_module(MAIN_LOG, LOG_ERROR, "Non-privileged user %s using OPMODE.", un->nick);
1098 return mod_chanmode(un, cn, argv+2, argc-2, MCP_ALLOW_OVB|MCP_FROM_SERVER); /* do NOT announce opmode locally */
1101 static int clear_chanmode(struct chanNode *channel, const char *modes);
1103 static CMD_FUNC(cmd_clearmode)
1105 struct chanNode *cn;
1106 struct userNode *un;
1111 if (!(cn = GetChannel(argv[1]))) {
1112 log_module(MAIN_LOG, LOG_ERROR, "Unable to find channel %s whose mode is changing.", argv[1]);
1115 if (!(un = GetUserH(origin))) {
1116 log_module(MAIN_LOG, LOG_ERROR, "Unable to find user %s requesting CLEARMODE.", origin);
1120 log_module(MAIN_LOG, LOG_ERROR, "Non-privileged user %s using CLEARMODE.", un->nick);
1124 return clear_chanmode(cn, argv[2]);
1127 static CMD_FUNC(cmd_topic)
1129 struct chanNode *cn;
1130 time_t chan_ts, topic_ts;
1134 if (!(cn = GetChannel(argv[1]))) {
1135 log_module(MAIN_LOG, LOG_ERROR, "Unable to find channel %s whose topic is being set", argv[1]);
1139 /* Looks like an Asuka style topic burst. */
1140 chan_ts = atoi(argv[2]);
1141 topic_ts = atoi(argv[3]);
1143 chan_ts = cn->timestamp;
1146 SetChannelTopic(cn, GetUserH(origin), argv[argc-1], 0);
1147 cn->topic_time = topic_ts;
1151 static CMD_FUNC(cmd_num_topic)
1153 static struct chanNode *cn;
1156 return 0; /* huh? */
1158 cn = GetChannel(argv[2]);
1160 log_module(MAIN_LOG, LOG_ERROR, "Unable to find channel %s in topic reply", argv[2]);
1166 switch (atoi(argv[0])) {
1169 break; /* no topic */
1173 safestrncpy(cn->topic, unsplit_string(argv+3, argc-3, NULL), sizeof(cn->topic));
1178 safestrncpy(cn->topic_nick, argv[3], sizeof(cn->topic_nick));
1179 cn->topic_time = atoi(argv[4]);
1182 return 0; /* should never happen */
1187 static CMD_FUNC(cmd_num_gline)
1191 gline_add(origin, argv[3], atoi(argv[4])-now, argv[5], now, 0);
1195 static CMD_FUNC(cmd_quit)
1197 struct userNode *user;
1200 /* Sometimes we get a KILL then a QUIT or the like, so we don't want to
1201 * call DelUser unless we have the user in our grasp. */
1202 if ((user = GetUserH(origin)))
1203 DelUser(user, NULL, false, argv[1]);
1207 static CMD_FUNC(cmd_kill)
1209 struct userNode *user;
1212 user = GetUserN(argv[1]);
1214 /* If we get a KILL for a non-existent user, it could be a
1215 * Ghost response to a KILL we sent out earlier. So we only
1216 * whine if the target is local.
1218 if (!strncmp(argv[1], self->numeric, strlen(self->numeric)))
1219 log_module(MAIN_LOG, LOG_ERROR, "Unable to find kill victim %s", argv[1]);
1223 if (IsLocal(user) && IsService(user)) {
1224 /* TODO: rate limit this so silly things don't happen. */
1225 ReintroduceUser(user);
1229 DelUser(user, NULL, false, argv[2]);
1233 static CMD_FUNC(cmd_part)
1235 struct userNode *user;
1239 user = GetUserH(origin);
1242 parse_foreach(argv[1], part_helper, NULL, NULL, NULL, user);
1246 static CMD_FUNC(cmd_kick)
1250 ChannelUserKicked(GetUserH(origin), GetUserN(argv[2]), GetChannel(argv[1]));
1254 static CMD_FUNC(cmd_squit)
1256 struct server *server;
1260 if (!(server = GetServerH(argv[1])))
1263 if (server == self->uplink) {
1264 /* Force a reconnect to the currently selected server. */
1265 cManager.uplink->tries = 0;
1266 log_module(MAIN_LOG, LOG_INFO, "Squitting from uplink: %s", argv[3]);
1271 DelServer(server, 0, argv[3]);
1275 static CMD_FUNC(cmd_privmsg)
1277 struct privmsg_desc pd;
1280 pd.user = GetUserH(origin);
1281 if (!pd.user || (IsGagged(pd.user) && !IsOper(pd.user)))
1285 parse_foreach(argv[1], privmsg_chan_helper, NULL, privmsg_user_helper, privmsg_invalid, &pd);
1289 static CMD_FUNC(cmd_notice)
1291 struct privmsg_desc pd;
1294 pd.user = GetUserH(origin);
1295 if (!pd.user || (IsGagged(pd.user) && !IsOper(pd.user)))
1299 parse_foreach(argv[1], privmsg_chan_helper, NULL, privmsg_user_helper, privmsg_invalid, &pd);
1303 static CMD_FUNC(cmd_away)
1305 struct userNode *uNode;
1307 uNode = GetUserH(origin);
1311 uNode->modes &= ~FLAGS_AWAY;
1313 uNode->modes |= FLAGS_AWAY;
1317 static CMD_FUNC(cmd_gline)
1321 if (argv[2][0] == '+') {
1324 gline_add(origin, argv[2]+1, strtoul(argv[3], NULL, 0), argv[argc-1], now, 0);
1326 } else if (argv[2][0] == '-') {
1327 gline_remove(argv[2]+1, 0);
1333 static CMD_FUNC(cmd_svsnick)
1335 struct userNode *target, *dest;
1337 || !(target = GetUserN(argv[1]))
1339 || (dest = GetUserH(argv[2])))
1341 NickChange(target, argv[2], 0);
1345 static oper_func_t *of_list;
1346 static unsigned int of_size = 0, of_used = 0;
1349 free_user(struct userNode *user)
1360 free(privmsg_funcs);
1363 dict_delete(irc_func_dict);
1364 for (nn=0; nn<dead_users.used; nn++)
1365 free_user(dead_users.list[nn]);
1366 userList_clean(&dead_users);
1370 p10_conf_reload(void) {
1371 hidden_host_suffix = conf_get_data("server/hidden_host", RECDB_QSTRING);
1375 remove_unbursted_channel(struct chanNode *cNode) {
1376 if (unbursted_channels)
1377 dict_remove(unbursted_channels, cNode->name);
1383 const char *str, *desc;
1384 int numnick, usermask, max_users;
1385 char numer[COMBO_NUMERIC_LEN+1];
1387 /* read config items */
1388 str = conf_get_data("server/ping_freq", RECDB_QSTRING);
1389 ping_freq = str ? ParseInterval(str) : 120;
1390 str = conf_get_data("server/ping_timeout", RECDB_QSTRING);
1391 ping_timeout = str ? ParseInterval(str) : 30;
1392 str = conf_get_data("server/force_n2k", RECDB_QSTRING);
1393 force_n2k = str ? enabled_string(str) : 1;
1394 str = conf_get_data("server/numeric", RECDB_QSTRING);
1396 log_module(MAIN_LOG, LOG_ERROR, "No server/numeric entry in config file.");
1399 numnick = atoi(str);
1400 str = conf_get_data("server/max_users", RECDB_QSTRING);
1401 max_users = str ? atoi(str) : 4096;
1402 for (usermask = 4; usermask < max_users; usermask <<= 1) ;
1404 if ((numnick < 64) && (usermask < 4096) && !force_n2k)
1405 inttobase64(numer, (numnick << 12) + (usermask & 0x00fff), 3);
1407 inttobase64(numer, (numnick << 18) + (usermask & 0x3ffff), 5);
1408 str = conf_get_data("server/hostname", RECDB_QSTRING);
1409 desc = conf_get_data("server/description", RECDB_QSTRING);
1410 if (!str || !desc) {
1411 log_module(MAIN_LOG, LOG_ERROR, "No server/hostname entry in config file.");
1414 self = AddServer(NULL, str, 0, boot_time, now, numer, desc);
1415 conf_register_reload(p10_conf_reload);
1417 irc_func_dict = dict_new();
1418 dict_insert(irc_func_dict, CMD_BURST, cmd_burst);
1419 dict_insert(irc_func_dict, TOK_BURST, cmd_burst);
1420 dict_insert(irc_func_dict, CMD_CREATE, cmd_create);
1421 dict_insert(irc_func_dict, TOK_CREATE, cmd_create);
1422 dict_insert(irc_func_dict, CMD_EOB, cmd_eob);
1423 dict_insert(irc_func_dict, TOK_EOB, cmd_eob);
1424 dict_insert(irc_func_dict, CMD_EOB_ACK, cmd_eob_ack);
1425 dict_insert(irc_func_dict, TOK_EOB_ACK, cmd_eob_ack);
1426 dict_insert(irc_func_dict, CMD_MODE, cmd_mode);
1427 dict_insert(irc_func_dict, TOK_MODE, cmd_mode);
1428 dict_insert(irc_func_dict, CMD_NICK, cmd_nick);
1429 dict_insert(irc_func_dict, TOK_NICK, cmd_nick);
1430 dict_insert(irc_func_dict, CMD_ACCOUNT, cmd_account);
1431 dict_insert(irc_func_dict, TOK_ACCOUNT, cmd_account);
1432 dict_insert(irc_func_dict, CMD_PASS, cmd_pass);
1433 dict_insert(irc_func_dict, TOK_PASS, cmd_pass);
1434 dict_insert(irc_func_dict, CMD_PING, cmd_ping);
1435 dict_insert(irc_func_dict, TOK_PING, cmd_ping);
1436 dict_insert(irc_func_dict, CMD_PRIVMSG, cmd_privmsg);
1437 dict_insert(irc_func_dict, TOK_PRIVMSG, cmd_privmsg);
1438 dict_insert(irc_func_dict, CMD_PONG, cmd_pong);
1439 dict_insert(irc_func_dict, TOK_PONG, cmd_pong);
1440 dict_insert(irc_func_dict, CMD_QUIT, cmd_quit);
1441 dict_insert(irc_func_dict, TOK_QUIT, cmd_quit);
1442 dict_insert(irc_func_dict, CMD_SERVER, cmd_server);
1443 dict_insert(irc_func_dict, TOK_SERVER, cmd_server);
1444 dict_insert(irc_func_dict, CMD_JOIN, cmd_join);
1445 dict_insert(irc_func_dict, TOK_JOIN, cmd_join);
1446 dict_insert(irc_func_dict, CMD_PART, cmd_part);
1447 dict_insert(irc_func_dict, TOK_PART, cmd_part);
1448 dict_insert(irc_func_dict, CMD_ERROR, cmd_error);
1449 dict_insert(irc_func_dict, TOK_ERROR, cmd_error);
1450 dict_insert(irc_func_dict, CMD_TOPIC, cmd_topic);
1451 dict_insert(irc_func_dict, TOK_TOPIC, cmd_topic);
1452 dict_insert(irc_func_dict, CMD_AWAY, cmd_away);
1453 dict_insert(irc_func_dict, TOK_AWAY, cmd_away);
1454 dict_insert(irc_func_dict, CMD_SILENCE, cmd_dummy);
1455 dict_insert(irc_func_dict, TOK_SILENCE, cmd_dummy);
1456 dict_insert(irc_func_dict, CMD_KICK, cmd_kick);
1457 dict_insert(irc_func_dict, TOK_KICK, cmd_kick);
1458 dict_insert(irc_func_dict, CMD_SQUIT, cmd_squit);
1459 dict_insert(irc_func_dict, TOK_SQUIT, cmd_squit);
1460 dict_insert(irc_func_dict, CMD_KILL, cmd_kill);
1461 dict_insert(irc_func_dict, TOK_KILL, cmd_kill);
1462 dict_insert(irc_func_dict, CMD_NOTICE, cmd_notice);
1463 dict_insert(irc_func_dict, TOK_NOTICE, cmd_notice);
1464 dict_insert(irc_func_dict, CMD_STATS, cmd_stats);
1465 dict_insert(irc_func_dict, TOK_STATS, cmd_stats);
1466 dict_insert(irc_func_dict, CMD_SVSNICK, cmd_svsnick);
1467 dict_insert(irc_func_dict, TOK_SVSNICK, cmd_svsnick);
1468 dict_insert(irc_func_dict, CMD_WHOIS, cmd_whois);
1469 dict_insert(irc_func_dict, TOK_WHOIS, cmd_whois);
1470 dict_insert(irc_func_dict, CMD_GLINE, cmd_gline);
1471 dict_insert(irc_func_dict, TOK_GLINE, cmd_gline);
1472 dict_insert(irc_func_dict, CMD_OPMODE, cmd_opmode);
1473 dict_insert(irc_func_dict, TOK_OPMODE, cmd_opmode);
1474 dict_insert(irc_func_dict, CMD_CLEARMODE, cmd_clearmode);
1475 dict_insert(irc_func_dict, TOK_CLEARMODE, cmd_clearmode);
1476 dict_insert(irc_func_dict, CMD_VERSION, cmd_version);
1477 dict_insert(irc_func_dict, TOK_VERSION, cmd_version);
1478 dict_insert(irc_func_dict, CMD_ADMIN, cmd_admin);
1479 dict_insert(irc_func_dict, TOK_ADMIN, cmd_admin);
1481 /* In P10, DESTRUCT doesn't do anything except be broadcast to servers.
1482 * Apparently to obliterate channels from any servers that think they
1485 dict_insert(irc_func_dict, CMD_DESTRUCT, cmd_dummy);
1486 dict_insert(irc_func_dict, TOK_DESTRUCT, cmd_dummy);
1487 /* Ignore invites */
1488 dict_insert(irc_func_dict, CMD_INVITE, cmd_dummy);
1489 dict_insert(irc_func_dict, TOK_INVITE, cmd_dummy);
1490 /* DESYNCH is just informational, so ignore it */
1491 dict_insert(irc_func_dict, CMD_DESYNCH, cmd_dummy);
1492 dict_insert(irc_func_dict, TOK_DESYNCH, cmd_dummy);
1493 /* Ignore channel operator notices. */
1494 dict_insert(irc_func_dict, CMD_WALLCHOPS, cmd_dummy);
1495 dict_insert(irc_func_dict, TOK_WALLCHOPS, cmd_dummy);
1496 dict_insert(irc_func_dict, CMD_WALLVOICES, cmd_dummy);
1497 dict_insert(irc_func_dict, TOK_WALLVOICES, cmd_dummy);
1498 /* Ignore opers being silly. */
1499 dict_insert(irc_func_dict, CMD_WALLOPS, cmd_dummy);
1500 dict_insert(irc_func_dict, TOK_WALLOPS, cmd_dummy);
1501 /* We have reliable clock! Always! Wraaa! */
1502 dict_insert(irc_func_dict, CMD_SETTIME, cmd_dummy);
1503 dict_insert(irc_func_dict, TOK_SETTIME, cmd_dummy);
1505 dict_insert(irc_func_dict, "331", cmd_num_topic);
1506 dict_insert(irc_func_dict, "332", cmd_num_topic);
1507 dict_insert(irc_func_dict, "333", cmd_num_topic);
1508 dict_insert(irc_func_dict, "432", cmd_error_nick); /* Erroneus [sic] nickname */
1509 /* ban list resetting */
1510 /* "stats g" responses */
1511 dict_insert(irc_func_dict, "247", cmd_num_gline);
1512 dict_insert(irc_func_dict, "219", cmd_dummy); /* "End of /STATS report" */
1513 /* other numeric responses we might get */
1514 dict_insert(irc_func_dict, "401", cmd_dummy); /* target left network */
1515 dict_insert(irc_func_dict, "403", cmd_dummy); /* no such channel */
1516 dict_insert(irc_func_dict, "404", cmd_dummy); /* cannot send to channel */
1517 dict_insert(irc_func_dict, "441", cmd_dummy); /* target isn't on that channel */
1518 dict_insert(irc_func_dict, "442", cmd_dummy); /* you aren't on that channel */
1519 dict_insert(irc_func_dict, "443", cmd_dummy); /* is already on channel (after invite?) */
1520 dict_insert(irc_func_dict, "461", cmd_dummy); /* Not enough parameters (after TOPIC w/ 0 args) */
1522 num_privmsg_funcs = 16;
1523 privmsg_funcs = malloc(sizeof(privmsg_func_t)*num_privmsg_funcs);
1524 memset(privmsg_funcs, 0, sizeof(privmsg_func_t)*num_privmsg_funcs);
1526 num_notice_funcs = 16;
1527 notice_funcs = malloc(sizeof(privmsg_func_t)*num_notice_funcs);
1528 memset(notice_funcs, 0, sizeof(privmsg_func_t)*num_notice_funcs);
1530 userList_init(&dead_users);
1531 reg_del_channel_func(remove_unbursted_channel);
1532 reg_exit_func(parse_cleanup);
1536 parse_line(char *line, int recursive)
1538 char *argv[MAXNUMPARAMS], *origin;
1539 int argc, cmd, res=0;
1542 argc = split_line(line, true, MAXNUMPARAMS, argv);
1543 cmd = self->uplink || !argv[0][1] || !argv[0][2];
1546 if (argv[0][0] == ':') {
1548 } else if (!argv[0][1] || !argv[0][2]) {
1549 struct server *sNode = GetServerN(argv[0]);
1550 origin = sNode ? sNode->name : 0;
1552 struct userNode *uNode = GetUserN(argv[0]);
1553 origin = uNode ? uNode->nick : 0;
1557 if ((func = dict_find(irc_func_dict, argv[cmd], NULL)))
1558 res = func(origin, argc-cmd, argv+cmd);
1561 log_module(MAIN_LOG, LOG_ERROR, "PARSE ERROR on line: %s", unsplit_string(argv, argc, NULL));
1562 } else if (!recursive) {
1564 for (i=0; i<dead_users.used; i++)
1565 free_user(dead_users.list[i]);
1566 dead_users.used = 0;
1572 parse_foreach(char *target_list, foreach_chanfunc cf, foreach_nonchan nc, foreach_userfunc uf, foreach_nonuser nu, void *data)
1577 while (*j != 0 && *j != ',')
1581 if (IsChannelName(target_list)
1582 || (target_list[0] == '0' && target_list[1] == '\0')) {
1583 struct chanNode *chan = GetChannel(target_list);
1589 nc(target_list, data);
1592 struct userNode *user;
1593 struct privmsg_desc *pd = data;
1595 pd->is_qualified = 0;
1596 if (*target_list == '@') {
1598 } else if (strchr(target_list, '@')) {
1599 struct server *server;
1601 pd->is_qualified = 1;
1602 user = GetUserH(strtok(target_list, "@"));
1603 server = GetServerH(strtok(NULL, "@"));
1605 if (user && (user->uplink != server)) {
1606 /* Don't attempt to index into any arrays
1607 using a user's numeric on another server. */
1611 user = GetUserN(target_list);
1619 nu(target_list, data);
1623 } while (old == ',');
1627 get_local_numeric(void)
1629 static unsigned int next_numeric = 0;
1630 if (self->clients > self->num_mask)
1632 while (self->users[next_numeric])
1633 if (++next_numeric > self->num_mask)
1635 return next_numeric;
1639 make_numeric(struct server *svr, int local_num, char *outbuf)
1643 if (force_n2k || svr->numeric[1]) {
1648 llen = (local_num < 64*64) ? 2 : 3;
1650 strncpy(outbuf, svr->numeric, slen);
1651 inttobase64(outbuf+slen, local_num, llen);
1652 outbuf[slen+llen] = 0;
1656 AddServer(struct server *uplink, const char *name, int hops, time_t boot, time_t link, const char *numeric, const char *description)
1658 struct server* sNode;
1661 if ((sNode = GetServerN(numeric))) {
1662 /* This means we're trying to re-add an existant server.
1663 * To be safe, we should forget the previous incarnation.
1664 * (And all its linked servers.)
1666 * It usually only happens in replays when the original
1667 * had a ping timeout and the replay didn't (because
1668 * replaying a ping timeout invariably gets things wrong).
1670 DelServer(sNode, 0, NULL);
1673 switch (strlen(numeric)) {
1674 case 5: slen = 2; mlen = 3; break;
1675 case 4: slen = 1; mlen = 3; break;
1676 case 3: slen = 1; mlen = 2; break;
1678 log_module(MAIN_LOG, LOG_ERROR, "AddServer(\"%s\", \"%s\", ...): Numeric %s has invalid length.", uplink->name, name, numeric);
1682 sNode = calloc(1, sizeof(*sNode));
1683 sNode->uplink = uplink;
1684 safestrncpy(sNode->name, name, sizeof(sNode->name));
1685 sNode->num_mask = base64toint(numeric+slen, mlen);
1689 strncpy(sNode->numeric, numeric, slen);
1690 safestrncpy(sNode->description, description, sizeof(sNode->description));
1691 sNode->users = calloc(sNode->num_mask+1, sizeof(*sNode->users));
1692 serverList_init(&sNode->children);
1693 if (sNode->uplink) {
1694 /* uplink may be NULL if we're just building ourself */
1695 serverList_append(&sNode->uplink->children, sNode);
1697 servers_num[base64toint(numeric, slen)] = sNode;
1698 dict_insert(servers, sNode->name, sNode);
1702 void DelServer(struct server* serv, int announce, const char *message)
1706 /* If we receive an ERROR command before the SERVER
1707 * command a NULL server can be passed */
1711 /* Hrm, what's the right way to SQUIT some other server?
1712 * (This code is only to handle killing juped servers.) */
1713 if (announce && (serv->uplink == self) && (serv != self->uplink))
1714 irc_squit(serv, message, NULL);
1716 /* must recursively remove servers linked to this one first */
1717 for (i=serv->children.used;i>0;)
1718 if (serv->children.list[--i] != self)
1719 DelServer(serv->children.list[i], false, NULL);
1721 /* clean up server's user hash tables */
1722 for (i=0;i<=serv->num_mask;i++)
1724 DelUser(serv->users[i], NULL, false, "server delinked");
1728 serverList_remove(&serv->uplink->children, serv);
1729 if (serv == self->uplink)
1730 self->uplink = NULL;
1731 servers_num[base64toint(serv->numeric, strlen(serv->numeric))] = NULL;
1732 dict_remove(servers, serv->name);
1733 serverList_clean(&serv->children);
1739 AddService(const char *nick, const char *desc)
1741 char numeric[COMBO_NUMERIC_LEN+1];
1742 int local_num = get_local_numeric();
1743 time_t timestamp = now;
1744 struct userNode *old_user = GetUserH(nick);
1747 if (IsLocal(old_user))
1749 timestamp = old_user->timestamp - 1;
1751 if (local_num == -1) {
1752 log_module(MAIN_LOG, LOG_ERROR, "Unable to allocate numnick for service %s", nick);
1755 make_numeric(self, local_num, numeric);
1756 return AddUser(self, nick, nick, self->name, "+oik", numeric, desc, now, "AAAAAA");
1760 AddClone(const char *nick, const char *ident, const char *hostname, const char *desc)
1762 char numeric[COMBO_NUMERIC_LEN+1];
1763 int local_num = get_local_numeric();
1764 time_t timestamp = now;
1765 struct userNode *old_user = GetUserH(nick);
1768 if (IsLocal(old_user))
1770 timestamp = old_user->timestamp - 1;
1772 if (local_num == -1) {
1773 log_module(MAIN_LOG, LOG_ERROR, "Unable to allocate numnick for clone %s", nick);
1776 make_numeric(self, local_num, numeric);
1777 return AddUser(self, nick, ident, hostname, "+i", numeric, desc, timestamp, "AAAAAA");
1781 is_valid_nick(const char *nick) {
1782 /* IRC has some of The Most Fucked-Up ideas about character sets
1784 if (!isalpha(*nick) && !strchr("{|}~[\\]^_`", *nick))
1786 for (++nick; *nick; ++nick)
1787 if (!isalnum(*nick) && !strchr("{|}~[\\]^-_`", *nick))
1789 if (strlen(nick) > nicklen)
1794 static struct userNode*
1795 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)
1797 struct userNode *oldUser, *uNode;
1798 unsigned int n, ignore_user;
1800 if ((strlen(numeric) < 3) || (strlen(numeric) > 5)) {
1801 log_module(MAIN_LOG, LOG_WARNING, "AddUser(%p, %s, ...): numeric %s wrong length!", uplink, nick, numeric);
1806 log_module(MAIN_LOG, LOG_WARNING, "AddUser(%p, %s, ...): server for numeric %s doesn't exist!", uplink, nick, numeric);
1810 if (uplink != GetServerN(numeric)) {
1811 log_module(MAIN_LOG, LOG_WARNING, "AddUser(%p, %s, ...): server for numeric %s differs from nominal uplink %s.", uplink, nick, numeric, uplink->name);
1815 if (!is_valid_nick(nick)) {
1816 log_module(MAIN_LOG, LOG_WARNING, "AddUser(%p, %s, ...): invalid nickname detected.", uplink, nick);
1821 if ((oldUser = GetUserH(nick))) {
1822 if (IsLocal(oldUser) && (IsService(oldUser) || IsPersistent(oldUser))) {
1823 /* The service should collide the new user off. */
1824 oldUser->timestamp = timestamp - 1;
1827 if (oldUser->timestamp > timestamp) {
1828 /* "Old" user is really newer; remove them */
1829 DelUser(oldUser, 0, 1, "Overruled by older nick");
1831 /* User being added is too new; do not add them to
1832 * clients, but do add them to the server's list, since it
1833 * will send a KILL and QUIT soon. */
1838 /* create new usernode and set all values */
1839 uNode = calloc(1, sizeof(*uNode));
1840 uNode->nick = strdup(nick);
1841 safestrncpy(uNode->ident, ident, sizeof(uNode->ident));
1842 safestrncpy(uNode->info, userinfo, sizeof(uNode->info));
1843 safestrncpy(uNode->hostname, hostname, sizeof(uNode->hostname));
1844 safestrncpy(uNode->numeric, numeric, sizeof(uNode->numeric));
1845 uNode->ip.s_addr = htonl(base64toint(realip, 6));
1846 uNode->timestamp = timestamp;
1847 modeList_init(&uNode->channels);
1848 uNode->uplink = uplink;
1849 if (++uNode->uplink->clients > uNode->uplink->max_clients) {
1850 uNode->uplink->max_clients = uNode->uplink->clients;
1852 uNode->num_local = base64toint(numeric+strlen(uNode->uplink->numeric), 3) & uNode->uplink->num_mask;
1853 uNode->uplink->users[uNode->num_local] = uNode;
1854 mod_usermode(uNode, modes);
1858 dict_insert(clients, uNode->nick, uNode);
1859 if (dict_size(clients) > max_clients) {
1860 max_clients = dict_size(clients);
1861 max_clients_time = now;
1865 for (n=0; n<nuf_used; n++)
1866 if (nuf_list[n](uNode))
1871 /* removes user from it's server's hash table and nick hash table */
1873 DelUser(struct userNode* user, struct userNode *killer, int announce, const char *why)
1877 /* mark them as dead, in case anybody cares */
1880 /* remove user from all channels */
1881 while (user->channels.used > 0)
1882 DelChannelUser(user, user->channels.list[user->channels.used-1]->channel, false, 0);
1884 /* Call these in reverse order so ChanServ can update presence
1885 information before NickServ nukes the handle_info. */
1886 for (n = duf_used; n > 0; )
1887 duf_list[--n](user, killer, why);
1889 user->uplink->clients--;
1890 user->uplink->users[user->num_local] = NULL;
1892 userList_remove(&curr_opers, user);
1893 /* remove from global dictionary, but not if after a collide */
1894 if (user == dict_find(clients, user->nick, NULL))
1895 dict_remove(clients, user->nick);
1897 if (IsInvisible(user))
1902 irc_quit(user, why);
1904 irc_kill(killer, user, why);
1907 modeList_clean(&user->channels);
1908 /* We don't free them, in case we try to privmsg them or something
1909 * (like when a stupid oper kills themself). We just put them onto
1910 * a list of clients that get freed after processing each line.
1912 if (dead_users.size)
1913 userList_append(&dead_users, user);
1918 void mod_usermode(struct userNode *user, const char *mode_change) {
1919 static void call_oper_funcs(struct userNode *user);
1921 const char *word = mode_change;
1923 if (!user || !mode_change)
1925 while (*word != ' ' && *word) word++;\
1926 while (*word == ' ') word++; \
1928 #define do_user_mode(FLAG) do { if (add) user->modes |= FLAG; else user->modes &= ~FLAG; } while (0)
1929 switch (*mode_change++) {
1930 case 0: case ' ': return;
1931 case '+': add = 1; break;
1932 case '-': add = 0; break;
1934 do_user_mode(FLAGS_OPER);
1936 userList_append(&curr_opers, user);
1937 call_oper_funcs(user);
1939 userList_remove(&curr_opers, user);
1942 case 'O': do_user_mode(FLAGS_LOCOP); break;
1943 case 'i': do_user_mode(FLAGS_INVISIBLE);
1949 case 'w': do_user_mode(FLAGS_WALLOP); break;
1950 case 's': do_user_mode(FLAGS_SERVNOTICE); break;
1951 case 'd': do_user_mode(FLAGS_DEAF); break;
1952 case 'k': do_user_mode(FLAGS_SERVICE); break;
1953 case 'g': do_user_mode(FLAGS_GLOBAL); break;
1954 case 'h': do_user_mode(FLAGS_HELPER); break;
1955 case 'x': do_user_mode(FLAGS_HIDDEN_HOST); break;
1960 for (ii=0; (*word != ' ') && (*word != '\0'); )
1961 tag[ii++] = *word++;
1963 while (*word == ' ')
1965 call_account_func(user, tag);
1973 struct mod_chanmode *
1974 mod_chanmode_parse(struct chanNode *channel, char **modes, unsigned int argc, unsigned int flags)
1976 struct mod_chanmode *change;
1977 unsigned int ii, in_arg, ch_arg, add;
1981 if (!(change = mod_chanmode_alloc(argc - 1)))
1984 for (ii = ch_arg = 0, in_arg = add = 1;
1985 (modes[0][ii] != '\0') && (modes[0][ii] != ' ');
1987 switch (modes[0][ii]) {
1994 #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)
1995 case 'C': do_chan_mode(MODE_NOCTCPS); break;
1996 case 'D': do_chan_mode(MODE_DELAYJOINS); break;
1997 case 'c': do_chan_mode(MODE_NOCOLORS); break;
1998 case 'i': do_chan_mode(MODE_INVITEONLY); break;
1999 case 'm': do_chan_mode(MODE_MODERATED); break;
2000 case 'n': do_chan_mode(MODE_NOPRIVMSGS); break;
2001 case 'p': do_chan_mode(MODE_PRIVATE); break;
2002 case 'r': do_chan_mode(MODE_REGONLY); break;
2003 case 's': do_chan_mode(MODE_SECRET); break;
2004 case 't': do_chan_mode(MODE_TOPICLIMIT); break;
2010 change->modes_set |= MODE_LIMIT;
2011 change->new_limit = atoi(modes[in_arg++]);
2013 change->modes_set &= ~MODE_LIMIT;
2014 change->modes_clear |= MODE_LIMIT;
2021 change->modes_set |= MODE_KEY;
2022 safestrncpy(change->new_key, modes[in_arg++], sizeof(change->new_key));
2024 change->modes_clear |= MODE_KEY;
2025 if (!(flags & MCP_KEY_FREE)) {
2033 if (!(flags & MCP_ALLOW_OVB))
2037 change->args[ch_arg].mode = MODE_BAN;
2039 change->args[ch_arg].mode |= MODE_REMOVE;
2040 change->args[ch_arg++].hostmask = modes[in_arg++];
2044 struct userNode *victim;
2045 if (!(flags & MCP_ALLOW_OVB))
2049 change->args[ch_arg].mode = (modes[0][ii] == 'o') ? MODE_CHANOP : MODE_VOICE;
2051 change->args[ch_arg].mode |= MODE_REMOVE;
2052 if (flags & MCP_FROM_SERVER)
2053 victim = GetUserN(modes[in_arg++]);
2055 victim = GetUserH(modes[in_arg++]);
2058 if ((change->args[ch_arg].member = GetUserMode(channel, victim)))
2063 if (!(flags & MCP_FROM_SERVER))
2068 change->argc = ch_arg; /* in case any turned out to be ignored */
2069 if (change->modes_set & MODE_SECRET) {
2070 change->modes_set &= ~(MODE_PRIVATE);
2071 change->modes_clear |= MODE_PRIVATE;
2072 } else if (change->modes_set & MODE_PRIVATE) {
2073 change->modes_set &= ~(MODE_SECRET);
2074 change->modes_clear |= MODE_SECRET;
2078 mod_chanmode_free(change);
2082 struct chanmode_buffer {
2085 struct chanNode *channel;
2086 struct userNode *actor;
2087 unsigned int modes_used;
2088 unsigned int args_used;
2090 unsigned int is_add : 1;
2091 unsigned int is_chanop : 1;
2095 mod_chanmode_append(struct chanmode_buffer *buf, char ch, const char *arg)
2097 size_t arg_len = strlen(arg);
2098 if (buf->modes_used > (MAXMODEPARAMS) ||
2099 buf->modes_used + buf->args_used + buf->chname_len + arg_len > 450) {
2100 memcpy(buf->modes + buf->modes_used, buf->args, buf->args_used);
2101 buf->modes[buf->modes_used + buf->args_used] = '\0';
2102 irc_mode((buf->is_chanop ? buf->actor : NULL), buf->channel, buf->modes);
2103 buf->modes[0] = buf->is_add ? '+' : '-';
2104 buf->modes_used = 1;
2107 buf->modes[buf->modes_used++] = ch;
2108 buf->args[buf->args_used++] = ' ';
2109 memcpy(buf->args + buf->args_used, arg, arg_len);
2110 buf->args_used += arg_len;
2114 mod_chanmode_announce(struct userNode *who, struct chanNode *channel, struct mod_chanmode *change)
2116 struct chanmode_buffer chbuf;
2118 struct modeNode *mn;
2119 char int_buff[32], mode = '\0';
2121 assert(change->argc <= change->alloc_argc);
2122 memset(&chbuf, 0, sizeof(chbuf));
2123 chbuf.channel = channel;
2125 chbuf.chname_len = strlen(channel->name);
2126 if ((mn = GetUserMode(channel, who)) && (mn->modes & MODE_CHANOP))
2127 chbuf.is_chanop = 1;
2129 /* First remove modes */
2131 if (change->modes_clear) {
2133 chbuf.modes[chbuf.modes_used++] = mode = '-';
2134 #define DO_MODE_CHAR(BIT, CHAR) if (change->modes_clear & MODE_##BIT) chbuf.modes[chbuf.modes_used++] = CHAR
2135 DO_MODE_CHAR(PRIVATE, 'p');
2136 DO_MODE_CHAR(SECRET, 's');
2137 DO_MODE_CHAR(MODERATED, 'm');
2138 DO_MODE_CHAR(TOPICLIMIT, 't');
2139 DO_MODE_CHAR(INVITEONLY, 'i');
2140 DO_MODE_CHAR(NOPRIVMSGS, 'n');
2141 DO_MODE_CHAR(LIMIT, 'l');
2142 DO_MODE_CHAR(DELAYJOINS, 'D');
2143 DO_MODE_CHAR(REGONLY, 'r');
2144 DO_MODE_CHAR(NOCOLORS, 'c');
2145 DO_MODE_CHAR(NOCTCPS, 'C');
2147 if (change->modes_clear & channel->modes & MODE_KEY)
2148 mod_chanmode_append(&chbuf, 'k', channel->key);
2150 for (arg = 0; arg < change->argc; ++arg) {
2151 if (!(change->args[arg].mode & MODE_REMOVE))
2154 chbuf.modes[chbuf.modes_used++] = mode = '-';
2155 switch (change->args[arg].mode & ~MODE_REMOVE) {
2157 mod_chanmode_append(&chbuf, 'b', change->args[arg].hostmask);
2160 if (change->args[arg].mode & MODE_CHANOP)
2161 mod_chanmode_append(&chbuf, 'o', change->args[arg].member->user->numeric);
2162 if (change->args[arg].mode & MODE_VOICE)
2163 mod_chanmode_append(&chbuf, 'v', change->args[arg].member->user->numeric);
2170 if (change->modes_set) {
2172 chbuf.modes[chbuf.modes_used++] = mode = '+';
2173 #define DO_MODE_CHAR(BIT, CHAR) if (change->modes_set & MODE_##BIT) chbuf.modes[chbuf.modes_used++] = CHAR
2174 DO_MODE_CHAR(PRIVATE, 'p');
2175 DO_MODE_CHAR(SECRET, 's');
2176 DO_MODE_CHAR(MODERATED, 'm');
2177 DO_MODE_CHAR(TOPICLIMIT, 't');
2178 DO_MODE_CHAR(INVITEONLY, 'i');
2179 DO_MODE_CHAR(NOPRIVMSGS, 'n');
2180 DO_MODE_CHAR(DELAYJOINS, 'D');
2181 DO_MODE_CHAR(REGONLY, 'r');
2182 DO_MODE_CHAR(NOCOLORS, 'c');
2183 DO_MODE_CHAR(NOCTCPS, 'C');
2185 if(change->modes_set & MODE_KEY)
2186 mod_chanmode_append(&chbuf, 'k', change->new_key);
2187 if(change->modes_set & MODE_LIMIT) {
2188 sprintf(int_buff, "%d", change->new_limit);
2189 mod_chanmode_append(&chbuf, 'l', int_buff);
2192 for (arg = 0; arg < change->argc; ++arg) {
2193 if (change->args[arg].mode & MODE_REMOVE)
2196 chbuf.modes[chbuf.modes_used++] = mode = '+';
2197 switch (change->args[arg].mode) {
2199 mod_chanmode_append(&chbuf, 'b', change->args[arg].hostmask);
2202 if (change->args[arg].mode & MODE_CHANOP)
2203 mod_chanmode_append(&chbuf, 'o', change->args[arg].member->user->numeric);
2204 if (change->args[arg].mode & MODE_VOICE)
2205 mod_chanmode_append(&chbuf, 'v', change->args[arg].member->user->numeric);
2210 /* Flush the buffer and apply changes locally */
2211 if (chbuf.modes_used > 0) {
2212 memcpy(chbuf.modes + chbuf.modes_used, chbuf.args, chbuf.args_used);
2213 chbuf.modes[chbuf.modes_used + chbuf.args_used] = '\0';
2214 irc_mode((chbuf.is_chanop ? chbuf.actor : NULL), chbuf.channel, chbuf.modes);
2216 mod_chanmode_apply(who, channel, change);
2220 mod_chanmode_format(struct mod_chanmode *change, char *outbuff)
2222 unsigned int used = 0;
2223 assert(change->argc <= change->alloc_argc);
2224 if (change->modes_clear) {
2225 outbuff[used++] = '-';
2226 #define DO_MODE_CHAR(BIT, CHAR) if (change->modes_clear & MODE_##BIT) outbuff[used++] = CHAR
2227 DO_MODE_CHAR(PRIVATE, 'p');
2228 DO_MODE_CHAR(SECRET, 's');
2229 DO_MODE_CHAR(MODERATED, 'm');
2230 DO_MODE_CHAR(TOPICLIMIT, 't');
2231 DO_MODE_CHAR(INVITEONLY, 'i');
2232 DO_MODE_CHAR(NOPRIVMSGS, 'n');
2233 DO_MODE_CHAR(LIMIT, 'l');
2234 DO_MODE_CHAR(KEY, 'k');
2235 DO_MODE_CHAR(DELAYJOINS, 'D');
2236 DO_MODE_CHAR(REGONLY, 'r');
2237 DO_MODE_CHAR(NOCOLORS, 'c');
2238 DO_MODE_CHAR(NOCTCPS, 'C');
2241 if (change->modes_set) {
2242 outbuff[used++] = '+';
2243 #define DO_MODE_CHAR(BIT, CHAR) if (change->modes_set & MODE_##BIT) outbuff[used++] = CHAR
2244 DO_MODE_CHAR(PRIVATE, 'p');
2245 DO_MODE_CHAR(SECRET, 's');
2246 DO_MODE_CHAR(MODERATED, 'm');
2247 DO_MODE_CHAR(TOPICLIMIT, 't');
2248 DO_MODE_CHAR(INVITEONLY, 'i');
2249 DO_MODE_CHAR(NOPRIVMSGS, 'n');
2250 DO_MODE_CHAR(DELAYJOINS, 'D');
2251 DO_MODE_CHAR(REGONLY, 'r');
2252 DO_MODE_CHAR(NOCOLORS, 'c');
2253 DO_MODE_CHAR(NOCTCPS, 'C');
2255 switch (change->modes_set & (MODE_KEY|MODE_LIMIT)) {
2256 case MODE_KEY|MODE_LIMIT:
2257 used += sprintf(outbuff+used, "lk %d %s", change->new_limit, change->new_key);
2260 used += sprintf(outbuff+used, "k %s", change->new_key);
2263 used += sprintf(outbuff+used, "l %d", change->new_limit);
2272 clear_chanmode(struct chanNode *channel, const char *modes)
2274 unsigned int remove;
2276 for (remove = 0; *modes; modes++) {
2278 case 'o': remove |= MODE_CHANOP; break;
2279 case 'v': remove |= MODE_VOICE; break;
2280 case 'p': remove |= MODE_PRIVATE; break;
2281 case 's': remove |= MODE_SECRET; break;
2282 case 'm': remove |= MODE_MODERATED; break;
2283 case 't': remove |= MODE_TOPICLIMIT; break;
2284 case 'i': remove |= MODE_INVITEONLY; break;
2285 case 'n': remove |= MODE_NOPRIVMSGS; break;
2288 channel->key[0] = '\0';
2291 remove |= MODE_LIMIT;
2294 case 'b': remove |= MODE_BAN; break;
2295 case 'D': remove |= MODE_DELAYJOINS; break;
2296 case 'r': remove |= MODE_REGONLY; break;
2297 case 'c': remove |= MODE_NOCOLORS;
2298 case 'C': remove |= MODE_NOCTCPS; break;
2305 /* Remove simple modes. */
2306 channel->modes &= ~remove;
2308 /* If removing bans, kill 'em all. */
2309 if ((remove & MODE_BAN) && channel->banlist.used) {
2311 for (i=0; i<channel->banlist.used; i++)
2312 free(channel->banlist.list[i]);
2313 channel->banlist.used = 0;
2316 /* Remove member modes. */
2317 if ((remove & (MODE_CHANOP | MODE_VOICE)) && channel->members.used) {
2318 int mask = ~(remove & (MODE_CHANOP | MODE_VOICE));
2321 for (i = 0; i < channel->members.used; i++)
2322 channel->members.list[i]->modes &= mask;
2329 reg_privmsg_func(struct userNode *user, privmsg_func_t handler)
2331 unsigned int numeric = user->num_local;
2332 if (numeric >= num_privmsg_funcs) {
2333 int newnum = numeric + 8;
2334 privmsg_funcs = realloc(privmsg_funcs, newnum*sizeof(privmsg_func_t));
2335 memset(privmsg_funcs+num_privmsg_funcs, 0, (newnum-num_privmsg_funcs)*sizeof(privmsg_func_t));
2336 num_privmsg_funcs = newnum;
2338 if (privmsg_funcs[numeric])
2339 log_module(MAIN_LOG, LOG_WARNING, "re-registering new privmsg handler for numeric %d", numeric);
2340 privmsg_funcs[numeric] = handler;
2344 reg_notice_func(struct userNode *user, privmsg_func_t handler)
2346 unsigned int numeric = user->num_local;
2347 if (numeric >= num_notice_funcs) {
2348 int newnum = numeric + 8;
2349 notice_funcs = realloc(notice_funcs, newnum*sizeof(privmsg_func_t));
2350 memset(notice_funcs+num_notice_funcs, 0, (newnum-num_notice_funcs)*sizeof(privmsg_func_t));
2351 num_notice_funcs = newnum;
2353 if (notice_funcs[numeric])
2354 log_module(MAIN_LOG, LOG_WARNING, "re-registering new notice handler for numeric %d", numeric);
2355 notice_funcs[numeric] = handler;
2359 reg_oper_func(oper_func_t handler)
2361 if (of_used == of_size) {
2364 of_list = realloc(of_list, of_size*sizeof(oper_func_t));
2367 of_list = malloc(of_size*sizeof(oper_func_t));
2370 of_list[of_used++] = handler;
2374 call_oper_funcs(struct userNode *user)
2379 for (n=0; n<of_used; n++)
2386 unsigned int i, hop, max_hop=1;
2389 /* burst (juped) servers, closest first (except self, which is sent already) */
2390 for (i=0; i<ArrayLength(servers_num); i++)
2391 if (servers_num[i] && servers_num[i]->hops > max_hop)
2392 max_hop = servers_num[i]->hops;
2393 for (hop=1; hop<=max_hop; hop++) {
2394 for (i=0;i<ArrayLength(servers_num);i++) {
2396 && (servers_num[i]->hops == hop)
2397 && (servers_num[i] != self->uplink))
2398 irc_server(servers_num[i]);
2402 /* burst local nicks */
2403 for (i=0; i<=self->num_mask; i++)
2405 irc_user(self->users[i]);
2407 /* build dict of unbursted channel names (just copy existing channels) */
2408 unbursted_channels = dict_new();
2409 for (it = dict_first(channels); it; it = iter_next(it))
2410 dict_insert(unbursted_channels, iter_key(it), iter_data(it));