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.36 2002/01/11 23:50:55 alex Exp $
17 * Revision 1.36 2002/01/11 23:50:55 alex
18 * - LINKS implementiert, LUSERS begonnen.
20 * Revision 1.35 2002/01/09 21:30:45 alex
21 * - WHOIS wurde faelschlicherweise an User geforwarded statt vom Server beantwortet.
23 * Revision 1.34 2002/01/09 01:09:58 alex
24 * - WHOIS wird im "Strict-RFC-Mode" nicht mehr automatisch geforwarded,
25 * - andere Server werden nun ueber bisherige Server und User informiert.
27 * Revision 1.33 2002/01/07 23:42:12 alex
28 * - Es werden fuer alle Server eigene Token generiert,
29 * - QUIT von einem Server fuer einen User wird an andere Server geforwarded,
30 * - ebenso NICK-Befehle, die "fremde" User einfuehren.
32 * Revision 1.32 2002/01/07 16:02:36 alex
33 * - Loglevel von Remote-Mode-Aenderungen angepasst (nun Debug).
34 * - Im Debug-Mode werden nun auch PING's protokolliert.
36 * Revision 1.31 2002/01/07 15:39:46 alex
37 * - Server nimmt nun Server-Links an: PASS und SERVER entsprechend angepasst.
38 * - MODE und NICK melden nun die Aenderungen an andere Server.
40 * Revision 1.30 2002/01/06 15:21:29 alex
41 * - Loglevel und Meldungen nochmals ueberarbeitet.
42 * - QUIT und SQUIT forwarden nun den Grund der Trennung,
43 * - WHOIS wird nun immer an den "Original-Server" weitergeleitet.
45 * Revision 1.29 2002/01/05 23:24:54 alex
46 * - WHOIS erweitert: Anfragen koennen an andere Server weitergeleitet werden.
47 * - Vorbereitungen fuer Ident-Abfragen bei neuen Client-Strukturen.
49 * Revision 1.28 2002/01/05 20:08:02 alex
50 * - Div. Aenderungen fuer die Server-Links (u.a. WHOIS, QUIT, NICK angepasst).
51 * - Neue Funktionen IRC_WriteStrServer() und IRC_WriteStrServerPrefix().
53 * Revision 1.27 2002/01/05 19:15:03 alex
54 * - Fehlerpruefung bei select() in der "Hauptschleife" korrigiert.
56 * Revision 1.26 2002/01/05 16:51:18 alex
57 * - das Passwort von Servern wird nun ueberprueft (PASS- und SERVER-Befehl).
59 * Revision 1.25 2002/01/05 00:48:33 alex
60 * - bei SQUIT wurde immer die Verbindung getrennt, auch bei Remote-Servern.
62 * Revision 1.24 2002/01/04 17:58:44 alex
63 * - IRC_WriteStrXXX()-Funktionen eingefuehrt, groessere Anpassungen daran.
64 * - neuer Befehl SQUIT, QUIT an Server-Links angepasst.
66 * Revision 1.23 2002/01/04 01:36:40 alex
67 * - Loglevel ein wenig angepasst.
69 * Revision 1.22 2002/01/04 01:21:47 alex
70 * - Client-Strukruren werden nur noch ueber Funktionen angesprochen.
71 * - Weitere Anpassungen und Erweiterungen der Server-Links.
73 * Revision 1.21 2002/01/03 02:26:51 alex
74 * - neue Befehle SERVER und NJOIN begonnen,
75 * - begonnen, diverse IRC-Befehle an Server-Links anzupassen.
77 * Revision 1.20 2002/01/02 12:46:41 alex
78 * - die Gross- und Kleinschreibung des Nicks kann mit NICK nun geaendert werden.
80 * Revision 1.19 2002/01/02 02:51:39 alex
81 * - Copyright-Texte angepasst.
82 * - neuer Befehl "ERROR".
84 * Revision 1.17 2001/12/31 15:33:13 alex
85 * - neuer Befehl NAMES, kleinere Bugfixes.
86 * - Bug bei PING behoben: war zu restriktiv implementiert :-)
88 * Revision 1.16 2001/12/31 02:18:51 alex
89 * - viele neue Befehle (WHOIS, ISON, OPER, DIE, RESTART),
90 * - neuen Header "defines.h" mit (fast) allen Konstanten.
91 * - Code Cleanups und viele "kleine" Aenderungen & Bugfixes.
93 * Revision 1.15 2001/12/30 19:26:11 alex
94 * - Unterstuetzung fuer die Konfigurationsdatei eingebaut.
96 * Revision 1.14 2001/12/30 11:42:00 alex
97 * - der Server meldet nun eine ordentliche "Start-Zeit".
99 * Revision 1.13 2001/12/29 03:10:06 alex
100 * - Neue Funktion IRC_MODE() implementiert, div. Aenderungen.
101 * - neue configure-Optione "--enable-strict-rfc".
103 * Revision 1.12 2001/12/27 19:17:26 alex
104 * - neue Befehle PRIVMSG, NOTICE, PING.
106 * Revision 1.11 2001/12/27 16:55:41 alex
107 * - neu: IRC_WriteStrRelated(), Aenderungen auch in IRC_WriteStrClient().
109 * Revision 1.10 2001/12/26 22:48:53 alex
110 * - MOTD-Datei ist nun konfigurierbar und wird gelesen.
112 * Revision 1.9 2001/12/26 14:45:37 alex
115 * Revision 1.8 2001/12/26 03:21:46 alex
116 * - PING/PONG-Befehle implementiert,
117 * - Meldungen ueberarbeitet: enthalten nun (fast) immer den Nick.
119 * Revision 1.7 2001/12/25 23:25:18 alex
120 * - und nochmal Aenderungen am Logging ;-)
122 * Revision 1.6 2001/12/25 23:13:33 alex
123 * - Debug-Meldungen angepasst.
125 * Revision 1.5 2001/12/25 22:02:42 alex
126 * - neuer IRC-Befehl "/QUIT". Verbessertes Logging & Debug-Ausgaben.
128 * Revision 1.4 2001/12/25 19:19:30 alex
129 * - bessere Fehler-Abfragen, diverse Bugfixes.
130 * - Nicks werden nur einmal vergeben :-)
131 * - /MOTD wird unterstuetzt.
133 * Revision 1.3 2001/12/24 01:34:06 alex
134 * - USER und NICK wird nun in beliebiger Reihenfolge akzeptiert (wg. BitchX)
135 * - MOTD-Ausgabe begonnen zu implementieren.
137 * Revision 1.2 2001/12/23 21:57:16 alex
138 * - erste IRC-Befehle zu implementieren begonnen.
140 * Revision 1.1 2001/12/14 08:13:43 alex
141 * - neues Modul begonnen :-)
161 #include "messages.h"
169 #define CONNECTED TRUE
170 #define DISCONNECTED FALSE
173 LOCAL BOOLEAN Hello_User( CLIENT *Client );
174 LOCAL BOOLEAN Show_MOTD( CLIENT *Client );
176 LOCAL VOID Kill_Nick( CHAR *Nick );
179 GLOBAL VOID IRC_Init( VOID )
184 GLOBAL VOID IRC_Exit( VOID )
189 GLOBAL BOOLEAN IRC_WriteStrClient( CLIENT *Client, CHAR *Format, ... )
192 BOOLEAN ok = CONNECTED;
195 assert( Client != NULL );
196 assert( Format != NULL );
198 va_start( ap, Format );
199 vsnprintf( buffer, 1000, Format, ap );
202 /* an den Client selber */
203 ok = IRC_WriteStrClientPrefix( Client, Client_ThisServer( ), buffer );
206 } /* IRC_WriteStrClient */
209 GLOBAL BOOLEAN IRC_WriteStrClientPrefix( CLIENT *Client, CLIENT *Prefix, CHAR *Format, ... )
211 /* Text an Clients, lokal bzw. remote, senden. */
216 assert( Client != NULL );
217 assert( Format != NULL );
218 assert( Prefix != NULL );
220 va_start( ap, Format );
221 vsnprintf( buffer, 1000, Format, ap );
224 return Conn_WriteStr( Client_Conn( Client_NextHop( Client )), ":%s %s", Client_ID( Prefix ), buffer );
225 } /* IRC_WriteStrClientPrefix */
228 GLOBAL BOOLEAN IRC_WriteStrRelated( CLIENT *Client, CHAR *Format, ... )
231 BOOLEAN ok = CONNECTED;
234 assert( Client != NULL );
235 assert( Format != NULL );
237 va_start( ap, Format );
238 vsnprintf( buffer, 1000, Format, ap );
241 /* an den Client selber */
242 ok = IRC_WriteStrClient( Client, buffer );
247 } /* IRC_WriteStrRelated */
250 GLOBAL VOID IRC_WriteStrServers( CLIENT *ExceptOf, CHAR *Format, ... )
255 assert( Format != NULL );
257 va_start( ap, Format );
258 vsnprintf( buffer, 1000, Format, ap );
261 /* an den Client selber */
262 return IRC_WriteStrServersPrefix( ExceptOf, Client_ThisServer( ), buffer );
263 } /* IRC_WriteStrServers */
266 GLOBAL VOID IRC_WriteStrServersPrefix( CLIENT *ExceptOf, CLIENT *Prefix, CHAR *Format, ... )
272 assert( Format != NULL );
273 assert( Prefix != NULL );
275 va_start( ap, Format );
276 vsnprintf( buffer, 1000, Format, ap );
282 if(( Client_Type( c ) == CLIENT_SERVER ) && ( Client_Conn( c ) > NONE ) && ( c != Client_ThisServer( )) && ( c != ExceptOf ))
284 /* Ziel-Server gefunden */
285 IRC_WriteStrClientPrefix( c, Prefix, buffer );
287 c = Client_Next( c );
289 } /* IRC_WriteStrServersPrefix */
292 GLOBAL BOOLEAN IRC_PASS( CLIENT *Client, REQUEST *Req )
294 assert( Client != NULL );
295 assert( Req != NULL );
297 /* Fehler liefern, wenn kein lokaler Client */
298 if( Client_Conn( Client ) <= NONE ) return IRC_WriteStrClient( Client, ERR_UNKNOWNCOMMAND_MSG, Client_ID( Client ), Req->command );
300 if(( Client_Type( Client ) == CLIENT_UNKNOWN ) && ( Req->argc == 1))
302 /* noch nicht registrierte unbekannte Verbindung */
303 Log( LOG_DEBUG, "Connection %d: got PASS command ...", Client_Conn( Client ));
305 /* Passwort speichern */
306 Client_SetPassword( Client, Req->argv[0] );
308 Client_SetType( Client, CLIENT_GOTPASS );
311 else if((( Client_Type( Client ) == CLIENT_UNKNOWN ) || ( Client_Type( Client ) == CLIENT_UNKNOWNSERVER )) && (( Req->argc == 3 ) || ( Req->argc == 4 )))
313 /* noch nicht registrierte Server-Verbindung */
314 Log( LOG_DEBUG, "Connection %d: got PASS command (new server link) ...", Client_Conn( Client ));
316 /* Passwort speichern */
317 Client_SetPassword( Client, Req->argv[0] );
319 Client_SetType( Client, CLIENT_GOTPASSSERVER );
322 else if(( Client_Type( Client ) == CLIENT_UNKNOWN ) || ( Client_Type( Client ) == CLIENT_UNKNOWNSERVER ))
324 /* Falsche Anzahl Parameter? */
325 return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
327 else return IRC_WriteStrClient( Client, ERR_ALREADYREGISTRED_MSG, Client_ID( Client ));
331 GLOBAL BOOLEAN IRC_SERVER( CLIENT *Client, REQUEST *Req )
333 CHAR str[LINE_LEN], *ptr;
338 assert( Client != NULL );
339 assert( Req != NULL );
341 /* Fehler liefern, wenn kein lokaler Client */
342 if( Client_Conn( Client ) <= NONE ) return IRC_WriteStrClient( Client, ERR_UNKNOWNCOMMAND_MSG, Client_ID( Client ), Req->command );
344 if( Client_Type( Client ) == CLIENT_GOTPASSSERVER )
346 /* Verbindung soll als Server-Server-Verbindung registriert werden */
347 Log( LOG_DEBUG, "Connection %d: got SERVER command (new server link) ...", Client_Conn( Client ));
349 /* Falsche Anzahl Parameter? */
350 if(( Req->argc != 2 ) && ( Req->argc != 3 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
352 /* Ist dieser Server bei uns konfiguriert? */
353 for( i = 0; i < Conf_Server_Count; i++ ) if( strcasecmp( Req->argv[0], Conf_Server[i].name ) == 0 ) break;
354 if( i >= Conf_Server_Count )
356 /* Server ist nicht konfiguriert! */
357 Log( LOG_ERR, "Connection %d: Server \"%s\" not configured here!", Client_Conn( Client ), Req->argv[0] );
358 Conn_Close( Client_Conn( Client ), NULL, "Server not configured here", TRUE );
361 if( strcmp( Client_Password( Client ), Conf_Server[i].pwd ) != 0 )
363 /* Falsches Passwort */
364 Log( LOG_ERR, "Connection %d: Bad password for server \"%s\"!", Client_Conn( Client ), Req->argv[0] );
365 Conn_Close( Client_Conn( Client ), NULL, "Bad password", TRUE );
369 /* Ist ein Server mit dieser ID bereits registriert? */
370 if( ! Client_CheckID( Client, Req->argv[0] )) return DISCONNECTED;
372 /* Server-Strukturen fuellen ;-) */
373 Client_SetID( Client, Req->argv[0] );
374 Client_SetHops( Client, 1 );
375 Client_SetInfo( Client, Req->argv[Req->argc - 1] );
377 /* Meldet sich der Server bei uns an? */
380 /* Unseren SERVER- und PASS-Befehl senden */
382 if( ! IRC_WriteStrClient( Client, "PASS %s "PASSSERVERADD, Conf_Server[i].pwd )) ok = FALSE;
383 else ok = IRC_WriteStrClient( Client, "SERVER %s 1 :%s", Conf_ServerName, Conf_ServerInfo );
386 Conn_Close( Client_Conn( Client ), "Unexpected server behavior!", NULL, FALSE );
389 Client_SetIntroducer( Client, Client );
390 Client_SetToken( Client, 1 );
392 else Client_SetToken( Client, atoi( Req->argv[1] ));
394 Log( LOG_NOTICE, "Server \"%s\" registered (connection %d, 1 hop - direct link).", Client_ID( Client ), Client_Conn( Client ));
396 Client_SetType( Client, CLIENT_SERVER );
398 /* Alle bisherigen Server dem neuen Server bekannt machen,
399 * die bisherigen Server ueber den neuen informierenn */
403 if(( Client_Type( c ) == CLIENT_SERVER ) && ( c != Client ) && ( c != Client_ThisServer( )))
405 if( Client_Conn( c ) > NONE )
407 /* Dem gefundenen Server gleich den neuen
408 * Server bekannt machen */
409 if( ! IRC_WriteStrClient( c, "SERVER %s %d %d :%s", Client_ID( Client ), Client_Hops( Client ) + 1, Client_MyToken( Client ), Client_Info( Client ))) return DISCONNECTED;
412 /* Den neuen Server ueber den alten informieren */
413 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;
415 c = Client_Next( c );
418 /* alle User dem neuen Server bekannt machen */
422 if( Client_Type( c ) == CLIENT_USER )
424 /* User an neuen Server melden */
425 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;
427 c = Client_Next( c );
432 else if( Client_Type( Client ) == CLIENT_SERVER )
434 /* Neuer Server wird im Netz angekuendigt */
436 /* Falsche Anzahl Parameter? */
437 if( Req->argc != 4 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
439 /* Ist ein Server mit dieser ID bereits registriert? */
440 if( ! Client_CheckID( Client, Req->argv[0] )) return DISCONNECTED;
442 /* Ueberfluessige Hostnamen aus Info-Text entfernen */
443 ptr = strchr( Req->argv[3] + 2, '[' );
444 if( ! ptr ) ptr = Req->argv[3];
446 /* Neue Client-Struktur anlegen */
447 c = Client_NewRemoteServer( Client, Req->argv[0], atoi( Req->argv[1] ), atoi( Req->argv[2] ), ptr, TRUE );
450 /* Neue Client-Struktur konnte nicht angelegt werden */
451 Log( LOG_ALERT, "Can't create client structure for server! (on connection %d)", Client_Conn( Client ));
452 Conn_Close( Client_Conn( Client ), NULL, "Can't allocate client structure for remote server", TRUE );
456 /* Log-Meldung zusammenbauen und ausgeben */
457 if(( Client_Hops( c ) > 1 ) && ( Req->prefix[0] )) sprintf( str, "connected to %s, ", Req->prefix );
458 else strcpy( str, "" );
459 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": "" );
463 else return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
467 GLOBAL BOOLEAN IRC_NJOIN( CLIENT *Client, REQUEST *Req )
469 assert( Client != NULL );
470 assert( Req != NULL );
472 if( Client_Type( Client ) != CLIENT_SERVER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTEREDSERVER_MSG, Client_ID( Client ));
478 GLOBAL BOOLEAN IRC_NICK( CLIENT *Client, REQUEST *Req )
480 CLIENT *intr_c, *target, *c;
482 assert( Client != NULL );
483 assert( Req != NULL );
485 /* Zumindest BitchX sendet NICK-USER in der falschen Reihenfolge. */
487 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 ))
489 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 ))
492 /* User-Registrierung bzw. Nick-Aenderung */
494 /* Falsche Anzahl Parameter? */
495 if( Req->argc != 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
497 /* "Ziel-Client" ermitteln */
498 if( Client_Type( Client ) == CLIENT_SERVER )
500 target = Client_GetFromID( Req->prefix );
501 if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->argv[0] );
505 /* Ist der Client "restricted"? */
506 if( Client_HasMode( Client, 'r' )) return IRC_WriteStrClient( Client, ERR_RESTRICTED_MSG, Client_ID( Client ));
510 /* Wenn der Client zu seinem eigenen Nick wechseln will, so machen
511 * wir nichts. So macht es das Original und mind. Snak hat probleme,
512 * wenn wir es nicht so machen. Ob es so okay ist? Hm ... */
514 if( strcmp( Client_ID( target ), Req->argv[0] ) == 0 ) return CONNECTED;
517 /* pruefen, ob Nick bereits vergeben. Speziallfall: der Client
518 * will nur die Gross- und Kleinschreibung aendern. Das darf
519 * er natuerlich machen :-) */
520 if( strcasecmp( Client_ID( target ), Req->argv[0] ) != 0 )
522 if( ! Client_CheckNick( target, Req->argv[0] )) return CONNECTED;
525 if( Client_Type( Client ) == CLIENT_USER )
527 /* Nick-Aenderung: allen mitteilen! */
528 Log( LOG_INFO, "User \"%s\" changed nick: \"%s\" -> \"%s\".", Client_Mask( target ), Client_ID( target ), Req->argv[0] );
529 IRC_WriteStrRelated( Client, "NICK :%s", Req->argv[0] );
530 IRC_WriteStrServersPrefix( NULL, Client, "NICK :%s", Req->argv[0] );
532 else if( Client_Type( Client ) == CLIENT_SERVER )
534 /* Nick-Aenderung: allen mitteilen! */
535 Log( LOG_DEBUG, "User \"%s\" changed nick: \"%s\" -> \"%s\".", Client_Mask( target ), Client_ID( target ), Req->argv[0] );
536 IRC_WriteStrServersPrefix( Client, Client, "NICK :%s", Req->argv[0] );
539 /* Client-Nick registrieren */
540 Client_SetID( target, Req->argv[0] );
542 if(( Client_Type( target ) != CLIENT_USER ) && ( Client_Type( target ) != CLIENT_SERVER ))
545 Log( LOG_DEBUG, "Connection %d: got NICK command ...", Client_Conn( Client ));
546 if( Client_Type( Client ) == CLIENT_GOTUSER ) return Hello_User( Client );
547 else Client_SetType( Client, CLIENT_GOTNICK );
551 else if( Client_Type( Client ) == CLIENT_SERVER )
553 /* Server fuehrt neuen Client ein */
555 /* Falsche Anzahl Parameter? */
556 if( Req->argc != 7 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
558 /* Nick ueberpruefen */
559 c = Client_GetFromID( Req->argv[0] );
562 /* Der neue Nick ist auf diesem Server bereits registriert:
563 * sowohl der neue, als auch der alte Client muessen nun
564 * disconnectiert werden. */
565 Log( LOG_ERR, "Server %s introduces already registered nick \"%s\"!", Client_ID( Client ), Req->argv[0] );
566 Kill_Nick( Req->argv[0] );
570 /* Server, zu dem der Client connectiert ist, suchen */
571 intr_c = Client_GetFromToken( Client, atoi( Req->argv[4] ));
574 Log( LOG_ERR, "Server %s introduces nick \"%s\" on unknown server!?", Client_ID( Client ), Req->argv[0] );
575 Kill_Nick( Req->argv[0] );
579 /* Neue Client-Struktur anlegen */
580 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 );
583 /* Eine neue Client-Struktur konnte nicht angelegt werden.
584 * Der Client muss disconnectiert werden, damit der Netz-
585 * status konsistent bleibt. */
586 Log( LOG_ALERT, "Can't create client structure! (on connection %d)", Client_Conn( Client ));
587 Kill_Nick( Req->argv[0] );
591 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": "" );
593 /* Andere Server, ausser dem Introducer, informieren */
594 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] );
598 else return IRC_WriteStrClient( Client, ERR_ALREADYREGISTRED_MSG, Client_ID( Client ));
602 GLOBAL BOOLEAN IRC_USER( CLIENT *Client, REQUEST *Req )
604 assert( Client != NULL );
605 assert( Req != NULL );
608 if( Client_Type( Client ) == CLIENT_GOTNICK || Client_Type( Client ) == CLIENT_GOTPASS || Client_Type( Client ) == CLIENT_UNKNOWN )
610 if( Client_Type( Client ) == CLIENT_GOTNICK || Client_Type( Client ) == CLIENT_GOTPASS )
613 /* Falsche Anzahl Parameter? */
614 if( Req->argc != 4 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
616 Client_SetUser( Client, Req->argv[0], FALSE );
617 Client_SetInfo( Client, Req->argv[3] );
619 Log( LOG_DEBUG, "Connection %d: got USER command ...", Client_Conn( Client ));
620 if( Client_Type( Client ) == CLIENT_GOTNICK ) return Hello_User( Client );
621 else Client_SetType( Client, CLIENT_GOTUSER );
624 else if( Client_Type( Client ) == CLIENT_USER || Client_Type( Client ) == CLIENT_SERVER || Client_Type( Client ) == CLIENT_SERVICE )
626 return IRC_WriteStrClient( Client, ERR_ALREADYREGISTRED_MSG, Client_ID( Client ));
628 else return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
632 GLOBAL BOOLEAN IRC_QUIT( CLIENT *Client, REQUEST *Req )
636 assert( Client != NULL );
637 assert( Req != NULL );
639 if(( Client_Type( Client ) == CLIENT_USER ) || ( Client_Type( Client ) == CLIENT_SERVICE ))
643 /* Falsche Anzahl Parameter? */
644 if( Req->argc > 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
646 if( Req->argc == 0 ) Conn_Close( Client_Conn( Client ), "Got QUIT command.", NULL, TRUE );
647 else Conn_Close( Client_Conn( Client ), "Got QUIT command.", Req->argv[0], TRUE );
651 else if ( Client_Type( Client ) == CLIENT_SERVER )
655 /* Falsche Anzahl Parameter? */
656 if( Req->argc > 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
658 target = Client_Search( Req->prefix );
661 Log( LOG_ERR, "Got QUIT from %s for unknown client!?", Client_ID( Client ));
665 if( Req->argc == 0 ) Client_Destroy( target, "Got QUIT command.", NULL );
666 else Client_Destroy( target, "Got QUIT command.", Req->argv[0] );
670 else return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
674 GLOBAL BOOLEAN IRC_SQUIT( CLIENT *Client, REQUEST *Req )
678 assert( Client != NULL );
679 assert( Req != NULL );
681 /* SQUIT ist nur fuer Server erlaubt */
682 if( Client_Type( Client ) != CLIENT_SERVER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
684 /* Falsche Anzahl Parameter? */
685 if( Req->argc != 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
687 target = Client_GetFromID( Req->argv[0] );
690 Log( LOG_ERR, "Got SQUIT from %s for unknown server \%s\"!?", Client_ID( Client ), Req->argv[0] );
694 if( target == Client ) Log( LOG_DEBUG, "Got SQUIT from %s: %s", Client_ID( Client ), Req->argv[1] );
695 else Log( LOG_DEBUG, "Got SQUIT from %s for %s: %s", Client_ID( Client ), Client_ID( target ), Req->argv[1] );
697 /* SQUIT an alle Server weiterleiten */
698 IRC_WriteStrServers( Client, "SQUIT %s :%s", Req->argv[0], Req->argv[1] );
700 if( Client_Conn( target ) > NONE )
702 if( Req->argv[1][0] ) Conn_Close( Client_Conn( target ), "Got SQUIT command.", Req->argv[1], TRUE );
703 else Conn_Close( Client_Conn( target ), "Got SQUIT command.", NULL, TRUE );
708 Client_Destroy( target, "Got SQUIT command.", Req->argv[1] );
714 GLOBAL BOOLEAN IRC_PING( CLIENT *Client, REQUEST *Req )
716 assert( Client != NULL );
717 assert( Req != NULL );
719 if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
721 /* Falsche Anzahl Parameter? */
722 if( Req->argc < 1 ) return IRC_WriteStrClient( Client, ERR_NOORIGIN_MSG, Client_ID( Client ));
723 if( Req->argc > 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
725 Log( LOG_DEBUG, "Connection %d: got PING, sending PONG ...", Client_Conn( Client ));
726 return IRC_WriteStrClient( Client, "PONG %s :%s", Client_ID( Client_ThisServer( )), Client_ID( Client ));
730 GLOBAL BOOLEAN IRC_PONG( CLIENT *Client, REQUEST *Req )
732 assert( Client != NULL );
733 assert( Req != NULL );
735 if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
737 /* Falsche Anzahl Parameter? */
738 if( Req->argc < 1 ) return IRC_WriteStrClient( Client, ERR_NOORIGIN_MSG, Client_ID( Client ));
739 if( Req->argc > 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
741 /* Der Connection-Timestamp wurde schon beim Lesen aus dem Socket
742 * aktualisiert, daher muss das hier nicht mehr gemacht werden. */
744 Log( LOG_DEBUG, "Connection %d: received PONG.", Client_Conn( Client ));
749 GLOBAL BOOLEAN IRC_MOTD( CLIENT *Client, REQUEST *Req )
751 assert( Client != NULL );
752 assert( Req != NULL );
754 if( Client_Type( Client ) != CLIENT_USER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
756 /* Falsche Anzahl Parameter? */
757 if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
759 return Show_MOTD( Client );
763 GLOBAL BOOLEAN IRC_PRIVMSG( CLIENT *Client, REQUEST *Req )
767 assert( Client != NULL );
768 assert( Req != NULL );
770 if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
772 /* Falsche Anzahl Parameter? */
773 if( Req->argc == 0 ) return IRC_WriteStrClient( Client, ERR_NORECIPIENT_MSG, Client_ID( Client ), Req->command );
774 if( Req->argc == 1 ) return IRC_WriteStrClient( Client, ERR_NOTEXTTOSEND_MSG, Client_ID( Client ));
775 if( Req->argc > 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
777 if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_GetFromID( Req->prefix );
779 if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
781 to = Client_Search( Req->argv[0] );
784 /* Okay, Ziel ist ein User */
785 if( Client_Conn( from ) >= 0 ) Conn_UpdateIdle( Client_Conn( from ));
786 return IRC_WriteStrClientPrefix( to, from, "PRIVMSG %s :%s", Client_ID( to ), Req->argv[1] );
788 else return IRC_WriteStrClient( from, ERR_NOSUCHNICK_MSG, Client_ID( from ), Req->argv[0] );
792 GLOBAL BOOLEAN IRC_NOTICE( CLIENT *Client, REQUEST *Req )
796 assert( Client != NULL );
797 assert( Req != NULL );
799 if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
801 /* Falsche Anzahl Parameter? */
802 if( Req->argc != 2 ) return CONNECTED;
804 if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_GetFromID( Req->prefix );
806 if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
808 to = Client_Search( Req->argv[0] );
811 /* Okay, Ziel ist ein User */
812 return IRC_WriteStrClientPrefix( to, from, "NOTICE %s :%s", Client_ID( to ), Req->argv[1] );
814 else return CONNECTED;
818 GLOBAL BOOLEAN IRC_MODE( CLIENT *Client, REQUEST *Req )
820 CHAR x[2], new_modes[CLIENT_MODE_LEN], *ptr;
824 assert( Client != NULL );
825 assert( Req != NULL );
827 if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
829 /* Falsche Anzahl Parameter? */
830 if(( Req->argc > 2 ) || ( Req->argc < 1 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
832 /* "Ziel-Client" suchen */
833 target = Client_Search( Req->argv[0] );
835 /* Wer ist der Anfragende? */
836 if( Client_Type( Client ) == CLIENT_USER )
838 /* User: MODE ist nur fuer sich selber zulaessig */
839 if( target != Client ) return IRC_WriteStrClient( Client, ERR_USERSDONTMATCH_MSG, Client_ID( Client ));
843 /* Server: gibt es den Client ueberhaupt? */
844 if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->argv[0] );
847 /* Werden die Modes erfragt? */
848 if( Req->argc == 1 ) return IRC_WriteStrClient( Client, RPL_UMODEIS_MSG, Client_ID( Client ), Client_Modes( Client ));
852 /* Sollen Modes gesetzt oder geloescht werden? */
853 if( *ptr == '+' ) set = TRUE;
854 else if( *ptr == '-' ) set = FALSE;
855 else return IRC_WriteStrClient( Client, ERR_UMODEUNKNOWNFLAG_MSG, Client_ID( Client ));
857 /* Reply-String mit Aenderungen vorbereiten */
858 if( set ) strcpy( new_modes, "+" );
859 else strcpy( new_modes, "-" );
867 if( Client_Type( Client ) == CLIENT_SERVER )
881 /* restricted (kann nur gesetzt werden) */
882 if( set ) x[0] = 'r';
883 else ok = IRC_WriteStrClient( target, ERR_RESTRICTED_MSG, Client_ID( target ));
886 /* operator (kann nur geloescht werden) */
889 Client_SetOperByMe( target, FALSE );
892 else ok = IRC_WriteStrClient( target, ERR_UMODEUNKNOWNFLAG_MSG, Client_ID( target ));
895 ok = IRC_WriteStrClient( target, ERR_UMODEUNKNOWNFLAG_MSG, Client_ID( target ));
902 if( ! x[0] ) continue;
904 /* Okay, gueltigen Mode gefunden */
907 /* Mode setzen. Wenn der Client ihn noch nicht hatte: merken */
908 if( Client_ModeAdd( target, x[0] )) strcat( new_modes, x );
912 /* Modes geloescht. Wenn der Client ihn hatte: merken */
913 if( Client_ModeDel( target, x[0] )) strcat( new_modes, x );
917 /* Geanderte Modes? */
920 if( Client_Type( Client ) == CLIENT_SERVER )
922 /* Modes an andere Server forwarden */
923 IRC_WriteStrServersPrefix( Client, Client, "MODE %s :%s", Client_ID( target ), new_modes );
927 /* Bestaetigung an Client schicken & andere Server informieren */
928 ok = IRC_WriteStrRelated( Client, "MODE %s :%s", Client_ID( target ), new_modes );
929 IRC_WriteStrServers( Client, "MODE %s :%s", Client_ID( target ), new_modes );
931 Log( LOG_DEBUG, "User \"%s\": Mode change, now \"%s\".", Client_Mask( target ), Client_Modes( target ));
937 GLOBAL BOOLEAN IRC_OPER( CLIENT *Client, REQUEST *Req )
941 assert( Client != NULL );
942 assert( Req != NULL );
944 if( Client_Type( Client ) != CLIENT_USER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
946 /* Falsche Anzahl Parameter? */
947 if( Req->argc != 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
949 /* Operator suchen */
950 for( i = 0; i < Conf_Oper_Count; i++)
952 if( Conf_Oper[i].name[0] && Conf_Oper[i].pwd[0] && ( strcmp( Conf_Oper[i].name, Req->argv[0] ) == 0 )) break;
954 if( i >= Conf_Oper_Count )
956 Log( LOG_WARNING, "Got invalid OPER from \"%s\": Name \"%s\" not configured!", Client_Mask( Client ), Req->argv[0] );
957 return IRC_WriteStrClient( Client, ERR_PASSWDMISMATCH_MSG, Client_ID( Client ));
960 /* Stimmt das Passwort? */
961 if( strcmp( Conf_Oper[i].pwd, Req->argv[1] ) != 0 )
963 Log( LOG_WARNING, "Got invalid OPER from \"%s\": Bad password for \"%s\"!", Client_Mask( Client ), Conf_Oper[i].name );
964 return IRC_WriteStrClient( Client, ERR_PASSWDMISMATCH_MSG, Client_ID( Client ));
967 if( ! Client_HasMode( Client, 'o' ))
969 /* noch kein o-Mode gesetzt */
970 Client_ModeAdd( Client, 'o' );
971 if( ! IRC_WriteStrRelated( Client, "MODE %s :+o", Client_ID( Client ))) return DISCONNECTED;
972 IRC_WriteStrServersPrefix( NULL, Client, "MODE %s :+o", Client_ID( Client ));
975 if( ! Client_OperByMe( Client )) Log( LOG_NOTICE, "Got valid OPER from \"%s\", user is an IRC operator now.", Client_Mask( Client ));
977 Client_SetOperByMe( Client, TRUE );
978 return IRC_WriteStrClient( Client, RPL_YOUREOPER_MSG, Client_ID( Client ));
982 GLOBAL BOOLEAN IRC_DIE( CLIENT *Client, REQUEST *Req )
984 assert( Client != NULL );
985 assert( Req != NULL );
987 if( Client_Type( Client ) != CLIENT_USER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
989 /* Falsche Anzahl Parameter? */
990 if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
992 if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
994 Log( LOG_NOTICE, "Got DIE command from \"%s\", going down!", Client_Mask( Client ));
1000 GLOBAL BOOLEAN IRC_RESTART( CLIENT *Client, REQUEST *Req )
1002 assert( Client != NULL );
1003 assert( Req != NULL );
1005 if( Client_Type( Client ) != CLIENT_USER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
1007 /* Falsche Anzahl Parameter? */
1008 if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
1010 if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
1012 Log( LOG_NOTICE, "Got RESTART command from \"%s\", going down!", Client_Mask( Client ));
1013 NGIRCd_Restart = TRUE;
1018 GLOBAL BOOLEAN IRC_NAMES( CLIENT *Client, REQUEST *Req )
1020 CHAR rpl[COMMAND_LEN];
1023 assert( Client != NULL );
1024 assert( Req != NULL );
1026 if( Client_Type( Client ) != CLIENT_USER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
1028 /* Falsche Anzahl Parameter? */
1029 if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
1031 /* Noch alle User ausgeben, die in keinem Channel sind */
1033 c = Client_First( );
1036 if( Client_Type( c ) == CLIENT_USER )
1038 /* Okay, das ist ein User */
1039 strcat( rpl, Client_ID( c ));
1043 /* Antwort zu lang? Splitten. */
1044 if( strlen( rpl ) > 480 )
1046 if( rpl[strlen( rpl ) - 1] == ' ' ) rpl[strlen( rpl ) - 1] = '\0';
1047 if( ! IRC_WriteStrClient( Client, RPL_NAMREPLY_MSG, Client_ID( Client ), "*", "*", rpl )) return DISCONNECTED;
1051 c = Client_Next( c );
1055 /* es wurden User gefunden */
1056 if( rpl[strlen( rpl ) - 1] == ' ' ) rpl[strlen( rpl ) - 1] = '\0';
1057 if( ! IRC_WriteStrClient( Client, RPL_NAMREPLY_MSG, Client_ID( Client ), "*", "*", rpl )) return DISCONNECTED;
1059 return IRC_WriteStrClient( Client, RPL_ENDOFNAMES_MSG, Client_ID( Client ), "*" );
1063 GLOBAL BOOLEAN IRC_ISON( CLIENT *Client, REQUEST *Req )
1065 CHAR rpl[COMMAND_LEN];
1070 assert( Client != NULL );
1071 assert( Req != NULL );
1073 if( Client_Type( Client ) != CLIENT_USER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
1075 /* Falsche Anzahl Parameter? */
1076 if(( Req->argc < 1 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
1078 strcpy( rpl, RPL_ISON_MSG );
1079 for( i = 0; i < Req->argc; i++ )
1081 ptr = strtok( Req->argv[i], " " );
1085 c = Client_GetFromID( ptr );
1086 if( c && ( Client_Type( c ) == CLIENT_USER ))
1088 /* Dieser Nick ist "online" */
1092 ptr = strtok( NULL, " " );
1095 if( rpl[strlen( rpl ) - 1] == ' ' ) rpl[strlen( rpl ) - 1] = '\0';
1097 return IRC_WriteStrClient( Client, rpl, Client_ID( Client ) );
1101 GLOBAL BOOLEAN IRC_WHOIS( CLIENT *Client, REQUEST *Req )
1103 CLIENT *from, *target, *c;
1106 assert( Client != NULL );
1107 assert( Req != NULL );
1109 if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
1111 /* Falsche Anzahl Parameter? */
1112 if(( Req->argc < 1 ) || ( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
1115 c = Client_GetFromID( Req->argv[Req->argc - 1] );
1116 if(( ! c ) || ( Client_Type( c ) != CLIENT_USER )) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->argv[Req->argc - 1] );
1118 /* Empfaenger des WHOIS suchen */
1119 if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_GetFromID( Req->prefix );
1121 if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
1123 /* Forwarden an anderen Server? */
1126 /* angegebenen Ziel-Server suchen */
1127 target = Client_GetFromID( Req->argv[1] );
1128 if( ! target ) return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[1] );
1132 else if( Client_Conn( c ) == NONE )
1134 /* Client ist nicht von uns. Ziel-Server suchen */
1141 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 );
1143 /* Nick, User und Name */
1144 if( ! IRC_WriteStrClient( from, RPL_WHOISUSER_MSG, Client_ID( from ), Client_ID( c ), Client_User( c ), Client_Hostname( c ), Client_Info( c ))) return DISCONNECTED;
1147 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;
1150 if( Client_HasMode( c, 'o' ))
1152 if( ! IRC_WriteStrClient( from, RPL_WHOISOPERATOR_MSG, Client_ID( from ), Client_ID( c ))) return DISCONNECTED;
1155 /* Idle (nur lokale Clients) */
1156 if( Client_Conn( c ) > NONE )
1158 if( ! IRC_WriteStrClient( from, RPL_WHOISIDLE_MSG, Client_ID( from ), Client_ID( c ), Conn_GetIdle( Client_Conn ( c )))) return DISCONNECTED;
1162 return IRC_WriteStrClient( from, RPL_ENDOFWHOIS_MSG, Client_ID( from ), Client_ID( c ));
1166 GLOBAL BOOLEAN IRC_USERHOST( CLIENT *Client, REQUEST *Req )
1168 CHAR rpl[COMMAND_LEN];
1172 assert( Client != NULL );
1173 assert( Req != NULL );
1175 if( Client_Type( Client ) != CLIENT_USER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
1177 /* Falsche Anzahl Parameter? */
1178 if(( Req->argc < 1 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
1180 if( Req->argc > 5 ) max = 5;
1181 else max = Req->argc;
1183 strcpy( rpl, RPL_USERHOST_MSG );
1184 for( i = 0; i < max; i++ )
1186 c = Client_GetFromID( Req->argv[i] );
1187 if( c && ( Client_Type( c ) == CLIENT_USER ))
1189 /* Dieser Nick ist "online" */
1190 strcat( rpl, Client_ID( c ));
1191 if( Client_HasMode( c, 'o' )) strcat( rpl, "*" );
1193 if( Client_HasMode( c, 'a' )) strcat( rpl, "-" );
1194 else strcat( rpl, "+" );
1195 strcat( rpl, Client_User( c ));
1197 strcat( rpl, Client_Hostname( c ));
1201 if( rpl[strlen( rpl ) - 1] == ' ' ) rpl[strlen( rpl ) - 1] = '\0';
1203 return IRC_WriteStrClient( Client, rpl, Client_ID( Client ) );
1204 } /* IRC_USERHOST */
1207 GLOBAL BOOLEAN IRC_ERROR( CLIENT *Client, REQUEST *Req )
1209 assert( Client != NULL );
1210 assert( Req != NULL );
1212 if( Req->argc < 1 ) Log( LOG_NOTICE, "Got ERROR from \"%s\"!", Client_Mask( Client ));
1213 else Log( LOG_NOTICE, "Got ERROR from \"%s\": %s!", Client_Mask( Client ), Req->argv[0] );
1219 GLOBAL BOOLEAN IRC_LUSERS( CLIENT *Client, REQUEST *Req )
1221 assert( Client != NULL );
1222 assert( Req != NULL );
1224 if( Client_Type( Client ) != CLIENT_USER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
1226 /* Falsche Anzahl Parameter? */
1227 if(( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
1233 GLOBAL BOOLEAN IRC_LINKS( CLIENT *Client, REQUEST *Req )
1235 CLIENT *target, *from, *c;
1238 assert( Client != NULL );
1239 assert( Req != NULL );
1241 if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
1243 /* Falsche Anzahl Parameter? */
1244 if(( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
1246 /* Server-Mask ermitteln */
1247 if( Req->argc > 0 ) mask = Req->argv[Req->argc - 1];
1250 /* Absender ermitteln */
1251 if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_GetFromID( Req->prefix );
1253 if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
1255 /* An anderen Server forwarden? */
1256 if( Req->argc == 2 )
1258 target = Client_GetFromID( Req->argv[0] );
1259 if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[0] );
1260 else if( target != Client_ThisServer( )) return IRC_WriteStrClientPrefix( target, from, "LINKS %s %s", Req->argv[0], Req->argv[1] );
1263 /* Wer ist der Absender? */
1264 if( Client_Type( Client ) == CLIENT_SERVER ) target = Client_GetFromID( Req->prefix );
1265 else target = Client;
1266 if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
1268 c = Client_First( );
1271 if( Client_Type( c ) == CLIENT_SERVER )
1273 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;
1275 c = Client_Next( c );
1278 return IRC_WriteStrClient( target, RPL_ENDOFLINKS_MSG, Client_ID( target ), mask );
1282 LOCAL BOOLEAN Hello_User( CLIENT *Client )
1284 assert( Client != NULL );
1286 /* Passwort ueberpruefen */
1287 if( strcmp( Client_Password( Client ), Conf_ServerPwd ) != 0 )
1289 /* Falsches Passwort */
1290 Log( LOG_ERR, "User \"%s\" rejected (connection %d): Bad password!", Client_Mask( Client ), Client_Conn( Client ));
1291 Conn_Close( Client_Conn( Client ), NULL, "Bad password", TRUE );
1292 return DISCONNECTED;
1295 Log( LOG_NOTICE, "User \"%s\" registered (connection %d).", Client_Mask( Client ), Client_Conn( Client ));
1297 /* Andere Server informieren */
1298 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 ));
1300 if( ! IRC_WriteStrClient( Client, RPL_WELCOME_MSG, Client_ID( Client ), Client_Mask( Client ))) return FALSE;
1301 if( ! IRC_WriteStrClient( Client, RPL_YOURHOST_MSG, Client_ID( Client ), Client_ID( Client_ThisServer( )))) return FALSE;
1302 if( ! IRC_WriteStrClient( Client, RPL_CREATED_MSG, Client_ID( Client ), NGIRCd_StartStr )) return FALSE;
1303 if( ! IRC_WriteStrClient( Client, RPL_MYINFO_MSG, Client_ID( Client ), Client_ID( Client_ThisServer( )))) return FALSE;
1305 Client_SetType( Client, CLIENT_USER );
1307 return Show_MOTD( Client );
1311 LOCAL BOOLEAN Show_MOTD( CLIENT *Client )
1317 assert( Client != NULL );
1319 fd = fopen( Conf_MotdFile, "r" );
1322 Log( LOG_WARNING, "Can't read MOTD file \"%s\": %s", Conf_MotdFile, strerror( errno ));
1323 return IRC_WriteStrClient( Client, ERR_NOMOTD_MSG, Client_ID( Client ) );
1326 IRC_WriteStrClient( Client, RPL_MOTDSTART_MSG, Client_ID( Client ), Client_ID( Client_ThisServer( )));
1329 if( ! fgets( line, 126, fd )) break;
1330 if( line[strlen( line ) - 1] == '\n' ) line[strlen( line ) - 1] = '\0';
1331 if( ! IRC_WriteStrClient( Client, RPL_MOTD_MSG, Client_ID( Client ), line ))
1337 ok = IRC_WriteStrClient( Client, RPL_ENDOFMOTD_MSG, Client_ID( Client ) );
1345 LOCAL VOID Kill_Nick( CHAR *Nick )
1347 Log( LOG_ERR, "User(s) with nick \"%s\" will be disconnected!", Nick );
1349 Log( LOG_ALERT, "[Kill_Nick() not implemented - OOOPS!]" );