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.20 2002/01/02 12:46:41 alex Exp $
17 * Revision 1.20 2002/01/02 12:46:41 alex
18 * - die Gross- und Kleinschreibung des Nicks kann mit NICK nun geaendert werden.
20 * Revision 1.19 2002/01/02 02:51:39 alex
21 * - Copyright-Texte angepasst.
22 * - neuer Befehl "ERROR".
24 * Revision 1.17 2001/12/31 15:33:13 alex
25 * - neuer Befehl NAMES, kleinere Bugfixes.
26 * - Bug bei PING behoben: war zu restriktiv implementiert :-)
28 * Revision 1.16 2001/12/31 02:18:51 alex
29 * - viele neue Befehle (WHOIS, ISON, OPER, DIE, RESTART),
30 * - neuen Header "defines.h" mit (fast) allen Konstanten.
31 * - Code Cleanups und viele "kleine" Aenderungen & Bugfixes.
33 * Revision 1.15 2001/12/30 19:26:11 alex
34 * - Unterstuetzung fuer die Konfigurationsdatei eingebaut.
36 * Revision 1.14 2001/12/30 11:42:00 alex
37 * - der Server meldet nun eine ordentliche "Start-Zeit".
39 * Revision 1.13 2001/12/29 03:10:06 alex
40 * - Neue Funktion IRC_MODE() implementiert, div. Aenderungen.
41 * - neue configure-Optione "--enable-strict-rfc".
43 * Revision 1.12 2001/12/27 19:17:26 alex
44 * - neue Befehle PRIVMSG, NOTICE, PING.
46 * Revision 1.11 2001/12/27 16:55:41 alex
47 * - neu: IRC_WriteStrRelated(), Aenderungen auch in IRC_WriteStrClient().
49 * Revision 1.10 2001/12/26 22:48:53 alex
50 * - MOTD-Datei ist nun konfigurierbar und wird gelesen.
52 * Revision 1.9 2001/12/26 14:45:37 alex
55 * Revision 1.8 2001/12/26 03:21:46 alex
56 * - PING/PONG-Befehle implementiert,
57 * - Meldungen ueberarbeitet: enthalten nun (fast) immer den Nick.
59 * Revision 1.7 2001/12/25 23:25:18 alex
60 * - und nochmal Aenderungen am Logging ;-)
62 * Revision 1.6 2001/12/25 23:13:33 alex
63 * - Debug-Meldungen angepasst.
65 * Revision 1.5 2001/12/25 22:02:42 alex
66 * - neuer IRC-Befehl "/QUIT". Verbessertes Logging & Debug-Ausgaben.
68 * Revision 1.4 2001/12/25 19:19:30 alex
69 * - bessere Fehler-Abfragen, diverse Bugfixes.
70 * - Nicks werden nur einmal vergeben :-)
71 * - /MOTD wird unterstuetzt.
73 * Revision 1.3 2001/12/24 01:34:06 alex
74 * - USER und NICK wird nun in beliebiger Reihenfolge akzeptiert (wg. BitchX)
75 * - MOTD-Ausgabe begonnen zu implementieren.
77 * Revision 1.2 2001/12/23 21:57:16 alex
78 * - erste IRC-Befehle zu implementieren begonnen.
80 * Revision 1.1 2001/12/14 08:13:43 alex
81 * - neues Modul begonnen :-)
100 #include "messages.h"
108 #define CONNECTED TRUE
109 #define DISCONNECTED FALSE
112 LOCAL BOOLEAN Check_Valid_User( CLIENT *Client );
114 LOCAL BOOLEAN Hello_User( CLIENT *Client );
115 LOCAL BOOLEAN Show_MOTD( CLIENT *Client );
118 GLOBAL VOID IRC_Init( VOID )
123 GLOBAL VOID IRC_Exit( VOID )
128 GLOBAL BOOLEAN IRC_WriteStrClient( CLIENT *Client, CLIENT *Prefix, CHAR *Format, ... )
130 /* Text an Clients, lokal bzw. remote, senden. */
133 BOOLEAN ok = CONNECTED;
137 assert( Client != NULL );
138 assert( Format != NULL );
140 va_start( ap, Format );
141 vsnprintf( buffer, 1000, Format, ap );
144 if( Client->conn_id != NONE ) send_to = Client->conn_id;
145 else send_to = Client->introducer->conn_id;
147 if( Prefix ) ok = Conn_WriteStr( Client->conn_id, ":%s %s", Client_GetID( Prefix ), buffer );
148 else ok = Conn_WriteStr( Client->conn_id, buffer );
151 } /* IRC_WriteStrClient */
154 GLOBAL BOOLEAN IRC_WriteStrRelated( CLIENT *Client, CHAR *Format, ... )
157 BOOLEAN ok = CONNECTED;
160 assert( Client != NULL );
161 assert( Format != NULL );
163 va_start( ap, Format );
164 vsnprintf( buffer, 1000, Format, ap );
167 /* an den Client selber */
168 ok = IRC_WriteStrClient( Client, Client, buffer );
171 } /* IRC_WriteStrRelated */
174 GLOBAL BOOLEAN IRC_PASS( CLIENT *Client, REQUEST *Req )
176 assert( Client != NULL );
177 assert( Req != NULL );
179 if( Client->type == CLIENT_UNKNOWN )
181 Log( LOG_DEBUG, "Connection %d: got PASS command ...", Client->conn_id );
182 return IRC_WriteStrClient( Client, This_Server, ERR_UNKNOWNCOMMAND_MSG, Client_Nick( Client ), Req->command );
184 else return IRC_WriteStrClient( Client, This_Server, ERR_ALREADYREGISTRED_MSG, Client_Nick( Client ));
188 GLOBAL BOOLEAN IRC_NICK( CLIENT *Client, REQUEST *Req )
190 assert( Client != NULL );
191 assert( Req != NULL );
193 /* Zumindest BitchX sendet NICK-USER in der falschen Reihenfolge. */
195 if( Client->type == CLIENT_UNKNOWN || Client->type == CLIENT_GOTPASS || Client->type == CLIENT_GOTNICK || Client->type == CLIENT_GOTUSER || Client->type == CLIENT_USER )
197 if( Client->type == CLIENT_UNKNOWN || Client->type == CLIENT_GOTPASS || Client->type == CLIENT_GOTNICK || Client->type == CLIENT_USER )
200 /* Falsche Anzahl Parameter? */
201 if( Req->argc != 1 ) return IRC_WriteStrClient( Client, This_Server, ERR_NEEDMOREPARAMS_MSG, Client_Nick( Client ), Req->command );
203 /* Ist der Client "restricted"? */
204 if( strchr( Client->modes, 'r' )) return IRC_WriteStrClient( Client, This_Server, ERR_RESTRICTED_MSG, Client_Nick( Client ));
206 /* Wenn der Client zu seinem eigenen Nick wechseln will, so machen
207 * wir nichts. So macht es das Original und mind. Snak hat probleme,
208 * wenn wir es nicht so machen. Ob es so okay ist? Hm ... */
210 if( strcmp( Client->nick, Req->argv[0] ) == 0 ) return CONNECTED;
213 /* pruefen, ob Nick bereits vergeben. Speziallfall: der Client
214 * will nur die Gross- und Kleinschreibung aendern. Das darf
215 * er natuerlich machen :-) */
216 if( strcasecmp( Client->nick, Req->argv[0] ) != 0 )
218 if( ! Client_CheckNick( Client, Req->argv[0] )) return CONNECTED;
221 if( Client->type == CLIENT_USER )
223 /* Nick-Aenderung: allen mitteilen! */
224 Log( LOG_INFO, "User \"%s!%s@%s\" changed nick: \"%s\" -> \"%s\".", Client->nick, Client->user, Client->host, Client->nick, Req->argv[0] );
225 IRC_WriteStrRelated( Client, "NICK :%s", Req->argv[0] );
228 /* Client-Nick registrieren */
229 strcpy( Client->nick, Req->argv[0] );
231 if( Client->type != CLIENT_USER )
234 Log( LOG_DEBUG, "Connection %d: got NICK command ...", Client->conn_id );
235 if( Client->type == CLIENT_GOTUSER ) return Hello_User( Client );
236 else Client->type = CLIENT_GOTNICK;
240 else return IRC_WriteStrClient( Client, This_Server, ERR_ALREADYREGISTRED_MSG, Client_Nick( Client ));
244 GLOBAL BOOLEAN IRC_USER( CLIENT *Client, REQUEST *Req )
246 assert( Client != NULL );
247 assert( Req != NULL );
250 if( Client->type == CLIENT_GOTNICK || Client->type == CLIENT_GOTPASS || Client->type == CLIENT_UNKNOWN )
252 if( Client->type == CLIENT_GOTNICK || Client->type == CLIENT_GOTPASS )
255 /* Falsche Anzahl Parameter? */
256 if( Req->argc != 4 ) return IRC_WriteStrClient( Client, This_Server, ERR_NEEDMOREPARAMS_MSG, Client_Nick( Client ), Req->command );
258 strncpy( Client->user, Req->argv[0], CLIENT_USER_LEN );
259 Client->user[CLIENT_USER_LEN - 1] = '\0';
260 strncpy( Client->name, Req->argv[3], CLIENT_NAME_LEN );
261 Client->name[CLIENT_NAME_LEN - 1] = '\0';
263 Log( LOG_DEBUG, "Connection %d: got USER command ...", Client->conn_id );
264 if( Client->type == CLIENT_GOTNICK ) return Hello_User( Client );
265 else Client->type = CLIENT_GOTUSER;
268 else if( Client->type == CLIENT_USER || Client->type == CLIENT_SERVER || Client->type == CLIENT_SERVICE )
270 return IRC_WriteStrClient( Client, This_Server, ERR_ALREADYREGISTRED_MSG, Client_Nick( Client ));
272 else return IRC_WriteStrClient( Client, This_Server, ERR_NOTREGISTERED_MSG, Client_Nick( Client ));
276 GLOBAL BOOLEAN IRC_QUIT( CLIENT *Client, REQUEST *Req )
278 assert( Client != NULL );
279 assert( Req != NULL );
281 if( Client->type != CLIENT_SERVER && Client->type != CLIENT_SERVICE )
283 /* Falsche Anzahl Parameter? */
284 if( Req->argc > 1 ) return IRC_WriteStrClient( Client, This_Server, ERR_NEEDMOREPARAMS_MSG, Client_Nick( Client ), Req->command );
286 Conn_Close( Client->conn_id, "Client wants to quit." );
289 else return IRC_WriteStrClient( Client, This_Server, ERR_NOTREGISTERED_MSG, Client_Nick( Client ));
293 GLOBAL BOOLEAN IRC_PING( CLIENT *Client, REQUEST *Req )
295 assert( Client != NULL );
296 assert( Req != NULL );
298 if( ! Check_Valid_User( Client )) return CONNECTED;
300 /* Falsche Anzahl Parameter? */
301 if( Req->argc < 1 ) return IRC_WriteStrClient( Client, This_Server, ERR_NOORIGIN_MSG, Client_Nick( Client ));
302 if( Req->argc > 1 ) return IRC_WriteStrClient( Client, This_Server, ERR_NEEDMOREPARAMS_MSG, Client_Nick( Client ), Req->command );
304 return IRC_WriteStrClient( Client, This_Server, "PONG %s :%s", Client_Nick( This_Server), Client_Nick( Client ));
308 GLOBAL BOOLEAN IRC_PONG( CLIENT *Client, REQUEST *Req )
310 assert( Client != NULL );
311 assert( Req != NULL );
313 if( ! Check_Valid_User( Client )) return CONNECTED;
315 /* Falsche Anzahl Parameter? */
316 if( Req->argc < 1 ) return IRC_WriteStrClient( Client, This_Server, ERR_NOORIGIN_MSG, Client_Nick( Client ));
317 if( Req->argc > 1 ) return IRC_WriteStrClient( Client, This_Server, ERR_NEEDMOREPARAMS_MSG, Client_Nick( Client ), Req->command );
319 /* Der Connection-Timestamp wurde schon beim Lesen aus dem Socket
320 * aktualisiert, daher muss das hier nicht mehr gemacht werden. */
322 Log( LOG_DEBUG, "Connection %d: received PONG.", Client->conn_id );
327 GLOBAL BOOLEAN IRC_MOTD( CLIENT *Client, REQUEST *Req )
329 assert( Client != NULL );
330 assert( Req != NULL );
332 if( ! Check_Valid_User( Client )) return CONNECTED;
334 /* Falsche Anzahl Parameter? */
335 if( Req->argc != 0 ) return IRC_WriteStrClient( Client, This_Server, ERR_NEEDMOREPARAMS_MSG, Client_Nick( Client ), Req->command );
337 return Show_MOTD( Client );
341 GLOBAL BOOLEAN IRC_PRIVMSG( CLIENT *Client, REQUEST *Req )
345 assert( Client != NULL );
346 assert( Req != NULL );
348 if( ! Check_Valid_User( Client )) return CONNECTED;
350 /* Falsche Anzahl Parameter? */
351 if( Req->argc == 0 ) return IRC_WriteStrClient( Client, This_Server, ERR_NORECIPIENT_MSG, Client_Nick( Client ), Req->command );
352 if( Req->argc == 1 ) return IRC_WriteStrClient( Client, This_Server, ERR_NOTEXTTOSEND_MSG, Client_Nick( Client ));
353 if( Req->argc > 2 ) return IRC_WriteStrClient( Client, This_Server, ERR_NEEDMOREPARAMS_MSG, Client_Nick( Client ), Req->command );
355 to = Client_Search( Req->argv[0] );
358 /* Okay, Ziel ist ein User */
359 if( Client->conn_id >= 0 ) Conn_UpdateIdle( Client->conn_id );
360 return IRC_WriteStrClient( to, Client, "PRIVMSG %s :%s", to->nick, Req->argv[1] );
363 return IRC_WriteStrClient( Client, This_Server, ERR_NOSUCHNICK_MSG, Client_Nick( Client ), Req->argv[0] );
367 GLOBAL BOOLEAN IRC_NOTICE( CLIENT *Client, REQUEST *Req )
371 assert( Client != NULL );
372 assert( Req != NULL );
374 if( ! Check_Valid_User( Client )) return CONNECTED;
376 /* Falsche Anzahl Parameter? */
377 if( Req->argc != 2 ) return CONNECTED;
379 to = Client_Search( Req->argv[0] );
382 /* Okay, Ziel ist ein User */
383 return IRC_WriteStrClient( to, Client, "NOTICE %s :%s", to->nick, Req->argv[1] );
390 GLOBAL BOOLEAN IRC_MODE( CLIENT *Client, REQUEST *Req )
392 CHAR x[2], new_modes[CLIENT_MODE_LEN], *ptr, *p;
395 assert( Client != NULL );
396 assert( Req != NULL );
398 if( ! Check_Valid_User( Client )) return CONNECTED;
400 /* Falsche Anzahl Parameter? */
401 if(( Req->argc > 2 ) || ( Req->argc < 1 )) return IRC_WriteStrClient( Client, This_Server, ERR_NEEDMOREPARAMS_MSG, Client_Nick( Client ), Req->command );
403 /* MODE ist nur fuer sich selber zulaessig */
404 if( Client_Search( Req->argv[0] ) != Client ) return IRC_WriteStrClient( Client, This_Server, ERR_USERSDONTMATCH_MSG, Client_Nick( Client ));
406 /* Werden die Modes erfragt? */
407 if( Req->argc == 1 ) return IRC_WriteStrClient( Client, This_Server, RPL_UMODEIS_MSG, Client_Nick( Client ), Client->modes );
411 /* Sollen Modes gesetzt oder geloescht werden? */
412 if( *ptr == '+' ) set = TRUE;
413 else if( *ptr == '-' ) set = FALSE;
414 else return IRC_WriteStrClient( Client, This_Server, ERR_UMODEUNKNOWNFLAG_MSG, Client_Nick( Client ));
416 /* Reply-String mit Aenderungen vorbereiten */
417 if( set ) strcpy( new_modes, "+" );
418 else strcpy( new_modes, "-" );
433 /* restricted (kann nur gesetzt werden) */
434 if( set ) x[0] = 'r';
435 else ok = IRC_WriteStrClient( Client, This_Server, ERR_RESTRICTED_MSG, Client_Nick( Client ));
438 /* operator (kann nur geloescht werden) */
441 Client->oper_by_me = FALSE;
444 else ok = IRC_WriteStrClient( Client, This_Server, ERR_UMODEUNKNOWNFLAG_MSG, Client_Nick( Client ));
447 ok = IRC_WriteStrClient( Client, This_Server, ERR_UMODEUNKNOWNFLAG_MSG, Client_Nick( Client ));
453 if( ! x[0] ) continue;
455 /* Okay, gueltigen Mode gefunden */
458 /* Modes sollen gesetzt werden */
459 if( ! strchr( Client->modes, x[0] ))
461 /* Client hat den Mode noch nicht -> setzen */
462 strcat( Client->modes, x );
463 strcat( new_modes, x );
468 /* Modes sollen geloescht werden */
469 p = strchr( Client->modes, x[0] );
472 /* Client hat den Mode -> loeschen */
478 strcat( new_modes, x );
483 /* Geanderte Modes? */
484 if( new_modes[1] && ok )
486 ok = IRC_WriteStrRelated( Client, "MODE %s :%s", Client->nick, new_modes );
487 Log( LOG_DEBUG, "User \"%s!%s@%s\": Mode change, now \"%s\".", Client->nick, Client->user, Client->host, Client->modes );
493 GLOBAL BOOLEAN IRC_OPER( CLIENT *Client, REQUEST *Req )
497 assert( Client != NULL );
498 assert( Req != NULL );
500 if( ! Check_Valid_User( Client )) return CONNECTED;
502 /* Falsche Anzahl Parameter? */
503 if( Req->argc != 2 ) return IRC_WriteStrClient( Client, This_Server, ERR_NEEDMOREPARAMS_MSG, Client_Nick( Client ), Req->command );
505 /* Operator suchen */
506 for( i = 0; i < Conf_Oper_Count; i++)
508 if( Conf_Oper[i].name[0] && Conf_Oper[i].pwd[0] && ( strcmp( Conf_Oper[i].name, Req->argv[0] ) == 0 )) break;
510 if( i >= Conf_Oper_Count ) return IRC_WriteStrClient( Client, This_Server, ERR_PASSWDMISMATCH_MSG, Client_Nick( Client ));
512 /* Stimmt der Name und das Passwort? */
513 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 ));
515 if( ! strchr( Client->modes, 'o' ))
517 /* noch kein o-Mode gesetzt */
518 strcat( Client->modes, "o" );
519 if( ! IRC_WriteStrRelated( Client, "MODE %s :+o", Client->nick )) return DISCONNECTED;
522 if( ! Client->oper_by_me ) Log( LOG_NOTICE, "User \"%s!%s@%s\" is now an IRC Operator.", Client->nick, Client->user, Client->host );
524 Client->oper_by_me = TRUE;
525 return IRC_WriteStrClient( Client, This_Server, RPL_YOUREOPER_MSG, Client_Nick( Client ));
529 GLOBAL BOOLEAN IRC_DIE( CLIENT *Client, REQUEST *Req )
531 assert( Client != NULL );
532 assert( Req != NULL );
534 if( ! Check_Valid_User( Client )) return CONNECTED;
536 /* Falsche Anzahl Parameter? */
537 if( Req->argc != 0 ) return IRC_WriteStrClient( Client, This_Server, ERR_NEEDMOREPARAMS_MSG, Client_Nick( Client ), Req->command );
539 if(( ! strchr( Client->modes, 'o' )) || ( ! Client->oper_by_me )) return IRC_WriteStrClient( Client, This_Server, ERR_NOPRIVILEGES_MSG, Client_Nick( Client ));
541 Log( LOG_NOTICE, "Got DIE command from \"%s!%s@%s\", going down!", Client->nick, Client->user, Client->host );
547 GLOBAL BOOLEAN IRC_RESTART( CLIENT *Client, REQUEST *Req )
549 assert( Client != NULL );
550 assert( Req != NULL );
552 if( ! Check_Valid_User( Client )) return CONNECTED;
554 /* Falsche Anzahl Parameter? */
555 if( Req->argc != 0 ) return IRC_WriteStrClient( Client, This_Server, ERR_NEEDMOREPARAMS_MSG, Client_Nick( Client ), Req->command );
557 if(( ! strchr( Client->modes, 'o' )) || ( ! Client->oper_by_me )) return IRC_WriteStrClient( Client, This_Server, ERR_NOPRIVILEGES_MSG, Client_Nick( Client ));
559 Log( LOG_NOTICE, "Got RESTART command from \"%s!%s@%s\", going down!", Client->nick, Client->user, Client->host );
560 NGIRCd_Restart = TRUE;
565 GLOBAL BOOLEAN IRC_NAMES( CLIENT *Client, REQUEST *Req )
567 CHAR rpl[COMMAND_LEN];
570 assert( Client != NULL );
571 assert( Req != NULL );
573 if( ! Check_Valid_User( Client )) return CONNECTED;
575 /* Falsche Anzahl Parameter? */
576 if( Req->argc != 0 ) return IRC_WriteStrClient( Client, This_Server, ERR_NEEDMOREPARAMS_MSG, Client_Nick( Client ), Req->command );
578 /* Noch alle User ausgeben, die in keinem Channel sind */
583 if( c->type == CLIENT_USER )
585 /* Okay, das ist ein User */
586 strcat( rpl, Client_Nick( c ));
590 /* Antwort zu lang? Splitten. */
591 if( strlen( rpl ) > 480 )
593 if( rpl[strlen( rpl ) - 1] == ' ' ) rpl[strlen( rpl ) - 1] = '\0';
594 if( ! IRC_WriteStrClient( Client, This_Server, RPL_NAMREPLY_MSG, Client_Nick( Client ), "*", "*", rpl )) return DISCONNECTED;
598 c = Client_Next( c );
602 /* es wurden User gefunden */
603 if( rpl[strlen( rpl ) - 1] == ' ' ) rpl[strlen( rpl ) - 1] = '\0';
604 if( ! IRC_WriteStrClient( Client, This_Server, RPL_NAMREPLY_MSG, Client_Nick( Client ), "*", "*", rpl )) return DISCONNECTED;
606 return IRC_WriteStrClient( Client, This_Server, RPL_ENDOFNAMES_MSG, Client_Nick( Client ), "*" );
610 GLOBAL BOOLEAN IRC_ISON( CLIENT *Client, REQUEST *Req )
612 CHAR rpl[COMMAND_LEN];
617 assert( Client != NULL );
618 assert( Req != NULL );
620 if( ! Check_Valid_User( Client )) return CONNECTED;
622 /* Falsche Anzahl Parameter? */
623 if(( Req->argc < 1 )) return IRC_WriteStrClient( Client, This_Server, ERR_NEEDMOREPARAMS_MSG, Client_Nick( Client ), Req->command );
625 strcpy( rpl, RPL_ISON_MSG );
626 for( i = 0; i < Req->argc; i++ )
628 ptr = strtok( Req->argv[i], " " );
632 c = Client_GetFromNick( ptr );
633 if( c && ( c->type == CLIENT_USER ))
635 /* Dieser Nick ist "online" */
639 ptr = strtok( NULL, " " );
642 if( rpl[strlen( rpl ) - 1] == ' ' ) rpl[strlen( rpl ) - 1] = '\0';
644 return IRC_WriteStrClient( Client, This_Server, rpl, Client->nick );
648 GLOBAL BOOLEAN IRC_WHOIS( CLIENT *Client, REQUEST *Req )
652 assert( Client != NULL );
653 assert( Req != NULL );
655 if( ! Check_Valid_User( Client )) return CONNECTED;
657 /* Falsche Anzahl Parameter? */
658 if(( Req->argc < 1 ) || ( Req->argc > 2 )) return IRC_WriteStrClient( Client, This_Server, ERR_NEEDMOREPARAMS_MSG, Client_Nick( Client ), Req->command );
661 c = Client_GetFromNick( Req->argv[0] );
662 if(( ! c ) || ( c->type != CLIENT_USER )) return IRC_WriteStrClient( Client, This_Server, ERR_NOSUCHNICK_MSG, Client_Nick( Client ), Req->argv[0] );
664 /* Nick, User und Name */
665 if( ! IRC_WriteStrClient( Client, This_Server, RPL_WHOISUSER_MSG, Client_Nick( Client ), c->nick, c->user, c->host, c->name )) return DISCONNECTED;
668 if( ! IRC_WriteStrClient( Client, This_Server, RPL_WHOISSERVER_MSG, Client_Nick( Client ), c->nick, c->introducer->nick, c->introducer->info )) return DISCONNECTED;
671 if( strchr( c->modes, 'o' ))
673 if( ! IRC_WriteStrClient( Client, This_Server, RPL_WHOISOPERATOR_MSG, Client_Nick( Client ), c->nick )) return DISCONNECTED;
676 /* Idle (nur lokale Clients) */
677 if( c->conn_id >= 0 )
679 if( ! IRC_WriteStrClient( Client, This_Server, RPL_WHOISIDLE_MSG, Client_Nick( Client ), c->nick, Conn_GetIdle( c->conn_id ))) return DISCONNECTED;
683 return IRC_WriteStrClient( Client, This_Server, RPL_ENDOFWHOIS_MSG, Client_Nick( Client ), c->nick );
687 GLOBAL BOOLEAN IRC_USERHOST( CLIENT *Client, REQUEST *Req )
689 CHAR rpl[COMMAND_LEN];
693 assert( Client != NULL );
694 assert( Req != NULL );
696 if( ! Check_Valid_User( Client )) return CONNECTED;
698 /* Falsche Anzahl Parameter? */
699 if(( Req->argc < 1 )) return IRC_WriteStrClient( Client, This_Server, ERR_NEEDMOREPARAMS_MSG, Client_Nick( Client ), Req->command );
701 if( Req->argc > 5 ) max = 5;
702 else max = Req->argc;
704 strcpy( rpl, RPL_USERHOST_MSG );
705 for( i = 0; i < max; i++ )
707 c = Client_GetFromNick( Req->argv[i] );
708 if( c && ( c->type == CLIENT_USER ))
710 /* Dieser Nick ist "online" */
711 strcat( rpl, c->nick );
712 if( strchr( c->modes, 'o' )) strcat( rpl, "*" );
714 if( strchr( c->modes, 'a' )) strcat( rpl, "-" );
715 else strcat( rpl, "+" );
716 strcat( rpl, c->user );
718 strcat( rpl, c->host );
722 if( rpl[strlen( rpl ) - 1] == ' ' ) rpl[strlen( rpl ) - 1] = '\0';
724 return IRC_WriteStrClient( Client, This_Server, rpl, Client->nick );
728 GLOBAL BOOLEAN IRC_ERROR( CLIENT *Client, REQUEST *Req )
730 assert( Client != NULL );
731 assert( Req != NULL );
733 if( Req->argc < 1 ) Log( LOG_NOTICE, "Got ERROR from \"%s!%s@%s\"!", Client_Nick( Client ), Client->user, Client->host );
734 else Log( LOG_NOTICE, "Got ERROR from \"%s!%s@%s\": %s!", Client_Nick( Client ), Client->user, Client->host, Req->argv[0] );
740 LOCAL BOOLEAN Check_Valid_User( CLIENT *Client )
742 assert( Client != NULL );
744 if( Client->type != CLIENT_USER )
746 IRC_WriteStrClient( Client, This_Server, ERR_NOTREGISTERED_MSG, Client_Nick( Client ));
750 } /* Check_Valid_User */
753 LOCAL BOOLEAN Hello_User( CLIENT *Client )
755 assert( Client != NULL );
756 assert( Client->nick[0] );
758 Log( LOG_NOTICE, "User \"%s!%s@%s\" (%s) registered (connection %d).", Client->nick, Client->user, Client->host, Client->name, Client->conn_id );
760 IRC_WriteStrClient( Client, This_Server, RPL_WELCOME_MSG, Client->nick, Client_GetID( Client ));
761 IRC_WriteStrClient( Client, This_Server, RPL_YOURHOST_MSG, Client->nick, This_Server->nick );
762 IRC_WriteStrClient( Client, This_Server, RPL_CREATED_MSG, Client->nick, NGIRCd_StartStr );
763 IRC_WriteStrClient( Client, This_Server, RPL_MYINFO_MSG, Client->nick, This_Server->nick );
765 Client->type = CLIENT_USER;
767 return Show_MOTD( Client );
771 LOCAL BOOLEAN Show_MOTD( CLIENT *Client )
777 assert( Client != NULL );
778 assert( Client->nick[0] );
780 fd = fopen( Conf_MotdFile, "r" );
783 Log( LOG_WARNING, "Can't read MOTD file \"%s\": %s", Conf_MotdFile, strerror( errno ));
784 return IRC_WriteStrClient( Client, This_Server, ERR_NOMOTD_MSG, Client->nick );
787 IRC_WriteStrClient( Client, This_Server, RPL_MOTDSTART_MSG, Client->nick, This_Server->nick );
790 if( ! fgets( line, 126, fd )) break;
791 if( line[strlen( line ) - 1] == '\n' ) line[strlen( line ) - 1] = '\0';
792 IRC_WriteStrClient( Client, This_Server, RPL_MOTD_MSG, Client->nick, line );
794 ok = IRC_WriteStrClient( Client, This_Server, RPL_ENDOFMOTD_MSG, Client->nick );