]> arthur.barton.de Git - ngircd-alex.git/blob - src/ngircd/irc.c
- das Passwort von Servern wird nun ueberprueft (PASS- und SERVER-Befehl).
[ngircd-alex.git] / src / ngircd / irc.c
1 /*
2  * ngIRCd -- The Next Generation IRC Daemon
3  * Copyright (c)2001,2002 by Alexander Barton (alex@barton.de)
4  *
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.
11  *
12  * $Id: irc.c,v 1.26 2002/01/05 16:51:18 alex Exp $
13  *
14  * irc.c: IRC-Befehle
15  *
16  * $Log: irc.c,v $
17  * Revision 1.26  2002/01/05 16:51:18  alex
18  * - das Passwort von Servern wird nun ueberprueft (PASS- und SERVER-Befehl).
19  *
20  * Revision 1.25  2002/01/05 00:48:33  alex
21  * - bei SQUIT wurde immer die Verbindung getrennt, auch bei Remote-Servern.
22  *
23  * Revision 1.24  2002/01/04 17:58:44  alex
24  * - IRC_WriteStrXXX()-Funktionen eingefuehrt, groessere Anpassungen daran.
25  * - neuer Befehl SQUIT, QUIT an Server-Links angepasst.
26  *
27  * Revision 1.23  2002/01/04 01:36:40  alex
28  * - Loglevel ein wenig angepasst.
29  *
30  * Revision 1.22  2002/01/04 01:21:47  alex
31  * - Client-Strukruren werden nur noch ueber Funktionen angesprochen.
32  * - Weitere Anpassungen und Erweiterungen der Server-Links.
33  *
34  * Revision 1.21  2002/01/03 02:26:51  alex
35  * - neue Befehle SERVER und NJOIN begonnen,
36  * - begonnen, diverse IRC-Befehle an Server-Links anzupassen.
37  *
38  * Revision 1.20  2002/01/02 12:46:41  alex
39  * - die Gross- und Kleinschreibung des Nicks kann mit NICK nun geaendert werden.
40  *
41  * Revision 1.19  2002/01/02 02:51:39  alex
42  * - Copyright-Texte angepasst.
43  * - neuer Befehl "ERROR".
44  *
45  * Revision 1.17  2001/12/31 15:33:13  alex
46  * - neuer Befehl NAMES, kleinere Bugfixes.
47  * - Bug bei PING behoben: war zu restriktiv implementiert :-)
48  *
49  * Revision 1.16  2001/12/31 02:18:51  alex
50  * - viele neue Befehle (WHOIS, ISON, OPER, DIE, RESTART),
51  * - neuen Header "defines.h" mit (fast) allen Konstanten.
52  * - Code Cleanups und viele "kleine" Aenderungen & Bugfixes.
53  *
54  * Revision 1.15  2001/12/30 19:26:11  alex
55  * - Unterstuetzung fuer die Konfigurationsdatei eingebaut.
56  *
57  * Revision 1.14  2001/12/30 11:42:00  alex
58  * - der Server meldet nun eine ordentliche "Start-Zeit".
59  *
60  * Revision 1.13  2001/12/29 03:10:06  alex
61  * - Neue Funktion IRC_MODE() implementiert, div. Aenderungen.
62  * - neue configure-Optione "--enable-strict-rfc".
63  *
64  * Revision 1.12  2001/12/27 19:17:26  alex
65  * - neue Befehle PRIVMSG, NOTICE, PING.
66  *
67  * Revision 1.11  2001/12/27 16:55:41  alex
68  * - neu: IRC_WriteStrRelated(), Aenderungen auch in IRC_WriteStrClient().
69  *
70  * Revision 1.10  2001/12/26 22:48:53  alex
71  * - MOTD-Datei ist nun konfigurierbar und wird gelesen.
72  *
73  * Revision 1.9  2001/12/26 14:45:37  alex
74  * - "Code Cleanups".
75  *
76  * Revision 1.8  2001/12/26 03:21:46  alex
77  * - PING/PONG-Befehle implementiert,
78  * - Meldungen ueberarbeitet: enthalten nun (fast) immer den Nick.
79  *
80  * Revision 1.7  2001/12/25 23:25:18  alex
81  * - und nochmal Aenderungen am Logging ;-)
82  *
83  * Revision 1.6  2001/12/25 23:13:33  alex
84  * - Debug-Meldungen angepasst.
85  *
86  * Revision 1.5  2001/12/25 22:02:42  alex
87  * - neuer IRC-Befehl "/QUIT". Verbessertes Logging & Debug-Ausgaben.
88  *
89  * Revision 1.4  2001/12/25 19:19:30  alex
90  * - bessere Fehler-Abfragen, diverse Bugfixes.
91  * - Nicks werden nur einmal vergeben :-)
92  * - /MOTD wird unterstuetzt.
93  *
94  * Revision 1.3  2001/12/24 01:34:06  alex
95  * - USER und NICK wird nun in beliebiger Reihenfolge akzeptiert (wg. BitchX)
96  * - MOTD-Ausgabe begonnen zu implementieren.
97  *
98  * Revision 1.2  2001/12/23 21:57:16  alex
99  * - erste IRC-Befehle zu implementieren begonnen.
100  *
101  * Revision 1.1  2001/12/14 08:13:43  alex
102  * - neues Modul begonnen :-)
103  */
104
105
106 #include <portab.h>
107 #include "global.h"
108
109 #include <imp.h>
110 #include <assert.h>
111 #include <errno.h>
112 #include <stdarg.h>
113 #include <stdio.h>
114 #include <stdlib.h>
115 #include <string.h>
116
117 #include "ngircd.h"
118 #include "client.h"
119 #include "conf.h"
120 #include "conn.h"
121 #include "log.h"
122 #include "messages.h"
123 #include "parse.h"
124 #include "tool.h"
125
126 #include <exp.h>
127 #include "irc.h"
128
129
130 #define CONNECTED TRUE
131 #define DISCONNECTED FALSE
132
133
134 LOCAL BOOLEAN Hello_User( CLIENT *Client );
135 LOCAL BOOLEAN Show_MOTD( CLIENT *Client );
136
137 LOCAL VOID Kill_Nick( CHAR *Nick );
138
139
140 GLOBAL VOID IRC_Init( VOID )
141 {
142 } /* IRC_Init */
143
144
145 GLOBAL VOID IRC_Exit( VOID )
146 {
147 } /* IRC_Exit */
148
149
150 GLOBAL BOOLEAN IRC_WriteStrClient( CLIENT *Client, CHAR *Format, ... )
151 {
152         CHAR buffer[1000];
153         BOOLEAN ok = CONNECTED;
154         va_list ap;
155
156         assert( Client != NULL );
157         assert( Format != NULL );
158
159         va_start( ap, Format );
160         vsnprintf( buffer, 1000, Format, ap );
161         va_end( ap );
162
163         /* an den Client selber */
164         ok = IRC_WriteStrClientPrefix( Client, Client_ThisServer( ), buffer );
165
166         return ok;
167 } /* IRC_WriteStrClient */
168
169
170 GLOBAL BOOLEAN IRC_WriteStrClientPrefix( CLIENT *Client, CLIENT *Prefix, CHAR *Format, ... )
171 {
172         /* Text an Clients, lokal bzw. remote, senden. */
173
174         CHAR buffer[1000];
175         BOOLEAN ok = CONNECTED;
176         CONN_ID send_to;
177         va_list ap;
178
179         assert( Client != NULL );
180         assert( Format != NULL );
181
182         va_start( ap, Format );
183         vsnprintf( buffer, 1000, Format, ap );
184         va_end( ap );
185
186         if( Client_Conn( Client ) != NONE ) send_to = Client_Conn( Client );
187         else send_to = Client_Conn( Client_Introducer( Client ));
188
189         if( Prefix ) ok = Conn_WriteStr( send_to, ":%s %s", Client_Mask( Prefix ), buffer );
190         else ok = Conn_WriteStr( send_to, buffer );
191
192         return ok;
193 } /* IRC_WriteStrClientPrefix */
194
195
196 GLOBAL BOOLEAN IRC_WriteStrRelated( CLIENT *Client, CHAR *Format, ... )
197 {
198         CHAR buffer[1000];
199         BOOLEAN ok = CONNECTED;
200         va_list ap;
201
202         assert( Client != NULL );
203         assert( Format != NULL );
204
205         va_start( ap, Format );
206         vsnprintf( buffer, 1000, Format, ap );
207         va_end( ap );
208
209         /* an den Client selber */
210         ok = IRC_WriteStrClient( Client, buffer );
211
212         return ok;
213 } /* IRC_WriteStrRelated */
214
215
216 GLOBAL BOOLEAN IRC_PASS( CLIENT *Client, REQUEST *Req )
217 {
218         assert( Client != NULL );
219         assert( Req != NULL );
220
221         /* Fehler liefern, wenn kein lokaler Client */
222         if( Client_Conn( Client ) <= NONE ) return IRC_WriteStrClient( Client, ERR_UNKNOWNCOMMAND_MSG, Client_ID( Client ), Req->command );
223         
224         if(( Client_Type( Client ) == CLIENT_UNKNOWN ) && ( Req->argc == 1))
225         {
226                 /* noch nicht registrierte unbekannte Verbindung */
227                 Log( LOG_DEBUG, "Connection %d: got PASS command ...", Client_Conn( Client ));
228
229                 /* Passwort speichern */
230                 Client_SetPassword( Client, Req->argv[0] );
231
232                 Client_SetType( Client, CLIENT_GOTPASS );
233                 return CONNECTED;
234         }
235         else if((( Client_Type( Client ) == CLIENT_UNKNOWN ) || ( Client_Type( Client ) == CLIENT_UNKNOWNSERVER )) && (( Req->argc == 3 ) || ( Req->argc == 4 )))
236         {
237                 /* noch nicht registrierte Server-Verbindung */
238                 Log( LOG_DEBUG, "Connection %d: got PASS command (new server link) ...", Client_Conn( Client ));
239
240                 /* Passwort speichern */
241                 Client_SetPassword( Client, Req->argv[0] );
242
243                 Client_SetType( Client, CLIENT_GOTPASSSERVER );
244                 return CONNECTED;
245         }
246         else if(( Client_Type( Client ) == CLIENT_UNKNOWN  ) || ( Client_Type( Client ) == CLIENT_UNKNOWNSERVER ))
247         {
248                 /* Falsche Anzahl Parameter? */
249                 return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
250         }
251         else return IRC_WriteStrClient( Client, ERR_ALREADYREGISTRED_MSG, Client_ID( Client ));
252 } /* IRC_PASS */
253
254
255 GLOBAL BOOLEAN IRC_SERVER( CLIENT *Client, REQUEST *Req )
256 {
257         CHAR str[LINE_LEN], *ptr;
258         CLIENT *c;
259         INT i;
260         
261         assert( Client != NULL );
262         assert( Req != NULL );
263
264         /* Fehler liefern, wenn kein lokaler Client */
265         if( Client_Conn( Client ) <= NONE ) return IRC_WriteStrClient( Client, ERR_UNKNOWNCOMMAND_MSG, Client_ID( Client ), Req->command );
266
267         if( Client_Type( Client ) == CLIENT_GOTPASSSERVER )
268         {
269                 /* Verbindung soll als Server-Server-Verbindung registriert werden */
270                 Log( LOG_DEBUG, "Connection %d: got SERVER command (new server link) ...", Client_Conn( Client ));
271
272                 /* Falsche Anzahl Parameter? */
273                 if( Req->argc != 3 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
274
275                 /* Ist dieser Server bei uns konfiguriert? */
276                 for( i = 0; i < Conf_Server_Count; i++ ) if( strcasecmp( Req->argv[0], Conf_Server[i].name ) == 0 ) break;
277                 if( i >= Conf_Server_Count )
278                 {
279                         /* Server ist nicht konfiguriert! */
280                         Log( LOG_ALERT, "Connection %d: Server \"%s\" not configured here!", Client_Conn( Client ), Req->argv[0] );
281                         Conn_Close( Client_Conn( Client ), "Server not configured here!" );
282                         return DISCONNECTED;
283                 }
284                 if( strcmp( Client_Password( Client ), Conf_Server[i].pwd ) != 0 )
285                 {
286                         /* Falsches Passwort */
287                         Log( LOG_ALERT, "Connection %d: Bad password for server \"%s\"!", Client_Conn( Client ), Req->argv[0] );
288                         Conn_Close( Client_Conn( Client ), "Bad password!" );
289                         return DISCONNECTED;
290                 }
291                 
292                 /* Ist ein Server mit dieser ID bereits registriert? */
293                 if( ! Client_CheckID( Client, Req->argv[0] )) return DISCONNECTED;
294
295                 /* Server-Strukturen fuellen ;-) */
296                 Client_SetID( Client, Req->argv[0] );
297                 Client_SetToken( Client, atoi( Req->argv[1] ));
298                 Client_SetInfo( Client, Req->argv[2] );
299                 Client_SetHops( Client, 1 );
300
301                 Log( LOG_NOTICE, "Server \"%s\" registered (connection %d, 1 hop - direct link).", Client_ID( Client ), Client_Conn( Client ));
302
303                 Client_SetType( Client, CLIENT_SERVER );
304                 return CONNECTED;
305         }
306         else if( Client_Type( Client ) == CLIENT_SERVER )
307         {
308                 /* Neuer Server wird im Netz angekuendigt */
309
310                 /* Falsche Anzahl Parameter? */
311                 if( Req->argc != 4 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
312
313                 /* Ist ein Server mit dieser ID bereits registriert? */
314                 if( ! Client_CheckID( Client, Req->argv[0] )) return DISCONNECTED;
315
316                 /* Ueberfluessige Hostnamen aus Info-Text entfernen */
317                 ptr = strchr( Req->argv[3] + 2, '[' );
318                 if( ! ptr ) ptr = Req->argv[3];
319
320                 /* Neue Client-Struktur anlegen */
321                 c = Client_NewRemoteServer( Client, Req->argv[0], atoi( Req->argv[1] ), atoi( Req->argv[2] ), ptr );
322                 if( ! c )
323                 {
324                         /* Neue Client-Struktur konnte nicht angelegt werden */
325                         Log( LOG_ALERT, "Can't allocate client structure for server! (on connection %d)", Client_Conn( Client ));
326                         Conn_Close( Client_Conn( Client ), "Can't allocate client structure for remote server!" );
327                         return DISCONNECTED;
328                 }
329
330                 /* Log-Meldung zusammenbauen und ausgeben */
331                 if(( Client_Hops( c ) > 1 ) && ( Req->prefix[0] )) sprintf( str, "connected to %s, ", Req->prefix );
332                 else strcpy( str, "" );
333                 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": "" );
334                 
335                 return CONNECTED;
336         }
337         else return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
338 } /* IRC_SERVER */
339
340
341 GLOBAL BOOLEAN IRC_NJOIN( CLIENT *Client, REQUEST *Req )
342 {
343         assert( Client != NULL );
344         assert( Req != NULL );
345
346         if( Client_Type( Client ) != CLIENT_SERVER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTEREDSERVER_MSG, Client_ID( Client ));
347
348         return CONNECTED;
349 } /* IRC_NJOIN */
350
351
352 GLOBAL BOOLEAN IRC_NICK( CLIENT *Client, REQUEST *Req )
353 {
354         CLIENT *intr_c, *c;
355
356         assert( Client != NULL );
357         assert( Req != NULL );
358
359         /* Zumindest BitchX sendet NICK-USER in der falschen Reihenfolge. */
360 #ifndef STRICT_RFC
361         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 )
362 #else
363         if( Client_Type( Client ) == CLIENT_UNKNOWN || Client_Type( Client ) == CLIENT_GOTPASS || Client_Type( Client ) == CLIENT_GOTNICK || Client_Type( Client ) == CLIENT_USER  )
364 #endif
365         {
366                 /* User-Registrierung bzw. Nick-Aenderung */
367
368                 /* Falsche Anzahl Parameter? */
369                 if( Req->argc != 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
370
371                 /* Ist der Client "restricted"? */
372                 if( Client_HasMode( Client, 'r' )) return IRC_WriteStrClient( Client, ERR_RESTRICTED_MSG, Client_ID( Client ));
373
374                 /* Wenn der Client zu seinem eigenen Nick wechseln will, so machen
375                  * wir nichts. So macht es das Original und mind. Snak hat probleme,
376                  * wenn wir es nicht so machen. Ob es so okay ist? Hm ... */
377 #ifndef STRICT_RFC
378                 if( strcmp( Client_ID( Client ), Req->argv[0] ) == 0 ) return CONNECTED;
379 #endif
380                 
381                 /* pruefen, ob Nick bereits vergeben. Speziallfall: der Client
382                  * will nur die Gross- und Kleinschreibung aendern. Das darf
383                  * er natuerlich machen :-) */
384                 if( strcasecmp( Client_ID( Client ), Req->argv[0] ) != 0 )
385                 {
386                         if( ! Client_CheckNick( Client, Req->argv[0] )) return CONNECTED;
387                 }
388
389                 if( Client_Type( Client ) == CLIENT_USER )
390                 {
391                         /* Nick-Aenderung: allen mitteilen! */
392                         Log( LOG_INFO, "User \"%s\" changed nick: \"%s\" -> \"%s\".", Client_Mask( Client ), Client_ID( Client ), Req->argv[0] );
393                         IRC_WriteStrRelated( Client, "NICK :%s", Req->argv[0] );
394                 }
395                 
396                 /* Client-Nick registrieren */
397                 Client_SetID( Client, Req->argv[0] );
398
399                 if( Client_Type( Client ) != CLIENT_USER )
400                 {
401                         /* Neuer Client */
402                         Log( LOG_DEBUG, "Connection %d: got NICK command ...", Client_Conn( Client ));
403                         if( Client_Type( Client ) == CLIENT_GOTUSER ) return Hello_User( Client );
404                         else Client_SetType( Client, CLIENT_GOTNICK );
405                 }
406                 return CONNECTED;
407         }
408         else if( Client_Type( Client ) == CLIENT_SERVER )
409         {
410                 /* Server fuehrt neuen Client ein */
411
412                 /* Falsche Anzahl Parameter? */
413                 if( Req->argc != 7 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
414
415                 /* Nick ueberpruefen */
416                 c = Client_GetFromID( Req->argv[0] );
417                 if( c )
418                 {
419                         /* Der neue Nick ist auf diesem Server bereits registriert:
420                          * sowohl der neue, als auch der alte Client muessen nun
421                          * disconnectiert werden. */
422                         Log( LOG_ALERT, "Server %s introduces already registered nick %s!", Client_ID( Client ), Req->argv[0] );
423                         Kill_Nick( Req->argv[0] );
424                         return CONNECTED;
425                 }
426
427                 /* Server, zu dem der Client connectiert ist, suchen */
428                 intr_c = Client_GetFromToken( Client, atoi( Req->argv[4] ));
429                 if( ! intr_c )
430                 {
431                         Log( LOG_ALERT, "Server %s introduces nick %s with unknown host server!?", Client_ID( Client ), Req->argv[0] );
432                         Kill_Nick( Req->argv[0] );
433                         return CONNECTED;
434                 }
435
436                 /* Neue Client-Struktur anlegen */
437                 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] );
438                 if( ! c )
439                 {
440                         /* Eine neue Client-Struktur konnte nicht angelegt werden.
441                          * Der Client muss disconnectiert werden, damit der Netz-
442                          * status konsistent bleibt. */
443                         Log( LOG_ALERT, "Can't allocate client structure! (on connection %d)", Client_Conn( Client ));
444                         Kill_Nick( Req->argv[0] );
445                         return CONNECTED;
446                 }
447
448                 Log( LOG_DEBUG, "User \"%s\" registered (via %s, on %s, %d hop%s).", Client_ID( c ), Client_ID( Client ), Client_ID( intr_c ), Client_Hops( c ), Client_Hops( c ) > 1 ? "s": "" );
449
450                 return CONNECTED;
451         }
452         else return IRC_WriteStrClient( Client, ERR_ALREADYREGISTRED_MSG, Client_ID( Client ));
453 } /* IRC_NICK */
454
455
456 GLOBAL BOOLEAN IRC_USER( CLIENT *Client, REQUEST *Req )
457 {
458         assert( Client != NULL );
459         assert( Req != NULL );
460
461 #ifndef STRICT_RFC
462         if( Client_Type( Client ) == CLIENT_GOTNICK || Client_Type( Client ) == CLIENT_GOTPASS || Client_Type( Client ) == CLIENT_UNKNOWN )
463 #else
464         if( Client_Type( Client ) == CLIENT_GOTNICK || Client_Type( Client ) == CLIENT_GOTPASS )
465 #endif
466         {
467                 /* Falsche Anzahl Parameter? */
468                 if( Req->argc != 4 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
469
470                 Client_SetUser( Client, Req->argv[0] );
471                 Client_SetInfo( Client, Req->argv[3] );
472
473                 Log( LOG_DEBUG, "Connection %d: got USER command ...", Client_Conn( Client ));
474                 if( Client_Type( Client ) == CLIENT_GOTNICK ) return Hello_User( Client );
475                 else Client_SetType( Client, CLIENT_GOTUSER );
476                 return CONNECTED;
477         }
478         else if( Client_Type( Client ) == CLIENT_USER || Client_Type( Client ) == CLIENT_SERVER || Client_Type( Client ) == CLIENT_SERVICE )
479         {
480                 return IRC_WriteStrClient( Client, ERR_ALREADYREGISTRED_MSG, Client_ID( Client ));
481         }
482         else return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
483 } /* IRC_USER */
484
485
486 GLOBAL BOOLEAN IRC_QUIT( CLIENT *Client, REQUEST *Req )
487 {
488         CLIENT *target;
489         
490         assert( Client != NULL );
491         assert( Req != NULL );
492
493         if(( Client_Type( Client ) == CLIENT_USER ) || ( Client_Type( Client ) == CLIENT_SERVICE ))
494         {
495                 /* User / Service */
496                 
497                 /* Falsche Anzahl Parameter? */
498                 if( Req->argc > 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
499
500                 Conn_Close( Client_Conn( Client ), "Client wants to quit." );
501                 return DISCONNECTED;
502         }
503         else if ( Client_Type( Client ) == CLIENT_SERVER )
504         {
505                 /* Server */
506
507                 /* Falsche Anzahl Parameter? */
508                 if( Req->argc > 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
509
510                 target = Client_Search( Req->prefix );
511                 if( ! target ) Log( LOG_ALERT, "Got QUIT from %s for unknown server!?", Client_ID( Client ));
512                 else Client_Destroy( target );
513                 return CONNECTED;
514         }
515         else return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
516 } /* IRC_QUIT */
517
518
519 GLOBAL BOOLEAN IRC_SQUIT( CLIENT *Client, REQUEST *Req )
520 {
521         CLIENT *target;
522         
523         assert( Client != NULL );
524         assert( Req != NULL );
525
526         /* SQUIT ist nur fuer Server erlaubt */
527         if( Client_Type( Client ) != CLIENT_SERVER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
528
529         /* Falsche Anzahl Parameter? */
530         if( Req->argc != 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
531
532         target = Client_GetFromID( Req->argv[0] );
533         if( ! target )
534         {
535                 Log( LOG_ALERT, "Got SQUIT from %s for unknown server \%s\"!?", Client_ID( Client ), Req->argv[0] );
536                 return CONNECTED;
537         }
538
539         if( target == Client ) Log( LOG_NOTICE, "Got SQUIT from %s: %s", Client_ID( Client ), Req->argv[1] );
540         else Log( LOG_NOTICE, "Got SQUIT from %s for %s: %s", Client_ID( Client ), Client_ID( target ), Req->argv[1] );
541
542         /* FIXME: das SQUIT muss an alle Server weiter-
543          * geleitet werden ... */
544
545         if( Client_Conn( target ) > NONE )
546         {
547                 Conn_Close( Client_Conn( target ), Req->argv[1] );
548                 return DISCONNECTED;
549         }
550         else
551         {
552                 Client_Destroy( target );
553                 return CONNECTED;
554         }
555 } /* IRC_SQUIT */
556
557
558 GLOBAL BOOLEAN IRC_PING( CLIENT *Client, REQUEST *Req )
559 {
560         assert( Client != NULL );
561         assert( Req != NULL );
562
563         if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
564
565         /* Falsche Anzahl Parameter? */
566         if( Req->argc < 1 ) return IRC_WriteStrClient( Client, ERR_NOORIGIN_MSG, Client_ID( Client ));
567         if( Req->argc > 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
568
569         return IRC_WriteStrClient( Client, "PONG %s :%s", Client_ID( Client_ThisServer( )), Client_ID( Client ));
570 } /* IRC_PING */
571
572
573 GLOBAL BOOLEAN IRC_PONG( CLIENT *Client, REQUEST *Req )
574 {
575         assert( Client != NULL );
576         assert( Req != NULL );
577
578         if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
579
580         /* Falsche Anzahl Parameter? */
581         if( Req->argc < 1 ) return IRC_WriteStrClient( Client, ERR_NOORIGIN_MSG, Client_ID( Client ));
582         if( Req->argc > 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
583
584         /* Der Connection-Timestamp wurde schon beim Lesen aus dem Socket
585          * aktualisiert, daher muss das hier nicht mehr gemacht werden. */
586
587         Log( LOG_DEBUG, "Connection %d: received PONG.", Client_Conn( Client ));
588         return CONNECTED;
589 } /* IRC_PONG */
590
591
592 GLOBAL BOOLEAN IRC_MOTD( CLIENT *Client, REQUEST *Req )
593 {
594         assert( Client != NULL );
595         assert( Req != NULL );
596
597         if( Client_Type( Client ) != CLIENT_USER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
598
599         /* Falsche Anzahl Parameter? */
600         if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
601
602         return Show_MOTD( Client );
603 } /* IRC_MOTD */
604
605
606 GLOBAL BOOLEAN IRC_PRIVMSG( CLIENT *Client, REQUEST *Req )
607 {
608         CLIENT *to;
609         
610         assert( Client != NULL );
611         assert( Req != NULL );
612
613         if( Client_Type( Client ) != CLIENT_USER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
614
615         /* Falsche Anzahl Parameter? */
616         if( Req->argc == 0 ) return IRC_WriteStrClient( Client, ERR_NORECIPIENT_MSG, Client_ID( Client ), Req->command );
617         if( Req->argc == 1 ) return IRC_WriteStrClient( Client, ERR_NOTEXTTOSEND_MSG, Client_ID( Client ));
618         if( Req->argc > 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
619
620         to = Client_Search( Req->argv[0] );
621         if( to )
622         {
623                 /* Okay, Ziel ist ein User */
624                 if( Client_Conn( Client ) >= 0 ) Conn_UpdateIdle( Client_Conn( Client ));
625                 return IRC_WriteStrClientPrefix( to, Client, "PRIVMSG %s :%s", Client_ID( to ), Req->argv[1] );
626         }
627
628         return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->argv[0] );
629 } /* IRC_PRIVMSG */
630
631
632 GLOBAL BOOLEAN IRC_NOTICE( CLIENT *Client, REQUEST *Req )
633 {
634         CLIENT *to;
635
636         assert( Client != NULL );
637         assert( Req != NULL );
638
639         if( Client_Type( Client ) != CLIENT_USER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
640
641         /* Falsche Anzahl Parameter? */
642         if( Req->argc != 2 ) return CONNECTED;
643
644         to = Client_Search( Req->argv[0] );
645         if( to )
646         {
647                 /* Okay, Ziel ist ein User */
648                 return IRC_WriteStrClientPrefix( to, Client, "NOTICE %s :%s", Client_ID( to ), Req->argv[1] );
649         }
650
651         return CONNECTED;
652 } /* IRC_NOTICE */
653
654
655 GLOBAL BOOLEAN IRC_MODE( CLIENT *Client, REQUEST *Req )
656 {
657         CHAR x[2], new_modes[CLIENT_MODE_LEN], *ptr;
658         BOOLEAN set, ok;
659         CLIENT *target;
660         
661         assert( Client != NULL );
662         assert( Req != NULL );
663
664         if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
665
666         /* Falsche Anzahl Parameter? */
667         if(( Req->argc > 2 ) || ( Req->argc < 1 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
668
669         /* "Ziel-Client" suchen */
670         target = Client_Search( Req->argv[0] );
671
672         /* Wer ist der Anfragende? */
673         if( Client_Type( Client ) == CLIENT_USER )
674         {
675                 /* User: MODE ist nur fuer sich selber zulaessig */
676                 if( target != Client ) return IRC_WriteStrClient( Client, ERR_USERSDONTMATCH_MSG, Client_ID( Client ));
677         }
678         else
679         {
680                 /* Server: gibt es den Client ueberhaupt? */
681                 if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->argv[0] );
682         }
683
684         /* Werden die Modes erfragt? */
685         if( Req->argc == 1 ) return IRC_WriteStrClient( Client, RPL_UMODEIS_MSG, Client_ID( Client ), Client_Modes( Client ));
686
687         ptr = Req->argv[1];
688
689         /* Sollen Modes gesetzt oder geloescht werden? */
690         if( *ptr == '+' ) set = TRUE;
691         else if( *ptr == '-' ) set = FALSE;
692         else return IRC_WriteStrClient( Client, ERR_UMODEUNKNOWNFLAG_MSG, Client_ID( Client ));
693
694         /* Reply-String mit Aenderungen vorbereiten */
695         if( set ) strcpy( new_modes, "+" );
696         else strcpy( new_modes, "-" );
697
698         ptr++;
699         ok = TRUE;
700         x[1] = '\0';
701         while( *ptr )
702         {
703                 x[0] = '\0';
704                 if( Client_Type( Client ) == CLIENT_SERVER )
705                 {
706                         x[0] = *ptr;
707                         ok = TRUE;
708                 }
709                 else
710                 {
711                         switch( *ptr )
712                         {
713                                 case 'i':
714                                         /* invisible */
715                                         x[0] = 'i';
716                                         break;
717                                 case 'r':
718                                         /* restricted (kann nur gesetzt werden) */
719                                         if( set ) x[0] = 'r';
720                                         else ok = IRC_WriteStrClient( target, ERR_RESTRICTED_MSG, Client_ID( target ));
721                                         break;
722                                 case 'o':
723                                         /* operator (kann nur geloescht werden) */
724                                         if( ! set )
725                                         {
726                                                 Client_SetOperByMe( target, FALSE );
727                                                 x[0] = 'o';
728                                         }
729                                         else ok = IRC_WriteStrClient( target, ERR_UMODEUNKNOWNFLAG_MSG, Client_ID( target ));
730                                         break;
731                                 default:
732                                         ok = IRC_WriteStrClient( target, ERR_UMODEUNKNOWNFLAG_MSG, Client_ID( target ));
733                                         x[0] = '\0';
734                         }
735                 }
736                 if( ! ok ) break;
737
738                 ptr++;
739                 if( ! x[0] ) continue;
740
741                 /* Okay, gueltigen Mode gefunden */
742                 if( set )
743                 {
744                         /* Mode setzen. Wenn der Client ihn noch nicht hatte: merken */
745                         if( Client_ModeAdd( target, x[0] )) strcat( new_modes, x );
746                 }
747                 else
748                 {
749                         /* Modes geloescht. Wenn der Client ihn hatte: merken */
750                         if( Client_ModeDel( target, x[0] )) strcat( new_modes, x );
751                 }
752         }
753         
754         /* Geanderte Modes? */
755         if( new_modes[1] )
756         {
757                 if( Client_Type( Client ) == CLIENT_SERVER )
758                 {
759                         /* Modes an andere Server forwarden */
760                         /* FIXME */
761                 }
762                 else
763                 {
764                         /* Bestaetigung an Client schicken */
765                         ok = IRC_WriteStrRelated( Client, "MODE %s :%s", Client_ID( target ), new_modes );
766                 }
767                 Log( LOG_DEBUG, "User \"%s\": Mode change, now \"%s\".", Client_Mask( target ), Client_Modes( target ));
768         }
769         return ok;
770 } /* IRC_MODE */
771
772
773 GLOBAL BOOLEAN IRC_OPER( CLIENT *Client, REQUEST *Req )
774 {
775         INT i;
776         
777         assert( Client != NULL );
778         assert( Req != NULL );
779
780         if( Client_Type( Client ) != CLIENT_USER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
781         
782         /* Falsche Anzahl Parameter? */
783         if( Req->argc != 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
784
785         /* Operator suchen */
786         for( i = 0; i < Conf_Oper_Count; i++)
787         {
788                 if( Conf_Oper[i].name[0] && Conf_Oper[i].pwd[0] && ( strcmp( Conf_Oper[i].name, Req->argv[0] ) == 0 )) break;
789         }
790         if( i >= Conf_Oper_Count ) return IRC_WriteStrClient( Client, ERR_PASSWDMISMATCH_MSG, Client_ID( Client ));
791
792         /* Stimmt der Name und das Passwort? */
793         if(( strcmp( Conf_Oper[i].name, Req->argv[0] ) != 0 ) || ( strcmp( Conf_Oper[i].pwd, Req->argv[1] ) != 0 )) return IRC_WriteStrClient( Client, ERR_PASSWDMISMATCH_MSG, Client_ID( Client ));
794         
795         if( ! Client_HasMode( Client, 'o' ))
796         {
797                 /* noch kein o-Mode gesetzt */
798                 Client_ModeAdd( Client, 'o' );
799                 if( ! IRC_WriteStrRelated( Client, "MODE %s :+o", Client_ID( Client ))) return DISCONNECTED;
800         }
801
802         if( ! Client_OperByMe( Client )) Log( LOG_NOTICE, "User \"%s\" is now an IRC Operator.", Client_Mask( Client ));
803
804         Client_SetOperByMe( Client, TRUE );
805         return IRC_WriteStrClient( Client, RPL_YOUREOPER_MSG, Client_ID( Client ));
806 } /* IRC_OPER */
807
808
809 GLOBAL BOOLEAN IRC_DIE( CLIENT *Client, REQUEST *Req )
810 {
811         assert( Client != NULL );
812         assert( Req != NULL );
813
814         if( Client_Type( Client ) != CLIENT_USER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
815
816         /* Falsche Anzahl Parameter? */
817         if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
818
819         if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
820
821         Log( LOG_NOTICE, "Got DIE command from \"%s\", going down!", Client_Mask( Client ));
822         NGIRCd_Quit = TRUE;
823         return CONNECTED;
824 } /* IRC_DIE */
825
826
827 GLOBAL BOOLEAN IRC_RESTART( CLIENT *Client, REQUEST *Req )
828 {
829         assert( Client != NULL );
830         assert( Req != NULL );
831
832         if( Client_Type( Client ) != CLIENT_USER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
833
834         /* Falsche Anzahl Parameter? */
835         if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
836
837         if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
838
839         Log( LOG_NOTICE, "Got RESTART command from \"%s\", going down!", Client_Mask( Client ));
840         NGIRCd_Restart = TRUE;
841         return CONNECTED;
842 } /* IRC_RESTART */
843
844
845 GLOBAL BOOLEAN IRC_NAMES( CLIENT *Client, REQUEST *Req )
846 {
847         CHAR rpl[COMMAND_LEN];
848         CLIENT *c;
849         
850         assert( Client != NULL );
851         assert( Req != NULL );
852
853         if( Client_Type( Client ) != CLIENT_USER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
854
855         /* Falsche Anzahl Parameter? */
856         if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
857
858         /* Noch alle User ausgeben, die in keinem Channel sind */
859         rpl[0] = '\0';
860         c = Client_First( );
861         while( c )
862         {
863                 if( Client_Type( c ) == CLIENT_USER )
864                 {
865                         /* Okay, das ist ein User */
866                         strcat( rpl, Client_ID( c ));
867                         strcat( rpl, " " );
868                 }
869
870                 /* Antwort zu lang? Splitten. */
871                 if( strlen( rpl ) > 480 )
872                 {
873                         if( rpl[strlen( rpl ) - 1] == ' ' ) rpl[strlen( rpl ) - 1] = '\0';
874                         if( ! IRC_WriteStrClient( Client, RPL_NAMREPLY_MSG, Client_ID( Client ), "*", "*", rpl )) return DISCONNECTED;
875                         rpl[0] = '\0';
876                 }
877                 
878                 c = Client_Next( c );
879         }
880         if( rpl[0] )
881         {
882                 /* es wurden User gefunden */
883                 if( rpl[strlen( rpl ) - 1] == ' ' ) rpl[strlen( rpl ) - 1] = '\0';
884                 if( ! IRC_WriteStrClient( Client, RPL_NAMREPLY_MSG, Client_ID( Client ), "*", "*", rpl )) return DISCONNECTED;
885         }
886         return IRC_WriteStrClient( Client, RPL_ENDOFNAMES_MSG, Client_ID( Client ), "*" );
887 } /* IRC_NAMES */
888
889
890 GLOBAL BOOLEAN IRC_ISON( CLIENT *Client, REQUEST *Req )
891 {
892         CHAR rpl[COMMAND_LEN];
893         CLIENT *c;
894         CHAR *ptr;
895         INT i;
896         
897         assert( Client != NULL );
898         assert( Req != NULL );
899
900         if( Client_Type( Client ) != CLIENT_USER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
901
902         /* Falsche Anzahl Parameter? */
903         if(( Req->argc < 1 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
904
905         strcpy( rpl, RPL_ISON_MSG );
906         for( i = 0; i < Req->argc; i++ )
907         {
908                 ptr = strtok( Req->argv[i], " " );
909                 while( ptr )
910                 {
911                         ngt_TrimStr( ptr );
912                         c = Client_GetFromID( ptr );
913                         if( c && ( Client_Type( c ) == CLIENT_USER ))
914                         {
915                                 /* Dieser Nick ist "online" */
916                                 strcat( rpl, ptr );
917                                 strcat( rpl, " " );
918                         }
919                         ptr = strtok( NULL, " " );
920                 }
921         }
922         if( rpl[strlen( rpl ) - 1] == ' ' ) rpl[strlen( rpl ) - 1] = '\0';
923
924         return IRC_WriteStrClient( Client, rpl, Client_ID( Client ) );
925 } /* IRC_ISON */
926
927
928 GLOBAL BOOLEAN IRC_WHOIS( CLIENT *Client, REQUEST *Req )
929 {
930         CLIENT *c;
931         
932         assert( Client != NULL );
933         assert( Req != NULL );
934
935         if( Client_Type( Client ) != CLIENT_USER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
936
937         /* Falsche Anzahl Parameter? */
938         if(( Req->argc < 1 ) || ( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
939
940         /* Client suchen */
941         c = Client_GetFromID( Req->argv[0] );
942         if(( ! c ) || ( Client_Type( c ) != CLIENT_USER )) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->argv[0] );
943         
944         /* Nick, User und Name */
945         if( ! IRC_WriteStrClient( Client, RPL_WHOISUSER_MSG, Client_ID( Client ), Client_ID( c ), Client_User( c ), Client_Hostname( c ), Client_Info( c ))) return DISCONNECTED;
946
947         /* Server */
948         if( ! IRC_WriteStrClient( Client, RPL_WHOISSERVER_MSG, Client_ID( Client ), Client_ID( c ), Client_ID( Client_Introducer( c )), Client_Info( Client_Introducer( c )))) return DISCONNECTED;
949
950         /* IRC-Operator? */
951         if( Client_HasMode( c, 'o' ))
952         {
953                 if( ! IRC_WriteStrClient( Client, RPL_WHOISOPERATOR_MSG, Client_ID( Client ), Client_ID( c ))) return DISCONNECTED;
954         }
955
956         /* Idle (nur lokale Clients) */
957         if( Client_Conn( c ) > NONE )
958         {
959                 if( ! IRC_WriteStrClient( Client, RPL_WHOISIDLE_MSG, Client_ID( Client ), Client_ID( c ), Conn_GetIdle( Client_Conn ( c )))) return DISCONNECTED;
960         }
961
962         /* End of Whois */
963         return IRC_WriteStrClient( Client, RPL_ENDOFWHOIS_MSG, Client_ID( Client ), Client_ID( c ));
964 } /* IRC_WHOIS */
965
966
967 GLOBAL BOOLEAN IRC_USERHOST( CLIENT *Client, REQUEST *Req )
968 {
969         CHAR rpl[COMMAND_LEN];
970         CLIENT *c;
971         INT max, i;
972
973         assert( Client != NULL );
974         assert( Req != NULL );
975
976         if( Client_Type( Client ) != CLIENT_USER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
977
978         /* Falsche Anzahl Parameter? */
979         if(( Req->argc < 1 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
980
981         if( Req->argc > 5 ) max = 5;
982         else max = Req->argc;
983         
984         strcpy( rpl, RPL_USERHOST_MSG );
985         for( i = 0; i < max; i++ )
986         {
987                 c = Client_GetFromID( Req->argv[i] );
988                 if( c && ( Client_Type( c ) == CLIENT_USER ))
989                 {
990                         /* Dieser Nick ist "online" */
991                         strcat( rpl, Client_ID( c ));
992                         if( Client_HasMode( c, 'o' )) strcat( rpl, "*" );
993                         strcat( rpl, "=" );
994                         if( Client_HasMode( c, 'a' )) strcat( rpl, "-" );
995                         else strcat( rpl, "+" );
996                         strcat( rpl, Client_User( c ));
997                         strcat( rpl, "@" );
998                         strcat( rpl, Client_Hostname( c ));
999                         strcat( rpl, " " );
1000                 }
1001         }
1002         if( rpl[strlen( rpl ) - 1] == ' ' ) rpl[strlen( rpl ) - 1] = '\0';
1003
1004         return IRC_WriteStrClient( Client, rpl, Client_ID( Client ) );
1005 } /* IRC_USERHOST */
1006
1007
1008 GLOBAL BOOLEAN IRC_ERROR( CLIENT *Client, REQUEST *Req )
1009 {
1010         assert( Client != NULL );
1011         assert( Req != NULL );
1012
1013         if( Req->argc < 1 ) Log( LOG_NOTICE, "Got ERROR from \"%s\"!", Client_Mask( Client ));
1014         else Log( LOG_NOTICE, "Got ERROR from \"%s\": %s!", Client_Mask( Client ), Req->argv[0] );
1015
1016         return CONNECTED;
1017 } /* IRC_ERROR */
1018
1019
1020 LOCAL BOOLEAN Hello_User( CLIENT *Client )
1021 {
1022         assert( Client != NULL );
1023
1024         /* Passwort ueberpruefen */
1025         if( strcmp( Client_Password( Client ), Conf_ServerPwd ) != 0 )
1026         {
1027                 /* Falsches Passwort */
1028                 Log( LOG_ALERT, "User \"%s\" rejected (connection %d): Bad password!", Client_Mask( Client ), Client_Conn( Client ));
1029                 Conn_Close( Client_Conn( Client ), "Bad password!" );
1030                 return DISCONNECTED;
1031         }
1032
1033         Log( LOG_NOTICE, "User \"%s\" registered (connection %d).", Client_Mask( Client ), Client_Conn( Client ));
1034
1035         IRC_WriteStrClient( Client, RPL_WELCOME_MSG, Client_ID( Client ), Client_Mask( Client ));
1036         IRC_WriteStrClient( Client, RPL_YOURHOST_MSG, Client_ID( Client ), Client_ID( Client_ThisServer( )));
1037         IRC_WriteStrClient( Client, RPL_CREATED_MSG, Client_ID( Client ), NGIRCd_StartStr );
1038         IRC_WriteStrClient( Client, RPL_MYINFO_MSG, Client_ID( Client ), Client_ID( Client_ThisServer( )));
1039
1040         Client_SetType( Client, CLIENT_USER );
1041
1042         return Show_MOTD( Client );
1043 } /* Hello_User */
1044
1045
1046 LOCAL BOOLEAN Show_MOTD( CLIENT *Client )
1047 {
1048         BOOLEAN ok;
1049         CHAR line[127];
1050         FILE *fd;
1051         
1052         assert( Client != NULL );
1053
1054         fd = fopen( Conf_MotdFile, "r" );
1055         if( ! fd )
1056         {
1057                 Log( LOG_WARNING, "Can't read MOTD file \"%s\": %s", Conf_MotdFile, strerror( errno ));
1058                 return IRC_WriteStrClient( Client, ERR_NOMOTD_MSG, Client_ID( Client ) );
1059         }
1060         
1061         IRC_WriteStrClient( Client, RPL_MOTDSTART_MSG, Client_ID( Client ), Client_ID( Client_ThisServer( )));
1062         while( TRUE )
1063         {
1064                 if( ! fgets( line, 126, fd )) break;
1065                 if( line[strlen( line ) - 1] == '\n' ) line[strlen( line ) - 1] = '\0';
1066                 IRC_WriteStrClient( Client, RPL_MOTD_MSG, Client_ID( Client ), line );
1067         }
1068         ok = IRC_WriteStrClient( Client, RPL_ENDOFMOTD_MSG, Client_ID( Client ) );
1069
1070         fclose( fd );
1071         
1072         return ok;
1073 } /* Show_MOTD */
1074
1075
1076 LOCAL VOID Kill_Nick( CHAR *Nick )
1077 {
1078         Log( LOG_ALERT, "User(s) with nick \"%s\" will be disconnected!", Nick );
1079         /* FIXME */
1080         Log( LOG_ALERT, "[Kill_Nick() not implemented - OOOPS!]" );
1081 } /* Kill_Nick */
1082
1083
1084 /* -eof- */