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