2 * ngIRCd -- The Next Generation IRC Daemon
3 * Copyright (c)2001,2002 by Alexander Barton (alex@barton.de)
5 * Dieses Programm ist freie Software. Sie koennen es unter den Bedingungen
6 * der GNU General Public License (GPL), wie von der Free Software Foundation
7 * herausgegeben, weitergeben und/oder modifizieren, entweder unter Version 2
8 * der Lizenz oder (wenn Sie es wuenschen) jeder spaeteren Version.
9 * Naehere Informationen entnehmen Sie bitter der Datei COPYING. Eine Liste
10 * der an ngIRCd beteiligten Autoren finden Sie in der Datei AUTHORS.
12 * $Id: irc.c,v 1.95 2002/09/16 09:14:45 alex Exp $
34 #include "irc-write.h"
45 IRC_MOTD( CLIENT *Client, REQUEST *Req )
47 assert( Client != NULL );
48 assert( Req != NULL );
50 if( Client_Type( Client ) != CLIENT_USER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
52 /* Falsche Anzahl Parameter? */
53 if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
55 return IRC_Show_MOTD( Client );
60 IRC_PRIVMSG( CLIENT *Client, REQUEST *Req )
65 assert( Client != NULL );
66 assert( Req != NULL );
68 if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
70 /* Falsche Anzahl Parameter? */
71 if( Req->argc == 0 ) return IRC_WriteStrClient( Client, ERR_NORECIPIENT_MSG, Client_ID( Client ), Req->command );
72 if( Req->argc == 1 ) return IRC_WriteStrClient( Client, ERR_NOTEXTTOSEND_MSG, Client_ID( Client ));
73 if( Req->argc > 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
75 if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
77 if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
79 cl = Client_Search( Req->argv[0] );
82 /* Okay, Ziel ist ein Client. Aber ist es auch ein User? */
83 if( Client_Type( cl ) != CLIENT_USER ) return IRC_WriteStrClient( from, ERR_NOSUCHNICK_MSG, Client_ID( from ), Req->argv[0] );
85 /* Okay, Ziel ist ein User */
86 if(( Client_Type( Client ) != CLIENT_SERVER ) && ( strchr( Client_Modes( cl ), 'a' )))
88 /* Ziel-User ist AWAY: Meldung verschicken */
89 if( ! IRC_WriteStrClient( from, RPL_AWAY_MSG, Client_ID( from ), Client_ID( cl ), Client_Away( cl ))) return DISCONNECTED;
93 if( Client_Conn( from ) > NONE ) Conn_UpdateIdle( Client_Conn( from ));
94 return IRC_WriteStrClientPrefix( cl, from, "PRIVMSG %s :%s", Client_ID( cl ), Req->argv[1] );
97 chan = Channel_Search( Req->argv[0] );
98 if( chan ) return Channel_Write( chan, from, Client, Req->argv[1] );
100 return IRC_WriteStrClient( from, ERR_NOSUCHNICK_MSG, Client_ID( from ), Req->argv[0] );
105 IRC_NOTICE( CLIENT *Client, REQUEST *Req )
109 assert( Client != NULL );
110 assert( Req != NULL );
112 if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
114 /* Falsche Anzahl Parameter? */
115 if( Req->argc != 2 ) return CONNECTED;
117 if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
119 if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
121 to = Client_Search( Req->argv[0] );
122 if(( to ) && ( Client_Type( to ) == CLIENT_USER ))
124 /* Okay, Ziel ist ein User */
125 return IRC_WriteStrClientPrefix( to, from, "NOTICE %s :%s", Client_ID( to ), Req->argv[1] );
127 else return CONNECTED;
132 IRC_NAMES( CLIENT *Client, REQUEST *Req )
134 CHAR rpl[COMMAND_LEN], *ptr;
135 CLIENT *target, *from, *c;
138 assert( Client != NULL );
139 assert( Req != NULL );
141 if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
143 /* Falsche Anzahl Parameter? */
144 if( Req->argc > 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
146 /* From aus Prefix ermitteln */
147 if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
149 if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->prefix );
153 /* an anderen Server forwarden */
154 target = Client_Search( Req->argv[1] );
155 if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[1] );
157 if( target != Client_ThisServer( ))
159 /* Ok, anderer Server ist das Ziel: forwarden */
160 return IRC_WriteStrClientPrefix( target, from, "NAMES %s :%s", Req->argv[0], Req->argv[1] );
166 /* bestimmte Channels durchgehen */
167 ptr = strtok( Req->argv[0], "," );
170 chan = Channel_Search( ptr );
174 if( ! IRC_Send_NAMES( from, chan )) return DISCONNECTED;
176 if( ! IRC_WriteStrClient( from, RPL_ENDOFNAMES_MSG, Client_ID( from ), ptr )) return DISCONNECTED;
178 /* naechsten Namen ermitteln */
179 ptr = strtok( NULL, "," );
184 /* alle Channels durchgehen */
185 chan = Channel_First( );
189 if( ! IRC_Send_NAMES( from, chan )) return DISCONNECTED;
191 /* naechster Channel */
192 chan = Channel_Next( chan );
195 /* Nun noch alle Clients ausgeben, die in keinem Channel sind */
197 sprintf( rpl, RPL_NAMREPLY_MSG, Client_ID( from ), "*", "*" );
200 if(( Client_Type( c ) == CLIENT_USER ) && ( Channel_FirstChannelOf( c ) == NULL ) && ( ! strchr( Client_Modes( c ), 'i' )))
202 /* Okay, das ist ein User: anhaengen */
203 if( rpl[strlen( rpl ) - 1] != ':' ) strcat( rpl, " " );
204 strcat( rpl, Client_ID( c ));
206 if( strlen( rpl ) > ( LINE_LEN - CLIENT_NICK_LEN - 4 ))
208 /* Zeile wird zu lang: senden! */
209 if( ! IRC_WriteStrClient( from, rpl )) return DISCONNECTED;
210 sprintf( rpl, RPL_NAMREPLY_MSG, Client_ID( from ), "*", "*" );
214 /* naechster Client */
215 c = Client_Next( c );
217 if( rpl[strlen( rpl ) - 1] != ':')
219 /* es wurden User gefunden */
220 if( ! IRC_WriteStrClient( from, rpl )) return DISCONNECTED;
223 return IRC_WriteStrClient( from, RPL_ENDOFNAMES_MSG, Client_ID( from ), "*" );
228 IRC_ISON( CLIENT *Client, REQUEST *Req )
230 CHAR rpl[COMMAND_LEN];
235 assert( Client != NULL );
236 assert( Req != NULL );
238 if( Client_Type( Client ) != CLIENT_USER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
240 /* Falsche Anzahl Parameter? */
241 if(( Req->argc < 1 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
243 strcpy( rpl, RPL_ISON_MSG );
244 for( i = 0; i < Req->argc; i++ )
246 ptr = strtok( Req->argv[i], " " );
250 c = Client_Search( ptr );
251 if( c && ( Client_Type( c ) == CLIENT_USER ))
253 /* Dieser Nick ist "online" */
257 ptr = strtok( NULL, " " );
260 if( rpl[strlen( rpl ) - 1] == ' ' ) rpl[strlen( rpl ) - 1] = '\0';
262 return IRC_WriteStrClient( Client, rpl, Client_ID( Client ) );
267 IRC_WHOIS( CLIENT *Client, REQUEST *Req )
269 CLIENT *from, *target, *c;
270 CHAR str[LINE_LEN + 1], *ptr = NULL;
274 assert( Client != NULL );
275 assert( Req != NULL );
277 if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
279 /* Falsche Anzahl Parameter? */
280 if(( Req->argc < 1 ) || ( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
283 c = Client_Search( Req->argv[Req->argc - 1] );
284 if(( ! c ) || ( Client_Type( c ) != CLIENT_USER )) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->argv[Req->argc - 1] );
286 /* Empfaenger des WHOIS suchen */
287 if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
289 if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
291 /* Forwarden an anderen Server? */
294 /* angegebenen Ziel-Server suchen */
295 target = Client_Search( Req->argv[1] );
296 if( ! target ) return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[1] );
299 else target = Client_ThisServer( );
301 assert( target != NULL );
303 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 );
305 /* Nick, User und Name */
306 if( ! IRC_WriteStrClient( from, RPL_WHOISUSER_MSG, Client_ID( from ), Client_ID( c ), Client_User( c ), Client_Hostname( c ), Client_Info( c ))) return DISCONNECTED;
309 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;
312 sprintf( str, RPL_WHOISCHANNELS_MSG, Client_ID( from ), Client_ID( c ));
313 cl2chan = Channel_FirstChannelOf( c );
316 chan = Channel_GetChannel( cl2chan );
317 assert( chan != NULL );
319 /* Channel-Name anhaengen */
320 if( str[strlen( str ) - 1] != ':' ) strcat( str, " " );
321 if( strchr( Channel_UserModes( chan, c ), 'o' )) strcat( str, "@" );
322 else if( strchr( Channel_UserModes( chan, c ), 'v' )) strcat( str, "+" );
323 strcat( str, Channel_Name( chan ));
325 if( strlen( str ) > ( LINE_LEN - CHANNEL_NAME_LEN - 4 ))
327 /* Zeile wird zu lang: senden! */
328 if( ! IRC_WriteStrClient( Client, str )) return DISCONNECTED;
329 sprintf( str, RPL_WHOISCHANNELS_MSG, Client_ID( from ), Client_ID( c ));
332 /* naechstes Mitglied suchen */
333 cl2chan = Channel_NextChannelOf( c, cl2chan );
335 if( str[strlen( str ) - 1] != ':')
337 /* Es sind noch Daten da, die gesendet werden muessen */
338 if( ! IRC_WriteStrClient( Client, str )) return DISCONNECTED;
342 if( Client_HasMode( c, 'o' ))
344 if( ! IRC_WriteStrClient( from, RPL_WHOISOPERATOR_MSG, Client_ID( from ), Client_ID( c ))) return DISCONNECTED;
347 /* Idle (nur lokale Clients) */
348 if( Client_Conn( c ) > NONE )
350 if( ! IRC_WriteStrClient( from, RPL_WHOISIDLE_MSG, Client_ID( from ), Client_ID( c ), Conn_GetIdle( Client_Conn ( c )))) return DISCONNECTED;
354 if( Client_HasMode( c, 'a' ))
356 if( ! IRC_WriteStrClient( from, RPL_AWAY_MSG, Client_ID( from ), Client_ID( c ), Client_Away( c ))) return DISCONNECTED;
360 return IRC_WriteStrClient( from, RPL_ENDOFWHOIS_MSG, Client_ID( from ), Client_ID( c ));
365 IRC_WHO( CLIENT *Client, REQUEST *Req )
367 BOOLEAN ok, only_ops;
373 assert( Client != NULL );
374 assert( Req != NULL );
376 if( Client_Type( Client ) != CLIENT_USER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
378 /* Falsche Anzahl Parameter? */
379 if(( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
386 /* Nur OPs anzeigen? */
387 if( strcmp( Req->argv[1], "o" ) == 0 ) only_ops = TRUE;
389 else return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
395 /* wurde ein Channel oder Nick-Mask angegeben? */
396 chan = Channel_Search( Req->argv[0] );
401 /* User eines Channels ausgeben */
402 if( ! IRC_Send_WHO( Client, chan, only_ops )) return DISCONNECTED;
408 if(( Client_Type( c ) == CLIENT_USER ) && ( ! strchr( Client_Modes( c ), 'i' )))
411 if( Req->argc == 0 ) ok = TRUE;
414 if( strcasecmp( Req->argv[0], Client_ID( c )) == 0 ) ok = TRUE;
415 else if( strcmp( Req->argv[0], "0" ) == 0 ) ok = TRUE;
418 if( ok && (( ! only_ops ) || ( strchr( Client_Modes( c ), 'o' ))))
420 /* Flags zusammenbasteln */
421 strcpy( flags, "H" );
422 if( strchr( Client_Modes( c ), 'o' )) strcat( flags, "*" );
425 cl2chan = Channel_FirstChannelOf( c );
426 if( cl2chan ) ptr = Channel_Name( Channel_GetChannel( cl2chan ));
428 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;
432 /* naechster Client */
433 c = Client_Next( c );
436 if( chan ) return IRC_WriteStrClient( Client, RPL_ENDOFWHO_MSG, Client_ID( Client ), Channel_Name( chan ));
437 else if( Req->argc == 0 ) return IRC_WriteStrClient( Client, RPL_ENDOFWHO_MSG, Client_ID( Client ), "*" );
438 else return IRC_WriteStrClient( Client, RPL_ENDOFWHO_MSG, Client_ID( Client ), Req->argv[0] );
443 IRC_USERHOST( CLIENT *Client, REQUEST *Req )
445 CHAR rpl[COMMAND_LEN];
449 assert( Client != NULL );
450 assert( Req != NULL );
452 if( Client_Type( Client ) != CLIENT_USER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
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_ERROR( CLIENT *Client, REQUEST *Req )
487 assert( Client != NULL );
488 assert( Req != NULL );
490 if( Req->argc < 1 ) Log( LOG_NOTICE, "Got ERROR from \"%s\"!", Client_Mask( Client ));
491 else Log( LOG_NOTICE, "Got ERROR from \"%s\": %s!", Client_Mask( Client ), Req->argv[0] );
498 IRC_LUSERS( CLIENT *Client, REQUEST *Req )
500 CLIENT *target, *from;
502 assert( Client != NULL );
503 assert( Req != NULL );
505 if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
507 /* Falsche Anzahl Parameter? */
508 if(( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
510 /* Absender ermitteln */
511 if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
513 if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
515 /* An anderen Server forwarden? */
518 target = Client_Search( Req->argv[1] );
519 if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[1] );
520 else if( target != Client_ThisServer( )) return IRC_WriteStrClientPrefix( target, from, "LUSERS %s %s", Req->argv[0], Req->argv[1] );
523 /* Wer ist der Absender? */
524 if( Client_Type( Client ) == CLIENT_SERVER ) target = Client_Search( Req->prefix );
525 else target = Client;
526 if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
528 IRC_Send_LUSERS( target );
535 IRC_LINKS( CLIENT *Client, REQUEST *Req )
537 CLIENT *target, *from, *c;
540 assert( Client != NULL );
541 assert( Req != NULL );
543 if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
545 /* Falsche Anzahl Parameter? */
546 if(( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
548 /* Server-Mask ermitteln */
549 if( Req->argc > 0 ) mask = Req->argv[Req->argc - 1];
552 /* Absender ermitteln */
553 if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
555 if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
557 /* An anderen Server forwarden? */
560 target = Client_Search( Req->argv[0] );
561 if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[0] );
562 else if( target != Client_ThisServer( )) return IRC_WriteStrClientPrefix( target, from, "LINKS %s %s", Req->argv[0], Req->argv[1] );
565 /* Wer ist der Absender? */
566 if( Client_Type( Client ) == CLIENT_SERVER ) target = Client_Search( Req->prefix );
567 else target = Client;
568 if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
573 if( Client_Type( c ) == CLIENT_SERVER )
575 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;
577 c = Client_Next( c );
580 return IRC_WriteStrClient( target, RPL_ENDOFLINKS_MSG, Client_ID( target ), mask );
585 IRC_VERSION( CLIENT *Client, REQUEST *Req )
587 CLIENT *target, *prefix;
589 assert( Client != NULL );
590 assert( Req != NULL );
592 /* Falsche Anzahl Parameter? */
593 if(( Req->argc > 1 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
596 if( Req->argc == 1 ) target = Client_Search( Req->argv[0] );
597 else target = Client_ThisServer( );
599 /* Prefix ermitteln */
600 if( Client_Type( Client ) == CLIENT_SERVER ) prefix = Client_Search( Req->prefix );
601 else prefix = Client;
602 if( ! prefix ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->prefix );
604 /* An anderen Server weiterleiten? */
605 if( target != Client_ThisServer( ))
607 if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[0] );
610 IRC_WriteStrClientPrefix( target, prefix, "VERSION %s", Req->argv[0] );
614 /* mit Versionsinfo antworten */
615 return IRC_WriteStrClient( Client, RPL_VERSION_MSG, Client_ID( prefix ), PACKAGE, VERSION, NGIRCd_DebugLevel, Conf_ServerName, NGIRCd_VersionAddition( ));
620 IRC_KILL( CLIENT *Client, REQUEST *Req )
624 assert( Client != NULL );
625 assert( Req != NULL );
627 if( Client_Type( Client ) != CLIENT_SERVER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
629 /* Falsche Anzahl Parameter? */
630 if(( Req->argc != 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
632 prefix = Client_Search( Req->prefix );
635 Log( LOG_WARNING, "Got KILL with invalid prefix: \"%s\"!", Req->prefix );
636 prefix = Client_ThisServer( );
639 Log( LOG_NOTICE, "Got KILL command from \"%s\" for \"%s\": %s", Client_Mask( prefix ), Req->argv[0], Req->argv[1] );
641 /* andere Server benachrichtigen */
642 IRC_WriteStrServersPrefix( Client, prefix, "KILL %s :%s", Req->argv[0], Req->argv[1] );
644 /* haben wir selber einen solchen Client? */
645 c = Client_Search( Req->argv[0] );
648 /* Ja, wir haben einen solchen Client */
649 if( Client_Conn( c ) != NONE ) Conn_Close( Client_Conn( c ), NULL, Req->argv[1], TRUE );
650 else Client_Destroy( c, NULL, Req->argv[1], TRUE );
652 else Log( LOG_NOTICE, "Client with nick \"%s\" is unknown here.", Req->argv[0] );
659 IRC_ADMIN(CLIENT *Client, REQUEST *Req )
661 CLIENT *target, *prefix;
663 assert( Client != NULL );
664 assert( Req != NULL );
666 if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
668 /* Falsche Anzahl Parameter? */
669 if(( Req->argc > 1 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
672 if( Req->argc == 1 ) target = Client_Search( Req->argv[0] );
673 else target = Client_ThisServer( );
675 /* Prefix ermitteln */
676 if( Client_Type( Client ) == CLIENT_SERVER ) prefix = Client_Search( Req->prefix );
677 else prefix = Client;
678 if( ! prefix ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->prefix );
680 /* An anderen Server weiterleiten? */
681 if( target != Client_ThisServer( ))
683 if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[0] );
686 IRC_WriteStrClientPrefix( target, prefix, "ADMIN %s", Req->argv[0] );
690 /* mit Versionsinfo antworten */
691 if( ! IRC_WriteStrClient( Client, RPL_ADMINME_MSG, Client_ID( prefix ), Conf_ServerName )) return DISCONNECTED;
692 if( ! IRC_WriteStrClient( Client, RPL_ADMINLOC1_MSG, Client_ID( prefix ), Conf_ServerAdmin1 )) return DISCONNECTED;
693 if( ! IRC_WriteStrClient( Client, RPL_ADMINLOC2_MSG, Client_ID( prefix ), Conf_ServerAdmin2 )) return DISCONNECTED;
694 if( ! IRC_WriteStrClient( Client, RPL_ADMINEMAIL_MSG, Client_ID( prefix ), Conf_ServerAdminMail )) return DISCONNECTED;
702 IRC_Show_MOTD( CLIENT *Client )
708 assert( Client != NULL );
710 fd = fopen( Conf_MotdFile, "r" );
713 Log( LOG_WARNING, "Can't read MOTD file \"%s\": %s", Conf_MotdFile, strerror( errno ));
714 return IRC_WriteStrClient( Client, ERR_NOMOTD_MSG, Client_ID( Client ) );
717 IRC_WriteStrClient( Client, RPL_MOTDSTART_MSG, Client_ID( Client ), Client_ID( Client_ThisServer( )));
720 if( ! fgets( line, 126, fd )) break;
721 if( line[strlen( line ) - 1] == '\n' ) line[strlen( line ) - 1] = '\0';
722 if( ! IRC_WriteStrClient( Client, RPL_MOTD_MSG, Client_ID( Client ), line ))
728 ok = IRC_WriteStrClient( Client, RPL_ENDOFMOTD_MSG, Client_ID( Client ) );
733 } /* IRC_Show_MOTD */
737 IRC_Send_NAMES( CLIENT *Client, CHANNEL *Chan )
739 BOOLEAN is_visible, is_member;
740 CHAR str[LINE_LEN + 1];
744 assert( Client != NULL );
745 assert( Chan != NULL );
747 if( Channel_IsMemberOf( Chan, Client )) is_member = TRUE;
748 else is_member = FALSE;
750 /* Alle Mitglieder suchen */
751 sprintf( str, RPL_NAMREPLY_MSG, Client_ID( Client ), "=", Channel_Name( Chan ));
752 cl2chan = Channel_FirstMember( Chan );
755 cl = Channel_GetClient( cl2chan );
757 if( strchr( Client_Modes( cl ), 'i' )) is_visible = FALSE;
758 else is_visible = TRUE;
760 if( is_member || is_visible )
763 if( str[strlen( str ) - 1] != ':' ) strcat( str, " " );
764 if( strchr( Channel_UserModes( Chan, cl ), 'o' )) strcat( str, "@" );
765 else if( strchr( Channel_UserModes( Chan, cl ), 'v' )) strcat( str, "+" );
766 strcat( str, Client_ID( cl ));
768 if( strlen( str ) > ( LINE_LEN - CLIENT_NICK_LEN - 4 ))
770 /* Zeile wird zu lang: senden! */
771 if( ! IRC_WriteStrClient( Client, str )) return DISCONNECTED;
772 sprintf( str, RPL_NAMREPLY_MSG, Client_ID( Client ), "=", Channel_Name( Chan ));
776 /* naechstes Mitglied suchen */
777 cl2chan = Channel_NextMember( Chan, cl2chan );
779 if( str[strlen( str ) - 1] != ':')
781 /* Es sind noch Daten da, die gesendet werden muessen */
782 if( ! IRC_WriteStrClient( Client, str )) return DISCONNECTED;
786 } /* IRC_Send_NAMES */
790 IRC_Send_WHO( CLIENT *Client, CHANNEL *Chan, BOOLEAN OnlyOps )
792 BOOLEAN is_visible, is_member;
797 assert( Client != NULL );
798 assert( Chan != NULL );
800 if( Channel_IsMemberOf( Chan, Client )) is_member = TRUE;
801 else is_member = FALSE;
803 /* Alle Mitglieder suchen */
804 cl2chan = Channel_FirstMember( Chan );
807 c = Channel_GetClient( cl2chan );
809 if( strchr( Client_Modes( c ), 'i' )) is_visible = FALSE;
810 else is_visible = TRUE;
812 if( is_member || is_visible )
814 /* Flags zusammenbasteln */
815 strcpy( flags, "H" );
816 if( strchr( Client_Modes( c ), 'o' )) strcat( flags, "*" );
817 if( strchr( Channel_UserModes( Chan, c ), 'o' )) strcat( flags, "@" );
818 else if( strchr( Channel_UserModes( Chan, c ), 'v' )) strcat( flags, "+" );
821 if(( ! OnlyOps ) || ( strchr( Client_Modes( c ), 'o' )))
823 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;
827 /* naechstes Mitglied suchen */
828 cl2chan = Channel_NextMember( Chan, cl2chan );
835 IRC_Send_LUSERS( CLIENT *Client )
839 assert( Client != NULL );
841 /* Users, Services und Serevr im Netz */
842 if( ! IRC_WriteStrClient( Client, RPL_LUSERCLIENT_MSG, Client_ID( Client ), Client_UserCount( ), Client_ServiceCount( ), Client_ServerCount( ))) return DISCONNECTED;
844 /* IRC-Operatoren im Netz */
845 cnt = Client_OperCount( );
848 if( ! IRC_WriteStrClient( Client, RPL_LUSEROP_MSG, Client_ID( Client ), cnt )) return DISCONNECTED;
851 /* Unbekannt Verbindungen */
852 cnt = Client_UnknownCount( );
855 if( ! IRC_WriteStrClient( Client, RPL_LUSERUNKNOWN_MSG, Client_ID( Client ), cnt )) return DISCONNECTED;
858 /* Channels im Netz */
859 if( ! IRC_WriteStrClient( Client, RPL_LUSERCHANNELS_MSG, Client_ID( Client ), Channel_Count( ))) return DISCONNECTED;
861 /* Channels im Netz */
862 if( ! IRC_WriteStrClient( Client, RPL_LUSERME_MSG, Client_ID( Client ), Client_MyUserCount( ), Client_MyServiceCount( ), Client_MyServerCount( ))) return DISCONNECTED;
865 } /* IRC_Send_LUSERS */