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