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.16 2001/12/31 02:18:51 alex Exp $
17 * Revision 1.16 2001/12/31 02:18:51 alex
18 * - viele neue Befehle (WHOIS, ISON, OPER, DIE, RESTART),
19 * - neuen Header "defines.h" mit (fast) allen Konstanten.
20 * - Code Cleanups und viele "kleine" Aenderungen & Bugfixes.
22 * Revision 1.15 2001/12/30 19:26:11 alex
23 * - Unterstuetzung fuer die Konfigurationsdatei eingebaut.
25 * Revision 1.14 2001/12/30 11:42:00 alex
26 * - der Server meldet nun eine ordentliche "Start-Zeit".
28 * Revision 1.13 2001/12/29 03:10:06 alex
29 * - Neue Funktion IRC_MODE() implementiert, div. Aenderungen.
30 * - neue configure-Optione "--enable-strict-rfc".
32 * Revision 1.12 2001/12/27 19:17:26 alex
33 * - neue Befehle PRIVMSG, NOTICE, PING.
35 * Revision 1.11 2001/12/27 16:55:41 alex
36 * - neu: IRC_WriteStrRelated(), Aenderungen auch in IRC_WriteStrClient().
38 * Revision 1.10 2001/12/26 22:48:53 alex
39 * - MOTD-Datei ist nun konfigurierbar und wird gelesen.
41 * Revision 1.9 2001/12/26 14:45:37 alex
44 * Revision 1.8 2001/12/26 03:21:46 alex
45 * - PING/PONG-Befehle implementiert,
46 * - Meldungen ueberarbeitet: enthalten nun (fast) immer den Nick.
48 * Revision 1.7 2001/12/25 23:25:18 alex
49 * - und nochmal Aenderungen am Logging ;-)
51 * Revision 1.6 2001/12/25 23:13:33 alex
52 * - Debug-Meldungen angepasst.
54 * Revision 1.5 2001/12/25 22:02:42 alex
55 * - neuer IRC-Befehl "/QUIT". Verbessertes Logging & Debug-Ausgaben.
57 * Revision 1.4 2001/12/25 19:19:30 alex
58 * - bessere Fehler-Abfragen, diverse Bugfixes.
59 * - Nicks werden nur einmal vergeben :-)
60 * - /MOTD wird unterstuetzt.
62 * Revision 1.3 2001/12/24 01:34:06 alex
63 * - USER und NICK wird nun in beliebiger Reihenfolge akzeptiert (wg. BitchX)
64 * - MOTD-Ausgabe begonnen zu implementieren.
66 * Revision 1.2 2001/12/23 21:57:16 alex
67 * - erste IRC-Befehle zu implementieren begonnen.
69 * Revision 1.1 2001/12/14 08:13:43 alex
70 * - neues Modul begonnen :-)
97 #define CONNECTED TRUE
98 #define DISCONNECTED FALSE
101 LOCAL BOOLEAN Check_Valid_User( CLIENT *Client );
103 LOCAL BOOLEAN Hello_User( CLIENT *Client );
104 LOCAL BOOLEAN Show_MOTD( CLIENT *Client );
107 GLOBAL VOID IRC_Init( VOID )
112 GLOBAL VOID IRC_Exit( VOID )
117 GLOBAL BOOLEAN IRC_WriteStrClient( CLIENT *Client, CLIENT *Prefix, CHAR *Format, ... )
119 /* Text an Clients, lokal bzw. remote, senden. */
122 BOOLEAN ok = CONNECTED;
126 assert( Client != NULL );
127 assert( Format != NULL );
129 va_start( ap, Format );
130 vsnprintf( buffer, 1000, Format, ap );
133 if( Client->conn_id != NONE ) send_to = Client->conn_id;
134 else send_to = Client->introducer->conn_id;
136 if( Prefix ) ok = Conn_WriteStr( Client->conn_id, ":%s %s", Client_GetID( Prefix ), buffer );
137 else ok = Conn_WriteStr( Client->conn_id, buffer );
140 } /* IRC_WriteStrClient */
143 GLOBAL BOOLEAN IRC_WriteStrRelated( CLIENT *Client, CHAR *Format, ... )
146 BOOLEAN ok = CONNECTED;
149 assert( Client != NULL );
150 assert( Format != NULL );
152 va_start( ap, Format );
153 vsnprintf( buffer, 1000, Format, ap );
156 /* an den Client selber */
157 ok = IRC_WriteStrClient( Client, Client, buffer );
160 } /* IRC_WriteStrRelated */
163 GLOBAL BOOLEAN IRC_PASS( CLIENT *Client, REQUEST *Req )
165 assert( Client != NULL );
166 assert( Req != NULL );
168 if( Client->type == CLIENT_UNKNOWN )
170 Log( LOG_DEBUG, "Connection %d: got PASS command ...", Client->conn_id );
171 return IRC_WriteStrClient( Client, This_Server, ERR_UNKNOWNCOMMAND_MSG, Client_Nick( Client ), Req->command );
173 else return IRC_WriteStrClient( Client, This_Server, ERR_ALREADYREGISTRED_MSG, Client_Nick( Client ));
177 GLOBAL BOOLEAN IRC_NICK( CLIENT *Client, REQUEST *Req )
179 assert( Client != NULL );
180 assert( Req != NULL );
182 /* Zumindest BitchX sendet NICK-USER in der falschen Reihenfolge. */
184 if( Client->type == CLIENT_UNKNOWN || Client->type == CLIENT_GOTPASS || Client->type == CLIENT_GOTNICK || Client->type == CLIENT_GOTUSER || Client->type == CLIENT_USER )
186 if( Client->type == CLIENT_UNKNOWN || Client->type == CLIENT_GOTPASS || Client->type == CLIENT_GOTNICK || Client->type == CLIENT_USER )
189 /* Falsche Anzahl Parameter? */
190 if( Req->argc != 1 ) return IRC_WriteStrClient( Client, This_Server, ERR_NEEDMOREPARAMS_MSG, Client_Nick( Client ), Req->command );
192 /* Ist der Client "restricted"? */
193 if( strchr( Client->modes, 'r' )) return IRC_WriteStrClient( Client, This_Server, ERR_RESTRICTED_MSG, Client_Nick( Client ));
195 /* Wenn der Client zu seinem eigenen Nick wechseln will, so machen
196 * wir nichts. So macht es das Original und mind. Snak hat probleme,
197 * wenn wir es nicht so machen. Ob es so okay ist? Hm ... */
199 if( strcasecmp( Client->nick, Req->argv[0] ) == 0 ) return CONNECTED;
202 /* pruefen, ob Nick bereits vergeben */
203 if( ! Client_CheckNick( Client, Req->argv[0] )) return CONNECTED;
205 if( Client->type == CLIENT_USER )
207 /* Nick-Aenderung: allen mitteilen! */
208 Log( LOG_INFO, "User \"%s!%s@%s\" changed nick: \"%s\" -> \"%s\".", Client->nick, Client->user, Client->host, Client->nick, Req->argv[0] );
209 IRC_WriteStrRelated( Client, "NICK :%s", Req->argv[0] );
212 /* Client-Nick registrieren */
213 strcpy( Client->nick, Req->argv[0] );
215 if( Client->type != CLIENT_USER )
218 Log( LOG_DEBUG, "Connection %d: got NICK command ...", Client->conn_id );
219 if( Client->type == CLIENT_GOTUSER ) return Hello_User( Client );
220 else Client->type = CLIENT_GOTNICK;
224 else return IRC_WriteStrClient( Client, This_Server, ERR_ALREADYREGISTRED_MSG, Client_Nick( Client ));
228 GLOBAL BOOLEAN IRC_USER( CLIENT *Client, REQUEST *Req )
230 assert( Client != NULL );
231 assert( Req != NULL );
234 if( Client->type == CLIENT_GOTNICK || Client->type == CLIENT_GOTPASS || Client->type == CLIENT_UNKNOWN )
236 if( Client->type == CLIENT_GOTNICK || Client->type == CLIENT_GOTPASS )
239 /* Falsche Anzahl Parameter? */
240 if( Req->argc != 4 ) return IRC_WriteStrClient( Client, This_Server, ERR_NEEDMOREPARAMS_MSG, Client_Nick( Client ), Req->command );
242 strncpy( Client->user, Req->argv[0], CLIENT_USER_LEN );
243 Client->user[CLIENT_USER_LEN - 1] = '\0';
244 strncpy( Client->name, Req->argv[3], CLIENT_NAME_LEN );
245 Client->name[CLIENT_NAME_LEN - 1] = '\0';
247 Log( LOG_DEBUG, "Connection %d: got USER command ...", Client->conn_id );
248 if( Client->type == CLIENT_GOTNICK ) return Hello_User( Client );
249 else Client->type = CLIENT_GOTUSER;
252 else if( Client->type == CLIENT_USER || Client->type == CLIENT_SERVER || Client->type == CLIENT_SERVICE )
254 return IRC_WriteStrClient( Client, This_Server, ERR_ALREADYREGISTRED_MSG, Client_Nick( Client ));
256 else return IRC_WriteStrClient( Client, This_Server, ERR_NOTREGISTERED_MSG, Client_Nick( Client ));
260 GLOBAL BOOLEAN IRC_QUIT( CLIENT *Client, REQUEST *Req )
262 assert( Client != NULL );
263 assert( Req != NULL );
265 if( Client->type != CLIENT_SERVER && Client->type != CLIENT_SERVICE )
267 /* Falsche Anzahl Parameter? */
268 if( Req->argc > 1 ) return IRC_WriteStrClient( Client, This_Server, ERR_NEEDMOREPARAMS_MSG, Client_Nick( Client ), Req->command );
270 Conn_Close( Client->conn_id, "Client wants to quit." );
273 else return IRC_WriteStrClient( Client, This_Server, ERR_NOTREGISTERED_MSG, Client_Nick( Client ));
277 GLOBAL BOOLEAN IRC_PING( CLIENT *Client, REQUEST *Req )
281 assert( Client != NULL );
282 assert( Req != NULL );
284 if( ! Check_Valid_User( Client )) return CONNECTED;
286 /* Falsche Anzahl Parameter? */
287 if( Req->argc < 1 ) return IRC_WriteStrClient( Client, This_Server, ERR_NOORIGIN_MSG, Client_Nick( Client ));
288 if( Req->argc > 1 ) return IRC_WriteStrClient( Client, This_Server, ERR_NEEDMOREPARAMS_MSG, Client_Nick( Client ), Req->command );
290 to = Client_Search( Req->argv[0] );
292 if( to ) return IRC_WriteStrClient( Client, This_Server, "PONG :%s", Client_Nick( Client ));
293 else return IRC_WriteStrClient( Client, This_Server, ERR_NOSUCHNICK_MSG, Client_Nick( Client ), Req->argv[0] );
297 GLOBAL BOOLEAN IRC_PONG( CLIENT *Client, REQUEST *Req )
299 assert( Client != NULL );
300 assert( Req != NULL );
302 if( ! Check_Valid_User( Client )) return CONNECTED;
304 /* Falsche Anzahl Parameter? */
305 if( Req->argc < 1 ) return IRC_WriteStrClient( Client, This_Server, ERR_NOORIGIN_MSG, Client_Nick( Client ));
306 if( Req->argc > 1 ) return IRC_WriteStrClient( Client, This_Server, ERR_NEEDMOREPARAMS_MSG, Client_Nick( Client ), Req->command );
308 /* Der Connection-Timestamp wurde schon beim Lesen aus dem Socket
309 * aktualisiert, daher muss das hier nicht mehr gemacht werden. */
311 Log( LOG_DEBUG, "Connection %d: received PONG.", Client->conn_id );
316 GLOBAL BOOLEAN IRC_MOTD( CLIENT *Client, REQUEST *Req )
318 assert( Client != NULL );
319 assert( Req != NULL );
321 if( ! Check_Valid_User( Client )) return CONNECTED;
323 /* Falsche Anzahl Parameter? */
324 if( Req->argc != 0 ) return IRC_WriteStrClient( Client, This_Server, ERR_NEEDMOREPARAMS_MSG, Client_Nick( Client ), Req->command );
326 return Show_MOTD( Client );
330 GLOBAL BOOLEAN IRC_PRIVMSG( CLIENT *Client, REQUEST *Req )
334 assert( Client != NULL );
335 assert( Req != NULL );
337 if( ! Check_Valid_User( Client )) return CONNECTED;
339 /* Falsche Anzahl Parameter? */
340 if( Req->argc == 0 ) return IRC_WriteStrClient( Client, This_Server, ERR_NORECIPIENT_MSG, Client_Nick( Client ), Req->command );
341 if( Req->argc == 1 ) return IRC_WriteStrClient( Client, This_Server, ERR_NOTEXTTOSEND_MSG, Client_Nick( Client ));
342 if( Req->argc > 2 ) return IRC_WriteStrClient( Client, This_Server, ERR_NEEDMOREPARAMS_MSG, Client_Nick( Client ), Req->command );
344 to = Client_Search( Req->argv[0] );
347 /* Okay, Ziel ist ein User */
348 if( Client->conn_id >= 0 ) Conn_UpdateIdle( Client->conn_id );
349 return IRC_WriteStrClient( to, Client, "PRIVMSG %s :%s", to->nick, Req->argv[1] );
352 return IRC_WriteStrClient( Client, This_Server, ERR_NOSUCHNICK_MSG, Client_Nick( Client ), Req->argv[0] );
356 GLOBAL BOOLEAN IRC_NOTICE( CLIENT *Client, REQUEST *Req )
360 assert( Client != NULL );
361 assert( Req != NULL );
363 if( ! Check_Valid_User( Client )) return CONNECTED;
365 /* Falsche Anzahl Parameter? */
366 if( Req->argc != 2 ) return CONNECTED;
368 to = Client_Search( Req->argv[0] );
371 /* Okay, Ziel ist ein User */
372 return IRC_WriteStrClient( to, Client, "NOTICE %s :%s", to->nick, Req->argv[1] );
379 GLOBAL BOOLEAN IRC_MODE( CLIENT *Client, REQUEST *Req )
381 CHAR x[2], new_modes[CLIENT_MODE_LEN], *ptr, *p;
384 assert( Client != NULL );
385 assert( Req != NULL );
387 if( ! Check_Valid_User( Client )) return CONNECTED;
389 /* Falsche Anzahl Parameter? */
390 if(( Req->argc > 2 ) || ( Req->argc < 1 )) return IRC_WriteStrClient( Client, This_Server, ERR_NEEDMOREPARAMS_MSG, Client_Nick( Client ), Req->command );
392 /* MODE ist nur fuer sich selber zulaessig */
393 if( Client_Search( Req->argv[0] ) != Client ) return IRC_WriteStrClient( Client, This_Server, ERR_USERSDONTMATCH_MSG, Client_Nick( Client ));
395 /* Werden die Modes erfragt? */
396 if( Req->argc == 1 ) return IRC_WriteStrClient( Client, This_Server, RPL_UMODEIS_MSG, Client_Nick( Client ), Client->modes );
400 /* Sollen Modes gesetzt oder geloescht werden? */
401 if( *ptr == '+' ) set = TRUE;
402 else if( *ptr == '-' ) set = FALSE;
403 else return IRC_WriteStrClient( Client, This_Server, ERR_UMODEUNKNOWNFLAG_MSG, Client_Nick( Client ));
405 /* Reply-String mit Aenderungen vorbereiten */
406 if( set ) strcpy( new_modes, "+" );
407 else strcpy( new_modes, "-" );
422 /* restricted (kann nur gesetzt werden) */
423 if( set ) x[0] = 'r';
424 else ok = IRC_WriteStrClient( Client, This_Server, ERR_RESTRICTED_MSG, Client_Nick( Client ));
427 /* operator (kann nur geloescht werden) */
430 Client->oper_by_me = FALSE;
433 else ok = IRC_WriteStrClient( Client, This_Server, ERR_UMODEUNKNOWNFLAG_MSG, Client_Nick( Client ));
436 ok = IRC_WriteStrClient( Client, This_Server, ERR_UMODEUNKNOWNFLAG_MSG, Client_Nick( Client ));
442 if( ! x[0] ) continue;
444 /* Okay, gueltigen Mode gefunden */
447 /* Modes sollen gesetzt werden */
448 if( ! strchr( Client->modes, x[0] ))
450 /* Client hat den Mode noch nicht -> setzen */
451 strcat( Client->modes, x );
452 strcat( new_modes, x );
457 /* Modes sollen geloescht werden */
458 p = strchr( Client->modes, x[0] );
461 /* Client hat den Mode -> loeschen */
467 strcat( new_modes, x );
472 /* Geanderte Modes? */
473 if( new_modes[1] && ok )
475 ok = IRC_WriteStrRelated( Client, "MODE %s :%s", Client->nick, new_modes );
476 Log( LOG_DEBUG, "User \"%s!%s@%s\": Mode change, now \"%s\".", Client->nick, Client->user, Client->host, Client->modes );
482 GLOBAL BOOLEAN IRC_OPER( CLIENT *Client, REQUEST *Req )
484 assert( Client != NULL );
485 assert( Req != NULL );
487 if( ! Check_Valid_User( Client )) return CONNECTED;
489 /* Falsche Anzahl Parameter? */
490 if( Req->argc != 2 ) return IRC_WriteStrClient( Client, This_Server, ERR_NEEDMOREPARAMS_MSG, Client_Nick( Client ), Req->command );
492 /* Ist ueberhaupt ein Operator gesetzt? */
493 if(( ! Conf_Oper[0] ) || ( ! Conf_OperPwd[0] )) return IRC_WriteStrClient( Client, This_Server, ERR_PASSWDMISMATCH_MSG, Client_Nick( Client ));
495 /* Stimmt der Name und das Passwort? */
496 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 ));
498 if( ! strchr( Client->modes, 'o' ))
500 /* noch kein o-Mode gesetzt */
501 strcat( Client->modes, "o" );
502 if( ! IRC_WriteStrRelated( Client, "MODE %s :+o", Client->nick )) return DISCONNECTED;
505 if( ! Client->oper_by_me ) Log( LOG_NOTICE, "User \"%s!%s@%s\" is now an IRC Operator.", Client->nick, Client->user, Client->host );
507 Client->oper_by_me = TRUE;
508 return IRC_WriteStrClient( Client, This_Server, RPL_YOUREOPER_MSG, Client_Nick( Client ));
512 GLOBAL BOOLEAN IRC_DIE( CLIENT *Client, REQUEST *Req )
514 assert( Client != NULL );
515 assert( Req != NULL );
517 if( ! Check_Valid_User( Client )) return CONNECTED;
519 /* Falsche Anzahl Parameter? */
520 if( Req->argc != 0 ) return IRC_WriteStrClient( Client, This_Server, ERR_NEEDMOREPARAMS_MSG, Client_Nick( Client ), Req->command );
522 if(( ! strchr( Client->modes, 'o' )) || ( ! Client->oper_by_me )) return IRC_WriteStrClient( Client, This_Server, ERR_NOPRIVILEGES_MSG, Client_Nick( Client ));
524 Log( LOG_NOTICE, "Got DIE command from \"%s!%s@%s\", going down!", Client->nick, Client->user, Client->host );
530 GLOBAL BOOLEAN IRC_RESTART( CLIENT *Client, REQUEST *Req )
532 assert( Client != NULL );
533 assert( Req != NULL );
535 if( ! Check_Valid_User( Client )) return CONNECTED;
537 /* Falsche Anzahl Parameter? */
538 if( Req->argc != 0 ) return IRC_WriteStrClient( Client, This_Server, ERR_NEEDMOREPARAMS_MSG, Client_Nick( Client ), Req->command );
540 if(( ! strchr( Client->modes, 'o' )) || ( ! Client->oper_by_me )) return IRC_WriteStrClient( Client, This_Server, ERR_NOPRIVILEGES_MSG, Client_Nick( Client ));
542 Log( LOG_NOTICE, "Got RESTART command from \"%s!%s@%s\", going down!", Client->nick, Client->user, Client->host );
543 NGIRCd_Restart = TRUE;
548 GLOBAL BOOLEAN IRC_ISON( CLIENT *Client, REQUEST *Req )
550 CHAR rpl[COMMAND_LEN];
555 assert( Client != NULL );
556 assert( Req != NULL );
558 if( ! Check_Valid_User( Client )) return CONNECTED;
560 /* Falsche Anzahl Parameter? */
561 if(( Req->argc < 1 )) return IRC_WriteStrClient( Client, This_Server, ERR_NEEDMOREPARAMS_MSG, Client_Nick( Client ), Req->command );
563 strcpy( rpl, RPL_ISON_MSG );
564 for( i = 0; i < Req->argc; i++ )
566 ptr = strtok( Req->argv[i], " " );
570 c = Client_GetFromNick( ptr );
571 if( c && ( c->type == CLIENT_USER ))
573 /* Dieser Nick ist "online" */
577 ptr = strtok( NULL, " " );
580 if( rpl[strlen( rpl ) - 1] == ' ' ) rpl[strlen( rpl ) - 1] = '\0';
582 return IRC_WriteStrClient( Client, This_Server, rpl, Client->nick );
586 GLOBAL BOOLEAN IRC_WHOIS( CLIENT *Client, REQUEST *Req )
590 assert( Client != NULL );
591 assert( Req != NULL );
593 if( ! Check_Valid_User( Client )) return CONNECTED;
595 /* Falsche Anzahl Parameter? */
596 if(( Req->argc < 1 ) || ( Req->argc > 2 )) return IRC_WriteStrClient( Client, This_Server, ERR_NEEDMOREPARAMS_MSG, Client_Nick( Client ), Req->command );
599 c = Client_GetFromNick( Req->argv[0] );
600 if(( ! c ) || ( c->type != CLIENT_USER )) return IRC_WriteStrClient( Client, This_Server, ERR_NOSUCHNICK_MSG, Client_Nick( Client ), Req->argv[0] );
602 /* Nick, User und Name */
603 if( ! IRC_WriteStrClient( Client, This_Server, RPL_WHOISUSER_MSG, Client_Nick( Client ), c->nick, c->user, c->host, c->name )) return DISCONNECTED;
606 if( ! IRC_WriteStrClient( Client, This_Server, RPL_WHOISSERVER_MSG, Client_Nick( Client ), c->nick, c->introducer->nick, c->introducer->info )) return DISCONNECTED;
609 if( strchr( c->modes, 'o' ))
611 if( ! IRC_WriteStrClient( Client, This_Server, RPL_WHOISOPERATOR_MSG, Client_Nick( Client ), c->nick )) return DISCONNECTED;
614 /* Idle (nur lokale Clients) */
615 if( c->conn_id >= 0 )
617 if( ! IRC_WriteStrClient( Client, This_Server, RPL_WHOISIDLE_MSG, Client_Nick( Client ), c->nick, Conn_GetIdle( c->conn_id ))) return DISCONNECTED;
621 return IRC_WriteStrClient( Client, This_Server, RPL_ENDOFWHOIS_MSG, Client_Nick( Client ), c->nick );
625 GLOBAL BOOLEAN IRC_USERHOST( CLIENT *Client, REQUEST *Req )
627 CHAR rpl[COMMAND_LEN];
631 assert( Client != NULL );
632 assert( Req != NULL );
634 if( ! Check_Valid_User( Client )) return CONNECTED;
636 /* Falsche Anzahl Parameter? */
637 if(( Req->argc < 1 )) return IRC_WriteStrClient( Client, This_Server, ERR_NEEDMOREPARAMS_MSG, Client_Nick( Client ), Req->command );
639 if( Req->argc > 5 ) max = 5;
640 else max = Req->argc;
642 strcpy( rpl, RPL_USERHOST_MSG );
643 for( i = 0; i < max; i++ )
645 c = Client_GetFromNick( Req->argv[i] );
646 if( c && ( c->type == CLIENT_USER ))
648 /* Dieser Nick ist "online" */
649 strcat( rpl, c->nick );
650 if( strchr( c->modes, 'o' )) strcat( rpl, "*" );
652 if( strchr( c->modes, 'a' )) strcat( rpl, "-" );
653 else strcat( rpl, "+" );
654 strcat( rpl, c->user );
656 strcat( rpl, c->host );
660 if( rpl[strlen( rpl ) - 1] == ' ' ) rpl[strlen( rpl ) - 1] = '\0';
662 return IRC_WriteStrClient( Client, This_Server, rpl, Client->nick );
666 LOCAL BOOLEAN Check_Valid_User( CLIENT *Client )
668 assert( Client != NULL );
670 if( Client->type != CLIENT_USER )
672 IRC_WriteStrClient( Client, This_Server, ERR_NOTREGISTERED_MSG, Client_Nick( Client ));
676 } /* Check_Valid_User */
679 LOCAL BOOLEAN Hello_User( CLIENT *Client )
681 assert( Client != NULL );
682 assert( Client->nick[0] );
684 Log( LOG_NOTICE, "User \"%s!%s@%s\" (%s) registered (connection %d).", Client->nick, Client->user, Client->host, Client->name, Client->conn_id );
686 IRC_WriteStrClient( Client, This_Server, RPL_WELCOME_MSG, Client->nick, Client_GetID( Client ));
687 IRC_WriteStrClient( Client, This_Server, RPL_YOURHOST_MSG, Client->nick, This_Server->nick );
688 IRC_WriteStrClient( Client, This_Server, RPL_CREATED_MSG, Client->nick, NGIRCd_StartStr );
689 IRC_WriteStrClient( Client, This_Server, RPL_MYINFO_MSG, Client->nick, This_Server->nick );
691 Client->type = CLIENT_USER;
693 return Show_MOTD( Client );
697 LOCAL BOOLEAN Show_MOTD( CLIENT *Client )
703 assert( Client != NULL );
704 assert( Client->nick[0] );
706 fd = fopen( Conf_MotdFile, "r" );
709 Log( LOG_WARNING, "Can't read MOTD file \"%s\": %s", Conf_MotdFile, strerror( errno ));
710 return IRC_WriteStrClient( Client, This_Server, ERR_NOMOTD_MSG, Client->nick );
713 IRC_WriteStrClient( Client, This_Server, RPL_MOTDSTART_MSG, Client->nick, This_Server->nick );
716 if( ! fgets( line, 126, fd )) break;
717 if( line[strlen( line ) - 1] == '\n' ) line[strlen( line ) - 1] = '\0';
718 IRC_WriteStrClient( Client, This_Server, RPL_MOTD_MSG, Client->nick, line );
720 ok = IRC_WriteStrClient( Client, This_Server, RPL_ENDOFMOTD_MSG, Client->nick );