2 * ngIRCd -- The Next Generation IRC Daemon
3 * Copyright (c)2001 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.17 2001/12/31 15:33:13 alex Exp $
17 * Revision 1.17 2001/12/31 15:33:13 alex
18 * - neuer Befehl NAMES, kleinere Bugfixes.
19 * - Bug bei PING behoben: war zu restriktiv implementiert :-)
21 * Revision 1.16 2001/12/31 02:18:51 alex
22 * - viele neue Befehle (WHOIS, ISON, OPER, DIE, RESTART),
23 * - neuen Header "defines.h" mit (fast) allen Konstanten.
24 * - Code Cleanups und viele "kleine" Aenderungen & Bugfixes.
26 * Revision 1.15 2001/12/30 19:26:11 alex
27 * - Unterstuetzung fuer die Konfigurationsdatei eingebaut.
29 * Revision 1.14 2001/12/30 11:42:00 alex
30 * - der Server meldet nun eine ordentliche "Start-Zeit".
32 * Revision 1.13 2001/12/29 03:10:06 alex
33 * - Neue Funktion IRC_MODE() implementiert, div. Aenderungen.
34 * - neue configure-Optione "--enable-strict-rfc".
36 * Revision 1.12 2001/12/27 19:17:26 alex
37 * - neue Befehle PRIVMSG, NOTICE, PING.
39 * Revision 1.11 2001/12/27 16:55:41 alex
40 * - neu: IRC_WriteStrRelated(), Aenderungen auch in IRC_WriteStrClient().
42 * Revision 1.10 2001/12/26 22:48:53 alex
43 * - MOTD-Datei ist nun konfigurierbar und wird gelesen.
45 * Revision 1.9 2001/12/26 14:45:37 alex
48 * Revision 1.8 2001/12/26 03:21:46 alex
49 * - PING/PONG-Befehle implementiert,
50 * - Meldungen ueberarbeitet: enthalten nun (fast) immer den Nick.
52 * Revision 1.7 2001/12/25 23:25:18 alex
53 * - und nochmal Aenderungen am Logging ;-)
55 * Revision 1.6 2001/12/25 23:13:33 alex
56 * - Debug-Meldungen angepasst.
58 * Revision 1.5 2001/12/25 22:02:42 alex
59 * - neuer IRC-Befehl "/QUIT". Verbessertes Logging & Debug-Ausgaben.
61 * Revision 1.4 2001/12/25 19:19:30 alex
62 * - bessere Fehler-Abfragen, diverse Bugfixes.
63 * - Nicks werden nur einmal vergeben :-)
64 * - /MOTD wird unterstuetzt.
66 * Revision 1.3 2001/12/24 01:34:06 alex
67 * - USER und NICK wird nun in beliebiger Reihenfolge akzeptiert (wg. BitchX)
68 * - MOTD-Ausgabe begonnen zu implementieren.
70 * Revision 1.2 2001/12/23 21:57:16 alex
71 * - erste IRC-Befehle zu implementieren begonnen.
73 * Revision 1.1 2001/12/14 08:13:43 alex
74 * - neues Modul begonnen :-)
101 #define CONNECTED TRUE
102 #define DISCONNECTED FALSE
105 LOCAL BOOLEAN Check_Valid_User( CLIENT *Client );
107 LOCAL BOOLEAN Hello_User( CLIENT *Client );
108 LOCAL BOOLEAN Show_MOTD( CLIENT *Client );
111 GLOBAL VOID IRC_Init( VOID )
116 GLOBAL VOID IRC_Exit( VOID )
121 GLOBAL BOOLEAN IRC_WriteStrClient( CLIENT *Client, CLIENT *Prefix, CHAR *Format, ... )
123 /* Text an Clients, lokal bzw. remote, senden. */
126 BOOLEAN ok = CONNECTED;
130 assert( Client != NULL );
131 assert( Format != NULL );
133 va_start( ap, Format );
134 vsnprintf( buffer, 1000, Format, ap );
137 if( Client->conn_id != NONE ) send_to = Client->conn_id;
138 else send_to = Client->introducer->conn_id;
140 if( Prefix ) ok = Conn_WriteStr( Client->conn_id, ":%s %s", Client_GetID( Prefix ), buffer );
141 else ok = Conn_WriteStr( Client->conn_id, buffer );
144 } /* IRC_WriteStrClient */
147 GLOBAL BOOLEAN IRC_WriteStrRelated( CLIENT *Client, CHAR *Format, ... )
150 BOOLEAN ok = CONNECTED;
153 assert( Client != NULL );
154 assert( Format != NULL );
156 va_start( ap, Format );
157 vsnprintf( buffer, 1000, Format, ap );
160 /* an den Client selber */
161 ok = IRC_WriteStrClient( Client, Client, buffer );
164 } /* IRC_WriteStrRelated */
167 GLOBAL BOOLEAN IRC_PASS( CLIENT *Client, REQUEST *Req )
169 assert( Client != NULL );
170 assert( Req != NULL );
172 if( Client->type == CLIENT_UNKNOWN )
174 Log( LOG_DEBUG, "Connection %d: got PASS command ...", Client->conn_id );
175 return IRC_WriteStrClient( Client, This_Server, ERR_UNKNOWNCOMMAND_MSG, Client_Nick( Client ), Req->command );
177 else return IRC_WriteStrClient( Client, This_Server, ERR_ALREADYREGISTRED_MSG, Client_Nick( Client ));
181 GLOBAL BOOLEAN IRC_NICK( CLIENT *Client, REQUEST *Req )
183 assert( Client != NULL );
184 assert( Req != NULL );
186 /* Zumindest BitchX sendet NICK-USER in der falschen Reihenfolge. */
188 if( Client->type == CLIENT_UNKNOWN || Client->type == CLIENT_GOTPASS || Client->type == CLIENT_GOTNICK || Client->type == CLIENT_GOTUSER || Client->type == CLIENT_USER )
190 if( Client->type == CLIENT_UNKNOWN || Client->type == CLIENT_GOTPASS || Client->type == CLIENT_GOTNICK || Client->type == CLIENT_USER )
193 /* Falsche Anzahl Parameter? */
194 if( Req->argc != 1 ) return IRC_WriteStrClient( Client, This_Server, ERR_NEEDMOREPARAMS_MSG, Client_Nick( Client ), Req->command );
196 /* Ist der Client "restricted"? */
197 if( strchr( Client->modes, 'r' )) return IRC_WriteStrClient( Client, This_Server, ERR_RESTRICTED_MSG, Client_Nick( Client ));
199 /* Wenn der Client zu seinem eigenen Nick wechseln will, so machen
200 * wir nichts. So macht es das Original und mind. Snak hat probleme,
201 * wenn wir es nicht so machen. Ob es so okay ist? Hm ... */
203 if( strcasecmp( Client->nick, Req->argv[0] ) == 0 ) return CONNECTED;
206 /* pruefen, ob Nick bereits vergeben */
207 if( ! Client_CheckNick( Client, Req->argv[0] )) return CONNECTED;
209 if( Client->type == CLIENT_USER )
211 /* Nick-Aenderung: allen mitteilen! */
212 Log( LOG_INFO, "User \"%s!%s@%s\" changed nick: \"%s\" -> \"%s\".", Client->nick, Client->user, Client->host, Client->nick, Req->argv[0] );
213 IRC_WriteStrRelated( Client, "NICK :%s", Req->argv[0] );
216 /* Client-Nick registrieren */
217 strcpy( Client->nick, Req->argv[0] );
219 if( Client->type != CLIENT_USER )
222 Log( LOG_DEBUG, "Connection %d: got NICK command ...", Client->conn_id );
223 if( Client->type == CLIENT_GOTUSER ) return Hello_User( Client );
224 else Client->type = CLIENT_GOTNICK;
228 else return IRC_WriteStrClient( Client, This_Server, ERR_ALREADYREGISTRED_MSG, Client_Nick( Client ));
232 GLOBAL BOOLEAN IRC_USER( CLIENT *Client, REQUEST *Req )
234 assert( Client != NULL );
235 assert( Req != NULL );
238 if( Client->type == CLIENT_GOTNICK || Client->type == CLIENT_GOTPASS || Client->type == CLIENT_UNKNOWN )
240 if( Client->type == CLIENT_GOTNICK || Client->type == CLIENT_GOTPASS )
243 /* Falsche Anzahl Parameter? */
244 if( Req->argc != 4 ) return IRC_WriteStrClient( Client, This_Server, ERR_NEEDMOREPARAMS_MSG, Client_Nick( Client ), Req->command );
246 strncpy( Client->user, Req->argv[0], CLIENT_USER_LEN );
247 Client->user[CLIENT_USER_LEN - 1] = '\0';
248 strncpy( Client->name, Req->argv[3], CLIENT_NAME_LEN );
249 Client->name[CLIENT_NAME_LEN - 1] = '\0';
251 Log( LOG_DEBUG, "Connection %d: got USER command ...", Client->conn_id );
252 if( Client->type == CLIENT_GOTNICK ) return Hello_User( Client );
253 else Client->type = CLIENT_GOTUSER;
256 else if( Client->type == CLIENT_USER || Client->type == CLIENT_SERVER || Client->type == CLIENT_SERVICE )
258 return IRC_WriteStrClient( Client, This_Server, ERR_ALREADYREGISTRED_MSG, Client_Nick( Client ));
260 else return IRC_WriteStrClient( Client, This_Server, ERR_NOTREGISTERED_MSG, Client_Nick( Client ));
264 GLOBAL BOOLEAN IRC_QUIT( CLIENT *Client, REQUEST *Req )
266 assert( Client != NULL );
267 assert( Req != NULL );
269 if( Client->type != CLIENT_SERVER && Client->type != CLIENT_SERVICE )
271 /* Falsche Anzahl Parameter? */
272 if( Req->argc > 1 ) return IRC_WriteStrClient( Client, This_Server, ERR_NEEDMOREPARAMS_MSG, Client_Nick( Client ), Req->command );
274 Conn_Close( Client->conn_id, "Client wants to quit." );
277 else return IRC_WriteStrClient( Client, This_Server, ERR_NOTREGISTERED_MSG, Client_Nick( Client ));
281 GLOBAL BOOLEAN IRC_PING( CLIENT *Client, REQUEST *Req )
283 assert( Client != NULL );
284 assert( Req != NULL );
286 if( ! Check_Valid_User( Client )) return CONNECTED;
288 /* Falsche Anzahl Parameter? */
289 if( Req->argc < 1 ) return IRC_WriteStrClient( Client, This_Server, ERR_NOORIGIN_MSG, Client_Nick( Client ));
290 if( Req->argc > 1 ) return IRC_WriteStrClient( Client, This_Server, ERR_NEEDMOREPARAMS_MSG, Client_Nick( Client ), Req->command );
292 return IRC_WriteStrClient( Client, This_Server, "PONG %s :%s", Client_Nick( This_Server), Client_Nick( Client ));
296 GLOBAL BOOLEAN IRC_PONG( CLIENT *Client, REQUEST *Req )
298 assert( Client != NULL );
299 assert( Req != NULL );
301 if( ! Check_Valid_User( Client )) return CONNECTED;
303 /* Falsche Anzahl Parameter? */
304 if( Req->argc < 1 ) return IRC_WriteStrClient( Client, This_Server, ERR_NOORIGIN_MSG, Client_Nick( Client ));
305 if( Req->argc > 1 ) return IRC_WriteStrClient( Client, This_Server, ERR_NEEDMOREPARAMS_MSG, Client_Nick( Client ), Req->command );
307 /* Der Connection-Timestamp wurde schon beim Lesen aus dem Socket
308 * aktualisiert, daher muss das hier nicht mehr gemacht werden. */
310 Log( LOG_DEBUG, "Connection %d: received PONG.", Client->conn_id );
315 GLOBAL BOOLEAN IRC_MOTD( CLIENT *Client, REQUEST *Req )
317 assert( Client != NULL );
318 assert( Req != NULL );
320 if( ! Check_Valid_User( Client )) return CONNECTED;
322 /* Falsche Anzahl Parameter? */
323 if( Req->argc != 0 ) return IRC_WriteStrClient( Client, This_Server, ERR_NEEDMOREPARAMS_MSG, Client_Nick( Client ), Req->command );
325 return Show_MOTD( Client );
329 GLOBAL BOOLEAN IRC_PRIVMSG( CLIENT *Client, REQUEST *Req )
333 assert( Client != NULL );
334 assert( Req != NULL );
336 if( ! Check_Valid_User( Client )) return CONNECTED;
338 /* Falsche Anzahl Parameter? */
339 if( Req->argc == 0 ) return IRC_WriteStrClient( Client, This_Server, ERR_NORECIPIENT_MSG, Client_Nick( Client ), Req->command );
340 if( Req->argc == 1 ) return IRC_WriteStrClient( Client, This_Server, ERR_NOTEXTTOSEND_MSG, Client_Nick( Client ));
341 if( Req->argc > 2 ) return IRC_WriteStrClient( Client, This_Server, ERR_NEEDMOREPARAMS_MSG, Client_Nick( Client ), Req->command );
343 to = Client_Search( Req->argv[0] );
346 /* Okay, Ziel ist ein User */
347 if( Client->conn_id >= 0 ) Conn_UpdateIdle( Client->conn_id );
348 return IRC_WriteStrClient( to, Client, "PRIVMSG %s :%s", to->nick, Req->argv[1] );
351 return IRC_WriteStrClient( Client, This_Server, ERR_NOSUCHNICK_MSG, Client_Nick( Client ), Req->argv[0] );
355 GLOBAL BOOLEAN IRC_NOTICE( CLIENT *Client, REQUEST *Req )
359 assert( Client != NULL );
360 assert( Req != NULL );
362 if( ! Check_Valid_User( Client )) return CONNECTED;
364 /* Falsche Anzahl Parameter? */
365 if( Req->argc != 2 ) return CONNECTED;
367 to = Client_Search( Req->argv[0] );
370 /* Okay, Ziel ist ein User */
371 return IRC_WriteStrClient( to, Client, "NOTICE %s :%s", to->nick, Req->argv[1] );
378 GLOBAL BOOLEAN IRC_MODE( CLIENT *Client, REQUEST *Req )
380 CHAR x[2], new_modes[CLIENT_MODE_LEN], *ptr, *p;
383 assert( Client != NULL );
384 assert( Req != NULL );
386 if( ! Check_Valid_User( Client )) return CONNECTED;
388 /* Falsche Anzahl Parameter? */
389 if(( Req->argc > 2 ) || ( Req->argc < 1 )) return IRC_WriteStrClient( Client, This_Server, ERR_NEEDMOREPARAMS_MSG, Client_Nick( Client ), Req->command );
391 /* MODE ist nur fuer sich selber zulaessig */
392 if( Client_Search( Req->argv[0] ) != Client ) return IRC_WriteStrClient( Client, This_Server, ERR_USERSDONTMATCH_MSG, Client_Nick( Client ));
394 /* Werden die Modes erfragt? */
395 if( Req->argc == 1 ) return IRC_WriteStrClient( Client, This_Server, RPL_UMODEIS_MSG, Client_Nick( Client ), Client->modes );
399 /* Sollen Modes gesetzt oder geloescht werden? */
400 if( *ptr == '+' ) set = TRUE;
401 else if( *ptr == '-' ) set = FALSE;
402 else return IRC_WriteStrClient( Client, This_Server, ERR_UMODEUNKNOWNFLAG_MSG, Client_Nick( Client ));
404 /* Reply-String mit Aenderungen vorbereiten */
405 if( set ) strcpy( new_modes, "+" );
406 else strcpy( new_modes, "-" );
421 /* restricted (kann nur gesetzt werden) */
422 if( set ) x[0] = 'r';
423 else ok = IRC_WriteStrClient( Client, This_Server, ERR_RESTRICTED_MSG, Client_Nick( Client ));
426 /* operator (kann nur geloescht werden) */
429 Client->oper_by_me = FALSE;
432 else ok = IRC_WriteStrClient( Client, This_Server, ERR_UMODEUNKNOWNFLAG_MSG, Client_Nick( Client ));
435 ok = IRC_WriteStrClient( Client, This_Server, ERR_UMODEUNKNOWNFLAG_MSG, Client_Nick( Client ));
441 if( ! x[0] ) continue;
443 /* Okay, gueltigen Mode gefunden */
446 /* Modes sollen gesetzt werden */
447 if( ! strchr( Client->modes, x[0] ))
449 /* Client hat den Mode noch nicht -> setzen */
450 strcat( Client->modes, x );
451 strcat( new_modes, x );
456 /* Modes sollen geloescht werden */
457 p = strchr( Client->modes, x[0] );
460 /* Client hat den Mode -> loeschen */
466 strcat( new_modes, x );
471 /* Geanderte Modes? */
472 if( new_modes[1] && ok )
474 ok = IRC_WriteStrRelated( Client, "MODE %s :%s", Client->nick, new_modes );
475 Log( LOG_DEBUG, "User \"%s!%s@%s\": Mode change, now \"%s\".", Client->nick, Client->user, Client->host, Client->modes );
481 GLOBAL BOOLEAN IRC_OPER( CLIENT *Client, REQUEST *Req )
483 assert( Client != NULL );
484 assert( Req != NULL );
486 if( ! Check_Valid_User( Client )) return CONNECTED;
488 /* Falsche Anzahl Parameter? */
489 if( Req->argc != 2 ) return IRC_WriteStrClient( Client, This_Server, ERR_NEEDMOREPARAMS_MSG, Client_Nick( Client ), Req->command );
491 /* Ist ueberhaupt ein Operator gesetzt? */
492 if(( ! Conf_Oper[0] ) || ( ! Conf_OperPwd[0] )) return IRC_WriteStrClient( Client, This_Server, ERR_PASSWDMISMATCH_MSG, Client_Nick( Client ));
494 /* Stimmt der Name und das Passwort? */
495 if(( strcmp( Conf_Oper, Req->argv[0] ) != 0 ) || ( strcmp( Conf_OperPwd, Req->argv[1] ) != 0 )) return IRC_WriteStrClient( Client, This_Server, ERR_PASSWDMISMATCH_MSG, Client_Nick( Client ));
497 if( ! strchr( Client->modes, 'o' ))
499 /* noch kein o-Mode gesetzt */
500 strcat( Client->modes, "o" );
501 if( ! IRC_WriteStrRelated( Client, "MODE %s :+o", Client->nick )) return DISCONNECTED;
504 if( ! Client->oper_by_me ) Log( LOG_NOTICE, "User \"%s!%s@%s\" is now an IRC Operator.", Client->nick, Client->user, Client->host );
506 Client->oper_by_me = TRUE;
507 return IRC_WriteStrClient( Client, This_Server, RPL_YOUREOPER_MSG, Client_Nick( Client ));
511 GLOBAL BOOLEAN IRC_DIE( CLIENT *Client, REQUEST *Req )
513 assert( Client != NULL );
514 assert( Req != NULL );
516 if( ! Check_Valid_User( Client )) return CONNECTED;
518 /* Falsche Anzahl Parameter? */
519 if( Req->argc != 0 ) return IRC_WriteStrClient( Client, This_Server, ERR_NEEDMOREPARAMS_MSG, Client_Nick( Client ), Req->command );
521 if(( ! strchr( Client->modes, 'o' )) || ( ! Client->oper_by_me )) return IRC_WriteStrClient( Client, This_Server, ERR_NOPRIVILEGES_MSG, Client_Nick( Client ));
523 Log( LOG_NOTICE, "Got DIE command from \"%s!%s@%s\", going down!", Client->nick, Client->user, Client->host );
529 GLOBAL BOOLEAN IRC_RESTART( 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 RESTART command from \"%s!%s@%s\", going down!", Client->nick, Client->user, Client->host );
542 NGIRCd_Restart = TRUE;
547 GLOBAL BOOLEAN IRC_NAMES( CLIENT *Client, REQUEST *Req )
549 CHAR rpl[COMMAND_LEN];
552 assert( Client != NULL );
553 assert( Req != NULL );
555 if( ! Check_Valid_User( Client )) return CONNECTED;
557 /* Falsche Anzahl Parameter? */
558 if( Req->argc != 0 ) return IRC_WriteStrClient( Client, This_Server, ERR_NEEDMOREPARAMS_MSG, Client_Nick( Client ), Req->command );
560 /* Noch alle User ausgeben, die in keinem Channel sind */
565 if( c->type == CLIENT_USER )
567 /* Okay, das ist ein User */
568 strcat( rpl, Client_Nick( c ));
572 /* Antwort zu lang? Splitten. */
573 if( strlen( rpl ) > 480 )
575 if( rpl[strlen( rpl ) - 1] == ' ' ) rpl[strlen( rpl ) - 1] = '\0';
576 if( ! IRC_WriteStrClient( Client, This_Server, RPL_NAMREPLY_MSG, Client_Nick( Client ), "*", "*", rpl )) return DISCONNECTED;
580 c = Client_Next( c );
584 /* es wurden User gefunden */
585 if( rpl[strlen( rpl ) - 1] == ' ' ) rpl[strlen( rpl ) - 1] = '\0';
586 if( ! IRC_WriteStrClient( Client, This_Server, RPL_NAMREPLY_MSG, Client_Nick( Client ), "*", "*", rpl )) return DISCONNECTED;
588 return IRC_WriteStrClient( Client, This_Server, RPL_ENDOFNAMES_MSG, Client_Nick( Client ), "*" );
592 GLOBAL BOOLEAN IRC_ISON( CLIENT *Client, REQUEST *Req )
594 CHAR rpl[COMMAND_LEN];
599 assert( Client != NULL );
600 assert( Req != NULL );
602 if( ! Check_Valid_User( Client )) return CONNECTED;
604 /* Falsche Anzahl Parameter? */
605 if(( Req->argc < 1 )) return IRC_WriteStrClient( Client, This_Server, ERR_NEEDMOREPARAMS_MSG, Client_Nick( Client ), Req->command );
607 strcpy( rpl, RPL_ISON_MSG );
608 for( i = 0; i < Req->argc; i++ )
610 ptr = strtok( Req->argv[i], " " );
614 c = Client_GetFromNick( ptr );
615 if( c && ( c->type == CLIENT_USER ))
617 /* Dieser Nick ist "online" */
621 ptr = strtok( NULL, " " );
624 if( rpl[strlen( rpl ) - 1] == ' ' ) rpl[strlen( rpl ) - 1] = '\0';
626 return IRC_WriteStrClient( Client, This_Server, rpl, Client->nick );
630 GLOBAL BOOLEAN IRC_WHOIS( CLIENT *Client, REQUEST *Req )
634 assert( Client != NULL );
635 assert( Req != NULL );
637 if( ! Check_Valid_User( Client )) return CONNECTED;
639 /* Falsche Anzahl Parameter? */
640 if(( Req->argc < 1 ) || ( Req->argc > 2 )) return IRC_WriteStrClient( Client, This_Server, ERR_NEEDMOREPARAMS_MSG, Client_Nick( Client ), Req->command );
643 c = Client_GetFromNick( Req->argv[0] );
644 if(( ! c ) || ( c->type != CLIENT_USER )) return IRC_WriteStrClient( Client, This_Server, ERR_NOSUCHNICK_MSG, Client_Nick( Client ), Req->argv[0] );
646 /* Nick, User und Name */
647 if( ! IRC_WriteStrClient( Client, This_Server, RPL_WHOISUSER_MSG, Client_Nick( Client ), c->nick, c->user, c->host, c->name )) return DISCONNECTED;
650 if( ! IRC_WriteStrClient( Client, This_Server, RPL_WHOISSERVER_MSG, Client_Nick( Client ), c->nick, c->introducer->nick, c->introducer->info )) return DISCONNECTED;
653 if( strchr( c->modes, 'o' ))
655 if( ! IRC_WriteStrClient( Client, This_Server, RPL_WHOISOPERATOR_MSG, Client_Nick( Client ), c->nick )) return DISCONNECTED;
658 /* Idle (nur lokale Clients) */
659 if( c->conn_id >= 0 )
661 if( ! IRC_WriteStrClient( Client, This_Server, RPL_WHOISIDLE_MSG, Client_Nick( Client ), c->nick, Conn_GetIdle( c->conn_id ))) return DISCONNECTED;
665 return IRC_WriteStrClient( Client, This_Server, RPL_ENDOFWHOIS_MSG, Client_Nick( Client ), c->nick );
669 GLOBAL BOOLEAN IRC_USERHOST( CLIENT *Client, REQUEST *Req )
671 CHAR rpl[COMMAND_LEN];
675 assert( Client != NULL );
676 assert( Req != NULL );
678 if( ! Check_Valid_User( Client )) return CONNECTED;
680 /* Falsche Anzahl Parameter? */
681 if(( Req->argc < 1 )) return IRC_WriteStrClient( Client, This_Server, ERR_NEEDMOREPARAMS_MSG, Client_Nick( Client ), Req->command );
683 if( Req->argc > 5 ) max = 5;
684 else max = Req->argc;
686 strcpy( rpl, RPL_USERHOST_MSG );
687 for( i = 0; i < max; i++ )
689 c = Client_GetFromNick( Req->argv[i] );
690 if( c && ( c->type == CLIENT_USER ))
692 /* Dieser Nick ist "online" */
693 strcat( rpl, c->nick );
694 if( strchr( c->modes, 'o' )) strcat( rpl, "*" );
696 if( strchr( c->modes, 'a' )) strcat( rpl, "-" );
697 else strcat( rpl, "+" );
698 strcat( rpl, c->user );
700 strcat( rpl, c->host );
704 if( rpl[strlen( rpl ) - 1] == ' ' ) rpl[strlen( rpl ) - 1] = '\0';
706 return IRC_WriteStrClient( Client, This_Server, rpl, Client->nick );
710 LOCAL BOOLEAN Check_Valid_User( CLIENT *Client )
712 assert( Client != NULL );
714 if( Client->type != CLIENT_USER )
716 IRC_WriteStrClient( Client, This_Server, ERR_NOTREGISTERED_MSG, Client_Nick( Client ));
720 } /* Check_Valid_User */
723 LOCAL BOOLEAN Hello_User( CLIENT *Client )
725 assert( Client != NULL );
726 assert( Client->nick[0] );
728 Log( LOG_NOTICE, "User \"%s!%s@%s\" (%s) registered (connection %d).", Client->nick, Client->user, Client->host, Client->name, Client->conn_id );
730 IRC_WriteStrClient( Client, This_Server, RPL_WELCOME_MSG, Client->nick, Client_GetID( Client ));
731 IRC_WriteStrClient( Client, This_Server, RPL_YOURHOST_MSG, Client->nick, This_Server->nick );
732 IRC_WriteStrClient( Client, This_Server, RPL_CREATED_MSG, Client->nick, NGIRCd_StartStr );
733 IRC_WriteStrClient( Client, This_Server, RPL_MYINFO_MSG, Client->nick, This_Server->nick );
735 Client->type = CLIENT_USER;
737 return Show_MOTD( Client );
741 LOCAL BOOLEAN Show_MOTD( CLIENT *Client )
747 assert( Client != NULL );
748 assert( Client->nick[0] );
750 fd = fopen( Conf_MotdFile, "r" );
753 Log( LOG_WARNING, "Can't read MOTD file \"%s\": %s", Conf_MotdFile, strerror( errno ));
754 return IRC_WriteStrClient( Client, This_Server, ERR_NOMOTD_MSG, Client->nick );
757 IRC_WriteStrClient( Client, This_Server, RPL_MOTDSTART_MSG, Client->nick, This_Server->nick );
760 if( ! fgets( line, 126, fd )) break;
761 if( line[strlen( line ) - 1] == '\n' ) line[strlen( line ) - 1] = '\0';
762 IRC_WriteStrClient( Client, This_Server, RPL_MOTD_MSG, Client->nick, line );
764 ok = IRC_WriteStrClient( Client, This_Server, RPL_ENDOFMOTD_MSG, Client->nick );