]> arthur.barton.de Git - ngircd-alex.git/blob - src/ngircd/irc.c
- Definition der CHANNEL-Struktur aus Header entfernt,
[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.39 2002/01/21 00:05:11 alex Exp $
13  *
14  * irc.c: IRC-Befehle
15  *
16  * $Log: irc.c,v $
17  * Revision 1.39  2002/01/21 00:05:11  alex
18  * - neue Funktionen IRC_JOIN und IRC_PART begonnen, ebenso die Funktionen
19  *   IRC_WriteStrRelatedPrefix und IRC_WriteStrRelatedChannelPrefix().
20  * - diverse Aenderungen im Zusammenhang mit Channels.
21  *
22  * Revision 1.38  2002/01/18 15:31:32  alex
23  * - die User-Modes bei einem NICK von einem Server wurden falsch uebernommen.
24  *
25  * Revision 1.37  2002/01/16 22:10:18  alex
26  * - IRC_LUSERS() implementiert.
27  *
28  * Revision 1.36  2002/01/11 23:50:55  alex
29  * - LINKS implementiert, LUSERS begonnen.
30  *
31  * Revision 1.35  2002/01/09 21:30:45  alex
32  * - WHOIS wurde faelschlicherweise an User geforwarded statt vom Server beantwortet.
33  *
34  * Revision 1.34  2002/01/09 01:09:58  alex
35  * - WHOIS wird im "Strict-RFC-Mode" nicht mehr automatisch geforwarded,
36  * - andere Server werden nun ueber bisherige Server und User informiert.
37  *
38  * Revision 1.33  2002/01/07 23:42:12  alex
39  * - Es werden fuer alle Server eigene Token generiert,
40  * - QUIT von einem Server fuer einen User wird an andere Server geforwarded,
41  * - ebenso NICK-Befehle, die "fremde" User einfuehren.
42  *
43  * Revision 1.32  2002/01/07 16:02:36  alex
44  * - Loglevel von Remote-Mode-Aenderungen angepasst (nun Debug).
45  * - Im Debug-Mode werden nun auch PING's protokolliert.
46  *
47  * Revision 1.31  2002/01/07 15:39:46  alex
48  * - Server nimmt nun Server-Links an: PASS und SERVER entsprechend angepasst.
49  * - MODE und NICK melden nun die Aenderungen an andere Server.
50  *
51  * Revision 1.30  2002/01/06 15:21:29  alex
52  * - Loglevel und Meldungen nochmals ueberarbeitet.
53  * - QUIT und SQUIT forwarden nun den Grund der Trennung,
54  * - WHOIS wird nun immer an den "Original-Server" weitergeleitet.
55  *
56  * Revision 1.29  2002/01/05 23:24:54  alex
57  * - WHOIS erweitert: Anfragen koennen an andere Server weitergeleitet werden.
58  * - Vorbereitungen fuer Ident-Abfragen bei neuen Client-Strukturen.
59  *
60  * Revision 1.28  2002/01/05 20:08:02  alex
61  * - Div. Aenderungen fuer die Server-Links (u.a. WHOIS, QUIT, NICK angepasst).
62  * - Neue Funktionen IRC_WriteStrServer() und IRC_WriteStrServerPrefix().
63  *
64  * Revision 1.27  2002/01/05 19:15:03  alex
65  * - Fehlerpruefung bei select() in der "Hauptschleife" korrigiert.
66  *
67  * Revision 1.26  2002/01/05 16:51:18  alex
68  * - das Passwort von Servern wird nun ueberprueft (PASS- und SERVER-Befehl).
69  *
70  * Revision 1.25  2002/01/05 00:48:33  alex
71  * - bei SQUIT wurde immer die Verbindung getrennt, auch bei Remote-Servern.
72  *
73  * Revision 1.24  2002/01/04 17:58:44  alex
74  * - IRC_WriteStrXXX()-Funktionen eingefuehrt, groessere Anpassungen daran.
75  * - neuer Befehl SQUIT, QUIT an Server-Links angepasst.
76  *
77  * Revision 1.23  2002/01/04 01:36:40  alex
78  * - Loglevel ein wenig angepasst.
79  *
80  * Revision 1.22  2002/01/04 01:21:47  alex
81  * - Client-Strukruren werden nur noch ueber Funktionen angesprochen.
82  * - Weitere Anpassungen und Erweiterungen der Server-Links.
83  *
84  * Revision 1.21  2002/01/03 02:26:51  alex
85  * - neue Befehle SERVER und NJOIN begonnen,
86  * - begonnen, diverse IRC-Befehle an Server-Links anzupassen.
87  *
88  * Revision 1.20  2002/01/02 12:46:41  alex
89  * - die Gross- und Kleinschreibung des Nicks kann mit NICK nun geaendert werden.
90  *
91  * Revision 1.19  2002/01/02 02:51:39  alex
92  * - Copyright-Texte angepasst.
93  * - neuer Befehl "ERROR".
94  *
95  * Revision 1.17  2001/12/31 15:33:13  alex
96  * - neuer Befehl NAMES, kleinere Bugfixes.
97  * - Bug bei PING behoben: war zu restriktiv implementiert :-)
98  *
99  * Revision 1.16  2001/12/31 02:18:51  alex
100  * - viele neue Befehle (WHOIS, ISON, OPER, DIE, RESTART),
101  * - neuen Header "defines.h" mit (fast) allen Konstanten.
102  * - Code Cleanups und viele "kleine" Aenderungen & Bugfixes.
103  *
104  * Revision 1.15  2001/12/30 19:26:11  alex
105  * - Unterstuetzung fuer die Konfigurationsdatei eingebaut.
106  *
107  * Revision 1.14  2001/12/30 11:42:00  alex
108  * - der Server meldet nun eine ordentliche "Start-Zeit".
109  *
110  * Revision 1.13  2001/12/29 03:10:06  alex
111  * - Neue Funktion IRC_MODE() implementiert, div. Aenderungen.
112  * - neue configure-Optione "--enable-strict-rfc".
113  *
114  * Revision 1.12  2001/12/27 19:17:26  alex
115  * - neue Befehle PRIVMSG, NOTICE, PING.
116  *
117  * Revision 1.11  2001/12/27 16:55:41  alex
118  * - neu: IRC_WriteStrRelated(), Aenderungen auch in IRC_WriteStrClient().
119  *
120  * Revision 1.10  2001/12/26 22:48:53  alex
121  * - MOTD-Datei ist nun konfigurierbar und wird gelesen.
122  *
123  * Revision 1.9  2001/12/26 14:45:37  alex
124  * - "Code Cleanups".
125  *
126  * Revision 1.8  2001/12/26 03:21:46  alex
127  * - PING/PONG-Befehle implementiert,
128  * - Meldungen ueberarbeitet: enthalten nun (fast) immer den Nick.
129  *
130  * Revision 1.7  2001/12/25 23:25:18  alex
131  * - und nochmal Aenderungen am Logging ;-)
132  *
133  * Revision 1.6  2001/12/25 23:13:33  alex
134  * - Debug-Meldungen angepasst.
135  *
136  * Revision 1.5  2001/12/25 22:02:42  alex
137  * - neuer IRC-Befehl "/QUIT". Verbessertes Logging & Debug-Ausgaben.
138  *
139  * Revision 1.4  2001/12/25 19:19:30  alex
140  * - bessere Fehler-Abfragen, diverse Bugfixes.
141  * - Nicks werden nur einmal vergeben :-)
142  * - /MOTD wird unterstuetzt.
143  *
144  * Revision 1.3  2001/12/24 01:34:06  alex
145  * - USER und NICK wird nun in beliebiger Reihenfolge akzeptiert (wg. BitchX)
146  * - MOTD-Ausgabe begonnen zu implementieren.
147  *
148  * Revision 1.2  2001/12/23 21:57:16  alex
149  * - erste IRC-Befehle zu implementieren begonnen.
150  *
151  * Revision 1.1  2001/12/14 08:13:43  alex
152  * - neues Modul begonnen :-)
153  */
154
155
156 #include <portab.h>
157 #include "global.h"
158
159 #include <imp.h>
160 #include <assert.h>
161 #include <errno.h>
162 #include <stdarg.h>
163 #include <stdio.h>
164 #include <stdlib.h>
165 #include <string.h>
166
167 #include "ngircd.h"
168 #include "channel.h"
169 #include "client.h"
170 #include "conf.h"
171 #include "conn.h"
172 #include "log.h"
173 #include "messages.h"
174 #include "parse.h"
175 #include "tool.h"
176
177 #include <exp.h>
178 #include "irc.h"
179
180
181 #define CONNECTED TRUE
182 #define DISCONNECTED FALSE
183
184
185 LOCAL BOOLEAN Hello_User( CLIENT *Client );
186 LOCAL BOOLEAN Show_MOTD( CLIENT *Client );
187
188 LOCAL VOID Kill_Nick( CHAR *Nick );
189
190
191 GLOBAL VOID IRC_Init( VOID )
192 {
193 } /* IRC_Init */
194
195
196 GLOBAL VOID IRC_Exit( VOID )
197 {
198 } /* IRC_Exit */
199
200
201 GLOBAL BOOLEAN IRC_WriteStrClient( CLIENT *Client, CHAR *Format, ... )
202 {
203         CHAR buffer[1000];
204         BOOLEAN ok = CONNECTED;
205         va_list ap;
206
207         assert( Client != NULL );
208         assert( Format != NULL );
209
210         va_start( ap, Format );
211         vsnprintf( buffer, 1000, Format, ap );
212         va_end( ap );
213
214         /* an den Client selber */
215         ok = IRC_WriteStrClientPrefix( Client, Client_ThisServer( ), buffer );
216
217         return ok;
218 } /* IRC_WriteStrClient */
219
220
221 GLOBAL BOOLEAN IRC_WriteStrClientPrefix( CLIENT *Client, CLIENT *Prefix, CHAR *Format, ... )
222 {
223         /* Text an Clients, lokal bzw. remote, senden. */
224
225         CHAR buffer[1000];
226         va_list ap;
227
228         assert( Client != NULL );
229         assert( Format != NULL );
230         assert( Prefix != NULL );
231
232         va_start( ap, Format );
233         vsnprintf( buffer, 1000, Format, ap );
234         va_end( ap );
235
236         return Conn_WriteStr( Client_Conn( Client_NextHop( Client )), ":%s %s", Client_Mask( Prefix ), buffer );
237 } /* IRC_WriteStrClientPrefix */
238
239
240 GLOBAL BOOLEAN IRC_WriteStrRelated( CLIENT *Client, CHAR *Format, ... )
241 {
242         CHAR buffer[1000];
243         va_list ap;
244
245         assert( Client != NULL );
246         assert( Format != NULL );
247
248         va_start( ap, Format );
249         vsnprintf( buffer, 1000, Format, ap );
250         va_end( ap );
251
252         return IRC_WriteStrRelatedPrefix( Client, Client_ThisServer( ), buffer );
253 } /* IRC_WriteStrRelated */
254
255
256 GLOBAL BOOLEAN IRC_WriteStrRelatedPrefix( CLIENT *Client, CLIENT *Prefix, CHAR *Format, ... )
257 {
258         CHAR buffer[1000];
259         va_list ap;
260
261         assert( Client != NULL );
262         assert( Format != NULL );
263
264         va_start( ap, Format );
265         vsnprintf( buffer, 1000, Format, ap );
266         va_end( ap );
267
268         return IRC_WriteStrRelatedChannelPrefix( Client, NULL, Client_ThisServer( ), buffer );
269 } /* IRC_WriteStrRelatedPrefix */
270
271
272 GLOBAL BOOLEAN IRC_WriteStrRelatedChannelPrefix( CLIENT *Client, CHAR *ChanName, CLIENT *Prefix, CHAR *Format, ... )
273 {
274         CHAR buffer[1000];
275         BOOLEAN ok = CONNECTED;
276         va_list ap;
277
278         assert( Client != NULL );
279         assert( Format != NULL );
280         assert( Prefix != NULL );
281
282         va_start( ap, Format );
283         vsnprintf( buffer, 1000, Format, ap );
284         va_end( ap );
285
286         /* An den Client selber, wenn User */
287         if( Client_Type( Client ) == CLIENT_USER ) ok = IRC_WriteStrClientPrefix( Client, Prefix, buffer );
288
289         /* An alle Clients, die in den selben Channels sind.
290          * Dabei aber nur einmal je Remote-Server */
291                 
292         return ok;
293 } /* IRC_WriteStrRelatedChannelPrefix */
294
295
296 GLOBAL VOID IRC_WriteStrServers( CLIENT *ExceptOf, CHAR *Format, ... )
297 {
298         CHAR buffer[1000];
299         va_list ap;
300
301         assert( Format != NULL );
302
303         va_start( ap, Format );
304         vsnprintf( buffer, 1000, Format, ap );
305         va_end( ap );
306
307         /* an den Client selber */
308         return IRC_WriteStrServersPrefix( ExceptOf, Client_ThisServer( ), buffer );
309 } /* IRC_WriteStrServers */
310
311
312 GLOBAL VOID IRC_WriteStrServersPrefix( CLIENT *ExceptOf, CLIENT *Prefix, CHAR *Format, ... )
313 {
314         CHAR buffer[1000];
315         CLIENT *c;
316         va_list ap;
317         
318         assert( Format != NULL );
319         assert( Prefix != NULL );
320
321         va_start( ap, Format );
322         vsnprintf( buffer, 1000, Format, ap );
323         va_end( ap );
324         
325         c = Client_First( );
326         while( c )
327         {
328                 if(( Client_Type( c ) == CLIENT_SERVER ) && ( Client_Conn( c ) > NONE ) && ( c != Client_ThisServer( )) && ( c != ExceptOf ))
329                 {
330                         /* Ziel-Server gefunden */
331                         IRC_WriteStrClientPrefix( c, Prefix, buffer );
332                 }
333                 c = Client_Next( c );
334         }
335 } /* IRC_WriteStrServersPrefix */
336
337
338 GLOBAL BOOLEAN IRC_PASS( CLIENT *Client, REQUEST *Req )
339 {
340         assert( Client != NULL );
341         assert( Req != NULL );
342
343         /* Fehler liefern, wenn kein lokaler Client */
344         if( Client_Conn( Client ) <= NONE ) return IRC_WriteStrClient( Client, ERR_UNKNOWNCOMMAND_MSG, Client_ID( Client ), Req->command );
345         
346         if(( Client_Type( Client ) == CLIENT_UNKNOWN ) && ( Req->argc == 1))
347         {
348                 /* noch nicht registrierte unbekannte Verbindung */
349                 Log( LOG_DEBUG, "Connection %d: got PASS command ...", Client_Conn( Client ));
350
351                 /* Passwort speichern */
352                 Client_SetPassword( Client, Req->argv[0] );
353
354                 Client_SetType( Client, CLIENT_GOTPASS );
355                 return CONNECTED;
356         }
357         else if((( Client_Type( Client ) == CLIENT_UNKNOWN ) || ( Client_Type( Client ) == CLIENT_UNKNOWNSERVER )) && (( Req->argc == 3 ) || ( Req->argc == 4 )))
358         {
359                 /* noch nicht registrierte Server-Verbindung */
360                 Log( LOG_DEBUG, "Connection %d: got PASS command (new server link) ...", Client_Conn( Client ));
361
362                 /* Passwort speichern */
363                 Client_SetPassword( Client, Req->argv[0] );
364
365                 Client_SetType( Client, CLIENT_GOTPASSSERVER );
366                 return CONNECTED;
367         }
368         else if(( Client_Type( Client ) == CLIENT_UNKNOWN  ) || ( Client_Type( Client ) == CLIENT_UNKNOWNSERVER ))
369         {
370                 /* Falsche Anzahl Parameter? */
371                 return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
372         }
373         else return IRC_WriteStrClient( Client, ERR_ALREADYREGISTRED_MSG, Client_ID( Client ));
374 } /* IRC_PASS */
375
376
377 GLOBAL BOOLEAN IRC_SERVER( CLIENT *Client, REQUEST *Req )
378 {
379         CHAR str[LINE_LEN], *ptr;
380         BOOLEAN ok;
381         CLIENT *c;
382         INT i;
383         
384         assert( Client != NULL );
385         assert( Req != NULL );
386
387         /* Fehler liefern, wenn kein lokaler Client */
388         if( Client_Conn( Client ) <= NONE ) return IRC_WriteStrClient( Client, ERR_UNKNOWNCOMMAND_MSG, Client_ID( Client ), Req->command );
389
390         if( Client_Type( Client ) == CLIENT_GOTPASSSERVER )
391         {
392                 /* Verbindung soll als Server-Server-Verbindung registriert werden */
393                 Log( LOG_DEBUG, "Connection %d: got SERVER command (new server link) ...", Client_Conn( Client ));
394
395                 /* Falsche Anzahl Parameter? */
396                 if(( Req->argc != 2 ) && ( Req->argc != 3 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
397
398                 /* Ist dieser Server bei uns konfiguriert? */
399                 for( i = 0; i < Conf_Server_Count; i++ ) if( strcasecmp( Req->argv[0], Conf_Server[i].name ) == 0 ) break;
400                 if( i >= Conf_Server_Count )
401                 {
402                         /* Server ist nicht konfiguriert! */
403                         Log( LOG_ERR, "Connection %d: Server \"%s\" not configured here!", Client_Conn( Client ), Req->argv[0] );
404                         Conn_Close( Client_Conn( Client ), NULL, "Server not configured here", TRUE );
405                         return DISCONNECTED;
406                 }
407                 if( strcmp( Client_Password( Client ), Conf_Server[i].pwd ) != 0 )
408                 {
409                         /* Falsches Passwort */
410                         Log( LOG_ERR, "Connection %d: Bad password for server \"%s\"!", Client_Conn( Client ), Req->argv[0] );
411                         Conn_Close( Client_Conn( Client ), NULL, "Bad password", TRUE );
412                         return DISCONNECTED;
413                 }
414                 
415                 /* Ist ein Server mit dieser ID bereits registriert? */
416                 if( ! Client_CheckID( Client, Req->argv[0] )) return DISCONNECTED;
417
418                 /* Server-Strukturen fuellen ;-) */
419                 Client_SetID( Client, Req->argv[0] );
420                 Client_SetHops( Client, 1 );
421                 Client_SetInfo( Client, Req->argv[Req->argc - 1] );
422                 
423                 /* Meldet sich der Server bei uns an? */
424                 if( Req->argc == 2 )
425                 {
426                         /* Unseren SERVER- und PASS-Befehl senden */
427                         ok = TRUE;
428                         if( ! IRC_WriteStrClient( Client, "PASS %s "PASSSERVERADD, Conf_Server[i].pwd )) ok = FALSE;
429                         else ok = IRC_WriteStrClient( Client, "SERVER %s 1 :%s", Conf_ServerName, Conf_ServerInfo );
430                         if( ! ok )
431                         {
432                                 Conn_Close( Client_Conn( Client ), "Unexpected server behavior!", NULL, FALSE );
433                                 return DISCONNECTED;
434                         }
435                         Client_SetIntroducer( Client, Client );
436                         Client_SetToken( Client, 1 );
437                 }
438                 else  Client_SetToken( Client, atoi( Req->argv[1] ));
439
440                 Log( LOG_NOTICE, "Server \"%s\" registered (connection %d, 1 hop - direct link).", Client_ID( Client ), Client_Conn( Client ));
441
442                 Client_SetType( Client, CLIENT_SERVER );
443
444                 /* Alle bisherigen Server dem neuen Server bekannt machen,
445                  * die bisherigen Server ueber den neuen informierenn */
446                 c = Client_First( );
447                 while( c )
448                 {
449                         if(( Client_Type( c ) == CLIENT_SERVER ) && ( c != Client ) && ( c != Client_ThisServer( )))
450                         {
451                                 if( Client_Conn( c ) > NONE )
452                                 {
453                                         /* Dem gefundenen Server gleich den neuen
454                                         * Server bekannt machen */
455                                         if( ! IRC_WriteStrClient( c, "SERVER %s %d %d :%s", Client_ID( Client ), Client_Hops( Client ) + 1, Client_MyToken( Client ), Client_Info( Client ))) return DISCONNECTED;
456                                 }
457                                 
458                                 /* Den neuen Server ueber den alten informieren */
459                                 if( ! IRC_WriteStrClientPrefix( Client, Client_Introducer( c ), "SERVER %s %d %d :%s", Client_ID( c ), Client_Hops( c ) + 1, Client_MyToken( c ), Client_Info( c ))) return DISCONNECTED;
460                         }
461                         c = Client_Next( c );
462                 }
463
464                 /* alle User dem neuen Server bekannt machen */
465                 c = Client_First( );
466                 while( c )
467                 {
468                         if( Client_Type( c ) == CLIENT_USER )
469                         {
470                                 /* User an neuen Server melden */
471                                 if( ! IRC_WriteStrClient( Client, "NICK %s %d %s %s %d +%s :%s", Client_ID( c ), Client_Hops( c ) + 1, Client_User( c ), Client_Hostname( c ), Client_MyToken( Client_Introducer( c )), Client_Modes( c ), Client_Info( c ))) return DISCONNECTED;
472                         }
473                         c = Client_Next( c );
474                 }
475                 
476                 return CONNECTED;
477         }
478         else if( Client_Type( Client ) == CLIENT_SERVER )
479         {
480                 /* Neuer Server wird im Netz angekuendigt */
481
482                 /* Falsche Anzahl Parameter? */
483                 if( Req->argc != 4 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
484
485                 /* Ist ein Server mit dieser ID bereits registriert? */
486                 if( ! Client_CheckID( Client, Req->argv[0] )) return DISCONNECTED;
487
488                 /* Ueberfluessige Hostnamen aus Info-Text entfernen */
489                 ptr = strchr( Req->argv[3] + 2, '[' );
490                 if( ! ptr ) ptr = Req->argv[3];
491
492                 /* Neue Client-Struktur anlegen */
493                 c = Client_NewRemoteServer( Client, Req->argv[0], atoi( Req->argv[1] ), atoi( Req->argv[2] ), ptr, TRUE );
494                 if( ! c )
495                 {
496                         /* Neue Client-Struktur konnte nicht angelegt werden */
497                         Log( LOG_ALERT, "Can't create client structure for server! (on connection %d)", Client_Conn( Client ));
498                         Conn_Close( Client_Conn( Client ), NULL, "Can't allocate client structure for remote server", TRUE );
499                         return DISCONNECTED;
500                 }
501
502                 /* Log-Meldung zusammenbauen und ausgeben */
503                 if(( Client_Hops( c ) > 1 ) && ( Req->prefix[0] )) sprintf( str, "connected to %s, ", Req->prefix );
504                 else strcpy( str, "" );
505                 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": "" );
506                 
507                 return CONNECTED;
508         }
509         else return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
510 } /* IRC_SERVER */
511
512
513 GLOBAL BOOLEAN IRC_NJOIN( CLIENT *Client, REQUEST *Req )
514 {
515         assert( Client != NULL );
516         assert( Req != NULL );
517
518         if( Client_Type( Client ) != CLIENT_SERVER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTEREDSERVER_MSG, Client_ID( Client ));
519
520         return CONNECTED;
521 } /* IRC_NJOIN */
522
523
524 GLOBAL BOOLEAN IRC_NICK( CLIENT *Client, REQUEST *Req )
525 {
526         CLIENT *intr_c, *target, *c;
527         CHAR *modes;
528
529         assert( Client != NULL );
530         assert( Req != NULL );
531
532         /* Zumindest BitchX sendet NICK-USER in der falschen Reihenfolge. */
533 #ifndef STRICT_RFC
534         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 || ( Client_Type( Client ) == CLIENT_SERVER && Req->argc == 1 ))
535 #else
536         if( Client_Type( Client ) == CLIENT_UNKNOWN || Client_Type( Client ) == CLIENT_GOTPASS || Client_Type( Client ) == CLIENT_GOTNICK || Client_Type( Client ) == CLIENT_USER || ( Client_Type( Client ) == CLIENT_SERVER && Req->argc == 1 ))
537 #endif
538         {
539                 /* User-Registrierung bzw. Nick-Aenderung */
540
541                 /* Falsche Anzahl Parameter? */
542                 if( Req->argc != 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
543
544                 /* "Ziel-Client" ermitteln */
545                 if( Client_Type( Client ) == CLIENT_SERVER )
546                 {
547                         target = Client_GetFromID( Req->prefix );
548                         if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->argv[0] );
549                 }
550                 else
551                 {
552                         /* Ist der Client "restricted"? */
553                         if( Client_HasMode( Client, 'r' )) return IRC_WriteStrClient( Client, ERR_RESTRICTED_MSG, Client_ID( Client ));
554                         target = Client;
555                 }
556
557                 /* Wenn der Client zu seinem eigenen Nick wechseln will, so machen
558                  * wir nichts. So macht es das Original und mind. Snak hat probleme,
559                  * wenn wir es nicht so machen. Ob es so okay ist? Hm ... */
560 #ifndef STRICT_RFC
561                 if( strcmp( Client_ID( target ), Req->argv[0] ) == 0 ) return CONNECTED;
562 #endif
563                 
564                 /* pruefen, ob Nick bereits vergeben. Speziallfall: der Client
565                  * will nur die Gross- und Kleinschreibung aendern. Das darf
566                  * er natuerlich machen :-) */
567                 if( strcasecmp( Client_ID( target ), Req->argv[0] ) != 0 )
568                 {
569                         if( ! Client_CheckNick( target, Req->argv[0] )) return CONNECTED;
570                 }
571
572                 if( Client_Type( Client ) == CLIENT_USER )
573                 {
574                         /* Nick-Aenderung: allen mitteilen! */
575                         Log( LOG_INFO, "User \"%s\" changed nick: \"%s\" -> \"%s\".", Client_Mask( target ), Client_ID( target ), Req->argv[0] );
576                         IRC_WriteStrRelated( Client, "NICK :%s", Req->argv[0] );
577                         IRC_WriteStrServersPrefix( NULL, Client, "NICK :%s", Req->argv[0] );
578                 }
579                 else if( Client_Type( Client ) == CLIENT_SERVER )
580                 {
581                         /* Nick-Aenderung: allen mitteilen! */
582                         Log( LOG_DEBUG, "User \"%s\" changed nick: \"%s\" -> \"%s\".", Client_Mask( target ), Client_ID( target ), Req->argv[0] );
583                         IRC_WriteStrServersPrefix( Client, Client, "NICK :%s", Req->argv[0] );
584                 }
585         
586                 /* Client-Nick registrieren */
587                 Client_SetID( target, Req->argv[0] );
588
589                 if(( Client_Type( target ) != CLIENT_USER ) && ( Client_Type( target ) != CLIENT_SERVER ))
590                 {
591                         /* Neuer Client */
592                         Log( LOG_DEBUG, "Connection %d: got NICK command ...", Client_Conn( Client ));
593                         if( Client_Type( Client ) == CLIENT_GOTUSER ) return Hello_User( Client );
594                         else Client_SetType( Client, CLIENT_GOTNICK );
595                 }
596                 return CONNECTED;
597         }
598         else if( Client_Type( Client ) == CLIENT_SERVER )
599         {
600                 /* Server fuehrt neuen Client ein */
601
602                 /* Falsche Anzahl Parameter? */
603                 if( Req->argc != 7 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
604
605                 /* Nick ueberpruefen */
606                 c = Client_GetFromID( Req->argv[0] );
607                 if( c )
608                 {
609                         /* Der neue Nick ist auf diesem Server bereits registriert:
610                          * sowohl der neue, als auch der alte Client muessen nun
611                          * disconnectiert werden. */
612                         Log( LOG_ERR, "Server %s introduces already registered nick \"%s\"!", Client_ID( Client ), Req->argv[0] );
613                         Kill_Nick( Req->argv[0] );
614                         return CONNECTED;
615                 }
616
617                 /* Server, zu dem der Client connectiert ist, suchen */
618                 intr_c = Client_GetFromToken( Client, atoi( Req->argv[4] ));
619                 if( ! intr_c )
620                 {
621                         Log( LOG_ERR, "Server %s introduces nick \"%s\" on unknown server!?", Client_ID( Client ), Req->argv[0] );
622                         Kill_Nick( Req->argv[0] );
623                         return CONNECTED;
624                 }
625
626                 /* Neue Client-Struktur anlegen */
627                 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] + 1, Req->argv[6], TRUE );
628                 if( ! c )
629                 {
630                         /* Eine neue Client-Struktur konnte nicht angelegt werden.
631                          * Der Client muss disconnectiert werden, damit der Netz-
632                          * status konsistent bleibt. */
633                         Log( LOG_ALERT, "Can't create client structure! (on connection %d)", Client_Conn( Client ));
634                         Kill_Nick( Req->argv[0] );
635                         return CONNECTED;
636                 }
637
638                 modes = Client_Modes( c );
639                 if( *modes ) Log( LOG_DEBUG, "User \"%s\" (+%s) registered (via %s, on %s, %d hop%s).", Client_Mask( c ), modes, Client_ID( Client ), Client_ID( intr_c ), Client_Hops( c ), Client_Hops( c ) > 1 ? "s": "" );
640                 else Log( LOG_DEBUG, "User \"%s\" registered (via %s, on %s, %d hop%s).", Client_Mask( c ), Client_ID( Client ), Client_ID( intr_c ), Client_Hops( c ), Client_Hops( c ) > 1 ? "s": "" );
641
642                 /* Andere Server, ausser dem Introducer, informieren */
643                 IRC_WriteStrServersPrefix( Client, Client, "NICK %s %d %s %s %d %s :%s", Req->argv[0], atoi( Req->argv[1] ) + 1, Req->argv[2], Req->argv[3], Client_MyToken( intr_c ), Req->argv[5], Req->argv[6] );
644
645                 return CONNECTED;
646         }
647         else return IRC_WriteStrClient( Client, ERR_ALREADYREGISTRED_MSG, Client_ID( Client ));
648 } /* IRC_NICK */
649
650
651 GLOBAL BOOLEAN IRC_USER( CLIENT *Client, REQUEST *Req )
652 {
653         assert( Client != NULL );
654         assert( Req != NULL );
655
656 #ifndef STRICT_RFC
657         if( Client_Type( Client ) == CLIENT_GOTNICK || Client_Type( Client ) == CLIENT_GOTPASS || Client_Type( Client ) == CLIENT_UNKNOWN )
658 #else
659         if( Client_Type( Client ) == CLIENT_GOTNICK || Client_Type( Client ) == CLIENT_GOTPASS )
660 #endif
661         {
662                 /* Falsche Anzahl Parameter? */
663                 if( Req->argc != 4 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
664
665                 Client_SetUser( Client, Req->argv[0], FALSE );
666                 Client_SetInfo( Client, Req->argv[3] );
667
668                 Log( LOG_DEBUG, "Connection %d: got USER command ...", Client_Conn( Client ));
669                 if( Client_Type( Client ) == CLIENT_GOTNICK ) return Hello_User( Client );
670                 else Client_SetType( Client, CLIENT_GOTUSER );
671                 return CONNECTED;
672         }
673         else if( Client_Type( Client ) == CLIENT_USER || Client_Type( Client ) == CLIENT_SERVER || Client_Type( Client ) == CLIENT_SERVICE )
674         {
675                 return IRC_WriteStrClient( Client, ERR_ALREADYREGISTRED_MSG, Client_ID( Client ));
676         }
677         else return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
678 } /* IRC_USER */
679
680
681 GLOBAL BOOLEAN IRC_QUIT( CLIENT *Client, REQUEST *Req )
682 {
683         CLIENT *target;
684         
685         assert( Client != NULL );
686         assert( Req != NULL );
687
688         if(( Client_Type( Client ) == CLIENT_USER ) || ( Client_Type( Client ) == CLIENT_SERVICE ))
689         {
690                 /* User / Service */
691                 
692                 /* Falsche Anzahl Parameter? */
693                 if( Req->argc > 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
694
695                 if( Req->argc == 0 ) Conn_Close( Client_Conn( Client ), "Got QUIT command.", NULL, TRUE );
696                 else Conn_Close( Client_Conn( Client ), "Got QUIT command.", Req->argv[0], TRUE );
697                 
698                 return DISCONNECTED;
699         }
700         else if ( Client_Type( Client ) == CLIENT_SERVER )
701         {
702                 /* Server */
703
704                 /* Falsche Anzahl Parameter? */
705                 if( Req->argc > 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
706
707                 target = Client_Search( Req->prefix );
708                 if( ! target )
709                 {
710                         Log( LOG_ERR, "Got QUIT from %s for unknown client!?", Client_ID( Client ));
711                         return CONNECTED;
712                 }
713
714                 if( Req->argc == 0 ) Client_Destroy( target, "Got QUIT command.", NULL );
715                 else Client_Destroy( target, "Got QUIT command.", Req->argv[0] );
716
717                 return CONNECTED;
718         }
719         else return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
720 } /* IRC_QUIT */
721
722
723 GLOBAL BOOLEAN IRC_SQUIT( CLIENT *Client, REQUEST *Req )
724 {
725         CLIENT *target;
726         
727         assert( Client != NULL );
728         assert( Req != NULL );
729
730         /* SQUIT ist nur fuer Server erlaubt */
731         if( Client_Type( Client ) != CLIENT_SERVER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
732
733         /* Falsche Anzahl Parameter? */
734         if( Req->argc != 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
735
736         target = Client_GetFromID( Req->argv[0] );
737         if( ! target )
738         {
739                 Log( LOG_ERR, "Got SQUIT from %s for unknown server \%s\"!?", Client_ID( Client ), Req->argv[0] );
740                 return CONNECTED;
741         }
742
743         if( target == Client ) Log( LOG_DEBUG, "Got SQUIT from %s: %s", Client_ID( Client ), Req->argv[1] );
744         else Log( LOG_DEBUG, "Got SQUIT from %s for %s: %s", Client_ID( Client ), Client_ID( target ), Req->argv[1] );
745
746         /* SQUIT an alle Server weiterleiten */
747         IRC_WriteStrServers( Client, "SQUIT %s :%s", Req->argv[0], Req->argv[1] );
748
749         if( Client_Conn( target ) > NONE )
750         {
751                 if( Req->argv[1][0] ) Conn_Close( Client_Conn( target ), "Got SQUIT command.", Req->argv[1], TRUE );
752                 else Conn_Close( Client_Conn( target ), "Got SQUIT command.", NULL, TRUE );
753                 return DISCONNECTED;
754         }
755         else
756         {
757                 Client_Destroy( target, "Got SQUIT command.", Req->argv[1] );
758                 return CONNECTED;
759         }
760 } /* IRC_SQUIT */
761
762
763 GLOBAL BOOLEAN IRC_PING( CLIENT *Client, REQUEST *Req )
764 {
765         assert( Client != NULL );
766         assert( Req != NULL );
767
768         if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
769
770         /* Falsche Anzahl Parameter? */
771         if( Req->argc < 1 ) return IRC_WriteStrClient( Client, ERR_NOORIGIN_MSG, Client_ID( Client ));
772         if( Req->argc > 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
773
774         Log( LOG_DEBUG, "Connection %d: got PING, sending PONG ...", Client_Conn( Client ));
775         return IRC_WriteStrClient( Client, "PONG %s :%s", Client_ID( Client_ThisServer( )), Client_ID( Client ));
776 } /* IRC_PING */
777
778
779 GLOBAL BOOLEAN IRC_PONG( CLIENT *Client, REQUEST *Req )
780 {
781         assert( Client != NULL );
782         assert( Req != NULL );
783
784         if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
785
786         /* Falsche Anzahl Parameter? */
787         if( Req->argc < 1 ) return IRC_WriteStrClient( Client, ERR_NOORIGIN_MSG, Client_ID( Client ));
788         if( Req->argc > 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
789
790         /* Der Connection-Timestamp wurde schon beim Lesen aus dem Socket
791          * aktualisiert, daher muss das hier nicht mehr gemacht werden. */
792
793         Log( LOG_DEBUG, "Connection %d: received PONG.", Client_Conn( Client ));
794         return CONNECTED;
795 } /* IRC_PONG */
796
797
798 GLOBAL BOOLEAN IRC_MOTD( CLIENT *Client, REQUEST *Req )
799 {
800         assert( Client != NULL );
801         assert( Req != NULL );
802
803         if( Client_Type( Client ) != CLIENT_USER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
804
805         /* Falsche Anzahl Parameter? */
806         if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
807
808         return Show_MOTD( Client );
809 } /* IRC_MOTD */
810
811
812 GLOBAL BOOLEAN IRC_PRIVMSG( CLIENT *Client, REQUEST *Req )
813 {
814         CLIENT *to, *from;
815         
816         assert( Client != NULL );
817         assert( Req != NULL );
818
819         if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
820
821         /* Falsche Anzahl Parameter? */
822         if( Req->argc == 0 ) return IRC_WriteStrClient( Client, ERR_NORECIPIENT_MSG, Client_ID( Client ), Req->command );
823         if( Req->argc == 1 ) return IRC_WriteStrClient( Client, ERR_NOTEXTTOSEND_MSG, Client_ID( Client ));
824         if( Req->argc > 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
825
826         if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_GetFromID( Req->prefix );
827         else from = Client;
828         if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
829
830         to = Client_Search( Req->argv[0] );
831         if( to )
832         {
833                 /* Okay, Ziel ist ein User */
834                 if( Client_Conn( from ) >= 0 ) Conn_UpdateIdle( Client_Conn( from ));
835                 return IRC_WriteStrClientPrefix( to, from, "PRIVMSG %s :%s", Client_ID( to ), Req->argv[1] );
836         }
837         else return IRC_WriteStrClient( from, ERR_NOSUCHNICK_MSG, Client_ID( from ), Req->argv[0] );
838 } /* IRC_PRIVMSG */
839
840
841 GLOBAL BOOLEAN IRC_NOTICE( CLIENT *Client, REQUEST *Req )
842 {
843         CLIENT *to, *from;
844
845         assert( Client != NULL );
846         assert( Req != NULL );
847
848         if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
849
850         /* Falsche Anzahl Parameter? */
851         if( Req->argc != 2 ) return CONNECTED;
852
853         if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_GetFromID( Req->prefix );
854         else from = Client;
855         if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
856
857         to = Client_Search( Req->argv[0] );
858         if( to )
859         {
860                 /* Okay, Ziel ist ein User */
861                 return IRC_WriteStrClientPrefix( to, from, "NOTICE %s :%s", Client_ID( to ), Req->argv[1] );
862         }
863         else return CONNECTED;
864 } /* IRC_NOTICE */
865
866
867 GLOBAL BOOLEAN IRC_MODE( CLIENT *Client, REQUEST *Req )
868 {
869         CHAR x[2], new_modes[CLIENT_MODE_LEN], *ptr;
870         BOOLEAN set, ok;
871         CLIENT *target;
872         
873         assert( Client != NULL );
874         assert( Req != NULL );
875
876         if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
877
878         /* Falsche Anzahl Parameter? */
879         if(( Req->argc > 2 ) || ( Req->argc < 1 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
880
881         /* "Ziel-Client" suchen */
882         target = Client_Search( Req->argv[0] );
883
884         /* Wer ist der Anfragende? */
885         if( Client_Type( Client ) == CLIENT_USER )
886         {
887                 /* User: MODE ist nur fuer sich selber zulaessig */
888                 if( target != Client ) return IRC_WriteStrClient( Client, ERR_USERSDONTMATCH_MSG, Client_ID( Client ));
889         }
890         else
891         {
892                 /* Server: gibt es den Client ueberhaupt? */
893                 if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->argv[0] );
894         }
895
896         /* Werden die Modes erfragt? */
897         if( Req->argc == 1 ) return IRC_WriteStrClient( Client, RPL_UMODEIS_MSG, Client_ID( Client ), Client_Modes( Client ));
898
899         ptr = Req->argv[1];
900
901         /* Sollen Modes gesetzt oder geloescht werden? */
902         if( *ptr == '+' ) set = TRUE;
903         else if( *ptr == '-' ) set = FALSE;
904         else return IRC_WriteStrClient( Client, ERR_UMODEUNKNOWNFLAG_MSG, Client_ID( Client ));
905
906         /* Reply-String mit Aenderungen vorbereiten */
907         if( set ) strcpy( new_modes, "+" );
908         else strcpy( new_modes, "-" );
909
910         ptr++;
911         ok = TRUE;
912         x[1] = '\0';
913         while( *ptr )
914         {
915                 x[0] = '\0';
916                 if( Client_Type( Client ) == CLIENT_SERVER )
917                 {
918                         x[0] = *ptr;
919                         ok = TRUE;
920                 }
921                 else
922                 {
923                         switch( *ptr )
924                         {
925                                 case 'i':
926                                         /* invisible */
927                                         x[0] = 'i';
928                                         break;
929                                 case 'r':
930                                         /* restricted (kann nur gesetzt werden) */
931                                         if( set ) x[0] = 'r';
932                                         else ok = IRC_WriteStrClient( target, ERR_RESTRICTED_MSG, Client_ID( target ));
933                                         break;
934                                 case 'o':
935                                         /* operator (kann nur geloescht werden) */
936                                         if( ! set )
937                                         {
938                                                 Client_SetOperByMe( target, FALSE );
939                                                 x[0] = 'o';
940                                         }
941                                         else ok = IRC_WriteStrClient( target, ERR_UMODEUNKNOWNFLAG_MSG, Client_ID( target ));
942                                         break;
943                                 default:
944                                         ok = IRC_WriteStrClient( target, ERR_UMODEUNKNOWNFLAG_MSG, Client_ID( target ));
945                                         x[0] = '\0';
946                         }
947                 }
948                 if( ! ok ) break;
949
950                 ptr++;
951                 if( ! x[0] ) continue;
952
953                 /* Okay, gueltigen Mode gefunden */
954                 if( set )
955                 {
956                         /* Mode setzen. Wenn der Client ihn noch nicht hatte: merken */
957                         if( Client_ModeAdd( target, x[0] )) strcat( new_modes, x );
958                 }
959                 else
960                 {
961                         /* Modes geloescht. Wenn der Client ihn hatte: merken */
962                         if( Client_ModeDel( target, x[0] )) strcat( new_modes, x );
963                 }
964         }
965         
966         /* Geanderte Modes? */
967         if( new_modes[1] )
968         {
969                 if( Client_Type( Client ) == CLIENT_SERVER )
970                 {
971                         /* Modes an andere Server forwarden */
972                         IRC_WriteStrServersPrefix( Client, Client, "MODE %s :%s", Client_ID( target ), new_modes );
973                 }
974                 else
975                 {
976                         /* Bestaetigung an Client schicken & andere Server informieren */
977                         ok = IRC_WriteStrClient( Client, "MODE %s :%s", Client_ID( target ), new_modes );
978                         IRC_WriteStrServers( Client, "MODE %s :%s", Client_ID( target ), new_modes );
979                 }
980                 Log( LOG_DEBUG, "User \"%s\": Mode change, now \"%s\".", Client_Mask( target ), Client_Modes( target ));
981         }
982         return ok;
983 } /* IRC_MODE */
984
985
986 GLOBAL BOOLEAN IRC_OPER( CLIENT *Client, REQUEST *Req )
987 {
988         INT i;
989         
990         assert( Client != NULL );
991         assert( Req != NULL );
992
993         if( Client_Type( Client ) != CLIENT_USER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
994         
995         /* Falsche Anzahl Parameter? */
996         if( Req->argc != 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
997
998         /* Operator suchen */
999         for( i = 0; i < Conf_Oper_Count; i++)
1000         {
1001                 if( Conf_Oper[i].name[0] && Conf_Oper[i].pwd[0] && ( strcmp( Conf_Oper[i].name, Req->argv[0] ) == 0 )) break;
1002         }
1003         if( i >= Conf_Oper_Count )
1004         {
1005                 Log( LOG_WARNING, "Got invalid OPER from \"%s\": Name \"%s\" not configured!", Client_Mask( Client ), Req->argv[0] );
1006                 return IRC_WriteStrClient( Client, ERR_PASSWDMISMATCH_MSG, Client_ID( Client ));
1007         }
1008
1009         /* Stimmt das Passwort? */
1010         if( strcmp( Conf_Oper[i].pwd, Req->argv[1] ) != 0 )
1011         {
1012                 Log( LOG_WARNING, "Got invalid OPER from \"%s\": Bad password for \"%s\"!", Client_Mask( Client ), Conf_Oper[i].name );
1013                 return IRC_WriteStrClient( Client, ERR_PASSWDMISMATCH_MSG, Client_ID( Client ));
1014         }
1015         
1016         if( ! Client_HasMode( Client, 'o' ))
1017         {
1018                 /* noch kein o-Mode gesetzt */
1019                 Client_ModeAdd( Client, 'o' );
1020                 if( ! IRC_WriteStrClient( Client, "MODE %s :+o", Client_ID( Client ))) return DISCONNECTED;
1021                 IRC_WriteStrServersPrefix( NULL, Client, "MODE %s :+o", Client_ID( Client ));
1022         }
1023
1024         if( ! Client_OperByMe( Client )) Log( LOG_NOTICE, "Got valid OPER from \"%s\", user is an IRC operator now.", Client_Mask( Client ));
1025
1026         Client_SetOperByMe( Client, TRUE );
1027         return IRC_WriteStrClient( Client, RPL_YOUREOPER_MSG, Client_ID( Client ));
1028 } /* IRC_OPER */
1029
1030
1031 GLOBAL BOOLEAN IRC_DIE( CLIENT *Client, REQUEST *Req )
1032 {
1033         assert( Client != NULL );
1034         assert( Req != NULL );
1035
1036         if( Client_Type( Client ) != CLIENT_USER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
1037
1038         /* Falsche Anzahl Parameter? */
1039         if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
1040
1041         if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
1042
1043         Log( LOG_NOTICE, "Got DIE command from \"%s\", going down!", Client_Mask( Client ));
1044         NGIRCd_Quit = TRUE;
1045         return CONNECTED;
1046 } /* IRC_DIE */
1047
1048
1049 GLOBAL BOOLEAN IRC_RESTART( CLIENT *Client, REQUEST *Req )
1050 {
1051         assert( Client != NULL );
1052         assert( Req != NULL );
1053
1054         if( Client_Type( Client ) != CLIENT_USER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
1055
1056         /* Falsche Anzahl Parameter? */
1057         if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
1058
1059         if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
1060
1061         Log( LOG_NOTICE, "Got RESTART command from \"%s\", going down!", Client_Mask( Client ));
1062         NGIRCd_Restart = TRUE;
1063         return CONNECTED;
1064 } /* IRC_RESTART */
1065
1066
1067 GLOBAL BOOLEAN IRC_NAMES( CLIENT *Client, REQUEST *Req )
1068 {
1069         CHAR rpl[COMMAND_LEN];
1070         CLIENT *c;
1071         
1072         assert( Client != NULL );
1073         assert( Req != NULL );
1074
1075         if( Client_Type( Client ) != CLIENT_USER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
1076
1077         /* Falsche Anzahl Parameter? */
1078         if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
1079
1080         /* Noch alle User ausgeben, die in keinem Channel sind */
1081         rpl[0] = '\0';
1082         c = Client_First( );
1083         while( c )
1084         {
1085                 if( Client_Type( c ) == CLIENT_USER )
1086                 {
1087                         /* Okay, das ist ein User */
1088                         strcat( rpl, Client_ID( c ));
1089                         strcat( rpl, " " );
1090                 }
1091
1092                 /* Antwort zu lang? Splitten. */
1093                 if( strlen( rpl ) > 480 )
1094                 {
1095                         if( rpl[strlen( rpl ) - 1] == ' ' ) rpl[strlen( rpl ) - 1] = '\0';
1096                         if( ! IRC_WriteStrClient( Client, RPL_NAMREPLY_MSG, Client_ID( Client ), "*", "*", rpl )) return DISCONNECTED;
1097                         rpl[0] = '\0';
1098                 }
1099                 
1100                 c = Client_Next( c );
1101         }
1102         if( rpl[0] )
1103         {
1104                 /* es wurden User gefunden */
1105                 if( rpl[strlen( rpl ) - 1] == ' ' ) rpl[strlen( rpl ) - 1] = '\0';
1106                 if( ! IRC_WriteStrClient( Client, RPL_NAMREPLY_MSG, Client_ID( Client ), "*", "*", rpl )) return DISCONNECTED;
1107         }
1108         return IRC_WriteStrClient( Client, RPL_ENDOFNAMES_MSG, Client_ID( Client ), "*" );
1109 } /* IRC_NAMES */
1110
1111
1112 GLOBAL BOOLEAN IRC_ISON( CLIENT *Client, REQUEST *Req )
1113 {
1114         CHAR rpl[COMMAND_LEN];
1115         CLIENT *c;
1116         CHAR *ptr;
1117         INT i;
1118         
1119         assert( Client != NULL );
1120         assert( Req != NULL );
1121
1122         if( Client_Type( Client ) != CLIENT_USER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
1123
1124         /* Falsche Anzahl Parameter? */
1125         if(( Req->argc < 1 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
1126
1127         strcpy( rpl, RPL_ISON_MSG );
1128         for( i = 0; i < Req->argc; i++ )
1129         {
1130                 ptr = strtok( Req->argv[i], " " );
1131                 while( ptr )
1132                 {
1133                         ngt_TrimStr( ptr );
1134                         c = Client_GetFromID( ptr );
1135                         if( c && ( Client_Type( c ) == CLIENT_USER ))
1136                         {
1137                                 /* Dieser Nick ist "online" */
1138                                 strcat( rpl, ptr );
1139                                 strcat( rpl, " " );
1140                         }
1141                         ptr = strtok( NULL, " " );
1142                 }
1143         }
1144         if( rpl[strlen( rpl ) - 1] == ' ' ) rpl[strlen( rpl ) - 1] = '\0';
1145
1146         return IRC_WriteStrClient( Client, rpl, Client_ID( Client ) );
1147 } /* IRC_ISON */
1148
1149
1150 GLOBAL BOOLEAN IRC_WHOIS( CLIENT *Client, REQUEST *Req )
1151 {
1152         CLIENT *from, *target, *c;
1153         CHAR *ptr = NULL;
1154         
1155         assert( Client != NULL );
1156         assert( Req != NULL );
1157
1158         if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
1159
1160         /* Falsche Anzahl Parameter? */
1161         if(( Req->argc < 1 ) || ( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
1162
1163         /* Client suchen */
1164         c = Client_GetFromID( Req->argv[Req->argc - 1] );
1165         if(( ! c ) || ( Client_Type( c ) != CLIENT_USER )) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->argv[Req->argc - 1] );
1166
1167         /* Empfaenger des WHOIS suchen */
1168         if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_GetFromID( Req->prefix );
1169         else from = Client;
1170         if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
1171         
1172         /* Forwarden an anderen Server? */
1173         if( Req->argc > 1 )
1174         {
1175                 /* angegebenen Ziel-Server suchen */
1176                 target = Client_GetFromID( Req->argv[1] );
1177                 if( ! target ) return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[1] );
1178                 ptr = Req->argv[1];
1179         }
1180 #ifndef STRICT_RFC
1181         else if( Client_Conn( c ) == NONE )
1182         {
1183                 /* Client ist nicht von uns. Ziel-Server suchen */
1184                 target = c;
1185                 ptr = Req->argv[0];
1186         }
1187 #endif
1188         else target = NULL;
1189         
1190         if( target && ( Client_NextHop( target ) != Client_ThisServer( )) && ( Client_Type( Client_NextHop( target )) == CLIENT_SERVER )) return IRC_WriteStrClientPrefix( target, from, "WHOIS %s :%s", Req->argv[0], ptr );
1191         
1192         /* Nick, User und Name */
1193         if( ! IRC_WriteStrClient( from, RPL_WHOISUSER_MSG, Client_ID( from ), Client_ID( c ), Client_User( c ), Client_Hostname( c ), Client_Info( c ))) return DISCONNECTED;
1194
1195         /* Server */
1196         if( ! IRC_WriteStrClient( from, RPL_WHOISSERVER_MSG, Client_ID( from ), Client_ID( c ), Client_ID( Client_Introducer( c )), Client_Info( Client_Introducer( c )))) return DISCONNECTED;
1197
1198         /* IRC-Operator? */
1199         if( Client_HasMode( c, 'o' ))
1200         {
1201                 if( ! IRC_WriteStrClient( from, RPL_WHOISOPERATOR_MSG, Client_ID( from ), Client_ID( c ))) return DISCONNECTED;
1202         }
1203
1204         /* Idle (nur lokale Clients) */
1205         if( Client_Conn( c ) > NONE )
1206         {
1207                 if( ! IRC_WriteStrClient( from, RPL_WHOISIDLE_MSG, Client_ID( from ), Client_ID( c ), Conn_GetIdle( Client_Conn ( c )))) return DISCONNECTED;
1208         }
1209
1210         /* End of Whois */
1211         return IRC_WriteStrClient( from, RPL_ENDOFWHOIS_MSG, Client_ID( from ), Client_ID( c ));
1212 } /* IRC_WHOIS */
1213
1214
1215 GLOBAL BOOLEAN IRC_USERHOST( CLIENT *Client, REQUEST *Req )
1216 {
1217         CHAR rpl[COMMAND_LEN];
1218         CLIENT *c;
1219         INT max, i;
1220
1221         assert( Client != NULL );
1222         assert( Req != NULL );
1223
1224         if( Client_Type( Client ) != CLIENT_USER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
1225
1226         /* Falsche Anzahl Parameter? */
1227         if(( Req->argc < 1 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
1228
1229         if( Req->argc > 5 ) max = 5;
1230         else max = Req->argc;
1231         
1232         strcpy( rpl, RPL_USERHOST_MSG );
1233         for( i = 0; i < max; i++ )
1234         {
1235                 c = Client_GetFromID( Req->argv[i] );
1236                 if( c && ( Client_Type( c ) == CLIENT_USER ))
1237                 {
1238                         /* Dieser Nick ist "online" */
1239                         strcat( rpl, Client_ID( c ));
1240                         if( Client_HasMode( c, 'o' )) strcat( rpl, "*" );
1241                         strcat( rpl, "=" );
1242                         if( Client_HasMode( c, 'a' )) strcat( rpl, "-" );
1243                         else strcat( rpl, "+" );
1244                         strcat( rpl, Client_User( c ));
1245                         strcat( rpl, "@" );
1246                         strcat( rpl, Client_Hostname( c ));
1247                         strcat( rpl, " " );
1248                 }
1249         }
1250         if( rpl[strlen( rpl ) - 1] == ' ' ) rpl[strlen( rpl ) - 1] = '\0';
1251
1252         return IRC_WriteStrClient( Client, rpl, Client_ID( Client ) );
1253 } /* IRC_USERHOST */
1254
1255
1256 GLOBAL BOOLEAN IRC_ERROR( CLIENT *Client, REQUEST *Req )
1257 {
1258         assert( Client != NULL );
1259         assert( Req != NULL );
1260
1261         if( Req->argc < 1 ) Log( LOG_NOTICE, "Got ERROR from \"%s\"!", Client_Mask( Client ));
1262         else Log( LOG_NOTICE, "Got ERROR from \"%s\": %s!", Client_Mask( Client ), Req->argv[0] );
1263
1264         return CONNECTED;
1265 } /* IRC_ERROR */
1266
1267
1268 GLOBAL BOOLEAN IRC_LUSERS( CLIENT *Client, REQUEST *Req )
1269 {
1270         CLIENT *target, *from;
1271         INT cnt;
1272         
1273         assert( Client != NULL );
1274         assert( Req != NULL );
1275
1276         if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
1277
1278         /* Falsche Anzahl Parameter? */
1279         if(( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
1280
1281         /* Absender ermitteln */
1282         if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_GetFromID( Req->prefix );
1283         else from = Client;
1284         if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
1285
1286         /* An anderen Server forwarden? */
1287         if( Req->argc == 2 )
1288         {
1289                 target = Client_GetFromID( Req->argv[1] );
1290                 if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[1] );
1291                 else if( target != Client_ThisServer( )) return IRC_WriteStrClientPrefix( target, from, "LUSERS %s %s", Req->argv[0], Req->argv[1] );
1292         }
1293
1294         /* Wer ist der Absender? */
1295         if( Client_Type( Client ) == CLIENT_SERVER ) target = Client_GetFromID( Req->prefix );
1296         else target = Client;
1297         if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
1298         
1299         /* Users, Services und Serevr im Netz */
1300         if( ! IRC_WriteStrClient( target, RPL_LUSERCLIENT_MSG, Client_ID( target ), Client_UserCount( ), Client_ServiceCount( ), Client_ServerCount( ))) return DISCONNECTED;
1301
1302         /* IRC-Operatoren im Netz */
1303         cnt = Client_OperCount( );
1304         if( cnt > 0 )
1305         {
1306                 if( ! IRC_WriteStrClient( target, RPL_LUSEROP_MSG, Client_ID( target ), cnt )) return DISCONNECTED;
1307         }
1308
1309         /* Unbekannt Verbindungen */
1310         cnt = Client_UnknownCount( );
1311         if( cnt > 0 )
1312         {
1313                 if( ! IRC_WriteStrClient( target, RPL_LUSERUNKNOWN_MSG, Client_ID( target ), cnt )) return DISCONNECTED;
1314         }
1315
1316         /* Channels im Netz */
1317         if( ! IRC_WriteStrClient( target, RPL_LUSERCHANNELS_MSG, Client_ID( target ), Channel_Count( ))) return DISCONNECTED;
1318
1319         /* Channels im Netz */
1320         if( ! IRC_WriteStrClient( target, RPL_LUSERME_MSG, Client_ID( target ), Client_MyUserCount( ), Client_MyServiceCount( ), Client_MyServerCount( ))) return DISCONNECTED;
1321
1322         return CONNECTED;
1323 } /* IRC_LUSERS */
1324
1325
1326 GLOBAL BOOLEAN IRC_LINKS( CLIENT *Client, REQUEST *Req )
1327 {
1328         CLIENT *target, *from, *c;
1329         CHAR *mask;
1330         
1331         assert( Client != NULL );
1332         assert( Req != NULL );
1333
1334         if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
1335
1336         /* Falsche Anzahl Parameter? */
1337         if(( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
1338
1339         /* Server-Mask ermitteln */
1340         if( Req->argc > 0 ) mask = Req->argv[Req->argc - 1];
1341         else mask = "*";
1342
1343         /* Absender ermitteln */
1344         if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_GetFromID( Req->prefix );
1345         else from = Client;
1346         if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
1347         
1348         /* An anderen Server forwarden? */
1349         if( Req->argc == 2 )
1350         {
1351                 target = Client_GetFromID( Req->argv[0] );
1352                 if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[0] );
1353                 else if( target != Client_ThisServer( )) return IRC_WriteStrClientPrefix( target, from, "LINKS %s %s", Req->argv[0], Req->argv[1] );
1354         }
1355
1356         /* Wer ist der Absender? */
1357         if( Client_Type( Client ) == CLIENT_SERVER ) target = Client_GetFromID( Req->prefix );
1358         else target = Client;
1359         if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
1360         
1361         c = Client_First( );
1362         while( c )
1363         {
1364                 if( Client_Type( c ) == CLIENT_SERVER )
1365                 {
1366                         if( ! IRC_WriteStrClient( target, RPL_LINKS_MSG, Client_ID( target ), Client_ID( c ), Client_ID( Client_Introducer( c )), Client_Hops( c ), Client_Info( c ))) return DISCONNECTED;
1367                 }
1368                 c = Client_Next( c );
1369         }
1370         
1371         return IRC_WriteStrClient( target, RPL_ENDOFLINKS_MSG, Client_ID( target ), mask );
1372 } /* IRC_LINKS */
1373
1374
1375 GLOBAL BOOLEAN IRC_JOIN( CLIENT *Client, REQUEST *Req )
1376 {
1377         CLIENT *target;
1378         CHAR *chan;
1379         
1380         assert( Client != NULL );
1381         assert( Req != NULL );
1382
1383         if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
1384
1385         /* Falsche Anzahl Parameter? */
1386         if(( Req->argc > 1 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
1387
1388         /* Wer ist der Absender? */
1389         if( Client_Type( Client ) == CLIENT_SERVER ) target = Client_GetFromID( Req->prefix );
1390         else target = Client;
1391         if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
1392         
1393         /* Channel-Namen durchgehen */
1394         chan = strtok( Req->argv[0], "," );
1395         while( chan )
1396         {
1397                 if( ! Channel_Join( target, chan ))
1398                 {
1399                         /* naechsten Namen ermitteln */
1400                         chan = strtok( NULL, "," );
1401                         continue;
1402                 }
1403
1404                 /* An andere Server weiterleiten, an Client bestaetigen */
1405                 IRC_WriteStrServersPrefix( Client, target, "JOIN :%s", chan );
1406                 IRC_WriteStrRelatedChannelPrefix( Client, chan, target, "JOIN :%s", chan );
1407
1408                 Log( LOG_DEBUG, "User \"%s\" joined channel \"%s\".", Client_Mask( target ), Req->argv[0] );
1409                 
1410                 /* naechsten Namen ermitteln */
1411                 chan = strtok( NULL, "," );
1412         }
1413         return CONNECTED;
1414 } /* IRC_JOIN */
1415
1416
1417 GLOBAL BOOLEAN IRC_PART( CLIENT *Client, REQUEST *Req )
1418 {
1419         CLIENT *target;
1420         CHAR *chan;
1421
1422         assert( Client != NULL );
1423         assert( Req != NULL );
1424
1425         if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
1426
1427         /* Falsche Anzahl Parameter? */
1428         if(( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
1429
1430         /* Wer ist der Absender? */
1431         if( Client_Type( Client ) == CLIENT_SERVER ) target = Client_GetFromID( Req->prefix );
1432         else target = Client;
1433         if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
1434
1435         /* Channel-Namen durchgehen */
1436         chan = strtok( Req->argv[0], "," );
1437         while( chan )
1438         {
1439                 if( ! Channel_Part( target, Client, chan, Req->argc > 1 ? Req->argv[1] : Client_ID( target )))
1440                 {
1441                         /* naechsten Namen ermitteln */
1442                         chan = strtok( NULL, "," );
1443                         continue;
1444                 }
1445
1446                 /* naechsten Namen ermitteln */
1447                 chan = strtok( NULL, "," );
1448         }
1449         return CONNECTED;
1450 } /* IRC_PART */
1451
1452
1453 LOCAL BOOLEAN Hello_User( CLIENT *Client )
1454 {
1455         assert( Client != NULL );
1456
1457         /* Passwort ueberpruefen */
1458         if( strcmp( Client_Password( Client ), Conf_ServerPwd ) != 0 )
1459         {
1460                 /* Falsches Passwort */
1461                 Log( LOG_ERR, "User \"%s\" rejected (connection %d): Bad password!", Client_Mask( Client ), Client_Conn( Client ));
1462                 Conn_Close( Client_Conn( Client ), NULL, "Bad password", TRUE );
1463                 return DISCONNECTED;
1464         }
1465
1466         Log( LOG_NOTICE, "User \"%s\" registered (connection %d).", Client_Mask( Client ), Client_Conn( Client ));
1467
1468         /* Andere Server informieren */
1469         IRC_WriteStrServers( NULL, "NICK %s 1 %s %s 1 +%s :%s", Client_ID( Client ), Client_User( Client ), Client_Hostname( Client ), Client_Modes( Client ), Client_Info( Client ));
1470
1471         if( ! IRC_WriteStrClient( Client, RPL_WELCOME_MSG, Client_ID( Client ), Client_Mask( Client ))) return FALSE;
1472         if( ! IRC_WriteStrClient( Client, RPL_YOURHOST_MSG, Client_ID( Client ), Client_ID( Client_ThisServer( )))) return FALSE;
1473         if( ! IRC_WriteStrClient( Client, RPL_CREATED_MSG, Client_ID( Client ), NGIRCd_StartStr )) return FALSE;
1474         if( ! IRC_WriteStrClient( Client, RPL_MYINFO_MSG, Client_ID( Client ), Client_ID( Client_ThisServer( )))) return FALSE;
1475
1476         Client_SetType( Client, CLIENT_USER );
1477
1478         return Show_MOTD( Client );
1479 } /* Hello_User */
1480
1481
1482 LOCAL BOOLEAN Show_MOTD( CLIENT *Client )
1483 {
1484         BOOLEAN ok;
1485         CHAR line[127];
1486         FILE *fd;
1487         
1488         assert( Client != NULL );
1489
1490         fd = fopen( Conf_MotdFile, "r" );
1491         if( ! fd )
1492         {
1493                 Log( LOG_WARNING, "Can't read MOTD file \"%s\": %s", Conf_MotdFile, strerror( errno ));
1494                 return IRC_WriteStrClient( Client, ERR_NOMOTD_MSG, Client_ID( Client ) );
1495         }
1496         
1497         IRC_WriteStrClient( Client, RPL_MOTDSTART_MSG, Client_ID( Client ), Client_ID( Client_ThisServer( )));
1498         while( TRUE )
1499         {
1500                 if( ! fgets( line, 126, fd )) break;
1501                 if( line[strlen( line ) - 1] == '\n' ) line[strlen( line ) - 1] = '\0';
1502                 if( ! IRC_WriteStrClient( Client, RPL_MOTD_MSG, Client_ID( Client ), line ))
1503                 {
1504                         fclose( fd );
1505                         return FALSE;
1506                 }
1507         }
1508         ok = IRC_WriteStrClient( Client, RPL_ENDOFMOTD_MSG, Client_ID( Client ) );
1509
1510         fclose( fd );
1511         
1512         return ok;
1513 } /* Show_MOTD */
1514
1515
1516 LOCAL VOID Kill_Nick( CHAR *Nick )
1517 {
1518         Log( LOG_ERR, "User(s) with nick \"%s\" will be disconnected!", Nick );
1519         /* FIXME */
1520         Log( LOG_ALERT, "[Kill_Nick() not implemented - OOOPS!]" );
1521 } /* Kill_Nick */
1522
1523
1524 /* -eof- */