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.101 2002/11/24 16:36:03 alex Exp $
34 #include "irc-write.h"
45 IRC_MOTD( CLIENT *Client, REQUEST *Req )
47 CLIENT *from, *target;
49 assert( Client != NULL );
50 assert( Req != NULL );
52 if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
54 /* Falsche Anzahl Parameter? */
55 if( Req->argc > 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
57 /* From aus Prefix ermitteln */
58 if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
60 if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->prefix );
64 /* an anderen Server forwarden */
65 target = Client_Search( Req->argv[0] );
66 if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[0] );
68 if( target != Client_ThisServer( ))
70 /* Ok, anderer Server ist das Ziel: forwarden */
71 return IRC_WriteStrClientPrefix( target, from, "MOTD %s", Req->argv[0] );
75 return IRC_Show_MOTD( from );
80 IRC_PRIVMSG( CLIENT *Client, REQUEST *Req )
85 assert( Client != NULL );
86 assert( Req != NULL );
88 if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
90 /* Falsche Anzahl Parameter? */
91 if( Req->argc == 0 ) return IRC_WriteStrClient( Client, ERR_NORECIPIENT_MSG, Client_ID( Client ), Req->command );
92 if( Req->argc == 1 ) return IRC_WriteStrClient( Client, ERR_NOTEXTTOSEND_MSG, Client_ID( Client ));
93 if( Req->argc > 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
95 if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
97 if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
99 cl = Client_Search( Req->argv[0] );
102 /* Okay, Ziel ist ein Client. Aber ist es auch ein User? */
103 if( Client_Type( cl ) != CLIENT_USER ) return IRC_WriteStrClient( from, ERR_NOSUCHNICK_MSG, Client_ID( from ), Req->argv[0] );
105 /* Okay, Ziel ist ein User */
106 if(( Client_Type( Client ) != CLIENT_SERVER ) && ( strchr( Client_Modes( cl ), 'a' )))
108 /* Ziel-User ist AWAY: Meldung verschicken */
109 if( ! IRC_WriteStrClient( from, RPL_AWAY_MSG, Client_ID( from ), Client_ID( cl ), Client_Away( cl ))) return DISCONNECTED;
113 if( Client_Conn( from ) > NONE ) Conn_UpdateIdle( Client_Conn( from ));
114 return IRC_WriteStrClientPrefix( cl, from, "PRIVMSG %s :%s", Client_ID( cl ), Req->argv[1] );
117 chan = Channel_Search( Req->argv[0] );
118 if( chan ) return Channel_Write( chan, from, Client, Req->argv[1] );
120 return IRC_WriteStrClient( from, ERR_NOSUCHNICK_MSG, Client_ID( from ), Req->argv[0] );
125 IRC_NOTICE( CLIENT *Client, REQUEST *Req )
129 assert( Client != NULL );
130 assert( Req != NULL );
132 if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return CONNECTED;
134 /* Falsche Anzahl Parameter? */
135 if( Req->argc != 2 ) return CONNECTED;
137 if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
139 if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
141 to = Client_Search( Req->argv[0] );
142 if(( to ) && ( Client_Type( to ) == CLIENT_USER ))
144 /* Okay, Ziel ist ein User */
145 return IRC_WriteStrClientPrefix( to, from, "NOTICE %s :%s", Client_ID( to ), Req->argv[1] );
147 else return CONNECTED;
152 IRC_NAMES( CLIENT *Client, REQUEST *Req )
154 CHAR rpl[COMMAND_LEN], *ptr;
155 CLIENT *target, *from, *c;
158 assert( Client != NULL );
159 assert( Req != NULL );
161 if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
163 /* Falsche Anzahl Parameter? */
164 if( Req->argc > 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
166 /* From aus Prefix ermitteln */
167 if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
169 if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->prefix );
173 /* an anderen Server forwarden */
174 target = Client_Search( Req->argv[1] );
175 if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[1] );
177 if( target != Client_ThisServer( ))
179 /* Ok, anderer Server ist das Ziel: forwarden */
180 return IRC_WriteStrClientPrefix( target, from, "NAMES %s :%s", Req->argv[0], Req->argv[1] );
186 /* bestimmte Channels durchgehen */
187 ptr = strtok( Req->argv[0], "," );
190 chan = Channel_Search( ptr );
194 if( ! IRC_Send_NAMES( from, chan )) return DISCONNECTED;
196 if( ! IRC_WriteStrClient( from, RPL_ENDOFNAMES_MSG, Client_ID( from ), ptr )) return DISCONNECTED;
198 /* naechsten Namen ermitteln */
199 ptr = strtok( NULL, "," );
204 /* alle Channels durchgehen */
205 chan = Channel_First( );
209 if( ! IRC_Send_NAMES( from, chan )) return DISCONNECTED;
211 /* naechster Channel */
212 chan = Channel_Next( chan );
215 /* Nun noch alle Clients ausgeben, die in keinem Channel sind */
217 sprintf( rpl, RPL_NAMREPLY_MSG, Client_ID( from ), "*", "*" );
220 if(( Client_Type( c ) == CLIENT_USER ) && ( Channel_FirstChannelOf( c ) == NULL ) && ( ! strchr( Client_Modes( c ), 'i' )))
222 /* Okay, das ist ein User: anhaengen */
223 if( rpl[strlen( rpl ) - 1] != ':' ) strcat( rpl, " " );
224 strcat( rpl, Client_ID( c ));
226 if( strlen( rpl ) > ( LINE_LEN - CLIENT_NICK_LEN - 4 ))
228 /* Zeile wird zu lang: senden! */
229 if( ! IRC_WriteStrClient( from, "%s", rpl )) return DISCONNECTED;
230 sprintf( rpl, RPL_NAMREPLY_MSG, Client_ID( from ), "*", "*" );
234 /* naechster Client */
235 c = Client_Next( c );
237 if( rpl[strlen( rpl ) - 1] != ':')
239 /* es wurden User gefunden */
240 if( ! IRC_WriteStrClient( from, "%s", rpl )) return DISCONNECTED;
243 return IRC_WriteStrClient( from, RPL_ENDOFNAMES_MSG, Client_ID( from ), "*" );
248 IRC_ISON( CLIENT *Client, REQUEST *Req )
250 CHAR rpl[COMMAND_LEN];
255 assert( Client != NULL );
256 assert( Req != NULL );
258 if( Client_Type( Client ) != CLIENT_USER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
260 /* Falsche Anzahl Parameter? */
261 if(( Req->argc < 1 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
263 strcpy( rpl, RPL_ISON_MSG );
264 for( i = 0; i < Req->argc; i++ )
266 ptr = strtok( Req->argv[i], " " );
270 c = Client_Search( ptr );
271 if( c && ( Client_Type( c ) == CLIENT_USER ))
273 /* Dieser Nick ist "online" */
277 ptr = strtok( NULL, " " );
280 if( rpl[strlen( rpl ) - 1] == ' ' ) rpl[strlen( rpl ) - 1] = '\0';
282 return IRC_WriteStrClient( Client, "%s", rpl, Client_ID( Client ) );
287 IRC_WHOIS( CLIENT *Client, REQUEST *Req )
289 CLIENT *from, *target, *c;
290 CHAR str[LINE_LEN + 1], *ptr = NULL;
294 assert( Client != NULL );
295 assert( Req != NULL );
297 if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
299 /* Falsche Anzahl Parameter? */
300 if(( Req->argc < 1 ) || ( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
303 c = Client_Search( Req->argv[Req->argc - 1] );
304 if(( ! c ) || ( Client_Type( c ) != CLIENT_USER )) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->argv[Req->argc - 1] );
306 /* Empfaenger des WHOIS suchen */
307 if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
309 if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
311 /* Forwarden an anderen Server? */
314 /* angegebenen Ziel-Server suchen */
315 target = Client_Search( Req->argv[1] );
316 if( ! target ) return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[1] );
319 else target = Client_ThisServer( );
321 assert( target != NULL );
323 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 );
325 /* Nick, User und Name */
326 if( ! IRC_WriteStrClient( from, RPL_WHOISUSER_MSG, Client_ID( from ), Client_ID( c ), Client_User( c ), Client_Hostname( c ), Client_Info( c ))) return DISCONNECTED;
329 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;
332 sprintf( str, RPL_WHOISCHANNELS_MSG, Client_ID( from ), Client_ID( c ));
333 cl2chan = Channel_FirstChannelOf( c );
336 chan = Channel_GetChannel( cl2chan );
337 assert( chan != NULL );
339 /* Channel-Name anhaengen */
340 if( str[strlen( str ) - 1] != ':' ) strcat( str, " " );
341 if( strchr( Channel_UserModes( chan, c ), 'o' )) strcat( str, "@" );
342 else if( strchr( Channel_UserModes( chan, c ), 'v' )) strcat( str, "+" );
343 strcat( str, Channel_Name( chan ));
345 if( strlen( str ) > ( LINE_LEN - CHANNEL_NAME_LEN - 4 ))
347 /* Zeile wird zu lang: senden! */
348 if( ! IRC_WriteStrClient( Client, "%s", str )) return DISCONNECTED;
349 sprintf( str, RPL_WHOISCHANNELS_MSG, Client_ID( from ), Client_ID( c ));
352 /* naechstes Mitglied suchen */
353 cl2chan = Channel_NextChannelOf( c, cl2chan );
355 if( str[strlen( str ) - 1] != ':')
357 /* Es sind noch Daten da, die gesendet werden muessen */
358 if( ! IRC_WriteStrClient( Client, "%s", str )) return DISCONNECTED;
362 if( Client_HasMode( c, 'o' ))
364 if( ! IRC_WriteStrClient( from, RPL_WHOISOPERATOR_MSG, Client_ID( from ), Client_ID( c ))) return DISCONNECTED;
367 /* Idle (nur lokale Clients) */
368 if( Client_Conn( c ) > NONE )
370 if( ! IRC_WriteStrClient( from, RPL_WHOISIDLE_MSG, Client_ID( from ), Client_ID( c ), Conn_GetIdle( Client_Conn ( c )))) return DISCONNECTED;
374 if( Client_HasMode( c, 'a' ))
376 if( ! IRC_WriteStrClient( from, RPL_AWAY_MSG, Client_ID( from ), Client_ID( c ), Client_Away( c ))) return DISCONNECTED;
380 return IRC_WriteStrClient( from, RPL_ENDOFWHOIS_MSG, Client_ID( from ), Client_ID( c ));
385 IRC_WHOWAS( CLIENT *Client, REQUEST *Req )
387 assert( Client != NULL );
388 assert( Req != NULL );
390 if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
392 /* Falsche Anzahl Parameter? */
393 if(( Req->argc < 1 ) || ( Req->argc > 3 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
402 IRC_WHO( CLIENT *Client, REQUEST *Req )
404 BOOLEAN ok, only_ops;
410 assert( Client != NULL );
411 assert( Req != NULL );
413 if( Client_Type( Client ) != CLIENT_USER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
415 /* Falsche Anzahl Parameter? */
416 if(( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
423 /* Nur OPs anzeigen? */
424 if( strcmp( Req->argv[1], "o" ) == 0 ) only_ops = TRUE;
426 else return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
432 /* wurde ein Channel oder Nick-Mask angegeben? */
433 chan = Channel_Search( Req->argv[0] );
438 /* User eines Channels ausgeben */
439 if( ! IRC_Send_WHO( Client, chan, only_ops )) return DISCONNECTED;
445 if(( Client_Type( c ) == CLIENT_USER ) && ( ! strchr( Client_Modes( c ), 'i' )))
448 if( Req->argc == 0 ) ok = TRUE;
451 if( strcasecmp( Req->argv[0], Client_ID( c )) == 0 ) ok = TRUE;
452 else if( strcmp( Req->argv[0], "0" ) == 0 ) ok = TRUE;
455 if( ok && (( ! only_ops ) || ( strchr( Client_Modes( c ), 'o' ))))
457 /* Flags zusammenbasteln */
458 strcpy( flags, "H" );
459 if( strchr( Client_Modes( c ), 'o' )) strcat( flags, "*" );
462 cl2chan = Channel_FirstChannelOf( c );
463 if( cl2chan ) ptr = Channel_Name( Channel_GetChannel( cl2chan ));
465 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;
469 /* naechster Client */
470 c = Client_Next( c );
473 if( chan ) return IRC_WriteStrClient( Client, RPL_ENDOFWHO_MSG, Client_ID( Client ), Channel_Name( chan ));
474 else if( Req->argc == 0 ) return IRC_WriteStrClient( Client, RPL_ENDOFWHO_MSG, Client_ID( Client ), "*" );
475 else return IRC_WriteStrClient( Client, RPL_ENDOFWHO_MSG, Client_ID( Client ), Req->argv[0] );
480 IRC_USERHOST( CLIENT *Client, REQUEST *Req )
482 CHAR rpl[COMMAND_LEN];
486 assert( Client != NULL );
487 assert( Req != NULL );
489 if( Client_Type( Client ) != CLIENT_USER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
491 /* Falsche Anzahl Parameter? */
492 if(( Req->argc < 1 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
494 if( Req->argc > 5 ) max = 5;
495 else max = Req->argc;
497 strcpy( rpl, RPL_USERHOST_MSG );
498 for( i = 0; i < max; i++ )
500 c = Client_Search( Req->argv[i] );
501 if( c && ( Client_Type( c ) == CLIENT_USER ))
503 /* Dieser Nick ist "online" */
504 strcat( rpl, Client_ID( c ));
505 if( Client_HasMode( c, 'o' )) strcat( rpl, "*" );
507 if( Client_HasMode( c, 'a' )) strcat( rpl, "-" );
508 else strcat( rpl, "+" );
509 strcat( rpl, Client_User( c ));
511 strcat( rpl, Client_Hostname( c ));
515 if( rpl[strlen( rpl ) - 1] == ' ' ) rpl[strlen( rpl ) - 1] = '\0';
517 return IRC_WriteStrClient( Client, "%s", rpl, Client_ID( Client ) );
522 IRC_ERROR( CLIENT *Client, REQUEST *Req )
524 assert( Client != NULL );
525 assert( Req != NULL );
527 if( Req->argc < 1 ) Log( LOG_NOTICE, "Got ERROR from \"%s\"!", Client_Mask( Client ));
528 else Log( LOG_NOTICE, "Got ERROR from \"%s\": %s!", Client_Mask( Client ), Req->argv[0] );
535 IRC_LUSERS( CLIENT *Client, REQUEST *Req )
537 CLIENT *target, *from;
539 assert( Client != NULL );
540 assert( Req != NULL );
542 if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
544 /* Falsche Anzahl Parameter? */
545 if(( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
547 /* Absender ermitteln */
548 if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
550 if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
552 /* An anderen Server forwarden? */
555 target = Client_Search( Req->argv[1] );
556 if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[1] );
557 else if( target != Client_ThisServer( )) return IRC_WriteStrClientPrefix( target, from, "LUSERS %s %s", Req->argv[0], Req->argv[1] );
560 /* Wer ist der Absender? */
561 if( Client_Type( Client ) == CLIENT_SERVER ) target = Client_Search( Req->prefix );
562 else target = Client;
563 if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
565 IRC_Send_LUSERS( target );
572 IRC_LINKS( CLIENT *Client, REQUEST *Req )
574 CLIENT *target, *from, *c;
577 assert( Client != NULL );
578 assert( Req != NULL );
580 if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
582 /* Falsche Anzahl Parameter? */
583 if(( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
585 /* Server-Mask ermitteln */
586 if( Req->argc > 0 ) mask = Req->argv[Req->argc - 1];
589 /* Absender ermitteln */
590 if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
592 if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
594 /* An anderen Server forwarden? */
597 target = Client_Search( Req->argv[0] );
598 if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[0] );
599 else if( target != Client_ThisServer( )) return IRC_WriteStrClientPrefix( target, from, "LINKS %s %s", Req->argv[0], Req->argv[1] );
602 /* Wer ist der Absender? */
603 if( Client_Type( Client ) == CLIENT_SERVER ) target = Client_Search( Req->prefix );
604 else target = Client;
605 if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
610 if( Client_Type( c ) == CLIENT_SERVER )
612 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;
614 c = Client_Next( c );
617 return IRC_WriteStrClient( target, RPL_ENDOFLINKS_MSG, Client_ID( target ), mask );
622 IRC_VERSION( CLIENT *Client, REQUEST *Req )
624 CLIENT *target, *prefix;
626 assert( Client != NULL );
627 assert( Req != NULL );
629 /* Falsche Anzahl Parameter? */
630 if(( Req->argc > 1 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
633 if( Req->argc == 1 ) target = Client_Search( Req->argv[0] );
634 else target = Client_ThisServer( );
636 /* Prefix ermitteln */
637 if( Client_Type( Client ) == CLIENT_SERVER ) prefix = Client_Search( Req->prefix );
638 else prefix = Client;
639 if( ! prefix ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->prefix );
641 /* An anderen Server weiterleiten? */
642 if( target != Client_ThisServer( ))
644 if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[0] );
647 IRC_WriteStrClientPrefix( target, prefix, "VERSION %s", Req->argv[0] );
651 /* mit Versionsinfo antworten */
652 return IRC_WriteStrClient( Client, RPL_VERSION_MSG, Client_ID( prefix ), PACKAGE, VERSION, NGIRCd_DebugLevel, Conf_ServerName, NGIRCd_VersionAddition( ));
657 IRC_KILL( CLIENT *Client, REQUEST *Req )
661 assert( Client != NULL );
662 assert( Req != NULL );
664 if( Client_Type( Client ) != CLIENT_SERVER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
666 /* Falsche Anzahl Parameter? */
667 if(( Req->argc != 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
669 prefix = Client_Search( Req->prefix );
672 Log( LOG_WARNING, "Got KILL with invalid prefix: \"%s\"!", Req->prefix );
673 prefix = Client_ThisServer( );
676 Log( LOG_NOTICE, "Got KILL command from \"%s\" for \"%s\": %s", Client_Mask( prefix ), Req->argv[0], Req->argv[1] );
678 /* andere Server benachrichtigen */
679 IRC_WriteStrServersPrefix( Client, prefix, "KILL %s :%s", Req->argv[0], Req->argv[1] );
681 /* haben wir selber einen solchen Client? */
682 c = Client_Search( Req->argv[0] );
685 /* Ja, wir haben einen solchen Client */
686 if( Client_Conn( c ) != NONE ) Conn_Close( Client_Conn( c ), NULL, Req->argv[1], TRUE );
687 else Client_Destroy( c, NULL, Req->argv[1], TRUE );
689 else Log( LOG_NOTICE, "Client with nick \"%s\" is unknown here.", Req->argv[0] );
696 IRC_ADMIN(CLIENT *Client, REQUEST *Req )
698 CLIENT *target, *prefix;
700 assert( Client != NULL );
701 assert( Req != NULL );
703 if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
705 /* Falsche Anzahl Parameter? */
706 if(( Req->argc > 1 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
709 if( Req->argc == 1 ) target = Client_Search( Req->argv[0] );
710 else target = Client_ThisServer( );
712 /* Prefix ermitteln */
713 if( Client_Type( Client ) == CLIENT_SERVER ) prefix = Client_Search( Req->prefix );
714 else prefix = Client;
715 if( ! prefix ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->prefix );
717 /* An anderen Server weiterleiten? */
718 if( target != Client_ThisServer( ))
720 if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[0] );
723 IRC_WriteStrClientPrefix( target, prefix, "ADMIN %s", Req->argv[0] );
727 /* mit Versionsinfo antworten */
728 if( ! IRC_WriteStrClient( Client, RPL_ADMINME_MSG, Client_ID( prefix ), Conf_ServerName )) return DISCONNECTED;
729 if( ! IRC_WriteStrClient( Client, RPL_ADMINLOC1_MSG, Client_ID( prefix ), Conf_ServerAdmin1 )) return DISCONNECTED;
730 if( ! IRC_WriteStrClient( Client, RPL_ADMINLOC2_MSG, Client_ID( prefix ), Conf_ServerAdmin2 )) return DISCONNECTED;
731 if( ! IRC_WriteStrClient( Client, RPL_ADMINEMAIL_MSG, Client_ID( prefix ), Conf_ServerAdminMail )) return DISCONNECTED;
739 IRC_Show_MOTD( CLIENT *Client )
745 assert( Client != NULL );
747 fd = fopen( Conf_MotdFile, "r" );
750 Log( LOG_WARNING, "Can't read MOTD file \"%s\": %s", Conf_MotdFile, strerror( errno ));
751 return IRC_WriteStrClient( Client, ERR_NOMOTD_MSG, Client_ID( Client ) );
754 IRC_WriteStrClient( Client, RPL_MOTDSTART_MSG, Client_ID( Client ), Client_ID( Client_ThisServer( )));
757 if( ! fgets( line, 126, fd )) break;
758 if( line[strlen( line ) - 1] == '\n' ) line[strlen( line ) - 1] = '\0';
759 if( ! IRC_WriteStrClient( Client, RPL_MOTD_MSG, Client_ID( Client ), line ))
765 ok = IRC_WriteStrClient( Client, RPL_ENDOFMOTD_MSG, Client_ID( Client ) );
770 } /* IRC_Show_MOTD */
774 IRC_Send_NAMES( CLIENT *Client, CHANNEL *Chan )
776 BOOLEAN is_visible, is_member;
777 CHAR str[LINE_LEN + 1];
781 assert( Client != NULL );
782 assert( Chan != NULL );
784 if( Channel_IsMemberOf( Chan, Client )) is_member = TRUE;
785 else is_member = FALSE;
787 /* Alle Mitglieder suchen */
788 sprintf( str, RPL_NAMREPLY_MSG, Client_ID( Client ), "=", Channel_Name( Chan ));
789 cl2chan = Channel_FirstMember( Chan );
792 cl = Channel_GetClient( cl2chan );
794 if( strchr( Client_Modes( cl ), 'i' )) is_visible = FALSE;
795 else is_visible = TRUE;
797 if( is_member || is_visible )
800 if( str[strlen( str ) - 1] != ':' ) strcat( str, " " );
801 if( strchr( Channel_UserModes( Chan, cl ), 'o' )) strcat( str, "@" );
802 else if( strchr( Channel_UserModes( Chan, cl ), 'v' )) strcat( str, "+" );
803 strcat( str, Client_ID( cl ));
805 if( strlen( str ) > ( LINE_LEN - CLIENT_NICK_LEN - 4 ))
807 /* Zeile wird zu lang: senden! */
808 if( ! IRC_WriteStrClient( Client, "%s", str )) return DISCONNECTED;
809 sprintf( str, RPL_NAMREPLY_MSG, Client_ID( Client ), "=", Channel_Name( Chan ));
813 /* naechstes Mitglied suchen */
814 cl2chan = Channel_NextMember( Chan, cl2chan );
816 if( str[strlen( str ) - 1] != ':')
818 /* Es sind noch Daten da, die gesendet werden muessen */
819 if( ! IRC_WriteStrClient( Client, "%s", str )) return DISCONNECTED;
823 } /* IRC_Send_NAMES */
827 IRC_Send_WHO( CLIENT *Client, CHANNEL *Chan, BOOLEAN OnlyOps )
829 BOOLEAN is_visible, is_member;
834 assert( Client != NULL );
835 assert( Chan != NULL );
837 if( Channel_IsMemberOf( Chan, Client )) is_member = TRUE;
838 else is_member = FALSE;
840 /* Alle Mitglieder suchen */
841 cl2chan = Channel_FirstMember( Chan );
844 c = Channel_GetClient( cl2chan );
846 if( strchr( Client_Modes( c ), 'i' )) is_visible = FALSE;
847 else is_visible = TRUE;
849 if( is_member || is_visible )
851 /* Flags zusammenbasteln */
852 strcpy( flags, "H" );
853 if( strchr( Client_Modes( c ), 'o' )) strcat( flags, "*" );
854 if( strchr( Channel_UserModes( Chan, c ), 'o' )) strcat( flags, "@" );
855 else if( strchr( Channel_UserModes( Chan, c ), 'v' )) strcat( flags, "+" );
858 if(( ! OnlyOps ) || ( strchr( Client_Modes( c ), 'o' )))
860 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;
864 /* naechstes Mitglied suchen */
865 cl2chan = Channel_NextMember( Chan, cl2chan );
872 IRC_Send_LUSERS( CLIENT *Client )
876 assert( Client != NULL );
878 /* Users, Services und Serevr im Netz */
879 if( ! IRC_WriteStrClient( Client, RPL_LUSERCLIENT_MSG, Client_ID( Client ), Client_UserCount( ), Client_ServiceCount( ), Client_ServerCount( ))) return DISCONNECTED;
881 /* IRC-Operatoren im Netz */
882 cnt = Client_OperCount( );
885 if( ! IRC_WriteStrClient( Client, RPL_LUSEROP_MSG, Client_ID( Client ), cnt )) return DISCONNECTED;
888 /* Unbekannt Verbindungen */
889 cnt = Client_UnknownCount( );
892 if( ! IRC_WriteStrClient( Client, RPL_LUSERUNKNOWN_MSG, Client_ID( Client ), cnt )) return DISCONNECTED;
895 /* Channels im Netz */
896 if( ! IRC_WriteStrClient( Client, RPL_LUSERCHANNELS_MSG, Client_ID( Client ), Channel_Count( ))) return DISCONNECTED;
898 /* Channels im Netz */
899 if( ! IRC_WriteStrClient( Client, RPL_LUSERME_MSG, Client_ID( Client ), Client_MyUserCount( ), Client_MyServiceCount( ), Client_MyServerCount( ))) return DISCONNECTED;
902 } /* IRC_Send_LUSERS */