Blame


1 c23199d9 2002-02-27 alex /*
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)
4 c23199d9 2002-02-27 alex *
5 c23199d9 2002-02-27 alex * Dieses Programm ist freie Software. Sie koennen es unter den Bedingungen
6 c23199d9 2002-02-27 alex * der GNU General Public License (GPL), wie von der Free Software Foundation
7 c23199d9 2002-02-27 alex * herausgegeben, weitergeben und/oder modifizieren, entweder unter Version 2
8 c23199d9 2002-02-27 alex * der Lizenz oder (wenn Sie es wuenschen) jeder spaeteren Version.
9 c23199d9 2002-02-27 alex * Naehere Informationen entnehmen Sie bitter der Datei COPYING. Eine Liste
10 c23199d9 2002-02-27 alex * der an ngIRCd beteiligten Autoren finden Sie in der Datei AUTHORS.
11 c23199d9 2002-02-27 alex *
12 2b6dbb07 2002-09-22 alex * $Id: irc-login.c,v 1.22 2002/09/22 21:40:33 alex Exp $
13 c23199d9 2002-02-27 alex *
14 c23199d9 2002-02-27 alex * irc-login.c: Anmeldung und Abmeldung im IRC
15 c23199d9 2002-02-27 alex */
16 c23199d9 2002-02-27 alex
17 c23199d9 2002-02-27 alex
18 ca33cbda 2002-03-12 alex #include "portab.h"
19 c23199d9 2002-02-27 alex
20 ca33cbda 2002-03-12 alex #include "imp.h"
21 c23199d9 2002-02-27 alex #include <assert.h>
22 c23199d9 2002-02-27 alex #include <stdio.h>
23 c23199d9 2002-02-27 alex #include <stdlib.h>
24 c23199d9 2002-02-27 alex #include <string.h>
25 c23199d9 2002-02-27 alex
26 c23199d9 2002-02-27 alex #include "ngircd.h"
27 c2f60abe 2002-05-27 alex #include "resolve.h"
28 c23199d9 2002-02-27 alex #include "conf.h"
29 c2f60abe 2002-05-27 alex #include "conn.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 c2f60abe 2002-05-27 alex #include "irc.h"
36 c2f60abe 2002-05-27 alex #include "irc-write.h"
37 c23199d9 2002-02-27 alex
38 ca33cbda 2002-03-12 alex #include "exp.h"
39 c23199d9 2002-02-27 alex #include "irc-login.h"
40 c23199d9 2002-02-27 alex
41 c23199d9 2002-02-27 alex
42 c2f60abe 2002-05-27 alex LOCAL BOOLEAN Hello_User PARAMS(( CLIENT *Client ));
43 c2f60abe 2002-05-27 alex LOCAL VOID Kill_Nick PARAMS(( CHAR *Nick, CHAR *Reason ));
44 c23199d9 2002-02-27 alex
45 c23199d9 2002-02-27 alex
46 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
47 c2f60abe 2002-05-27 alex IRC_PASS( CLIENT *Client, REQUEST *Req )
48 c23199d9 2002-02-27 alex {
49 c23199d9 2002-02-27 alex assert( Client != NULL );
50 c23199d9 2002-02-27 alex assert( Req != NULL );
51 c23199d9 2002-02-27 alex
52 c23199d9 2002-02-27 alex /* Fehler liefern, wenn kein lokaler Client */
53 c23199d9 2002-02-27 alex if( Client_Conn( Client ) <= NONE ) return IRC_WriteStrClient( Client, ERR_UNKNOWNCOMMAND_MSG, Client_ID( Client ), Req->command );
54 c23199d9 2002-02-27 alex
55 c23199d9 2002-02-27 alex if(( Client_Type( Client ) == CLIENT_UNKNOWN ) && ( Req->argc == 1))
56 c23199d9 2002-02-27 alex {
57 c23199d9 2002-02-27 alex /* noch nicht registrierte unbekannte Verbindung */
58 c23199d9 2002-02-27 alex Log( LOG_DEBUG, "Connection %d: got PASS command ...", Client_Conn( Client ));
59 c23199d9 2002-02-27 alex
60 c23199d9 2002-02-27 alex /* Passwort speichern */
61 c23199d9 2002-02-27 alex Client_SetPassword( Client, Req->argv[0] );
62 c23199d9 2002-02-27 alex
63 c23199d9 2002-02-27 alex Client_SetType( Client, CLIENT_GOTPASS );
64 c23199d9 2002-02-27 alex return CONNECTED;
65 c23199d9 2002-02-27 alex }
66 c23199d9 2002-02-27 alex else if((( Client_Type( Client ) == CLIENT_UNKNOWN ) || ( Client_Type( Client ) == CLIENT_UNKNOWNSERVER )) && (( Req->argc == 3 ) || ( Req->argc == 4 )))
67 c23199d9 2002-02-27 alex {
68 55ee4c95 2002-09-03 alex CHAR c2, c4, *type, *impl, *serverver, *flags, *ptr;
69 c67bb2ac 2002-09-02 alex INT protohigh, protolow;
70 c67bb2ac 2002-09-02 alex
71 c23199d9 2002-02-27 alex /* noch nicht registrierte Server-Verbindung */
72 c23199d9 2002-02-27 alex Log( LOG_DEBUG, "Connection %d: got PASS command (new server link) ...", Client_Conn( Client ));
73 c23199d9 2002-02-27 alex
74 c23199d9 2002-02-27 alex /* Passwort speichern */
75 c23199d9 2002-02-27 alex Client_SetPassword( Client, Req->argv[0] );
76 c23199d9 2002-02-27 alex
77 ad1cbe34 2002-09-03 alex /* Protokollversion ermitteln */
78 ad1cbe34 2002-09-03 alex if( strlen( Req->argv[1] ) >= 4 )
79 c67bb2ac 2002-09-02 alex {
80 55ee4c95 2002-09-03 alex c2 = Req->argv[1][2];
81 55ee4c95 2002-09-03 alex c4 = Req->argv[1][4];
82 55ee4c95 2002-09-03 alex
83 ad1cbe34 2002-09-03 alex Req->argv[1][4] = '\0';
84 c67bb2ac 2002-09-02 alex protolow = atoi( &Req->argv[1][2] );
85 c67bb2ac 2002-09-02 alex Req->argv[1][2] = '\0';
86 c67bb2ac 2002-09-02 alex protohigh = atoi( Req->argv[1] );
87 ad1cbe34 2002-09-03 alex
88 55ee4c95 2002-09-03 alex Req->argv[1][2] = c2;
89 55ee4c95 2002-09-03 alex Req->argv[1][4] = c4;
90 ad1cbe34 2002-09-03 alex }
91 ad1cbe34 2002-09-03 alex else protohigh = protolow = 0;
92 c67bb2ac 2002-09-02 alex
93 ad1cbe34 2002-09-03 alex /* Protokoll-Typ */
94 ad1cbe34 2002-09-03 alex if( strlen( Req->argv[1] ) > 4 ) type = &Req->argv[1][4];
95 ad1cbe34 2002-09-03 alex else type = NULL;
96 ad1cbe34 2002-09-03 alex
97 c67bb2ac 2002-09-02 alex /* Implementation, Version und ngIRCd-Flags */
98 c67bb2ac 2002-09-02 alex impl = Req->argv[2];
99 c67bb2ac 2002-09-02 alex ptr = strchr( impl, '|' );
100 c67bb2ac 2002-09-02 alex if( ptr ) *ptr = '\0';
101 c67bb2ac 2002-09-02 alex
102 ad1cbe34 2002-09-03 alex if( type && ( strcmp( type, PROTOIRCPLUS ) == 0 ))
103 c67bb2ac 2002-09-02 alex {
104 ad1cbe34 2002-09-03 alex /* auf der anderen Seite laeuft ein Server, der
105 ad1cbe34 2002-09-03 alex * ebenfalls das IRC+-Protokoll versteht */
106 c67bb2ac 2002-09-02 alex serverver = ptr + 1;
107 c67bb2ac 2002-09-02 alex flags = strchr( serverver, ':' );
108 c67bb2ac 2002-09-02 alex if( flags )
109 c67bb2ac 2002-09-02 alex {
110 c67bb2ac 2002-09-02 alex *flags = '\0';
111 c67bb2ac 2002-09-02 alex flags++;
112 c67bb2ac 2002-09-02 alex }
113 c67bb2ac 2002-09-02 alex else flags = "";
114 51dabeaf 2002-09-09 alex Log( LOG_INFO, "Connection %d: Peer announces itself as %s-%s using protocol %d.%d/IRC+ (flags: \"%s\").", Client_Conn( Client ), impl, serverver, protohigh, protolow, flags );
115 c67bb2ac 2002-09-02 alex }
116 c67bb2ac 2002-09-02 alex else
117 c67bb2ac 2002-09-02 alex {
118 c67bb2ac 2002-09-02 alex serverver = flags = "";
119 51dabeaf 2002-09-09 alex Log( LOG_INFO, "Connection %d: Peer announces itself as \"%s\" using protocol %d.%d.", Client_Conn( Client ), impl, protohigh, protolow );
120 c67bb2ac 2002-09-02 alex }
121 c67bb2ac 2002-09-02 alex
122 c23199d9 2002-02-27 alex Client_SetType( Client, CLIENT_GOTPASSSERVER );
123 5aa9c8f4 2002-09-03 alex Client_SetFlags( Client, flags );
124 5aa9c8f4 2002-09-03 alex
125 c23199d9 2002-02-27 alex return CONNECTED;
126 c23199d9 2002-02-27 alex }
127 c23199d9 2002-02-27 alex else if(( Client_Type( Client ) == CLIENT_UNKNOWN ) || ( Client_Type( Client ) == CLIENT_UNKNOWNSERVER ))
128 c23199d9 2002-02-27 alex {
129 c23199d9 2002-02-27 alex /* Falsche Anzahl Parameter? */
130 c23199d9 2002-02-27 alex return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
131 c23199d9 2002-02-27 alex }
132 c23199d9 2002-02-27 alex else return IRC_WriteStrClient( Client, ERR_ALREADYREGISTRED_MSG, Client_ID( Client ));
133 c23199d9 2002-02-27 alex } /* IRC_PASS */
134 c23199d9 2002-02-27 alex
135 c23199d9 2002-02-27 alex
136 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
137 c2f60abe 2002-05-27 alex IRC_NICK( CLIENT *Client, REQUEST *Req )
138 c23199d9 2002-02-27 alex {
139 c23199d9 2002-02-27 alex CLIENT *intr_c, *target, *c;
140 c23199d9 2002-02-27 alex CHAR *modes;
141 c23199d9 2002-02-27 alex
142 c23199d9 2002-02-27 alex assert( Client != NULL );
143 c23199d9 2002-02-27 alex assert( Req != NULL );
144 c23199d9 2002-02-27 alex
145 c23199d9 2002-02-27 alex /* Zumindest BitchX sendet NICK-USER in der falschen Reihenfolge. */
146 c23199d9 2002-02-27 alex #ifndef STRICT_RFC
147 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 ))
148 c23199d9 2002-02-27 alex #else
149 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 ))
150 c23199d9 2002-02-27 alex #endif
151 c23199d9 2002-02-27 alex {
152 c23199d9 2002-02-27 alex /* User-Registrierung bzw. Nick-Aenderung */
153 c23199d9 2002-02-27 alex
154 c23199d9 2002-02-27 alex /* Falsche Anzahl Parameter? */
155 c23199d9 2002-02-27 alex if( Req->argc != 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
156 c23199d9 2002-02-27 alex
157 c23199d9 2002-02-27 alex /* "Ziel-Client" ermitteln */
158 c23199d9 2002-02-27 alex if( Client_Type( Client ) == CLIENT_SERVER )
159 c23199d9 2002-02-27 alex {
160 bc4ed226 2002-03-25 alex target = Client_Search( Req->prefix );
161 c23199d9 2002-02-27 alex if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->argv[0] );
162 c23199d9 2002-02-27 alex }
163 c23199d9 2002-02-27 alex else
164 c23199d9 2002-02-27 alex {
165 c23199d9 2002-02-27 alex /* Ist der Client "restricted"? */
166 c23199d9 2002-02-27 alex if( Client_HasMode( Client, 'r' )) return IRC_WriteStrClient( Client, ERR_RESTRICTED_MSG, Client_ID( Client ));
167 c23199d9 2002-02-27 alex target = Client;
168 c23199d9 2002-02-27 alex }
169 c23199d9 2002-02-27 alex
170 c23199d9 2002-02-27 alex #ifndef STRICT_RFC
171 c23199d9 2002-02-27 alex /* Wenn der Client zu seinem eigenen Nick wechseln will, so machen
172 c23199d9 2002-02-27 alex * wir nichts. So macht es das Original und mind. Snak hat probleme,
173 c23199d9 2002-02-27 alex * wenn wir es nicht so machen. Ob es so okay ist? Hm ... */
174 c23199d9 2002-02-27 alex if( strcmp( Client_ID( target ), Req->argv[0] ) == 0 ) return CONNECTED;
175 c23199d9 2002-02-27 alex #endif
176 5b4e9152 2002-04-08 alex
177 c23199d9 2002-02-27 alex /* pruefen, ob Nick bereits vergeben. Speziallfall: der Client
178 c23199d9 2002-02-27 alex * will nur die Gross- und Kleinschreibung aendern. Das darf
179 c23199d9 2002-02-27 alex * er natuerlich machen :-) */
180 c23199d9 2002-02-27 alex if( strcasecmp( Client_ID( target ), Req->argv[0] ) != 0 )
181 c23199d9 2002-02-27 alex {
182 c23199d9 2002-02-27 alex if( ! Client_CheckNick( target, Req->argv[0] )) return CONNECTED;
183 c23199d9 2002-02-27 alex }
184 c23199d9 2002-02-27 alex
185 c23199d9 2002-02-27 alex if(( Client_Type( target ) != CLIENT_USER ) && ( Client_Type( target ) != CLIENT_SERVER ))
186 c23199d9 2002-02-27 alex {
187 c23199d9 2002-02-27 alex /* Neuer Client */
188 c23199d9 2002-02-27 alex Log( LOG_DEBUG, "Connection %d: got valid NICK command ...", Client_Conn( Client ));
189 c23199d9 2002-02-27 alex
190 c23199d9 2002-02-27 alex /* Client-Nick registrieren */
191 c23199d9 2002-02-27 alex Client_SetID( target, Req->argv[0] );
192 c23199d9 2002-02-27 alex
193 c23199d9 2002-02-27 alex /* schon ein USER da? Dann registrieren! */
194 c23199d9 2002-02-27 alex if( Client_Type( Client ) == CLIENT_GOTUSER ) return Hello_User( Client );
195 c23199d9 2002-02-27 alex else Client_SetType( Client, CLIENT_GOTNICK );
196 c23199d9 2002-02-27 alex }
197 c23199d9 2002-02-27 alex else
198 c23199d9 2002-02-27 alex {
199 c23199d9 2002-02-27 alex /* Nick-Aenderung */
200 5b4e9152 2002-04-08 alex if( Client_Conn( target ) > NONE )
201 5b4e9152 2002-04-08 alex {
202 5b4e9152 2002-04-08 alex /* lokaler Client */
203 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] );
204 5b4e9152 2002-04-08 alex }
205 5b4e9152 2002-04-08 alex else
206 5b4e9152 2002-04-08 alex {
207 5b4e9152 2002-04-08 alex /* Remote-Client */
208 5b4e9152 2002-04-08 alex Log( LOG_DEBUG, "User \"%s\" changed nick: \"%s\" -> \"%s\".", Client_Mask( target ), Client_ID( target ), Req->argv[0] );
209 5b4e9152 2002-04-08 alex }
210 c23199d9 2002-02-27 alex
211 0370c484 2002-03-02 alex /* alle betroffenen User und Server ueber Nick-Aenderung informieren */
212 0370c484 2002-03-02 alex if( Client_Type( Client ) == CLIENT_USER ) IRC_WriteStrClientPrefix( Client, Client, "NICK :%s", Req->argv[0] );
213 0370c484 2002-03-02 alex IRC_WriteStrServersPrefix( Client, target, "NICK :%s", Req->argv[0] );
214 0370c484 2002-03-02 alex IRC_WriteStrRelatedPrefix( target, target, FALSE, "NICK :%s", Req->argv[0] );
215 0370c484 2002-03-02 alex
216 c23199d9 2002-02-27 alex /* neuen Client-Nick speichern */
217 c23199d9 2002-02-27 alex Client_SetID( target, Req->argv[0] );
218 c23199d9 2002-02-27 alex }
219 c23199d9 2002-02-27 alex
220 c23199d9 2002-02-27 alex return CONNECTED;
221 c23199d9 2002-02-27 alex }
222 c23199d9 2002-02-27 alex else if( Client_Type( Client ) == CLIENT_SERVER )
223 c23199d9 2002-02-27 alex {
224 c23199d9 2002-02-27 alex /* Server fuehrt neuen Client ein */
225 c23199d9 2002-02-27 alex
226 c23199d9 2002-02-27 alex /* Falsche Anzahl Parameter? */
227 c23199d9 2002-02-27 alex if( Req->argc != 7 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
228 c23199d9 2002-02-27 alex
229 c23199d9 2002-02-27 alex /* Nick ueberpruefen */
230 bc4ed226 2002-03-25 alex c = Client_Search( Req->argv[0] );
231 c23199d9 2002-02-27 alex if( c )
232 c23199d9 2002-02-27 alex {
233 c23199d9 2002-02-27 alex /* Der neue Nick ist auf diesem Server bereits registriert:
234 c23199d9 2002-02-27 alex * sowohl der neue, als auch der alte Client muessen nun
235 c23199d9 2002-02-27 alex * disconnectiert werden. */
236 c23199d9 2002-02-27 alex Log( LOG_ERR, "Server %s introduces already registered nick \"%s\"!", Client_ID( Client ), Req->argv[0] );
237 c23199d9 2002-02-27 alex Kill_Nick( Req->argv[0], "Nick collision" );
238 c23199d9 2002-02-27 alex return CONNECTED;
239 c23199d9 2002-02-27 alex }
240 c23199d9 2002-02-27 alex
241 c23199d9 2002-02-27 alex /* Server, zu dem der Client connectiert ist, suchen */
242 c23199d9 2002-02-27 alex intr_c = Client_GetFromToken( Client, atoi( Req->argv[4] ));
243 c23199d9 2002-02-27 alex if( ! intr_c )
244 c23199d9 2002-02-27 alex {
245 c23199d9 2002-02-27 alex Log( LOG_ERR, "Server %s introduces nick \"%s\" on unknown server!?", Client_ID( Client ), Req->argv[0] );
246 c23199d9 2002-02-27 alex Kill_Nick( Req->argv[0], "Unknown server" );
247 c23199d9 2002-02-27 alex return CONNECTED;
248 c23199d9 2002-02-27 alex }
249 c23199d9 2002-02-27 alex
250 c23199d9 2002-02-27 alex /* Neue Client-Struktur anlegen */
251 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 );
252 c23199d9 2002-02-27 alex if( ! c )
253 c23199d9 2002-02-27 alex {
254 c23199d9 2002-02-27 alex /* Eine neue Client-Struktur konnte nicht angelegt werden.
255 c23199d9 2002-02-27 alex * Der Client muss disconnectiert werden, damit der Netz-
256 c23199d9 2002-02-27 alex * status konsistent bleibt. */
257 c23199d9 2002-02-27 alex Log( LOG_ALERT, "Can't create client structure! (on connection %d)", Client_Conn( Client ));
258 c23199d9 2002-02-27 alex Kill_Nick( Req->argv[0], "Server error" );
259 c23199d9 2002-02-27 alex return CONNECTED;
260 c23199d9 2002-02-27 alex }
261 c23199d9 2002-02-27 alex
262 c23199d9 2002-02-27 alex modes = Client_Modes( c );
263 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": "" );
264 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": "" );
265 c23199d9 2002-02-27 alex
266 c23199d9 2002-02-27 alex /* Andere Server, ausser dem Introducer, informieren */
267 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] );
268 c23199d9 2002-02-27 alex
269 c23199d9 2002-02-27 alex return CONNECTED;
270 c23199d9 2002-02-27 alex }
271 c23199d9 2002-02-27 alex else return IRC_WriteStrClient( Client, ERR_ALREADYREGISTRED_MSG, Client_ID( Client ));
272 c23199d9 2002-02-27 alex } /* IRC_NICK */
273 c23199d9 2002-02-27 alex
274 c23199d9 2002-02-27 alex
275 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
276 c2f60abe 2002-05-27 alex IRC_USER( CLIENT *Client, REQUEST *Req )
277 c23199d9 2002-02-27 alex {
278 c23199d9 2002-02-27 alex assert( Client != NULL );
279 c23199d9 2002-02-27 alex assert( Req != NULL );
280 c23199d9 2002-02-27 alex
281 c23199d9 2002-02-27 alex #ifndef STRICT_RFC
282 c23199d9 2002-02-27 alex if( Client_Type( Client ) == CLIENT_GOTNICK || Client_Type( Client ) == CLIENT_GOTPASS || Client_Type( Client ) == CLIENT_UNKNOWN )
283 c23199d9 2002-02-27 alex #else
284 c23199d9 2002-02-27 alex if( Client_Type( Client ) == CLIENT_GOTNICK || Client_Type( Client ) == CLIENT_GOTPASS )
285 c23199d9 2002-02-27 alex #endif
286 c23199d9 2002-02-27 alex {
287 c23199d9 2002-02-27 alex /* Falsche Anzahl Parameter? */
288 c23199d9 2002-02-27 alex if( Req->argc != 4 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
289 c23199d9 2002-02-27 alex
290 c23199d9 2002-02-27 alex Client_SetUser( Client, Req->argv[0], FALSE );
291 c23199d9 2002-02-27 alex Client_SetInfo( Client, Req->argv[3] );
292 c23199d9 2002-02-27 alex
293 c23199d9 2002-02-27 alex Log( LOG_DEBUG, "Connection %d: got valid USER command ...", Client_Conn( Client ));
294 c23199d9 2002-02-27 alex if( Client_Type( Client ) == CLIENT_GOTNICK ) return Hello_User( Client );
295 c23199d9 2002-02-27 alex else Client_SetType( Client, CLIENT_GOTUSER );
296 c23199d9 2002-02-27 alex return CONNECTED;
297 c23199d9 2002-02-27 alex }
298 c23199d9 2002-02-27 alex else if( Client_Type( Client ) == CLIENT_USER || Client_Type( Client ) == CLIENT_SERVER || Client_Type( Client ) == CLIENT_SERVICE )
299 c23199d9 2002-02-27 alex {
300 c23199d9 2002-02-27 alex return IRC_WriteStrClient( Client, ERR_ALREADYREGISTRED_MSG, Client_ID( Client ));
301 c23199d9 2002-02-27 alex }
302 c23199d9 2002-02-27 alex else return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
303 c23199d9 2002-02-27 alex } /* IRC_USER */
304 c23199d9 2002-02-27 alex
305 c23199d9 2002-02-27 alex
306 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
307 c2f60abe 2002-05-27 alex IRC_QUIT( CLIENT *Client, REQUEST *Req )
308 c23199d9 2002-02-27 alex {
309 c23199d9 2002-02-27 alex CLIENT *target;
310 c23199d9 2002-02-27 alex
311 c23199d9 2002-02-27 alex assert( Client != NULL );
312 c23199d9 2002-02-27 alex assert( Req != NULL );
313 c23199d9 2002-02-27 alex
314 7f795915 2002-04-14 alex if ( Client_Type( Client ) == CLIENT_SERVER )
315 c23199d9 2002-02-27 alex {
316 c23199d9 2002-02-27 alex /* Server */
317 c23199d9 2002-02-27 alex
318 c23199d9 2002-02-27 alex /* Falsche Anzahl Parameter? */
319 c23199d9 2002-02-27 alex if( Req->argc > 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
320 c23199d9 2002-02-27 alex
321 c23199d9 2002-02-27 alex target = Client_Search( Req->prefix );
322 c23199d9 2002-02-27 alex if( ! target )
323 c23199d9 2002-02-27 alex {
324 9fc7e66f 2002-03-11 alex /* Den Client kennen wir nicht (mehr), also nichts zu tun. */
325 f7a0ff1f 2002-03-11 alex Log( LOG_WARNING, "Got QUIT from %s for unknown client!?", Client_ID( Client ));
326 c23199d9 2002-02-27 alex return CONNECTED;
327 c23199d9 2002-02-27 alex }
328 c23199d9 2002-02-27 alex
329 50ec7a56 2002-03-11 alex if( Req->argc == 0 ) Client_Destroy( target, "Got QUIT command.", NULL, TRUE );
330 50ec7a56 2002-03-11 alex else Client_Destroy( target, "Got QUIT command.", Req->argv[0], TRUE );
331 c23199d9 2002-02-27 alex
332 c23199d9 2002-02-27 alex return CONNECTED;
333 c23199d9 2002-02-27 alex }
334 7f795915 2002-04-14 alex else
335 7f795915 2002-04-14 alex {
336 7f795915 2002-04-14 alex /* User, Service, oder noch nicht registriert */
337 7f795915 2002-04-14 alex
338 7f795915 2002-04-14 alex /* Falsche Anzahl Parameter? */
339 7f795915 2002-04-14 alex if( Req->argc > 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
340 7f795915 2002-04-14 alex
341 7f795915 2002-04-14 alex if( Req->argc == 0 ) Conn_Close( Client_Conn( Client ), "Got QUIT command.", NULL, TRUE );
342 7f795915 2002-04-14 alex else Conn_Close( Client_Conn( Client ), "Got QUIT command.", Req->argv[0], TRUE );
343 7f795915 2002-04-14 alex
344 7f795915 2002-04-14 alex return DISCONNECTED;
345 7f795915 2002-04-14 alex }
346 c23199d9 2002-02-27 alex } /* IRC_QUIT */
347 c23199d9 2002-02-27 alex
348 c23199d9 2002-02-27 alex
349 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
350 c2f60abe 2002-05-27 alex IRC_PING( CLIENT *Client, REQUEST *Req )
351 c23199d9 2002-02-27 alex {
352 c23199d9 2002-02-27 alex CLIENT *target, *from;
353 c23199d9 2002-02-27 alex
354 c23199d9 2002-02-27 alex assert( Client != NULL );
355 c23199d9 2002-02-27 alex assert( Req != NULL );
356 c23199d9 2002-02-27 alex
357 c23199d9 2002-02-27 alex if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
358 c23199d9 2002-02-27 alex
359 c23199d9 2002-02-27 alex /* Falsche Anzahl Parameter? */
360 c23199d9 2002-02-27 alex if( Req->argc < 1 ) return IRC_WriteStrClient( Client, ERR_NOORIGIN_MSG, Client_ID( Client ));
361 5fa05dce 2002-03-10 alex #ifdef STRICT_RFC
362 c23199d9 2002-02-27 alex if( Req->argc > 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
363 5fa05dce 2002-03-10 alex #endif
364 c23199d9 2002-02-27 alex
365 5fa05dce 2002-03-10 alex if( Req->argc > 1 )
366 c23199d9 2002-02-27 alex {
367 c23199d9 2002-02-27 alex /* es wurde ein Ziel-Client angegeben */
368 bc4ed226 2002-03-25 alex target = Client_Search( Req->argv[1] );
369 c23199d9 2002-02-27 alex if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[1] );
370 c23199d9 2002-02-27 alex if( target != Client_ThisServer( ))
371 c23199d9 2002-02-27 alex {
372 c23199d9 2002-02-27 alex /* ok, forwarden */
373 bc4ed226 2002-03-25 alex if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
374 c23199d9 2002-02-27 alex else from = Client;
375 c23199d9 2002-02-27 alex if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->prefix );
376 c23199d9 2002-02-27 alex return IRC_WriteStrClientPrefix( target, from, "PING %s :%s", Client_ID( from ), Req->argv[1] );
377 c23199d9 2002-02-27 alex }
378 c23199d9 2002-02-27 alex }
379 c23199d9 2002-02-27 alex
380 c23199d9 2002-02-27 alex Log( LOG_DEBUG, "Connection %d: got PING, sending PONG ...", Client_Conn( Client ));
381 c23199d9 2002-02-27 alex return IRC_WriteStrClient( Client, "PONG %s :%s", Client_ID( Client_ThisServer( )), Client_ID( Client ));
382 c23199d9 2002-02-27 alex } /* IRC_PING */
383 c23199d9 2002-02-27 alex
384 c23199d9 2002-02-27 alex
385 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
386 c2f60abe 2002-05-27 alex IRC_PONG( CLIENT *Client, REQUEST *Req )
387 c23199d9 2002-02-27 alex {
388 c23199d9 2002-02-27 alex CLIENT *target, *from;
389 c23199d9 2002-02-27 alex
390 c23199d9 2002-02-27 alex assert( Client != NULL );
391 c23199d9 2002-02-27 alex assert( Req != NULL );
392 c23199d9 2002-02-27 alex
393 c23199d9 2002-02-27 alex if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
394 c23199d9 2002-02-27 alex
395 c23199d9 2002-02-27 alex /* Falsche Anzahl Parameter? */
396 c23199d9 2002-02-27 alex if( Req->argc < 1 ) return IRC_WriteStrClient( Client, ERR_NOORIGIN_MSG, Client_ID( Client ));
397 c23199d9 2002-02-27 alex if( Req->argc > 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
398 c23199d9 2002-02-27 alex
399 c23199d9 2002-02-27 alex /* forwarden? */
400 c23199d9 2002-02-27 alex if( Req->argc == 2 )
401 c23199d9 2002-02-27 alex {
402 bc4ed226 2002-03-25 alex target = Client_Search( Req->argv[1] );
403 c23199d9 2002-02-27 alex if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[1] );
404 c23199d9 2002-02-27 alex if( target != Client_ThisServer( ))
405 c23199d9 2002-02-27 alex {
406 c23199d9 2002-02-27 alex /* ok, forwarden */
407 bc4ed226 2002-03-25 alex if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
408 c23199d9 2002-02-27 alex else from = Client;
409 c23199d9 2002-02-27 alex if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->prefix );
410 c23199d9 2002-02-27 alex return IRC_WriteStrClientPrefix( target, from, "PONG %s :%s", Client_ID( from ), Req->argv[1] );
411 c23199d9 2002-02-27 alex }
412 c23199d9 2002-02-27 alex }
413 c23199d9 2002-02-27 alex
414 c23199d9 2002-02-27 alex /* Der Connection-Timestamp wurde schon beim Lesen aus dem Socket
415 bcc51385 2002-03-26 alex * aktualisiert, daher muss das hier nicht mehr gemacht werden. */
416 c23199d9 2002-02-27 alex
417 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 )));
418 c23199d9 2002-02-27 alex else Log( LOG_DEBUG, "Connection %d: received PONG.", Client_Conn( Client ));
419 c23199d9 2002-02-27 alex
420 c23199d9 2002-02-27 alex return CONNECTED;
421 c23199d9 2002-02-27 alex } /* IRC_PONG */
422 c23199d9 2002-02-27 alex
423 c23199d9 2002-02-27 alex
424 c2f60abe 2002-05-27 alex LOCAL BOOLEAN
425 c2f60abe 2002-05-27 alex Hello_User( CLIENT *Client )
426 c23199d9 2002-02-27 alex {
427 c23199d9 2002-02-27 alex assert( Client != NULL );
428 c23199d9 2002-02-27 alex
429 c23199d9 2002-02-27 alex /* Passwort ueberpruefen */
430 c23199d9 2002-02-27 alex if( strcmp( Client_Password( Client ), Conf_ServerPwd ) != 0 )
431 c23199d9 2002-02-27 alex {
432 c23199d9 2002-02-27 alex /* Falsches Passwort */
433 c23199d9 2002-02-27 alex Log( LOG_ERR, "User \"%s\" rejected (connection %d): Bad password!", Client_Mask( Client ), Client_Conn( Client ));
434 c23199d9 2002-02-27 alex Conn_Close( Client_Conn( Client ), NULL, "Bad password", TRUE );
435 c23199d9 2002-02-27 alex return DISCONNECTED;
436 c23199d9 2002-02-27 alex }
437 c23199d9 2002-02-27 alex
438 c23199d9 2002-02-27 alex Log( LOG_NOTICE, "User \"%s\" registered (connection %d).", Client_Mask( Client ), Client_Conn( Client ));
439 c23199d9 2002-02-27 alex
440 c23199d9 2002-02-27 alex /* Andere Server informieren */
441 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 ));
442 c23199d9 2002-02-27 alex
443 c23199d9 2002-02-27 alex if( ! IRC_WriteStrClient( Client, RPL_WELCOME_MSG, Client_ID( Client ), Client_Mask( Client ))) return FALSE;
444 2b6dbb07 2002-09-22 alex if( ! IRC_WriteStrClient( Client, RPL_YOURHOST_MSG, Client_ID( Client ), Client_ID( Client_ThisServer( )), VERSION, TARGET_CPU, TARGET_VENDOR, TARGET_OS )) return FALSE;
445 c23199d9 2002-02-27 alex if( ! IRC_WriteStrClient( Client, RPL_CREATED_MSG, Client_ID( Client ), NGIRCd_StartStr )) return FALSE;
446 f7327524 2002-05-30 alex if( ! IRC_WriteStrClient( Client, RPL_MYINFO_MSG, Client_ID( Client ), Client_ID( Client_ThisServer( )), VERSION, USERMODES, CHANMODES )) return FALSE;
447 c23199d9 2002-02-27 alex
448 c23199d9 2002-02-27 alex Client_SetType( Client, CLIENT_USER );
449 c23199d9 2002-02-27 alex
450 c23199d9 2002-02-27 alex if( ! IRC_Send_LUSERS( Client )) return DISCONNECTED;
451 c23199d9 2002-02-27 alex if( ! IRC_Show_MOTD( Client )) return DISCONNECTED;
452 c23199d9 2002-02-27 alex
453 c23199d9 2002-02-27 alex return CONNECTED;
454 c23199d9 2002-02-27 alex } /* Hello_User */
455 c23199d9 2002-02-27 alex
456 c23199d9 2002-02-27 alex
457 c2f60abe 2002-05-27 alex LOCAL VOID
458 c2f60abe 2002-05-27 alex Kill_Nick( CHAR *Nick, CHAR *Reason )
459 c23199d9 2002-02-27 alex {
460 c23199d9 2002-02-27 alex CLIENT *c;
461 c23199d9 2002-02-27 alex
462 c23199d9 2002-02-27 alex assert( Nick != NULL );
463 c23199d9 2002-02-27 alex assert( Reason != NULL );
464 c23199d9 2002-02-27 alex
465 c23199d9 2002-02-27 alex Log( LOG_ERR, "User(s) with nick \"%s\" will be disconnected: %s", Nick, Reason );
466 c23199d9 2002-02-27 alex
467 c23199d9 2002-02-27 alex /* andere Server benachrichtigen */
468 c23199d9 2002-02-27 alex IRC_WriteStrServers( NULL, "KILL %s :%s", Nick, Reason );
469 c23199d9 2002-02-27 alex
470 c23199d9 2002-02-27 alex /* Ggf. einen eigenen Client toeten */
471 bc4ed226 2002-03-25 alex c = Client_Search( Nick );
472 c23199d9 2002-02-27 alex if( c && ( Client_Conn( c ) != NONE )) Conn_Close( Client_Conn( c ), NULL, Reason, TRUE );
473 c23199d9 2002-02-27 alex } /* Kill_Nick */
474 c23199d9 2002-02-27 alex
475 c23199d9 2002-02-27 alex
476 c23199d9 2002-02-27 alex /* -eof- */