Blob


1 /*
2 * ngIRCd -- The Next Generation IRC Daemon
3 * Copyright (c)2001-2008 Alexander Barton (alex@barton.de)
4 *
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.
10 *
11 * IRC info commands
12 */
15 #include "portab.h"
17 #include "imp.h"
18 #include <assert.h>
19 #include <errno.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <strings.h>
25 #include "ngircd.h"
26 #include "conn-func.h"
27 #include "conn-zip.h"
28 #include "client.h"
29 #include "channel.h"
30 #include "resolve.h"
31 #include "conf.h"
32 #include "defines.h"
33 #include "log.h"
34 #include "messages.h"
35 #include "match.h"
36 #include "tool.h"
37 #include "parse.h"
38 #include "irc-write.h"
40 #include "exp.h"
41 #include "irc-info.h"
44 GLOBAL bool
45 IRC_ADMIN(CLIENT *Client, REQUEST *Req )
46 {
47 CLIENT *target, *prefix;
49 assert( Client != NULL );
50 assert( Req != NULL );
52 /* Falsche Anzahl Parameter? */
53 if(( Req->argc > 1 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
55 /* Ziel suchen */
56 if( Req->argc == 1 ) target = Client_Search( Req->argv[0] );
57 else target = Client_ThisServer( );
59 /* Prefix ermitteln */
60 if( Client_Type( Client ) == CLIENT_SERVER ) prefix = Client_Search( Req->prefix );
61 else prefix = Client;
62 if( ! prefix ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
64 /* An anderen Server weiterleiten? */
65 if( target != Client_ThisServer( ))
66 {
67 if(( ! target ) || ( Client_Type( target ) != CLIENT_SERVER )) return IRC_WriteStrClient( prefix, ERR_NOSUCHSERVER_MSG, Client_ID( prefix ), Req->argv[0] );
69 /* forwarden */
70 IRC_WriteStrClientPrefix( target, prefix, "ADMIN %s", Req->argv[0] );
71 return CONNECTED;
72 }
74 /* mit Versionsinfo antworten */
75 if( ! IRC_WriteStrClient( Client, RPL_ADMINME_MSG, Client_ID( prefix ), Conf_ServerName )) return DISCONNECTED;
76 if( ! IRC_WriteStrClient( Client, RPL_ADMINLOC1_MSG, Client_ID( prefix ), Conf_ServerAdmin1 )) return DISCONNECTED;
77 if( ! IRC_WriteStrClient( Client, RPL_ADMINLOC2_MSG, Client_ID( prefix ), Conf_ServerAdmin2 )) return DISCONNECTED;
78 if( ! IRC_WriteStrClient( Client, RPL_ADMINEMAIL_MSG, Client_ID( prefix ), Conf_ServerAdminMail )) return DISCONNECTED;
80 IRC_SetPenalty( Client, 1 );
81 return CONNECTED;
82 } /* IRC_ADMIN */
85 /**
86 * Handler for the IRC command "INFO".
87 * See RFC 2812 section 3.4.10.
88 */
89 GLOBAL bool
90 IRC_INFO(CLIENT * Client, REQUEST * Req)
91 {
92 CLIENT *target, *prefix;
93 char msg[510];
95 assert(Client != NULL);
96 assert(Req != NULL);
98 /* Wrong number of parameters? */
99 if (Req->argc > 1)
100 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
101 Client_ID(Client), Req->command);
103 /* Determine prefix */
104 if (Client_Type(Client) == CLIENT_SERVER)
105 prefix = Client_Search(Req->prefix);
106 else
107 prefix = Client;
108 if (!prefix)
109 return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG,
110 Client_ID(Client), Req->prefix);
112 /* Look for a target */
113 if (Req->argc > 0)
114 target = Client_Search(Req->argv[0]);
115 else
116 target = Client_ThisServer();
118 /* Make sure that the target is a server */
119 if (target && Client_Type(target) != CLIENT_SERVER)
120 target = Client_Introducer(target);
122 if (!target)
123 return IRC_WriteStrClient(prefix, ERR_NOSUCHSERVER_MSG,
124 Client_ID(prefix), Req->argv[0]);
126 /* Pass on to another server? */
127 if (target != Client_ThisServer()) {
128 IRC_WriteStrClientPrefix(target, prefix, "INFO %s",
129 Req->argv[0]);
130 return CONNECTED;
133 if (!IRC_WriteStrClient(Client, RPL_INFO_MSG, Client_ID(prefix),
134 NGIRCd_Version))
135 return DISCONNECTED;
137 strlcpy(msg, "Server has been started ", sizeof(msg));
138 strlcat(msg, NGIRCd_StartStr, sizeof(msg));
139 if (!IRC_WriteStrClient(Client, RPL_INFO_MSG, Client_ID(prefix), msg))
140 return DISCONNECTED;
142 if (!IRC_WriteStrClient(Client, RPL_ENDOFINFO_MSG, Client_ID(prefix)))
143 return DISCONNECTED;
145 IRC_SetPenalty(Client, 2);
146 return CONNECTED;
147 } /* IRC_INFO */
150 GLOBAL bool
151 IRC_ISON( CLIENT *Client, REQUEST *Req )
153 char rpl[COMMAND_LEN];
154 CLIENT *c;
155 char *ptr;
156 int i;
158 assert( Client != NULL );
159 assert( Req != NULL );
161 /* Falsche Anzahl Parameter? */
162 if(( Req->argc < 1 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
164 strlcpy( rpl, RPL_ISON_MSG, sizeof rpl );
165 for( i = 0; i < Req->argc; i++ )
167 ptr = strtok( Req->argv[i], " " );
168 while( ptr )
170 ngt_TrimStr( ptr );
171 c = Client_Search( ptr );
172 if( c && ( Client_Type( c ) == CLIENT_USER ))
174 /* Dieser Nick ist "online" */
175 strlcat( rpl, ptr, sizeof( rpl ));
176 strlcat( rpl, " ", sizeof( rpl ));
178 ptr = strtok( NULL, " " );
181 ngt_TrimLastChr(rpl, ' ');
183 return IRC_WriteStrClient( Client, rpl, Client_ID( Client ) );
184 } /* IRC_ISON */
187 GLOBAL bool
188 IRC_LINKS( CLIENT *Client, REQUEST *Req )
190 CLIENT *target, *from, *c;
191 char *mask;
193 assert( Client != NULL );
194 assert( Req != NULL );
196 /* Falsche Anzahl Parameter? */
197 if(( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
199 /* Server-Mask ermitteln */
200 if( Req->argc > 0 ) mask = Req->argv[Req->argc - 1];
201 else mask = "*";
203 /* Absender ermitteln */
204 if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
205 else from = Client;
206 if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
208 /* An anderen Server forwarden? */
209 if( Req->argc == 2 )
211 target = Client_Search( Req->argv[0] );
212 if(( ! target ) || ( Client_Type( target ) != CLIENT_SERVER )) return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[0] );
213 else if( target != Client_ThisServer( )) return IRC_WriteStrClientPrefix( target, from, "LINKS %s %s", Req->argv[0], Req->argv[1] );
216 /* Wer ist der Absender? */
217 if( Client_Type( Client ) == CLIENT_SERVER ) target = Client_Search( Req->prefix );
218 else target = Client;
219 if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
221 c = Client_First( );
222 while( c )
224 if( Client_Type( c ) == CLIENT_SERVER )
226 if( ! IRC_WriteStrClient( target, RPL_LINKS_MSG, Client_ID( target ), Client_ID( c ), Client_ID( Client_TopServer( c ) ? Client_TopServer( c ) : Client_ThisServer( )), Client_Hops( c ), Client_Info( c ))) return DISCONNECTED;
228 c = Client_Next( c );
231 IRC_SetPenalty( target, 1 );
232 return IRC_WriteStrClient( target, RPL_ENDOFLINKS_MSG, Client_ID( target ), mask );
233 } /* IRC_LINKS */
236 GLOBAL bool
237 IRC_LUSERS( CLIENT *Client, REQUEST *Req )
239 CLIENT *target, *from;
241 assert( Client != NULL );
242 assert( Req != NULL );
244 /* Falsche Anzahl Parameter? */
245 if(( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
247 /* Absender ermitteln */
248 if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
249 else from = Client;
250 if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
252 /* An anderen Server forwarden? */
253 if( Req->argc == 2 )
255 target = Client_Search( Req->argv[1] );
256 if(( ! target ) || ( Client_Type( target ) != CLIENT_SERVER )) return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[1] );
257 else if( target != Client_ThisServer( )) return IRC_WriteStrClientPrefix( target, from, "LUSERS %s %s", Req->argv[0], Req->argv[1] );
260 /* Wer ist der Absender? */
261 if( Client_Type( Client ) == CLIENT_SERVER ) target = Client_Search( Req->prefix );
262 else target = Client;
263 if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
265 IRC_Send_LUSERS( target );
267 IRC_SetPenalty( target, 1 );
268 return CONNECTED;
269 } /* IRC_LUSERS */
272 /**
273 * List registered services.
274 * This function is a dummy that immediately returns RPL_SERVLISTEND.
275 */
276 GLOBAL bool
277 IRC_SERVLIST(CLIENT *Client, REQUEST *Req)
279 assert(Client != NULL);
280 assert(Req != NULL);
282 if (Req->argc > 2)
283 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
284 Client_ID(Client), Req->command);
286 return IRC_WriteStrClient(Client, RPL_SERVLISTEND_MSG, Client_ID(Client),
287 Req->argc > 0 ? Req->argv[0] : "*",
288 Req->argc > 1 ? Req->argv[1] : "0");
289 } /* IRC_SERVLIST */
292 GLOBAL bool
293 IRC_MOTD( CLIENT *Client, REQUEST *Req )
295 CLIENT *from, *target;
297 assert( Client != NULL );
298 assert( Req != NULL );
300 /* Falsche Anzahl Parameter? */
301 if( Req->argc > 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
303 /* From aus Prefix ermitteln */
304 if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
305 else from = Client;
306 if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
308 if( Req->argc == 1 )
310 /* an anderen Server forwarden */
311 target = Client_Search( Req->argv[0] );
312 if(( ! target ) || ( Client_Type( target ) != CLIENT_SERVER )) return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[0] );
314 if( target != Client_ThisServer( ))
316 /* Ok, anderer Server ist das Ziel: forwarden */
317 return IRC_WriteStrClientPrefix( target, from, "MOTD %s", Req->argv[0] );
321 IRC_SetPenalty( from, 3 );
322 return IRC_Show_MOTD( from );
323 } /* IRC_MOTD */
326 GLOBAL bool
327 IRC_NAMES( CLIENT *Client, REQUEST *Req )
329 char rpl[COMMAND_LEN], *ptr;
330 CLIENT *target, *from, *c;
331 CHANNEL *chan;
333 assert( Client != NULL );
334 assert( Req != NULL );
336 /* Falsche Anzahl Parameter? */
337 if( Req->argc > 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
339 /* From aus Prefix ermitteln */
340 if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
341 else from = Client;
342 if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
344 if( Req->argc == 2 )
346 /* an anderen Server forwarden */
347 target = Client_Search( Req->argv[1] );
348 if(( ! target ) || ( Client_Type( target ) != CLIENT_SERVER )) return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[1] );
350 if( target != Client_ThisServer( ))
352 /* Ok, anderer Server ist das Ziel: forwarden */
353 return IRC_WriteStrClientPrefix( target, from, "NAMES %s :%s", Req->argv[0], Req->argv[1] );
357 if( Req->argc > 0 )
359 /* bestimmte Channels durchgehen */
360 ptr = strtok( Req->argv[0], "," );
361 while( ptr )
363 chan = Channel_Search( ptr );
364 if( chan )
366 /* Namen ausgeben */
367 if( ! IRC_Send_NAMES( from, chan )) return DISCONNECTED;
369 if( ! IRC_WriteStrClient( from, RPL_ENDOFNAMES_MSG, Client_ID( from ), ptr )) return DISCONNECTED;
371 /* naechsten Namen ermitteln */
372 ptr = strtok( NULL, "," );
374 return CONNECTED;
377 /* alle Channels durchgehen */
378 chan = Channel_First( );
379 while( chan )
381 /* Namen ausgeben */
382 if( ! IRC_Send_NAMES( from, chan )) return DISCONNECTED;
384 /* naechster Channel */
385 chan = Channel_Next( chan );
388 /* Nun noch alle Clients ausgeben, die in keinem Channel sind */
389 c = Client_First( );
390 snprintf( rpl, sizeof( rpl ), RPL_NAMREPLY_MSG, Client_ID( from ), "*", "*" );
391 while( c )
393 if(( Client_Type( c ) == CLIENT_USER ) && ( Channel_FirstChannelOf( c ) == NULL ) && ( ! strchr( Client_Modes( c ), 'i' )))
395 /* Okay, das ist ein User: anhaengen */
396 if( rpl[strlen( rpl ) - 1] != ':' ) strlcat( rpl, " ", sizeof( rpl ));
397 strlcat( rpl, Client_ID( c ), sizeof( rpl ));
399 if( strlen( rpl ) > ( LINE_LEN - CLIENT_NICK_LEN - 4 ))
401 /* Zeile wird zu lang: senden! */
402 if( ! IRC_WriteStrClient( from, "%s", rpl )) return DISCONNECTED;
403 snprintf( rpl, sizeof( rpl ), RPL_NAMREPLY_MSG, Client_ID( from ), "*", "*" );
407 /* naechster Client */
408 c = Client_Next( c );
410 if( rpl[strlen( rpl ) - 1] != ':')
412 /* es wurden User gefunden */
413 if( ! IRC_WriteStrClient( from, "%s", rpl )) return DISCONNECTED;
416 IRC_SetPenalty( from, 1 );
417 return IRC_WriteStrClient( from, RPL_ENDOFNAMES_MSG, Client_ID( from ), "*" );
418 } /* IRC_NAMES */
421 static unsigned int
422 t_diff(time_t *t, const time_t d)
424 time_t diff, remain;
426 diff = *t / d;
427 remain = diff * d;
428 *t -= remain;
430 return diff;
434 static unsigned int
435 uptime_days(time_t *now)
437 return t_diff(now, 60 * 60 * 24);
441 static unsigned int
442 uptime_hrs(time_t *now)
444 return t_diff(now, 60 * 60);
448 static unsigned int
449 uptime_mins(time_t *now)
451 return t_diff(now, 60);
455 GLOBAL bool
456 IRC_STATS( CLIENT *Client, REQUEST *Req )
458 CLIENT *from, *target, *cl;
459 CONN_ID con;
460 char query;
461 COMMAND *cmd;
462 time_t time_now;
463 unsigned int days, hrs, mins;
465 assert( Client != NULL );
466 assert( Req != NULL );
468 /* Falsche Anzahl Parameter? */
469 if (Req->argc > 2)
470 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG, Client_ID(Client), Req->command);
472 /* From aus Prefix ermitteln */
473 if (Client_Type(Client) == CLIENT_SERVER)
474 from = Client_Search(Req->prefix);
475 else
476 from = Client;
478 if (! from)
479 return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix);
481 if (Req->argc == 2) {
482 /* an anderen Server forwarden */
483 target = Client_Search( Req->argv[1] );
484 if(( ! target ) || ( Client_Type( target ) != CLIENT_SERVER ))
485 return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[1] );
487 if( target != Client_ThisServer()) {
488 /* Ok, anderer Server ist das Ziel: forwarden */
489 return IRC_WriteStrClientPrefix( target, from, "STATS %s %s", Req->argv[0], Req->argv[1] );
493 if (Req->argc > 0)
494 query = Req->argv[0][0] ? Req->argv[0][0] : '*';
495 else
496 query = '*';
498 switch (query) {
499 case 'l': /* Links */
500 case 'L':
501 time_now = time(NULL);
502 for (con = Conn_First(); con != NONE ;con = Conn_Next(con)) {
503 cl = Conn_GetClient(con);
504 if (!cl)
505 continue;
506 if ((Client_Type(cl) == CLIENT_SERVER) || (cl == Client)) {
507 /* Server link or our own connection */
508 #ifdef ZLIB
509 if (Conn_Options(con) & CONN_ZIP) {
510 if (!IRC_WriteStrClient(from, RPL_STATSLINKINFOZIP_MSG,
511 Client_ID(from), Client_Mask(cl), Conn_SendQ(con),
512 Conn_SendMsg(con), Zip_SendBytes(con), Conn_SendBytes(con),
513 Conn_RecvMsg(con), Zip_RecvBytes(con), Conn_RecvBytes(con), (long)(time_now - Conn_StartTime(con))))
514 return DISCONNECTED;
515 continue;
517 #endif
518 if (!IRC_WriteStrClient(from, RPL_STATSLINKINFO_MSG, Client_ID(from),
519 Client_Mask(cl), Conn_SendQ(con), Conn_SendMsg(con), Conn_SendBytes(con),
520 Conn_RecvMsg(con), Conn_RecvBytes(con), (long)(time_now - Conn_StartTime(con))))
521 return DISCONNECTED;
524 break;
525 case 'm': /* IRC-Commands */
526 case 'M':
527 cmd = Parse_GetCommandStruct( );
528 for (; cmd->name ; cmd++) {
529 if (cmd->lcount == 0 && cmd->rcount == 0)
530 continue;
531 if (!IRC_WriteStrClient(from, RPL_STATSCOMMANDS_MSG, Client_ID(from),
532 cmd->name, cmd->lcount, cmd->bytes, cmd->rcount))
533 return DISCONNECTED;
535 break;
536 case 'u': /* server uptime */
537 case 'U':
538 time_now = time(NULL) - NGIRCd_Start;
539 days = uptime_days(&time_now);
540 hrs = uptime_hrs(&time_now);
541 mins = uptime_mins(&time_now);
542 if (!IRC_WriteStrClient(from, RPL_STATSUPTIME, Client_ID(from),
543 days, hrs, mins, (unsigned int) time_now))
544 return DISCONNECTED;
545 break;
548 IRC_SetPenalty(from, 2);
549 return IRC_WriteStrClient(from, RPL_ENDOFSTATS_MSG, Client_ID(from), query);
550 } /* IRC_STATS */
553 /**
554 * Handler for the IRC command "SUMMON".
555 * See RFC 2812 section 4.5. ngIRCd doesn't implement this functionality and
556 * therefore answers with ERR_SUMMONDISABLED.
557 */
558 GLOBAL bool
559 IRC_SUMMON(CLIENT * Client, REQUEST * Req)
561 return IRC_WriteStrClient(Client, ERR_SUMMONDISABLED_MSG,
562 Client_ID(Client), Req->command);
563 } /* IRC_SUMMON */
566 GLOBAL bool
567 IRC_TIME( CLIENT *Client, REQUEST *Req )
569 CLIENT *from, *target;
570 char t_str[64];
571 time_t t;
573 assert( Client != NULL );
574 assert( Req != NULL );
576 /* Falsche Anzahl Parameter? */
577 if( Req->argc > 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
579 /* From aus Prefix ermitteln */
580 if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
581 else from = Client;
582 if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
584 if( Req->argc == 1 )
586 /* an anderen Server forwarden */
587 target = Client_Search( Req->argv[0] );
588 if(( ! target ) || ( Client_Type( target ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[0] );
590 if( target != Client_ThisServer( ))
592 /* Ok, anderer Server ist das Ziel: forwarden */
593 return IRC_WriteStrClientPrefix( target, from, "TIME %s", Req->argv[0] );
597 t = time( NULL );
598 (void)strftime( t_str, 60, "%A %B %d %Y -- %H:%M %Z", localtime( &t ));
599 return IRC_WriteStrClient( from, RPL_TIME_MSG, Client_ID( from ), Client_ID( Client_ThisServer( )), t_str );
600 } /* IRC_TIME */
603 GLOBAL bool
604 IRC_USERHOST( CLIENT *Client, REQUEST *Req )
606 char rpl[COMMAND_LEN];
607 CLIENT *c;
608 int max, i;
610 assert( Client != NULL );
611 assert( Req != NULL );
613 /* Falsche Anzahl Parameter? */
614 if(( Req->argc < 1 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
616 if( Req->argc > 5 ) max = 5;
617 else max = Req->argc;
619 strlcpy( rpl, RPL_USERHOST_MSG, sizeof rpl );
620 for( i = 0; i < max; i++ )
622 c = Client_Search( Req->argv[i] );
623 if( c && ( Client_Type( c ) == CLIENT_USER ))
625 /* Dieser Nick ist "online" */
626 strlcat( rpl, Client_ID( c ), sizeof( rpl ));
627 if( Client_HasMode( c, 'o' )) strlcat( rpl, "*", sizeof( rpl ));
628 strlcat( rpl, "=", sizeof( rpl ));
629 if( Client_HasMode( c, 'a' )) strlcat( rpl, "-", sizeof( rpl ));
630 else strlcat( rpl, "+", sizeof( rpl ));
631 strlcat( rpl, Client_User( c ), sizeof( rpl ));
632 strlcat( rpl, "@", sizeof( rpl ));
633 strlcat( rpl, Client_Hostname( c ), sizeof( rpl ));
634 strlcat( rpl, " ", sizeof( rpl ));
637 ngt_TrimLastChr( rpl, ' ');
639 return IRC_WriteStrClient( Client, rpl, Client_ID( Client ) );
640 } /* IRC_USERHOST */
643 /**
644 * Handler for the IRC command "USERS".
645 * See RFC 2812 section 4.6. As suggested there the command is disabled.
646 */
647 GLOBAL bool
648 IRC_USERS(CLIENT * Client, REQUEST * Req)
650 return IRC_WriteStrClient(Client, ERR_USERSDISABLED_MSG,
651 Client_ID(Client), Req->command);
652 } /* IRC_USERS */
655 GLOBAL bool
656 IRC_VERSION( CLIENT *Client, REQUEST *Req )
658 CLIENT *target, *prefix;
660 assert( Client != NULL );
661 assert( Req != NULL );
663 /* Falsche Anzahl Parameter? */
664 if(( Req->argc > 1 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
666 /* Ziel suchen */
667 if( Req->argc == 1 ) target = Client_Search( Req->argv[0] );
668 else target = Client_ThisServer( );
670 /* Prefix ermitteln */
671 if( Client_Type( Client ) == CLIENT_SERVER ) prefix = Client_Search( Req->prefix );
672 else prefix = Client;
673 if( ! prefix ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
675 /* An anderen Server weiterleiten? */
676 if( target != Client_ThisServer( ))
678 if(( ! target ) || ( Client_Type( target ) != CLIENT_SERVER )) return IRC_WriteStrClient( prefix, ERR_NOSUCHSERVER_MSG, Client_ID( prefix ), Req->argv[0] );
680 /* forwarden */
681 IRC_WriteStrClientPrefix( target, prefix, "VERSION %s", Req->argv[0] );
682 return CONNECTED;
685 /* send version information */
686 IRC_SetPenalty(Client, 1);
687 return IRC_WriteStrClient(Client, RPL_VERSION_MSG, Client_ID(prefix),
688 PACKAGE_NAME, PACKAGE_VERSION,
689 NGIRCd_DebugLevel, Conf_ServerName,
690 NGIRCd_VersionAddition);
691 } /* IRC_VERSION */
694 static bool
695 write_whoreply(CLIENT *Client, CLIENT *c, const char *channelname, const char *flags)
697 return IRC_WriteStrClient(Client, RPL_WHOREPLY_MSG, Client_ID(Client), channelname,
698 Client_User(c), Client_Hostname(c), Client_ID(Client_Introducer(c)), Client_ID(c),
699 flags, Client_Hops(c), Client_Info(c));
703 static const char *
704 who_flags_status(const char *client_modes)
706 if (strchr(client_modes, 'a'))
707 return "G"; /* away */
708 return "H";
712 static const char *
713 who_flags_qualifier(const char *chan_user_modes)
715 if (strchr(chan_user_modes, 'o'))
716 return "@";
717 else if (strchr(chan_user_modes, 'v'))
718 return "+";
719 return "";
723 static bool
724 IRC_Send_WHO(CLIENT *Client, CHANNEL *Chan, bool OnlyOps)
726 bool is_visible, is_member, is_ircop;
727 CL2CHAN *cl2chan;
728 const char *client_modes;
729 const char *chan_user_modes;
730 char flags[8];
731 CLIENT *c;
733 assert( Client != NULL );
734 assert( Chan != NULL );
736 is_member = Channel_IsMemberOf(Chan, Client);
738 /* Secret channel? */
739 if (!is_member && strchr(Channel_Modes(Chan), 's'))
740 return IRC_WriteStrClient(Client, RPL_ENDOFWHO_MSG, Client_ID(Client), Channel_Name(Chan));
742 cl2chan = Channel_FirstMember(Chan);
743 for (; cl2chan ; cl2chan = Channel_NextMember(Chan, cl2chan)) {
744 c = Channel_GetClient(cl2chan);
746 client_modes = Client_Modes(c);
747 is_ircop = strchr(client_modes, 'o') != NULL;
748 if (OnlyOps && !is_ircop)
749 continue;
751 is_visible = strchr(client_modes, 'i') == NULL;
752 if (is_member || is_visible) {
753 strcpy(flags, who_flags_status(client_modes));
754 if (is_ircop)
755 strlcat(flags, "*", sizeof(flags));
757 chan_user_modes = Channel_UserModes(Chan, c);
758 strlcat(flags, who_flags_qualifier(chan_user_modes), sizeof(flags));
760 if (!write_whoreply(Client, c, Channel_Name(Chan), flags))
761 return DISCONNECTED;
764 return IRC_WriteStrClient(Client, RPL_ENDOFWHO_MSG, Client_ID(Client), Channel_Name(Chan));
765 } /* IRC_Send_WHO */
768 GLOBAL bool
769 IRC_WHO( CLIENT *Client, REQUEST *Req )
771 bool only_ops, have_arg, client_match;
772 const char *channelname, *client_modes, *chan_user_modes;
773 char pattern[COMMAND_LEN];
774 char flags[4];
775 CL2CHAN *cl2chan;
776 CHANNEL *chan, *cn;
777 CLIENT *c;
779 assert( Client != NULL );
780 assert( Req != NULL );
782 if (Req->argc > 2)
783 return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
785 only_ops = false;
786 have_arg = false;
788 if (Req->argc == 2) {
789 if (strcmp(Req->argv[1], "o") == 0)
790 only_ops = true;
791 #ifdef STRICT_RFC
792 else return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG, Client_ID(Client), Req->command);
793 #endif
796 IRC_SetPenalty(Client, 1);
797 if (Req->argc >= 1) { /* Channel or Mask. */
798 chan = Channel_Search(Req->argv[0]);
799 if (chan)
800 return IRC_Send_WHO(Client, chan, only_ops);
801 if (strcmp(Req->argv[0], "0") != 0) { /* RFC stupidity, same as no arguments */
802 have_arg = true;
803 strlcpy(pattern, Req->argv[0], sizeof(pattern));
804 ngt_LowerStr(pattern);
805 IRC_SetPenalty(Client, 3);
809 for (c = Client_First(); c != NULL; c = Client_Next(c)) {
810 if (Client_Type(c) != CLIENT_USER)
811 continue;
812 /*
813 * RFC 2812, 3.6.1:
814 * In the absence of the parameter, all visible (users who aren't
815 * invisible (user mode +i) and who don't have a common channel
816 * with the requesting client) are listed.
818 * The same result can be achieved by using a [sic] of "0"
819 * or any wildcard which will end up matching every visible user.
821 * The [sic] passed to WHO is matched against users' host, server, real name and
822 * nickname if the channel cannot be found.
823 */
824 client_modes = Client_Modes(c);
825 if (strchr(client_modes, 'i'))
826 continue;
828 if (only_ops && !strchr(client_modes, 'o'))
829 continue;
831 if (have_arg) { /* match pattern against user host/server/name/nick */
832 client_match = MatchCaseInsensitive(pattern, Client_Hostname(c)); /* user's host */
833 if (!client_match)
834 client_match = MatchCaseInsensitive(pattern, Client_ID(Client_Introducer(c))); /* server */
835 if (!client_match)
836 client_match = Match(Req->argv[0], Client_Info(c)); /* realname */
837 if (!client_match)
838 client_match = MatchCaseInsensitive(pattern, Client_ID(c)); /* nick name */
840 if (!client_match) /* This isn't the client you're looking for */
841 continue;
844 strcpy(flags, who_flags_status(client_modes));
846 if (strchr(client_modes, 'o')) /* this client is an operator */
847 strlcat(flags, "*", sizeof(flags));
849 /* Search suitable channel */
850 cl2chan = Channel_FirstChannelOf(c);
851 while (cl2chan) {
852 cn = Channel_GetChannel(cl2chan);
853 if (Channel_IsMemberOf(cn, Client) ||
854 !strchr(Channel_Modes(cn), 's'))
856 channelname = Channel_Name(cn);
857 break;
859 cl2chan = Channel_NextChannelOf(c, cl2chan);
861 if (cl2chan) {
862 chan = Channel_GetChannel(cl2chan);
863 chan_user_modes = Channel_UserModes(chan, c);
864 strlcat(flags, who_flags_qualifier(chan_user_modes), sizeof(flags));
865 } else
866 channelname = "*";
868 if (!write_whoreply(Client, c, channelname, flags))
869 return DISCONNECTED;
872 if (Req->argc > 0)
873 channelname = Req->argv[0];
874 else
875 channelname = "*";
877 return IRC_WriteStrClient(Client, RPL_ENDOFWHO_MSG, Client_ID(Client), channelname);
878 } /* IRC_WHO */
881 GLOBAL bool
882 IRC_WHOIS( CLIENT *Client, REQUEST *Req )
884 CLIENT *from, *target, *c;
885 char str[LINE_LEN + 1];
886 CL2CHAN *cl2chan;
887 CHANNEL *chan;
889 assert( Client != NULL );
890 assert( Req != NULL );
892 /* Bad number of parameters? */
893 if(( Req->argc < 1 ) || ( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
895 /* Search client */
896 c = Client_Search( Req->argv[Req->argc - 1] );
897 if(( ! c ) || ( Client_Type( c ) != CLIENT_USER )) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->argv[Req->argc - 1] );
899 /* Search sender of the WHOIS */
900 if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
901 else from = Client;
902 if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
904 /* Forward to other server? */
905 if( Req->argc > 1 )
907 /* Search target server (can be specified as nick of that server!) */
908 target = Client_Search( Req->argv[0] );
909 if( ! target ) return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[0] );
911 else target = Client_ThisServer( );
913 assert( target != NULL );
915 if(( Client_NextHop( target ) != Client_ThisServer( )) && ( Client_Type( Client_NextHop( target )) == CLIENT_SERVER )) return IRC_WriteStrClientPrefix( target, from, "WHOIS %s :%s", Req->argv[0], Req->argv[1] );
917 /* Nick, user and name */
918 if( ! IRC_WriteStrClient( from, RPL_WHOISUSER_MSG, Client_ID( from ), Client_ID( c ), Client_User( c ), Client_Hostname( c ), Client_Info( c ))) return DISCONNECTED;
920 /* Server */
921 if( ! IRC_WriteStrClient( from, RPL_WHOISSERVER_MSG, Client_ID( from ), Client_ID( c ), Client_ID( Client_Introducer( c )), Client_Info( Client_Introducer( c )))) return DISCONNECTED;
923 /* Channels */
924 snprintf( str, sizeof( str ), RPL_WHOISCHANNELS_MSG, Client_ID( from ), Client_ID( c ));
925 cl2chan = Channel_FirstChannelOf( c );
926 while( cl2chan )
928 chan = Channel_GetChannel( cl2chan );
929 assert( chan != NULL );
931 /* next */
932 cl2chan = Channel_NextChannelOf( c, cl2chan );
934 /* Secret channel? */
935 if( strchr( Channel_Modes( chan ), 's' ) && ! Channel_IsMemberOf( chan, Client )) continue;
937 /* Concatenate channel names */
938 if( str[strlen( str ) - 1] != ':' ) strlcat( str, " ", sizeof( str ));
939 if( strchr( Channel_UserModes( chan, c ), 'o' )) strlcat( str, "@", sizeof( str ));
940 else if( strchr( Channel_UserModes( chan, c ), 'v' )) strlcat( str, "+", sizeof( str ));
941 strlcat( str, Channel_Name( chan ), sizeof( str ));
943 if( strlen( str ) > ( LINE_LEN - CHANNEL_NAME_LEN - 4 ))
945 /* Line becomes too long: send it! */
946 if( ! IRC_WriteStrClient( Client, "%s", str )) return DISCONNECTED;
947 snprintf( str, sizeof( str ), RPL_WHOISCHANNELS_MSG, Client_ID( from ), Client_ID( c ));
950 if( str[strlen( str ) - 1] != ':')
952 /* There is data left to send: */
953 if( ! IRC_WriteStrClient( Client, "%s", str )) return DISCONNECTED;
956 /* IRC-Operator? */
957 if( Client_HasMode( c, 'o' ))
959 if( ! IRC_WriteStrClient( from, RPL_WHOISOPERATOR_MSG, Client_ID( from ), Client_ID( c ))) return DISCONNECTED;
962 /* Idle and signon time (local clients only!) */
963 if (Client_Conn(c) > NONE ) {
964 if (! IRC_WriteStrClient(from, RPL_WHOISIDLE_MSG,
965 Client_ID(from), Client_ID(c),
966 (unsigned long)Conn_GetIdle(Client_Conn(c)),
967 (unsigned long)Conn_GetSignon(Client_Conn(c))))
968 return DISCONNECTED;
971 /* Away? */
972 if( Client_HasMode( c, 'a' ))
974 if( ! IRC_WriteStrClient( from, RPL_AWAY_MSG, Client_ID( from ), Client_ID( c ), Client_Away( c ))) return DISCONNECTED;
977 /* End of Whois */
978 return IRC_WriteStrClient( from, RPL_ENDOFWHOIS_MSG, Client_ID( from ), Client_ID( c ));
979 } /* IRC_WHOIS */
982 static bool
983 WHOWAS_EntryWrite(CLIENT *prefix, WHOWAS *entry)
985 char t_str[60];
987 (void)strftime(t_str, sizeof(t_str), "%a %b %d %H:%M:%S %Y",
988 localtime(&entry->time));
990 if (!IRC_WriteStrClient(prefix, RPL_WHOWASUSER_MSG, Client_ID(prefix),
991 entry->id, entry->user, entry->host, entry->info))
992 return DISCONNECTED;
994 return IRC_WriteStrClient(prefix, RPL_WHOISSERVER_MSG, Client_ID(prefix),
995 entry->id, entry->server, t_str);
998 /**
999 * IRC "WHOWAS" function.
1000 * This function implements the IRC command "WHOWHAS". It handles local
1001 * requests and request that should be forwarded to other servers.
1003 GLOBAL bool
1004 IRC_WHOWAS( CLIENT *Client, REQUEST *Req )
1006 CLIENT *target, *prefix;
1007 WHOWAS *whowas;
1008 char tok_buf[COMMAND_LEN];
1009 int max, last, count, i, nc;
1010 const char *nick;
1012 assert( Client != NULL );
1013 assert( Req != NULL );
1015 /* Wrong number of parameters? */
1016 if (Req->argc > 3)
1017 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
1018 Client_ID(Client), Req->command);
1019 if (Req->argc < 1)
1020 return IRC_WriteStrClient(Client, ERR_NONICKNAMEGIVEN_MSG, Client_ID(Client));
1022 /* Search target */
1023 if (Req->argc == 3)
1024 target = Client_Search(Req->argv[2]);
1025 else
1026 target = Client_ThisServer();
1028 /* Get prefix */
1029 if (Client_Type(Client) == CLIENT_SERVER)
1030 prefix = Client_Search(Req->prefix);
1031 else
1032 prefix = Client;
1034 if (!prefix)
1035 return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG,
1036 Client_ID(Client), Req->prefix);
1038 /* Forward to other server? */
1039 if (target != Client_ThisServer()) {
1040 if (!target || (Client_Type(target) != CLIENT_SERVER))
1041 return IRC_WriteStrClient(prefix, ERR_NOSUCHSERVER_MSG,
1042 Client_ID(prefix), Req->argv[2]);
1044 /* Forward */
1045 IRC_WriteStrClientPrefix( target, prefix, "WHOWAS %s %s %s",
1046 Req->argv[0], Req->argv[1],
1047 Req->argv[2] );
1048 return CONNECTED;
1051 whowas = Client_GetWhowas( );
1052 last = Client_GetLastWhowasIndex( );
1053 if (last < 0)
1054 last = 0;
1056 max = DEFAULT_WHOWAS;
1057 if (Req->argc > 1) {
1058 max = atoi(Req->argv[1]);
1059 if (max < 1)
1060 max = MAX_WHOWAS;
1064 * Break up the nick argument into a list of nicks, if applicable
1065 * Can't modify Req->argv[0] because we need it for RPL_ENDOFWHOWAS_MSG.
1067 strlcpy(tok_buf, Req->argv[0], sizeof(tok_buf));
1068 nick = strtok(tok_buf, ",");
1070 for (i=last, count=0; nick != NULL ; nick = strtok(NULL, ",")) {
1071 nc = 0;
1072 do {
1073 /* Used entry? */
1074 if (whowas[i].time > 0 && strcasecmp(nick, whowas[i].id) == 0) {
1075 if (!WHOWAS_EntryWrite(prefix, &whowas[i]))
1076 return DISCONNECTED;
1077 nc++;
1078 count++;
1080 /* previous entry */
1081 i--;
1083 /* "underflow", wrap around */
1084 if (i < 0)
1085 i = MAX_WHOWAS - 1;
1087 if (nc && count >= max)
1088 break;
1089 } while (i != last);
1091 if (nc == 0 && !IRC_WriteStrClient(prefix, ERR_WASNOSUCHNICK_MSG,
1092 Client_ID(prefix), nick))
1093 return DISCONNECTED;
1095 return IRC_WriteStrClient(prefix, RPL_ENDOFWHOWAS_MSG, Client_ID(prefix), Req->argv[0]);
1096 } /* IRC_WHOWAS */
1099 GLOBAL bool
1100 IRC_Send_LUSERS( CLIENT *Client )
1102 unsigned long cnt;
1103 #ifndef STRICT_RFC
1104 unsigned long max;
1105 #endif
1107 assert( Client != NULL );
1109 /* Users, services and serevers in the network */
1110 if( ! IRC_WriteStrClient( Client, RPL_LUSERCLIENT_MSG, Client_ID( Client ), Client_UserCount( ), Client_ServiceCount( ), Client_ServerCount( ))) return DISCONNECTED;
1112 /* Number of IRC operators */
1113 cnt = Client_OperCount( );
1114 if( cnt > 0 )
1116 if( ! IRC_WriteStrClient( Client, RPL_LUSEROP_MSG, Client_ID( Client ), cnt )) return DISCONNECTED;
1119 /* Unknown connections */
1120 cnt = Client_UnknownCount( );
1121 if( cnt > 0 )
1123 if( ! IRC_WriteStrClient( Client, RPL_LUSERUNKNOWN_MSG, Client_ID( Client ), cnt )) return DISCONNECTED;
1126 /* Number of created channels */
1127 if( ! IRC_WriteStrClient( Client, RPL_LUSERCHANNELS_MSG, Client_ID( Client ), Channel_Count( ))) return DISCONNECTED;
1129 /* Number of local users, services and servers */
1130 if( ! IRC_WriteStrClient( Client, RPL_LUSERME_MSG, Client_ID( Client ), Client_MyUserCount( ), Client_MyServiceCount( ), Client_MyServerCount( ))) return DISCONNECTED;
1132 #ifndef STRICT_RFC
1133 /* Maximum number of local users */
1134 cnt = Client_MyUserCount();
1135 max = Client_MyMaxUserCount();
1136 if (! IRC_WriteStrClient(Client, RPL_LOCALUSERS_MSG, Client_ID(Client),
1137 cnt, max, cnt, max))
1138 return DISCONNECTED;
1139 /* Maximum number of users in the network */
1140 cnt = Client_UserCount();
1141 max = Client_MaxUserCount();
1142 if(! IRC_WriteStrClient(Client, RPL_NETUSERS_MSG, Client_ID(Client),
1143 cnt, max, cnt, max))
1144 return DISCONNECTED;
1145 #endif
1147 return CONNECTED;
1148 } /* IRC_Send_LUSERS */
1151 static bool
1152 Show_MOTD_Start(CLIENT *Client)
1154 return IRC_WriteStrClient(Client, RPL_MOTDSTART_MSG,
1155 Client_ID( Client ), Client_ID( Client_ThisServer( )));
1158 static bool
1159 Show_MOTD_Sendline(CLIENT *Client, const char *msg)
1161 return IRC_WriteStrClient(Client, RPL_MOTD_MSG, Client_ID( Client ), msg);
1164 static bool
1165 Show_MOTD_End(CLIENT *Client)
1167 return IRC_WriteStrClient( Client, RPL_ENDOFMOTD_MSG, Client_ID( Client ));
1170 #ifdef SSL_SUPPORT
1171 static bool Show_MOTD_SSLInfo(CLIENT *Client)
1173 bool ret = true;
1174 char buf[COMMAND_LEN] = "Connected using Cipher ";
1176 if (!Conn_GetCipherInfo(Client_Conn(Client), buf + 23, sizeof buf - 23))
1177 return true;
1179 if (!Show_MOTD_Sendline(Client, buf))
1180 ret = false;
1182 return ret;
1184 #else
1185 static inline bool Show_MOTD_SSLInfo(UNUSED CLIENT *c) { return true; }
1186 #endif
1188 GLOBAL bool
1189 IRC_Show_MOTD( CLIENT *Client )
1191 char line[127];
1192 FILE *fd;
1194 assert( Client != NULL );
1196 if (Conf_MotdPhrase[0]) {
1197 if (!Show_MOTD_Start(Client))
1198 return DISCONNECTED;
1199 if (!Show_MOTD_Sendline(Client, Conf_MotdPhrase))
1200 return DISCONNECTED;
1201 goto out;
1204 fd = fopen( Conf_MotdFile, "r" );
1205 if( ! fd ) {
1206 Log( LOG_WARNING, "Can't read MOTD file \"%s\": %s", Conf_MotdFile, strerror( errno ));
1207 if (Conn_UsesSSL(Client_Conn(Client))) {
1208 if (!Show_MOTD_Start(Client))
1209 return DISCONNECTED;
1210 goto out;
1212 return IRC_WriteStrClient( Client, ERR_NOMOTD_MSG, Client_ID( Client ) );
1215 if (!Show_MOTD_Start( Client )) {
1216 fclose(fd);
1217 return false;
1220 while (fgets( line, (int)sizeof line, fd )) {
1221 ngt_TrimLastChr( line, '\n');
1223 if( ! Show_MOTD_Sendline( Client, line)) {
1224 fclose( fd );
1225 return false;
1228 fclose(fd);
1229 out:
1230 if (!Show_MOTD_SSLInfo(Client))
1231 return DISCONNECTED;
1232 return Show_MOTD_End(Client);
1233 } /* IRC_Show_MOTD */
1236 GLOBAL bool
1237 IRC_Send_NAMES( CLIENT *Client, CHANNEL *Chan )
1239 bool is_visible, is_member;
1240 char str[LINE_LEN + 1];
1241 CL2CHAN *cl2chan;
1242 CLIENT *cl;
1244 assert( Client != NULL );
1245 assert( Chan != NULL );
1247 if( Channel_IsMemberOf( Chan, Client )) is_member = true;
1248 else is_member = false;
1250 /* Secret channel? */
1251 if( ! is_member && strchr( Channel_Modes( Chan ), 's' )) return CONNECTED;
1253 /* Alle Mitglieder suchen */
1254 snprintf( str, sizeof( str ), RPL_NAMREPLY_MSG, Client_ID( Client ), "=", Channel_Name( Chan ));
1255 cl2chan = Channel_FirstMember( Chan );
1256 while( cl2chan )
1258 cl = Channel_GetClient( cl2chan );
1260 if( strchr( Client_Modes( cl ), 'i' )) is_visible = false;
1261 else is_visible = true;
1263 if( is_member || is_visible )
1265 /* Nick anhaengen */
1266 if( str[strlen( str ) - 1] != ':' ) strlcat( str, " ", sizeof( str ));
1267 if( strchr( Channel_UserModes( Chan, cl ), 'o' )) strlcat( str, "@", sizeof( str ));
1268 else if( strchr( Channel_UserModes( Chan, cl ), 'v' )) strlcat( str, "+", sizeof( str ));
1269 strlcat( str, Client_ID( cl ), sizeof( str ));
1271 if( strlen( str ) > ( LINE_LEN - CLIENT_NICK_LEN - 4 ))
1273 /* Zeile wird zu lang: senden! */
1274 if( ! IRC_WriteStrClient( Client, "%s", str )) return DISCONNECTED;
1275 snprintf( str, sizeof( str ), RPL_NAMREPLY_MSG, Client_ID( Client ), "=", Channel_Name( Chan ));
1279 /* naechstes Mitglied suchen */
1280 cl2chan = Channel_NextMember( Chan, cl2chan );
1282 if( str[strlen( str ) - 1] != ':')
1284 /* Es sind noch Daten da, die gesendet werden muessen */
1285 if( ! IRC_WriteStrClient( Client, "%s", str )) return DISCONNECTED;
1288 return CONNECTED;
1289 } /* IRC_Send_NAMES */
1293 /**
1294 * Send the ISUPPORT numeric (005).
1295 * This numeric indicates the features that are supported by this server.
1296 * See <http://www.irc.org/tech_docs/005.html> for details.
1298 GLOBAL bool
1299 IRC_Send_ISUPPORT PARAMS((CLIENT * Client))
1301 if (!IRC_WriteStrClient(Client, RPL_ISUPPORT1_MSG, Client_ID(Client),
1302 Conf_MaxJoins))
1303 return DISCONNECTED;
1304 return IRC_WriteStrClient(Client, RPL_ISUPPORT2_MSG, Client_ID(Client),
1305 CHANNEL_NAME_LEN - 1, Conf_MaxNickLength - 1,
1306 COMMAND_LEN - 23, CLIENT_AWAY_LEN - 1,
1307 COMMAND_LEN - 113);
1308 } /* IRC_Send_ISUPPORT */
1311 /* -eof- */