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.9 2002/12/22 23:30:33 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;
337 assert( Client != NULL );
338 assert( Req != NULL );
340 /* Falsche Anzahl Parameter? */
341 if( Req->argc > 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
343 /* From aus Prefix ermitteln */
344 if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
346 if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
350 /* an anderen Server forwarden */
351 target = Client_Search( Req->argv[1] );
352 if( ! target ) return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[1] );
354 if( target != Client_ThisServer( ))
356 /* Ok, anderer Server ist das Ziel: forwarden */
357 return IRC_WriteStrClientPrefix( target, from, "STATS %s %s", Req->argv[0], Req->argv[1] );
361 if( Req->argc > 0 ) query = Req->argv[0][0] ? Req->argv[0][0] : '*';
366 case 'l': /* Links */
371 cl = Client_GetFromConn( con );
372 if( cl && (( Client_Type( cl ) == CLIENT_SERVER ) || ( cl == Client )))
374 /* Server link or our own connection */
376 if( Conn_Options( con ) & CONN_ZIP )
378 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;
383 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;
386 con = Conn_Next( con );
389 case 'm': /* IRC-Befehle */
391 cmd = Parse_GetCommandStruct( );
394 if( cmd->lcount > 0 || cmd->rcount > 0 )
396 if( ! IRC_WriteStrClient( from, RPL_STATSCOMMANDS_MSG, Client_ID( from ), cmd->name, cmd->lcount, cmd->bytes, cmd->rcount )) return DISCONNECTED;
403 return IRC_WriteStrClient( from, RPL_ENDOFSTATS_MSG, Client_ID( from ), query );
408 IRC_TIME( CLIENT *Client, REQUEST *Req )
410 CLIENT *from, *target;
414 assert( Client != NULL );
415 assert( Req != NULL );
417 /* Falsche Anzahl Parameter? */
418 if( Req->argc > 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
420 /* From aus Prefix ermitteln */
421 if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
423 if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
427 /* an anderen Server forwarden */
428 target = Client_Search( Req->argv[0] );
429 if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[0] );
431 if( target != Client_ThisServer( ))
433 /* Ok, anderer Server ist das Ziel: forwarden */
434 return IRC_WriteStrClientPrefix( target, from, "TIME %s", Req->argv[0] );
439 (VOID)strftime( t_str, 60, "%A %B %d %Y -- %H:%M %z", localtime( &t ));
440 return IRC_WriteStrClient( from, RPL_TIME_MSG, Client_ID( from ), Client_ID( Client_ThisServer( )), t_str );
445 IRC_USERHOST( CLIENT *Client, REQUEST *Req )
447 CHAR rpl[COMMAND_LEN];
451 assert( Client != NULL );
452 assert( Req != NULL );
454 /* Falsche Anzahl Parameter? */
455 if(( Req->argc < 1 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
457 if( Req->argc > 5 ) max = 5;
458 else max = Req->argc;
460 strcpy( rpl, RPL_USERHOST_MSG );
461 for( i = 0; i < max; i++ )
463 c = Client_Search( Req->argv[i] );
464 if( c && ( Client_Type( c ) == CLIENT_USER ))
466 /* Dieser Nick ist "online" */
467 strcat( rpl, Client_ID( c ));
468 if( Client_HasMode( c, 'o' )) strcat( rpl, "*" );
470 if( Client_HasMode( c, 'a' )) strcat( rpl, "-" );
471 else strcat( rpl, "+" );
472 strcat( rpl, Client_User( c ));
474 strcat( rpl, Client_Hostname( c ));
478 if( rpl[strlen( rpl ) - 1] == ' ' ) rpl[strlen( rpl ) - 1] = '\0';
480 return IRC_WriteStrClient( Client, rpl, Client_ID( Client ) );
485 IRC_VERSION( CLIENT *Client, REQUEST *Req )
487 CLIENT *target, *prefix;
489 assert( Client != NULL );
490 assert( Req != NULL );
492 /* Falsche Anzahl Parameter? */
493 if(( Req->argc > 1 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
496 if( Req->argc == 1 ) target = Client_Search( Req->argv[0] );
497 else target = Client_ThisServer( );
499 /* Prefix ermitteln */
500 if( Client_Type( Client ) == CLIENT_SERVER ) prefix = Client_Search( Req->prefix );
501 else prefix = Client;
502 if( ! prefix ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
504 /* An anderen Server weiterleiten? */
505 if( target != Client_ThisServer( ))
507 if( ! target ) return IRC_WriteStrClient( prefix, ERR_NOSUCHSERVER_MSG, Client_ID( prefix ), Req->argv[0] );
510 IRC_WriteStrClientPrefix( target, prefix, "VERSION %s", Req->argv[0] );
514 /* mit Versionsinfo antworten */
515 return IRC_WriteStrClient( Client, RPL_VERSION_MSG, Client_ID( prefix ), PACKAGE, VERSION, NGIRCd_DebugLevel, Conf_ServerName, NGIRCd_VersionAddition( ));
520 IRC_WHO( CLIENT *Client, REQUEST *Req )
522 BOOLEAN ok, only_ops;
528 assert( Client != NULL );
529 assert( Req != NULL );
531 /* Falsche Anzahl Parameter? */
532 if(( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
539 /* Nur OPs anzeigen? */
540 if( strcmp( Req->argv[1], "o" ) == 0 ) only_ops = TRUE;
542 else return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
548 /* wurde ein Channel oder Nick-Mask angegeben? */
549 chan = Channel_Search( Req->argv[0] );
554 /* User eines Channels ausgeben */
555 if( ! IRC_Send_WHO( Client, chan, only_ops )) return DISCONNECTED;
561 if(( Client_Type( c ) == CLIENT_USER ) && ( ! strchr( Client_Modes( c ), 'i' )))
564 if( Req->argc == 0 ) ok = TRUE;
567 if( strcasecmp( Req->argv[0], Client_ID( c )) == 0 ) ok = TRUE;
568 else if( strcmp( Req->argv[0], "0" ) == 0 ) ok = TRUE;
571 if( ok && (( ! only_ops ) || ( strchr( Client_Modes( c ), 'o' ))))
573 /* Flags zusammenbasteln */
574 strcpy( flags, "H" );
575 if( strchr( Client_Modes( c ), 'o' )) strcat( flags, "*" );
578 cl2chan = Channel_FirstChannelOf( c );
579 if( cl2chan ) ptr = Channel_Name( Channel_GetChannel( cl2chan ));
581 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;
585 /* naechster Client */
586 c = Client_Next( c );
589 if( chan ) return IRC_WriteStrClient( Client, RPL_ENDOFWHO_MSG, Client_ID( Client ), Channel_Name( chan ));
590 else if( Req->argc == 0 ) return IRC_WriteStrClient( Client, RPL_ENDOFWHO_MSG, Client_ID( Client ), "*" );
591 else return IRC_WriteStrClient( Client, RPL_ENDOFWHO_MSG, Client_ID( Client ), Req->argv[0] );
596 IRC_WHOIS( CLIENT *Client, REQUEST *Req )
598 CLIENT *from, *target, *c;
599 CHAR str[LINE_LEN + 1], *ptr = NULL;
603 assert( Client != NULL );
604 assert( Req != NULL );
606 /* Falsche Anzahl Parameter? */
607 if(( Req->argc < 1 ) || ( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
610 c = Client_Search( Req->argv[Req->argc - 1] );
611 if(( ! c ) || ( Client_Type( c ) != CLIENT_USER )) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->argv[Req->argc - 1] );
613 /* Empfaenger des WHOIS suchen */
614 if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
616 if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
618 /* Forwarden an anderen Server? */
621 /* angegebenen Ziel-Server suchen */
622 target = Client_Search( Req->argv[1] );
623 if( ! target ) return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[1] );
626 else target = Client_ThisServer( );
628 assert( target != NULL );
630 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 );
632 /* Nick, User und Name */
633 if( ! IRC_WriteStrClient( from, RPL_WHOISUSER_MSG, Client_ID( from ), Client_ID( c ), Client_User( c ), Client_Hostname( c ), Client_Info( c ))) return DISCONNECTED;
636 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;
639 sprintf( str, RPL_WHOISCHANNELS_MSG, Client_ID( from ), Client_ID( c ));
640 cl2chan = Channel_FirstChannelOf( c );
643 chan = Channel_GetChannel( cl2chan );
644 assert( chan != NULL );
646 /* Channel-Name anhaengen */
647 if( str[strlen( str ) - 1] != ':' ) strcat( str, " " );
648 if( strchr( Channel_UserModes( chan, c ), 'o' )) strcat( str, "@" );
649 else if( strchr( Channel_UserModes( chan, c ), 'v' )) strcat( str, "+" );
650 strcat( str, Channel_Name( chan ));
652 if( strlen( str ) > ( LINE_LEN - CHANNEL_NAME_LEN - 4 ))
654 /* Zeile wird zu lang: senden! */
655 if( ! IRC_WriteStrClient( Client, "%s", str )) return DISCONNECTED;
656 sprintf( str, RPL_WHOISCHANNELS_MSG, Client_ID( from ), Client_ID( c ));
659 /* naechstes Mitglied suchen */
660 cl2chan = Channel_NextChannelOf( c, cl2chan );
662 if( str[strlen( str ) - 1] != ':')
664 /* Es sind noch Daten da, die gesendet werden muessen */
665 if( ! IRC_WriteStrClient( Client, "%s", str )) return DISCONNECTED;
669 if( Client_HasMode( c, 'o' ))
671 if( ! IRC_WriteStrClient( from, RPL_WHOISOPERATOR_MSG, Client_ID( from ), Client_ID( c ))) return DISCONNECTED;
674 /* Idle (nur lokale Clients) */
675 if( Client_Conn( c ) > NONE )
677 if( ! IRC_WriteStrClient( from, RPL_WHOISIDLE_MSG, Client_ID( from ), Client_ID( c ), Conn_GetIdle( Client_Conn ( c )))) return DISCONNECTED;
681 if( Client_HasMode( c, 'a' ))
683 if( ! IRC_WriteStrClient( from, RPL_AWAY_MSG, Client_ID( from ), Client_ID( c ), Client_Away( c ))) return DISCONNECTED;
687 return IRC_WriteStrClient( from, RPL_ENDOFWHOIS_MSG, Client_ID( from ), Client_ID( c ));
692 IRC_WHOWAS( CLIENT *Client, REQUEST *Req )
694 assert( Client != NULL );
695 assert( Req != NULL );
697 /* Falsche Anzahl Parameter? */
698 if(( Req->argc < 1 ) || ( Req->argc > 3 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
707 IRC_Send_LUSERS( CLIENT *Client )
711 assert( Client != NULL );
713 /* Users, services and serevers in the network */
714 if( ! IRC_WriteStrClient( Client, RPL_LUSERCLIENT_MSG, Client_ID( Client ), Client_UserCount( ), Client_ServiceCount( ), Client_ServerCount( ))) return DISCONNECTED;
716 /* Number of IRC operators */
717 cnt = Client_OperCount( );
720 if( ! IRC_WriteStrClient( Client, RPL_LUSEROP_MSG, Client_ID( Client ), cnt )) return DISCONNECTED;
723 /* Unknown connections */
724 cnt = Client_UnknownCount( );
727 if( ! IRC_WriteStrClient( Client, RPL_LUSERUNKNOWN_MSG, Client_ID( Client ), cnt )) return DISCONNECTED;
730 /* Number of created channels */
731 if( ! IRC_WriteStrClient( Client, RPL_LUSERCHANNELS_MSG, Client_ID( Client ), Channel_Count( ))) return DISCONNECTED;
733 /* Number of local users, services and servers */
734 if( ! IRC_WriteStrClient( Client, RPL_LUSERME_MSG, Client_ID( Client ), Client_MyUserCount( ), Client_MyServiceCount( ), Client_MyServerCount( ))) return DISCONNECTED;
737 /* Maximum number of local users */
738 if( ! IRC_WriteStrClient( Client, RPL_LOCALUSERS_MSG, Client_ID( Client ), Client_MyUserCount( ), Client_MyMaxUserCount( ))) return DISCONNECTED;
739 /* Maximum number of users in the network */
740 if( ! IRC_WriteStrClient( Client, RPL_NETUSERS_MSG, Client_ID( Client ), Client_UserCount( ), Client_MaxUserCount( ))) return DISCONNECTED;
744 } /* IRC_Send_LUSERS */
748 IRC_Show_MOTD( CLIENT *Client )
754 assert( Client != NULL );
756 fd = fopen( Conf_MotdFile, "r" );
759 Log( LOG_WARNING, "Can't read MOTD file \"%s\": %s", Conf_MotdFile, strerror( errno ));
760 return IRC_WriteStrClient( Client, ERR_NOMOTD_MSG, Client_ID( Client ) );
763 IRC_WriteStrClient( Client, RPL_MOTDSTART_MSG, Client_ID( Client ), Client_ID( Client_ThisServer( )));
766 if( ! fgets( line, 126, fd )) break;
767 if( line[strlen( line ) - 1] == '\n' ) line[strlen( line ) - 1] = '\0';
768 if( ! IRC_WriteStrClient( Client, RPL_MOTD_MSG, Client_ID( Client ), line ))
774 ok = IRC_WriteStrClient( Client, RPL_ENDOFMOTD_MSG, Client_ID( Client ) );
779 } /* IRC_Show_MOTD */
783 IRC_Send_NAMES( CLIENT *Client, CHANNEL *Chan )
785 BOOLEAN is_visible, is_member;
786 CHAR str[LINE_LEN + 1];
790 assert( Client != NULL );
791 assert( Chan != NULL );
793 if( Channel_IsMemberOf( Chan, Client )) is_member = TRUE;
794 else is_member = FALSE;
796 /* Alle Mitglieder suchen */
797 sprintf( str, RPL_NAMREPLY_MSG, Client_ID( Client ), "=", Channel_Name( Chan ));
798 cl2chan = Channel_FirstMember( Chan );
801 cl = Channel_GetClient( cl2chan );
803 if( strchr( Client_Modes( cl ), 'i' )) is_visible = FALSE;
804 else is_visible = TRUE;
806 if( is_member || is_visible )
809 if( str[strlen( str ) - 1] != ':' ) strcat( str, " " );
810 if( strchr( Channel_UserModes( Chan, cl ), 'o' )) strcat( str, "@" );
811 else if( strchr( Channel_UserModes( Chan, cl ), 'v' )) strcat( str, "+" );
812 strcat( str, Client_ID( cl ));
814 if( strlen( str ) > ( LINE_LEN - CLIENT_NICK_LEN - 4 ))
816 /* Zeile wird zu lang: senden! */
817 if( ! IRC_WriteStrClient( Client, "%s", str )) return DISCONNECTED;
818 sprintf( str, RPL_NAMREPLY_MSG, Client_ID( Client ), "=", Channel_Name( Chan ));
822 /* naechstes Mitglied suchen */
823 cl2chan = Channel_NextMember( Chan, cl2chan );
825 if( str[strlen( str ) - 1] != ':')
827 /* Es sind noch Daten da, die gesendet werden muessen */
828 if( ! IRC_WriteStrClient( Client, "%s", str )) return DISCONNECTED;
832 } /* IRC_Send_NAMES */
836 IRC_Send_WHO( CLIENT *Client, CHANNEL *Chan, BOOLEAN OnlyOps )
838 BOOLEAN is_visible, is_member;
843 assert( Client != NULL );
844 assert( Chan != NULL );
846 if( Channel_IsMemberOf( Chan, Client )) is_member = TRUE;
847 else is_member = FALSE;
849 /* Alle Mitglieder suchen */
850 cl2chan = Channel_FirstMember( Chan );
853 c = Channel_GetClient( cl2chan );
855 if( strchr( Client_Modes( c ), 'i' )) is_visible = FALSE;
856 else is_visible = TRUE;
858 if( is_member || is_visible )
860 /* Flags zusammenbasteln */
861 strcpy( flags, "H" );
862 if( strchr( Client_Modes( c ), 'o' )) strcat( flags, "*" );
863 if( strchr( Channel_UserModes( Chan, c ), 'o' )) strcat( flags, "@" );
864 else if( strchr( Channel_UserModes( Chan, c ), 'v' )) strcat( flags, "+" );
867 if(( ! OnlyOps ) || ( strchr( Client_Modes( c ), 'o' )))
869 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;
873 /* naechstes Mitglied suchen */
874 cl2chan = Channel_NextMember( Chan, cl2chan );