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