2 * ngIRCd -- The Next Generation IRC Daemon
3 * Copyright (c)2001,2002 by Alexander Barton (alex@barton.de)
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.
17 static char UNUSED id[] = "$Id: irc-info.c,v 1.6 2002/12/16 17:14:57 alex Exp $";
36 #include "irc-write.h"
43 IRC_ADMIN(CLIENT *Client, REQUEST *Req )
45 CLIENT *target, *prefix;
47 assert( Client != NULL );
48 assert( Req != NULL );
50 /* Falsche Anzahl Parameter? */
51 if(( Req->argc > 1 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
54 if( Req->argc == 1 ) target = Client_Search( Req->argv[0] );
55 else target = Client_ThisServer( );
57 /* Prefix ermitteln */
58 if( Client_Type( Client ) == CLIENT_SERVER ) prefix = Client_Search( Req->prefix );
60 if( ! prefix ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
62 /* An anderen Server weiterleiten? */
63 if( target != Client_ThisServer( ))
65 if( ! target ) return IRC_WriteStrClient( prefix, ERR_NOSUCHSERVER_MSG, Client_ID( prefix ), Req->argv[0] );
68 IRC_WriteStrClientPrefix( target, prefix, "ADMIN %s", Req->argv[0] );
72 /* mit Versionsinfo antworten */
73 if( ! IRC_WriteStrClient( Client, RPL_ADMINME_MSG, Client_ID( prefix ), Conf_ServerName )) return DISCONNECTED;
74 if( ! IRC_WriteStrClient( Client, RPL_ADMINLOC1_MSG, Client_ID( prefix ), Conf_ServerAdmin1 )) return DISCONNECTED;
75 if( ! IRC_WriteStrClient( Client, RPL_ADMINLOC2_MSG, Client_ID( prefix ), Conf_ServerAdmin2 )) return DISCONNECTED;
76 if( ! IRC_WriteStrClient( Client, RPL_ADMINEMAIL_MSG, Client_ID( prefix ), Conf_ServerAdminMail )) return DISCONNECTED;
83 IRC_ISON( CLIENT *Client, REQUEST *Req )
85 CHAR rpl[COMMAND_LEN];
90 assert( Client != NULL );
91 assert( Req != NULL );
93 /* Falsche Anzahl Parameter? */
94 if(( Req->argc < 1 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
96 strcpy( rpl, RPL_ISON_MSG );
97 for( i = 0; i < Req->argc; i++ )
99 ptr = strtok( Req->argv[i], " " );
103 c = Client_Search( ptr );
104 if( c && ( Client_Type( c ) == CLIENT_USER ))
106 /* Dieser Nick ist "online" */
110 ptr = strtok( NULL, " " );
113 if( rpl[strlen( rpl ) - 1] == ' ' ) rpl[strlen( rpl ) - 1] = '\0';
115 return IRC_WriteStrClient( Client, rpl, Client_ID( Client ) );
120 IRC_LINKS( CLIENT *Client, REQUEST *Req )
122 CLIENT *target, *from, *c;
125 assert( Client != NULL );
126 assert( Req != NULL );
128 /* Falsche Anzahl Parameter? */
129 if(( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
131 /* Server-Mask ermitteln */
132 if( Req->argc > 0 ) mask = Req->argv[Req->argc - 1];
135 /* Absender ermitteln */
136 if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
138 if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
140 /* An anderen Server forwarden? */
143 target = Client_Search( Req->argv[0] );
144 if( ! target ) return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[0] );
145 else if( target != Client_ThisServer( )) return IRC_WriteStrClientPrefix( target, from, "LINKS %s %s", Req->argv[0], Req->argv[1] );
148 /* Wer ist der Absender? */
149 if( Client_Type( Client ) == CLIENT_SERVER ) target = Client_Search( Req->prefix );
150 else target = Client;
151 if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
156 if( Client_Type( c ) == CLIENT_SERVER )
158 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;
160 c = Client_Next( c );
163 return IRC_WriteStrClient( target, RPL_ENDOFLINKS_MSG, Client_ID( target ), mask );
168 IRC_LUSERS( CLIENT *Client, REQUEST *Req )
170 CLIENT *target, *from;
172 assert( Client != NULL );
173 assert( Req != NULL );
175 /* Falsche Anzahl Parameter? */
176 if(( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
178 /* Absender ermitteln */
179 if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
181 if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
183 /* An anderen Server forwarden? */
186 target = Client_Search( Req->argv[1] );
187 if( ! target ) return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[1] );
188 else if( target != Client_ThisServer( )) return IRC_WriteStrClientPrefix( target, from, "LUSERS %s %s", Req->argv[0], Req->argv[1] );
191 /* Wer ist der Absender? */
192 if( Client_Type( Client ) == CLIENT_SERVER ) target = Client_Search( Req->prefix );
193 else target = Client;
194 if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
196 IRC_Send_LUSERS( target );
203 IRC_MOTD( CLIENT *Client, REQUEST *Req )
205 CLIENT *from, *target;
207 assert( Client != NULL );
208 assert( Req != NULL );
210 /* Falsche Anzahl Parameter? */
211 if( Req->argc > 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
213 /* From aus Prefix ermitteln */
214 if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
216 if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
220 /* an anderen Server forwarden */
221 target = Client_Search( Req->argv[0] );
222 if( ! target ) return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[0] );
224 if( target != Client_ThisServer( ))
226 /* Ok, anderer Server ist das Ziel: forwarden */
227 return IRC_WriteStrClientPrefix( target, from, "MOTD %s", Req->argv[0] );
231 return IRC_Show_MOTD( from );
236 IRC_NAMES( CLIENT *Client, REQUEST *Req )
238 CHAR rpl[COMMAND_LEN], *ptr;
239 CLIENT *target, *from, *c;
242 assert( Client != NULL );
243 assert( Req != NULL );
245 /* Falsche Anzahl Parameter? */
246 if( Req->argc > 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
248 /* From aus Prefix ermitteln */
249 if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
251 if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
255 /* an anderen Server forwarden */
256 target = Client_Search( Req->argv[1] );
257 if( ! target ) return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[1] );
259 if( target != Client_ThisServer( ))
261 /* Ok, anderer Server ist das Ziel: forwarden */
262 return IRC_WriteStrClientPrefix( target, from, "NAMES %s :%s", Req->argv[0], Req->argv[1] );
268 /* bestimmte Channels durchgehen */
269 ptr = strtok( Req->argv[0], "," );
272 chan = Channel_Search( ptr );
276 if( ! IRC_Send_NAMES( from, chan )) return DISCONNECTED;
278 if( ! IRC_WriteStrClient( from, RPL_ENDOFNAMES_MSG, Client_ID( from ), ptr )) return DISCONNECTED;
280 /* naechsten Namen ermitteln */
281 ptr = strtok( NULL, "," );
286 /* alle Channels durchgehen */
287 chan = Channel_First( );
291 if( ! IRC_Send_NAMES( from, chan )) return DISCONNECTED;
293 /* naechster Channel */
294 chan = Channel_Next( chan );
297 /* Nun noch alle Clients ausgeben, die in keinem Channel sind */
299 sprintf( rpl, RPL_NAMREPLY_MSG, Client_ID( from ), "*", "*" );
302 if(( Client_Type( c ) == CLIENT_USER ) && ( Channel_FirstChannelOf( c ) == NULL ) && ( ! strchr( Client_Modes( c ), 'i' )))
304 /* Okay, das ist ein User: anhaengen */
305 if( rpl[strlen( rpl ) - 1] != ':' ) strcat( rpl, " " );
306 strcat( rpl, Client_ID( c ));
308 if( strlen( rpl ) > ( LINE_LEN - CLIENT_NICK_LEN - 4 ))
310 /* Zeile wird zu lang: senden! */
311 if( ! IRC_WriteStrClient( from, "%s", rpl )) return DISCONNECTED;
312 sprintf( rpl, RPL_NAMREPLY_MSG, Client_ID( from ), "*", "*" );
316 /* naechster Client */
317 c = Client_Next( c );
319 if( rpl[strlen( rpl ) - 1] != ':')
321 /* es wurden User gefunden */
322 if( ! IRC_WriteStrClient( from, "%s", rpl )) return DISCONNECTED;
325 return IRC_WriteStrClient( from, RPL_ENDOFNAMES_MSG, Client_ID( from ), "*" );
330 IRC_STATS( CLIENT *Client, REQUEST *Req )
332 CLIENT *from, *target, *cl;
336 assert( Client != NULL );
337 assert( Req != NULL );
339 /* Falsche Anzahl Parameter? */
340 if( Req->argc > 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
342 /* From aus Prefix ermitteln */
343 if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
345 if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
349 /* an anderen Server forwarden */
350 target = Client_Search( Req->argv[1] );
351 if( ! target ) return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[1] );
353 if( target != Client_ThisServer( ))
355 /* Ok, anderer Server ist das Ziel: forwarden */
356 return IRC_WriteStrClientPrefix( target, from, "STATS %s %s", Req->argv[0], Req->argv[1] );
360 if( Req->argc > 0 ) query = Req->argv[0][0] ? Req->argv[0][0] : '*';
365 case 'l': /* Links */
370 cl = Client_GetFromConn( con );
374 if( Conn_Options( con ) & CONN_ZIP )
376 if( ! IRC_WriteStrClient( from, RPL_STATSLINKINFOZIP_MSG, Client_ID( from ), Client_Mask( cl ), Conn_SendQ( con ), Conn_SendMsg( con ), Conn_SendBytesZip( con ), Conn_SendBytes( con ), Conn_RecvMsg( con ), Conn_RecvBytesZip( con ), Conn_RecvBytes( con ), (LONG)( time( NULL ) - Conn_StartTime( con )))) return DISCONNECTED;
381 if( ! IRC_WriteStrClient( from, RPL_STATSLINKINFO_MSG, Client_ID( from ), Client_Mask( cl ), Conn_SendQ( con ), Conn_SendMsg( con ), Conn_SendBytes( con ), Conn_RecvMsg( con ), Conn_RecvBytes( con ), (LONG)( time( NULL ) - Conn_StartTime( con )))) return DISCONNECTED;
384 con = Conn_Next( con );
387 case 'm': /* IRC-Befehle */
392 return IRC_WriteStrClient( from, RPL_ENDOFSTATS_MSG, Client_ID( from ), query );
397 IRC_TIME( CLIENT *Client, REQUEST *Req )
399 CLIENT *from, *target;
403 assert( Client != NULL );
404 assert( Req != NULL );
406 /* Falsche Anzahl Parameter? */
407 if( Req->argc > 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
409 /* From aus Prefix ermitteln */
410 if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
412 if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
416 /* an anderen Server forwarden */
417 target = Client_Search( Req->argv[0] );
418 if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[0] );
420 if( target != Client_ThisServer( ))
422 /* Ok, anderer Server ist das Ziel: forwarden */
423 return IRC_WriteStrClientPrefix( target, from, "TIME %s", Req->argv[0] );
428 (VOID)strftime( t_str, 60, "%A %B %d %Y -- %H:%M %z", localtime( &t ));
429 return IRC_WriteStrClient( from, RPL_TIME_MSG, Client_ID( from ), Client_ID( Client_ThisServer( )), t_str );
434 IRC_USERHOST( CLIENT *Client, REQUEST *Req )
436 CHAR rpl[COMMAND_LEN];
440 assert( Client != NULL );
441 assert( Req != NULL );
443 /* Falsche Anzahl Parameter? */
444 if(( Req->argc < 1 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
446 if( Req->argc > 5 ) max = 5;
447 else max = Req->argc;
449 strcpy( rpl, RPL_USERHOST_MSG );
450 for( i = 0; i < max; i++ )
452 c = Client_Search( Req->argv[i] );
453 if( c && ( Client_Type( c ) == CLIENT_USER ))
455 /* Dieser Nick ist "online" */
456 strcat( rpl, Client_ID( c ));
457 if( Client_HasMode( c, 'o' )) strcat( rpl, "*" );
459 if( Client_HasMode( c, 'a' )) strcat( rpl, "-" );
460 else strcat( rpl, "+" );
461 strcat( rpl, Client_User( c ));
463 strcat( rpl, Client_Hostname( c ));
467 if( rpl[strlen( rpl ) - 1] == ' ' ) rpl[strlen( rpl ) - 1] = '\0';
469 return IRC_WriteStrClient( Client, rpl, Client_ID( Client ) );
474 IRC_VERSION( CLIENT *Client, REQUEST *Req )
476 CLIENT *target, *prefix;
478 assert( Client != NULL );
479 assert( Req != NULL );
481 /* Falsche Anzahl Parameter? */
482 if(( Req->argc > 1 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
485 if( Req->argc == 1 ) target = Client_Search( Req->argv[0] );
486 else target = Client_ThisServer( );
488 /* Prefix ermitteln */
489 if( Client_Type( Client ) == CLIENT_SERVER ) prefix = Client_Search( Req->prefix );
490 else prefix = Client;
491 if( ! prefix ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
493 /* An anderen Server weiterleiten? */
494 if( target != Client_ThisServer( ))
496 if( ! target ) return IRC_WriteStrClient( prefix, ERR_NOSUCHSERVER_MSG, Client_ID( prefix ), Req->argv[0] );
499 IRC_WriteStrClientPrefix( target, prefix, "VERSION %s", Req->argv[0] );
503 /* mit Versionsinfo antworten */
504 return IRC_WriteStrClient( Client, RPL_VERSION_MSG, Client_ID( prefix ), PACKAGE, VERSION, NGIRCd_DebugLevel, Conf_ServerName, NGIRCd_VersionAddition( ));
509 IRC_WHO( CLIENT *Client, REQUEST *Req )
511 BOOLEAN ok, only_ops;
517 assert( Client != NULL );
518 assert( Req != NULL );
520 /* Falsche Anzahl Parameter? */
521 if(( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
528 /* Nur OPs anzeigen? */
529 if( strcmp( Req->argv[1], "o" ) == 0 ) only_ops = TRUE;
531 else return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
537 /* wurde ein Channel oder Nick-Mask angegeben? */
538 chan = Channel_Search( Req->argv[0] );
543 /* User eines Channels ausgeben */
544 if( ! IRC_Send_WHO( Client, chan, only_ops )) return DISCONNECTED;
550 if(( Client_Type( c ) == CLIENT_USER ) && ( ! strchr( Client_Modes( c ), 'i' )))
553 if( Req->argc == 0 ) ok = TRUE;
556 if( strcasecmp( Req->argv[0], Client_ID( c )) == 0 ) ok = TRUE;
557 else if( strcmp( Req->argv[0], "0" ) == 0 ) ok = TRUE;
560 if( ok && (( ! only_ops ) || ( strchr( Client_Modes( c ), 'o' ))))
562 /* Flags zusammenbasteln */
563 strcpy( flags, "H" );
564 if( strchr( Client_Modes( c ), 'o' )) strcat( flags, "*" );
567 cl2chan = Channel_FirstChannelOf( c );
568 if( cl2chan ) ptr = Channel_Name( Channel_GetChannel( cl2chan ));
570 if( ! IRC_WriteStrClient( Client, RPL_WHOREPLY_MSG, Client_ID( Client ), ptr, Client_User( c ), Client_Hostname( c ), Client_ID( Client_Introducer( c )), Client_ID( c ), flags, Client_Hops( c ), Client_Info( c ))) return DISCONNECTED;
574 /* naechster Client */
575 c = Client_Next( c );
578 if( chan ) return IRC_WriteStrClient( Client, RPL_ENDOFWHO_MSG, Client_ID( Client ), Channel_Name( chan ));
579 else if( Req->argc == 0 ) return IRC_WriteStrClient( Client, RPL_ENDOFWHO_MSG, Client_ID( Client ), "*" );
580 else return IRC_WriteStrClient( Client, RPL_ENDOFWHO_MSG, Client_ID( Client ), Req->argv[0] );
585 IRC_WHOIS( CLIENT *Client, REQUEST *Req )
587 CLIENT *from, *target, *c;
588 CHAR str[LINE_LEN + 1], *ptr = NULL;
592 assert( Client != NULL );
593 assert( Req != NULL );
595 /* Falsche Anzahl Parameter? */
596 if(( Req->argc < 1 ) || ( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
599 c = Client_Search( Req->argv[Req->argc - 1] );
600 if(( ! c ) || ( Client_Type( c ) != CLIENT_USER )) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->argv[Req->argc - 1] );
602 /* Empfaenger des WHOIS suchen */
603 if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
605 if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
607 /* Forwarden an anderen Server? */
610 /* angegebenen Ziel-Server suchen */
611 target = Client_Search( Req->argv[1] );
612 if( ! target ) return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[1] );
615 else target = Client_ThisServer( );
617 assert( target != NULL );
619 if(( Client_NextHop( target ) != Client_ThisServer( )) && ( Client_Type( Client_NextHop( target )) == CLIENT_SERVER )) return IRC_WriteStrClientPrefix( target, from, "WHOIS %s :%s", Req->argv[0], ptr );
621 /* Nick, User und Name */
622 if( ! IRC_WriteStrClient( from, RPL_WHOISUSER_MSG, Client_ID( from ), Client_ID( c ), Client_User( c ), Client_Hostname( c ), Client_Info( c ))) return DISCONNECTED;
625 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;
628 sprintf( str, RPL_WHOISCHANNELS_MSG, Client_ID( from ), Client_ID( c ));
629 cl2chan = Channel_FirstChannelOf( c );
632 chan = Channel_GetChannel( cl2chan );
633 assert( chan != NULL );
635 /* Channel-Name anhaengen */
636 if( str[strlen( str ) - 1] != ':' ) strcat( str, " " );
637 if( strchr( Channel_UserModes( chan, c ), 'o' )) strcat( str, "@" );
638 else if( strchr( Channel_UserModes( chan, c ), 'v' )) strcat( str, "+" );
639 strcat( str, Channel_Name( chan ));
641 if( strlen( str ) > ( LINE_LEN - CHANNEL_NAME_LEN - 4 ))
643 /* Zeile wird zu lang: senden! */
644 if( ! IRC_WriteStrClient( Client, "%s", str )) return DISCONNECTED;
645 sprintf( str, RPL_WHOISCHANNELS_MSG, Client_ID( from ), Client_ID( c ));
648 /* naechstes Mitglied suchen */
649 cl2chan = Channel_NextChannelOf( c, cl2chan );
651 if( str[strlen( str ) - 1] != ':')
653 /* Es sind noch Daten da, die gesendet werden muessen */
654 if( ! IRC_WriteStrClient( Client, "%s", str )) return DISCONNECTED;
658 if( Client_HasMode( c, 'o' ))
660 if( ! IRC_WriteStrClient( from, RPL_WHOISOPERATOR_MSG, Client_ID( from ), Client_ID( c ))) return DISCONNECTED;
663 /* Idle (nur lokale Clients) */
664 if( Client_Conn( c ) > NONE )
666 if( ! IRC_WriteStrClient( from, RPL_WHOISIDLE_MSG, Client_ID( from ), Client_ID( c ), Conn_GetIdle( Client_Conn ( c )))) return DISCONNECTED;
670 if( Client_HasMode( c, 'a' ))
672 if( ! IRC_WriteStrClient( from, RPL_AWAY_MSG, Client_ID( from ), Client_ID( c ), Client_Away( c ))) return DISCONNECTED;
676 return IRC_WriteStrClient( from, RPL_ENDOFWHOIS_MSG, Client_ID( from ), Client_ID( c ));
681 IRC_WHOWAS( CLIENT *Client, REQUEST *Req )
683 assert( Client != NULL );
684 assert( Req != NULL );
686 /* Falsche Anzahl Parameter? */
687 if(( Req->argc < 1 ) || ( Req->argc > 3 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
696 IRC_Send_LUSERS( CLIENT *Client )
700 assert( Client != NULL );
702 /* Users, Services und Serevr im Netz */
703 if( ! IRC_WriteStrClient( Client, RPL_LUSERCLIENT_MSG, Client_ID( Client ), Client_UserCount( ), Client_ServiceCount( ), Client_ServerCount( ))) return DISCONNECTED;
705 /* IRC-Operatoren im Netz */
706 cnt = Client_OperCount( );
709 if( ! IRC_WriteStrClient( Client, RPL_LUSEROP_MSG, Client_ID( Client ), cnt )) return DISCONNECTED;
712 /* Unbekannt Verbindungen */
713 cnt = Client_UnknownCount( );
716 if( ! IRC_WriteStrClient( Client, RPL_LUSERUNKNOWN_MSG, Client_ID( Client ), cnt )) return DISCONNECTED;
719 /* Channels im Netz */
720 if( ! IRC_WriteStrClient( Client, RPL_LUSERCHANNELS_MSG, Client_ID( Client ), Channel_Count( ))) return DISCONNECTED;
722 /* Channels im Netz */
723 if( ! IRC_WriteStrClient( Client, RPL_LUSERME_MSG, Client_ID( Client ), Client_MyUserCount( ), Client_MyServiceCount( ), Client_MyServerCount( ))) return DISCONNECTED;
726 } /* IRC_Send_LUSERS */
730 IRC_Show_MOTD( CLIENT *Client )
736 assert( Client != NULL );
738 fd = fopen( Conf_MotdFile, "r" );
741 Log( LOG_WARNING, "Can't read MOTD file \"%s\": %s", Conf_MotdFile, strerror( errno ));
742 return IRC_WriteStrClient( Client, ERR_NOMOTD_MSG, Client_ID( Client ) );
745 IRC_WriteStrClient( Client, RPL_MOTDSTART_MSG, Client_ID( Client ), Client_ID( Client_ThisServer( )));
748 if( ! fgets( line, 126, fd )) break;
749 if( line[strlen( line ) - 1] == '\n' ) line[strlen( line ) - 1] = '\0';
750 if( ! IRC_WriteStrClient( Client, RPL_MOTD_MSG, Client_ID( Client ), line ))
756 ok = IRC_WriteStrClient( Client, RPL_ENDOFMOTD_MSG, Client_ID( Client ) );
761 } /* IRC_Show_MOTD */
765 IRC_Send_NAMES( CLIENT *Client, CHANNEL *Chan )
767 BOOLEAN is_visible, is_member;
768 CHAR str[LINE_LEN + 1];
772 assert( Client != NULL );
773 assert( Chan != NULL );
775 if( Channel_IsMemberOf( Chan, Client )) is_member = TRUE;
776 else is_member = FALSE;
778 /* Alle Mitglieder suchen */
779 sprintf( str, RPL_NAMREPLY_MSG, Client_ID( Client ), "=", Channel_Name( Chan ));
780 cl2chan = Channel_FirstMember( Chan );
783 cl = Channel_GetClient( cl2chan );
785 if( strchr( Client_Modes( cl ), 'i' )) is_visible = FALSE;
786 else is_visible = TRUE;
788 if( is_member || is_visible )
791 if( str[strlen( str ) - 1] != ':' ) strcat( str, " " );
792 if( strchr( Channel_UserModes( Chan, cl ), 'o' )) strcat( str, "@" );
793 else if( strchr( Channel_UserModes( Chan, cl ), 'v' )) strcat( str, "+" );
794 strcat( str, Client_ID( cl ));
796 if( strlen( str ) > ( LINE_LEN - CLIENT_NICK_LEN - 4 ))
798 /* Zeile wird zu lang: senden! */
799 if( ! IRC_WriteStrClient( Client, "%s", str )) return DISCONNECTED;
800 sprintf( str, RPL_NAMREPLY_MSG, Client_ID( Client ), "=", Channel_Name( Chan ));
804 /* naechstes Mitglied suchen */
805 cl2chan = Channel_NextMember( Chan, cl2chan );
807 if( str[strlen( str ) - 1] != ':')
809 /* Es sind noch Daten da, die gesendet werden muessen */
810 if( ! IRC_WriteStrClient( Client, "%s", str )) return DISCONNECTED;
814 } /* IRC_Send_NAMES */
818 IRC_Send_WHO( CLIENT *Client, CHANNEL *Chan, BOOLEAN OnlyOps )
820 BOOLEAN is_visible, is_member;
825 assert( Client != NULL );
826 assert( Chan != NULL );
828 if( Channel_IsMemberOf( Chan, Client )) is_member = TRUE;
829 else is_member = FALSE;
831 /* Alle Mitglieder suchen */
832 cl2chan = Channel_FirstMember( Chan );
835 c = Channel_GetClient( cl2chan );
837 if( strchr( Client_Modes( c ), 'i' )) is_visible = FALSE;
838 else is_visible = TRUE;
840 if( is_member || is_visible )
842 /* Flags zusammenbasteln */
843 strcpy( flags, "H" );
844 if( strchr( Client_Modes( c ), 'o' )) strcat( flags, "*" );
845 if( strchr( Channel_UserModes( Chan, c ), 'o' )) strcat( flags, "@" );
846 else if( strchr( Channel_UserModes( Chan, c ), 'v' )) strcat( flags, "+" );
849 if(( ! OnlyOps ) || ( strchr( Client_Modes( c ), 'o' )))
851 if( ! IRC_WriteStrClient( Client, RPL_WHOREPLY_MSG, Client_ID( Client ), Channel_Name( Chan ), Client_User( c ), Client_Hostname( c ), Client_ID( Client_Introducer( c )), Client_ID( c ), flags, Client_Hops( c ), Client_Info( c ))) return DISCONNECTED;
855 /* naechstes Mitglied suchen */
856 cl2chan = Channel_NextMember( Chan, cl2chan );