2 * ngIRCd -- The Next Generation IRC Daemon
3 * Copyright (c)2001-2013 Alexander Barton (alex@barton.de) and Contributors.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 * Please read the file COPYING, README and AUTHORS for more information.
28 #include "conn-func.h"
41 #include "irc-write.h"
42 #include "client-cap.h"
50 t_diff(time_t *t, const time_t d)
58 return (unsigned int)diff;
62 uptime_days(time_t *now)
64 return t_diff(now, 60 * 60 * 24);
68 uptime_hrs(time_t *now)
70 return t_diff(now, 60 * 60);
74 uptime_mins(time_t *now)
76 return t_diff(now, 60);
80 write_whoreply(CLIENT *Client, CLIENT *c, const char *channelname, const char *flags)
82 return IRC_WriteStrClient(Client, RPL_WHOREPLY_MSG, Client_ID(Client),
83 channelname, Client_User(c),
84 Client_HostnameDisplayed(c),
85 Client_ID(Client_Introducer(c)), Client_ID(c),
86 flags, Client_Hops(c), Client_Info(c));
90 who_flags_status(const char *client_modes)
92 if (strchr(client_modes, 'a'))
93 return "G"; /* away */
98 * Return channel user mode prefix(es).
100 * @param Client The client requesting the mode prefixes.
101 * @param chan_user_modes String with channel user modes.
102 * @param str String buffer to which the prefix(es) will be appended.
103 * @param len Size of "str" buffer.
104 * @return Pointer to "str".
107 who_flags_qualifier(CLIENT *Client, const char *chan_user_modes,
108 char *str, size_t len)
110 assert(Client != NULL);
112 if (Client_Cap(Client) & CLIENT_CAP_MULTI_PREFIX) {
113 if (strchr(chan_user_modes, 'q'))
114 strlcat(str, "~", len);
115 if (strchr(chan_user_modes, 'a'))
116 strlcat(str, "&", len);
117 if (strchr(chan_user_modes, 'o'))
118 strlcat(str, "@", len);
119 if (strchr(chan_user_modes, 'h'))
120 strlcat(str, "%", len);
121 if (strchr(chan_user_modes, 'v'))
122 strlcat(str, "+", len);
127 if (strchr(chan_user_modes, 'q'))
128 strlcat(str, "~", len);
129 else if (strchr(chan_user_modes, 'a'))
130 strlcat(str, "&", len);
131 else if (strchr(chan_user_modes, 'o'))
132 strlcat(str, "@", len);
133 else if (strchr(chan_user_modes, 'h'))
134 strlcat(str, "%", len);
135 else if (strchr(chan_user_modes, 'v'))
136 strlcat(str, "+", len);
142 * Send WHO reply for a "channel target" ("WHO #channel").
144 * @param Client Client requesting the information.
145 * @param Chan Channel being requested.
146 * @param OnlyOps Only display IRC operators.
147 * @return CONNECTED or DISCONNECTED.
150 IRC_WHO_Channel(CLIENT *Client, CHANNEL *Chan, bool OnlyOps)
152 bool is_visible, is_member, is_ircop;
154 const char *client_modes;
159 assert( Client != NULL );
160 assert( Chan != NULL );
162 IRC_SetPenalty(Client, 1);
164 is_member = Channel_IsMemberOf(Chan, Client);
166 /* Secret channel? */
167 if (!is_member && strchr(Channel_Modes(Chan), 's'))
168 return IRC_WriteStrClient(Client, RPL_ENDOFWHO_MSG,
169 Client_ID(Client), Channel_Name(Chan));
171 cl2chan = Channel_FirstMember(Chan);
172 for (; cl2chan ; cl2chan = Channel_NextMember(Chan, cl2chan)) {
173 c = Channel_GetClient(cl2chan);
175 client_modes = Client_Modes(c);
176 is_ircop = strchr(client_modes, 'o') != NULL;
177 if (OnlyOps && !is_ircop)
180 is_visible = strchr(client_modes, 'i') == NULL;
181 if (is_member || is_visible) {
182 strlcpy(flags, who_flags_status(client_modes),
185 strlcat(flags, "*", sizeof(flags));
187 who_flags_qualifier(Client, Channel_UserModes(Chan, c),
188 flags, sizeof(flags));
190 if (!write_whoreply(Client, c, Channel_Name(Chan),
197 /* If there are a lot of clients, augment penalty a bit */
198 if (count > MAX_RPL_WHO)
199 IRC_SetPenalty(Client, 1);
201 return IRC_WriteStrClient(Client, RPL_ENDOFWHO_MSG, Client_ID(Client),
206 * Send WHO reply for a "mask target" ("WHO m*sk").
208 * @param Client Client requesting the information.
209 * @param Mask Mask being requested or NULL for "all" clients.
210 * @param OnlyOps Only display IRC operators.
211 * @return CONNECTED or DISCONNECTED.
214 IRC_WHO_Mask(CLIENT *Client, char *Mask, bool OnlyOps)
219 bool client_match, is_visible;
223 assert (Client != NULL);
228 IRC_SetPenalty(Client, 3);
229 for (c = Client_First(); c != NULL; c = Client_Next(c)) {
230 if (Client_Type(c) != CLIENT_USER)
233 if (OnlyOps && !Client_HasMode(c, 'o'))
237 /* Match pattern against user host/server/name/nick */
238 client_match = MatchCaseInsensitive(Mask,
241 client_match = MatchCaseInsensitive(Mask,
242 Client_ID(Client_Introducer(c)));
244 client_match = MatchCaseInsensitive(Mask,
247 client_match = MatchCaseInsensitive(Mask,
250 continue; /* no match: skip this client */
253 is_visible = !Client_HasMode(c, 'i');
255 /* Target client is invisible, but mask matches exactly? */
256 if (!is_visible && Mask && strcasecmp(Client_ID(c), Mask) == 0)
259 /* Target still invisible, but are both on the same channel? */
261 cl2chan = Channel_FirstChannelOf(Client);
262 while (cl2chan && !is_visible) {
263 chan = Channel_GetChannel(cl2chan);
264 if (Channel_IsMemberOf(chan, c))
266 cl2chan = Channel_NextChannelOf(Client, cl2chan);
270 if (!is_visible) /* target user is not visible */
273 if (IRC_CheckListTooBig(Client, count, MAX_RPL_WHO, "WHO"))
276 strlcpy(flags, who_flags_status(Client_Modes(c)), sizeof(flags));
277 if (strchr(Client_Modes(c), 'o'))
278 strlcat(flags, "*", sizeof(flags));
280 if (!write_whoreply(Client, c, "*", flags))
285 return IRC_WriteStrClient(Client, RPL_ENDOFWHO_MSG, Client_ID(Client),
290 * Generate WHOIS reply of one actual client.
292 * @param Client The client from which this command has been received.
293 * @param from The client requesting the information ("originator").
294 * @param c The client of which information should be returned.
295 * @return CONNECTED or DISCONNECTED.
298 IRC_WHOIS_SendReply(CLIENT *Client, CLIENT *from, CLIENT *c)
300 char str[LINE_LEN + 1];
304 assert(Client != NULL);
305 assert(from != NULL);
308 /* Nick, user, hostname and client info */
309 if (!IRC_WriteStrClient(from, RPL_WHOISUSER_MSG, Client_ID(from),
310 Client_ID(c), Client_User(c),
311 Client_HostnameDisplayed(c), Client_Info(c)))
315 if (!IRC_WriteStrClient(from, RPL_WHOISSERVER_MSG, Client_ID(from),
316 Client_ID(c), Client_ID(Client_Introducer(c)),
317 Client_Info(Client_Introducer(c))))
321 snprintf(str, sizeof(str), RPL_WHOISCHANNELS_MSG,
322 Client_ID(from), Client_ID(c));
323 cl2chan = Channel_FirstChannelOf(c);
325 chan = Channel_GetChannel(cl2chan);
326 assert(chan != NULL);
329 cl2chan = Channel_NextChannelOf(c, cl2chan);
331 /* Secret channel? */
332 if (strchr(Channel_Modes(chan), 's')
333 && !Channel_IsMemberOf(chan, Client))
336 /* Local channel and request is not from a user? */
337 if (Client_Type(Client) == CLIENT_SERVER
338 && Channel_IsLocal(chan))
341 /* Concatenate channel names */
342 if (str[strlen(str) - 1] != ':')
343 strlcat(str, " ", sizeof(str));
345 who_flags_qualifier(Client, Channel_UserModes(chan, c),
347 strlcat(str, Channel_Name(chan), sizeof(str));
349 if (strlen(str) > (LINE_LEN - CHANNEL_NAME_LEN - 4)) {
350 /* Line becomes too long: send it! */
351 if (!IRC_WriteStrClient(Client, "%s", str))
353 snprintf(str, sizeof(str), RPL_WHOISCHANNELS_MSG,
354 Client_ID(from), Client_ID(c));
357 if(str[strlen(str) - 1] != ':') {
358 /* There is data left to send: */
359 if (!IRC_WriteStrClient(Client, "%s", str))
364 if (Client_HasMode(c, 'o') &&
365 !IRC_WriteStrClient(from, RPL_WHOISOPERATOR_MSG,
366 Client_ID(from), Client_ID(c)))
370 if (Client_HasMode(c, 'B') &&
371 !IRC_WriteStrClient(from, RPL_WHOISBOT_MSG,
372 Client_ID(from), Client_ID(c)))
375 /* Connected using SSL? */
376 if (Conn_UsesSSL(Client_Conn(c)) &&
377 !IRC_WriteStrClient(from, RPL_WHOISSSL_MSG, Client_ID(from),
381 /* Registered nickname? */
382 if (Client_HasMode(c, 'R') &&
383 !IRC_WriteStrClient(from, RPL_WHOISREGNICK_MSG,
384 Client_ID(from), Client_ID(c)))
387 /* Local client and requester is the user itself or an IRC Op? */
388 if (Client_Conn(c) > NONE &&
389 (from == c || (!Conf_MorePrivacy && Client_HasMode(from, 'o')))) {
390 /* Client hostname */
391 if (!IRC_WriteStrClient(from, RPL_WHOISHOST_MSG,
392 Client_ID(from), Client_ID(c), Client_Hostname(c),
393 Conn_GetIPAInfo(Client_Conn(c))))
396 if (!IRC_WriteStrClient(from, RPL_WHOISMODES_MSG,
397 Client_ID(from), Client_ID(c), Client_Modes(c)))
401 /* Idle and signon time (local clients only!) */
402 if (!Conf_MorePrivacy && Client_Conn(c) > NONE &&
403 !IRC_WriteStrClient(from, RPL_WHOISIDLE_MSG,
404 Client_ID(from), Client_ID(c),
405 (unsigned long)Conn_GetIdle(Client_Conn(c)),
406 (unsigned long)Conn_GetSignon(Client_Conn(c))))
410 if (Client_HasMode(c, 'a') &&
411 !IRC_WriteStrClient(from, RPL_AWAY_MSG,
412 Client_ID(from), Client_ID(c), Client_Away(c)))
419 WHOWAS_EntryWrite(CLIENT *prefix, WHOWAS *entry)
423 (void)strftime(t_str, sizeof(t_str), "%a %b %d %H:%M:%S %Y",
424 localtime(&entry->time));
426 if (!IRC_WriteStrClient(prefix, RPL_WHOWASUSER_MSG, Client_ID(prefix),
427 entry->id, entry->user, entry->host, entry->info))
430 return IRC_WriteStrClient(prefix, RPL_WHOISSERVER_MSG, Client_ID(prefix),
431 entry->id, entry->server, t_str);
435 Show_MOTD_Start(CLIENT *Client)
437 return IRC_WriteStrClient(Client, RPL_MOTDSTART_MSG,
438 Client_ID( Client ), Client_ID( Client_ThisServer( )));
442 Show_MOTD_Sendline(CLIENT *Client, const char *msg)
444 return IRC_WriteStrClient(Client, RPL_MOTD_MSG, Client_ID( Client ), msg);
448 Show_MOTD_End(CLIENT *Client)
450 if (!IRC_WriteStrClient(Client, RPL_ENDOFMOTD_MSG, Client_ID(Client)))
454 return IRC_WriteStrClient(Client, RPL_HOSTHIDDEN_MSG,
456 Client_Hostname(Client));
462 static bool Show_MOTD_SSLInfo(CLIENT *Client)
465 char buf[COMMAND_LEN] = "Connected using Cipher ";
467 if (!Conn_GetCipherInfo(Client_Conn(Client), buf + 23, sizeof buf - 23))
470 if (!Show_MOTD_Sendline(Client, buf))
477 Show_MOTD_SSLInfo(UNUSED CLIENT *c)
481 /* Global functions */
484 * Handler for the IRC command "ADMIN".
486 * @param Client The client from which this command has been received.
487 * @param Req Request structure with prefix and all parameters.
488 * @return CONNECTED or DISCONNECTED.
491 IRC_ADMIN(CLIENT *Client, REQUEST *Req )
493 CLIENT *target, *prefix;
495 assert( Client != NULL );
496 assert( Req != NULL );
498 if(( Req->argc > 1 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
500 /* find target ... */
501 if( Req->argc == 1 ) target = Client_Search( Req->argv[0] );
502 else target = Client_ThisServer( );
505 if( Client_Type( Client ) == CLIENT_SERVER ) prefix = Client_Search( Req->prefix );
506 else prefix = Client;
507 if( ! prefix ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
509 /* forwad message to another server? */
510 if( target != Client_ThisServer( ))
512 if(( ! target ) || ( Client_Type( target ) != CLIENT_SERVER )) return IRC_WriteStrClient( prefix, ERR_NOSUCHSERVER_MSG, Client_ID( prefix ), Req->argv[0] );
515 IRC_WriteStrClientPrefix( target, prefix, "ADMIN %s", Req->argv[0] );
519 /* mit Versionsinfo antworten */
520 if( ! IRC_WriteStrClient( Client, RPL_ADMINME_MSG, Client_ID( prefix ), Conf_ServerName )) return DISCONNECTED;
521 if( ! IRC_WriteStrClient( Client, RPL_ADMINLOC1_MSG, Client_ID( prefix ), Conf_ServerAdmin1 )) return DISCONNECTED;
522 if( ! IRC_WriteStrClient( Client, RPL_ADMINLOC2_MSG, Client_ID( prefix ), Conf_ServerAdmin2 )) return DISCONNECTED;
523 if( ! IRC_WriteStrClient( Client, RPL_ADMINEMAIL_MSG, Client_ID( prefix ), Conf_ServerAdminMail )) return DISCONNECTED;
525 IRC_SetPenalty( Client, 1 );
530 * Handler for the IRC command "INFO".
532 * @param Client The client from which this command has been received.
533 * @param Req Request structure with prefix and all parameters.
534 * @return CONNECTED or DISCONNECTED.
537 IRC_INFO(CLIENT * Client, REQUEST * Req)
539 CLIENT *target, *prefix;
542 assert(Client != NULL);
545 /* Wrong number of parameters? */
547 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
548 Client_ID(Client), Req->command);
550 /* Determine prefix */
551 if (Client_Type(Client) == CLIENT_SERVER)
552 prefix = Client_Search(Req->prefix);
556 return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG,
557 Client_ID(Client), Req->prefix);
559 /* Look for a target */
561 target = Client_Search(Req->argv[0]);
563 target = Client_ThisServer();
565 /* Make sure that the target is a server */
566 if (target && Client_Type(target) != CLIENT_SERVER)
567 target = Client_Introducer(target);
570 return IRC_WriteStrClient(prefix, ERR_NOSUCHSERVER_MSG,
571 Client_ID(prefix), Req->argv[0]);
573 /* Pass on to another server? */
574 if (target != Client_ThisServer()) {
575 IRC_WriteStrClientPrefix(target, prefix, "INFO %s",
580 if (!IRC_WriteStrClient(Client, RPL_INFO_MSG, Client_ID(prefix),
584 #if defined(__DATE__) && defined(__TIME__)
585 snprintf(msg, sizeof(msg), "Birth Date: %s at %s", __DATE__, __TIME__);
586 if (!IRC_WriteStrClient(Client, RPL_INFO_MSG, Client_ID(prefix), msg))
590 strlcpy(msg, "On-line since ", sizeof(msg));
591 strlcat(msg, NGIRCd_StartStr, sizeof(msg));
592 if (!IRC_WriteStrClient(Client, RPL_INFO_MSG, Client_ID(prefix), msg))
595 if (!IRC_WriteStrClient(Client, RPL_ENDOFINFO_MSG, Client_ID(prefix)))
598 IRC_SetPenalty(Client, 2);
603 * Handler for the IRC "ISON" command.
605 * @param Client The client from which this command has been received.
606 * @param Req Request structure with prefix and all parameters.
607 * @return CONNECTED or DISCONNECTED.
610 IRC_ISON( CLIENT *Client, REQUEST *Req )
612 char rpl[COMMAND_LEN];
617 assert(Client != NULL);
620 /* Bad number of arguments? */
622 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
623 Client_ID(Client), Req->command);
625 strlcpy(rpl, RPL_ISON_MSG, sizeof rpl);
626 for (i = 0; i < Req->argc; i++) {
627 /* "All" ircd even parse ":<x> <y> ..." arguments and split
628 * them up; so we do the same ... */
629 ptr = strtok(Req->argv[i], " ");
632 c = Client_Search(ptr);
633 if (c && Client_Type(c) == CLIENT_USER) {
634 strlcat(rpl, Client_ID(c), sizeof(rpl));
635 strlcat(rpl, " ", sizeof(rpl));
637 ptr = strtok(NULL, " ");
640 ngt_TrimLastChr(rpl, ' ');
642 return IRC_WriteStrClient(Client, rpl, Client_ID(Client));
646 * Handler for the IRC "LINKS" command.
648 * @param Client The client from which this command has been received.
649 * @param Req Request structure with prefix and all parameters.
650 * @return CONNECTED or DISCONNECTED.
653 IRC_LINKS(CLIENT *Client, REQUEST *Req)
655 CLIENT *target, *from, *c;
658 assert(Client != NULL);
661 IRC_SetPenalty(Client, 1);
664 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
665 Client_ID(Client), Req->command);
667 /* Get pointer to server mask or "*", if none given */
669 mask = Req->argv[Req->argc - 1];
673 if (Client_Type(Client) == CLIENT_SERVER)
674 from = Client_Search(Req->prefix);
678 return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG,
679 Client_ID(Client), Req->prefix);
682 if (Req->argc == 2) {
683 target = Client_Search(Req->argv[0]);
684 if (! target || Client_Type(target) != CLIENT_SERVER)
685 return IRC_WriteStrClient(from, ERR_NOSUCHSERVER_MSG,
689 if (target != Client_ThisServer())
690 return IRC_WriteStrClientPrefix(target, from,
691 "LINKS %s %s", Req->argv[0],
697 if (Client_Type(c) == CLIENT_SERVER
698 && MatchCaseInsensitive(mask, Client_ID(c))) {
699 if (!IRC_WriteStrClient(from, RPL_LINKS_MSG,
700 Client_ID(from), Client_ID(c),
701 Client_ID(Client_TopServer(c)
702 ? Client_TopServer(c)
703 : Client_ThisServer()),
704 Client_Hops(c), Client_Info(c)))
709 return IRC_WriteStrClient(from, RPL_ENDOFLINKS_MSG,
710 Client_ID(from), mask);
714 * Handler for the IRC "LUSERS" command.
716 * @param Client The client from which this command has been received.
717 * @param Req Request structure with prefix and all parameters.
718 * @return CONNECTED or DISCONNECTED.
721 IRC_LUSERS( CLIENT *Client, REQUEST *Req )
723 CLIENT *target, *from;
725 assert( Client != NULL );
726 assert( Req != NULL );
728 if(( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
730 /* Absender ermitteln */
731 if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
733 if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
735 /* An anderen Server forwarden? */
738 target = Client_Search( Req->argv[1] );
739 if(( ! target ) || ( Client_Type( target ) != CLIENT_SERVER )) return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[1] );
740 else if( target != Client_ThisServer( )) return IRC_WriteStrClientPrefix( target, from, "LUSERS %s %s", Req->argv[0], Req->argv[1] );
743 /* Wer ist der Absender? */
744 if( Client_Type( Client ) == CLIENT_SERVER ) target = Client_Search( Req->prefix );
745 else target = Client;
746 if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
748 IRC_Send_LUSERS( target );
750 IRC_SetPenalty( target, 1 );
755 * Handler for the IRC command "SERVLIST".
757 * @param Client The client from which this command has been received.
758 * @param Req Request structure with prefix and all parameters.
759 * @return CONNECTED or DISCONNECTED.
762 IRC_SERVLIST(CLIENT *Client, REQUEST *Req)
766 assert(Client != NULL);
770 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
771 Client_ID(Client), Req->command);
773 if (Req->argc < 2 || strcmp(Req->argv[1], "0") == 0) {
774 for (c = Client_First(); c!= NULL; c = Client_Next(c)) {
775 if (Client_Type(c) != CLIENT_SERVICE)
777 if (Req->argc > 0 && !MatchCaseInsensitive(Req->argv[0],
780 if (!IRC_WriteStrClient(Client, RPL_SERVLIST_MSG,
781 Client_ID(Client), Client_Mask(c),
782 Client_Mask(Client_Introducer(c)), "*",
783 0, Client_Hops(c), Client_Info(c)))
788 return IRC_WriteStrClient(Client, RPL_SERVLISTEND_MSG, Client_ID(Client),
789 Req->argc > 0 ? Req->argv[0] : "*",
790 Req->argc > 1 ? Req->argv[1] : "0");
794 * Handler for the IRC command "MOTD".
796 * @param Client The client from which this command has been received.
797 * @param Req Request structure with prefix and all parameters.
798 * @return CONNECTED or DISCONNECTED.
801 IRC_MOTD( CLIENT *Client, REQUEST *Req )
803 CLIENT *from, *target;
805 assert( Client != NULL );
806 assert( Req != NULL );
808 if( Req->argc > 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
810 /* From aus Prefix ermitteln */
811 if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
813 if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
818 target = Client_Search( Req->argv[0] );
819 if(( ! target ) || ( Client_Type( target ) != CLIENT_SERVER )) return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[0] );
821 if( target != Client_ThisServer( ))
823 /* Ok, anderer Server ist das Ziel: forwarden */
824 return IRC_WriteStrClientPrefix( target, from, "MOTD %s", Req->argv[0] );
828 IRC_SetPenalty( from, 3 );
829 return IRC_Show_MOTD( from );
833 * Handler for the IRC command "NAMES".
835 * @param Client The client from which this command has been received.
836 * @param Req Request structure with prefix and all parameters.
837 * @return CONNECTED or DISCONNECTED.
840 IRC_NAMES( CLIENT *Client, REQUEST *Req )
842 char rpl[COMMAND_LEN], *ptr;
843 CLIENT *target, *from, *c;
846 assert( Client != NULL );
847 assert( Req != NULL );
849 if( Req->argc > 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
851 /* use prefix to determine "From" */
852 if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
854 if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
858 /* forward to another server? */
859 target = Client_Search( Req->argv[1] );
860 if(( ! target ) || ( Client_Type( target ) != CLIENT_SERVER )) return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[1] );
862 if( target != Client_ThisServer( )) {
863 /* target is another server, forward */
864 return IRC_WriteStrClientPrefix( target, from, "NAMES %s :%s", Req->argv[0], Req->argv[1] );
870 /* bestimmte Channels durchgehen */
871 ptr = strtok( Req->argv[0], "," );
874 chan = Channel_Search( ptr );
878 if( ! IRC_Send_NAMES( from, chan )) return DISCONNECTED;
880 if( ! IRC_WriteStrClient( from, RPL_ENDOFNAMES_MSG, Client_ID( from ), ptr )) return DISCONNECTED;
882 /* get next channel name */
883 ptr = strtok( NULL, "," );
888 chan = Channel_First( );
891 if( ! IRC_Send_NAMES( from, chan )) return DISCONNECTED;
893 chan = Channel_Next( chan );
896 /* Now print all clients which are not in any channel */
898 snprintf( rpl, sizeof( rpl ), RPL_NAMREPLY_MSG, Client_ID( from ), "*", "*" );
901 if(( Client_Type( c ) == CLIENT_USER ) && ( Channel_FirstChannelOf( c ) == NULL ) && ( ! strchr( Client_Modes( c ), 'i' )))
903 /* its a user, concatenate ... */
904 if( rpl[strlen( rpl ) - 1] != ':' ) strlcat( rpl, " ", sizeof( rpl ));
905 strlcat( rpl, Client_ID( c ), sizeof( rpl ));
907 if( strlen( rpl ) > ( LINE_LEN - CLIENT_NICK_LEN - 4 ))
909 /* Line is gwoing too long, send now */
910 if( ! IRC_WriteStrClient( from, "%s", rpl )) return DISCONNECTED;
911 snprintf( rpl, sizeof( rpl ), RPL_NAMREPLY_MSG, Client_ID( from ), "*", "*" );
915 c = Client_Next( c );
917 if( rpl[strlen( rpl ) - 1] != ':')
919 if( ! IRC_WriteStrClient( from, "%s", rpl )) return DISCONNECTED;
922 IRC_SetPenalty( from, 1 );
923 return IRC_WriteStrClient( from, RPL_ENDOFNAMES_MSG, Client_ID( from ), "*" );
927 * Handler for the IRC command "STATS".
929 * @param Client The client from which this command has been received.
930 * @param Req Request structure with prefix and all parameters.
931 * @return CONNECTED or DISCONNECTED.
934 IRC_STATS( CLIENT *Client, REQUEST *Req )
936 CLIENT *from, *target, *cl;
941 unsigned int days, hrs, mins;
942 struct list_head *list;
943 struct list_elem *list_item;
945 assert(Client != NULL);
949 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
950 Client_ID(Client), Req->command);
952 /* use prefix to determine "From" */
953 if (Client_Type(Client) == CLIENT_SERVER)
954 from = Client_Search(Req->prefix);
959 return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG,
960 Client_ID(Client), Req->prefix);
962 if (Req->argc == 2) {
963 /* forward to another server? */
964 target = Client_Search(Req->argv[1]);
965 if ((!target) || (Client_Type(target) != CLIENT_SERVER))
966 return IRC_WriteStrClient(from, ERR_NOSUCHSERVER_MSG,
967 Client_ID(from), Req->argv[1]);
969 if (target != Client_ThisServer()) {
970 /* forward to another server */
971 return IRC_WriteStrClientPrefix(target, from,
972 "STATS %s %s", Req->argv[0], Req->argv[1]);
977 query = Req->argv[0][0] ? Req->argv[0][0] : '*';
982 case 'g': /* Network-wide bans ("G-Lines") */
984 case 'k': /* Server-local bans ("K-Lines") */
986 if (!Client_HasMode(from, 'o'))
987 return IRC_WriteStrClient(from, ERR_NOPRIVILEGES_MSG,
989 if (query == 'g' || query == 'G')
990 list = Class_GetList(CLASS_GLINE);
992 list = Class_GetList(CLASS_KLINE);
993 list_item = Lists_GetFirst(list);
995 if (!IRC_WriteStrClient(from, RPL_STATSXLINE_MSG,
996 Client_ID(from), query,
997 Lists_GetMask(list_item),
998 Lists_GetValidity(list_item),
999 Lists_GetReason(list_item)))
1000 return DISCONNECTED;
1001 list_item = Lists_GetNext(list_item);
1004 case 'l': /* Link status (servers and own link) */
1006 time_now = time(NULL);
1007 for (con = Conn_First(); con != NONE; con = Conn_Next(con)) {
1008 cl = Conn_GetClient(con);
1011 if ((Client_Type(cl) == CLIENT_SERVER)
1012 || (cl == Client)) {
1013 /* Server link or our own connection */
1015 if (Conn_Options(con) & CONN_ZIP) {
1016 if (!IRC_WriteStrClient
1017 (from, RPL_STATSLINKINFOZIP_MSG,
1018 Client_ID(from), Client_Mask(cl),
1019 Conn_SendQ(con), Conn_SendMsg(con),
1021 Conn_SendBytes(con),
1024 Conn_RecvBytes(con),
1025 (long)(time_now - Conn_StartTime(con))))
1026 return DISCONNECTED;
1030 if (!IRC_WriteStrClient
1031 (from, RPL_STATSLINKINFO_MSG,
1032 Client_ID(from), Client_Mask(cl),
1033 Conn_SendQ(con), Conn_SendMsg(con),
1034 Conn_SendBytes(con), Conn_RecvMsg(con),
1035 Conn_RecvBytes(con),
1036 (long)(time_now - Conn_StartTime(con))))
1037 return DISCONNECTED;
1041 case 'm': /* IRC command status (usage count) */
1043 cmd = Parse_GetCommandStruct();
1044 for (; cmd->name; cmd++) {
1045 if (cmd->lcount == 0 && cmd->rcount == 0)
1047 if (!IRC_WriteStrClient
1048 (from, RPL_STATSCOMMANDS_MSG, Client_ID(from),
1049 cmd->name, cmd->lcount, cmd->bytes, cmd->rcount))
1050 return DISCONNECTED;
1053 case 'u': /* Server uptime */
1055 time_now = time(NULL) - NGIRCd_Start;
1056 days = uptime_days(&time_now);
1057 hrs = uptime_hrs(&time_now);
1058 mins = uptime_mins(&time_now);
1059 if (!IRC_WriteStrClient(from, RPL_STATSUPTIME, Client_ID(from),
1060 days, hrs, mins, (unsigned int)time_now))
1061 return DISCONNECTED;
1065 IRC_SetPenalty(from, 2);
1066 return IRC_WriteStrClient(from, RPL_ENDOFSTATS_MSG,
1067 Client_ID(from), query);
1071 * Handler for the IRC command "SUMMON".
1073 * @param Client The client from which this command has been received.
1074 * @param Req Request structure with prefix and all parameters.
1075 * @return CONNECTED or DISCONNECTED.
1078 IRC_SUMMON(CLIENT * Client, UNUSED REQUEST * Req)
1080 return IRC_WriteStrClient(Client, ERR_SUMMONDISABLED_MSG,
1085 * Handler for the IRC command "TIME".
1087 * @param Client The client from which this command has been received.
1088 * @param Req Request structure with prefix and all parameters.
1089 * @return CONNECTED or DISCONNECTED.
1092 IRC_TIME( CLIENT *Client, REQUEST *Req )
1094 CLIENT *from, *target;
1098 assert( Client != NULL );
1099 assert( Req != NULL );
1101 if( Req->argc > 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
1103 if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
1105 if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
1107 if( Req->argc == 1 )
1109 target = Client_Search( Req->argv[0] );
1110 if(( ! target ) || ( Client_Type( target ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[0] );
1112 if( target != Client_ThisServer( ))
1114 return IRC_WriteStrClientPrefix( target, from, "TIME %s", Req->argv[0] );
1119 (void)strftime( t_str, 60, "%A %B %d %Y -- %H:%M %Z", localtime( &t ));
1120 return IRC_WriteStrClient( from, RPL_TIME_MSG, Client_ID( from ), Client_ID( Client_ThisServer( )), t_str );
1124 * Handler for the IRC command "USERHOST".
1126 * @param Client The client from which this command has been received.
1127 * @param Req Request structure with prefix and all parameters.
1128 * @return CONNECTED or DISCONNECTED.
1131 IRC_USERHOST(CLIENT *Client, REQUEST *Req)
1133 char rpl[COMMAND_LEN];
1137 assert(Client != NULL);
1138 assert(Req != NULL);
1140 if ((Req->argc < 1))
1141 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
1142 Client_ID(Client), Req->command);
1149 strlcpy(rpl, RPL_USERHOST_MSG, sizeof rpl);
1150 for (i = 0; i < max; i++) {
1151 c = Client_Search(Req->argv[i]);
1152 if (c && (Client_Type(c) == CLIENT_USER)) {
1153 /* This Nick is "online" */
1154 strlcat(rpl, Client_ID(c), sizeof(rpl));
1155 if (Client_HasMode(c, 'o'))
1156 strlcat(rpl, "*", sizeof(rpl));
1157 strlcat(rpl, "=", sizeof(rpl));
1158 if (Client_HasMode(c, 'a'))
1159 strlcat(rpl, "-", sizeof(rpl));
1161 strlcat(rpl, "+", sizeof(rpl));
1162 strlcat(rpl, Client_User(c), sizeof(rpl));
1163 strlcat(rpl, "@", sizeof(rpl));
1164 strlcat(rpl, Client_HostnameDisplayed(c), sizeof(rpl));
1165 strlcat(rpl, " ", sizeof(rpl));
1168 ngt_TrimLastChr(rpl, ' ');
1170 return IRC_WriteStrClient(Client, rpl, Client_ID(Client));
1171 } /* IRC_USERHOST */
1174 * Handler for the IRC command "USERS".
1176 * @param Client The client from which this command has been received.
1177 * @param Req Request structure with prefix and all parameters.
1178 * @return CONNECTED or DISCONNECTED.
1181 IRC_USERS(CLIENT * Client, UNUSED REQUEST * Req)
1183 return IRC_WriteStrClient(Client, ERR_USERSDISABLED_MSG,
1188 * Handler for the IRC command "VERSION".
1190 * @param Client The client from which this command has been received.
1191 * @param Req Request structure with prefix and all parameters.
1192 * @return CONNECTED or DISCONNECTED.
1195 IRC_VERSION( CLIENT *Client, REQUEST *Req )
1197 CLIENT *target, *prefix;
1199 assert( Client != NULL );
1200 assert( Req != NULL );
1202 if(( Req->argc > 1 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
1205 if( Req->argc == 1 ) target = Client_Search( Req->argv[0] );
1206 else target = Client_ThisServer( );
1208 /* Prefix ermitteln */
1209 if( Client_Type( Client ) == CLIENT_SERVER ) prefix = Client_Search( Req->prefix );
1210 else prefix = Client;
1211 if( ! prefix ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
1213 /* An anderen Server weiterleiten? */
1214 if( target != Client_ThisServer( ))
1216 if(( ! target ) || ( Client_Type( target ) != CLIENT_SERVER )) return IRC_WriteStrClient( prefix, ERR_NOSUCHSERVER_MSG, Client_ID( prefix ), Req->argv[0] );
1219 IRC_WriteStrClientPrefix( target, prefix, "VERSION %s", Req->argv[0] );
1223 /* send version information */
1224 IRC_SetPenalty(Client, 1);
1225 return IRC_WriteStrClient(Client, RPL_VERSION_MSG, Client_ID(prefix),
1226 PACKAGE_NAME, PACKAGE_VERSION,
1227 NGIRCd_DebugLevel, Conf_ServerName,
1228 NGIRCd_VersionAddition);
1232 * Handler for the IRC "WHO" command.
1234 * @param Client The client from which this command has been received.
1235 * @param Req Request structure with prefix and all parameters.
1236 * @return CONNECTED or DISCONNECTED.
1239 IRC_WHO(CLIENT *Client, REQUEST *Req)
1244 assert (Client != NULL);
1245 assert (Req != NULL);
1248 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
1249 Client_ID(Client), Req->command);
1253 if (Req->argc == 2) {
1254 if (strcmp(Req->argv[1], "o") == 0)
1258 return IRC_WriteStrClient(Client,
1259 ERR_NEEDMOREPARAMS_MSG,
1265 IRC_SetPenalty(Client, 1);
1266 if (Req->argc >= 1) {
1267 /* Channel or mask given */
1268 chan = Channel_Search(Req->argv[0]);
1270 /* Members of a channel have been requested */
1271 return IRC_WHO_Channel(Client, chan, only_ops);
1273 if (strcmp(Req->argv[0], "0") != 0) {
1274 /* A mask has been given. But please note this RFC
1275 * stupidity: "0" is same as no arguments ... */
1276 return IRC_WHO_Mask(Client, Req->argv[0], only_ops);
1280 /* No channel or (valid) mask given */
1281 IRC_SetPenalty(Client, 2);
1282 return IRC_WHO_Mask(Client, NULL, only_ops);
1286 * Handler for the IRC "WHOIS" command.
1288 * @param Client The client from which this command has been received.
1289 * @param Req Request structure with prefix and all parameters.
1290 * @return CONNECTED or DISCONNECTED.
1293 IRC_WHOIS( CLIENT *Client, REQUEST *Req )
1295 CLIENT *from, *target, *c;
1296 unsigned int match_count = 0, found = 0;
1297 bool has_wildcards, is_remote;
1298 bool got_wildcard = false;
1299 char mask[COMMAND_LEN], *query;
1301 assert( Client != NULL );
1302 assert( Req != NULL );
1304 /* Bad number of parameters? */
1305 if (Req->argc < 1 || Req->argc > 2)
1306 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
1307 Client_ID(Client), Req->command);
1309 /* Search sender of the WHOIS */
1310 if (Client_Type(Client) == CLIENT_SERVER) {
1311 from = Client_Search(Req->prefix);
1313 IRC_SetPenalty(Client, 1);
1317 return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG,
1318 Client_ID(Client), Req->prefix);
1320 /* Get target server for this command */
1321 if (Req->argc > 1) {
1322 /* Search the target server, which can be specified as a
1323 * nickname on that server as well: */
1324 target = Client_Search(Req->argv[0]);
1326 return IRC_WriteStrClient(from, ERR_NOSUCHSERVER_MSG,
1327 Client_ID(from), Req->argv[0]);
1329 target = Client_ThisServer();
1330 assert(target != NULL);
1332 /* Forward to other server? */
1333 if (Client_NextHop(target) != Client_ThisServer() &&
1334 Client_Type(Client_NextHop(target)) == CLIENT_SERVER)
1335 return IRC_WriteStrClientPrefix(target, from,
1337 Req->argv[0], Req->argv[1]);
1339 is_remote = Client_Conn(from) < 0;
1340 strlcpy(mask, Req->argv[Req->argc - 1], sizeof(mask));
1341 for (query = strtok(ngt_LowerStr(mask), ",");
1343 query = strtok(NULL, ","), found++)
1345 has_wildcards = query[strcspn(query, "*?")] != 0;
1347 * follows ircd 2.10 implementation:
1348 * - handle up to 3 targets
1349 * - no wildcards for remote clients
1350 * - only one wildcard target per local client
1352 * Also, at most MAX_RPL_WHOIS matches are returned.
1354 if (!has_wildcards || is_remote) {
1355 c = Client_Search(query);
1356 if (c && Client_Type(c) == CLIENT_USER) {
1357 if (!IRC_WHOIS_SendReply(Client, from, c))
1358 return DISCONNECTED;
1360 if (!IRC_WriteStrClient(Client,
1364 return DISCONNECTED;
1369 /* we already handled one wildcard query */
1370 if (!IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG,
1371 Client_ID(Client), query))
1372 return DISCONNECTED;
1375 got_wildcard = true;
1376 IRC_SetPenalty(Client, 3);
1378 for (c = Client_First(); c; c = Client_Next(c)) {
1379 if (IRC_CheckListTooBig(Client, match_count,
1380 MAX_RPL_WHOIS, "WHOIS"))
1383 if (Client_Type(c) != CLIENT_USER)
1385 if (!MatchCaseInsensitive(query, Client_ID(c)))
1387 if (!IRC_WHOIS_SendReply(Client, from, c))
1388 return DISCONNECTED;
1393 if (match_count == 0)
1394 IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG,
1396 Req->argv[Req->argc - 1]);
1398 return IRC_WriteStrClient(from, RPL_ENDOFWHOIS_MSG,
1399 Client_ID(from), Req->argv[Req->argc - 1]);
1403 * Handler for the IRC "WHOWAS" command.
1405 * @param Client The client from which this command has been received.
1406 * @param Req Request structure with prefix and all parameters.
1407 * @return CONNECTED or DISCONNECTED.
1410 IRC_WHOWAS( CLIENT *Client, REQUEST *Req )
1412 CLIENT *target, *prefix;
1414 char tok_buf[COMMAND_LEN];
1415 int max, last, count, i, nc;
1418 assert( Client != NULL );
1419 assert( Req != NULL );
1421 /* Do not reveal any info on disconnected users? */
1422 if (Conf_MorePrivacy)
1425 /* Wrong number of parameters? */
1427 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
1428 Client_ID(Client), Req->command);
1430 return IRC_WriteStrClient(Client, ERR_NONICKNAMEGIVEN_MSG, Client_ID(Client));
1434 target = Client_Search(Req->argv[2]);
1436 target = Client_ThisServer();
1439 if (Client_Type(Client) == CLIENT_SERVER)
1440 prefix = Client_Search(Req->prefix);
1445 return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG,
1446 Client_ID(Client), Req->prefix);
1448 /* Forward to other server? */
1449 if (target != Client_ThisServer()) {
1450 if (!target || (Client_Type(target) != CLIENT_SERVER))
1451 return IRC_WriteStrClient(prefix, ERR_NOSUCHSERVER_MSG,
1452 Client_ID(prefix), Req->argv[2]);
1455 IRC_WriteStrClientPrefix( target, prefix, "WHOWAS %s %s %s",
1456 Req->argv[0], Req->argv[1],
1461 whowas = Client_GetWhowas( );
1462 last = Client_GetLastWhowasIndex( );
1466 max = DEF_RPL_WHOWAS;
1467 if (Req->argc > 1) {
1468 max = atoi(Req->argv[1]);
1470 max = MAX_RPL_WHOWAS;
1474 * Break up the nick argument into a list of nicks, if applicable
1475 * Can't modify Req->argv[0] because we need it for RPL_ENDOFWHOWAS_MSG.
1477 strlcpy(tok_buf, Req->argv[0], sizeof(tok_buf));
1478 nick = strtok(tok_buf, ",");
1480 for (i=last, count=0; nick != NULL ; nick = strtok(NULL, ",")) {
1484 if (whowas[i].time > 0 && strcasecmp(nick, whowas[i].id) == 0) {
1485 if (!WHOWAS_EntryWrite(prefix, &whowas[i]))
1486 return DISCONNECTED;
1490 /* previous entry */
1493 /* "underflow", wrap around */
1497 if (nc && count >= max)
1499 } while (i != last);
1501 if (nc == 0 && !IRC_WriteStrClient(prefix, ERR_WASNOSUCHNICK_MSG,
1502 Client_ID(prefix), nick))
1503 return DISCONNECTED;
1505 return IRC_WriteStrClient(prefix, RPL_ENDOFWHOWAS_MSG, Client_ID(prefix), Req->argv[0]);
1509 * Send LUSERS reply to a client.
1511 * @param Client The receipient of the information.
1512 * @return CONNECTED or DISCONNECTED.
1515 IRC_Send_LUSERS(CLIENT *Client)
1522 assert(Client != NULL);
1524 /* Users, services and serevers in the network */
1525 if (!IRC_WriteStrClient(Client, RPL_LUSERCLIENT_MSG, Client_ID(Client),
1526 Client_UserCount(), Client_ServiceCount(),
1527 Client_ServerCount()))
1528 return DISCONNECTED;
1530 /* Number of IRC operators */
1531 cnt = Client_OperCount( );
1533 if (!IRC_WriteStrClient(Client, RPL_LUSEROP_MSG,
1534 Client_ID(Client), cnt))
1535 return DISCONNECTED;
1538 /* Unknown connections */
1539 cnt = Client_UnknownCount( );
1541 if (!IRC_WriteStrClient(Client, RPL_LUSERUNKNOWN_MSG,
1542 Client_ID(Client), cnt))
1543 return DISCONNECTED;
1546 /* Number of created channels */
1547 if (!IRC_WriteStrClient(Client, RPL_LUSERCHANNELS_MSG,
1549 Channel_CountVisible(Client)))
1550 return DISCONNECTED;
1552 /* Number of local users, services and servers */
1553 if (!IRC_WriteStrClient(Client, RPL_LUSERME_MSG, Client_ID(Client),
1554 Client_MyUserCount(), Client_MyServiceCount(),
1555 Client_MyServerCount()))
1556 return DISCONNECTED;
1559 /* Maximum number of local users */
1560 cnt = Client_MyUserCount();
1561 max = Client_MyMaxUserCount();
1562 if (! IRC_WriteStrClient(Client, RPL_LOCALUSERS_MSG, Client_ID(Client),
1563 cnt, max, cnt, max))
1564 return DISCONNECTED;
1565 /* Maximum number of users in the network */
1566 cnt = Client_UserCount();
1567 max = Client_MaxUserCount();
1568 if(! IRC_WriteStrClient(Client, RPL_NETUSERS_MSG, Client_ID(Client),
1569 cnt, max, cnt, max))
1570 return DISCONNECTED;
1571 /* Connection counters */
1572 if (! IRC_WriteStrClient(Client, RPL_STATSCONN_MSG, Client_ID(Client),
1573 Conn_CountMax(), Conn_CountAccepted()))
1574 return DISCONNECTED;
1578 } /* IRC_Send_LUSERS */
1581 IRC_Show_MOTD( CLIENT *Client )
1584 size_t len_tot, len_str;
1586 assert( Client != NULL );
1588 len_tot = array_bytes(&Conf_Motd);
1589 if (len_tot == 0 && !Conn_UsesSSL(Client_Conn(Client)))
1590 return IRC_WriteStrClient(Client, ERR_NOMOTD_MSG, Client_ID(Client));
1592 if (!Show_MOTD_Start(Client))
1593 return DISCONNECTED;
1595 line = array_start(&Conf_Motd);
1596 while (len_tot > 0) {
1597 len_str = strlen(line) + 1;
1599 assert(len_tot >= len_str);
1602 if (!Show_MOTD_Sendline(Client, line))
1603 return DISCONNECTED;
1607 if (!Show_MOTD_SSLInfo(Client))
1608 return DISCONNECTED;
1609 return Show_MOTD_End(Client);
1610 } /* IRC_Show_MOTD */
1613 * Send NAMES reply for a specific client and channel.
1615 * @param Client The client requesting the NAMES information.
1616 * @param Chan The channel
1617 * @return CONNECTED or DISCONNECTED.
1620 IRC_Send_NAMES(CLIENT * Client, CHANNEL * Chan)
1622 bool is_visible, is_member;
1623 char str[LINE_LEN + 1];
1627 assert(Client != NULL);
1628 assert(Chan != NULL);
1630 if (Channel_IsMemberOf(Chan, Client))
1635 /* Do not print info on channel memberships to anyone that is not member? */
1636 if (Conf_MorePrivacy && !is_member)
1639 /* Secret channel? */
1640 if (!is_member && strchr(Channel_Modes(Chan), 's'))
1643 snprintf(str, sizeof(str), RPL_NAMREPLY_MSG, Client_ID(Client), "=",
1644 Channel_Name(Chan));
1645 cl2chan = Channel_FirstMember(Chan);
1647 cl = Channel_GetClient(cl2chan);
1649 if (strchr(Client_Modes(cl), 'i'))
1654 if (is_member || is_visible) {
1655 if (str[strlen(str) - 1] != ':')
1656 strlcat(str, " ", sizeof(str));
1658 who_flags_qualifier(Client, Channel_UserModes(Chan, cl),
1660 strlcat(str, Client_ID(cl), sizeof(str));
1662 if (strlen(str) > (LINE_LEN - CLIENT_NICK_LEN - 4)) {
1663 if (!IRC_WriteStrClient(Client, "%s", str))
1664 return DISCONNECTED;
1665 snprintf(str, sizeof(str), RPL_NAMREPLY_MSG,
1666 Client_ID(Client), "=",
1667 Channel_Name(Chan));
1671 cl2chan = Channel_NextMember(Chan, cl2chan);
1673 if (str[strlen(str) - 1] != ':') {
1674 if (!IRC_WriteStrClient(Client, "%s", str))
1675 return DISCONNECTED;
1679 } /* IRC_Send_NAMES */
1682 * Send the ISUPPORT numeric (005).
1683 * This numeric indicates the features that are supported by this server.
1684 * See <http://www.irc.org/tech_docs/005.html> for details.
1687 IRC_Send_ISUPPORT(CLIENT * Client)
1689 if (!IRC_WriteStrClient(Client, RPL_ISUPPORT1_MSG, Client_ID(Client),
1691 return DISCONNECTED;
1692 return IRC_WriteStrClient(Client, RPL_ISUPPORT2_MSG, Client_ID(Client),
1693 CHANNEL_NAME_LEN - 1, Conf_MaxNickLength - 1,
1694 COMMAND_LEN - 23, CLIENT_AWAY_LEN - 1,
1695 COMMAND_LEN - 113, MAX_HNDL_MODES_ARG,
1696 MAX_HNDL_CHANNEL_LISTS);
1697 } /* IRC_Send_ISUPPORT */