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 bcc51385 2002-03-26 alex * $Id: irc-login.c,v 1.11 2002/03/26 23:58:34 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 c23199d9 2002-02-27 alex #include "conf.h"
28 c23199d9 2002-02-27 alex #include "irc.h"
29 c23199d9 2002-02-27 alex #include "irc-write.h"
30 c23199d9 2002-02-27 alex #include "log.h"
31 c23199d9 2002-02-27 alex #include "messages.h"
32 c23199d9 2002-02-27 alex
33 ca33cbda 2002-03-12 alex #include "exp.h"
34 c23199d9 2002-02-27 alex #include "irc-login.h"
35 c23199d9 2002-02-27 alex
36 c23199d9 2002-02-27 alex
37 c23199d9 2002-02-27 alex LOCAL BOOLEAN Hello_User( CLIENT *Client );
38 c23199d9 2002-02-27 alex LOCAL VOID Kill_Nick( CHAR *Nick, CHAR *Reason );
39 c23199d9 2002-02-27 alex
40 c23199d9 2002-02-27 alex
41 c23199d9 2002-02-27 alex GLOBAL BOOLEAN IRC_PASS( CLIENT *Client, REQUEST *Req )
42 c23199d9 2002-02-27 alex {
43 c23199d9 2002-02-27 alex assert( Client != NULL );
44 c23199d9 2002-02-27 alex assert( Req != NULL );
45 c23199d9 2002-02-27 alex
46 c23199d9 2002-02-27 alex /* Fehler liefern, wenn kein lokaler Client */
47 c23199d9 2002-02-27 alex if( Client_Conn( Client ) <= NONE ) return IRC_WriteStrClient( Client, ERR_UNKNOWNCOMMAND_MSG, Client_ID( Client ), Req->command );
48 c23199d9 2002-02-27 alex
49 c23199d9 2002-02-27 alex if(( Client_Type( Client ) == CLIENT_UNKNOWN ) && ( Req->argc == 1))
50 c23199d9 2002-02-27 alex {
51 c23199d9 2002-02-27 alex /* noch nicht registrierte unbekannte Verbindung */
52 c23199d9 2002-02-27 alex Log( LOG_DEBUG, "Connection %d: got PASS command ...", Client_Conn( Client ));
53 c23199d9 2002-02-27 alex
54 c23199d9 2002-02-27 alex /* Passwort speichern */
55 c23199d9 2002-02-27 alex Client_SetPassword( Client, Req->argv[0] );
56 c23199d9 2002-02-27 alex
57 c23199d9 2002-02-27 alex Client_SetType( Client, CLIENT_GOTPASS );
58 c23199d9 2002-02-27 alex return CONNECTED;
59 c23199d9 2002-02-27 alex }
60 c23199d9 2002-02-27 alex else if((( Client_Type( Client ) == CLIENT_UNKNOWN ) || ( Client_Type( Client ) == CLIENT_UNKNOWNSERVER )) && (( Req->argc == 3 ) || ( Req->argc == 4 )))
61 c23199d9 2002-02-27 alex {
62 c23199d9 2002-02-27 alex /* noch nicht registrierte Server-Verbindung */
63 c23199d9 2002-02-27 alex Log( LOG_DEBUG, "Connection %d: got PASS command (new server link) ...", Client_Conn( Client ));
64 c23199d9 2002-02-27 alex
65 c23199d9 2002-02-27 alex /* Passwort speichern */
66 c23199d9 2002-02-27 alex Client_SetPassword( Client, Req->argv[0] );
67 c23199d9 2002-02-27 alex
68 c23199d9 2002-02-27 alex Client_SetType( Client, CLIENT_GOTPASSSERVER );
69 c23199d9 2002-02-27 alex return CONNECTED;
70 c23199d9 2002-02-27 alex }
71 c23199d9 2002-02-27 alex else if(( Client_Type( Client ) == CLIENT_UNKNOWN ) || ( Client_Type( Client ) == CLIENT_UNKNOWNSERVER ))
72 c23199d9 2002-02-27 alex {
73 c23199d9 2002-02-27 alex /* Falsche Anzahl Parameter? */
74 c23199d9 2002-02-27 alex return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
75 c23199d9 2002-02-27 alex }
76 c23199d9 2002-02-27 alex else return IRC_WriteStrClient( Client, ERR_ALREADYREGISTRED_MSG, Client_ID( Client ));
77 c23199d9 2002-02-27 alex } /* IRC_PASS */
78 c23199d9 2002-02-27 alex
79 c23199d9 2002-02-27 alex
80 c23199d9 2002-02-27 alex GLOBAL BOOLEAN IRC_NICK( CLIENT *Client, REQUEST *Req )
81 c23199d9 2002-02-27 alex {
82 c23199d9 2002-02-27 alex CLIENT *intr_c, *target, *c;
83 c23199d9 2002-02-27 alex CHAR *modes;
84 c23199d9 2002-02-27 alex
85 c23199d9 2002-02-27 alex assert( Client != NULL );
86 c23199d9 2002-02-27 alex assert( Req != NULL );
87 c23199d9 2002-02-27 alex
88 c23199d9 2002-02-27 alex /* Zumindest BitchX sendet NICK-USER in der falschen Reihenfolge. */
89 c23199d9 2002-02-27 alex #ifndef STRICT_RFC
90 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 ))
91 c23199d9 2002-02-27 alex #else
92 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 ))
93 c23199d9 2002-02-27 alex #endif
94 c23199d9 2002-02-27 alex {
95 c23199d9 2002-02-27 alex /* User-Registrierung bzw. Nick-Aenderung */
96 c23199d9 2002-02-27 alex
97 c23199d9 2002-02-27 alex /* Falsche Anzahl Parameter? */
98 c23199d9 2002-02-27 alex if( Req->argc != 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
99 c23199d9 2002-02-27 alex
100 c23199d9 2002-02-27 alex /* "Ziel-Client" ermitteln */
101 c23199d9 2002-02-27 alex if( Client_Type( Client ) == CLIENT_SERVER )
102 c23199d9 2002-02-27 alex {
103 bc4ed226 2002-03-25 alex target = Client_Search( Req->prefix );
104 c23199d9 2002-02-27 alex if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->argv[0] );
105 c23199d9 2002-02-27 alex }
106 c23199d9 2002-02-27 alex else
107 c23199d9 2002-02-27 alex {
108 c23199d9 2002-02-27 alex /* Ist der Client "restricted"? */
109 c23199d9 2002-02-27 alex if( Client_HasMode( Client, 'r' )) return IRC_WriteStrClient( Client, ERR_RESTRICTED_MSG, Client_ID( Client ));
110 c23199d9 2002-02-27 alex target = Client;
111 c23199d9 2002-02-27 alex }
112 c23199d9 2002-02-27 alex
113 c23199d9 2002-02-27 alex #ifndef STRICT_RFC
114 c23199d9 2002-02-27 alex /* Wenn der Client zu seinem eigenen Nick wechseln will, so machen
115 c23199d9 2002-02-27 alex * wir nichts. So macht es das Original und mind. Snak hat probleme,
116 c23199d9 2002-02-27 alex * wenn wir es nicht so machen. Ob es so okay ist? Hm ... */
117 c23199d9 2002-02-27 alex if( strcmp( Client_ID( target ), Req->argv[0] ) == 0 ) return CONNECTED;
118 c23199d9 2002-02-27 alex #endif
119 c23199d9 2002-02-27 alex
120 c23199d9 2002-02-27 alex /* pruefen, ob Nick bereits vergeben. Speziallfall: der Client
121 c23199d9 2002-02-27 alex * will nur die Gross- und Kleinschreibung aendern. Das darf
122 c23199d9 2002-02-27 alex * er natuerlich machen :-) */
123 c23199d9 2002-02-27 alex if( strcasecmp( Client_ID( target ), Req->argv[0] ) != 0 )
124 c23199d9 2002-02-27 alex {
125 c23199d9 2002-02-27 alex if( ! Client_CheckNick( target, Req->argv[0] )) return CONNECTED;
126 c23199d9 2002-02-27 alex }
127 c23199d9 2002-02-27 alex
128 c23199d9 2002-02-27 alex if(( Client_Type( target ) != CLIENT_USER ) && ( Client_Type( target ) != CLIENT_SERVER ))
129 c23199d9 2002-02-27 alex {
130 c23199d9 2002-02-27 alex /* Neuer Client */
131 c23199d9 2002-02-27 alex Log( LOG_DEBUG, "Connection %d: got valid NICK command ...", Client_Conn( Client ));
132 c23199d9 2002-02-27 alex
133 c23199d9 2002-02-27 alex /* Client-Nick registrieren */
134 c23199d9 2002-02-27 alex Client_SetID( target, Req->argv[0] );
135 c23199d9 2002-02-27 alex
136 c23199d9 2002-02-27 alex /* schon ein USER da? Dann registrieren! */
137 c23199d9 2002-02-27 alex if( Client_Type( Client ) == CLIENT_GOTUSER ) return Hello_User( Client );
138 c23199d9 2002-02-27 alex else Client_SetType( Client, CLIENT_GOTNICK );
139 c23199d9 2002-02-27 alex }
140 c23199d9 2002-02-27 alex else
141 c23199d9 2002-02-27 alex {
142 c23199d9 2002-02-27 alex /* Nick-Aenderung */
143 69f68307 2002-03-19 alex if( Client_Conn( target ) > NONE ) Log( LOG_INFO, "User \"%s\" changed nick (connection %d): \"%s\" -> \"%s\".", Client_Mask( target ), Client_ID( target ), Req->argv[0], Client_Conn( target ));
144 69f68307 2002-03-19 alex else Log( LOG_DEBUG, "User \"%s\" changed nick: \"%s\" -> \"%s\".", Client_Mask( target ), Client_ID( target ), Req->argv[0] );
145 c23199d9 2002-02-27 alex
146 0370c484 2002-03-02 alex /* alle betroffenen User und Server ueber Nick-Aenderung informieren */
147 0370c484 2002-03-02 alex if( Client_Type( Client ) == CLIENT_USER ) IRC_WriteStrClientPrefix( Client, Client, "NICK :%s", Req->argv[0] );
148 0370c484 2002-03-02 alex IRC_WriteStrServersPrefix( Client, target, "NICK :%s", Req->argv[0] );
149 0370c484 2002-03-02 alex IRC_WriteStrRelatedPrefix( target, target, FALSE, "NICK :%s", Req->argv[0] );
150 0370c484 2002-03-02 alex
151 c23199d9 2002-02-27 alex /* neuen Client-Nick speichern */
152 c23199d9 2002-02-27 alex Client_SetID( target, Req->argv[0] );
153 c23199d9 2002-02-27 alex }
154 c23199d9 2002-02-27 alex
155 c23199d9 2002-02-27 alex return CONNECTED;
156 c23199d9 2002-02-27 alex }
157 c23199d9 2002-02-27 alex else if( Client_Type( Client ) == CLIENT_SERVER )
158 c23199d9 2002-02-27 alex {
159 c23199d9 2002-02-27 alex /* Server fuehrt neuen Client ein */
160 c23199d9 2002-02-27 alex
161 c23199d9 2002-02-27 alex /* Falsche Anzahl Parameter? */
162 c23199d9 2002-02-27 alex if( Req->argc != 7 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
163 c23199d9 2002-02-27 alex
164 c23199d9 2002-02-27 alex /* Nick ueberpruefen */
165 bc4ed226 2002-03-25 alex c = Client_Search( Req->argv[0] );
166 c23199d9 2002-02-27 alex if( c )
167 c23199d9 2002-02-27 alex {
168 c23199d9 2002-02-27 alex /* Der neue Nick ist auf diesem Server bereits registriert:
169 c23199d9 2002-02-27 alex * sowohl der neue, als auch der alte Client muessen nun
170 c23199d9 2002-02-27 alex * disconnectiert werden. */
171 c23199d9 2002-02-27 alex Log( LOG_ERR, "Server %s introduces already registered nick \"%s\"!", Client_ID( Client ), Req->argv[0] );
172 c23199d9 2002-02-27 alex Kill_Nick( Req->argv[0], "Nick collision" );
173 c23199d9 2002-02-27 alex return CONNECTED;
174 c23199d9 2002-02-27 alex }
175 c23199d9 2002-02-27 alex
176 c23199d9 2002-02-27 alex /* Server, zu dem der Client connectiert ist, suchen */
177 c23199d9 2002-02-27 alex intr_c = Client_GetFromToken( Client, atoi( Req->argv[4] ));
178 c23199d9 2002-02-27 alex if( ! intr_c )
179 c23199d9 2002-02-27 alex {
180 c23199d9 2002-02-27 alex Log( LOG_ERR, "Server %s introduces nick \"%s\" on unknown server!?", Client_ID( Client ), Req->argv[0] );
181 c23199d9 2002-02-27 alex Kill_Nick( Req->argv[0], "Unknown server" );
182 c23199d9 2002-02-27 alex return CONNECTED;
183 c23199d9 2002-02-27 alex }
184 c23199d9 2002-02-27 alex
185 c23199d9 2002-02-27 alex /* Neue Client-Struktur anlegen */
186 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 );
187 c23199d9 2002-02-27 alex if( ! c )
188 c23199d9 2002-02-27 alex {
189 c23199d9 2002-02-27 alex /* Eine neue Client-Struktur konnte nicht angelegt werden.
190 c23199d9 2002-02-27 alex * Der Client muss disconnectiert werden, damit der Netz-
191 c23199d9 2002-02-27 alex * status konsistent bleibt. */
192 c23199d9 2002-02-27 alex Log( LOG_ALERT, "Can't create client structure! (on connection %d)", Client_Conn( Client ));
193 c23199d9 2002-02-27 alex Kill_Nick( Req->argv[0], "Server error" );
194 c23199d9 2002-02-27 alex return CONNECTED;
195 c23199d9 2002-02-27 alex }
196 c23199d9 2002-02-27 alex
197 c23199d9 2002-02-27 alex modes = Client_Modes( c );
198 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": "" );
199 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": "" );
200 c23199d9 2002-02-27 alex
201 c23199d9 2002-02-27 alex /* Andere Server, ausser dem Introducer, informieren */
202 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] );
203 c23199d9 2002-02-27 alex
204 c23199d9 2002-02-27 alex return CONNECTED;
205 c23199d9 2002-02-27 alex }
206 c23199d9 2002-02-27 alex else return IRC_WriteStrClient( Client, ERR_ALREADYREGISTRED_MSG, Client_ID( Client ));
207 c23199d9 2002-02-27 alex } /* IRC_NICK */
208 c23199d9 2002-02-27 alex
209 c23199d9 2002-02-27 alex
210 c23199d9 2002-02-27 alex GLOBAL BOOLEAN IRC_USER( CLIENT *Client, REQUEST *Req )
211 c23199d9 2002-02-27 alex {
212 c23199d9 2002-02-27 alex assert( Client != NULL );
213 c23199d9 2002-02-27 alex assert( Req != NULL );
214 c23199d9 2002-02-27 alex
215 c23199d9 2002-02-27 alex #ifndef STRICT_RFC
216 c23199d9 2002-02-27 alex if( Client_Type( Client ) == CLIENT_GOTNICK || Client_Type( Client ) == CLIENT_GOTPASS || Client_Type( Client ) == CLIENT_UNKNOWN )
217 c23199d9 2002-02-27 alex #else
218 c23199d9 2002-02-27 alex if( Client_Type( Client ) == CLIENT_GOTNICK || Client_Type( Client ) == CLIENT_GOTPASS )
219 c23199d9 2002-02-27 alex #endif
220 c23199d9 2002-02-27 alex {
221 c23199d9 2002-02-27 alex /* Falsche Anzahl Parameter? */
222 c23199d9 2002-02-27 alex if( Req->argc != 4 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
223 c23199d9 2002-02-27 alex
224 c23199d9 2002-02-27 alex Client_SetUser( Client, Req->argv[0], FALSE );
225 c23199d9 2002-02-27 alex Client_SetInfo( Client, Req->argv[3] );
226 c23199d9 2002-02-27 alex
227 c23199d9 2002-02-27 alex Log( LOG_DEBUG, "Connection %d: got valid USER command ...", Client_Conn( Client ));
228 c23199d9 2002-02-27 alex if( Client_Type( Client ) == CLIENT_GOTNICK ) return Hello_User( Client );
229 c23199d9 2002-02-27 alex else Client_SetType( Client, CLIENT_GOTUSER );
230 c23199d9 2002-02-27 alex return CONNECTED;
231 c23199d9 2002-02-27 alex }
232 c23199d9 2002-02-27 alex else if( Client_Type( Client ) == CLIENT_USER || Client_Type( Client ) == CLIENT_SERVER || Client_Type( Client ) == CLIENT_SERVICE )
233 c23199d9 2002-02-27 alex {
234 c23199d9 2002-02-27 alex return IRC_WriteStrClient( Client, ERR_ALREADYREGISTRED_MSG, Client_ID( Client ));
235 c23199d9 2002-02-27 alex }
236 c23199d9 2002-02-27 alex else return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
237 c23199d9 2002-02-27 alex } /* IRC_USER */
238 c23199d9 2002-02-27 alex
239 c23199d9 2002-02-27 alex
240 c23199d9 2002-02-27 alex GLOBAL BOOLEAN IRC_QUIT( CLIENT *Client, REQUEST *Req )
241 c23199d9 2002-02-27 alex {
242 c23199d9 2002-02-27 alex CLIENT *target;
243 c23199d9 2002-02-27 alex
244 c23199d9 2002-02-27 alex assert( Client != NULL );
245 c23199d9 2002-02-27 alex assert( Req != NULL );
246 c23199d9 2002-02-27 alex
247 c23199d9 2002-02-27 alex if(( Client_Type( Client ) == CLIENT_USER ) || ( Client_Type( Client ) == CLIENT_SERVICE ))
248 c23199d9 2002-02-27 alex {
249 c23199d9 2002-02-27 alex /* User / Service */
250 c23199d9 2002-02-27 alex
251 c23199d9 2002-02-27 alex /* Falsche Anzahl Parameter? */
252 c23199d9 2002-02-27 alex if( Req->argc > 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
253 c23199d9 2002-02-27 alex
254 c23199d9 2002-02-27 alex if( Req->argc == 0 ) Conn_Close( Client_Conn( Client ), "Got QUIT command.", NULL, TRUE );
255 c23199d9 2002-02-27 alex else Conn_Close( Client_Conn( Client ), "Got QUIT command.", Req->argv[0], TRUE );
256 c23199d9 2002-02-27 alex
257 c23199d9 2002-02-27 alex return DISCONNECTED;
258 c23199d9 2002-02-27 alex }
259 c23199d9 2002-02-27 alex else if ( Client_Type( Client ) == CLIENT_SERVER )
260 c23199d9 2002-02-27 alex {
261 c23199d9 2002-02-27 alex /* Server */
262 c23199d9 2002-02-27 alex
263 c23199d9 2002-02-27 alex /* Falsche Anzahl Parameter? */
264 c23199d9 2002-02-27 alex if( Req->argc > 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
265 c23199d9 2002-02-27 alex
266 c23199d9 2002-02-27 alex target = Client_Search( Req->prefix );
267 c23199d9 2002-02-27 alex if( ! target )
268 c23199d9 2002-02-27 alex {
269 9fc7e66f 2002-03-11 alex /* Den Client kennen wir nicht (mehr), also nichts zu tun. */
270 f7a0ff1f 2002-03-11 alex Log( LOG_WARNING, "Got QUIT from %s for unknown client!?", Client_ID( Client ));
271 c23199d9 2002-02-27 alex return CONNECTED;
272 c23199d9 2002-02-27 alex }
273 c23199d9 2002-02-27 alex
274 50ec7a56 2002-03-11 alex if( Req->argc == 0 ) Client_Destroy( target, "Got QUIT command.", NULL, TRUE );
275 50ec7a56 2002-03-11 alex else Client_Destroy( target, "Got QUIT command.", Req->argv[0], TRUE );
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_NOTREGISTERED_MSG, Client_ID( Client ));
280 c23199d9 2002-02-27 alex } /* IRC_QUIT */
281 c23199d9 2002-02-27 alex
282 c23199d9 2002-02-27 alex
283 c23199d9 2002-02-27 alex GLOBAL BOOLEAN IRC_PING( CLIENT *Client, REQUEST *Req )
284 c23199d9 2002-02-27 alex {
285 c23199d9 2002-02-27 alex CLIENT *target, *from;
286 c23199d9 2002-02-27 alex
287 c23199d9 2002-02-27 alex assert( Client != NULL );
288 c23199d9 2002-02-27 alex assert( Req != NULL );
289 c23199d9 2002-02-27 alex
290 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 ));
291 c23199d9 2002-02-27 alex
292 c23199d9 2002-02-27 alex /* Falsche Anzahl Parameter? */
293 c23199d9 2002-02-27 alex if( Req->argc < 1 ) return IRC_WriteStrClient( Client, ERR_NOORIGIN_MSG, Client_ID( Client ));
294 5fa05dce 2002-03-10 alex #ifdef STRICT_RFC
295 c23199d9 2002-02-27 alex if( Req->argc > 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
296 5fa05dce 2002-03-10 alex #endif
297 c23199d9 2002-02-27 alex
298 5fa05dce 2002-03-10 alex if( Req->argc > 1 )
299 c23199d9 2002-02-27 alex {
300 c23199d9 2002-02-27 alex /* es wurde ein Ziel-Client angegeben */
301 bc4ed226 2002-03-25 alex target = Client_Search( Req->argv[1] );
302 c23199d9 2002-02-27 alex if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[1] );
303 c23199d9 2002-02-27 alex if( target != Client_ThisServer( ))
304 c23199d9 2002-02-27 alex {
305 c23199d9 2002-02-27 alex /* ok, forwarden */
306 bc4ed226 2002-03-25 alex if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
307 c23199d9 2002-02-27 alex else from = Client;
308 c23199d9 2002-02-27 alex if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->prefix );
309 c23199d9 2002-02-27 alex return IRC_WriteStrClientPrefix( target, from, "PING %s :%s", Client_ID( from ), Req->argv[1] );
310 c23199d9 2002-02-27 alex }
311 c23199d9 2002-02-27 alex }
312 c23199d9 2002-02-27 alex
313 c23199d9 2002-02-27 alex Log( LOG_DEBUG, "Connection %d: got PING, sending PONG ...", Client_Conn( Client ));
314 c23199d9 2002-02-27 alex return IRC_WriteStrClient( Client, "PONG %s :%s", Client_ID( Client_ThisServer( )), Client_ID( Client ));
315 c23199d9 2002-02-27 alex } /* IRC_PING */
316 c23199d9 2002-02-27 alex
317 c23199d9 2002-02-27 alex
318 c23199d9 2002-02-27 alex GLOBAL BOOLEAN IRC_PONG( CLIENT *Client, REQUEST *Req )
319 c23199d9 2002-02-27 alex {
320 c23199d9 2002-02-27 alex CLIENT *target, *from;
321 c23199d9 2002-02-27 alex
322 c23199d9 2002-02-27 alex assert( Client != NULL );
323 c23199d9 2002-02-27 alex assert( Req != NULL );
324 c23199d9 2002-02-27 alex
325 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 ));
326 c23199d9 2002-02-27 alex
327 c23199d9 2002-02-27 alex /* Falsche Anzahl Parameter? */
328 c23199d9 2002-02-27 alex if( Req->argc < 1 ) return IRC_WriteStrClient( Client, ERR_NOORIGIN_MSG, Client_ID( Client ));
329 c23199d9 2002-02-27 alex if( Req->argc > 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
330 c23199d9 2002-02-27 alex
331 c23199d9 2002-02-27 alex /* forwarden? */
332 c23199d9 2002-02-27 alex if( Req->argc == 2 )
333 c23199d9 2002-02-27 alex {
334 bc4ed226 2002-03-25 alex target = Client_Search( Req->argv[1] );
335 c23199d9 2002-02-27 alex if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[1] );
336 c23199d9 2002-02-27 alex if( target != Client_ThisServer( ))
337 c23199d9 2002-02-27 alex {
338 c23199d9 2002-02-27 alex /* ok, forwarden */
339 bc4ed226 2002-03-25 alex if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
340 c23199d9 2002-02-27 alex else from = Client;
341 c23199d9 2002-02-27 alex if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->prefix );
342 c23199d9 2002-02-27 alex return IRC_WriteStrClientPrefix( target, from, "PONG %s :%s", Client_ID( from ), Req->argv[1] );
343 c23199d9 2002-02-27 alex }
344 c23199d9 2002-02-27 alex }
345 c23199d9 2002-02-27 alex
346 c23199d9 2002-02-27 alex /* Der Connection-Timestamp wurde schon beim Lesen aus dem Socket
347 bcc51385 2002-03-26 alex * aktualisiert, daher muss das hier nicht mehr gemacht werden. */
348 c23199d9 2002-02-27 alex
349 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 )));
350 c23199d9 2002-02-27 alex else Log( LOG_DEBUG, "Connection %d: received PONG.", Client_Conn( Client ));
351 c23199d9 2002-02-27 alex
352 c23199d9 2002-02-27 alex return CONNECTED;
353 c23199d9 2002-02-27 alex } /* IRC_PONG */
354 c23199d9 2002-02-27 alex
355 c23199d9 2002-02-27 alex
356 c23199d9 2002-02-27 alex LOCAL BOOLEAN Hello_User( CLIENT *Client )
357 c23199d9 2002-02-27 alex {
358 c23199d9 2002-02-27 alex assert( Client != NULL );
359 c23199d9 2002-02-27 alex
360 c23199d9 2002-02-27 alex /* Passwort ueberpruefen */
361 c23199d9 2002-02-27 alex if( strcmp( Client_Password( Client ), Conf_ServerPwd ) != 0 )
362 c23199d9 2002-02-27 alex {
363 c23199d9 2002-02-27 alex /* Falsches Passwort */
364 c23199d9 2002-02-27 alex Log( LOG_ERR, "User \"%s\" rejected (connection %d): Bad password!", Client_Mask( Client ), Client_Conn( Client ));
365 c23199d9 2002-02-27 alex Conn_Close( Client_Conn( Client ), NULL, "Bad password", TRUE );
366 c23199d9 2002-02-27 alex return DISCONNECTED;
367 c23199d9 2002-02-27 alex }
368 c23199d9 2002-02-27 alex
369 c23199d9 2002-02-27 alex Log( LOG_NOTICE, "User \"%s\" registered (connection %d).", Client_Mask( Client ), Client_Conn( Client ));
370 c23199d9 2002-02-27 alex
371 c23199d9 2002-02-27 alex /* Andere Server informieren */
372 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 ));
373 c23199d9 2002-02-27 alex
374 c23199d9 2002-02-27 alex if( ! IRC_WriteStrClient( Client, RPL_WELCOME_MSG, Client_ID( Client ), Client_Mask( Client ))) return FALSE;
375 c23199d9 2002-02-27 alex if( ! IRC_WriteStrClient( Client, RPL_YOURHOST_MSG, Client_ID( Client ), Client_ID( Client_ThisServer( )))) return FALSE;
376 c23199d9 2002-02-27 alex if( ! IRC_WriteStrClient( Client, RPL_CREATED_MSG, Client_ID( Client ), NGIRCd_StartStr )) return FALSE;
377 c23199d9 2002-02-27 alex if( ! IRC_WriteStrClient( Client, RPL_MYINFO_MSG, Client_ID( Client ), Client_ID( Client_ThisServer( )))) return FALSE;
378 c23199d9 2002-02-27 alex
379 c23199d9 2002-02-27 alex Client_SetType( Client, CLIENT_USER );
380 c23199d9 2002-02-27 alex
381 c23199d9 2002-02-27 alex if( ! IRC_Send_LUSERS( Client )) return DISCONNECTED;
382 c23199d9 2002-02-27 alex if( ! IRC_Show_MOTD( Client )) return DISCONNECTED;
383 c23199d9 2002-02-27 alex
384 c23199d9 2002-02-27 alex return CONNECTED;
385 c23199d9 2002-02-27 alex } /* Hello_User */
386 c23199d9 2002-02-27 alex
387 c23199d9 2002-02-27 alex
388 c23199d9 2002-02-27 alex LOCAL VOID Kill_Nick( CHAR *Nick, CHAR *Reason )
389 c23199d9 2002-02-27 alex {
390 c23199d9 2002-02-27 alex CLIENT *c;
391 c23199d9 2002-02-27 alex
392 c23199d9 2002-02-27 alex assert( Nick != NULL );
393 c23199d9 2002-02-27 alex assert( Reason != NULL );
394 c23199d9 2002-02-27 alex
395 c23199d9 2002-02-27 alex Log( LOG_ERR, "User(s) with nick \"%s\" will be disconnected: %s", Nick, Reason );
396 c23199d9 2002-02-27 alex
397 c23199d9 2002-02-27 alex /* andere Server benachrichtigen */
398 c23199d9 2002-02-27 alex IRC_WriteStrServers( NULL, "KILL %s :%s", Nick, Reason );
399 c23199d9 2002-02-27 alex
400 c23199d9 2002-02-27 alex /* Ggf. einen eigenen Client toeten */
401 bc4ed226 2002-03-25 alex c = Client_Search( Nick );
402 c23199d9 2002-02-27 alex if( c && ( Client_Conn( c ) != NONE )) Conn_Close( Client_Conn( c ), NULL, Reason, TRUE );
403 c23199d9 2002-02-27 alex } /* Kill_Nick */
404 c23199d9 2002-02-27 alex
405 c23199d9 2002-02-27 alex
406 c23199d9 2002-02-27 alex /* -eof- */