2 c23199d9 2002-02-27 alex * ngIRCd -- The Next Generation IRC Daemon
3 c23199d9 2002-02-27 alex * Copyright (c)2001,2002 by Alexander Barton (alex@barton.de)
5 490f28ff 2002-12-12 alex * This program is free software; you can redistribute it and/or modify
6 490f28ff 2002-12-12 alex * it under the terms of the GNU General Public License as published by
7 490f28ff 2002-12-12 alex * the Free Software Foundation; either version 2 of the License, or
8 490f28ff 2002-12-12 alex * (at your option) any later version.
9 490f28ff 2002-12-12 alex * Please read the file COPYING, README and AUTHORS for more information.
11 490f28ff 2002-12-12 alex * Login and logout
15 ca33cbda 2002-03-12 alex #include "portab.h"
17 cb76d96e 2004-03-11 alex static char UNUSED id[] = "$Id: irc-login.c,v 1.40 2004/03/11 22:16:31 alex Exp $";
19 ca33cbda 2002-03-12 alex #include "imp.h"
20 c23199d9 2002-02-27 alex #include <assert.h>
21 c23199d9 2002-02-27 alex #include <stdio.h>
22 c23199d9 2002-02-27 alex #include <stdlib.h>
23 c23199d9 2002-02-27 alex #include <string.h>
24 57c7e236 2004-01-17 alex #include <strings.h>
26 c23199d9 2002-02-27 alex #include "ngircd.h"
27 c2f60abe 2002-05-27 alex #include "resolve.h"
28 b8d7dcec 2002-12-30 alex #include "conn-func.h"
29 a2544e49 2002-12-30 alex #include "conf.h"
30 c2f60abe 2002-05-27 alex #include "client.h"
31 c2f60abe 2002-05-27 alex #include "channel.h"
32 c23199d9 2002-02-27 alex #include "log.h"
33 c23199d9 2002-02-27 alex #include "messages.h"
34 c2f60abe 2002-05-27 alex #include "parse.h"
35 ff988331 2003-01-08 alex #include "irc.h"
36 0c471b84 2002-11-30 alex #include "irc-info.h"
37 c2f60abe 2002-05-27 alex #include "irc-write.h"
38 05e2c0f0 2003-12-04 alex #include "cvs-version.h"
40 ca33cbda 2002-03-12 alex #include "exp.h"
41 c23199d9 2002-02-27 alex #include "irc-login.h"
44 c2f60abe 2002-05-27 alex LOCAL BOOLEAN Hello_User PARAMS(( CLIENT *Client ));
45 c2f60abe 2002-05-27 alex LOCAL VOID Kill_Nick PARAMS(( CHAR *Nick, CHAR *Reason ));
48 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
49 c2f60abe 2002-05-27 alex IRC_PASS( CLIENT *Client, REQUEST *Req )
51 c23199d9 2002-02-27 alex assert( Client != NULL );
52 c23199d9 2002-02-27 alex assert( Req != NULL );
54 c23199d9 2002-02-27 alex /* Fehler liefern, wenn kein lokaler Client */
55 c23199d9 2002-02-27 alex if( Client_Conn( Client ) <= NONE ) return IRC_WriteStrClient( Client, ERR_UNKNOWNCOMMAND_MSG, Client_ID( Client ), Req->command );
57 c23199d9 2002-02-27 alex if(( Client_Type( Client ) == CLIENT_UNKNOWN ) && ( Req->argc == 1))
59 c23199d9 2002-02-27 alex /* noch nicht registrierte unbekannte Verbindung */
60 c23199d9 2002-02-27 alex Log( LOG_DEBUG, "Connection %d: got PASS command ...", Client_Conn( Client ));
62 c23199d9 2002-02-27 alex /* Passwort speichern */
63 c23199d9 2002-02-27 alex Client_SetPassword( Client, Req->argv[0] );
65 c23199d9 2002-02-27 alex Client_SetType( Client, CLIENT_GOTPASS );
66 c23199d9 2002-02-27 alex return CONNECTED;
68 c23199d9 2002-02-27 alex else if((( Client_Type( Client ) == CLIENT_UNKNOWN ) || ( Client_Type( Client ) == CLIENT_UNKNOWNSERVER )) && (( Req->argc == 3 ) || ( Req->argc == 4 )))
70 65f3adca 2002-11-26 alex CHAR c2, c4, *type, *impl, *serverver, *flags, *ptr, *ircflags;
71 c67bb2ac 2002-09-02 alex INT protohigh, protolow;
73 c23199d9 2002-02-27 alex /* noch nicht registrierte Server-Verbindung */
74 c23199d9 2002-02-27 alex Log( LOG_DEBUG, "Connection %d: got PASS command (new server link) ...", Client_Conn( Client ));
76 c23199d9 2002-02-27 alex /* Passwort speichern */
77 c23199d9 2002-02-27 alex Client_SetPassword( Client, Req->argv[0] );
79 ad1cbe34 2002-09-03 alex /* Protokollversion ermitteln */
80 ad1cbe34 2002-09-03 alex if( strlen( Req->argv[1] ) >= 4 )
82 55ee4c95 2002-09-03 alex c2 = Req->argv[1][2];
83 55ee4c95 2002-09-03 alex c4 = Req->argv[1][4];
85 ad1cbe34 2002-09-03 alex Req->argv[1][4] = '\0';
86 c67bb2ac 2002-09-02 alex protolow = atoi( &Req->argv[1][2] );
87 c67bb2ac 2002-09-02 alex Req->argv[1][2] = '\0';
88 c67bb2ac 2002-09-02 alex protohigh = atoi( Req->argv[1] );
90 55ee4c95 2002-09-03 alex Req->argv[1][2] = c2;
91 55ee4c95 2002-09-03 alex Req->argv[1][4] = c4;
93 ad1cbe34 2002-09-03 alex else protohigh = protolow = 0;
95 ad1cbe34 2002-09-03 alex /* Protokoll-Typ */
96 ad1cbe34 2002-09-03 alex if( strlen( Req->argv[1] ) > 4 ) type = &Req->argv[1][4];
97 ad1cbe34 2002-09-03 alex else type = NULL;
99 65f3adca 2002-11-26 alex /* IRC-Flags (nach RFC 2813) */
100 65f3adca 2002-11-26 alex if( Req->argc >= 4 ) ircflags = Req->argv[3];
101 65f3adca 2002-11-26 alex else ircflags = "";
103 c67bb2ac 2002-09-02 alex /* Implementation, Version und ngIRCd-Flags */
104 c67bb2ac 2002-09-02 alex impl = Req->argv[2];
105 c67bb2ac 2002-09-02 alex ptr = strchr( impl, '|' );
106 c67bb2ac 2002-09-02 alex if( ptr ) *ptr = '\0';
108 ad1cbe34 2002-09-03 alex if( type && ( strcmp( type, PROTOIRCPLUS ) == 0 ))
110 ad1cbe34 2002-09-03 alex /* auf der anderen Seite laeuft ein Server, der
111 ad1cbe34 2002-09-03 alex * ebenfalls das IRC+-Protokoll versteht */
112 c67bb2ac 2002-09-02 alex serverver = ptr + 1;
113 c67bb2ac 2002-09-02 alex flags = strchr( serverver, ':' );
114 c67bb2ac 2002-09-02 alex if( flags )
116 c67bb2ac 2002-09-02 alex *flags = '\0';
119 c67bb2ac 2002-09-02 alex else flags = "";
120 9f122037 2002-12-03 alex Log( LOG_INFO, "Peer announces itself as %s-%s using protocol %d.%d/IRC+ (flags: \"%s\").", impl, serverver, protohigh, protolow, flags );
124 65f3adca 2002-11-26 alex /* auf der anderen Seite laeuft ein Server, der
125 65f3adca 2002-11-26 alex * nur das Originalprotokoll unterstuetzt */
126 65f3adca 2002-11-26 alex serverver = "";
127 65f3adca 2002-11-26 alex if( strchr( ircflags, 'Z' )) flags = "Z";
128 65f3adca 2002-11-26 alex else flags = "";
129 9f122037 2002-12-03 alex Log( LOG_INFO, "Peer announces itself as \"%s\" using protocol %d.%d (flags: \"%s\").", impl, protohigh, protolow, flags );
132 c23199d9 2002-02-27 alex Client_SetType( Client, CLIENT_GOTPASSSERVER );
133 5aa9c8f4 2002-09-03 alex Client_SetFlags( Client, flags );
135 c23199d9 2002-02-27 alex return CONNECTED;
137 c23199d9 2002-02-27 alex else if(( Client_Type( Client ) == CLIENT_UNKNOWN ) || ( Client_Type( Client ) == CLIENT_UNKNOWNSERVER ))
139 c23199d9 2002-02-27 alex /* Falsche Anzahl Parameter? */
140 c23199d9 2002-02-27 alex return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
142 c23199d9 2002-02-27 alex else return IRC_WriteStrClient( Client, ERR_ALREADYREGISTRED_MSG, Client_ID( Client ));
143 c23199d9 2002-02-27 alex } /* IRC_PASS */
146 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
147 c2f60abe 2002-05-27 alex IRC_NICK( CLIENT *Client, REQUEST *Req )
149 c23199d9 2002-02-27 alex CLIENT *intr_c, *target, *c;
150 c23199d9 2002-02-27 alex CHAR *modes;
152 c23199d9 2002-02-27 alex assert( Client != NULL );
153 c23199d9 2002-02-27 alex assert( Req != NULL );
155 c23199d9 2002-02-27 alex /* Zumindest BitchX sendet NICK-USER in der falschen Reihenfolge. */
156 c23199d9 2002-02-27 alex #ifndef STRICT_RFC
157 c23199d9 2002-02-27 alex 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 ))
159 c23199d9 2002-02-27 alex 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 ))
162 c23199d9 2002-02-27 alex /* User-Registrierung bzw. Nick-Aenderung */
164 c23199d9 2002-02-27 alex /* Falsche Anzahl Parameter? */
165 c23199d9 2002-02-27 alex if( Req->argc != 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
167 c23199d9 2002-02-27 alex /* "Ziel-Client" ermitteln */
168 c23199d9 2002-02-27 alex if( Client_Type( Client ) == CLIENT_SERVER )
170 bc4ed226 2002-03-25 alex target = Client_Search( Req->prefix );
171 c23199d9 2002-02-27 alex if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->argv[0] );
175 c23199d9 2002-02-27 alex /* Ist der Client "restricted"? */
176 c23199d9 2002-02-27 alex if( Client_HasMode( Client, 'r' )) return IRC_WriteStrClient( Client, ERR_RESTRICTED_MSG, Client_ID( Client ));
177 c23199d9 2002-02-27 alex target = Client;
180 c23199d9 2002-02-27 alex #ifndef STRICT_RFC
181 c23199d9 2002-02-27 alex /* Wenn der Client zu seinem eigenen Nick wechseln will, so machen
182 c23199d9 2002-02-27 alex * wir nichts. So macht es das Original und mind. Snak hat probleme,
183 c23199d9 2002-02-27 alex * wenn wir es nicht so machen. Ob es so okay ist? Hm ... */
184 c23199d9 2002-02-27 alex if( strcmp( Client_ID( target ), Req->argv[0] ) == 0 ) return CONNECTED;
187 c23199d9 2002-02-27 alex /* pruefen, ob Nick bereits vergeben. Speziallfall: der Client
188 c23199d9 2002-02-27 alex * will nur die Gross- und Kleinschreibung aendern. Das darf
189 c23199d9 2002-02-27 alex * er natuerlich machen :-) */
190 c23199d9 2002-02-27 alex if( strcasecmp( Client_ID( target ), Req->argv[0] ) != 0 )
192 c23199d9 2002-02-27 alex if( ! Client_CheckNick( target, Req->argv[0] )) return CONNECTED;
195 c23199d9 2002-02-27 alex if(( Client_Type( target ) != CLIENT_USER ) && ( Client_Type( target ) != CLIENT_SERVER ))
197 c23199d9 2002-02-27 alex /* Neuer Client */
198 c23199d9 2002-02-27 alex Log( LOG_DEBUG, "Connection %d: got valid NICK command ...", Client_Conn( Client ));
200 c23199d9 2002-02-27 alex /* Client-Nick registrieren */
201 c23199d9 2002-02-27 alex Client_SetID( target, Req->argv[0] );
203 c23199d9 2002-02-27 alex /* schon ein USER da? Dann registrieren! */
204 c23199d9 2002-02-27 alex if( Client_Type( Client ) == CLIENT_GOTUSER ) return Hello_User( Client );
205 c23199d9 2002-02-27 alex else Client_SetType( Client, CLIENT_GOTNICK );
209 c23199d9 2002-02-27 alex /* Nick-Aenderung */
210 5b4e9152 2002-04-08 alex if( Client_Conn( target ) > NONE )
212 5b4e9152 2002-04-08 alex /* lokaler Client */
213 5b4e9152 2002-04-08 alex Log( LOG_INFO, "User \"%s\" changed nick (connection %d): \"%s\" -> \"%s\".", Client_Mask( target ), Client_Conn( target ), Client_ID( target ), Req->argv[0] );
217 5b4e9152 2002-04-08 alex /* Remote-Client */
218 5b4e9152 2002-04-08 alex Log( LOG_DEBUG, "User \"%s\" changed nick: \"%s\" -> \"%s\".", Client_Mask( target ), Client_ID( target ), Req->argv[0] );
221 0370c484 2002-03-02 alex /* alle betroffenen User und Server ueber Nick-Aenderung informieren */
222 0370c484 2002-03-02 alex if( Client_Type( Client ) == CLIENT_USER ) IRC_WriteStrClientPrefix( Client, Client, "NICK :%s", Req->argv[0] );
223 0370c484 2002-03-02 alex IRC_WriteStrServersPrefix( Client, target, "NICK :%s", Req->argv[0] );
224 0370c484 2002-03-02 alex IRC_WriteStrRelatedPrefix( target, target, FALSE, "NICK :%s", Req->argv[0] );
226 c23199d9 2002-02-27 alex /* neuen Client-Nick speichern */
227 c23199d9 2002-02-27 alex Client_SetID( target, Req->argv[0] );
228 7b6e2662 2003-11-05 alex IRC_SetPenalty( target, 2 );
231 c23199d9 2002-02-27 alex return CONNECTED;
233 c23199d9 2002-02-27 alex else if( Client_Type( Client ) == CLIENT_SERVER )
235 c23199d9 2002-02-27 alex /* Server fuehrt neuen Client ein */
237 c23199d9 2002-02-27 alex /* Falsche Anzahl Parameter? */
238 c23199d9 2002-02-27 alex if( Req->argc != 7 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
240 c23199d9 2002-02-27 alex /* Nick ueberpruefen */
241 bc4ed226 2002-03-25 alex c = Client_Search( Req->argv[0] );
244 c23199d9 2002-02-27 alex /* Der neue Nick ist auf diesem Server bereits registriert:
245 c23199d9 2002-02-27 alex * sowohl der neue, als auch der alte Client muessen nun
246 c23199d9 2002-02-27 alex * disconnectiert werden. */
247 c23199d9 2002-02-27 alex Log( LOG_ERR, "Server %s introduces already registered nick \"%s\"!", Client_ID( Client ), Req->argv[0] );
248 c23199d9 2002-02-27 alex Kill_Nick( Req->argv[0], "Nick collision" );
249 c23199d9 2002-02-27 alex return CONNECTED;
252 c23199d9 2002-02-27 alex /* Server, zu dem der Client connectiert ist, suchen */
253 c23199d9 2002-02-27 alex intr_c = Client_GetFromToken( Client, atoi( Req->argv[4] ));
254 c23199d9 2002-02-27 alex if( ! intr_c )
256 c23199d9 2002-02-27 alex Log( LOG_ERR, "Server %s introduces nick \"%s\" on unknown server!?", Client_ID( Client ), Req->argv[0] );
257 c23199d9 2002-02-27 alex Kill_Nick( Req->argv[0], "Unknown server" );
258 c23199d9 2002-02-27 alex return CONNECTED;
261 c23199d9 2002-02-27 alex /* Neue Client-Struktur anlegen */
262 c23199d9 2002-02-27 alex 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 );
265 c23199d9 2002-02-27 alex /* Eine neue Client-Struktur konnte nicht angelegt werden.
266 c23199d9 2002-02-27 alex * Der Client muss disconnectiert werden, damit der Netz-
267 c23199d9 2002-02-27 alex * status konsistent bleibt. */
268 c23199d9 2002-02-27 alex Log( LOG_ALERT, "Can't create client structure! (on connection %d)", Client_Conn( Client ));
269 c23199d9 2002-02-27 alex Kill_Nick( Req->argv[0], "Server error" );
270 c23199d9 2002-02-27 alex return CONNECTED;
273 c23199d9 2002-02-27 alex modes = Client_Modes( c );
274 c23199d9 2002-02-27 alex 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": "" );
275 c23199d9 2002-02-27 alex 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": "" );
277 c23199d9 2002-02-27 alex /* Andere Server, ausser dem Introducer, informieren */
278 c23199d9 2002-02-27 alex 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] );
280 c23199d9 2002-02-27 alex return CONNECTED;
282 c23199d9 2002-02-27 alex else return IRC_WriteStrClient( Client, ERR_ALREADYREGISTRED_MSG, Client_ID( Client ));
283 c23199d9 2002-02-27 alex } /* IRC_NICK */
286 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
287 c2f60abe 2002-05-27 alex IRC_USER( CLIENT *Client, REQUEST *Req )
289 b79b315d 2003-12-27 alex #ifdef IDENTAUTH
293 c23199d9 2002-02-27 alex assert( Client != NULL );
294 c23199d9 2002-02-27 alex assert( Req != NULL );
296 c23199d9 2002-02-27 alex #ifndef STRICT_RFC
297 c23199d9 2002-02-27 alex if( Client_Type( Client ) == CLIENT_GOTNICK || Client_Type( Client ) == CLIENT_GOTPASS || Client_Type( Client ) == CLIENT_UNKNOWN )
299 c23199d9 2002-02-27 alex if( Client_Type( Client ) == CLIENT_GOTNICK || Client_Type( Client ) == CLIENT_GOTPASS )
302 6667bb6b 2004-02-04 alex /* Wrong number of parameters? */
303 c23199d9 2002-02-27 alex if( Req->argc != 4 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
305 6667bb6b 2004-02-04 alex /* User name */
306 b79b315d 2003-12-27 alex #ifdef IDENTAUTH
307 b79b315d 2003-12-27 alex ptr = Client_User( Client );
308 6667bb6b 2004-02-04 alex if( ! ptr || ! *ptr || *ptr == '~' ) Client_SetUser( Client, Req->argv[0], FALSE );
310 c23199d9 2002-02-27 alex Client_SetUser( Client, Req->argv[0], FALSE );
313 6667bb6b 2004-02-04 alex /* "Real name" or user info text: Don't set it to the empty string, the original ircd
314 6667bb6b 2004-02-04 alex * can't deal with such "real names" (e. g. "USER user * * :") ... */
315 6667bb6b 2004-02-04 alex if( *Req->argv[3] ) Client_SetInfo( Client, Req->argv[3] );
316 6667bb6b 2004-02-04 alex else Client_SetInfo( Client, "-" );
318 c23199d9 2002-02-27 alex Log( LOG_DEBUG, "Connection %d: got valid USER command ...", Client_Conn( Client ));
319 c23199d9 2002-02-27 alex if( Client_Type( Client ) == CLIENT_GOTNICK ) return Hello_User( Client );
320 c23199d9 2002-02-27 alex else Client_SetType( Client, CLIENT_GOTUSER );
321 c23199d9 2002-02-27 alex return CONNECTED;
323 c23199d9 2002-02-27 alex else if( Client_Type( Client ) == CLIENT_USER || Client_Type( Client ) == CLIENT_SERVER || Client_Type( Client ) == CLIENT_SERVICE )
325 c23199d9 2002-02-27 alex return IRC_WriteStrClient( Client, ERR_ALREADYREGISTRED_MSG, Client_ID( Client ));
327 c23199d9 2002-02-27 alex else return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
328 c23199d9 2002-02-27 alex } /* IRC_USER */
331 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
332 c2f60abe 2002-05-27 alex IRC_QUIT( CLIENT *Client, REQUEST *Req )
334 c23199d9 2002-02-27 alex CLIENT *target;
336 c23199d9 2002-02-27 alex assert( Client != NULL );
337 c23199d9 2002-02-27 alex assert( Req != NULL );
339 7f795915 2002-04-14 alex if ( Client_Type( Client ) == CLIENT_SERVER )
341 c23199d9 2002-02-27 alex /* Server */
343 c23199d9 2002-02-27 alex /* Falsche Anzahl Parameter? */
344 c23199d9 2002-02-27 alex if( Req->argc > 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
346 c23199d9 2002-02-27 alex target = Client_Search( Req->prefix );
347 c23199d9 2002-02-27 alex if( ! target )
349 9fc7e66f 2002-03-11 alex /* Den Client kennen wir nicht (mehr), also nichts zu tun. */
350 f7a0ff1f 2002-03-11 alex Log( LOG_WARNING, "Got QUIT from %s for unknown client!?", Client_ID( Client ));
351 c23199d9 2002-02-27 alex return CONNECTED;
354 50ec7a56 2002-03-11 alex if( Req->argc == 0 ) Client_Destroy( target, "Got QUIT command.", NULL, TRUE );
355 50ec7a56 2002-03-11 alex else Client_Destroy( target, "Got QUIT command.", Req->argv[0], TRUE );
357 c23199d9 2002-02-27 alex return CONNECTED;
361 7f795915 2002-04-14 alex /* User, Service, oder noch nicht registriert */
363 7f795915 2002-04-14 alex /* Falsche Anzahl Parameter? */
364 7f795915 2002-04-14 alex if( Req->argc > 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
366 7f795915 2002-04-14 alex if( Req->argc == 0 ) Conn_Close( Client_Conn( Client ), "Got QUIT command.", NULL, TRUE );
367 7f795915 2002-04-14 alex else Conn_Close( Client_Conn( Client ), "Got QUIT command.", Req->argv[0], TRUE );
369 7f795915 2002-04-14 alex return DISCONNECTED;
371 c23199d9 2002-02-27 alex } /* IRC_QUIT */
374 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
375 c2f60abe 2002-05-27 alex IRC_PING( CLIENT *Client, REQUEST *Req )
377 c23199d9 2002-02-27 alex CLIENT *target, *from;
379 c23199d9 2002-02-27 alex assert( Client != NULL );
380 c23199d9 2002-02-27 alex assert( Req != NULL );
382 c23199d9 2002-02-27 alex /* Falsche Anzahl Parameter? */
383 c23199d9 2002-02-27 alex if( Req->argc < 1 ) return IRC_WriteStrClient( Client, ERR_NOORIGIN_MSG, Client_ID( Client ));
384 5fa05dce 2002-03-10 alex #ifdef STRICT_RFC
385 c23199d9 2002-02-27 alex if( Req->argc > 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
388 5fa05dce 2002-03-10 alex if( Req->argc > 1 )
390 c23199d9 2002-02-27 alex /* es wurde ein Ziel-Client angegeben */
391 bc4ed226 2002-03-25 alex target = Client_Search( Req->argv[1] );
392 ae6a7e7c 2003-01-01 alex if(( ! target ) || ( Client_Type( target ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[1] );
393 c23199d9 2002-02-27 alex if( target != Client_ThisServer( ))
395 c23199d9 2002-02-27 alex /* ok, forwarden */
396 bc4ed226 2002-03-25 alex if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
397 c23199d9 2002-02-27 alex else from = Client;
398 c23199d9 2002-02-27 alex if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->prefix );
399 c23199d9 2002-02-27 alex return IRC_WriteStrClientPrefix( target, from, "PING %s :%s", Client_ID( from ), Req->argv[1] );
403 c23199d9 2002-02-27 alex Log( LOG_DEBUG, "Connection %d: got PING, sending PONG ...", Client_Conn( Client ));
404 c23199d9 2002-02-27 alex return IRC_WriteStrClient( Client, "PONG %s :%s", Client_ID( Client_ThisServer( )), Client_ID( Client ));
405 c23199d9 2002-02-27 alex } /* IRC_PING */
408 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
409 c2f60abe 2002-05-27 alex IRC_PONG( CLIENT *Client, REQUEST *Req )
411 c23199d9 2002-02-27 alex CLIENT *target, *from;
413 c23199d9 2002-02-27 alex assert( Client != NULL );
414 c23199d9 2002-02-27 alex assert( Req != NULL );
416 c23199d9 2002-02-27 alex /* Falsche Anzahl Parameter? */
417 c23199d9 2002-02-27 alex if( Req->argc < 1 ) return IRC_WriteStrClient( Client, ERR_NOORIGIN_MSG, Client_ID( Client ));
418 c23199d9 2002-02-27 alex if( Req->argc > 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
420 c23199d9 2002-02-27 alex /* forwarden? */
421 c23199d9 2002-02-27 alex if( Req->argc == 2 )
423 bc4ed226 2002-03-25 alex target = Client_Search( Req->argv[1] );
424 ae6a7e7c 2003-01-01 alex if(( ! target ) || ( Client_Type( target ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[1] );
425 c23199d9 2002-02-27 alex if( target != Client_ThisServer( ))
427 c23199d9 2002-02-27 alex /* ok, forwarden */
428 bc4ed226 2002-03-25 alex if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
429 c23199d9 2002-02-27 alex else from = Client;
430 c23199d9 2002-02-27 alex if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->prefix );
431 c23199d9 2002-02-27 alex return IRC_WriteStrClientPrefix( target, from, "PONG %s :%s", Client_ID( from ), Req->argv[1] );
435 c23199d9 2002-02-27 alex /* Der Connection-Timestamp wurde schon beim Lesen aus dem Socket
436 bcc51385 2002-03-26 alex * aktualisiert, daher muss das hier nicht mehr gemacht werden. */
438 c23199d9 2002-02-27 alex if( Client_Conn( Client ) > NONE ) Log( LOG_DEBUG, "Connection %d: received PONG. Lag: %ld seconds.", Client_Conn( Client ), time( NULL ) - Conn_LastPing( Client_Conn( Client )));
439 c23199d9 2002-02-27 alex else Log( LOG_DEBUG, "Connection %d: received PONG.", Client_Conn( Client ));
441 c23199d9 2002-02-27 alex return CONNECTED;
442 c23199d9 2002-02-27 alex } /* IRC_PONG */
445 c2f60abe 2002-05-27 alex LOCAL BOOLEAN
446 c2f60abe 2002-05-27 alex Hello_User( CLIENT *Client )
448 05e2c0f0 2003-12-04 alex #ifdef CVSDATE
449 05e2c0f0 2003-12-04 alex CHAR ver[12], vertxt[30];
452 c23199d9 2002-02-27 alex assert( Client != NULL );
454 05e2c0f0 2003-12-04 alex /* Check password ... */
455 c23199d9 2002-02-27 alex if( strcmp( Client_Password( Client ), Conf_ServerPwd ) != 0 )
457 05e2c0f0 2003-12-04 alex /* Bad password! */
458 c23199d9 2002-02-27 alex Log( LOG_ERR, "User \"%s\" rejected (connection %d): Bad password!", Client_Mask( Client ), Client_Conn( Client ));
459 c23199d9 2002-02-27 alex Conn_Close( Client_Conn( Client ), NULL, "Bad password", TRUE );
460 c23199d9 2002-02-27 alex return DISCONNECTED;
463 c23199d9 2002-02-27 alex Log( LOG_NOTICE, "User \"%s\" registered (connection %d).", Client_Mask( Client ), Client_Conn( Client ));
465 05e2c0f0 2003-12-04 alex /* Inform other servers */
466 c23199d9 2002-02-27 alex 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 ));
468 05e2c0f0 2003-12-04 alex /* Welcome :-) */
469 c23199d9 2002-02-27 alex if( ! IRC_WriteStrClient( Client, RPL_WELCOME_MSG, Client_ID( Client ), Client_Mask( Client ))) return FALSE;
471 05e2c0f0 2003-12-04 alex /* Version and system type */
472 05e2c0f0 2003-12-04 alex #ifdef CVSDATE
473 05e2c0f0 2003-12-04 alex strlcpy( ver, CVSDATE, sizeof( ver ));
474 05e2c0f0 2003-12-04 alex strncpy( ver + 4, ver + 5, 2 );
475 05e2c0f0 2003-12-04 alex strncpy( ver + 6, ver + 8, 3 );
476 05e2c0f0 2003-12-04 alex snprintf( vertxt, sizeof( vertxt ), "%s(%s)", PACKAGE_VERSION, ver );
477 05e2c0f0 2003-12-04 alex if( ! IRC_WriteStrClient( Client, RPL_YOURHOST_MSG, Client_ID( Client ), Client_ID( Client_ThisServer( )), vertxt, TARGET_CPU, TARGET_VENDOR, TARGET_OS )) return FALSE;
479 62796722 2003-03-31 alex if( ! IRC_WriteStrClient( Client, RPL_YOURHOST_MSG, Client_ID( Client ), Client_ID( Client_ThisServer( )), PACKAGE_VERSION, TARGET_CPU, TARGET_VENDOR, TARGET_OS )) return FALSE;
482 c23199d9 2002-02-27 alex if( ! IRC_WriteStrClient( Client, RPL_CREATED_MSG, Client_ID( Client ), NGIRCd_StartStr )) return FALSE;
483 05e2c0f0 2003-12-04 alex #ifdef CVSDATE
484 05e2c0f0 2003-12-04 alex if( ! IRC_WriteStrClient( Client, RPL_MYINFO_MSG, Client_ID( Client ), Client_ID( Client_ThisServer( )), vertxt, USERMODES, CHANMODES )) return FALSE;
486 62796722 2003-03-31 alex if( ! IRC_WriteStrClient( Client, RPL_MYINFO_MSG, Client_ID( Client ), Client_ID( Client_ThisServer( )), PACKAGE_VERSION, USERMODES, CHANMODES )) return FALSE;
489 a3f59f1a 2002-12-22 alex /* Features */
490 c428ac75 2003-01-02 alex if( ! IRC_WriteStrClient( Client, RPL_ISUPPORT_MSG, Client_ID( Client ), CLIENT_NICK_LEN - 1, CHANNEL_TOPIC_LEN - 1, CLIENT_AWAY_LEN - 1, Conf_MaxJoins )) return DISCONNECTED;
492 c23199d9 2002-02-27 alex Client_SetType( Client, CLIENT_USER );
494 c23199d9 2002-02-27 alex if( ! IRC_Send_LUSERS( Client )) return DISCONNECTED;
495 c23199d9 2002-02-27 alex if( ! IRC_Show_MOTD( Client )) return DISCONNECTED;
497 7b6e2662 2003-11-05 alex /* Suspend the client for a second ... */
498 7b6e2662 2003-11-05 alex IRC_SetPenalty( Client, 1 );
500 c23199d9 2002-02-27 alex return CONNECTED;
501 c23199d9 2002-02-27 alex } /* Hello_User */
505 c2f60abe 2002-05-27 alex Kill_Nick( CHAR *Nick, CHAR *Reason )
509 c23199d9 2002-02-27 alex assert( Nick != NULL );
510 c23199d9 2002-02-27 alex assert( Reason != NULL );
512 cb76d96e 2004-03-11 alex r.prefix = (CHAR *)Client_ThisServer( );
513 ff988331 2003-01-08 alex r.argv[0] = Nick;
514 ff988331 2003-01-08 alex r.argv[1] = Reason;
515 ff988331 2003-01-08 alex r.argc = 2;
517 ff988331 2003-01-08 alex Log( LOG_ERR, "User(s) with nick \"%s\" will be disconnected: %s", Nick, Reason );
518 ff988331 2003-01-08 alex IRC_KILL( Client_ThisServer( ), &r );
519 c23199d9 2002-02-27 alex } /* Kill_Nick */
522 c23199d9 2002-02-27 alex /* -eof- */