Blob


1 /*
2 * ngIRCd -- The Next Generation IRC Daemon
3 * Copyright (c)2001,2002 by Alexander Barton (alex@barton.de)
4 *
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.
11 *
12 * $Id: irc.c,v 1.99 2002/10/09 16:53:02 alex Exp $
13 *
14 * irc.c: IRC-Befehle
15 */
18 #include "portab.h"
20 #include "imp.h"
21 #include <assert.h>
22 #include <errno.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
27 #include "ngircd.h"
28 #include "conn.h"
29 #include "client.h"
30 #include "channel.h"
31 #include "resolve.h"
32 #include "conf.h"
33 #include "conn.h"
34 #include "irc-write.h"
35 #include "log.h"
36 #include "messages.h"
37 #include "parse.h"
38 #include "tool.h"
40 #include "exp.h"
41 #include "irc.h"
44 GLOBAL BOOLEAN
45 IRC_MOTD( CLIENT *Client, REQUEST *Req )
46 {
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 );
56 } /* IRC_MOTD */
59 GLOBAL BOOLEAN
60 IRC_PRIVMSG( CLIENT *Client, REQUEST *Req )
61 {
62 CLIENT *cl, *from;
63 CHANNEL *chan;
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 );
76 else from = Client;
77 if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
79 cl = Client_Search( Req->argv[0] );
80 if( cl )
81 {
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' )))
87 {
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;
90 }
92 /* Text senden */
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] );
95 }
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] );
101 } /* IRC_PRIVMSG */
104 GLOBAL BOOLEAN
105 IRC_NOTICE( CLIENT *Client, REQUEST *Req )
107 CLIENT *to, *from;
109 assert( Client != NULL );
110 assert( Req != NULL );
112 if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return CONNECTED;
114 /* Falsche Anzahl Parameter? */
115 if( Req->argc != 2 ) return CONNECTED;
117 if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
118 else from = Client;
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;
128 } /* IRC_NOTICE */
131 GLOBAL BOOLEAN
132 IRC_NAMES( CLIENT *Client, REQUEST *Req )
134 CHAR rpl[COMMAND_LEN], *ptr;
135 CLIENT *target, *from, *c;
136 CHANNEL *chan;
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 );
148 else from = Client;
149 if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->prefix );
151 if( Req->argc == 2 )
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] );
164 if( Req->argc > 0 )
166 /* bestimmte Channels durchgehen */
167 ptr = strtok( Req->argv[0], "," );
168 while( ptr )
170 chan = Channel_Search( ptr );
171 if( chan )
173 /* Namen ausgeben */
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, "," );
181 return CONNECTED;
184 /* alle Channels durchgehen */
185 chan = Channel_First( );
186 while( chan )
188 /* Namen ausgeben */
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 */
196 c = Client_First( );
197 sprintf( rpl, RPL_NAMREPLY_MSG, Client_ID( from ), "*", "*" );
198 while( c )
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, "%s", 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, "%s", rpl )) return DISCONNECTED;
223 return IRC_WriteStrClient( from, RPL_ENDOFNAMES_MSG, Client_ID( from ), "*" );
224 } /* IRC_NAMES */
227 GLOBAL BOOLEAN
228 IRC_ISON( CLIENT *Client, REQUEST *Req )
230 CHAR rpl[COMMAND_LEN];
231 CLIENT *c;
232 CHAR *ptr;
233 INT i;
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], " " );
247 while( ptr )
249 ngt_TrimStr( ptr );
250 c = Client_Search( ptr );
251 if( c && ( Client_Type( c ) == CLIENT_USER ))
253 /* Dieser Nick ist "online" */
254 strcat( rpl, ptr );
255 strcat( rpl, " " );
257 ptr = strtok( NULL, " " );
260 if( rpl[strlen( rpl ) - 1] == ' ' ) rpl[strlen( rpl ) - 1] = '\0';
262 return IRC_WriteStrClient( Client, "%s", rpl, Client_ID( Client ) );
263 } /* IRC_ISON */
266 GLOBAL BOOLEAN
267 IRC_WHOIS( CLIENT *Client, REQUEST *Req )
269 CLIENT *from, *target, *c;
270 CHAR str[LINE_LEN + 1], *ptr = NULL;
271 CL2CHAN *cl2chan;
272 CHANNEL *chan;
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 );
282 /* Client suchen */
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 );
288 else from = Client;
289 if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
291 /* Forwarden an anderen Server? */
292 if( Req->argc > 1 )
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] );
297 ptr = 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;
308 /* Server */
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;
311 /* Channels */
312 sprintf( str, RPL_WHOISCHANNELS_MSG, Client_ID( from ), Client_ID( c ));
313 cl2chan = Channel_FirstChannelOf( c );
314 while( cl2chan )
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, "%s", 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, "%s", str )) return DISCONNECTED;
341 /* IRC-Operator? */
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;
353 /* Away? */
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;
359 /* End of Whois */
360 return IRC_WriteStrClient( from, RPL_ENDOFWHOIS_MSG, Client_ID( from ), Client_ID( c ));
361 } /* IRC_WHOIS */
364 GLOBAL BOOLEAN
365 IRC_WHO( CLIENT *Client, REQUEST *Req )
367 BOOLEAN ok, only_ops;
368 CHAR flags[8], *ptr;
369 CL2CHAN *cl2chan;
370 CHANNEL *chan;
371 CLIENT *c;
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 );
381 only_ops = FALSE;
382 chan = NULL;
384 if( Req->argc == 2 )
386 /* Nur OPs anzeigen? */
387 if( strcmp( Req->argv[1], "o" ) == 0 ) only_ops = TRUE;
388 #ifdef STRICT_RFC
389 else return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
390 #endif
393 if( Req->argc >= 1 )
395 /* wurde ein Channel oder Nick-Mask angegeben? */
396 chan = Channel_Search( Req->argv[0] );
399 if( chan )
401 /* User eines Channels ausgeben */
402 if( ! IRC_Send_WHO( Client, chan, only_ops )) return DISCONNECTED;
405 c = Client_First( );
406 while( c )
408 if(( Client_Type( c ) == CLIENT_USER ) && ( ! strchr( Client_Modes( c ), 'i' )))
410 ok = FALSE;
411 if( Req->argc == 0 ) ok = TRUE;
412 else
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, "*" );
424 /* ausgeben */
425 cl2chan = Channel_FirstChannelOf( c );
426 if( cl2chan ) ptr = Channel_Name( Channel_GetChannel( cl2chan ));
427 else ptr = "*";
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] );
439 } /* IRC_WHO */
442 GLOBAL BOOLEAN
443 IRC_USERHOST( CLIENT *Client, REQUEST *Req )
445 CHAR rpl[COMMAND_LEN];
446 CLIENT *c;
447 INT max, i;
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, "*" );
469 strcat( rpl, "=" );
470 if( Client_HasMode( c, 'a' )) strcat( rpl, "-" );
471 else strcat( rpl, "+" );
472 strcat( rpl, Client_User( c ));
473 strcat( rpl, "@" );
474 strcat( rpl, Client_Hostname( c ));
475 strcat( rpl, " " );
478 if( rpl[strlen( rpl ) - 1] == ' ' ) rpl[strlen( rpl ) - 1] = '\0';
480 return IRC_WriteStrClient( Client, "%s", rpl, Client_ID( Client ) );
481 } /* IRC_USERHOST */
484 GLOBAL BOOLEAN
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] );
493 return CONNECTED;
494 } /* IRC_ERROR */
497 GLOBAL BOOLEAN
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 );
512 else from = Client;
513 if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
515 /* An anderen Server forwarden? */
516 if( Req->argc == 2 )
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 );
530 return CONNECTED;
531 } /* IRC_LUSERS */
534 GLOBAL BOOLEAN
535 IRC_LINKS( CLIENT *Client, REQUEST *Req )
537 CLIENT *target, *from, *c;
538 CHAR *mask;
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];
550 else mask = "*";
552 /* Absender ermitteln */
553 if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
554 else from = Client;
555 if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
557 /* An anderen Server forwarden? */
558 if( Req->argc == 2 )
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 );
570 c = Client_First( );
571 while( c )
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 );
581 } /* IRC_LINKS */
584 GLOBAL BOOLEAN
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 );
595 /* Ziel suchen */
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] );
609 /* forwarden */
610 IRC_WriteStrClientPrefix( target, prefix, "VERSION %s", Req->argv[0] );
611 return CONNECTED;
614 /* mit Versionsinfo antworten */
615 return IRC_WriteStrClient( Client, RPL_VERSION_MSG, Client_ID( prefix ), PACKAGE, VERSION, NGIRCd_DebugLevel, Conf_ServerName, NGIRCd_VersionAddition( ));
616 } /* IRC_VERSION */
619 GLOBAL BOOLEAN
620 IRC_KILL( CLIENT *Client, REQUEST *Req )
622 CLIENT *prefix, *c;
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 );
633 if( ! 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] );
646 if( c )
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] );
654 return CONNECTED;
655 } /* IRC_KILL */
658 GLOBAL BOOLEAN
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 );
671 /* Ziel suchen */
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] );
685 /* forwarden */
686 IRC_WriteStrClientPrefix( target, prefix, "ADMIN %s", Req->argv[0] );
687 return CONNECTED;
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;
696 return CONNECTED;
697 } /* IRC_ADMIN */
701 GLOBAL BOOLEAN
702 IRC_Show_MOTD( CLIENT *Client )
704 BOOLEAN ok;
705 CHAR line[127];
706 FILE *fd;
708 assert( Client != NULL );
710 fd = fopen( Conf_MotdFile, "r" );
711 if( ! fd )
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( )));
718 while( TRUE )
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 ))
724 fclose( fd );
725 return FALSE;
728 ok = IRC_WriteStrClient( Client, RPL_ENDOFMOTD_MSG, Client_ID( Client ) );
730 fclose( fd );
732 return ok;
733 } /* IRC_Show_MOTD */
736 GLOBAL BOOLEAN
737 IRC_Send_NAMES( CLIENT *Client, CHANNEL *Chan )
739 BOOLEAN is_visible, is_member;
740 CHAR str[LINE_LEN + 1];
741 CL2CHAN *cl2chan;
742 CLIENT *cl;
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 );
753 while( cl2chan )
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 )
762 /* Nick anhaengen */
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, "%s", 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, "%s", str )) return DISCONNECTED;
785 return CONNECTED;
786 } /* IRC_Send_NAMES */
789 GLOBAL BOOLEAN
790 IRC_Send_WHO( CLIENT *Client, CHANNEL *Chan, BOOLEAN OnlyOps )
792 BOOLEAN is_visible, is_member;
793 CL2CHAN *cl2chan;
794 CHAR flags[8];
795 CLIENT *c;
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 );
805 while( cl2chan )
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, "+" );
820 /* ausgeben */
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 );
830 return CONNECTED;
831 } /* IRC_Send_WHO */
834 GLOBAL BOOLEAN
835 IRC_Send_LUSERS( CLIENT *Client )
837 LONG cnt;
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( );
846 if( cnt > 0 )
848 if( ! IRC_WriteStrClient( Client, RPL_LUSEROP_MSG, Client_ID( Client ), cnt )) return DISCONNECTED;
851 /* Unbekannt Verbindungen */
852 cnt = Client_UnknownCount( );
853 if( cnt > 0 )
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;
864 return CONNECTED;
865 } /* IRC_Send_LUSERS */
868 /* -eof- */