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