Blame


1 38b9cb88 2001-12-14 alex /*
2 38b9cb88 2001-12-14 alex * ngIRCd -- The Next Generation IRC Daemon
3 1547f76c 2002-01-02 alex * Copyright (c)2001,2002 by Alexander Barton (alex@barton.de)
4 38b9cb88 2001-12-14 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 38b9cb88 2001-12-14 alex *
11 490f28ff 2002-12-12 alex * Client management.
12 38b9cb88 2001-12-14 alex */
13 38b9cb88 2001-12-14 alex
14 38b9cb88 2001-12-14 alex
15 f7551900 2002-01-04 alex #define __client_c__
16 f7551900 2002-01-04 alex
17 f7551900 2002-01-04 alex
18 ca33cbda 2002-03-12 alex #include "portab.h"
19 38b9cb88 2001-12-14 alex
20 51e1a2e0 2003-01-08 alex static char UNUSED id[] = "$Id: client.c,v 1.72 2003/01/08 22:03:21 alex Exp $";
21 490f28ff 2002-12-12 alex
22 ca33cbda 2002-03-12 alex #include "imp.h"
23 38b9cb88 2001-12-14 alex #include <assert.h>
24 d0ac1e9c 2001-12-23 alex #include <unistd.h>
25 118adda8 2001-12-27 alex #include <stdio.h>
26 b20fa7c6 2002-01-01 alex #include <stdlib.h>
27 d0ac1e9c 2001-12-23 alex #include <string.h>
28 c57a4645 2001-12-27 alex #include <netdb.h>
29 38b9cb88 2001-12-14 alex
30 c2f60abe 2002-05-27 alex #include "conn.h"
31 c2f60abe 2002-05-27 alex
32 ca33cbda 2002-03-12 alex #include "exp.h"
33 08cf5607 2001-12-26 alex #include "client.h"
34 08cf5607 2001-12-26 alex
35 08cf5607 2001-12-26 alex #include <imp.h>
36 79809118 2002-01-06 alex #include "ngircd.h"
37 38b9cb88 2001-12-14 alex #include "channel.h"
38 c2f60abe 2002-05-27 alex #include "resolve.h"
39 9856253d 2001-12-30 alex #include "conf.h"
40 b5c16c22 2002-03-25 alex #include "hash.h"
41 ff54198f 2002-02-27 alex #include "irc-write.h"
42 38b9cb88 2001-12-14 alex #include "log.h"
43 08cf5607 2001-12-26 alex #include "messages.h"
44 38b9cb88 2001-12-14 alex
45 38b9cb88 2001-12-14 alex #include <exp.h>
46 38b9cb88 2001-12-14 alex
47 38b9cb88 2001-12-14 alex
48 467e76aa 2002-10-04 alex #define GETID_LEN (CLIENT_NICK_LEN-1) + 1 + (CLIENT_USER_LEN-1) + 1 + (CLIENT_HOST_LEN-1) + 1
49 467e76aa 2002-10-04 alex
50 467e76aa 2002-10-04 alex
51 f7551900 2002-01-04 alex LOCAL CLIENT *This_Server, *My_Clients;
52 467e76aa 2002-10-04 alex LOCAL CHAR GetID_Buffer[GETID_LEN];
53 08cf5607 2001-12-26 alex
54 08cf5607 2001-12-26 alex
55 c7b55aa6 2002-10-09 alex LOCAL LONG Count PARAMS(( CLIENT_TYPE Type ));
56 c7b55aa6 2002-10-09 alex LOCAL LONG MyCount PARAMS(( CLIENT_TYPE Type ));
57 b9d701db 2002-01-16 alex
58 c2f60abe 2002-05-27 alex LOCAL CLIENT *New_Client_Struct PARAMS(( VOID ));
59 c2f60abe 2002-05-27 alex LOCAL VOID Generate_MyToken PARAMS(( CLIENT *Client ));
60 d0304b19 2002-12-22 alex LOCAL VOID Adjust_Counters PARAMS(( CLIENT *Client ));
61 38b9cb88 2001-12-14 alex
62 38b9cb88 2001-12-14 alex
63 d0304b19 2002-12-22 alex LONG Max_Users = 0, My_Max_Users = 0;
64 d0304b19 2002-12-22 alex
65 d0304b19 2002-12-22 alex
66 c2f60abe 2002-05-27 alex GLOBAL VOID
67 c2f60abe 2002-05-27 alex Client_Init( VOID )
68 38b9cb88 2001-12-14 alex {
69 c57a4645 2001-12-27 alex struct hostent *h;
70 c57a4645 2001-12-27 alex
71 38b9cb88 2001-12-14 alex This_Server = New_Client_Struct( );
72 38b9cb88 2001-12-14 alex if( ! This_Server )
73 38b9cb88 2001-12-14 alex {
74 38b9cb88 2001-12-14 alex Log( LOG_EMERG, "Can't allocate client structure for server! Going down." );
75 f7327524 2002-05-30 alex Log( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE );
76 38b9cb88 2001-12-14 alex exit( 1 );
77 38b9cb88 2001-12-14 alex }
78 38b9cb88 2001-12-14 alex
79 38b9cb88 2001-12-14 alex /* Client-Struktur dieses Servers */
80 38b9cb88 2001-12-14 alex This_Server->next = NULL;
81 38b9cb88 2001-12-14 alex This_Server->type = CLIENT_SERVER;
82 38b9cb88 2001-12-14 alex This_Server->conn_id = NONE;
83 38b9cb88 2001-12-14 alex This_Server->introducer = This_Server;
84 8f7e7d66 2002-01-09 alex This_Server->mytoken = 1;
85 4fe7e9d6 2002-01-11 alex This_Server->hops = 0;
86 c57a4645 2001-12-27 alex
87 d0ac1e9c 2001-12-23 alex gethostname( This_Server->host, CLIENT_HOST_LEN );
88 c57a4645 2001-12-27 alex h = gethostbyname( This_Server->host );
89 695631b2 2002-12-26 alex if( h ) strlcpy( This_Server->host, h->h_name, sizeof( This_Server->host ));
90 c57a4645 2001-12-27 alex
91 b5c16c22 2002-03-25 alex Client_SetID( This_Server, Conf_ServerName );
92 b5c16c22 2002-03-25 alex Client_SetInfo( This_Server, Conf_ServerInfo );
93 d0ac1e9c 2001-12-23 alex
94 38b9cb88 2001-12-14 alex My_Clients = This_Server;
95 38b9cb88 2001-12-14 alex } /* Client_Init */
96 38b9cb88 2001-12-14 alex
97 38b9cb88 2001-12-14 alex
98 c2f60abe 2002-05-27 alex GLOBAL VOID
99 c2f60abe 2002-05-27 alex Client_Exit( VOID )
100 38b9cb88 2001-12-14 alex {
101 d0ac1e9c 2001-12-23 alex CLIENT *c, *next;
102 d0ac1e9c 2001-12-23 alex INT cnt;
103 d0ac1e9c 2001-12-23 alex
104 77c4c015 2002-12-19 alex if( NGIRCd_SignalRestart ) Client_Destroy( This_Server, "Server going down (restarting).", NULL, FALSE );
105 9cb74e81 2002-06-02 alex else Client_Destroy( This_Server, "Server going down.", NULL, FALSE );
106 d0ac1e9c 2001-12-23 alex
107 d0ac1e9c 2001-12-23 alex cnt = 0;
108 d0ac1e9c 2001-12-23 alex c = My_Clients;
109 d0ac1e9c 2001-12-23 alex while( c )
110 d0ac1e9c 2001-12-23 alex {
111 d0ac1e9c 2001-12-23 alex cnt++;
112 95a4b1b1 2002-03-25 alex next = (CLIENT *)c->next;
113 d0ac1e9c 2001-12-23 alex free( c );
114 d0ac1e9c 2001-12-23 alex c = next;
115 d0ac1e9c 2001-12-23 alex }
116 d4a60bd4 2001-12-25 alex if( cnt ) Log( LOG_INFO, "Freed %d client structure%s.", cnt, cnt == 1 ? "" : "s" );
117 79809118 2002-01-06 alex } /* Client_Exit */
118 38b9cb88 2001-12-14 alex
119 38b9cb88 2001-12-14 alex
120 c2f60abe 2002-05-27 alex GLOBAL CLIENT *
121 c2f60abe 2002-05-27 alex Client_ThisServer( VOID )
122 d0ac1e9c 2001-12-23 alex {
123 f7551900 2002-01-04 alex return This_Server;
124 f7551900 2002-01-04 alex } /* Client_ThisServer */
125 f7551900 2002-01-04 alex
126 f7551900 2002-01-04 alex
127 c2f60abe 2002-05-27 alex GLOBAL CLIENT *
128 c2f60abe 2002-05-27 alex Client_NewLocal( CONN_ID Idx, CHAR *Hostname, INT Type, BOOLEAN Idented )
129 f7551900 2002-01-04 alex {
130 f7551900 2002-01-04 alex /* Neuen lokalen Client erzeugen: Wrapper-Funktion fuer Client_New(). */
131 1ab92bb9 2002-01-29 alex return Client_New( Idx, This_Server, NULL, Type, NULL, NULL, Hostname, NULL, 0, 0, NULL, Idented );
132 f7551900 2002-01-04 alex } /* Client_NewLocal */
133 f7551900 2002-01-04 alex
134 f7551900 2002-01-04 alex
135 c2f60abe 2002-05-27 alex GLOBAL CLIENT *
136 c2f60abe 2002-05-27 alex Client_NewRemoteServer( CLIENT *Introducer, CHAR *Hostname, CLIENT *TopServer, INT Hops, INT Token, CHAR *Info, BOOLEAN Idented )
137 f7551900 2002-01-04 alex {
138 f7551900 2002-01-04 alex /* Neuen Remote-Client erzeugen: Wrapper-Funktion fuer Client_New (). */
139 1ab92bb9 2002-01-29 alex return Client_New( NONE, Introducer, TopServer, CLIENT_SERVER, Hostname, NULL, Hostname, Info, Hops, Token, NULL, Idented );
140 f7551900 2002-01-04 alex } /* Client_NewRemoteServer */
141 f7551900 2002-01-04 alex
142 f7551900 2002-01-04 alex
143 c2f60abe 2002-05-27 alex GLOBAL CLIENT *
144 c2f60abe 2002-05-27 alex Client_NewRemoteUser( CLIENT *Introducer, CHAR *Nick, INT Hops, CHAR *User, CHAR *Hostname, INT Token, CHAR *Modes, CHAR *Info, BOOLEAN Idented )
145 f7551900 2002-01-04 alex {
146 f7551900 2002-01-04 alex /* Neuen Remote-Client erzeugen: Wrapper-Funktion fuer Client_New (). */
147 1ab92bb9 2002-01-29 alex return Client_New( NONE, Introducer, NULL, CLIENT_USER, Nick, User, Hostname, Info, Hops, Token, Modes, Idented );
148 f7551900 2002-01-04 alex } /* Client_NewRemoteUser */
149 f7551900 2002-01-04 alex
150 f7551900 2002-01-04 alex
151 c2f60abe 2002-05-27 alex GLOBAL CLIENT *
152 c2f60abe 2002-05-27 alex Client_New( CONN_ID Idx, CLIENT *Introducer, CLIENT *TopServer, INT Type, CHAR *ID, CHAR *User, CHAR *Hostname, CHAR *Info, INT Hops, INT Token, CHAR *Modes, BOOLEAN Idented )
153 f7551900 2002-01-04 alex {
154 d0ac1e9c 2001-12-23 alex CLIENT *client;
155 d0ac1e9c 2001-12-23 alex
156 f7551900 2002-01-04 alex assert( Idx >= NONE );
157 f7551900 2002-01-04 alex assert( Introducer != NULL );
158 b7a18e9f 2001-12-24 alex assert( Hostname != NULL );
159 f7551900 2002-01-04 alex
160 d0ac1e9c 2001-12-23 alex client = New_Client_Struct( );
161 d0ac1e9c 2001-12-23 alex if( ! client ) return NULL;
162 d0ac1e9c 2001-12-23 alex
163 2c5da58d 2001-12-29 alex /* Initialisieren */
164 d0ac1e9c 2001-12-23 alex client->conn_id = Idx;
165 f7551900 2002-01-04 alex client->introducer = Introducer;
166 1ab92bb9 2002-01-29 alex client->topserver = TopServer;
167 f7551900 2002-01-04 alex client->type = Type;
168 f7551900 2002-01-04 alex if( ID ) Client_SetID( client, ID );
169 904d5e5b 2002-01-05 alex if( User ) Client_SetUser( client, User, Idented );
170 f7551900 2002-01-04 alex if( Hostname ) Client_SetHostname( client, Hostname );
171 f7551900 2002-01-04 alex if( Info ) Client_SetInfo( client, Info );
172 f7551900 2002-01-04 alex client->hops = Hops;
173 f7551900 2002-01-04 alex client->token = Token;
174 f7551900 2002-01-04 alex if( Modes ) Client_SetModes( client, Modes );
175 a53857b4 2002-01-07 alex if( Type == CLIENT_SERVER ) Generate_MyToken( client );
176 d0ac1e9c 2001-12-23 alex
177 a1a3e67d 2002-03-04 alex /* ist der User away? */
178 695631b2 2002-12-26 alex if( strchr( client->modes, 'a' )) strlcpy( client->away, DEFAULT_AWAY_MSG, sizeof( client->away ));
179 a1a3e67d 2002-03-04 alex
180 d0ac1e9c 2001-12-23 alex /* Verketten */
181 95a4b1b1 2002-03-25 alex client->next = (POINTER *)My_Clients;
182 d0ac1e9c 2001-12-23 alex My_Clients = client;
183 f7551900 2002-01-04 alex
184 d0304b19 2002-12-22 alex /* Adjust counters */
185 d0304b19 2002-12-22 alex Adjust_Counters( client );
186 d0304b19 2002-12-22 alex
187 d0ac1e9c 2001-12-23 alex return client;
188 f7551900 2002-01-04 alex } /* Client_New */
189 d0ac1e9c 2001-12-23 alex
190 d0ac1e9c 2001-12-23 alex
191 c2f60abe 2002-05-27 alex GLOBAL VOID
192 c2f60abe 2002-05-27 alex Client_Destroy( CLIENT *Client, CHAR *LogMsg, CHAR *FwdMsg, BOOLEAN SendQuit )
193 d0ac1e9c 2001-12-23 alex {
194 d0ac1e9c 2001-12-23 alex /* Client entfernen. */
195 d0ac1e9c 2001-12-23 alex
196 d0ac1e9c 2001-12-23 alex CLIENT *last, *c;
197 dce77559 2002-03-10 alex CHAR msg[LINE_LEN], *txt;
198 d0ac1e9c 2001-12-23 alex
199 b7a18e9f 2001-12-24 alex assert( Client != NULL );
200 c4854470 2002-01-04 alex
201 79809118 2002-01-06 alex if( LogMsg ) txt = LogMsg;
202 79809118 2002-01-06 alex else txt = FwdMsg;
203 79809118 2002-01-06 alex if( ! txt ) txt = "Reason unknown.";
204 dce77559 2002-03-10 alex
205 03c3f3c9 2002-03-12 alex /* Netz-Split-Nachricht vorbereiten (noch nicht optimal) */
206 b316c380 2002-12-26 alex if( Client->type == CLIENT_SERVER ) snprintf( msg, sizeof( msg ), "%s: lost server %s", This_Server->id, Client->id );
207 79809118 2002-01-06 alex
208 d0ac1e9c 2001-12-23 alex last = NULL;
209 d0ac1e9c 2001-12-23 alex c = My_Clients;
210 d0ac1e9c 2001-12-23 alex while( c )
211 d0ac1e9c 2001-12-23 alex {
212 c4854470 2002-01-04 alex if(( Client->type == CLIENT_SERVER ) && ( c->introducer == Client ) && ( c != Client ))
213 c4854470 2002-01-04 alex {
214 dce77559 2002-03-10 alex /* der Client, der geloescht wird ist ein Server. Der Client, den wir gerade
215 dce77559 2002-03-10 alex * pruefen, ist ein Child von diesem und muss daher auch entfernt werden */
216 50ec7a56 2002-03-11 alex Client_Destroy( c, NULL, msg, FALSE );
217 c4854470 2002-01-04 alex last = NULL;
218 c4854470 2002-01-04 alex c = My_Clients;
219 c4854470 2002-01-04 alex continue;
220 c4854470 2002-01-04 alex }
221 d0ac1e9c 2001-12-23 alex if( c == Client )
222 d0ac1e9c 2001-12-23 alex {
223 dce77559 2002-03-10 alex /* Wir haben den Client gefunden: entfernen */
224 d0ac1e9c 2001-12-23 alex if( last ) last->next = c->next;
225 95a4b1b1 2002-03-25 alex else My_Clients = (CLIENT *)c->next;
226 15764f98 2001-12-27 alex
227 c4854470 2002-01-04 alex if( c->type == CLIENT_USER )
228 c4854470 2002-01-04 alex {
229 db58d347 2002-01-05 alex if( c->conn_id != NONE )
230 db58d347 2002-01-05 alex {
231 50ec7a56 2002-03-11 alex /* Ein lokaler User */
232 b89c3108 2002-01-07 alex Log( LOG_NOTICE, "User \"%s\" unregistered (connection %d): %s", Client_Mask( c ), c->conn_id, txt );
233 79809118 2002-01-06 alex
234 50ec7a56 2002-03-11 alex if( SendQuit )
235 50ec7a56 2002-03-11 alex {
236 50ec7a56 2002-03-11 alex /* Alle andere Server informieren! */
237 50ec7a56 2002-03-11 alex if( FwdMsg ) IRC_WriteStrServersPrefix( NULL, c, "QUIT :%s", FwdMsg );
238 50ec7a56 2002-03-11 alex else IRC_WriteStrServersPrefix( NULL, c, "QUIT :" );
239 50ec7a56 2002-03-11 alex }
240 db58d347 2002-01-05 alex }
241 79809118 2002-01-06 alex else
242 79809118 2002-01-06 alex {
243 50ec7a56 2002-03-11 alex /* Remote User */
244 b89c3108 2002-01-07 alex Log( LOG_DEBUG, "User \"%s\" unregistered: %s", Client_Mask( c ), txt );
245 50ec7a56 2002-03-11 alex
246 50ec7a56 2002-03-11 alex if( SendQuit )
247 50ec7a56 2002-03-11 alex {
248 50ec7a56 2002-03-11 alex /* Andere Server informieren, ausser denen, die "in
249 50ec7a56 2002-03-11 alex * Richtung dem liegen", auf dem der User registriert
250 50ec7a56 2002-03-11 alex * ist. Von denen haben wir das QUIT ja wohl bekommen. */
251 50ec7a56 2002-03-11 alex if( FwdMsg ) IRC_WriteStrServersPrefix( Client_NextHop( c ), c, "QUIT :%s", FwdMsg );
252 50ec7a56 2002-03-11 alex else IRC_WriteStrServersPrefix( Client_NextHop( c ), c, "QUIT :" );
253 50ec7a56 2002-03-11 alex }
254 79809118 2002-01-06 alex }
255 dadebb21 2002-06-01 alex Channel_Quit( c, FwdMsg ? FwdMsg : c->id );
256 c4854470 2002-01-04 alex }
257 79809118 2002-01-06 alex else if( c->type == CLIENT_SERVER )
258 79809118 2002-01-06 alex {
259 28d58986 2002-02-27 alex if( c != This_Server )
260 28d58986 2002-02-27 alex {
261 6b58ab84 2002-03-27 alex if( c->conn_id != NONE ) Log( LOG_NOTICE|LOG_snotice, "Server \"%s\" unregistered (connection %d): %s", c->id, c->conn_id, txt );
262 6b58ab84 2002-03-27 alex else Log( LOG_NOTICE|LOG_snotice, "Server \"%s\" unregistered: %s", c->id, txt );
263 28d58986 2002-02-27 alex }
264 8f7e7d66 2002-01-09 alex
265 8f7e7d66 2002-01-09 alex /* andere Server informieren */
266 77c4c015 2002-12-19 alex if( ! NGIRCd_SignalQuit )
267 8f7e7d66 2002-01-09 alex {
268 8f7e7d66 2002-01-09 alex if( FwdMsg ) IRC_WriteStrServersPrefix( Client_NextHop( c ), c, "SQUIT %s :%s", c->id, FwdMsg );
269 8f7e7d66 2002-01-09 alex else IRC_WriteStrServersPrefix( Client_NextHop( c ), c, "SQUIT %s :", c->id );
270 8f7e7d66 2002-01-09 alex }
271 79809118 2002-01-06 alex }
272 28d58986 2002-02-27 alex else
273 28d58986 2002-02-27 alex {
274 28d58986 2002-02-27 alex if( c->conn_id != NONE )
275 28d58986 2002-02-27 alex {
276 28d58986 2002-02-27 alex if( c->id[0] ) Log( LOG_NOTICE, "Client \"%s\" unregistered (connection %d): %s", c->id, c->conn_id, txt );
277 28d58986 2002-02-27 alex else Log( LOG_NOTICE, "Client unregistered (connection %d): %s", c->conn_id, txt );
278 28d58986 2002-02-27 alex }
279 28d58986 2002-02-27 alex else
280 28d58986 2002-02-27 alex {
281 28d58986 2002-02-27 alex if( c->id[0] ) Log( LOG_WARNING, "Unregistered unknown client \"%s\": %s", c->id, txt );
282 28d58986 2002-02-27 alex else Log( LOG_WARNING, "Unregistered unknown client: %s", c->id, txt );
283 28d58986 2002-02-27 alex }
284 28d58986 2002-02-27 alex }
285 15764f98 2001-12-27 alex
286 d0ac1e9c 2001-12-23 alex free( c );
287 d0ac1e9c 2001-12-23 alex break;
288 d0ac1e9c 2001-12-23 alex }
289 d0ac1e9c 2001-12-23 alex last = c;
290 95a4b1b1 2002-03-25 alex c = (CLIENT *)c->next;
291 d0ac1e9c 2001-12-23 alex }
292 d0ac1e9c 2001-12-23 alex } /* Client_Destroy */
293 d0ac1e9c 2001-12-23 alex
294 d0ac1e9c 2001-12-23 alex
295 c2f60abe 2002-05-27 alex GLOBAL VOID
296 c2f60abe 2002-05-27 alex Client_SetHostname( CLIENT *Client, CHAR *Hostname )
297 2c5da58d 2001-12-29 alex {
298 2c5da58d 2001-12-29 alex /* Hostname eines Clients setzen */
299 2c5da58d 2001-12-29 alex
300 2c5da58d 2001-12-29 alex assert( Client != NULL );
301 c68c092c 2002-03-06 alex assert( Hostname != NULL );
302 c68c092c 2002-03-06 alex
303 0ced4181 2002-12-26 alex strlcpy( Client->host, Hostname, sizeof( Client->host ));
304 2c5da58d 2001-12-29 alex } /* Client_SetHostname */
305 f7551900 2002-01-04 alex
306 f7551900 2002-01-04 alex
307 c2f60abe 2002-05-27 alex GLOBAL VOID
308 c2f60abe 2002-05-27 alex Client_SetID( CLIENT *Client, CHAR *ID )
309 f7551900 2002-01-04 alex {
310 b5c16c22 2002-03-25 alex /* Hostname eines Clients setzen, Hash-Wert berechnen */
311 f7551900 2002-01-04 alex
312 f7551900 2002-01-04 alex assert( Client != NULL );
313 c68c092c 2002-03-06 alex assert( ID != NULL );
314 c68c092c 2002-03-06 alex
315 0ced4181 2002-12-26 alex strlcpy( Client->id, ID, sizeof( Client->id ));
316 b5c16c22 2002-03-25 alex
317 b5c16c22 2002-03-25 alex /* Hash */
318 b5c16c22 2002-03-25 alex Client->hash = Hash( Client->id );
319 f7551900 2002-01-04 alex } /* Client_SetID */
320 f7551900 2002-01-04 alex
321 f7551900 2002-01-04 alex
322 c2f60abe 2002-05-27 alex GLOBAL VOID
323 c2f60abe 2002-05-27 alex Client_SetUser( CLIENT *Client, CHAR *User, BOOLEAN Idented )
324 f7551900 2002-01-04 alex {
325 f7551900 2002-01-04 alex /* Username eines Clients setzen */
326 f7551900 2002-01-04 alex
327 f7551900 2002-01-04 alex assert( Client != NULL );
328 c68c092c 2002-03-06 alex assert( User != NULL );
329 c68c092c 2002-03-06 alex
330 0ced4181 2002-12-26 alex if( Idented ) strlcpy( Client->user, User, sizeof( Client->user ));
331 904d5e5b 2002-01-05 alex else
332 904d5e5b 2002-01-05 alex {
333 904d5e5b 2002-01-05 alex Client->user[0] = '~';
334 0ced4181 2002-12-26 alex strlcpy( Client->user + 1, User, sizeof( Client->user ) - 1 );
335 904d5e5b 2002-01-05 alex }
336 f7551900 2002-01-04 alex } /* Client_SetUser */
337 f7551900 2002-01-04 alex
338 f7551900 2002-01-04 alex
339 c2f60abe 2002-05-27 alex GLOBAL VOID
340 c2f60abe 2002-05-27 alex Client_SetInfo( CLIENT *Client, CHAR *Info )
341 f7551900 2002-01-04 alex {
342 f7551900 2002-01-04 alex /* Hostname eines Clients setzen */
343 f7551900 2002-01-04 alex
344 f7551900 2002-01-04 alex assert( Client != NULL );
345 c68c092c 2002-03-06 alex assert( Info != NULL );
346 c68c092c 2002-03-06 alex
347 0ced4181 2002-12-26 alex strlcpy( Client->info, Info, sizeof( Client->info ));
348 f7551900 2002-01-04 alex } /* Client_SetInfo */
349 f7551900 2002-01-04 alex
350 f7551900 2002-01-04 alex
351 c2f60abe 2002-05-27 alex GLOBAL VOID
352 c2f60abe 2002-05-27 alex Client_SetModes( CLIENT *Client, CHAR *Modes )
353 f7551900 2002-01-04 alex {
354 e62ad979 2002-09-03 alex /* Modes eines Clients setzen */
355 f7551900 2002-01-04 alex
356 f7551900 2002-01-04 alex assert( Client != NULL );
357 c68c092c 2002-03-06 alex assert( Modes != NULL );
358 c68c092c 2002-03-06 alex
359 0ced4181 2002-12-26 alex strlcpy( Client->modes, Modes, sizeof( Client->modes ));
360 f7551900 2002-01-04 alex } /* Client_SetModes */
361 e62ad979 2002-09-03 alex
362 e62ad979 2002-09-03 alex
363 e62ad979 2002-09-03 alex GLOBAL VOID
364 e62ad979 2002-09-03 alex Client_SetFlags( CLIENT *Client, CHAR *Flags )
365 e62ad979 2002-09-03 alex {
366 e62ad979 2002-09-03 alex /* Flags eines Clients setzen */
367 e62ad979 2002-09-03 alex
368 e62ad979 2002-09-03 alex assert( Client != NULL );
369 e62ad979 2002-09-03 alex assert( Flags != NULL );
370 e62ad979 2002-09-03 alex
371 0ced4181 2002-12-26 alex strlcpy( Client->flags, Flags, sizeof( Client->flags ));
372 e62ad979 2002-09-03 alex } /* Client_SetFlags */
373 f7551900 2002-01-04 alex
374 f7551900 2002-01-04 alex
375 c2f60abe 2002-05-27 alex GLOBAL VOID
376 c2f60abe 2002-05-27 alex Client_SetPassword( CLIENT *Client, CHAR *Pwd )
377 f7551900 2002-01-04 alex {
378 f7551900 2002-01-04 alex /* Von einem Client geliefertes Passwort */
379 f7551900 2002-01-04 alex
380 f7551900 2002-01-04 alex assert( Client != NULL );
381 c68c092c 2002-03-06 alex assert( Pwd != NULL );
382 c68c092c 2002-03-06 alex
383 0ced4181 2002-12-26 alex strlcpy( Client->pwd, Pwd, sizeof( Client->pwd ));
384 f7551900 2002-01-04 alex } /* Client_SetPassword */
385 c4850124 2002-02-27 alex
386 c4850124 2002-02-27 alex
387 c2f60abe 2002-05-27 alex GLOBAL VOID
388 c2f60abe 2002-05-27 alex Client_SetAway( CLIENT *Client, CHAR *Txt )
389 c4850124 2002-02-27 alex {
390 51e1a2e0 2003-01-08 alex /* Set AWAY reason of client */
391 c4850124 2002-02-27 alex
392 c4850124 2002-02-27 alex assert( Client != NULL );
393 51e1a2e0 2003-01-08 alex assert( Txt != NULL );
394 c4850124 2002-02-27 alex
395 51e1a2e0 2003-01-08 alex strlcpy( Client->away, Txt, sizeof( Client->away ));
396 51e1a2e0 2003-01-08 alex Log( LOG_DEBUG, "User \"%s\" is away: %s", Client_Mask( Client ), Txt );
397 c4850124 2002-02-27 alex } /* Client_SetAway */
398 f7551900 2002-01-04 alex
399 f7551900 2002-01-04 alex
400 c2f60abe 2002-05-27 alex GLOBAL VOID
401 c2f60abe 2002-05-27 alex Client_SetType( CLIENT *Client, INT Type )
402 f7551900 2002-01-04 alex {
403 f7551900 2002-01-04 alex assert( Client != NULL );
404 f7551900 2002-01-04 alex Client->type = Type;
405 a53857b4 2002-01-07 alex if( Type == CLIENT_SERVER ) Generate_MyToken( Client );
406 d0304b19 2002-12-22 alex Adjust_Counters( Client );
407 f7551900 2002-01-04 alex } /* Client_SetType */
408 f7551900 2002-01-04 alex
409 f7551900 2002-01-04 alex
410 c2f60abe 2002-05-27 alex GLOBAL VOID
411 c2f60abe 2002-05-27 alex Client_SetHops( CLIENT *Client, INT Hops )
412 f7551900 2002-01-04 alex {
413 f7551900 2002-01-04 alex assert( Client != NULL );
414 f7551900 2002-01-04 alex Client->hops = Hops;
415 f7551900 2002-01-04 alex } /* Client_SetHops */
416 f7551900 2002-01-04 alex
417 f7551900 2002-01-04 alex
418 c2f60abe 2002-05-27 alex GLOBAL VOID
419 c2f60abe 2002-05-27 alex Client_SetToken( CLIENT *Client, INT Token )
420 f7551900 2002-01-04 alex {
421 f7551900 2002-01-04 alex assert( Client != NULL );
422 f7551900 2002-01-04 alex Client->token = Token;
423 f7551900 2002-01-04 alex } /* Client_SetToken */
424 f7551900 2002-01-04 alex
425 f7551900 2002-01-04 alex
426 c2f60abe 2002-05-27 alex GLOBAL VOID
427 c2f60abe 2002-05-27 alex Client_SetIntroducer( CLIENT *Client, CLIENT *Introducer )
428 f7551900 2002-01-04 alex {
429 f7551900 2002-01-04 alex assert( Client != NULL );
430 c68c092c 2002-03-06 alex assert( Introducer != NULL );
431 f7551900 2002-01-04 alex Client->introducer = Introducer;
432 f7551900 2002-01-04 alex } /* Client_SetIntroducer */
433 f7551900 2002-01-04 alex
434 f7551900 2002-01-04 alex
435 c2f60abe 2002-05-27 alex GLOBAL VOID
436 c2f60abe 2002-05-27 alex Client_SetOperByMe( CLIENT *Client, BOOLEAN OperByMe )
437 f7551900 2002-01-04 alex {
438 f7551900 2002-01-04 alex assert( Client != NULL );
439 f7551900 2002-01-04 alex Client->oper_by_me = OperByMe;
440 f7551900 2002-01-04 alex } /* Client_SetOperByMe */
441 f7551900 2002-01-04 alex
442 f7551900 2002-01-04 alex
443 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
444 c2f60abe 2002-05-27 alex Client_ModeAdd( CLIENT *Client, CHAR Mode )
445 f7551900 2002-01-04 alex {
446 f7551900 2002-01-04 alex /* Mode soll gesetzt werden. TRUE wird geliefert, wenn der
447 f7551900 2002-01-04 alex * Mode neu gesetzt wurde, FALSE, wenn der Client den Mode
448 f7551900 2002-01-04 alex * bereits hatte. */
449 f7551900 2002-01-04 alex
450 f7551900 2002-01-04 alex CHAR x[2];
451 f7551900 2002-01-04 alex
452 f7551900 2002-01-04 alex assert( Client != NULL );
453 f7551900 2002-01-04 alex
454 f7551900 2002-01-04 alex x[0] = Mode; x[1] = '\0';
455 f7551900 2002-01-04 alex if( ! strchr( Client->modes, x[0] ))
456 f7551900 2002-01-04 alex {
457 f7551900 2002-01-04 alex /* Client hat den Mode noch nicht -> setzen */
458 6626395c 2002-12-26 alex strlcat( Client->modes, x, sizeof( Client->modes ));
459 f7551900 2002-01-04 alex return TRUE;
460 f7551900 2002-01-04 alex }
461 f7551900 2002-01-04 alex else return FALSE;
462 f7551900 2002-01-04 alex } /* Client_ModeAdd */
463 f7551900 2002-01-04 alex
464 f7551900 2002-01-04 alex
465 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
466 c2f60abe 2002-05-27 alex Client_ModeDel( CLIENT *Client, CHAR Mode )
467 f7551900 2002-01-04 alex {
468 f7551900 2002-01-04 alex /* Mode soll geloescht werden. TRUE wird geliefert, wenn der
469 f7551900 2002-01-04 alex * Mode entfernt wurde, FALSE, wenn der Client den Mode
470 f7551900 2002-01-04 alex * ueberhaupt nicht hatte. */
471 f7551900 2002-01-04 alex
472 f7551900 2002-01-04 alex CHAR x[2], *p;
473 f7551900 2002-01-04 alex
474 f7551900 2002-01-04 alex assert( Client != NULL );
475 f7551900 2002-01-04 alex
476 f7551900 2002-01-04 alex x[0] = Mode; x[1] = '\0';
477 2c5da58d 2001-12-29 alex
478 f7551900 2002-01-04 alex p = strchr( Client->modes, x[0] );
479 f7551900 2002-01-04 alex if( ! p ) return FALSE;
480 2c5da58d 2001-12-29 alex
481 f7551900 2002-01-04 alex /* Client hat den Mode -> loeschen */
482 f7551900 2002-01-04 alex while( *p )
483 f7551900 2002-01-04 alex {
484 f7551900 2002-01-04 alex *p = *(p + 1);
485 f7551900 2002-01-04 alex p++;
486 f7551900 2002-01-04 alex }
487 f7551900 2002-01-04 alex return TRUE;
488 f7551900 2002-01-04 alex } /* Client_ModeDel */
489 f7551900 2002-01-04 alex
490 f7551900 2002-01-04 alex
491 c2f60abe 2002-05-27 alex GLOBAL CLIENT *
492 c2f60abe 2002-05-27 alex Client_GetFromConn( CONN_ID Idx )
493 d0ac1e9c 2001-12-23 alex {
494 804b1ec4 2001-12-31 alex /* Client-Struktur, die zur lokalen Verbindung Idx gehoert,
495 d0ac1e9c 2001-12-23 alex * liefern. Wird keine gefunden, so wird NULL geliefert. */
496 d0ac1e9c 2001-12-23 alex
497 d0ac1e9c 2001-12-23 alex CLIENT *c;
498 d0ac1e9c 2001-12-23 alex
499 b7a18e9f 2001-12-24 alex assert( Idx >= 0 );
500 b7a18e9f 2001-12-24 alex
501 d0ac1e9c 2001-12-23 alex c = My_Clients;
502 d0ac1e9c 2001-12-23 alex while( c )
503 d0ac1e9c 2001-12-23 alex {
504 d0ac1e9c 2001-12-23 alex if( c->conn_id == Idx ) return c;
505 95a4b1b1 2002-03-25 alex c = (CLIENT *)c->next;
506 d0ac1e9c 2001-12-23 alex }
507 d0ac1e9c 2001-12-23 alex return NULL;
508 d0ac1e9c 2001-12-23 alex } /* Client_GetFromConn */
509 d0ac1e9c 2001-12-23 alex
510 d0ac1e9c 2001-12-23 alex
511 c2f60abe 2002-05-27 alex GLOBAL CLIENT *
512 c2f60abe 2002-05-27 alex Client_Search( CHAR *Nick )
513 90676129 2001-12-26 alex {
514 10363b39 2002-03-03 alex /* Client-Struktur, die den entsprechenden Nick hat, liefern.
515 10363b39 2002-03-03 alex * Wird keine gefunden, so wird NULL geliefert. */
516 804b1ec4 2001-12-31 alex
517 b5c16c22 2002-03-25 alex CHAR search_id[CLIENT_ID_LEN], *ptr;
518 40c9fd26 2002-01-27 alex CLIENT *c = NULL;
519 b5c16c22 2002-03-25 alex UINT32 search_hash;
520 804b1ec4 2001-12-31 alex
521 804b1ec4 2001-12-31 alex assert( Nick != NULL );
522 d17748e9 2002-01-27 alex
523 40c9fd26 2002-01-27 alex /* Nick kopieren und ggf. Host-Mask abschneiden */
524 0ced4181 2002-12-26 alex strlcpy( search_id, Nick, sizeof( search_id ));
525 b5c16c22 2002-03-25 alex ptr = strchr( search_id, '!' );
526 d17748e9 2002-01-27 alex if( ptr ) *ptr = '\0';
527 804b1ec4 2001-12-31 alex
528 b5c16c22 2002-03-25 alex search_hash = Hash( search_id );
529 b5c16c22 2002-03-25 alex
530 804b1ec4 2001-12-31 alex c = My_Clients;
531 804b1ec4 2001-12-31 alex while( c )
532 804b1ec4 2001-12-31 alex {
533 b5c16c22 2002-03-25 alex if( c->hash == search_hash )
534 b5c16c22 2002-03-25 alex {
535 b5c16c22 2002-03-25 alex /* lt. Hash-Wert: Treffer! */
536 b5c16c22 2002-03-25 alex if( strcasecmp( c->id, search_id ) == 0 ) return c;
537 b5c16c22 2002-03-25 alex }
538 95a4b1b1 2002-03-25 alex c = (CLIENT *)c->next;
539 804b1ec4 2001-12-31 alex }
540 804b1ec4 2001-12-31 alex return NULL;
541 b5c16c22 2002-03-25 alex } /* Client_Search */
542 804b1ec4 2001-12-31 alex
543 804b1ec4 2001-12-31 alex
544 c2f60abe 2002-05-27 alex GLOBAL CLIENT *
545 c2f60abe 2002-05-27 alex Client_GetFromToken( CLIENT *Client, INT Token )
546 804b1ec4 2001-12-31 alex {
547 f7551900 2002-01-04 alex /* Client-Struktur, die den entsprechenden Introducer (=Client)
548 f7551900 2002-01-04 alex * und das gegebene Token hat, liefern. Wird keine gefunden,
549 f7551900 2002-01-04 alex * so wird NULL geliefert. */
550 f7551900 2002-01-04 alex
551 f7551900 2002-01-04 alex CLIENT *c;
552 f7551900 2002-01-04 alex
553 90676129 2001-12-26 alex assert( Client != NULL );
554 f7551900 2002-01-04 alex assert( Token > 0 );
555 90676129 2001-12-26 alex
556 f7551900 2002-01-04 alex c = My_Clients;
557 f7551900 2002-01-04 alex while( c )
558 f7551900 2002-01-04 alex {
559 f7551900 2002-01-04 alex if(( c->type == CLIENT_SERVER ) && ( c->introducer == Client ) && ( c->token == Token )) return c;
560 95a4b1b1 2002-03-25 alex c = (CLIENT *)c->next;
561 f7551900 2002-01-04 alex }
562 f7551900 2002-01-04 alex return NULL;
563 f7551900 2002-01-04 alex } /* Client_GetFromToken */
564 f7551900 2002-01-04 alex
565 f7551900 2002-01-04 alex
566 c2f60abe 2002-05-27 alex GLOBAL INT
567 c2f60abe 2002-05-27 alex Client_Type( CLIENT *Client )
568 f7551900 2002-01-04 alex {
569 f7551900 2002-01-04 alex assert( Client != NULL );
570 f7551900 2002-01-04 alex return Client->type;
571 f7551900 2002-01-04 alex } /* Client_Type */
572 f7551900 2002-01-04 alex
573 f7551900 2002-01-04 alex
574 c2f60abe 2002-05-27 alex GLOBAL CONN_ID
575 c2f60abe 2002-05-27 alex Client_Conn( CLIENT *Client )
576 f7551900 2002-01-04 alex {
577 f7551900 2002-01-04 alex assert( Client != NULL );
578 f7551900 2002-01-04 alex return Client->conn_id;
579 f7551900 2002-01-04 alex } /* Client_Conn */
580 f7551900 2002-01-04 alex
581 f7551900 2002-01-04 alex
582 c2f60abe 2002-05-27 alex GLOBAL CHAR *
583 c2f60abe 2002-05-27 alex Client_ID( CLIENT *Client )
584 f7551900 2002-01-04 alex {
585 f7551900 2002-01-04 alex assert( Client != NULL );
586 f7551900 2002-01-04 alex
587 c68c092c 2002-03-06 alex #ifdef DEBUG
588 c68c092c 2002-03-06 alex if( Client->type == CLIENT_USER ) assert( strlen( Client->id ) < CLIENT_NICK_LEN );
589 c68c092c 2002-03-06 alex #endif
590 c68c092c 2002-03-06 alex
591 f7551900 2002-01-04 alex if( Client->id[0] ) return Client->id;
592 90676129 2001-12-26 alex else return "*";
593 f7551900 2002-01-04 alex } /* Client_ID */
594 90676129 2001-12-26 alex
595 90676129 2001-12-26 alex
596 c2f60abe 2002-05-27 alex GLOBAL CHAR *
597 c2f60abe 2002-05-27 alex Client_Info( CLIENT *Client )
598 f7551900 2002-01-04 alex {
599 f7551900 2002-01-04 alex assert( Client != NULL );
600 f7551900 2002-01-04 alex return Client->info;
601 f7551900 2002-01-04 alex } /* Client_Info */
602 f7551900 2002-01-04 alex
603 f7551900 2002-01-04 alex
604 c2f60abe 2002-05-27 alex GLOBAL CHAR *
605 c2f60abe 2002-05-27 alex Client_User( CLIENT *Client )
606 f7551900 2002-01-04 alex {
607 f7551900 2002-01-04 alex assert( Client != NULL );
608 95a4b1b1 2002-03-25 alex if( Client->user[0] ) return Client->user;
609 f7551900 2002-01-04 alex else return "~";
610 f7551900 2002-01-04 alex } /* Client_User */
611 f7551900 2002-01-04 alex
612 f7551900 2002-01-04 alex
613 c2f60abe 2002-05-27 alex GLOBAL CHAR *
614 c2f60abe 2002-05-27 alex Client_Hostname( CLIENT *Client )
615 f7551900 2002-01-04 alex {
616 f7551900 2002-01-04 alex assert( Client != NULL );
617 f7551900 2002-01-04 alex return Client->host;
618 f7551900 2002-01-04 alex } /* Client_Hostname */
619 f7551900 2002-01-04 alex
620 f7551900 2002-01-04 alex
621 c2f60abe 2002-05-27 alex GLOBAL CHAR *
622 c2f60abe 2002-05-27 alex Client_Password( CLIENT *Client )
623 f7551900 2002-01-04 alex {
624 f7551900 2002-01-04 alex assert( Client != NULL );
625 f7551900 2002-01-04 alex return Client->pwd;
626 f7551900 2002-01-04 alex } /* Client_Password */
627 f7551900 2002-01-04 alex
628 f7551900 2002-01-04 alex
629 c2f60abe 2002-05-27 alex GLOBAL CHAR *
630 c2f60abe 2002-05-27 alex Client_Modes( CLIENT *Client )
631 f7551900 2002-01-04 alex {
632 f7551900 2002-01-04 alex assert( Client != NULL );
633 f7551900 2002-01-04 alex return Client->modes;
634 f7551900 2002-01-04 alex } /* Client_Modes */
635 e62ad979 2002-09-03 alex
636 e62ad979 2002-09-03 alex
637 e62ad979 2002-09-03 alex GLOBAL CHAR *
638 e62ad979 2002-09-03 alex Client_Flags( CLIENT *Client )
639 e62ad979 2002-09-03 alex {
640 e62ad979 2002-09-03 alex assert( Client != NULL );
641 e62ad979 2002-09-03 alex return Client->flags;
642 e62ad979 2002-09-03 alex } /* Client_Flags */
643 f7551900 2002-01-04 alex
644 f7551900 2002-01-04 alex
645 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
646 c2f60abe 2002-05-27 alex Client_OperByMe( CLIENT *Client )
647 f7551900 2002-01-04 alex {
648 f7551900 2002-01-04 alex assert( Client != NULL );
649 f7551900 2002-01-04 alex return Client->oper_by_me;
650 f7551900 2002-01-04 alex } /* Client_OperByMe */
651 f7551900 2002-01-04 alex
652 f7551900 2002-01-04 alex
653 c2f60abe 2002-05-27 alex GLOBAL INT
654 c2f60abe 2002-05-27 alex Client_Hops( CLIENT *Client )
655 f7551900 2002-01-04 alex {
656 f7551900 2002-01-04 alex assert( Client != NULL );
657 f7551900 2002-01-04 alex return Client->hops;
658 f7551900 2002-01-04 alex } /* Client_Hops */
659 f7551900 2002-01-04 alex
660 f7551900 2002-01-04 alex
661 c2f60abe 2002-05-27 alex GLOBAL INT
662 c2f60abe 2002-05-27 alex Client_Token( CLIENT *Client )
663 f7551900 2002-01-04 alex {
664 f7551900 2002-01-04 alex assert( Client != NULL );
665 f7551900 2002-01-04 alex return Client->token;
666 f7551900 2002-01-04 alex } /* Client_Token */
667 a53857b4 2002-01-07 alex
668 a53857b4 2002-01-07 alex
669 c2f60abe 2002-05-27 alex GLOBAL INT
670 c2f60abe 2002-05-27 alex Client_MyToken( CLIENT *Client )
671 a53857b4 2002-01-07 alex {
672 a53857b4 2002-01-07 alex assert( Client != NULL );
673 a53857b4 2002-01-07 alex return Client->mytoken;
674 a53857b4 2002-01-07 alex } /* Client_MyToken */
675 f7551900 2002-01-04 alex
676 f7551900 2002-01-04 alex
677 c2f60abe 2002-05-27 alex GLOBAL CLIENT *
678 c2f60abe 2002-05-27 alex Client_NextHop( CLIENT *Client )
679 e7be3a01 2002-01-05 alex {
680 e7be3a01 2002-01-05 alex CLIENT *c;
681 e7be3a01 2002-01-05 alex
682 e7be3a01 2002-01-05 alex assert( Client != NULL );
683 e7be3a01 2002-01-05 alex
684 e7be3a01 2002-01-05 alex c = Client;
685 e7be3a01 2002-01-05 alex while( c->introducer && ( c->introducer != c ) && ( c->introducer != This_Server )) c = c->introducer;
686 e7be3a01 2002-01-05 alex return c;
687 e7be3a01 2002-01-05 alex } /* Client_NextHop */
688 e7be3a01 2002-01-05 alex
689 e7be3a01 2002-01-05 alex
690 c2f60abe 2002-05-27 alex GLOBAL CHAR *
691 c2f60abe 2002-05-27 alex Client_Mask( CLIENT *Client )
692 f7551900 2002-01-04 alex {
693 f7551900 2002-01-04 alex /* Client-"ID" liefern, wie sie z.B. fuer
694 f7551900 2002-01-04 alex * Prefixe benoetigt wird. */
695 f7551900 2002-01-04 alex
696 f7551900 2002-01-04 alex assert( Client != NULL );
697 f7551900 2002-01-04 alex
698 f7551900 2002-01-04 alex if( Client->type == CLIENT_SERVER ) return Client->id;
699 f7551900 2002-01-04 alex
700 467e76aa 2002-10-04 alex snprintf( GetID_Buffer, GETID_LEN, "%s!%s@%s", Client->id, Client->user, Client->host );
701 f7551900 2002-01-04 alex return GetID_Buffer;
702 f7551900 2002-01-04 alex } /* Client_Mask */
703 f7551900 2002-01-04 alex
704 f7551900 2002-01-04 alex
705 c2f60abe 2002-05-27 alex GLOBAL CLIENT *
706 c2f60abe 2002-05-27 alex Client_Introducer( CLIENT *Client )
707 f7551900 2002-01-04 alex {
708 f7551900 2002-01-04 alex assert( Client != NULL );
709 f7551900 2002-01-04 alex return Client->introducer;
710 f7551900 2002-01-04 alex } /* Client_Introducer */
711 f7551900 2002-01-04 alex
712 f7551900 2002-01-04 alex
713 c2f60abe 2002-05-27 alex GLOBAL CLIENT *
714 c2f60abe 2002-05-27 alex Client_TopServer( CLIENT *Client )
715 1ab92bb9 2002-01-29 alex {
716 1ab92bb9 2002-01-29 alex assert( Client != NULL );
717 1ab92bb9 2002-01-29 alex return Client->topserver;
718 1ab92bb9 2002-01-29 alex } /* Client_TopServer */
719 1ab92bb9 2002-01-29 alex
720 1ab92bb9 2002-01-29 alex
721 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
722 c2f60abe 2002-05-27 alex Client_HasMode( CLIENT *Client, CHAR Mode )
723 f7551900 2002-01-04 alex {
724 f7551900 2002-01-04 alex assert( Client != NULL );
725 f7551900 2002-01-04 alex return strchr( Client->modes, Mode ) != NULL;
726 f7551900 2002-01-04 alex } /* Client_HasMode */
727 c4850124 2002-02-27 alex
728 c4850124 2002-02-27 alex
729 c2f60abe 2002-05-27 alex GLOBAL CHAR *
730 c2f60abe 2002-05-27 alex Client_Away( CLIENT *Client )
731 c4850124 2002-02-27 alex {
732 c4850124 2002-02-27 alex /* AWAY-Text liefern */
733 c4850124 2002-02-27 alex
734 c4850124 2002-02-27 alex assert( Client != NULL );
735 c4850124 2002-02-27 alex return Client->away;
736 c4850124 2002-02-27 alex } /* Client_Away */
737 f7551900 2002-01-04 alex
738 f7551900 2002-01-04 alex
739 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
740 c2f60abe 2002-05-27 alex Client_CheckNick( CLIENT *Client, CHAR *Nick )
741 08cf5607 2001-12-26 alex {
742 08cf5607 2001-12-26 alex /* Nick ueberpruefen */
743 08cf5607 2001-12-26 alex
744 08cf5607 2001-12-26 alex assert( Client != NULL );
745 08cf5607 2001-12-26 alex assert( Nick != NULL );
746 08cf5607 2001-12-26 alex
747 33944e8c 2002-02-06 alex /* Nick ungueltig? */
748 9f3a9df2 2002-02-17 alex if( ! Client_IsValidNick( Nick ))
749 9f3a9df2 2002-02-17 alex {
750 9f3a9df2 2002-02-17 alex IRC_WriteStrClient( Client, ERR_ERRONEUSNICKNAME_MSG, Client_ID( Client ), Nick );
751 9f3a9df2 2002-02-17 alex return FALSE;
752 9f3a9df2 2002-02-17 alex }
753 08cf5607 2001-12-26 alex
754 08cf5607 2001-12-26 alex /* Nick bereits vergeben? */
755 b5c16c22 2002-03-25 alex if( Client_Search( Nick ))
756 08cf5607 2001-12-26 alex {
757 b5c16c22 2002-03-25 alex /* den Nick gibt es bereits */
758 b5c16c22 2002-03-25 alex IRC_WriteStrClient( Client, ERR_NICKNAMEINUSE_MSG, Client_ID( Client ), Nick );
759 b5c16c22 2002-03-25 alex return FALSE;
760 08cf5607 2001-12-26 alex }
761 08cf5607 2001-12-26 alex
762 08cf5607 2001-12-26 alex return TRUE;
763 08cf5607 2001-12-26 alex } /* Client_CheckNick */
764 07903baa 2002-01-03 alex
765 07903baa 2002-01-03 alex
766 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
767 c2f60abe 2002-05-27 alex Client_CheckID( CLIENT *Client, CHAR *ID )
768 07903baa 2002-01-03 alex {
769 07903baa 2002-01-03 alex /* Nick ueberpruefen */
770 07903baa 2002-01-03 alex
771 07903baa 2002-01-03 alex CHAR str[COMMAND_LEN];
772 07903baa 2002-01-03 alex CLIENT *c;
773 07903baa 2002-01-03 alex
774 07903baa 2002-01-03 alex assert( Client != NULL );
775 07903baa 2002-01-03 alex assert( Client->conn_id > NONE );
776 07903baa 2002-01-03 alex assert( ID != NULL );
777 07903baa 2002-01-03 alex
778 07903baa 2002-01-03 alex /* Nick zu lang? */
779 9f3a9df2 2002-02-17 alex if( strlen( ID ) > CLIENT_ID_LEN )
780 9f3a9df2 2002-02-17 alex {
781 9f3a9df2 2002-02-17 alex IRC_WriteStrClient( Client, ERR_ERRONEUSNICKNAME_MSG, Client_ID( Client ), ID );
782 9f3a9df2 2002-02-17 alex return FALSE;
783 9f3a9df2 2002-02-17 alex }
784 08cf5607 2001-12-26 alex
785 07903baa 2002-01-03 alex /* ID bereits vergeben? */
786 07903baa 2002-01-03 alex c = My_Clients;
787 07903baa 2002-01-03 alex while( c )
788 07903baa 2002-01-03 alex {
789 f7551900 2002-01-04 alex if( strcasecmp( c->id, ID ) == 0 )
790 07903baa 2002-01-03 alex {
791 07903baa 2002-01-03 alex /* die Server-ID gibt es bereits */
792 b316c380 2002-12-26 alex snprintf( str, sizeof( str ), "ID \"%s\" already registered", ID );
793 9f122037 2002-12-03 alex if( Client->conn_id != c->conn_id ) Log( LOG_ERR, "%s (on connection %d)!", str, c->conn_id );
794 9f122037 2002-12-03 alex else Log( LOG_ERR, "%s (via network)!", str );
795 79809118 2002-01-06 alex Conn_Close( Client->conn_id, str, str, TRUE );
796 07903baa 2002-01-03 alex return FALSE;
797 07903baa 2002-01-03 alex }
798 95a4b1b1 2002-03-25 alex c = (CLIENT *)c->next;
799 07903baa 2002-01-03 alex }
800 08cf5607 2001-12-26 alex
801 07903baa 2002-01-03 alex return TRUE;
802 07903baa 2002-01-03 alex } /* Client_CheckID */
803 07903baa 2002-01-03 alex
804 07903baa 2002-01-03 alex
805 c2f60abe 2002-05-27 alex GLOBAL CLIENT *
806 c2f60abe 2002-05-27 alex Client_First( VOID )
807 fb9d6ce1 2001-12-31 alex {
808 fb9d6ce1 2001-12-31 alex /* Ersten Client liefern. */
809 fb9d6ce1 2001-12-31 alex
810 fb9d6ce1 2001-12-31 alex return My_Clients;
811 fb9d6ce1 2001-12-31 alex } /* Client_First */
812 15764f98 2001-12-27 alex
813 15764f98 2001-12-27 alex
814 c2f60abe 2002-05-27 alex GLOBAL CLIENT *
815 c2f60abe 2002-05-27 alex Client_Next( CLIENT *c )
816 fb9d6ce1 2001-12-31 alex {
817 fb9d6ce1 2001-12-31 alex /* Naechsten Client liefern. Existiert keiner,
818 fb9d6ce1 2001-12-31 alex * so wird NULL geliefert. */
819 fb9d6ce1 2001-12-31 alex
820 fb9d6ce1 2001-12-31 alex assert( c != NULL );
821 95a4b1b1 2002-03-25 alex return (CLIENT *)c->next;
822 fb9d6ce1 2001-12-31 alex } /* Client_Next */
823 b9d701db 2002-01-16 alex
824 b9d701db 2002-01-16 alex
825 c7b55aa6 2002-10-09 alex GLOBAL LONG
826 c2f60abe 2002-05-27 alex Client_UserCount( VOID )
827 b9d701db 2002-01-16 alex {
828 b9d701db 2002-01-16 alex return Count( CLIENT_USER );
829 b9d701db 2002-01-16 alex } /* Client_UserCount */
830 b9d701db 2002-01-16 alex
831 b9d701db 2002-01-16 alex
832 c7b55aa6 2002-10-09 alex GLOBAL LONG
833 c2f60abe 2002-05-27 alex Client_ServiceCount( VOID )
834 b9d701db 2002-01-16 alex {
835 b9d701db 2002-01-16 alex return Count( CLIENT_SERVICE );;
836 b9d701db 2002-01-16 alex } /* Client_ServiceCount */
837 b9d701db 2002-01-16 alex
838 b9d701db 2002-01-16 alex
839 c7b55aa6 2002-10-09 alex GLOBAL LONG
840 c2f60abe 2002-05-27 alex Client_ServerCount( VOID )
841 b9d701db 2002-01-16 alex {
842 b9d701db 2002-01-16 alex return Count( CLIENT_SERVER );
843 b9d701db 2002-01-16 alex } /* Client_ServerCount */
844 b9d701db 2002-01-16 alex
845 b9d701db 2002-01-16 alex
846 c7b55aa6 2002-10-09 alex GLOBAL LONG
847 c2f60abe 2002-05-27 alex Client_MyUserCount( VOID )
848 b9d701db 2002-01-16 alex {
849 b9d701db 2002-01-16 alex return MyCount( CLIENT_USER );
850 b9d701db 2002-01-16 alex } /* Client_MyUserCount */
851 b9d701db 2002-01-16 alex
852 b9d701db 2002-01-16 alex
853 c7b55aa6 2002-10-09 alex GLOBAL LONG
854 c2f60abe 2002-05-27 alex Client_MyServiceCount( VOID )
855 b9d701db 2002-01-16 alex {
856 b9d701db 2002-01-16 alex return MyCount( CLIENT_SERVICE );
857 b9d701db 2002-01-16 alex } /* Client_MyServiceCount */
858 b9d701db 2002-01-16 alex
859 b9d701db 2002-01-16 alex
860 c7b55aa6 2002-10-09 alex GLOBAL LONG
861 c2f60abe 2002-05-27 alex Client_MyServerCount( VOID )
862 b9d701db 2002-01-16 alex {
863 3be7b9ef 2002-04-14 alex CLIENT *c;
864 c7b55aa6 2002-10-09 alex LONG cnt;
865 3be7b9ef 2002-04-14 alex
866 3be7b9ef 2002-04-14 alex cnt = 0;
867 3be7b9ef 2002-04-14 alex c = My_Clients;
868 3be7b9ef 2002-04-14 alex while( c )
869 3be7b9ef 2002-04-14 alex {
870 3be7b9ef 2002-04-14 alex if(( c->type == CLIENT_SERVER ) && ( c->hops == 1 )) cnt++;
871 3be7b9ef 2002-04-14 alex c = (CLIENT *)c->next;
872 3be7b9ef 2002-04-14 alex }
873 3be7b9ef 2002-04-14 alex return cnt;
874 b9d701db 2002-01-16 alex } /* Client_MyServerCount */
875 b9d701db 2002-01-16 alex
876 b9d701db 2002-01-16 alex
877 c7b55aa6 2002-10-09 alex GLOBAL LONG
878 c2f60abe 2002-05-27 alex Client_OperCount( VOID )
879 b9d701db 2002-01-16 alex {
880 b9d701db 2002-01-16 alex CLIENT *c;
881 c7b55aa6 2002-10-09 alex LONG cnt;
882 b9d701db 2002-01-16 alex
883 b9d701db 2002-01-16 alex cnt = 0;
884 b9d701db 2002-01-16 alex c = My_Clients;
885 b9d701db 2002-01-16 alex while( c )
886 b9d701db 2002-01-16 alex {
887 b9d701db 2002-01-16 alex if( c && ( c->type == CLIENT_USER ) && ( strchr( c->modes, 'o' ))) cnt++;
888 95a4b1b1 2002-03-25 alex c = (CLIENT *)c->next;
889 b9d701db 2002-01-16 alex }
890 b9d701db 2002-01-16 alex return cnt;
891 b9d701db 2002-01-16 alex } /* Client_OperCount */
892 fb9d6ce1 2001-12-31 alex
893 fb9d6ce1 2001-12-31 alex
894 c7b55aa6 2002-10-09 alex GLOBAL LONG
895 c2f60abe 2002-05-27 alex Client_UnknownCount( VOID )
896 b9d701db 2002-01-16 alex {
897 b9d701db 2002-01-16 alex CLIENT *c;
898 c7b55aa6 2002-10-09 alex LONG cnt;
899 b9d701db 2002-01-16 alex
900 b9d701db 2002-01-16 alex cnt = 0;
901 b9d701db 2002-01-16 alex c = My_Clients;
902 b9d701db 2002-01-16 alex while( c )
903 b9d701db 2002-01-16 alex {
904 b9d701db 2002-01-16 alex if( c && ( c->type != CLIENT_USER ) && ( c->type != CLIENT_SERVICE ) && ( c->type != CLIENT_SERVER )) cnt++;
905 95a4b1b1 2002-03-25 alex c = (CLIENT *)c->next;
906 b9d701db 2002-01-16 alex }
907 b9d701db 2002-01-16 alex return cnt;
908 b9d701db 2002-01-16 alex } /* Client_UnknownCount */
909 d0304b19 2002-12-22 alex
910 d0304b19 2002-12-22 alex
911 d0304b19 2002-12-22 alex GLOBAL LONG
912 d0304b19 2002-12-22 alex Client_MaxUserCount( VOID )
913 d0304b19 2002-12-22 alex {
914 d0304b19 2002-12-22 alex return Max_Users;
915 d0304b19 2002-12-22 alex } /* Client_MaxUserCount */
916 d0304b19 2002-12-22 alex
917 d0304b19 2002-12-22 alex
918 d0304b19 2002-12-22 alex GLOBAL LONG
919 d0304b19 2002-12-22 alex Client_MyMaxUserCount( VOID )
920 d0304b19 2002-12-22 alex {
921 d0304b19 2002-12-22 alex return My_Max_Users;
922 d0304b19 2002-12-22 alex } /* Client_MyMaxUserCount */
923 b9d701db 2002-01-16 alex
924 b9d701db 2002-01-16 alex
925 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
926 c2f60abe 2002-05-27 alex Client_IsValidNick( CHAR *Nick )
927 33944e8c 2002-02-06 alex {
928 33944e8c 2002-02-06 alex /* Ist der Nick gueltig? */
929 7157d936 2002-03-02 alex
930 f7327524 2002-05-30 alex CHAR *ptr, goodchars[20];
931 33944e8c 2002-02-06 alex
932 33944e8c 2002-02-06 alex assert( Nick != NULL );
933 33944e8c 2002-02-06 alex
934 f7327524 2002-05-30 alex strcpy( goodchars, ";0123456789-" );
935 f7327524 2002-05-30 alex
936 33944e8c 2002-02-06 alex if( Nick[0] == '#' ) return FALSE;
937 7157d936 2002-03-02 alex if( strchr( goodchars, Nick[0] )) return FALSE;
938 7157d936 2002-03-02 alex if( strlen( Nick ) >= CLIENT_NICK_LEN ) return FALSE;
939 7157d936 2002-03-02 alex
940 7157d936 2002-03-02 alex ptr = Nick;
941 7157d936 2002-03-02 alex while( *ptr )
942 7157d936 2002-03-02 alex {
943 7157d936 2002-03-02 alex if(( *ptr < 'A' ) && ( ! strchr( goodchars, *ptr ))) return FALSE;
944 7157d936 2002-03-02 alex if(( *ptr > '}' ) && ( ! strchr( goodchars, *ptr ))) return FALSE;
945 7157d936 2002-03-02 alex ptr++;
946 7157d936 2002-03-02 alex }
947 7157d936 2002-03-02 alex
948 33944e8c 2002-02-06 alex return TRUE;
949 33944e8c 2002-02-06 alex } /* Client_IsValidNick */
950 33944e8c 2002-02-06 alex
951 33944e8c 2002-02-06 alex
952 c7b55aa6 2002-10-09 alex LOCAL LONG
953 c2f60abe 2002-05-27 alex Count( CLIENT_TYPE Type )
954 b9d701db 2002-01-16 alex {
955 b9d701db 2002-01-16 alex CLIENT *c;
956 c7b55aa6 2002-10-09 alex LONG cnt;
957 b9d701db 2002-01-16 alex
958 b9d701db 2002-01-16 alex cnt = 0;
959 b9d701db 2002-01-16 alex c = My_Clients;
960 b9d701db 2002-01-16 alex while( c )
961 b9d701db 2002-01-16 alex {
962 3be7b9ef 2002-04-14 alex if( c->type == Type ) cnt++;
963 95a4b1b1 2002-03-25 alex c = (CLIENT *)c->next;
964 b9d701db 2002-01-16 alex }
965 b9d701db 2002-01-16 alex return cnt;
966 b9d701db 2002-01-16 alex } /* Count */
967 b9d701db 2002-01-16 alex
968 b9d701db 2002-01-16 alex
969 c7b55aa6 2002-10-09 alex LOCAL LONG
970 c2f60abe 2002-05-27 alex MyCount( CLIENT_TYPE Type )
971 b9d701db 2002-01-16 alex {
972 b9d701db 2002-01-16 alex CLIENT *c;
973 c7b55aa6 2002-10-09 alex LONG cnt;
974 b9d701db 2002-01-16 alex
975 b9d701db 2002-01-16 alex cnt = 0;
976 b9d701db 2002-01-16 alex c = My_Clients;
977 b9d701db 2002-01-16 alex while( c )
978 b9d701db 2002-01-16 alex {
979 3be7b9ef 2002-04-14 alex if(( c->introducer == This_Server ) && ( c->type == Type )) cnt++;
980 95a4b1b1 2002-03-25 alex c = (CLIENT *)c->next;
981 b9d701db 2002-01-16 alex }
982 b9d701db 2002-01-16 alex return cnt;
983 b9d701db 2002-01-16 alex } /* MyCount */
984 b9d701db 2002-01-16 alex
985 b9d701db 2002-01-16 alex
986 c2f60abe 2002-05-27 alex LOCAL CLIENT *
987 c2f60abe 2002-05-27 alex New_Client_Struct( VOID )
988 38b9cb88 2001-12-14 alex {
989 d0ac1e9c 2001-12-23 alex /* Neue CLIENT-Struktur pre-initialisieren */
990 d0ac1e9c 2001-12-23 alex
991 38b9cb88 2001-12-14 alex CLIENT *c;
992 38b9cb88 2001-12-14 alex
993 38b9cb88 2001-12-14 alex c = malloc( sizeof( CLIENT ));
994 38b9cb88 2001-12-14 alex if( ! c )
995 38b9cb88 2001-12-14 alex {
996 e6d1bcdf 2002-06-10 alex Log( LOG_EMERG, "Can't allocate memory! [New_Client_Struct]" );
997 38b9cb88 2001-12-14 alex return NULL;
998 38b9cb88 2001-12-14 alex }
999 38b9cb88 2001-12-14 alex
1000 38b9cb88 2001-12-14 alex c->next = NULL;
1001 b5c16c22 2002-03-25 alex c->hash = 0;
1002 38b9cb88 2001-12-14 alex c->type = CLIENT_UNKNOWN;
1003 38b9cb88 2001-12-14 alex c->conn_id = NONE;
1004 38b9cb88 2001-12-14 alex c->introducer = NULL;
1005 1ab92bb9 2002-01-29 alex c->topserver = NULL;
1006 f7551900 2002-01-04 alex strcpy( c->id, "" );
1007 f7551900 2002-01-04 alex strcpy( c->pwd, "" );
1008 d0ac1e9c 2001-12-23 alex strcpy( c->host, "" );
1009 d0ac1e9c 2001-12-23 alex strcpy( c->user, "" );
1010 804b1ec4 2001-12-31 alex strcpy( c->info, "" );
1011 f0dacce9 2001-12-29 alex strcpy( c->modes, "" );
1012 804b1ec4 2001-12-31 alex c->oper_by_me = FALSE;
1013 f7551900 2002-01-04 alex c->hops = -1;
1014 f7551900 2002-01-04 alex c->token = -1;
1015 a53857b4 2002-01-07 alex c->mytoken = -1;
1016 c4850124 2002-02-27 alex strcpy( c->away, "" );
1017 e62ad979 2002-09-03 alex strcpy( c->flags, "" );
1018 d0ac1e9c 2001-12-23 alex
1019 38b9cb88 2001-12-14 alex return c;
1020 38b9cb88 2001-12-14 alex } /* New_Client */
1021 38b9cb88 2001-12-14 alex
1022 38b9cb88 2001-12-14 alex
1023 c2f60abe 2002-05-27 alex LOCAL VOID
1024 c2f60abe 2002-05-27 alex Generate_MyToken( CLIENT *Client )
1025 a53857b4 2002-01-07 alex {
1026 a53857b4 2002-01-07 alex CLIENT *c;
1027 a53857b4 2002-01-07 alex INT token;
1028 a53857b4 2002-01-07 alex
1029 a53857b4 2002-01-07 alex c = My_Clients;
1030 a53857b4 2002-01-07 alex token = 2;
1031 a53857b4 2002-01-07 alex while( c )
1032 a53857b4 2002-01-07 alex {
1033 a53857b4 2002-01-07 alex if( c->mytoken == token )
1034 a53857b4 2002-01-07 alex {
1035 a53857b4 2002-01-07 alex /* Das Token wurde bereits vergeben */
1036 a53857b4 2002-01-07 alex token++;
1037 a53857b4 2002-01-07 alex c = My_Clients;
1038 a53857b4 2002-01-07 alex continue;
1039 a53857b4 2002-01-07 alex }
1040 95a4b1b1 2002-03-25 alex else c = (CLIENT *)c->next;
1041 a53857b4 2002-01-07 alex }
1042 a53857b4 2002-01-07 alex Client->mytoken = token;
1043 a53857b4 2002-01-07 alex Log( LOG_DEBUG, "Assigned token %d to server \"%s\".", token, Client->id );
1044 a53857b4 2002-01-07 alex } /* Generate_MyToken */
1045 a53857b4 2002-01-07 alex
1046 a53857b4 2002-01-07 alex
1047 d0304b19 2002-12-22 alex LOCAL VOID
1048 d0304b19 2002-12-22 alex Adjust_Counters( CLIENT *Client )
1049 d0304b19 2002-12-22 alex {
1050 d0304b19 2002-12-22 alex LONG count;
1051 d0304b19 2002-12-22 alex
1052 d0304b19 2002-12-22 alex assert( Client != NULL );
1053 d0304b19 2002-12-22 alex
1054 d0304b19 2002-12-22 alex if( Client->type != CLIENT_USER ) return;
1055 d0304b19 2002-12-22 alex
1056 d0304b19 2002-12-22 alex if( Client->conn_id != NONE )
1057 d0304b19 2002-12-22 alex {
1058 d0304b19 2002-12-22 alex /* Local connection */
1059 d0304b19 2002-12-22 alex count = Client_MyUserCount( );
1060 d0304b19 2002-12-22 alex if( count > My_Max_Users ) My_Max_Users = count;
1061 d0304b19 2002-12-22 alex }
1062 d0304b19 2002-12-22 alex count = Client_UserCount( );
1063 d0304b19 2002-12-22 alex if( count > Max_Users ) Max_Users = count;
1064 d0304b19 2002-12-22 alex } /* Adjust_Counters */
1065 d0304b19 2002-12-22 alex
1066 d0304b19 2002-12-22 alex
1067 38b9cb88 2001-12-14 alex /* -eof- */