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.18 2002/01/02 02:44:36 alex Exp $
17 * Revision 1.18 2002/01/02 02:44:36 alex
18 * - neue Defines fuer max. Anzahl Server und Operatoren.
20 * Revision 1.17 2001/12/31 15:33:13 alex
21 * - neuer Befehl NAMES, kleinere Bugfixes.
22 * - Bug bei PING behoben: war zu restriktiv implementiert :-)
24 * Revision 1.16 2001/12/31 02:18:51 alex
25 * - viele neue Befehle (WHOIS, ISON, OPER, DIE, RESTART),
26 * - neuen Header "defines.h" mit (fast) allen Konstanten.
27 * - Code Cleanups und viele "kleine" Aenderungen & Bugfixes.
29 * Revision 1.15 2001/12/30 19:26:11 alex
30 * - Unterstuetzung fuer die Konfigurationsdatei eingebaut.
32 * Revision 1.14 2001/12/30 11:42:00 alex
33 * - der Server meldet nun eine ordentliche "Start-Zeit".
35 * Revision 1.13 2001/12/29 03:10:06 alex
36 * - Neue Funktion IRC_MODE() implementiert, div. Aenderungen.
37 * - neue configure-Optione "--enable-strict-rfc".
39 * Revision 1.12 2001/12/27 19:17:26 alex
40 * - neue Befehle PRIVMSG, NOTICE, PING.
42 * Revision 1.11 2001/12/27 16:55:41 alex
43 * - neu: IRC_WriteStrRelated(), Aenderungen auch in IRC_WriteStrClient().
45 * Revision 1.10 2001/12/26 22:48:53 alex
46 * - MOTD-Datei ist nun konfigurierbar und wird gelesen.
48 * Revision 1.9 2001/12/26 14:45:37 alex
51 * Revision 1.8 2001/12/26 03:21:46 alex
52 * - PING/PONG-Befehle implementiert,
53 * - Meldungen ueberarbeitet: enthalten nun (fast) immer den Nick.
55 * Revision 1.7 2001/12/25 23:25:18 alex
56 * - und nochmal Aenderungen am Logging ;-)
58 * Revision 1.6 2001/12/25 23:13:33 alex
59 * - Debug-Meldungen angepasst.
61 * Revision 1.5 2001/12/25 22:02:42 alex
62 * - neuer IRC-Befehl "/QUIT". Verbessertes Logging & Debug-Ausgaben.
64 * Revision 1.4 2001/12/25 19:19:30 alex
65 * - bessere Fehler-Abfragen, diverse Bugfixes.
66 * - Nicks werden nur einmal vergeben :-)
67 * - /MOTD wird unterstuetzt.
69 * Revision 1.3 2001/12/24 01:34:06 alex
70 * - USER und NICK wird nun in beliebiger Reihenfolge akzeptiert (wg. BitchX)
71 * - MOTD-Ausgabe begonnen zu implementieren.
73 * Revision 1.2 2001/12/23 21:57:16 alex
74 * - erste IRC-Befehle zu implementieren begonnen.
76 * Revision 1.1 2001/12/14 08:13:43 alex
77 * - neues Modul begonnen :-)
104 #define CONNECTED TRUE
105 #define DISCONNECTED FALSE
108 LOCAL BOOLEAN Check_Valid_User( CLIENT *Client );
110 LOCAL BOOLEAN Hello_User( CLIENT *Client );
111 LOCAL BOOLEAN Show_MOTD( CLIENT *Client );
114 GLOBAL VOID IRC_Init( VOID )
119 GLOBAL VOID IRC_Exit( VOID )
124 GLOBAL BOOLEAN IRC_WriteStrClient( CLIENT *Client, CLIENT *Prefix, CHAR *Format, ... )
126 /* Text an Clients, lokal bzw. remote, senden. */
129 BOOLEAN ok = CONNECTED;
133 assert( Client != NULL );
134 assert( Format != NULL );
136 va_start( ap, Format );
137 vsnprintf( buffer, 1000, Format, ap );
140 if( Client->conn_id != NONE ) send_to = Client->conn_id;
141 else send_to = Client->introducer->conn_id;
143 if( Prefix ) ok = Conn_WriteStr( Client->conn_id, ":%s %s", Client_GetID( Prefix ), buffer );
144 else ok = Conn_WriteStr( Client->conn_id, buffer );
147 } /* IRC_WriteStrClient */
150 GLOBAL BOOLEAN IRC_WriteStrRelated( CLIENT *Client, CHAR *Format, ... )
153 BOOLEAN ok = CONNECTED;
156 assert( Client != NULL );
157 assert( Format != NULL );
159 va_start( ap, Format );
160 vsnprintf( buffer, 1000, Format, ap );
163 /* an den Client selber */
164 ok = IRC_WriteStrClient( Client, Client, buffer );
167 } /* IRC_WriteStrRelated */
170 GLOBAL BOOLEAN IRC_PASS( CLIENT *Client, REQUEST *Req )
172 assert( Client != NULL );
173 assert( Req != NULL );
175 if( Client->type == CLIENT_UNKNOWN )
177 Log( LOG_DEBUG, "Connection %d: got PASS command ...", Client->conn_id );
178 return IRC_WriteStrClient( Client, This_Server, ERR_UNKNOWNCOMMAND_MSG, Client_Nick( Client ), Req->command );
180 else return IRC_WriteStrClient( Client, This_Server, ERR_ALREADYREGISTRED_MSG, Client_Nick( Client ));
184 GLOBAL BOOLEAN IRC_NICK( CLIENT *Client, REQUEST *Req )
186 assert( Client != NULL );
187 assert( Req != NULL );
189 /* Zumindest BitchX sendet NICK-USER in der falschen Reihenfolge. */
191 if( Client->type == CLIENT_UNKNOWN || Client->type == CLIENT_GOTPASS || Client->type == CLIENT_GOTNICK || Client->type == CLIENT_GOTUSER || Client->type == CLIENT_USER )
193 if( Client->type == CLIENT_UNKNOWN || Client->type == CLIENT_GOTPASS || Client->type == CLIENT_GOTNICK || Client->type == CLIENT_USER )
196 /* Falsche Anzahl Parameter? */
197 if( Req->argc != 1 ) return IRC_WriteStrClient( Client, This_Server, ERR_NEEDMOREPARAMS_MSG, Client_Nick( Client ), Req->command );
199 /* Ist der Client "restricted"? */
200 if( strchr( Client->modes, 'r' )) return IRC_WriteStrClient( Client, This_Server, ERR_RESTRICTED_MSG, Client_Nick( Client ));
202 /* Wenn der Client zu seinem eigenen Nick wechseln will, so machen
203 * wir nichts. So macht es das Original und mind. Snak hat probleme,
204 * wenn wir es nicht so machen. Ob es so okay ist? Hm ... */
206 if( strcasecmp( Client->nick, Req->argv[0] ) == 0 ) return CONNECTED;
209 /* pruefen, ob Nick bereits vergeben */
210 if( ! Client_CheckNick( Client, Req->argv[0] )) return CONNECTED;
212 if( Client->type == CLIENT_USER )
214 /* Nick-Aenderung: allen mitteilen! */
215 Log( LOG_INFO, "User \"%s!%s@%s\" changed nick: \"%s\" -> \"%s\".", Client->nick, Client->user, Client->host, Client->nick, Req->argv[0] );
216 IRC_WriteStrRelated( Client, "NICK :%s", Req->argv[0] );
219 /* Client-Nick registrieren */
220 strcpy( Client->nick, Req->argv[0] );
222 if( Client->type != CLIENT_USER )
225 Log( LOG_DEBUG, "Connection %d: got NICK command ...", Client->conn_id );
226 if( Client->type == CLIENT_GOTUSER ) return Hello_User( Client );
227 else Client->type = CLIENT_GOTNICK;
231 else return IRC_WriteStrClient( Client, This_Server, ERR_ALREADYREGISTRED_MSG, Client_Nick( Client ));
235 GLOBAL BOOLEAN IRC_USER( CLIENT *Client, REQUEST *Req )
237 assert( Client != NULL );
238 assert( Req != NULL );
241 if( Client->type == CLIENT_GOTNICK || Client->type == CLIENT_GOTPASS || Client->type == CLIENT_UNKNOWN )
243 if( Client->type == CLIENT_GOTNICK || Client->type == CLIENT_GOTPASS )
246 /* Falsche Anzahl Parameter? */
247 if( Req->argc != 4 ) return IRC_WriteStrClient( Client, This_Server, ERR_NEEDMOREPARAMS_MSG, Client_Nick( Client ), Req->command );
249 strncpy( Client->user, Req->argv[0], CLIENT_USER_LEN );
250 Client->user[CLIENT_USER_LEN - 1] = '\0';
251 strncpy( Client->name, Req->argv[3], CLIENT_NAME_LEN );
252 Client->name[CLIENT_NAME_LEN - 1] = '\0';
254 Log( LOG_DEBUG, "Connection %d: got USER command ...", Client->conn_id );
255 if( Client->type == CLIENT_GOTNICK ) return Hello_User( Client );
256 else Client->type = CLIENT_GOTUSER;
259 else if( Client->type == CLIENT_USER || Client->type == CLIENT_SERVER || Client->type == CLIENT_SERVICE )
261 return IRC_WriteStrClient( Client, This_Server, ERR_ALREADYREGISTRED_MSG, Client_Nick( Client ));
263 else return IRC_WriteStrClient( Client, This_Server, ERR_NOTREGISTERED_MSG, Client_Nick( Client ));
267 GLOBAL BOOLEAN IRC_QUIT( CLIENT *Client, REQUEST *Req )
269 assert( Client != NULL );
270 assert( Req != NULL );
272 if( Client->type != CLIENT_SERVER && Client->type != CLIENT_SERVICE )
274 /* Falsche Anzahl Parameter? */
275 if( Req->argc > 1 ) return IRC_WriteStrClient( Client, This_Server, ERR_NEEDMOREPARAMS_MSG, Client_Nick( Client ), Req->command );
277 Conn_Close( Client->conn_id, "Client wants to quit." );
280 else return IRC_WriteStrClient( Client, This_Server, ERR_NOTREGISTERED_MSG, Client_Nick( Client ));
284 GLOBAL BOOLEAN IRC_PING( CLIENT *Client, REQUEST *Req )
286 assert( Client != NULL );
287 assert( Req != NULL );
289 if( ! Check_Valid_User( Client )) return CONNECTED;
291 /* Falsche Anzahl Parameter? */
292 if( Req->argc < 1 ) return IRC_WriteStrClient( Client, This_Server, ERR_NOORIGIN_MSG, Client_Nick( Client ));
293 if( Req->argc > 1 ) return IRC_WriteStrClient( Client, This_Server, ERR_NEEDMOREPARAMS_MSG, Client_Nick( Client ), Req->command );
295 return IRC_WriteStrClient( Client, This_Server, "PONG %s :%s", Client_Nick( This_Server), Client_Nick( Client ));
299 GLOBAL BOOLEAN IRC_PONG( CLIENT *Client, REQUEST *Req )
301 assert( Client != NULL );
302 assert( Req != NULL );
304 if( ! Check_Valid_User( Client )) return CONNECTED;
306 /* Falsche Anzahl Parameter? */
307 if( Req->argc < 1 ) return IRC_WriteStrClient( Client, This_Server, ERR_NOORIGIN_MSG, Client_Nick( Client ));
308 if( Req->argc > 1 ) return IRC_WriteStrClient( Client, This_Server, ERR_NEEDMOREPARAMS_MSG, Client_Nick( Client ), Req->command );
310 /* Der Connection-Timestamp wurde schon beim Lesen aus dem Socket
311 * aktualisiert, daher muss das hier nicht mehr gemacht werden. */
313 Log( LOG_DEBUG, "Connection %d: received PONG.", Client->conn_id );
318 GLOBAL BOOLEAN IRC_MOTD( CLIENT *Client, REQUEST *Req )
320 assert( Client != NULL );
321 assert( Req != NULL );
323 if( ! Check_Valid_User( Client )) return CONNECTED;
325 /* Falsche Anzahl Parameter? */
326 if( Req->argc != 0 ) return IRC_WriteStrClient( Client, This_Server, ERR_NEEDMOREPARAMS_MSG, Client_Nick( Client ), Req->command );
328 return Show_MOTD( Client );
332 GLOBAL BOOLEAN IRC_PRIVMSG( CLIENT *Client, REQUEST *Req )
336 assert( Client != NULL );
337 assert( Req != NULL );
339 if( ! Check_Valid_User( Client )) return CONNECTED;
341 /* Falsche Anzahl Parameter? */
342 if( Req->argc == 0 ) return IRC_WriteStrClient( Client, This_Server, ERR_NORECIPIENT_MSG, Client_Nick( Client ), Req->command );
343 if( Req->argc == 1 ) return IRC_WriteStrClient( Client, This_Server, ERR_NOTEXTTOSEND_MSG, Client_Nick( Client ));
344 if( Req->argc > 2 ) return IRC_WriteStrClient( Client, This_Server, ERR_NEEDMOREPARAMS_MSG, Client_Nick( Client ), Req->command );
346 to = Client_Search( Req->argv[0] );
349 /* Okay, Ziel ist ein User */
350 if( Client->conn_id >= 0 ) Conn_UpdateIdle( Client->conn_id );
351 return IRC_WriteStrClient( to, Client, "PRIVMSG %s :%s", to->nick, Req->argv[1] );
354 return IRC_WriteStrClient( Client, This_Server, ERR_NOSUCHNICK_MSG, Client_Nick( Client ), Req->argv[0] );
358 GLOBAL BOOLEAN IRC_NOTICE( CLIENT *Client, REQUEST *Req )
362 assert( Client != NULL );
363 assert( Req != NULL );
365 if( ! Check_Valid_User( Client )) return CONNECTED;
367 /* Falsche Anzahl Parameter? */
368 if( Req->argc != 2 ) return CONNECTED;
370 to = Client_Search( Req->argv[0] );
373 /* Okay, Ziel ist ein User */
374 return IRC_WriteStrClient( to, Client, "NOTICE %s :%s", to->nick, Req->argv[1] );
381 GLOBAL BOOLEAN IRC_MODE( CLIENT *Client, REQUEST *Req )
383 CHAR x[2], new_modes[CLIENT_MODE_LEN], *ptr, *p;
386 assert( Client != NULL );
387 assert( Req != NULL );
389 if( ! Check_Valid_User( Client )) return CONNECTED;
391 /* Falsche Anzahl Parameter? */
392 if(( Req->argc > 2 ) || ( Req->argc < 1 )) return IRC_WriteStrClient( Client, This_Server, ERR_NEEDMOREPARAMS_MSG, Client_Nick( Client ), Req->command );
394 /* MODE ist nur fuer sich selber zulaessig */
395 if( Client_Search( Req->argv[0] ) != Client ) return IRC_WriteStrClient( Client, This_Server, ERR_USERSDONTMATCH_MSG, Client_Nick( Client ));
397 /* Werden die Modes erfragt? */
398 if( Req->argc == 1 ) return IRC_WriteStrClient( Client, This_Server, RPL_UMODEIS_MSG, Client_Nick( Client ), Client->modes );
402 /* Sollen Modes gesetzt oder geloescht werden? */
403 if( *ptr == '+' ) set = TRUE;
404 else if( *ptr == '-' ) set = FALSE;
405 else return IRC_WriteStrClient( Client, This_Server, ERR_UMODEUNKNOWNFLAG_MSG, Client_Nick( Client ));
407 /* Reply-String mit Aenderungen vorbereiten */
408 if( set ) strcpy( new_modes, "+" );
409 else strcpy( new_modes, "-" );
424 /* restricted (kann nur gesetzt werden) */
425 if( set ) x[0] = 'r';
426 else ok = IRC_WriteStrClient( Client, This_Server, ERR_RESTRICTED_MSG, Client_Nick( Client ));
429 /* operator (kann nur geloescht werden) */
432 Client->oper_by_me = FALSE;
435 else ok = IRC_WriteStrClient( Client, This_Server, ERR_UMODEUNKNOWNFLAG_MSG, Client_Nick( Client ));
438 ok = IRC_WriteStrClient( Client, This_Server, ERR_UMODEUNKNOWNFLAG_MSG, Client_Nick( Client ));
444 if( ! x[0] ) continue;
446 /* Okay, gueltigen Mode gefunden */
449 /* Modes sollen gesetzt werden */
450 if( ! strchr( Client->modes, x[0] ))
452 /* Client hat den Mode noch nicht -> setzen */
453 strcat( Client->modes, x );
454 strcat( new_modes, x );
459 /* Modes sollen geloescht werden */
460 p = strchr( Client->modes, x[0] );
463 /* Client hat den Mode -> loeschen */
469 strcat( new_modes, x );
474 /* Geanderte Modes? */
475 if( new_modes[1] && ok )
477 ok = IRC_WriteStrRelated( Client, "MODE %s :%s", Client->nick, new_modes );
478 Log( LOG_DEBUG, "User \"%s!%s@%s\": Mode change, now \"%s\".", Client->nick, Client->user, Client->host, Client->modes );
484 GLOBAL BOOLEAN IRC_OPER( CLIENT *Client, REQUEST *Req )
488 assert( Client != NULL );
489 assert( Req != NULL );
491 if( ! Check_Valid_User( Client )) return CONNECTED;
493 /* Falsche Anzahl Parameter? */
494 if( Req->argc != 2 ) return IRC_WriteStrClient( Client, This_Server, ERR_NEEDMOREPARAMS_MSG, Client_Nick( Client ), Req->command );
496 /* Operator suchen */
497 for( i = 0; i < Conf_Oper_Count; i++)
499 if( Conf_Oper[i].name[0] && Conf_Oper[i].pwd[0] && ( strcmp( Conf_Oper[i].name, Req->argv[0] ) == 0 )) break;
501 if( i >= Conf_Oper_Count ) return IRC_WriteStrClient( Client, This_Server, ERR_PASSWDMISMATCH_MSG, Client_Nick( Client ));
503 /* Stimmt der Name und das Passwort? */
504 if(( strcmp( Conf_Oper[i].name, Req->argv[0] ) != 0 ) || ( strcmp( Conf_Oper[i].pwd, Req->argv[1] ) != 0 )) return IRC_WriteStrClient( Client, This_Server, ERR_PASSWDMISMATCH_MSG, Client_Nick( Client ));
506 if( ! strchr( Client->modes, 'o' ))
508 /* noch kein o-Mode gesetzt */
509 strcat( Client->modes, "o" );
510 if( ! IRC_WriteStrRelated( Client, "MODE %s :+o", Client->nick )) return DISCONNECTED;
513 if( ! Client->oper_by_me ) Log( LOG_NOTICE, "User \"%s!%s@%s\" is now an IRC Operator.", Client->nick, Client->user, Client->host );
515 Client->oper_by_me = TRUE;
516 return IRC_WriteStrClient( Client, This_Server, RPL_YOUREOPER_MSG, Client_Nick( Client ));
520 GLOBAL BOOLEAN IRC_DIE( CLIENT *Client, REQUEST *Req )
522 assert( Client != NULL );
523 assert( Req != NULL );
525 if( ! Check_Valid_User( Client )) return CONNECTED;
527 /* Falsche Anzahl Parameter? */
528 if( Req->argc != 0 ) return IRC_WriteStrClient( Client, This_Server, ERR_NEEDMOREPARAMS_MSG, Client_Nick( Client ), Req->command );
530 if(( ! strchr( Client->modes, 'o' )) || ( ! Client->oper_by_me )) return IRC_WriteStrClient( Client, This_Server, ERR_NOPRIVILEGES_MSG, Client_Nick( Client ));
532 Log( LOG_NOTICE, "Got DIE command from \"%s!%s@%s\", going down!", Client->nick, Client->user, Client->host );
538 GLOBAL BOOLEAN IRC_RESTART( CLIENT *Client, REQUEST *Req )
540 assert( Client != NULL );
541 assert( Req != NULL );
543 if( ! Check_Valid_User( Client )) return CONNECTED;
545 /* Falsche Anzahl Parameter? */
546 if( Req->argc != 0 ) return IRC_WriteStrClient( Client, This_Server, ERR_NEEDMOREPARAMS_MSG, Client_Nick( Client ), Req->command );
548 if(( ! strchr( Client->modes, 'o' )) || ( ! Client->oper_by_me )) return IRC_WriteStrClient( Client, This_Server, ERR_NOPRIVILEGES_MSG, Client_Nick( Client ));
550 Log( LOG_NOTICE, "Got RESTART command from \"%s!%s@%s\", going down!", Client->nick, Client->user, Client->host );
551 NGIRCd_Restart = TRUE;
556 GLOBAL BOOLEAN IRC_NAMES( CLIENT *Client, REQUEST *Req )
558 CHAR rpl[COMMAND_LEN];
561 assert( Client != NULL );
562 assert( Req != NULL );
564 if( ! Check_Valid_User( Client )) return CONNECTED;
566 /* Falsche Anzahl Parameter? */
567 if( Req->argc != 0 ) return IRC_WriteStrClient( Client, This_Server, ERR_NEEDMOREPARAMS_MSG, Client_Nick( Client ), Req->command );
569 /* Noch alle User ausgeben, die in keinem Channel sind */
574 if( c->type == CLIENT_USER )
576 /* Okay, das ist ein User */
577 strcat( rpl, Client_Nick( c ));
581 /* Antwort zu lang? Splitten. */
582 if( strlen( rpl ) > 480 )
584 if( rpl[strlen( rpl ) - 1] == ' ' ) rpl[strlen( rpl ) - 1] = '\0';
585 if( ! IRC_WriteStrClient( Client, This_Server, RPL_NAMREPLY_MSG, Client_Nick( Client ), "*", "*", rpl )) return DISCONNECTED;
589 c = Client_Next( c );
593 /* es wurden User gefunden */
594 if( rpl[strlen( rpl ) - 1] == ' ' ) rpl[strlen( rpl ) - 1] = '\0';
595 if( ! IRC_WriteStrClient( Client, This_Server, RPL_NAMREPLY_MSG, Client_Nick( Client ), "*", "*", rpl )) return DISCONNECTED;
597 return IRC_WriteStrClient( Client, This_Server, RPL_ENDOFNAMES_MSG, Client_Nick( Client ), "*" );
601 GLOBAL BOOLEAN IRC_ISON( CLIENT *Client, REQUEST *Req )
603 CHAR rpl[COMMAND_LEN];
608 assert( Client != NULL );
609 assert( Req != NULL );
611 if( ! Check_Valid_User( Client )) return CONNECTED;
613 /* Falsche Anzahl Parameter? */
614 if(( Req->argc < 1 )) return IRC_WriteStrClient( Client, This_Server, ERR_NEEDMOREPARAMS_MSG, Client_Nick( Client ), Req->command );
616 strcpy( rpl, RPL_ISON_MSG );
617 for( i = 0; i < Req->argc; i++ )
619 ptr = strtok( Req->argv[i], " " );
623 c = Client_GetFromNick( ptr );
624 if( c && ( c->type == CLIENT_USER ))
626 /* Dieser Nick ist "online" */
630 ptr = strtok( NULL, " " );
633 if( rpl[strlen( rpl ) - 1] == ' ' ) rpl[strlen( rpl ) - 1] = '\0';
635 return IRC_WriteStrClient( Client, This_Server, rpl, Client->nick );
639 GLOBAL BOOLEAN IRC_WHOIS( CLIENT *Client, REQUEST *Req )
643 assert( Client != NULL );
644 assert( Req != NULL );
646 if( ! Check_Valid_User( Client )) return CONNECTED;
648 /* Falsche Anzahl Parameter? */
649 if(( Req->argc < 1 ) || ( Req->argc > 2 )) return IRC_WriteStrClient( Client, This_Server, ERR_NEEDMOREPARAMS_MSG, Client_Nick( Client ), Req->command );
652 c = Client_GetFromNick( Req->argv[0] );
653 if(( ! c ) || ( c->type != CLIENT_USER )) return IRC_WriteStrClient( Client, This_Server, ERR_NOSUCHNICK_MSG, Client_Nick( Client ), Req->argv[0] );
655 /* Nick, User und Name */
656 if( ! IRC_WriteStrClient( Client, This_Server, RPL_WHOISUSER_MSG, Client_Nick( Client ), c->nick, c->user, c->host, c->name )) return DISCONNECTED;
659 if( ! IRC_WriteStrClient( Client, This_Server, RPL_WHOISSERVER_MSG, Client_Nick( Client ), c->nick, c->introducer->nick, c->introducer->info )) return DISCONNECTED;
662 if( strchr( c->modes, 'o' ))
664 if( ! IRC_WriteStrClient( Client, This_Server, RPL_WHOISOPERATOR_MSG, Client_Nick( Client ), c->nick )) return DISCONNECTED;
667 /* Idle (nur lokale Clients) */
668 if( c->conn_id >= 0 )
670 if( ! IRC_WriteStrClient( Client, This_Server, RPL_WHOISIDLE_MSG, Client_Nick( Client ), c->nick, Conn_GetIdle( c->conn_id ))) return DISCONNECTED;
674 return IRC_WriteStrClient( Client, This_Server, RPL_ENDOFWHOIS_MSG, Client_Nick( Client ), c->nick );
678 GLOBAL BOOLEAN IRC_USERHOST( CLIENT *Client, REQUEST *Req )
680 CHAR rpl[COMMAND_LEN];
684 assert( Client != NULL );
685 assert( Req != NULL );
687 if( ! Check_Valid_User( Client )) return CONNECTED;
689 /* Falsche Anzahl Parameter? */
690 if(( Req->argc < 1 )) return IRC_WriteStrClient( Client, This_Server, ERR_NEEDMOREPARAMS_MSG, Client_Nick( Client ), Req->command );
692 if( Req->argc > 5 ) max = 5;
693 else max = Req->argc;
695 strcpy( rpl, RPL_USERHOST_MSG );
696 for( i = 0; i < max; i++ )
698 c = Client_GetFromNick( Req->argv[i] );
699 if( c && ( c->type == CLIENT_USER ))
701 /* Dieser Nick ist "online" */
702 strcat( rpl, c->nick );
703 if( strchr( c->modes, 'o' )) strcat( rpl, "*" );
705 if( strchr( c->modes, 'a' )) strcat( rpl, "-" );
706 else strcat( rpl, "+" );
707 strcat( rpl, c->user );
709 strcat( rpl, c->host );
713 if( rpl[strlen( rpl ) - 1] == ' ' ) rpl[strlen( rpl ) - 1] = '\0';
715 return IRC_WriteStrClient( Client, This_Server, rpl, Client->nick );
719 GLOBAL BOOLEAN IRC_ERROR( CLIENT *Client, REQUEST *Req )
721 assert( Client != NULL );
722 assert( Req != NULL );
724 if( Req->argc < 1 ) Log( LOG_NOTICE, "Got ERROR from \"%s!%s@%s\"!", Client_Nick( Client ), Client->user, Client->host );
725 else Log( LOG_NOTICE, "Got ERROR from \"%s!%s@%s\": %s!", Client_Nick( Client ), Client->user, Client->host, Req->argv[0] );
731 LOCAL BOOLEAN Check_Valid_User( CLIENT *Client )
733 assert( Client != NULL );
735 if( Client->type != CLIENT_USER )
737 IRC_WriteStrClient( Client, This_Server, ERR_NOTREGISTERED_MSG, Client_Nick( Client ));
741 } /* Check_Valid_User */
744 LOCAL BOOLEAN Hello_User( CLIENT *Client )
746 assert( Client != NULL );
747 assert( Client->nick[0] );
749 Log( LOG_NOTICE, "User \"%s!%s@%s\" (%s) registered (connection %d).", Client->nick, Client->user, Client->host, Client->name, Client->conn_id );
751 IRC_WriteStrClient( Client, This_Server, RPL_WELCOME_MSG, Client->nick, Client_GetID( Client ));
752 IRC_WriteStrClient( Client, This_Server, RPL_YOURHOST_MSG, Client->nick, This_Server->nick );
753 IRC_WriteStrClient( Client, This_Server, RPL_CREATED_MSG, Client->nick, NGIRCd_StartStr );
754 IRC_WriteStrClient( Client, This_Server, RPL_MYINFO_MSG, Client->nick, This_Server->nick );
756 Client->type = CLIENT_USER;
758 return Show_MOTD( Client );
762 LOCAL BOOLEAN Show_MOTD( CLIENT *Client )
768 assert( Client != NULL );
769 assert( Client->nick[0] );
771 fd = fopen( Conf_MotdFile, "r" );
774 Log( LOG_WARNING, "Can't read MOTD file \"%s\": %s", Conf_MotdFile, strerror( errno ));
775 return IRC_WriteStrClient( Client, This_Server, ERR_NOMOTD_MSG, Client->nick );
778 IRC_WriteStrClient( Client, This_Server, RPL_MOTDSTART_MSG, Client->nick, This_Server->nick );
781 if( ! fgets( line, 126, fd )) break;
782 if( line[strlen( line ) - 1] == '\n' ) line[strlen( line ) - 1] = '\0';
783 IRC_WriteStrClient( Client, This_Server, RPL_MOTD_MSG, Client->nick, line );
785 ok = IRC_WriteStrClient( Client, This_Server, RPL_ENDOFMOTD_MSG, Client->nick );