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.37 2002/01/16 22:10:18 alex Exp $
17 * Revision 1.37 2002/01/16 22:10:18 alex
18 * - IRC_LUSERS() implementiert.
20 * Revision 1.36 2002/01/11 23:50:55 alex
21 * - LINKS implementiert, LUSERS begonnen.
23 * Revision 1.35 2002/01/09 21:30:45 alex
24 * - WHOIS wurde faelschlicherweise an User geforwarded statt vom Server beantwortet.
26 * Revision 1.34 2002/01/09 01:09:58 alex
27 * - WHOIS wird im "Strict-RFC-Mode" nicht mehr automatisch geforwarded,
28 * - andere Server werden nun ueber bisherige Server und User informiert.
30 * Revision 1.33 2002/01/07 23:42:12 alex
31 * - Es werden fuer alle Server eigene Token generiert,
32 * - QUIT von einem Server fuer einen User wird an andere Server geforwarded,
33 * - ebenso NICK-Befehle, die "fremde" User einfuehren.
35 * Revision 1.32 2002/01/07 16:02:36 alex
36 * - Loglevel von Remote-Mode-Aenderungen angepasst (nun Debug).
37 * - Im Debug-Mode werden nun auch PING's protokolliert.
39 * Revision 1.31 2002/01/07 15:39:46 alex
40 * - Server nimmt nun Server-Links an: PASS und SERVER entsprechend angepasst.
41 * - MODE und NICK melden nun die Aenderungen an andere Server.
43 * Revision 1.30 2002/01/06 15:21:29 alex
44 * - Loglevel und Meldungen nochmals ueberarbeitet.
45 * - QUIT und SQUIT forwarden nun den Grund der Trennung,
46 * - WHOIS wird nun immer an den "Original-Server" weitergeleitet.
48 * Revision 1.29 2002/01/05 23:24:54 alex
49 * - WHOIS erweitert: Anfragen koennen an andere Server weitergeleitet werden.
50 * - Vorbereitungen fuer Ident-Abfragen bei neuen Client-Strukturen.
52 * Revision 1.28 2002/01/05 20:08:02 alex
53 * - Div. Aenderungen fuer die Server-Links (u.a. WHOIS, QUIT, NICK angepasst).
54 * - Neue Funktionen IRC_WriteStrServer() und IRC_WriteStrServerPrefix().
56 * Revision 1.27 2002/01/05 19:15:03 alex
57 * - Fehlerpruefung bei select() in der "Hauptschleife" korrigiert.
59 * Revision 1.26 2002/01/05 16:51:18 alex
60 * - das Passwort von Servern wird nun ueberprueft (PASS- und SERVER-Befehl).
62 * Revision 1.25 2002/01/05 00:48:33 alex
63 * - bei SQUIT wurde immer die Verbindung getrennt, auch bei Remote-Servern.
65 * Revision 1.24 2002/01/04 17:58:44 alex
66 * - IRC_WriteStrXXX()-Funktionen eingefuehrt, groessere Anpassungen daran.
67 * - neuer Befehl SQUIT, QUIT an Server-Links angepasst.
69 * Revision 1.23 2002/01/04 01:36:40 alex
70 * - Loglevel ein wenig angepasst.
72 * Revision 1.22 2002/01/04 01:21:47 alex
73 * - Client-Strukruren werden nur noch ueber Funktionen angesprochen.
74 * - Weitere Anpassungen und Erweiterungen der Server-Links.
76 * Revision 1.21 2002/01/03 02:26:51 alex
77 * - neue Befehle SERVER und NJOIN begonnen,
78 * - begonnen, diverse IRC-Befehle an Server-Links anzupassen.
80 * Revision 1.20 2002/01/02 12:46:41 alex
81 * - die Gross- und Kleinschreibung des Nicks kann mit NICK nun geaendert werden.
83 * Revision 1.19 2002/01/02 02:51:39 alex
84 * - Copyright-Texte angepasst.
85 * - neuer Befehl "ERROR".
87 * Revision 1.17 2001/12/31 15:33:13 alex
88 * - neuer Befehl NAMES, kleinere Bugfixes.
89 * - Bug bei PING behoben: war zu restriktiv implementiert :-)
91 * Revision 1.16 2001/12/31 02:18:51 alex
92 * - viele neue Befehle (WHOIS, ISON, OPER, DIE, RESTART),
93 * - neuen Header "defines.h" mit (fast) allen Konstanten.
94 * - Code Cleanups und viele "kleine" Aenderungen & Bugfixes.
96 * Revision 1.15 2001/12/30 19:26:11 alex
97 * - Unterstuetzung fuer die Konfigurationsdatei eingebaut.
99 * Revision 1.14 2001/12/30 11:42:00 alex
100 * - der Server meldet nun eine ordentliche "Start-Zeit".
102 * Revision 1.13 2001/12/29 03:10:06 alex
103 * - Neue Funktion IRC_MODE() implementiert, div. Aenderungen.
104 * - neue configure-Optione "--enable-strict-rfc".
106 * Revision 1.12 2001/12/27 19:17:26 alex
107 * - neue Befehle PRIVMSG, NOTICE, PING.
109 * Revision 1.11 2001/12/27 16:55:41 alex
110 * - neu: IRC_WriteStrRelated(), Aenderungen auch in IRC_WriteStrClient().
112 * Revision 1.10 2001/12/26 22:48:53 alex
113 * - MOTD-Datei ist nun konfigurierbar und wird gelesen.
115 * Revision 1.9 2001/12/26 14:45:37 alex
118 * Revision 1.8 2001/12/26 03:21:46 alex
119 * - PING/PONG-Befehle implementiert,
120 * - Meldungen ueberarbeitet: enthalten nun (fast) immer den Nick.
122 * Revision 1.7 2001/12/25 23:25:18 alex
123 * - und nochmal Aenderungen am Logging ;-)
125 * Revision 1.6 2001/12/25 23:13:33 alex
126 * - Debug-Meldungen angepasst.
128 * Revision 1.5 2001/12/25 22:02:42 alex
129 * - neuer IRC-Befehl "/QUIT". Verbessertes Logging & Debug-Ausgaben.
131 * Revision 1.4 2001/12/25 19:19:30 alex
132 * - bessere Fehler-Abfragen, diverse Bugfixes.
133 * - Nicks werden nur einmal vergeben :-)
134 * - /MOTD wird unterstuetzt.
136 * Revision 1.3 2001/12/24 01:34:06 alex
137 * - USER und NICK wird nun in beliebiger Reihenfolge akzeptiert (wg. BitchX)
138 * - MOTD-Ausgabe begonnen zu implementieren.
140 * Revision 1.2 2001/12/23 21:57:16 alex
141 * - erste IRC-Befehle zu implementieren begonnen.
143 * Revision 1.1 2001/12/14 08:13:43 alex
144 * - neues Modul begonnen :-)
164 #include "messages.h"
172 #define CONNECTED TRUE
173 #define DISCONNECTED FALSE
176 LOCAL BOOLEAN Hello_User( CLIENT *Client );
177 LOCAL BOOLEAN Show_MOTD( CLIENT *Client );
179 LOCAL VOID Kill_Nick( CHAR *Nick );
182 GLOBAL VOID IRC_Init( VOID )
187 GLOBAL VOID IRC_Exit( VOID )
192 GLOBAL BOOLEAN IRC_WriteStrClient( CLIENT *Client, CHAR *Format, ... )
195 BOOLEAN ok = CONNECTED;
198 assert( Client != NULL );
199 assert( Format != NULL );
201 va_start( ap, Format );
202 vsnprintf( buffer, 1000, Format, ap );
205 /* an den Client selber */
206 ok = IRC_WriteStrClientPrefix( Client, Client_ThisServer( ), buffer );
209 } /* IRC_WriteStrClient */
212 GLOBAL BOOLEAN IRC_WriteStrClientPrefix( CLIENT *Client, CLIENT *Prefix, CHAR *Format, ... )
214 /* Text an Clients, lokal bzw. remote, senden. */
219 assert( Client != NULL );
220 assert( Format != NULL );
221 assert( Prefix != NULL );
223 va_start( ap, Format );
224 vsnprintf( buffer, 1000, Format, ap );
227 return Conn_WriteStr( Client_Conn( Client_NextHop( Client )), ":%s %s", Client_ID( Prefix ), buffer );
228 } /* IRC_WriteStrClientPrefix */
231 GLOBAL BOOLEAN IRC_WriteStrRelated( CLIENT *Client, CHAR *Format, ... )
234 BOOLEAN ok = CONNECTED;
237 assert( Client != NULL );
238 assert( Format != NULL );
240 va_start( ap, Format );
241 vsnprintf( buffer, 1000, Format, ap );
244 /* an den Client selber */
245 ok = IRC_WriteStrClient( Client, buffer );
250 } /* IRC_WriteStrRelated */
253 GLOBAL VOID IRC_WriteStrServers( CLIENT *ExceptOf, CHAR *Format, ... )
258 assert( Format != NULL );
260 va_start( ap, Format );
261 vsnprintf( buffer, 1000, Format, ap );
264 /* an den Client selber */
265 return IRC_WriteStrServersPrefix( ExceptOf, Client_ThisServer( ), buffer );
266 } /* IRC_WriteStrServers */
269 GLOBAL VOID IRC_WriteStrServersPrefix( CLIENT *ExceptOf, CLIENT *Prefix, CHAR *Format, ... )
275 assert( Format != NULL );
276 assert( Prefix != NULL );
278 va_start( ap, Format );
279 vsnprintf( buffer, 1000, Format, ap );
285 if(( Client_Type( c ) == CLIENT_SERVER ) && ( Client_Conn( c ) > NONE ) && ( c != Client_ThisServer( )) && ( c != ExceptOf ))
287 /* Ziel-Server gefunden */
288 IRC_WriteStrClientPrefix( c, Prefix, buffer );
290 c = Client_Next( c );
292 } /* IRC_WriteStrServersPrefix */
295 GLOBAL BOOLEAN IRC_PASS( CLIENT *Client, REQUEST *Req )
297 assert( Client != NULL );
298 assert( Req != NULL );
300 /* Fehler liefern, wenn kein lokaler Client */
301 if( Client_Conn( Client ) <= NONE ) return IRC_WriteStrClient( Client, ERR_UNKNOWNCOMMAND_MSG, Client_ID( Client ), Req->command );
303 if(( Client_Type( Client ) == CLIENT_UNKNOWN ) && ( Req->argc == 1))
305 /* noch nicht registrierte unbekannte Verbindung */
306 Log( LOG_DEBUG, "Connection %d: got PASS command ...", Client_Conn( Client ));
308 /* Passwort speichern */
309 Client_SetPassword( Client, Req->argv[0] );
311 Client_SetType( Client, CLIENT_GOTPASS );
314 else if((( Client_Type( Client ) == CLIENT_UNKNOWN ) || ( Client_Type( Client ) == CLIENT_UNKNOWNSERVER )) && (( Req->argc == 3 ) || ( Req->argc == 4 )))
316 /* noch nicht registrierte Server-Verbindung */
317 Log( LOG_DEBUG, "Connection %d: got PASS command (new server link) ...", Client_Conn( Client ));
319 /* Passwort speichern */
320 Client_SetPassword( Client, Req->argv[0] );
322 Client_SetType( Client, CLIENT_GOTPASSSERVER );
325 else if(( Client_Type( Client ) == CLIENT_UNKNOWN ) || ( Client_Type( Client ) == CLIENT_UNKNOWNSERVER ))
327 /* Falsche Anzahl Parameter? */
328 return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
330 else return IRC_WriteStrClient( Client, ERR_ALREADYREGISTRED_MSG, Client_ID( Client ));
334 GLOBAL BOOLEAN IRC_SERVER( CLIENT *Client, REQUEST *Req )
336 CHAR str[LINE_LEN], *ptr;
341 assert( Client != NULL );
342 assert( Req != NULL );
344 /* Fehler liefern, wenn kein lokaler Client */
345 if( Client_Conn( Client ) <= NONE ) return IRC_WriteStrClient( Client, ERR_UNKNOWNCOMMAND_MSG, Client_ID( Client ), Req->command );
347 if( Client_Type( Client ) == CLIENT_GOTPASSSERVER )
349 /* Verbindung soll als Server-Server-Verbindung registriert werden */
350 Log( LOG_DEBUG, "Connection %d: got SERVER command (new server link) ...", Client_Conn( Client ));
352 /* Falsche Anzahl Parameter? */
353 if(( Req->argc != 2 ) && ( Req->argc != 3 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
355 /* Ist dieser Server bei uns konfiguriert? */
356 for( i = 0; i < Conf_Server_Count; i++ ) if( strcasecmp( Req->argv[0], Conf_Server[i].name ) == 0 ) break;
357 if( i >= Conf_Server_Count )
359 /* Server ist nicht konfiguriert! */
360 Log( LOG_ERR, "Connection %d: Server \"%s\" not configured here!", Client_Conn( Client ), Req->argv[0] );
361 Conn_Close( Client_Conn( Client ), NULL, "Server not configured here", TRUE );
364 if( strcmp( Client_Password( Client ), Conf_Server[i].pwd ) != 0 )
366 /* Falsches Passwort */
367 Log( LOG_ERR, "Connection %d: Bad password for server \"%s\"!", Client_Conn( Client ), Req->argv[0] );
368 Conn_Close( Client_Conn( Client ), NULL, "Bad password", TRUE );
372 /* Ist ein Server mit dieser ID bereits registriert? */
373 if( ! Client_CheckID( Client, Req->argv[0] )) return DISCONNECTED;
375 /* Server-Strukturen fuellen ;-) */
376 Client_SetID( Client, Req->argv[0] );
377 Client_SetHops( Client, 1 );
378 Client_SetInfo( Client, Req->argv[Req->argc - 1] );
380 /* Meldet sich der Server bei uns an? */
383 /* Unseren SERVER- und PASS-Befehl senden */
385 if( ! IRC_WriteStrClient( Client, "PASS %s "PASSSERVERADD, Conf_Server[i].pwd )) ok = FALSE;
386 else ok = IRC_WriteStrClient( Client, "SERVER %s 1 :%s", Conf_ServerName, Conf_ServerInfo );
389 Conn_Close( Client_Conn( Client ), "Unexpected server behavior!", NULL, FALSE );
392 Client_SetIntroducer( Client, Client );
393 Client_SetToken( Client, 1 );
395 else Client_SetToken( Client, atoi( Req->argv[1] ));
397 Log( LOG_NOTICE, "Server \"%s\" registered (connection %d, 1 hop - direct link).", Client_ID( Client ), Client_Conn( Client ));
399 Client_SetType( Client, CLIENT_SERVER );
401 /* Alle bisherigen Server dem neuen Server bekannt machen,
402 * die bisherigen Server ueber den neuen informierenn */
406 if(( Client_Type( c ) == CLIENT_SERVER ) && ( c != Client ) && ( c != Client_ThisServer( )))
408 if( Client_Conn( c ) > NONE )
410 /* Dem gefundenen Server gleich den neuen
411 * Server bekannt machen */
412 if( ! IRC_WriteStrClient( c, "SERVER %s %d %d :%s", Client_ID( Client ), Client_Hops( Client ) + 1, Client_MyToken( Client ), Client_Info( Client ))) return DISCONNECTED;
415 /* Den neuen Server ueber den alten informieren */
416 if( ! IRC_WriteStrClientPrefix( Client, Client_Introducer( c ), "SERVER %s %d %d :%s", Client_ID( c ), Client_Hops( c ) + 1, Client_MyToken( c ), Client_Info( c ))) return DISCONNECTED;
418 c = Client_Next( c );
421 /* alle User dem neuen Server bekannt machen */
425 if( Client_Type( c ) == CLIENT_USER )
427 /* User an neuen Server melden */
428 if( ! IRC_WriteStrClient( Client, "NICK %s %d %s %s %d +%s :%s", Client_ID( c ), Client_Hops( c ) + 1, Client_User( c ), Client_Hostname( c ), Client_MyToken( Client_Introducer( c )), Client_Modes( c ), Client_Info( c ))) return DISCONNECTED;
430 c = Client_Next( c );
435 else if( Client_Type( Client ) == CLIENT_SERVER )
437 /* Neuer Server wird im Netz angekuendigt */
439 /* Falsche Anzahl Parameter? */
440 if( Req->argc != 4 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
442 /* Ist ein Server mit dieser ID bereits registriert? */
443 if( ! Client_CheckID( Client, Req->argv[0] )) return DISCONNECTED;
445 /* Ueberfluessige Hostnamen aus Info-Text entfernen */
446 ptr = strchr( Req->argv[3] + 2, '[' );
447 if( ! ptr ) ptr = Req->argv[3];
449 /* Neue Client-Struktur anlegen */
450 c = Client_NewRemoteServer( Client, Req->argv[0], atoi( Req->argv[1] ), atoi( Req->argv[2] ), ptr, TRUE );
453 /* Neue Client-Struktur konnte nicht angelegt werden */
454 Log( LOG_ALERT, "Can't create client structure for server! (on connection %d)", Client_Conn( Client ));
455 Conn_Close( Client_Conn( Client ), NULL, "Can't allocate client structure for remote server", TRUE );
459 /* Log-Meldung zusammenbauen und ausgeben */
460 if(( Client_Hops( c ) > 1 ) && ( Req->prefix[0] )) sprintf( str, "connected to %s, ", Req->prefix );
461 else strcpy( str, "" );
462 Log( LOG_NOTICE, "Server \"%s\" registered (via %s, %s%d hop%s).", Client_ID( c ), Client_ID( Client ), str, Client_Hops( c ), Client_Hops( c ) > 1 ? "s": "" );
466 else return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
470 GLOBAL BOOLEAN IRC_NJOIN( CLIENT *Client, REQUEST *Req )
472 assert( Client != NULL );
473 assert( Req != NULL );
475 if( Client_Type( Client ) != CLIENT_SERVER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTEREDSERVER_MSG, Client_ID( Client ));
481 GLOBAL BOOLEAN IRC_NICK( CLIENT *Client, REQUEST *Req )
483 CLIENT *intr_c, *target, *c;
485 assert( Client != NULL );
486 assert( Req != NULL );
488 /* Zumindest BitchX sendet NICK-USER in der falschen Reihenfolge. */
490 if( Client_Type( Client ) == CLIENT_UNKNOWN || Client_Type( Client ) == CLIENT_GOTPASS || Client_Type( Client ) == CLIENT_GOTNICK || Client_Type( Client ) == CLIENT_GOTUSER || Client_Type( Client ) == CLIENT_USER || ( Client_Type( Client ) == CLIENT_SERVER && Req->argc == 1 ))
492 if( Client_Type( Client ) == CLIENT_UNKNOWN || Client_Type( Client ) == CLIENT_GOTPASS || Client_Type( Client ) == CLIENT_GOTNICK || Client_Type( Client ) == CLIENT_USER || ( Client_Type( Client ) == CLIENT_SERVER && Req->argc == 1 ))
495 /* User-Registrierung bzw. Nick-Aenderung */
497 /* Falsche Anzahl Parameter? */
498 if( Req->argc != 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
500 /* "Ziel-Client" ermitteln */
501 if( Client_Type( Client ) == CLIENT_SERVER )
503 target = Client_GetFromID( Req->prefix );
504 if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->argv[0] );
508 /* Ist der Client "restricted"? */
509 if( Client_HasMode( Client, 'r' )) return IRC_WriteStrClient( Client, ERR_RESTRICTED_MSG, Client_ID( Client ));
513 /* Wenn der Client zu seinem eigenen Nick wechseln will, so machen
514 * wir nichts. So macht es das Original und mind. Snak hat probleme,
515 * wenn wir es nicht so machen. Ob es so okay ist? Hm ... */
517 if( strcmp( Client_ID( target ), Req->argv[0] ) == 0 ) return CONNECTED;
520 /* pruefen, ob Nick bereits vergeben. Speziallfall: der Client
521 * will nur die Gross- und Kleinschreibung aendern. Das darf
522 * er natuerlich machen :-) */
523 if( strcasecmp( Client_ID( target ), Req->argv[0] ) != 0 )
525 if( ! Client_CheckNick( target, Req->argv[0] )) return CONNECTED;
528 if( Client_Type( Client ) == CLIENT_USER )
530 /* Nick-Aenderung: allen mitteilen! */
531 Log( LOG_INFO, "User \"%s\" changed nick: \"%s\" -> \"%s\".", Client_Mask( target ), Client_ID( target ), Req->argv[0] );
532 IRC_WriteStrRelated( Client, "NICK :%s", Req->argv[0] );
533 IRC_WriteStrServersPrefix( NULL, Client, "NICK :%s", Req->argv[0] );
535 else if( Client_Type( Client ) == CLIENT_SERVER )
537 /* Nick-Aenderung: allen mitteilen! */
538 Log( LOG_DEBUG, "User \"%s\" changed nick: \"%s\" -> \"%s\".", Client_Mask( target ), Client_ID( target ), Req->argv[0] );
539 IRC_WriteStrServersPrefix( Client, Client, "NICK :%s", Req->argv[0] );
542 /* Client-Nick registrieren */
543 Client_SetID( target, Req->argv[0] );
545 if(( Client_Type( target ) != CLIENT_USER ) && ( Client_Type( target ) != CLIENT_SERVER ))
548 Log( LOG_DEBUG, "Connection %d: got NICK command ...", Client_Conn( Client ));
549 if( Client_Type( Client ) == CLIENT_GOTUSER ) return Hello_User( Client );
550 else Client_SetType( Client, CLIENT_GOTNICK );
554 else if( Client_Type( Client ) == CLIENT_SERVER )
556 /* Server fuehrt neuen Client ein */
558 /* Falsche Anzahl Parameter? */
559 if( Req->argc != 7 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
561 /* Nick ueberpruefen */
562 c = Client_GetFromID( Req->argv[0] );
565 /* Der neue Nick ist auf diesem Server bereits registriert:
566 * sowohl der neue, als auch der alte Client muessen nun
567 * disconnectiert werden. */
568 Log( LOG_ERR, "Server %s introduces already registered nick \"%s\"!", Client_ID( Client ), Req->argv[0] );
569 Kill_Nick( Req->argv[0] );
573 /* Server, zu dem der Client connectiert ist, suchen */
574 intr_c = Client_GetFromToken( Client, atoi( Req->argv[4] ));
577 Log( LOG_ERR, "Server %s introduces nick \"%s\" on unknown server!?", Client_ID( Client ), Req->argv[0] );
578 Kill_Nick( Req->argv[0] );
582 /* Neue Client-Struktur anlegen */
583 c = Client_NewRemoteUser( intr_c, Req->argv[0], atoi( Req->argv[1] ), Req->argv[2], Req->argv[3], atoi( Req->argv[4] ), Req->argv[5], Req->argv[6], TRUE );
586 /* Eine neue Client-Struktur konnte nicht angelegt werden.
587 * Der Client muss disconnectiert werden, damit der Netz-
588 * status konsistent bleibt. */
589 Log( LOG_ALERT, "Can't create client structure! (on connection %d)", Client_Conn( Client ));
590 Kill_Nick( Req->argv[0] );
594 Log( LOG_DEBUG, "User \"%s\" registered (via %s, on %s, %d hop%s).", Client_Mask( c ), Client_ID( Client ), Client_ID( intr_c ), Client_Hops( c ), Client_Hops( c ) > 1 ? "s": "" );
596 /* Andere Server, ausser dem Introducer, informieren */
597 IRC_WriteStrServersPrefix( Client, Client, "NICK %s %d %s %s %d %s :%s", Req->argv[0], atoi( Req->argv[1] ) + 1, Req->argv[2], Req->argv[3], Client_MyToken( intr_c ), Req->argv[5], Req->argv[6] );
601 else return IRC_WriteStrClient( Client, ERR_ALREADYREGISTRED_MSG, Client_ID( Client ));
605 GLOBAL BOOLEAN IRC_USER( CLIENT *Client, REQUEST *Req )
607 assert( Client != NULL );
608 assert( Req != NULL );
611 if( Client_Type( Client ) == CLIENT_GOTNICK || Client_Type( Client ) == CLIENT_GOTPASS || Client_Type( Client ) == CLIENT_UNKNOWN )
613 if( Client_Type( Client ) == CLIENT_GOTNICK || Client_Type( Client ) == CLIENT_GOTPASS )
616 /* Falsche Anzahl Parameter? */
617 if( Req->argc != 4 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
619 Client_SetUser( Client, Req->argv[0], FALSE );
620 Client_SetInfo( Client, Req->argv[3] );
622 Log( LOG_DEBUG, "Connection %d: got USER command ...", Client_Conn( Client ));
623 if( Client_Type( Client ) == CLIENT_GOTNICK ) return Hello_User( Client );
624 else Client_SetType( Client, CLIENT_GOTUSER );
627 else if( Client_Type( Client ) == CLIENT_USER || Client_Type( Client ) == CLIENT_SERVER || Client_Type( Client ) == CLIENT_SERVICE )
629 return IRC_WriteStrClient( Client, ERR_ALREADYREGISTRED_MSG, Client_ID( Client ));
631 else return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
635 GLOBAL BOOLEAN IRC_QUIT( CLIENT *Client, REQUEST *Req )
639 assert( Client != NULL );
640 assert( Req != NULL );
642 if(( Client_Type( Client ) == CLIENT_USER ) || ( Client_Type( Client ) == CLIENT_SERVICE ))
646 /* Falsche Anzahl Parameter? */
647 if( Req->argc > 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
649 if( Req->argc == 0 ) Conn_Close( Client_Conn( Client ), "Got QUIT command.", NULL, TRUE );
650 else Conn_Close( Client_Conn( Client ), "Got QUIT command.", Req->argv[0], TRUE );
654 else if ( Client_Type( Client ) == CLIENT_SERVER )
658 /* Falsche Anzahl Parameter? */
659 if( Req->argc > 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
661 target = Client_Search( Req->prefix );
664 Log( LOG_ERR, "Got QUIT from %s for unknown client!?", Client_ID( Client ));
668 if( Req->argc == 0 ) Client_Destroy( target, "Got QUIT command.", NULL );
669 else Client_Destroy( target, "Got QUIT command.", Req->argv[0] );
673 else return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
677 GLOBAL BOOLEAN IRC_SQUIT( CLIENT *Client, REQUEST *Req )
681 assert( Client != NULL );
682 assert( Req != NULL );
684 /* SQUIT ist nur fuer Server erlaubt */
685 if( Client_Type( Client ) != CLIENT_SERVER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
687 /* Falsche Anzahl Parameter? */
688 if( Req->argc != 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
690 target = Client_GetFromID( Req->argv[0] );
693 Log( LOG_ERR, "Got SQUIT from %s for unknown server \%s\"!?", Client_ID( Client ), Req->argv[0] );
697 if( target == Client ) Log( LOG_DEBUG, "Got SQUIT from %s: %s", Client_ID( Client ), Req->argv[1] );
698 else Log( LOG_DEBUG, "Got SQUIT from %s for %s: %s", Client_ID( Client ), Client_ID( target ), Req->argv[1] );
700 /* SQUIT an alle Server weiterleiten */
701 IRC_WriteStrServers( Client, "SQUIT %s :%s", Req->argv[0], Req->argv[1] );
703 if( Client_Conn( target ) > NONE )
705 if( Req->argv[1][0] ) Conn_Close( Client_Conn( target ), "Got SQUIT command.", Req->argv[1], TRUE );
706 else Conn_Close( Client_Conn( target ), "Got SQUIT command.", NULL, TRUE );
711 Client_Destroy( target, "Got SQUIT command.", Req->argv[1] );
717 GLOBAL BOOLEAN IRC_PING( CLIENT *Client, REQUEST *Req )
719 assert( Client != NULL );
720 assert( Req != NULL );
722 if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
724 /* Falsche Anzahl Parameter? */
725 if( Req->argc < 1 ) return IRC_WriteStrClient( Client, ERR_NOORIGIN_MSG, Client_ID( Client ));
726 if( Req->argc > 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
728 Log( LOG_DEBUG, "Connection %d: got PING, sending PONG ...", Client_Conn( Client ));
729 return IRC_WriteStrClient( Client, "PONG %s :%s", Client_ID( Client_ThisServer( )), Client_ID( Client ));
733 GLOBAL BOOLEAN IRC_PONG( CLIENT *Client, REQUEST *Req )
735 assert( Client != NULL );
736 assert( Req != NULL );
738 if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
740 /* Falsche Anzahl Parameter? */
741 if( Req->argc < 1 ) return IRC_WriteStrClient( Client, ERR_NOORIGIN_MSG, Client_ID( Client ));
742 if( Req->argc > 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
744 /* Der Connection-Timestamp wurde schon beim Lesen aus dem Socket
745 * aktualisiert, daher muss das hier nicht mehr gemacht werden. */
747 Log( LOG_DEBUG, "Connection %d: received PONG.", Client_Conn( Client ));
752 GLOBAL BOOLEAN IRC_MOTD( CLIENT *Client, REQUEST *Req )
754 assert( Client != NULL );
755 assert( Req != NULL );
757 if( Client_Type( Client ) != CLIENT_USER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
759 /* Falsche Anzahl Parameter? */
760 if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
762 return Show_MOTD( Client );
766 GLOBAL BOOLEAN IRC_PRIVMSG( CLIENT *Client, REQUEST *Req )
770 assert( Client != NULL );
771 assert( Req != NULL );
773 if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
775 /* Falsche Anzahl Parameter? */
776 if( Req->argc == 0 ) return IRC_WriteStrClient( Client, ERR_NORECIPIENT_MSG, Client_ID( Client ), Req->command );
777 if( Req->argc == 1 ) return IRC_WriteStrClient( Client, ERR_NOTEXTTOSEND_MSG, Client_ID( Client ));
778 if( Req->argc > 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
780 if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_GetFromID( Req->prefix );
782 if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
784 to = Client_Search( Req->argv[0] );
787 /* Okay, Ziel ist ein User */
788 if( Client_Conn( from ) >= 0 ) Conn_UpdateIdle( Client_Conn( from ));
789 return IRC_WriteStrClientPrefix( to, from, "PRIVMSG %s :%s", Client_ID( to ), Req->argv[1] );
791 else return IRC_WriteStrClient( from, ERR_NOSUCHNICK_MSG, Client_ID( from ), Req->argv[0] );
795 GLOBAL BOOLEAN IRC_NOTICE( CLIENT *Client, REQUEST *Req )
799 assert( Client != NULL );
800 assert( Req != NULL );
802 if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
804 /* Falsche Anzahl Parameter? */
805 if( Req->argc != 2 ) return CONNECTED;
807 if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_GetFromID( Req->prefix );
809 if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
811 to = Client_Search( Req->argv[0] );
814 /* Okay, Ziel ist ein User */
815 return IRC_WriteStrClientPrefix( to, from, "NOTICE %s :%s", Client_ID( to ), Req->argv[1] );
817 else return CONNECTED;
821 GLOBAL BOOLEAN IRC_MODE( CLIENT *Client, REQUEST *Req )
823 CHAR x[2], new_modes[CLIENT_MODE_LEN], *ptr;
827 assert( Client != NULL );
828 assert( Req != NULL );
830 if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
832 /* Falsche Anzahl Parameter? */
833 if(( Req->argc > 2 ) || ( Req->argc < 1 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
835 /* "Ziel-Client" suchen */
836 target = Client_Search( Req->argv[0] );
838 /* Wer ist der Anfragende? */
839 if( Client_Type( Client ) == CLIENT_USER )
841 /* User: MODE ist nur fuer sich selber zulaessig */
842 if( target != Client ) return IRC_WriteStrClient( Client, ERR_USERSDONTMATCH_MSG, Client_ID( Client ));
846 /* Server: gibt es den Client ueberhaupt? */
847 if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->argv[0] );
850 /* Werden die Modes erfragt? */
851 if( Req->argc == 1 ) return IRC_WriteStrClient( Client, RPL_UMODEIS_MSG, Client_ID( Client ), Client_Modes( Client ));
855 /* Sollen Modes gesetzt oder geloescht werden? */
856 if( *ptr == '+' ) set = TRUE;
857 else if( *ptr == '-' ) set = FALSE;
858 else return IRC_WriteStrClient( Client, ERR_UMODEUNKNOWNFLAG_MSG, Client_ID( Client ));
860 /* Reply-String mit Aenderungen vorbereiten */
861 if( set ) strcpy( new_modes, "+" );
862 else strcpy( new_modes, "-" );
870 if( Client_Type( Client ) == CLIENT_SERVER )
884 /* restricted (kann nur gesetzt werden) */
885 if( set ) x[0] = 'r';
886 else ok = IRC_WriteStrClient( target, ERR_RESTRICTED_MSG, Client_ID( target ));
889 /* operator (kann nur geloescht werden) */
892 Client_SetOperByMe( target, FALSE );
895 else ok = IRC_WriteStrClient( target, ERR_UMODEUNKNOWNFLAG_MSG, Client_ID( target ));
898 ok = IRC_WriteStrClient( target, ERR_UMODEUNKNOWNFLAG_MSG, Client_ID( target ));
905 if( ! x[0] ) continue;
907 /* Okay, gueltigen Mode gefunden */
910 /* Mode setzen. Wenn der Client ihn noch nicht hatte: merken */
911 if( Client_ModeAdd( target, x[0] )) strcat( new_modes, x );
915 /* Modes geloescht. Wenn der Client ihn hatte: merken */
916 if( Client_ModeDel( target, x[0] )) strcat( new_modes, x );
920 /* Geanderte Modes? */
923 if( Client_Type( Client ) == CLIENT_SERVER )
925 /* Modes an andere Server forwarden */
926 IRC_WriteStrServersPrefix( Client, Client, "MODE %s :%s", Client_ID( target ), new_modes );
930 /* Bestaetigung an Client schicken & andere Server informieren */
931 ok = IRC_WriteStrRelated( Client, "MODE %s :%s", Client_ID( target ), new_modes );
932 IRC_WriteStrServers( Client, "MODE %s :%s", Client_ID( target ), new_modes );
934 Log( LOG_DEBUG, "User \"%s\": Mode change, now \"%s\".", Client_Mask( target ), Client_Modes( target ));
940 GLOBAL BOOLEAN IRC_OPER( CLIENT *Client, REQUEST *Req )
944 assert( Client != NULL );
945 assert( Req != NULL );
947 if( Client_Type( Client ) != CLIENT_USER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
949 /* Falsche Anzahl Parameter? */
950 if( Req->argc != 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
952 /* Operator suchen */
953 for( i = 0; i < Conf_Oper_Count; i++)
955 if( Conf_Oper[i].name[0] && Conf_Oper[i].pwd[0] && ( strcmp( Conf_Oper[i].name, Req->argv[0] ) == 0 )) break;
957 if( i >= Conf_Oper_Count )
959 Log( LOG_WARNING, "Got invalid OPER from \"%s\": Name \"%s\" not configured!", Client_Mask( Client ), Req->argv[0] );
960 return IRC_WriteStrClient( Client, ERR_PASSWDMISMATCH_MSG, Client_ID( Client ));
963 /* Stimmt das Passwort? */
964 if( strcmp( Conf_Oper[i].pwd, Req->argv[1] ) != 0 )
966 Log( LOG_WARNING, "Got invalid OPER from \"%s\": Bad password for \"%s\"!", Client_Mask( Client ), Conf_Oper[i].name );
967 return IRC_WriteStrClient( Client, ERR_PASSWDMISMATCH_MSG, Client_ID( Client ));
970 if( ! Client_HasMode( Client, 'o' ))
972 /* noch kein o-Mode gesetzt */
973 Client_ModeAdd( Client, 'o' );
974 if( ! IRC_WriteStrRelated( Client, "MODE %s :+o", Client_ID( Client ))) return DISCONNECTED;
975 IRC_WriteStrServersPrefix( NULL, Client, "MODE %s :+o", Client_ID( Client ));
978 if( ! Client_OperByMe( Client )) Log( LOG_NOTICE, "Got valid OPER from \"%s\", user is an IRC operator now.", Client_Mask( Client ));
980 Client_SetOperByMe( Client, TRUE );
981 return IRC_WriteStrClient( Client, RPL_YOUREOPER_MSG, Client_ID( Client ));
985 GLOBAL BOOLEAN IRC_DIE( CLIENT *Client, REQUEST *Req )
987 assert( Client != NULL );
988 assert( Req != NULL );
990 if( Client_Type( Client ) != CLIENT_USER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
992 /* Falsche Anzahl Parameter? */
993 if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
995 if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
997 Log( LOG_NOTICE, "Got DIE command from \"%s\", going down!", Client_Mask( Client ));
1003 GLOBAL BOOLEAN IRC_RESTART( CLIENT *Client, REQUEST *Req )
1005 assert( Client != NULL );
1006 assert( Req != NULL );
1008 if( Client_Type( Client ) != CLIENT_USER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
1010 /* Falsche Anzahl Parameter? */
1011 if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
1013 if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
1015 Log( LOG_NOTICE, "Got RESTART command from \"%s\", going down!", Client_Mask( Client ));
1016 NGIRCd_Restart = TRUE;
1021 GLOBAL BOOLEAN IRC_NAMES( CLIENT *Client, REQUEST *Req )
1023 CHAR rpl[COMMAND_LEN];
1026 assert( Client != NULL );
1027 assert( Req != NULL );
1029 if( Client_Type( Client ) != CLIENT_USER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
1031 /* Falsche Anzahl Parameter? */
1032 if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
1034 /* Noch alle User ausgeben, die in keinem Channel sind */
1036 c = Client_First( );
1039 if( Client_Type( c ) == CLIENT_USER )
1041 /* Okay, das ist ein User */
1042 strcat( rpl, Client_ID( c ));
1046 /* Antwort zu lang? Splitten. */
1047 if( strlen( rpl ) > 480 )
1049 if( rpl[strlen( rpl ) - 1] == ' ' ) rpl[strlen( rpl ) - 1] = '\0';
1050 if( ! IRC_WriteStrClient( Client, RPL_NAMREPLY_MSG, Client_ID( Client ), "*", "*", rpl )) return DISCONNECTED;
1054 c = Client_Next( c );
1058 /* es wurden User gefunden */
1059 if( rpl[strlen( rpl ) - 1] == ' ' ) rpl[strlen( rpl ) - 1] = '\0';
1060 if( ! IRC_WriteStrClient( Client, RPL_NAMREPLY_MSG, Client_ID( Client ), "*", "*", rpl )) return DISCONNECTED;
1062 return IRC_WriteStrClient( Client, RPL_ENDOFNAMES_MSG, Client_ID( Client ), "*" );
1066 GLOBAL BOOLEAN IRC_ISON( CLIENT *Client, REQUEST *Req )
1068 CHAR rpl[COMMAND_LEN];
1073 assert( Client != NULL );
1074 assert( Req != NULL );
1076 if( Client_Type( Client ) != CLIENT_USER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
1078 /* Falsche Anzahl Parameter? */
1079 if(( Req->argc < 1 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
1081 strcpy( rpl, RPL_ISON_MSG );
1082 for( i = 0; i < Req->argc; i++ )
1084 ptr = strtok( Req->argv[i], " " );
1088 c = Client_GetFromID( ptr );
1089 if( c && ( Client_Type( c ) == CLIENT_USER ))
1091 /* Dieser Nick ist "online" */
1095 ptr = strtok( NULL, " " );
1098 if( rpl[strlen( rpl ) - 1] == ' ' ) rpl[strlen( rpl ) - 1] = '\0';
1100 return IRC_WriteStrClient( Client, rpl, Client_ID( Client ) );
1104 GLOBAL BOOLEAN IRC_WHOIS( CLIENT *Client, REQUEST *Req )
1106 CLIENT *from, *target, *c;
1109 assert( Client != NULL );
1110 assert( Req != NULL );
1112 if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
1114 /* Falsche Anzahl Parameter? */
1115 if(( Req->argc < 1 ) || ( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
1118 c = Client_GetFromID( Req->argv[Req->argc - 1] );
1119 if(( ! c ) || ( Client_Type( c ) != CLIENT_USER )) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->argv[Req->argc - 1] );
1121 /* Empfaenger des WHOIS suchen */
1122 if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_GetFromID( Req->prefix );
1124 if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
1126 /* Forwarden an anderen Server? */
1129 /* angegebenen Ziel-Server suchen */
1130 target = Client_GetFromID( Req->argv[1] );
1131 if( ! target ) return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[1] );
1135 else if( Client_Conn( c ) == NONE )
1137 /* Client ist nicht von uns. Ziel-Server suchen */
1144 if( target && ( Client_NextHop( target ) != Client_ThisServer( )) && ( Client_Type( Client_NextHop( target )) == CLIENT_SERVER )) return IRC_WriteStrClientPrefix( target, from, "WHOIS %s :%s", Req->argv[0], ptr );
1146 /* Nick, User und Name */
1147 if( ! IRC_WriteStrClient( from, RPL_WHOISUSER_MSG, Client_ID( from ), Client_ID( c ), Client_User( c ), Client_Hostname( c ), Client_Info( c ))) return DISCONNECTED;
1150 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;
1153 if( Client_HasMode( c, 'o' ))
1155 if( ! IRC_WriteStrClient( from, RPL_WHOISOPERATOR_MSG, Client_ID( from ), Client_ID( c ))) return DISCONNECTED;
1158 /* Idle (nur lokale Clients) */
1159 if( Client_Conn( c ) > NONE )
1161 if( ! IRC_WriteStrClient( from, RPL_WHOISIDLE_MSG, Client_ID( from ), Client_ID( c ), Conn_GetIdle( Client_Conn ( c )))) return DISCONNECTED;
1165 return IRC_WriteStrClient( from, RPL_ENDOFWHOIS_MSG, Client_ID( from ), Client_ID( c ));
1169 GLOBAL BOOLEAN IRC_USERHOST( CLIENT *Client, REQUEST *Req )
1171 CHAR rpl[COMMAND_LEN];
1175 assert( Client != NULL );
1176 assert( Req != NULL );
1178 if( Client_Type( Client ) != CLIENT_USER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
1180 /* Falsche Anzahl Parameter? */
1181 if(( Req->argc < 1 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
1183 if( Req->argc > 5 ) max = 5;
1184 else max = Req->argc;
1186 strcpy( rpl, RPL_USERHOST_MSG );
1187 for( i = 0; i < max; i++ )
1189 c = Client_GetFromID( Req->argv[i] );
1190 if( c && ( Client_Type( c ) == CLIENT_USER ))
1192 /* Dieser Nick ist "online" */
1193 strcat( rpl, Client_ID( c ));
1194 if( Client_HasMode( c, 'o' )) strcat( rpl, "*" );
1196 if( Client_HasMode( c, 'a' )) strcat( rpl, "-" );
1197 else strcat( rpl, "+" );
1198 strcat( rpl, Client_User( c ));
1200 strcat( rpl, Client_Hostname( c ));
1204 if( rpl[strlen( rpl ) - 1] == ' ' ) rpl[strlen( rpl ) - 1] = '\0';
1206 return IRC_WriteStrClient( Client, rpl, Client_ID( Client ) );
1207 } /* IRC_USERHOST */
1210 GLOBAL BOOLEAN IRC_ERROR( CLIENT *Client, REQUEST *Req )
1212 assert( Client != NULL );
1213 assert( Req != NULL );
1215 if( Req->argc < 1 ) Log( LOG_NOTICE, "Got ERROR from \"%s\"!", Client_Mask( Client ));
1216 else Log( LOG_NOTICE, "Got ERROR from \"%s\": %s!", Client_Mask( Client ), Req->argv[0] );
1222 GLOBAL BOOLEAN IRC_LUSERS( CLIENT *Client, REQUEST *Req )
1224 CLIENT *target, *from;
1227 assert( Client != NULL );
1228 assert( Req != NULL );
1230 if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
1232 /* Falsche Anzahl Parameter? */
1233 if(( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
1235 /* Absender ermitteln */
1236 if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_GetFromID( Req->prefix );
1238 if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
1240 /* An anderen Server forwarden? */
1241 if( Req->argc == 2 )
1243 target = Client_GetFromID( Req->argv[1] );
1244 if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[1] );
1245 else if( target != Client_ThisServer( )) return IRC_WriteStrClientPrefix( target, from, "LUSERS %s %s", Req->argv[0], Req->argv[1] );
1248 /* Wer ist der Absender? */
1249 if( Client_Type( Client ) == CLIENT_SERVER ) target = Client_GetFromID( Req->prefix );
1250 else target = Client;
1251 if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
1253 /* Users, Services und Serevr im Netz */
1254 if( ! IRC_WriteStrClient( target, RPL_LUSERCLIENT_MSG, Client_ID( target ), Client_UserCount( ), Client_ServiceCount( ), Client_ServerCount( ))) return DISCONNECTED;
1256 /* IRC-Operatoren im Netz */
1257 cnt = Client_OperCount( );
1260 if( ! IRC_WriteStrClient( target, RPL_LUSEROP_MSG, Client_ID( target ), cnt )) return DISCONNECTED;
1263 /* Unbekannt Verbindungen */
1264 cnt = Client_UnknownCount( );
1267 if( ! IRC_WriteStrClient( target, RPL_LUSERUNKNOWN_MSG, Client_ID( target ), cnt )) return DISCONNECTED;
1270 /* Channels im Netz */
1271 if( ! IRC_WriteStrClient( target, RPL_LUSERCHANNELS_MSG, Client_ID( target ), Channel_Count( ))) return DISCONNECTED;
1273 /* Channels im Netz */
1274 if( ! IRC_WriteStrClient( target, RPL_LUSERME_MSG, Client_ID( target ), Client_MyUserCount( ), Client_MyServiceCount( ), Client_MyServerCount( ))) return DISCONNECTED;
1280 GLOBAL BOOLEAN IRC_LINKS( CLIENT *Client, REQUEST *Req )
1282 CLIENT *target, *from, *c;
1285 assert( Client != NULL );
1286 assert( Req != NULL );
1288 if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
1290 /* Falsche Anzahl Parameter? */
1291 if(( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
1293 /* Server-Mask ermitteln */
1294 if( Req->argc > 0 ) mask = Req->argv[Req->argc - 1];
1297 /* Absender ermitteln */
1298 if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_GetFromID( Req->prefix );
1300 if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
1302 /* An anderen Server forwarden? */
1303 if( Req->argc == 2 )
1305 target = Client_GetFromID( Req->argv[0] );
1306 if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[0] );
1307 else if( target != Client_ThisServer( )) return IRC_WriteStrClientPrefix( target, from, "LINKS %s %s", Req->argv[0], Req->argv[1] );
1310 /* Wer ist der Absender? */
1311 if( Client_Type( Client ) == CLIENT_SERVER ) target = Client_GetFromID( Req->prefix );
1312 else target = Client;
1313 if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
1315 c = Client_First( );
1318 if( Client_Type( c ) == CLIENT_SERVER )
1320 if( ! IRC_WriteStrClient( target, RPL_LINKS_MSG, Client_ID( target ), Client_ID( c ), Client_ID( Client_Introducer( c )), Client_Hops( c ), Client_Info( c ))) return DISCONNECTED;
1322 c = Client_Next( c );
1325 return IRC_WriteStrClient( target, RPL_ENDOFLINKS_MSG, Client_ID( target ), mask );
1329 LOCAL BOOLEAN Hello_User( CLIENT *Client )
1331 assert( Client != NULL );
1333 /* Passwort ueberpruefen */
1334 if( strcmp( Client_Password( Client ), Conf_ServerPwd ) != 0 )
1336 /* Falsches Passwort */
1337 Log( LOG_ERR, "User \"%s\" rejected (connection %d): Bad password!", Client_Mask( Client ), Client_Conn( Client ));
1338 Conn_Close( Client_Conn( Client ), NULL, "Bad password", TRUE );
1339 return DISCONNECTED;
1342 Log( LOG_NOTICE, "User \"%s\" registered (connection %d).", Client_Mask( Client ), Client_Conn( Client ));
1344 /* Andere Server informieren */
1345 IRC_WriteStrServers( NULL, "NICK %s 1 %s %s 1 +%s :%s", Client_ID( Client ), Client_User( Client ), Client_Hostname( Client ), Client_Modes( Client ), Client_Info( Client ));
1347 if( ! IRC_WriteStrClient( Client, RPL_WELCOME_MSG, Client_ID( Client ), Client_Mask( Client ))) return FALSE;
1348 if( ! IRC_WriteStrClient( Client, RPL_YOURHOST_MSG, Client_ID( Client ), Client_ID( Client_ThisServer( )))) return FALSE;
1349 if( ! IRC_WriteStrClient( Client, RPL_CREATED_MSG, Client_ID( Client ), NGIRCd_StartStr )) return FALSE;
1350 if( ! IRC_WriteStrClient( Client, RPL_MYINFO_MSG, Client_ID( Client ), Client_ID( Client_ThisServer( )))) return FALSE;
1352 Client_SetType( Client, CLIENT_USER );
1354 return Show_MOTD( Client );
1358 LOCAL BOOLEAN Show_MOTD( CLIENT *Client )
1364 assert( Client != NULL );
1366 fd = fopen( Conf_MotdFile, "r" );
1369 Log( LOG_WARNING, "Can't read MOTD file \"%s\": %s", Conf_MotdFile, strerror( errno ));
1370 return IRC_WriteStrClient( Client, ERR_NOMOTD_MSG, Client_ID( Client ) );
1373 IRC_WriteStrClient( Client, RPL_MOTDSTART_MSG, Client_ID( Client ), Client_ID( Client_ThisServer( )));
1376 if( ! fgets( line, 126, fd )) break;
1377 if( line[strlen( line ) - 1] == '\n' ) line[strlen( line ) - 1] = '\0';
1378 if( ! IRC_WriteStrClient( Client, RPL_MOTD_MSG, Client_ID( Client ), line ))
1384 ok = IRC_WriteStrClient( Client, RPL_ENDOFMOTD_MSG, Client_ID( Client ) );
1392 LOCAL VOID Kill_Nick( CHAR *Nick )
1394 Log( LOG_ERR, "User(s) with nick \"%s\" will be disconnected!", Nick );
1396 Log( LOG_ALERT, "[Kill_Nick() not implemented - OOOPS!]" );