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