Blame


1 0c471b84 2002-11-30 alex /*
2 0c471b84 2002-11-30 alex * ngIRCd -- The Next Generation IRC Daemon
3 06caecb0 2005-05-16 alex * Copyright (c)2001-2005 Alexander Barton (alex@barton.de)
4 0c471b84 2002-11-30 alex *
5 490f28ff 2002-12-12 alex * This program is free software; you can redistribute it and/or modify
6 490f28ff 2002-12-12 alex * it under the terms of the GNU General Public License as published by
7 490f28ff 2002-12-12 alex * the Free Software Foundation; either version 2 of the License, or
8 490f28ff 2002-12-12 alex * (at your option) any later version.
9 490f28ff 2002-12-12 alex * Please read the file COPYING, README and AUTHORS for more information.
10 0c471b84 2002-11-30 alex *
11 490f28ff 2002-12-12 alex * IRC info commands
12 0c471b84 2002-11-30 alex */
13 0c471b84 2002-11-30 alex
14 0c471b84 2002-11-30 alex
15 0c471b84 2002-11-30 alex #include "portab.h"
16 490f28ff 2002-12-12 alex
17 06caecb0 2005-05-16 alex static char UNUSED id[] = "$Id: irc-info.c,v 1.29 2005/05/16 12:25:15 alex Exp $";
18 0c471b84 2002-11-30 alex
19 0c471b84 2002-11-30 alex #include "imp.h"
20 0c471b84 2002-11-30 alex #include <assert.h>
21 0c471b84 2002-11-30 alex #include <errno.h>
22 0c471b84 2002-11-30 alex #include <stdio.h>
23 06caecb0 2005-05-16 alex #include <stdlib.h>
24 0c471b84 2002-11-30 alex #include <string.h>
25 57c7e236 2004-01-17 alex #include <strings.h>
26 0c471b84 2002-11-30 alex
27 0c471b84 2002-11-30 alex #include "ngircd.h"
28 260b8e5f 2003-06-06 alex #include "cvs-version.h"
29 b8d7dcec 2002-12-30 alex #include "conn-func.h"
30 437f2c33 2002-12-30 alex #include "conn-zip.h"
31 0c471b84 2002-11-30 alex #include "client.h"
32 0c471b84 2002-11-30 alex #include "channel.h"
33 0c471b84 2002-11-30 alex #include "resolve.h"
34 0c471b84 2002-11-30 alex #include "conf.h"
35 0c471b84 2002-11-30 alex #include "defines.h"
36 0c471b84 2002-11-30 alex #include "log.h"
37 0c471b84 2002-11-30 alex #include "messages.h"
38 0c471b84 2002-11-30 alex #include "tool.h"
39 0c471b84 2002-11-30 alex #include "parse.h"
40 0c471b84 2002-11-30 alex #include "irc-write.h"
41 0c471b84 2002-11-30 alex
42 0c471b84 2002-11-30 alex #include "exp.h"
43 0c471b84 2002-11-30 alex #include "irc-info.h"
44 0c471b84 2002-11-30 alex
45 0c471b84 2002-11-30 alex
46 8adff592 2005-03-19 fw GLOBAL bool
47 0c471b84 2002-11-30 alex IRC_ADMIN(CLIENT *Client, REQUEST *Req )
48 0c471b84 2002-11-30 alex {
49 0c471b84 2002-11-30 alex CLIENT *target, *prefix;
50 0c471b84 2002-11-30 alex
51 0c471b84 2002-11-30 alex assert( Client != NULL );
52 0c471b84 2002-11-30 alex assert( Req != NULL );
53 0c471b84 2002-11-30 alex
54 0c471b84 2002-11-30 alex /* Falsche Anzahl Parameter? */
55 0c471b84 2002-11-30 alex if(( Req->argc > 1 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
56 0c471b84 2002-11-30 alex
57 0c471b84 2002-11-30 alex /* Ziel suchen */
58 0c471b84 2002-11-30 alex if( Req->argc == 1 ) target = Client_Search( Req->argv[0] );
59 0c471b84 2002-11-30 alex else target = Client_ThisServer( );
60 0c471b84 2002-11-30 alex
61 0c471b84 2002-11-30 alex /* Prefix ermitteln */
62 0c471b84 2002-11-30 alex if( Client_Type( Client ) == CLIENT_SERVER ) prefix = Client_Search( Req->prefix );
63 0c471b84 2002-11-30 alex else prefix = Client;
64 7924fafb 2002-12-16 alex if( ! prefix ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
65 0c471b84 2002-11-30 alex
66 0c471b84 2002-11-30 alex /* An anderen Server weiterleiten? */
67 0c471b84 2002-11-30 alex if( target != Client_ThisServer( ))
68 0c471b84 2002-11-30 alex {
69 e17976a1 2003-01-01 alex if(( ! target ) || ( Client_Type( target ) != CLIENT_SERVER )) return IRC_WriteStrClient( prefix, ERR_NOSUCHSERVER_MSG, Client_ID( prefix ), Req->argv[0] );
70 0c471b84 2002-11-30 alex
71 0c471b84 2002-11-30 alex /* forwarden */
72 0c471b84 2002-11-30 alex IRC_WriteStrClientPrefix( target, prefix, "ADMIN %s", Req->argv[0] );
73 0c471b84 2002-11-30 alex return CONNECTED;
74 0c471b84 2002-11-30 alex }
75 0c471b84 2002-11-30 alex
76 0c471b84 2002-11-30 alex /* mit Versionsinfo antworten */
77 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( Client, RPL_ADMINME_MSG, Client_ID( prefix ), Conf_ServerName )) return DISCONNECTED;
78 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( Client, RPL_ADMINLOC1_MSG, Client_ID( prefix ), Conf_ServerAdmin1 )) return DISCONNECTED;
79 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( Client, RPL_ADMINLOC2_MSG, Client_ID( prefix ), Conf_ServerAdmin2 )) return DISCONNECTED;
80 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( Client, RPL_ADMINEMAIL_MSG, Client_ID( prefix ), Conf_ServerAdminMail )) return DISCONNECTED;
81 0c471b84 2002-11-30 alex
82 7b6e2662 2003-11-05 alex IRC_SetPenalty( Client, 1 );
83 0c471b84 2002-11-30 alex return CONNECTED;
84 0c471b84 2002-11-30 alex } /* IRC_ADMIN */
85 0c471b84 2002-11-30 alex
86 0c471b84 2002-11-30 alex
87 8adff592 2005-03-19 fw GLOBAL bool
88 0c471b84 2002-11-30 alex IRC_ISON( CLIENT *Client, REQUEST *Req )
89 0c471b84 2002-11-30 alex {
90 8adff592 2005-03-19 fw char rpl[COMMAND_LEN];
91 0c471b84 2002-11-30 alex CLIENT *c;
92 8adff592 2005-03-19 fw char *ptr;
93 8adff592 2005-03-19 fw int i;
94 0c471b84 2002-11-30 alex
95 0c471b84 2002-11-30 alex assert( Client != NULL );
96 0c471b84 2002-11-30 alex assert( Req != NULL );
97 0c471b84 2002-11-30 alex
98 0c471b84 2002-11-30 alex /* Falsche Anzahl Parameter? */
99 0c471b84 2002-11-30 alex if(( Req->argc < 1 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
100 0c471b84 2002-11-30 alex
101 0c471b84 2002-11-30 alex strcpy( rpl, RPL_ISON_MSG );
102 0c471b84 2002-11-30 alex for( i = 0; i < Req->argc; i++ )
103 0c471b84 2002-11-30 alex {
104 0c471b84 2002-11-30 alex ptr = strtok( Req->argv[i], " " );
105 0c471b84 2002-11-30 alex while( ptr )
106 0c471b84 2002-11-30 alex {
107 0c471b84 2002-11-30 alex ngt_TrimStr( ptr );
108 0c471b84 2002-11-30 alex c = Client_Search( ptr );
109 0c471b84 2002-11-30 alex if( c && ( Client_Type( c ) == CLIENT_USER ))
110 0c471b84 2002-11-30 alex {
111 0c471b84 2002-11-30 alex /* Dieser Nick ist "online" */
112 6626395c 2002-12-26 alex strlcat( rpl, ptr, sizeof( rpl ));
113 6626395c 2002-12-26 alex strlcat( rpl, " ", sizeof( rpl ));
114 0c471b84 2002-11-30 alex }
115 0c471b84 2002-11-30 alex ptr = strtok( NULL, " " );
116 0c471b84 2002-11-30 alex }
117 0c471b84 2002-11-30 alex }
118 85acb824 2005-02-04 alex ngt_TrimLastChr(rpl, ' ');
119 0c471b84 2002-11-30 alex
120 f0349f52 2002-12-02 alex return IRC_WriteStrClient( Client, rpl, Client_ID( Client ) );
121 0c471b84 2002-11-30 alex } /* IRC_ISON */
122 0c471b84 2002-11-30 alex
123 0c471b84 2002-11-30 alex
124 8adff592 2005-03-19 fw GLOBAL bool
125 0c471b84 2002-11-30 alex IRC_LINKS( CLIENT *Client, REQUEST *Req )
126 0c471b84 2002-11-30 alex {
127 0c471b84 2002-11-30 alex CLIENT *target, *from, *c;
128 8adff592 2005-03-19 fw char *mask;
129 0c471b84 2002-11-30 alex
130 0c471b84 2002-11-30 alex assert( Client != NULL );
131 0c471b84 2002-11-30 alex assert( Req != NULL );
132 0c471b84 2002-11-30 alex
133 0c471b84 2002-11-30 alex /* Falsche Anzahl Parameter? */
134 0c471b84 2002-11-30 alex if(( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
135 0c471b84 2002-11-30 alex
136 0c471b84 2002-11-30 alex /* Server-Mask ermitteln */
137 0c471b84 2002-11-30 alex if( Req->argc > 0 ) mask = Req->argv[Req->argc - 1];
138 0c471b84 2002-11-30 alex else mask = "*";
139 0c471b84 2002-11-30 alex
140 0c471b84 2002-11-30 alex /* Absender ermitteln */
141 0c471b84 2002-11-30 alex if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
142 0c471b84 2002-11-30 alex else from = Client;
143 0c471b84 2002-11-30 alex if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
144 0c471b84 2002-11-30 alex
145 0c471b84 2002-11-30 alex /* An anderen Server forwarden? */
146 0c471b84 2002-11-30 alex if( Req->argc == 2 )
147 0c471b84 2002-11-30 alex {
148 0c471b84 2002-11-30 alex target = Client_Search( Req->argv[0] );
149 e17976a1 2003-01-01 alex if(( ! target ) || ( Client_Type( target ) != CLIENT_SERVER )) return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[0] );
150 0c471b84 2002-11-30 alex else if( target != Client_ThisServer( )) return IRC_WriteStrClientPrefix( target, from, "LINKS %s %s", Req->argv[0], Req->argv[1] );
151 0c471b84 2002-11-30 alex }
152 0c471b84 2002-11-30 alex
153 0c471b84 2002-11-30 alex /* Wer ist der Absender? */
154 0c471b84 2002-11-30 alex if( Client_Type( Client ) == CLIENT_SERVER ) target = Client_Search( Req->prefix );
155 0c471b84 2002-11-30 alex else target = Client;
156 0c471b84 2002-11-30 alex if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
157 0c471b84 2002-11-30 alex
158 0c471b84 2002-11-30 alex c = Client_First( );
159 0c471b84 2002-11-30 alex while( c )
160 0c471b84 2002-11-30 alex {
161 0c471b84 2002-11-30 alex if( Client_Type( c ) == CLIENT_SERVER )
162 0c471b84 2002-11-30 alex {
163 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( target, RPL_LINKS_MSG, Client_ID( target ), Client_ID( c ), Client_ID( Client_TopServer( c ) ? Client_TopServer( c ) : Client_ThisServer( )), Client_Hops( c ), Client_Info( c ))) return DISCONNECTED;
164 0c471b84 2002-11-30 alex }
165 0c471b84 2002-11-30 alex c = Client_Next( c );
166 0c471b84 2002-11-30 alex }
167 7b6e2662 2003-11-05 alex
168 7b6e2662 2003-11-05 alex IRC_SetPenalty( target, 1 );
169 0c471b84 2002-11-30 alex return IRC_WriteStrClient( target, RPL_ENDOFLINKS_MSG, Client_ID( target ), mask );
170 0c471b84 2002-11-30 alex } /* IRC_LINKS */
171 0c471b84 2002-11-30 alex
172 0c471b84 2002-11-30 alex
173 8adff592 2005-03-19 fw GLOBAL bool
174 0c471b84 2002-11-30 alex IRC_LUSERS( CLIENT *Client, REQUEST *Req )
175 0c471b84 2002-11-30 alex {
176 0c471b84 2002-11-30 alex CLIENT *target, *from;
177 0c471b84 2002-11-30 alex
178 0c471b84 2002-11-30 alex assert( Client != NULL );
179 0c471b84 2002-11-30 alex assert( Req != NULL );
180 0c471b84 2002-11-30 alex
181 0c471b84 2002-11-30 alex /* Falsche Anzahl Parameter? */
182 0c471b84 2002-11-30 alex if(( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
183 0c471b84 2002-11-30 alex
184 0c471b84 2002-11-30 alex /* Absender ermitteln */
185 0c471b84 2002-11-30 alex if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
186 0c471b84 2002-11-30 alex else from = Client;
187 0c471b84 2002-11-30 alex if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
188 0c471b84 2002-11-30 alex
189 0c471b84 2002-11-30 alex /* An anderen Server forwarden? */
190 0c471b84 2002-11-30 alex if( Req->argc == 2 )
191 0c471b84 2002-11-30 alex {
192 0c471b84 2002-11-30 alex target = Client_Search( Req->argv[1] );
193 e17976a1 2003-01-01 alex if(( ! target ) || ( Client_Type( target ) != CLIENT_SERVER )) return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[1] );
194 0c471b84 2002-11-30 alex else if( target != Client_ThisServer( )) return IRC_WriteStrClientPrefix( target, from, "LUSERS %s %s", Req->argv[0], Req->argv[1] );
195 0c471b84 2002-11-30 alex }
196 0c471b84 2002-11-30 alex
197 0c471b84 2002-11-30 alex /* Wer ist der Absender? */
198 0c471b84 2002-11-30 alex if( Client_Type( Client ) == CLIENT_SERVER ) target = Client_Search( Req->prefix );
199 0c471b84 2002-11-30 alex else target = Client;
200 0c471b84 2002-11-30 alex if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
201 0c471b84 2002-11-30 alex
202 0c471b84 2002-11-30 alex IRC_Send_LUSERS( target );
203 0c471b84 2002-11-30 alex
204 7b6e2662 2003-11-05 alex IRC_SetPenalty( target, 1 );
205 0c471b84 2002-11-30 alex return CONNECTED;
206 0c471b84 2002-11-30 alex } /* IRC_LUSERS */
207 0c471b84 2002-11-30 alex
208 0c471b84 2002-11-30 alex
209 8adff592 2005-03-19 fw GLOBAL bool
210 0c471b84 2002-11-30 alex IRC_MOTD( CLIENT *Client, REQUEST *Req )
211 0c471b84 2002-11-30 alex {
212 0c471b84 2002-11-30 alex CLIENT *from, *target;
213 0c471b84 2002-11-30 alex
214 0c471b84 2002-11-30 alex assert( Client != NULL );
215 0c471b84 2002-11-30 alex assert( Req != NULL );
216 0c471b84 2002-11-30 alex
217 0c471b84 2002-11-30 alex /* Falsche Anzahl Parameter? */
218 0c471b84 2002-11-30 alex if( Req->argc > 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
219 0c471b84 2002-11-30 alex
220 0c471b84 2002-11-30 alex /* From aus Prefix ermitteln */
221 0c471b84 2002-11-30 alex if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
222 0c471b84 2002-11-30 alex else from = Client;
223 7924fafb 2002-12-16 alex if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
224 0c471b84 2002-11-30 alex
225 0c471b84 2002-11-30 alex if( Req->argc == 1 )
226 0c471b84 2002-11-30 alex {
227 0c471b84 2002-11-30 alex /* an anderen Server forwarden */
228 0c471b84 2002-11-30 alex target = Client_Search( Req->argv[0] );
229 e17976a1 2003-01-01 alex if(( ! target ) || ( Client_Type( target ) != CLIENT_SERVER )) return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[0] );
230 0c471b84 2002-11-30 alex
231 0c471b84 2002-11-30 alex if( target != Client_ThisServer( ))
232 0c471b84 2002-11-30 alex {
233 0c471b84 2002-11-30 alex /* Ok, anderer Server ist das Ziel: forwarden */
234 0c471b84 2002-11-30 alex return IRC_WriteStrClientPrefix( target, from, "MOTD %s", Req->argv[0] );
235 0c471b84 2002-11-30 alex }
236 0c471b84 2002-11-30 alex }
237 0c471b84 2002-11-30 alex
238 7b6e2662 2003-11-05 alex IRC_SetPenalty( from, 3 );
239 0c471b84 2002-11-30 alex return IRC_Show_MOTD( from );
240 0c471b84 2002-11-30 alex } /* IRC_MOTD */
241 0c471b84 2002-11-30 alex
242 0c471b84 2002-11-30 alex
243 8adff592 2005-03-19 fw GLOBAL bool
244 0c471b84 2002-11-30 alex IRC_NAMES( CLIENT *Client, REQUEST *Req )
245 0c471b84 2002-11-30 alex {
246 8adff592 2005-03-19 fw char rpl[COMMAND_LEN], *ptr;
247 0c471b84 2002-11-30 alex CLIENT *target, *from, *c;
248 0c471b84 2002-11-30 alex CHANNEL *chan;
249 0c471b84 2002-11-30 alex
250 0c471b84 2002-11-30 alex assert( Client != NULL );
251 0c471b84 2002-11-30 alex assert( Req != NULL );
252 0c471b84 2002-11-30 alex
253 0c471b84 2002-11-30 alex /* Falsche Anzahl Parameter? */
254 0c471b84 2002-11-30 alex if( Req->argc > 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
255 0c471b84 2002-11-30 alex
256 0c471b84 2002-11-30 alex /* From aus Prefix ermitteln */
257 0c471b84 2002-11-30 alex if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
258 0c471b84 2002-11-30 alex else from = Client;
259 7924fafb 2002-12-16 alex if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
260 0c471b84 2002-11-30 alex
261 0c471b84 2002-11-30 alex if( Req->argc == 2 )
262 0c471b84 2002-11-30 alex {
263 0c471b84 2002-11-30 alex /* an anderen Server forwarden */
264 0c471b84 2002-11-30 alex target = Client_Search( Req->argv[1] );
265 e17976a1 2003-01-01 alex if(( ! target ) || ( Client_Type( target ) != CLIENT_SERVER )) return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[1] );
266 0c471b84 2002-11-30 alex
267 0c471b84 2002-11-30 alex if( target != Client_ThisServer( ))
268 0c471b84 2002-11-30 alex {
269 0c471b84 2002-11-30 alex /* Ok, anderer Server ist das Ziel: forwarden */
270 0c471b84 2002-11-30 alex return IRC_WriteStrClientPrefix( target, from, "NAMES %s :%s", Req->argv[0], Req->argv[1] );
271 0c471b84 2002-11-30 alex }
272 0c471b84 2002-11-30 alex }
273 0c471b84 2002-11-30 alex
274 0c471b84 2002-11-30 alex if( Req->argc > 0 )
275 0c471b84 2002-11-30 alex {
276 0c471b84 2002-11-30 alex /* bestimmte Channels durchgehen */
277 0c471b84 2002-11-30 alex ptr = strtok( Req->argv[0], "," );
278 0c471b84 2002-11-30 alex while( ptr )
279 0c471b84 2002-11-30 alex {
280 0c471b84 2002-11-30 alex chan = Channel_Search( ptr );
281 0c471b84 2002-11-30 alex if( chan )
282 0c471b84 2002-11-30 alex {
283 0c471b84 2002-11-30 alex /* Namen ausgeben */
284 0c471b84 2002-11-30 alex if( ! IRC_Send_NAMES( from, chan )) return DISCONNECTED;
285 0c471b84 2002-11-30 alex }
286 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( from, RPL_ENDOFNAMES_MSG, Client_ID( from ), ptr )) return DISCONNECTED;
287 0c471b84 2002-11-30 alex
288 0c471b84 2002-11-30 alex /* naechsten Namen ermitteln */
289 0c471b84 2002-11-30 alex ptr = strtok( NULL, "," );
290 0c471b84 2002-11-30 alex }
291 0c471b84 2002-11-30 alex return CONNECTED;
292 0c471b84 2002-11-30 alex }
293 0c471b84 2002-11-30 alex
294 0c471b84 2002-11-30 alex /* alle Channels durchgehen */
295 0c471b84 2002-11-30 alex chan = Channel_First( );
296 0c471b84 2002-11-30 alex while( chan )
297 0c471b84 2002-11-30 alex {
298 0c471b84 2002-11-30 alex /* Namen ausgeben */
299 0c471b84 2002-11-30 alex if( ! IRC_Send_NAMES( from, chan )) return DISCONNECTED;
300 0c471b84 2002-11-30 alex
301 0c471b84 2002-11-30 alex /* naechster Channel */
302 0c471b84 2002-11-30 alex chan = Channel_Next( chan );
303 0c471b84 2002-11-30 alex }
304 0c471b84 2002-11-30 alex
305 0c471b84 2002-11-30 alex /* Nun noch alle Clients ausgeben, die in keinem Channel sind */
306 0c471b84 2002-11-30 alex c = Client_First( );
307 b316c380 2002-12-26 alex snprintf( rpl, sizeof( rpl ), RPL_NAMREPLY_MSG, Client_ID( from ), "*", "*" );
308 0c471b84 2002-11-30 alex while( c )
309 0c471b84 2002-11-30 alex {
310 0c471b84 2002-11-30 alex if(( Client_Type( c ) == CLIENT_USER ) && ( Channel_FirstChannelOf( c ) == NULL ) && ( ! strchr( Client_Modes( c ), 'i' )))
311 0c471b84 2002-11-30 alex {
312 0c471b84 2002-11-30 alex /* Okay, das ist ein User: anhaengen */
313 6626395c 2002-12-26 alex if( rpl[strlen( rpl ) - 1] != ':' ) strlcat( rpl, " ", sizeof( rpl ));
314 6626395c 2002-12-26 alex strlcat( rpl, Client_ID( c ), sizeof( rpl ));
315 0c471b84 2002-11-30 alex
316 0c471b84 2002-11-30 alex if( strlen( rpl ) > ( LINE_LEN - CLIENT_NICK_LEN - 4 ))
317 0c471b84 2002-11-30 alex {
318 0c471b84 2002-11-30 alex /* Zeile wird zu lang: senden! */
319 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( from, "%s", rpl )) return DISCONNECTED;
320 b316c380 2002-12-26 alex snprintf( rpl, sizeof( rpl ), RPL_NAMREPLY_MSG, Client_ID( from ), "*", "*" );
321 0c471b84 2002-11-30 alex }
322 0c471b84 2002-11-30 alex }
323 0c471b84 2002-11-30 alex
324 0c471b84 2002-11-30 alex /* naechster Client */
325 0c471b84 2002-11-30 alex c = Client_Next( c );
326 0c471b84 2002-11-30 alex }
327 0c471b84 2002-11-30 alex if( rpl[strlen( rpl ) - 1] != ':')
328 0c471b84 2002-11-30 alex {
329 0c471b84 2002-11-30 alex /* es wurden User gefunden */
330 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( from, "%s", rpl )) return DISCONNECTED;
331 0c471b84 2002-11-30 alex }
332 0c471b84 2002-11-30 alex
333 7b6e2662 2003-11-05 alex IRC_SetPenalty( from, 1 );
334 0c471b84 2002-11-30 alex return IRC_WriteStrClient( from, RPL_ENDOFNAMES_MSG, Client_ID( from ), "*" );
335 0c471b84 2002-11-30 alex } /* IRC_NAMES */
336 0c471b84 2002-11-30 alex
337 0c471b84 2002-11-30 alex
338 8adff592 2005-03-19 fw GLOBAL bool
339 0c471b84 2002-11-30 alex IRC_STATS( CLIENT *Client, REQUEST *Req )
340 0c471b84 2002-11-30 alex {
341 bad7ac62 2002-12-02 alex CLIENT *from, *target, *cl;
342 bad7ac62 2002-12-02 alex CONN_ID con;
343 8adff592 2005-03-19 fw char query;
344 210282d0 2002-12-18 alex COMMAND *cmd;
345 0c471b84 2002-11-30 alex
346 0c471b84 2002-11-30 alex assert( Client != NULL );
347 0c471b84 2002-11-30 alex assert( Req != NULL );
348 0c471b84 2002-11-30 alex
349 0c471b84 2002-11-30 alex /* Falsche Anzahl Parameter? */
350 0c471b84 2002-11-30 alex if( Req->argc > 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
351 0c471b84 2002-11-30 alex
352 0c471b84 2002-11-30 alex /* From aus Prefix ermitteln */
353 0c471b84 2002-11-30 alex if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
354 0c471b84 2002-11-30 alex else from = Client;
355 7924fafb 2002-12-16 alex if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
356 0c471b84 2002-11-30 alex
357 0c471b84 2002-11-30 alex if( Req->argc == 2 )
358 0c471b84 2002-11-30 alex {
359 0c471b84 2002-11-30 alex /* an anderen Server forwarden */
360 e50d568f 2002-11-30 alex target = Client_Search( Req->argv[1] );
361 e17976a1 2003-01-01 alex if(( ! target ) || ( Client_Type( target ) != CLIENT_SERVER )) return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[1] );
362 0c471b84 2002-11-30 alex
363 0c471b84 2002-11-30 alex if( target != Client_ThisServer( ))
364 0c471b84 2002-11-30 alex {
365 0c471b84 2002-11-30 alex /* Ok, anderer Server ist das Ziel: forwarden */
366 7924fafb 2002-12-16 alex return IRC_WriteStrClientPrefix( target, from, "STATS %s %s", Req->argv[0], Req->argv[1] );
367 0c471b84 2002-11-30 alex }
368 0c471b84 2002-11-30 alex }
369 0c471b84 2002-11-30 alex
370 0c471b84 2002-11-30 alex if( Req->argc > 0 ) query = Req->argv[0][0] ? Req->argv[0][0] : '*';
371 0c471b84 2002-11-30 alex else query = '*';
372 bad7ac62 2002-12-02 alex
373 bad7ac62 2002-12-02 alex switch ( query )
374 bad7ac62 2002-12-02 alex {
375 bad7ac62 2002-12-02 alex case 'l': /* Links */
376 bad7ac62 2002-12-02 alex case 'L':
377 bad7ac62 2002-12-02 alex con = Conn_First( );
378 bad7ac62 2002-12-02 alex while( con != NONE )
379 bad7ac62 2002-12-02 alex {
380 bad7ac62 2002-12-02 alex cl = Client_GetFromConn( con );
381 98677b43 2002-12-18 alex if( cl && (( Client_Type( cl ) == CLIENT_SERVER ) || ( cl == Client )))
382 bad7ac62 2002-12-02 alex {
383 98677b43 2002-12-18 alex /* Server link or our own connection */
384 c40592d2 2003-12-26 alex #ifdef ZLIB
385 bad7ac62 2002-12-02 alex if( Conn_Options( con ) & CONN_ZIP )
386 bad7ac62 2002-12-02 alex {
387 8adff592 2005-03-19 fw if( ! IRC_WriteStrClient( from, RPL_STATSLINKINFOZIP_MSG, Client_ID( from ), Client_Mask( cl ), Conn_SendQ( con ), Conn_SendMsg( con ), Zip_SendBytes( con ), Conn_SendBytes( con ), Conn_RecvMsg( con ), Zip_RecvBytes( con ), Conn_RecvBytes( con ), (long)( time( NULL ) - Conn_StartTime( con )))) return DISCONNECTED;
388 bad7ac62 2002-12-02 alex }
389 bad7ac62 2002-12-02 alex else
390 bad7ac62 2002-12-02 alex #endif
391 bad7ac62 2002-12-02 alex {
392 8adff592 2005-03-19 fw if( ! IRC_WriteStrClient( from, RPL_STATSLINKINFO_MSG, Client_ID( from ), Client_Mask( cl ), Conn_SendQ( con ), Conn_SendMsg( con ), Conn_SendBytes( con ), Conn_RecvMsg( con ), Conn_RecvBytes( con ), (long)( time( NULL ) - Conn_StartTime( con )))) return DISCONNECTED;
393 bad7ac62 2002-12-02 alex }
394 bad7ac62 2002-12-02 alex }
395 bad7ac62 2002-12-02 alex con = Conn_Next( con );
396 bad7ac62 2002-12-02 alex }
397 bad7ac62 2002-12-02 alex break;
398 bad7ac62 2002-12-02 alex case 'm': /* IRC-Befehle */
399 bad7ac62 2002-12-02 alex case 'M':
400 210282d0 2002-12-18 alex cmd = Parse_GetCommandStruct( );
401 210282d0 2002-12-18 alex while( cmd->name )
402 210282d0 2002-12-18 alex {
403 210282d0 2002-12-18 alex if( cmd->lcount > 0 || cmd->rcount > 0 )
404 210282d0 2002-12-18 alex {
405 210282d0 2002-12-18 alex if( ! IRC_WriteStrClient( from, RPL_STATSCOMMANDS_MSG, Client_ID( from ), cmd->name, cmd->lcount, cmd->bytes, cmd->rcount )) return DISCONNECTED;
406 210282d0 2002-12-18 alex }
407 210282d0 2002-12-18 alex cmd++;
408 210282d0 2002-12-18 alex }
409 bad7ac62 2002-12-02 alex break;
410 bad7ac62 2002-12-02 alex }
411 0c471b84 2002-11-30 alex
412 7b6e2662 2003-11-05 alex IRC_SetPenalty( from, 2 );
413 0c471b84 2002-11-30 alex return IRC_WriteStrClient( from, RPL_ENDOFSTATS_MSG, Client_ID( from ), query );
414 0c471b84 2002-11-30 alex } /* IRC_STATS */
415 0c471b84 2002-11-30 alex
416 0c471b84 2002-11-30 alex
417 8adff592 2005-03-19 fw GLOBAL bool
418 0c471b84 2002-11-30 alex IRC_TIME( CLIENT *Client, REQUEST *Req )
419 0c471b84 2002-11-30 alex {
420 0c471b84 2002-11-30 alex CLIENT *from, *target;
421 8adff592 2005-03-19 fw char t_str[64];
422 0c471b84 2002-11-30 alex time_t t;
423 0c471b84 2002-11-30 alex
424 0c471b84 2002-11-30 alex assert( Client != NULL );
425 0c471b84 2002-11-30 alex assert( Req != NULL );
426 0c471b84 2002-11-30 alex
427 0c471b84 2002-11-30 alex /* Falsche Anzahl Parameter? */
428 0c471b84 2002-11-30 alex if( Req->argc > 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
429 0c471b84 2002-11-30 alex
430 0c471b84 2002-11-30 alex /* From aus Prefix ermitteln */
431 0c471b84 2002-11-30 alex if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
432 0c471b84 2002-11-30 alex else from = Client;
433 7924fafb 2002-12-16 alex if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
434 0c471b84 2002-11-30 alex
435 0c471b84 2002-11-30 alex if( Req->argc == 1 )
436 0c471b84 2002-11-30 alex {
437 0c471b84 2002-11-30 alex /* an anderen Server forwarden */
438 0c471b84 2002-11-30 alex target = Client_Search( Req->argv[0] );
439 e17976a1 2003-01-01 alex if(( ! target ) || ( Client_Type( target ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[0] );
440 0c471b84 2002-11-30 alex
441 0c471b84 2002-11-30 alex if( target != Client_ThisServer( ))
442 0c471b84 2002-11-30 alex {
443 0c471b84 2002-11-30 alex /* Ok, anderer Server ist das Ziel: forwarden */
444 0c471b84 2002-11-30 alex return IRC_WriteStrClientPrefix( target, from, "TIME %s", Req->argv[0] );
445 0c471b84 2002-11-30 alex }
446 0c471b84 2002-11-30 alex }
447 0c471b84 2002-11-30 alex
448 0c471b84 2002-11-30 alex t = time( NULL );
449 8adff592 2005-03-19 fw (void)strftime( t_str, 60, "%A %B %d %Y -- %H:%M %Z", localtime( &t ));
450 0c471b84 2002-11-30 alex return IRC_WriteStrClient( from, RPL_TIME_MSG, Client_ID( from ), Client_ID( Client_ThisServer( )), t_str );
451 0c471b84 2002-11-30 alex } /* IRC_TIME */
452 0c471b84 2002-11-30 alex
453 0c471b84 2002-11-30 alex
454 8adff592 2005-03-19 fw GLOBAL bool
455 0c471b84 2002-11-30 alex IRC_USERHOST( CLIENT *Client, REQUEST *Req )
456 0c471b84 2002-11-30 alex {
457 8adff592 2005-03-19 fw char rpl[COMMAND_LEN];
458 0c471b84 2002-11-30 alex CLIENT *c;
459 8adff592 2005-03-19 fw int max, i;
460 0c471b84 2002-11-30 alex
461 0c471b84 2002-11-30 alex assert( Client != NULL );
462 0c471b84 2002-11-30 alex assert( Req != NULL );
463 0c471b84 2002-11-30 alex
464 0c471b84 2002-11-30 alex /* Falsche Anzahl Parameter? */
465 0c471b84 2002-11-30 alex if(( Req->argc < 1 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
466 0c471b84 2002-11-30 alex
467 0c471b84 2002-11-30 alex if( Req->argc > 5 ) max = 5;
468 0c471b84 2002-11-30 alex else max = Req->argc;
469 0c471b84 2002-11-30 alex
470 0c471b84 2002-11-30 alex strcpy( rpl, RPL_USERHOST_MSG );
471 0c471b84 2002-11-30 alex for( i = 0; i < max; i++ )
472 0c471b84 2002-11-30 alex {
473 0c471b84 2002-11-30 alex c = Client_Search( Req->argv[i] );
474 0c471b84 2002-11-30 alex if( c && ( Client_Type( c ) == CLIENT_USER ))
475 0c471b84 2002-11-30 alex {
476 0c471b84 2002-11-30 alex /* Dieser Nick ist "online" */
477 6626395c 2002-12-26 alex strlcat( rpl, Client_ID( c ), sizeof( rpl ));
478 6626395c 2002-12-26 alex if( Client_HasMode( c, 'o' )) strlcat( rpl, "*", sizeof( rpl ));
479 6626395c 2002-12-26 alex strlcat( rpl, "=", sizeof( rpl ));
480 6626395c 2002-12-26 alex if( Client_HasMode( c, 'a' )) strlcat( rpl, "-", sizeof( rpl ));
481 6626395c 2002-12-26 alex else strlcat( rpl, "+", sizeof( rpl ));
482 6626395c 2002-12-26 alex strlcat( rpl, Client_User( c ), sizeof( rpl ));
483 6626395c 2002-12-26 alex strlcat( rpl, "@", sizeof( rpl ));
484 6626395c 2002-12-26 alex strlcat( rpl, Client_Hostname( c ), sizeof( rpl ));
485 6626395c 2002-12-26 alex strlcat( rpl, " ", sizeof( rpl ));
486 0c471b84 2002-11-30 alex }
487 0c471b84 2002-11-30 alex }
488 85acb824 2005-02-04 alex ngt_TrimLastChr( rpl, ' ');
489 0c471b84 2002-11-30 alex
490 f0349f52 2002-12-02 alex return IRC_WriteStrClient( Client, rpl, Client_ID( Client ) );
491 0c471b84 2002-11-30 alex } /* IRC_USERHOST */
492 0c471b84 2002-11-30 alex
493 0c471b84 2002-11-30 alex
494 8adff592 2005-03-19 fw GLOBAL bool
495 0c471b84 2002-11-30 alex IRC_VERSION( CLIENT *Client, REQUEST *Req )
496 0c471b84 2002-11-30 alex {
497 0c471b84 2002-11-30 alex CLIENT *target, *prefix;
498 260b8e5f 2003-06-06 alex #ifdef CVSDATE
499 8adff592 2005-03-19 fw char ver[12], vertxt[30];
500 260b8e5f 2003-06-06 alex #endif
501 0c471b84 2002-11-30 alex
502 0c471b84 2002-11-30 alex assert( Client != NULL );
503 0c471b84 2002-11-30 alex assert( Req != NULL );
504 0c471b84 2002-11-30 alex
505 0c471b84 2002-11-30 alex /* Falsche Anzahl Parameter? */
506 0c471b84 2002-11-30 alex if(( Req->argc > 1 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
507 0c471b84 2002-11-30 alex
508 0c471b84 2002-11-30 alex /* Ziel suchen */
509 0c471b84 2002-11-30 alex if( Req->argc == 1 ) target = Client_Search( Req->argv[0] );
510 0c471b84 2002-11-30 alex else target = Client_ThisServer( );
511 0c471b84 2002-11-30 alex
512 0c471b84 2002-11-30 alex /* Prefix ermitteln */
513 0c471b84 2002-11-30 alex if( Client_Type( Client ) == CLIENT_SERVER ) prefix = Client_Search( Req->prefix );
514 0c471b84 2002-11-30 alex else prefix = Client;
515 7924fafb 2002-12-16 alex if( ! prefix ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
516 0c471b84 2002-11-30 alex
517 0c471b84 2002-11-30 alex /* An anderen Server weiterleiten? */
518 0c471b84 2002-11-30 alex if( target != Client_ThisServer( ))
519 0c471b84 2002-11-30 alex {
520 e17976a1 2003-01-01 alex if(( ! target ) || ( Client_Type( target ) != CLIENT_SERVER )) return IRC_WriteStrClient( prefix, ERR_NOSUCHSERVER_MSG, Client_ID( prefix ), Req->argv[0] );
521 0c471b84 2002-11-30 alex
522 0c471b84 2002-11-30 alex /* forwarden */
523 0c471b84 2002-11-30 alex IRC_WriteStrClientPrefix( target, prefix, "VERSION %s", Req->argv[0] );
524 0c471b84 2002-11-30 alex return CONNECTED;
525 0c471b84 2002-11-30 alex }
526 0c471b84 2002-11-30 alex
527 0c471b84 2002-11-30 alex /* mit Versionsinfo antworten */
528 7b6e2662 2003-11-05 alex IRC_SetPenalty( Client, 1 );
529 260b8e5f 2003-06-06 alex #ifdef CVSDATE
530 260b8e5f 2003-06-06 alex strlcpy( ver, CVSDATE, sizeof( ver ));
531 260b8e5f 2003-06-06 alex strncpy( ver + 4, ver + 5, 2 );
532 260b8e5f 2003-06-06 alex strncpy( ver + 6, ver + 8, 3 );
533 05e2c0f0 2003-12-04 alex snprintf( vertxt, sizeof( vertxt ), "%s(%s)", PACKAGE_VERSION, ver );
534 894cd2cd 2005-02-09 alex return IRC_WriteStrClient( Client, RPL_VERSION_MSG, Client_ID( prefix ), PACKAGE_NAME, vertxt, NGIRCd_DebugLevel, Conf_ServerName, NGIRCd_VersionAddition );
535 260b8e5f 2003-06-06 alex #else
536 894cd2cd 2005-02-09 alex return IRC_WriteStrClient( Client, RPL_VERSION_MSG, Client_ID( prefix ), PACKAGE_NAME, PACKAGE_VERSION, NGIRCd_DebugLevel, Conf_ServerName, NGIRCd_VersionAddition );
537 260b8e5f 2003-06-06 alex #endif
538 0c471b84 2002-11-30 alex } /* IRC_VERSION */
539 0c471b84 2002-11-30 alex
540 0c471b84 2002-11-30 alex
541 8adff592 2005-03-19 fw GLOBAL bool
542 0c471b84 2002-11-30 alex IRC_WHO( CLIENT *Client, REQUEST *Req )
543 0c471b84 2002-11-30 alex {
544 8adff592 2005-03-19 fw bool ok, only_ops;
545 8adff592 2005-03-19 fw char flags[8], *ptr;
546 0c471b84 2002-11-30 alex CL2CHAN *cl2chan;
547 4ef172d6 2005-03-02 alex CHANNEL *chan, *cn;
548 0c471b84 2002-11-30 alex CLIENT *c;
549 0c471b84 2002-11-30 alex
550 0c471b84 2002-11-30 alex assert( Client != NULL );
551 0c471b84 2002-11-30 alex assert( Req != NULL );
552 0c471b84 2002-11-30 alex
553 0c471b84 2002-11-30 alex /* Falsche Anzahl Parameter? */
554 0c471b84 2002-11-30 alex if(( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
555 0c471b84 2002-11-30 alex
556 8adff592 2005-03-19 fw only_ops = false;
557 0c471b84 2002-11-30 alex chan = NULL;
558 0c471b84 2002-11-30 alex
559 0c471b84 2002-11-30 alex if( Req->argc == 2 )
560 0c471b84 2002-11-30 alex {
561 0c471b84 2002-11-30 alex /* Nur OPs anzeigen? */
562 8adff592 2005-03-19 fw if( strcmp( Req->argv[1], "o" ) == 0 ) only_ops = true;
563 0c471b84 2002-11-30 alex #ifdef STRICT_RFC
564 0c471b84 2002-11-30 alex else return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
565 0c471b84 2002-11-30 alex #endif
566 0c471b84 2002-11-30 alex }
567 0c471b84 2002-11-30 alex
568 0c471b84 2002-11-30 alex if( Req->argc >= 1 )
569 0c471b84 2002-11-30 alex {
570 0c471b84 2002-11-30 alex /* wurde ein Channel oder Nick-Mask angegeben? */
571 0c471b84 2002-11-30 alex chan = Channel_Search( Req->argv[0] );
572 0c471b84 2002-11-30 alex }
573 0c471b84 2002-11-30 alex
574 0c471b84 2002-11-30 alex if( chan )
575 0c471b84 2002-11-30 alex {
576 0c471b84 2002-11-30 alex /* User eines Channels ausgeben */
577 0c471b84 2002-11-30 alex if( ! IRC_Send_WHO( Client, chan, only_ops )) return DISCONNECTED;
578 0c471b84 2002-11-30 alex }
579 0c471b84 2002-11-30 alex
580 0c471b84 2002-11-30 alex c = Client_First( );
581 0c471b84 2002-11-30 alex while( c )
582 0c471b84 2002-11-30 alex {
583 0c471b84 2002-11-30 alex if(( Client_Type( c ) == CLIENT_USER ) && ( ! strchr( Client_Modes( c ), 'i' )))
584 0c471b84 2002-11-30 alex {
585 8adff592 2005-03-19 fw ok = false;
586 8adff592 2005-03-19 fw if( Req->argc == 0 ) ok = true;
587 0c471b84 2002-11-30 alex else
588 0c471b84 2002-11-30 alex {
589 8adff592 2005-03-19 fw if( strcasecmp( Req->argv[0], Client_ID( c )) == 0 ) ok = true;
590 8adff592 2005-03-19 fw else if( strcmp( Req->argv[0], "0" ) == 0 ) ok = true;
591 0c471b84 2002-11-30 alex }
592 0c471b84 2002-11-30 alex
593 0c471b84 2002-11-30 alex if( ok && (( ! only_ops ) || ( strchr( Client_Modes( c ), 'o' ))))
594 0c471b84 2002-11-30 alex {
595 4ef172d6 2005-03-02 alex /* Get flags */
596 0c471b84 2002-11-30 alex strcpy( flags, "H" );
597 6626395c 2002-12-26 alex if( strchr( Client_Modes( c ), 'o' )) strlcat( flags, "*", sizeof( flags ));
598 0c471b84 2002-11-30 alex
599 4ef172d6 2005-03-02 alex /* Search suitable channel */
600 0c471b84 2002-11-30 alex cl2chan = Channel_FirstChannelOf( c );
601 4ef172d6 2005-03-02 alex while( cl2chan )
602 4ef172d6 2005-03-02 alex {
603 4ef172d6 2005-03-02 alex cn = Channel_GetChannel( cl2chan );
604 4ef172d6 2005-03-02 alex if( Channel_IsMemberOf( cn, Client ) ||
605 4ef172d6 2005-03-02 alex ! strchr( Channel_Modes( cn ), 's' ))
606 4ef172d6 2005-03-02 alex {
607 4ef172d6 2005-03-02 alex ptr = Channel_Name( cn );
608 4ef172d6 2005-03-02 alex break;
609 4ef172d6 2005-03-02 alex }
610 4ef172d6 2005-03-02 alex cl2chan = Channel_NextChannelOf( c, cl2chan );
611 4ef172d6 2005-03-02 alex }
612 4ef172d6 2005-03-02 alex if( ! cl2chan ) ptr = "*";
613 4ef172d6 2005-03-02 alex
614 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( Client, RPL_WHOREPLY_MSG, Client_ID( Client ), ptr, Client_User( c ), Client_Hostname( c ), Client_ID( Client_Introducer( c )), Client_ID( c ), flags, Client_Hops( c ), Client_Info( c ))) return DISCONNECTED;
615 0c471b84 2002-11-30 alex }
616 0c471b84 2002-11-30 alex }
617 0c471b84 2002-11-30 alex
618 0c471b84 2002-11-30 alex /* naechster Client */
619 0c471b84 2002-11-30 alex c = Client_Next( c );
620 0c471b84 2002-11-30 alex }
621 0c471b84 2002-11-30 alex
622 0c471b84 2002-11-30 alex if( chan ) return IRC_WriteStrClient( Client, RPL_ENDOFWHO_MSG, Client_ID( Client ), Channel_Name( chan ));
623 0c471b84 2002-11-30 alex else if( Req->argc == 0 ) return IRC_WriteStrClient( Client, RPL_ENDOFWHO_MSG, Client_ID( Client ), "*" );
624 0c471b84 2002-11-30 alex else return IRC_WriteStrClient( Client, RPL_ENDOFWHO_MSG, Client_ID( Client ), Req->argv[0] );
625 0c471b84 2002-11-30 alex } /* IRC_WHO */
626 0c471b84 2002-11-30 alex
627 0c471b84 2002-11-30 alex
628 8adff592 2005-03-19 fw GLOBAL bool
629 0c471b84 2002-11-30 alex IRC_WHOIS( CLIENT *Client, REQUEST *Req )
630 0c471b84 2002-11-30 alex {
631 0c471b84 2002-11-30 alex CLIENT *from, *target, *c;
632 8adff592 2005-03-19 fw char str[LINE_LEN + 1];
633 0c471b84 2002-11-30 alex CL2CHAN *cl2chan;
634 0c471b84 2002-11-30 alex CHANNEL *chan;
635 0c471b84 2002-11-30 alex
636 0c471b84 2002-11-30 alex assert( Client != NULL );
637 0c471b84 2002-11-30 alex assert( Req != NULL );
638 0c471b84 2002-11-30 alex
639 e17976a1 2003-01-01 alex /* Bad number of parameters? */
640 0c471b84 2002-11-30 alex if(( Req->argc < 1 ) || ( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
641 0c471b84 2002-11-30 alex
642 e17976a1 2003-01-01 alex /* Search client */
643 0c471b84 2002-11-30 alex c = Client_Search( Req->argv[Req->argc - 1] );
644 0c471b84 2002-11-30 alex if(( ! c ) || ( Client_Type( c ) != CLIENT_USER )) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->argv[Req->argc - 1] );
645 0c471b84 2002-11-30 alex
646 e17976a1 2003-01-01 alex /* Search sender of the WHOIS */
647 0c471b84 2002-11-30 alex if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
648 0c471b84 2002-11-30 alex else from = Client;
649 0c471b84 2002-11-30 alex if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
650 0c471b84 2002-11-30 alex
651 e17976a1 2003-01-01 alex /* Forward to other server? */
652 0c471b84 2002-11-30 alex if( Req->argc > 1 )
653 0c471b84 2002-11-30 alex {
654 e17976a1 2003-01-01 alex /* Search target server (can be specified as nick of that server!) */
655 e17976a1 2003-01-01 alex target = Client_Search( Req->argv[0] );
656 e17976a1 2003-01-01 alex if( ! target ) return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[0] );
657 0c471b84 2002-11-30 alex }
658 0c471b84 2002-11-30 alex else target = Client_ThisServer( );
659 0c471b84 2002-11-30 alex
660 0c471b84 2002-11-30 alex assert( target != NULL );
661 0c471b84 2002-11-30 alex
662 e17976a1 2003-01-01 alex if(( Client_NextHop( target ) != Client_ThisServer( )) && ( Client_Type( Client_NextHop( target )) == CLIENT_SERVER )) return IRC_WriteStrClientPrefix( target, from, "WHOIS %s :%s", Req->argv[0], Req->argv[1] );
663 0c471b84 2002-11-30 alex
664 e17976a1 2003-01-01 alex /* Nick, user and name */
665 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( from, RPL_WHOISUSER_MSG, Client_ID( from ), Client_ID( c ), Client_User( c ), Client_Hostname( c ), Client_Info( c ))) return DISCONNECTED;
666 0c471b84 2002-11-30 alex
667 0c471b84 2002-11-30 alex /* Server */
668 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( from, RPL_WHOISSERVER_MSG, Client_ID( from ), Client_ID( c ), Client_ID( Client_Introducer( c )), Client_Info( Client_Introducer( c )))) return DISCONNECTED;
669 0c471b84 2002-11-30 alex
670 0c471b84 2002-11-30 alex /* Channels */
671 b316c380 2002-12-26 alex snprintf( str, sizeof( str ), RPL_WHOISCHANNELS_MSG, Client_ID( from ), Client_ID( c ));
672 0c471b84 2002-11-30 alex cl2chan = Channel_FirstChannelOf( c );
673 0c471b84 2002-11-30 alex while( cl2chan )
674 0c471b84 2002-11-30 alex {
675 0c471b84 2002-11-30 alex chan = Channel_GetChannel( cl2chan );
676 0c471b84 2002-11-30 alex assert( chan != NULL );
677 4ef172d6 2005-03-02 alex
678 4ef172d6 2005-03-02 alex /* next */
679 4ef172d6 2005-03-02 alex cl2chan = Channel_NextChannelOf( c, cl2chan );
680 4ef172d6 2005-03-02 alex
681 4ef172d6 2005-03-02 alex /* Secret channel? */
682 4ef172d6 2005-03-02 alex if( strchr( Channel_Modes( chan ), 's' ) && ! Channel_IsMemberOf( chan, Client )) continue;
683 0c471b84 2002-11-30 alex
684 e17976a1 2003-01-01 alex /* Concatenate channel names */
685 6626395c 2002-12-26 alex if( str[strlen( str ) - 1] != ':' ) strlcat( str, " ", sizeof( str ));
686 6626395c 2002-12-26 alex if( strchr( Channel_UserModes( chan, c ), 'o' )) strlcat( str, "@", sizeof( str ));
687 6626395c 2002-12-26 alex else if( strchr( Channel_UserModes( chan, c ), 'v' )) strlcat( str, "+", sizeof( str ));
688 6626395c 2002-12-26 alex strlcat( str, Channel_Name( chan ), sizeof( str ));
689 0c471b84 2002-11-30 alex
690 0c471b84 2002-11-30 alex if( strlen( str ) > ( LINE_LEN - CHANNEL_NAME_LEN - 4 ))
691 0c471b84 2002-11-30 alex {
692 e17976a1 2003-01-01 alex /* Line becomes too long: send it! */
693 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( Client, "%s", str )) return DISCONNECTED;
694 b316c380 2002-12-26 alex snprintf( str, sizeof( str ), RPL_WHOISCHANNELS_MSG, Client_ID( from ), Client_ID( c ));
695 0c471b84 2002-11-30 alex }
696 0c471b84 2002-11-30 alex }
697 0c471b84 2002-11-30 alex if( str[strlen( str ) - 1] != ':')
698 0c471b84 2002-11-30 alex {
699 e17976a1 2003-01-01 alex /* There is data left to send: */
700 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( Client, "%s", str )) return DISCONNECTED;
701 0c471b84 2002-11-30 alex }
702 0c471b84 2002-11-30 alex
703 0c471b84 2002-11-30 alex /* IRC-Operator? */
704 0c471b84 2002-11-30 alex if( Client_HasMode( c, 'o' ))
705 0c471b84 2002-11-30 alex {
706 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( from, RPL_WHOISOPERATOR_MSG, Client_ID( from ), Client_ID( c ))) return DISCONNECTED;
707 0c471b84 2002-11-30 alex }
708 0c471b84 2002-11-30 alex
709 e17976a1 2003-01-01 alex /* Idle (only local clients) */
710 0c471b84 2002-11-30 alex if( Client_Conn( c ) > NONE )
711 0c471b84 2002-11-30 alex {
712 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( from, RPL_WHOISIDLE_MSG, Client_ID( from ), Client_ID( c ), Conn_GetIdle( Client_Conn ( c )))) return DISCONNECTED;
713 0c471b84 2002-11-30 alex }
714 0c471b84 2002-11-30 alex
715 0c471b84 2002-11-30 alex /* Away? */
716 0c471b84 2002-11-30 alex if( Client_HasMode( c, 'a' ))
717 0c471b84 2002-11-30 alex {
718 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( from, RPL_AWAY_MSG, Client_ID( from ), Client_ID( c ), Client_Away( c ))) return DISCONNECTED;
719 0c471b84 2002-11-30 alex }
720 0c471b84 2002-11-30 alex
721 0c471b84 2002-11-30 alex /* End of Whois */
722 0c471b84 2002-11-30 alex return IRC_WriteStrClient( from, RPL_ENDOFWHOIS_MSG, Client_ID( from ), Client_ID( c ));
723 0c471b84 2002-11-30 alex } /* IRC_WHOIS */
724 0c471b84 2002-11-30 alex
725 0c471b84 2002-11-30 alex
726 06caecb0 2005-05-16 alex /**
727 06caecb0 2005-05-16 alex * IRC "WHOWAS" function.
728 06caecb0 2005-05-16 alex * This function implements the IRC command "WHOWHAS". It handles local
729 06caecb0 2005-05-16 alex * requests and request that should be forwarded to other servers.
730 06caecb0 2005-05-16 alex */
731 8adff592 2005-03-19 fw GLOBAL bool
732 0c471b84 2002-11-30 alex IRC_WHOWAS( CLIENT *Client, REQUEST *Req )
733 0c471b84 2002-11-30 alex {
734 06caecb0 2005-05-16 alex CLIENT *target, *prefix;
735 06caecb0 2005-05-16 alex WHOWAS *whowas;
736 06caecb0 2005-05-16 alex int max, last, count, i;
737 06caecb0 2005-05-16 alex char t_str[60];
738 06caecb0 2005-05-16 alex
739 0c471b84 2002-11-30 alex assert( Client != NULL );
740 0c471b84 2002-11-30 alex assert( Req != NULL );
741 0c471b84 2002-11-30 alex
742 06caecb0 2005-05-16 alex /* Wrong number of parameters? */
743 06caecb0 2005-05-16 alex if(( Req->argc < 1 ) || ( Req->argc > 3 ))
744 06caecb0 2005-05-16 alex return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG,
745 06caecb0 2005-05-16 alex Client_ID( Client ), Req->command );
746 0c471b84 2002-11-30 alex
747 06caecb0 2005-05-16 alex /* Search taget */
748 06caecb0 2005-05-16 alex if( Req->argc == 3 )
749 06caecb0 2005-05-16 alex target = Client_Search( Req->argv[2] );
750 06caecb0 2005-05-16 alex else
751 06caecb0 2005-05-16 alex target = Client_ThisServer( );
752 0c471b84 2002-11-30 alex
753 06caecb0 2005-05-16 alex /* Get prefix */
754 06caecb0 2005-05-16 alex if( Client_Type( Client ) == CLIENT_SERVER )
755 06caecb0 2005-05-16 alex prefix = Client_Search( Req->prefix );
756 06caecb0 2005-05-16 alex else
757 06caecb0 2005-05-16 alex prefix = Client;
758 06caecb0 2005-05-16 alex
759 06caecb0 2005-05-16 alex if( ! prefix )
760 06caecb0 2005-05-16 alex return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG,
761 06caecb0 2005-05-16 alex Client_ID( Client ), Req->prefix );
762 06caecb0 2005-05-16 alex
763 06caecb0 2005-05-16 alex /* Forward to other server? */
764 06caecb0 2005-05-16 alex if( target != Client_ThisServer( ))
765 06caecb0 2005-05-16 alex {
766 06caecb0 2005-05-16 alex if(( ! target ) || ( Client_Type( target ) != CLIENT_SERVER ))
767 06caecb0 2005-05-16 alex return IRC_WriteStrClient( prefix, ERR_NOSUCHSERVER_MSG,
768 06caecb0 2005-05-16 alex Client_ID( prefix ),
769 06caecb0 2005-05-16 alex Req->argv[2] );
770 06caecb0 2005-05-16 alex
771 06caecb0 2005-05-16 alex /* Forward */
772 06caecb0 2005-05-16 alex IRC_WriteStrClientPrefix( target, prefix, "WHOWAS %s %s %s",
773 06caecb0 2005-05-16 alex Req->argv[0], Req->argv[1],
774 06caecb0 2005-05-16 alex Req->argv[2] );
775 06caecb0 2005-05-16 alex return CONNECTED;
776 06caecb0 2005-05-16 alex }
777 06caecb0 2005-05-16 alex
778 06caecb0 2005-05-16 alex whowas = Client_GetWhowas( );
779 06caecb0 2005-05-16 alex last = Client_GetLastWhowasIndex( );
780 06caecb0 2005-05-16 alex if( last < 0 ) last = 0;
781 06caecb0 2005-05-16 alex
782 06caecb0 2005-05-16 alex if( Req->argc > 1 )
783 06caecb0 2005-05-16 alex {
784 06caecb0 2005-05-16 alex max = atoi( Req->argv[1] );
785 06caecb0 2005-05-16 alex if( max < 1 ) max = MAX_WHOWAS;
786 06caecb0 2005-05-16 alex }
787 06caecb0 2005-05-16 alex else
788 06caecb0 2005-05-16 alex max = DEFAULT_WHOWAS;
789 06caecb0 2005-05-16 alex
790 06caecb0 2005-05-16 alex i = last;
791 06caecb0 2005-05-16 alex count = 0;
792 06caecb0 2005-05-16 alex do
793 06caecb0 2005-05-16 alex {
794 06caecb0 2005-05-16 alex /* Used entry? */
795 06caecb0 2005-05-16 alex if( whowas[i].time > 0 &&
796 06caecb0 2005-05-16 alex strcasecmp( Req->argv[0], whowas[i].id ) == 0 )
797 06caecb0 2005-05-16 alex {
798 06caecb0 2005-05-16 alex (void)strftime( t_str, sizeof(t_str),
799 06caecb0 2005-05-16 alex "%a %b %d %H:%M:%S %Y",
800 06caecb0 2005-05-16 alex localtime( &whowas[i].time ));
801 06caecb0 2005-05-16 alex
802 06caecb0 2005-05-16 alex if( ! IRC_WriteStrClient( prefix, RPL_WHOWASUSER_MSG,
803 06caecb0 2005-05-16 alex Client_ID( prefix ),
804 06caecb0 2005-05-16 alex whowas[i].id,
805 06caecb0 2005-05-16 alex whowas[i].user,
806 06caecb0 2005-05-16 alex whowas[i].host,
807 06caecb0 2005-05-16 alex whowas[i].info ))
808 06caecb0 2005-05-16 alex return DISCONNECTED;
809 06caecb0 2005-05-16 alex
810 06caecb0 2005-05-16 alex if( ! IRC_WriteStrClient( prefix, RPL_WHOISSERVER_MSG,
811 06caecb0 2005-05-16 alex Client_ID( prefix ),
812 06caecb0 2005-05-16 alex whowas[i].id,
813 06caecb0 2005-05-16 alex whowas[i].server, t_str ))
814 06caecb0 2005-05-16 alex return DISCONNECTED;
815 06caecb0 2005-05-16 alex
816 06caecb0 2005-05-16 alex count++;
817 06caecb0 2005-05-16 alex if( count >= max ) break;
818 06caecb0 2005-05-16 alex }
819 06caecb0 2005-05-16 alex
820 06caecb0 2005-05-16 alex /* previos entry */
821 06caecb0 2005-05-16 alex i--;
822 06caecb0 2005-05-16 alex
823 06caecb0 2005-05-16 alex /* "underflow", wrap around */
824 06caecb0 2005-05-16 alex if( i < 0 ) i = MAX_WHOWAS - 1;
825 06caecb0 2005-05-16 alex } while( i != last );
826 06caecb0 2005-05-16 alex
827 06caecb0 2005-05-16 alex return IRC_WriteStrClient( prefix, RPL_ENDOFWHOWAS_MSG,
828 06caecb0 2005-05-16 alex Client_ID( prefix ), Req->argv[0] );
829 0c471b84 2002-11-30 alex } /* IRC_WHOWAS */
830 0c471b84 2002-11-30 alex
831 0c471b84 2002-11-30 alex
832 8adff592 2005-03-19 fw GLOBAL bool
833 0c471b84 2002-11-30 alex IRC_Send_LUSERS( CLIENT *Client )
834 0c471b84 2002-11-30 alex {
835 8adff592 2005-03-19 fw long cnt;
836 0c471b84 2002-11-30 alex
837 0c471b84 2002-11-30 alex assert( Client != NULL );
838 0c471b84 2002-11-30 alex
839 212d36a3 2002-12-22 alex /* Users, services and serevers in the network */
840 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( Client, RPL_LUSERCLIENT_MSG, Client_ID( Client ), Client_UserCount( ), Client_ServiceCount( ), Client_ServerCount( ))) return DISCONNECTED;
841 0c471b84 2002-11-30 alex
842 212d36a3 2002-12-22 alex /* Number of IRC operators */
843 0c471b84 2002-11-30 alex cnt = Client_OperCount( );
844 0c471b84 2002-11-30 alex if( cnt > 0 )
845 0c471b84 2002-11-30 alex {
846 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( Client, RPL_LUSEROP_MSG, Client_ID( Client ), cnt )) return DISCONNECTED;
847 0c471b84 2002-11-30 alex }
848 0c471b84 2002-11-30 alex
849 212d36a3 2002-12-22 alex /* Unknown connections */
850 0c471b84 2002-11-30 alex cnt = Client_UnknownCount( );
851 0c471b84 2002-11-30 alex if( cnt > 0 )
852 0c471b84 2002-11-30 alex {
853 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( Client, RPL_LUSERUNKNOWN_MSG, Client_ID( Client ), cnt )) return DISCONNECTED;
854 0c471b84 2002-11-30 alex }
855 0c471b84 2002-11-30 alex
856 212d36a3 2002-12-22 alex /* Number of created channels */
857 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( Client, RPL_LUSERCHANNELS_MSG, Client_ID( Client ), Channel_Count( ))) return DISCONNECTED;
858 0c471b84 2002-11-30 alex
859 212d36a3 2002-12-22 alex /* Number of local users, services and servers */
860 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( Client, RPL_LUSERME_MSG, Client_ID( Client ), Client_MyUserCount( ), Client_MyServiceCount( ), Client_MyServerCount( ))) return DISCONNECTED;
861 0c471b84 2002-11-30 alex
862 212d36a3 2002-12-22 alex #ifndef STRICT_RFC
863 212d36a3 2002-12-22 alex /* Maximum number of local users */
864 212d36a3 2002-12-22 alex if( ! IRC_WriteStrClient( Client, RPL_LOCALUSERS_MSG, Client_ID( Client ), Client_MyUserCount( ), Client_MyMaxUserCount( ))) return DISCONNECTED;
865 212d36a3 2002-12-22 alex /* Maximum number of users in the network */
866 212d36a3 2002-12-22 alex if( ! IRC_WriteStrClient( Client, RPL_NETUSERS_MSG, Client_ID( Client ), Client_UserCount( ), Client_MaxUserCount( ))) return DISCONNECTED;
867 212d36a3 2002-12-22 alex #endif
868 212d36a3 2002-12-22 alex
869 0c471b84 2002-11-30 alex return CONNECTED;
870 0c471b84 2002-11-30 alex } /* IRC_Send_LUSERS */
871 0c471b84 2002-11-30 alex
872 0c471b84 2002-11-30 alex
873 8adff592 2005-03-19 fw GLOBAL bool
874 0c471b84 2002-11-30 alex IRC_Show_MOTD( CLIENT *Client )
875 0c471b84 2002-11-30 alex {
876 8adff592 2005-03-19 fw bool ok;
877 8adff592 2005-03-19 fw char line[127];
878 0c471b84 2002-11-30 alex FILE *fd;
879 0c471b84 2002-11-30 alex
880 0c471b84 2002-11-30 alex assert( Client != NULL );
881 0c471b84 2002-11-30 alex
882 7281b8dd 2004-05-07 alex if( Conf_MotdPhrase[0] )
883 7281b8dd 2004-05-07 alex {
884 7281b8dd 2004-05-07 alex if( ! IRC_WriteStrClient( Client, RPL_MOTDSTART_MSG, Client_ID( Client ), Client_ID( Client_ThisServer( )))) return DISCONNECTED;
885 7281b8dd 2004-05-07 alex if( ! IRC_WriteStrClient( Client, RPL_MOTD_MSG, Client_ID( Client ), Conf_MotdPhrase )) return DISCONNECTED;
886 7281b8dd 2004-05-07 alex return IRC_WriteStrClient( Client, RPL_ENDOFMOTD_MSG, Client_ID( Client ));
887 7281b8dd 2004-05-07 alex }
888 7281b8dd 2004-05-07 alex
889 0c471b84 2002-11-30 alex fd = fopen( Conf_MotdFile, "r" );
890 0c471b84 2002-11-30 alex if( ! fd )
891 0c471b84 2002-11-30 alex {
892 0c471b84 2002-11-30 alex Log( LOG_WARNING, "Can't read MOTD file \"%s\": %s", Conf_MotdFile, strerror( errno ));
893 0c471b84 2002-11-30 alex return IRC_WriteStrClient( Client, ERR_NOMOTD_MSG, Client_ID( Client ) );
894 0c471b84 2002-11-30 alex }
895 0c471b84 2002-11-30 alex
896 7281b8dd 2004-05-07 alex if( ! IRC_WriteStrClient( Client, RPL_MOTDSTART_MSG, Client_ID( Client ), Client_ID( Client_ThisServer( )))) return DISCONNECTED;
897 8adff592 2005-03-19 fw while( true )
898 0c471b84 2002-11-30 alex {
899 44172a8c 2005-01-24 alex if( ! fgets( line, sizeof( line ), fd )) break;
900 44172a8c 2005-01-24 alex
901 85acb824 2005-02-04 alex ngt_TrimLastChr( line, '\n');
902 44172a8c 2005-01-24 alex
903 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( Client, RPL_MOTD_MSG, Client_ID( Client ), line ))
904 0c471b84 2002-11-30 alex {
905 0c471b84 2002-11-30 alex fclose( fd );
906 8adff592 2005-03-19 fw return false;
907 0c471b84 2002-11-30 alex }
908 0c471b84 2002-11-30 alex }
909 0c471b84 2002-11-30 alex ok = IRC_WriteStrClient( Client, RPL_ENDOFMOTD_MSG, Client_ID( Client ) );
910 0c471b84 2002-11-30 alex
911 0c471b84 2002-11-30 alex fclose( fd );
912 0c471b84 2002-11-30 alex
913 0c471b84 2002-11-30 alex return ok;
914 0c471b84 2002-11-30 alex } /* IRC_Show_MOTD */
915 0c471b84 2002-11-30 alex
916 0c471b84 2002-11-30 alex
917 8adff592 2005-03-19 fw GLOBAL bool
918 0c471b84 2002-11-30 alex IRC_Send_NAMES( CLIENT *Client, CHANNEL *Chan )
919 0c471b84 2002-11-30 alex {
920 8adff592 2005-03-19 fw bool is_visible, is_member;
921 8adff592 2005-03-19 fw char str[LINE_LEN + 1];
922 0c471b84 2002-11-30 alex CL2CHAN *cl2chan;
923 0c471b84 2002-11-30 alex CLIENT *cl;
924 0c471b84 2002-11-30 alex
925 0c471b84 2002-11-30 alex assert( Client != NULL );
926 0c471b84 2002-11-30 alex assert( Chan != NULL );
927 0c471b84 2002-11-30 alex
928 8adff592 2005-03-19 fw if( Channel_IsMemberOf( Chan, Client )) is_member = true;
929 8adff592 2005-03-19 fw else is_member = false;
930 0c471b84 2002-11-30 alex
931 4ef172d6 2005-03-02 alex /* Secret channel? */
932 4ef172d6 2005-03-02 alex if( ! is_member && strchr( Channel_Modes( Chan ), 's' )) return CONNECTED;
933 4ef172d6 2005-03-02 alex
934 0c471b84 2002-11-30 alex /* Alle Mitglieder suchen */
935 b316c380 2002-12-26 alex snprintf( str, sizeof( str ), RPL_NAMREPLY_MSG, Client_ID( Client ), "=", Channel_Name( Chan ));
936 0c471b84 2002-11-30 alex cl2chan = Channel_FirstMember( Chan );
937 0c471b84 2002-11-30 alex while( cl2chan )
938 0c471b84 2002-11-30 alex {
939 0c471b84 2002-11-30 alex cl = Channel_GetClient( cl2chan );
940 0c471b84 2002-11-30 alex
941 8adff592 2005-03-19 fw if( strchr( Client_Modes( cl ), 'i' )) is_visible = false;
942 8adff592 2005-03-19 fw else is_visible = true;
943 0c471b84 2002-11-30 alex
944 0c471b84 2002-11-30 alex if( is_member || is_visible )
945 0c471b84 2002-11-30 alex {
946 0c471b84 2002-11-30 alex /* Nick anhaengen */
947 6626395c 2002-12-26 alex if( str[strlen( str ) - 1] != ':' ) strlcat( str, " ", sizeof( str ));
948 6626395c 2002-12-26 alex if( strchr( Channel_UserModes( Chan, cl ), 'o' )) strlcat( str, "@", sizeof( str ));
949 6626395c 2002-12-26 alex else if( strchr( Channel_UserModes( Chan, cl ), 'v' )) strlcat( str, "+", sizeof( str ));
950 6626395c 2002-12-26 alex strlcat( str, Client_ID( cl ), sizeof( str ));
951 0c471b84 2002-11-30 alex
952 0c471b84 2002-11-30 alex if( strlen( str ) > ( LINE_LEN - CLIENT_NICK_LEN - 4 ))
953 0c471b84 2002-11-30 alex {
954 0c471b84 2002-11-30 alex /* Zeile wird zu lang: senden! */
955 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( Client, "%s", str )) return DISCONNECTED;
956 b316c380 2002-12-26 alex snprintf( str, sizeof( str ), RPL_NAMREPLY_MSG, Client_ID( Client ), "=", Channel_Name( Chan ));
957 0c471b84 2002-11-30 alex }
958 0c471b84 2002-11-30 alex }
959 0c471b84 2002-11-30 alex
960 0c471b84 2002-11-30 alex /* naechstes Mitglied suchen */
961 0c471b84 2002-11-30 alex cl2chan = Channel_NextMember( Chan, cl2chan );
962 0c471b84 2002-11-30 alex }
963 0c471b84 2002-11-30 alex if( str[strlen( str ) - 1] != ':')
964 0c471b84 2002-11-30 alex {
965 0c471b84 2002-11-30 alex /* Es sind noch Daten da, die gesendet werden muessen */
966 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( Client, "%s", str )) return DISCONNECTED;
967 0c471b84 2002-11-30 alex }
968 0c471b84 2002-11-30 alex
969 0c471b84 2002-11-30 alex return CONNECTED;
970 0c471b84 2002-11-30 alex } /* IRC_Send_NAMES */
971 0c471b84 2002-11-30 alex
972 0c471b84 2002-11-30 alex
973 8adff592 2005-03-19 fw GLOBAL bool
974 8adff592 2005-03-19 fw IRC_Send_WHO( CLIENT *Client, CHANNEL *Chan, bool OnlyOps )
975 0c471b84 2002-11-30 alex {
976 8adff592 2005-03-19 fw bool is_visible, is_member;
977 0c471b84 2002-11-30 alex CL2CHAN *cl2chan;
978 8adff592 2005-03-19 fw char flags[8];
979 0c471b84 2002-11-30 alex CLIENT *c;
980 0c471b84 2002-11-30 alex
981 0c471b84 2002-11-30 alex assert( Client != NULL );
982 0c471b84 2002-11-30 alex assert( Chan != NULL );
983 0c471b84 2002-11-30 alex
984 8adff592 2005-03-19 fw if( Channel_IsMemberOf( Chan, Client )) is_member = true;
985 8adff592 2005-03-19 fw else is_member = false;
986 0c471b84 2002-11-30 alex
987 4ef172d6 2005-03-02 alex /* Secret channel? */
988 4ef172d6 2005-03-02 alex if( ! is_member && strchr( Channel_Modes( Chan ), 's' )) return CONNECTED;
989 4ef172d6 2005-03-02 alex
990 0c471b84 2002-11-30 alex /* Alle Mitglieder suchen */
991 0c471b84 2002-11-30 alex cl2chan = Channel_FirstMember( Chan );
992 0c471b84 2002-11-30 alex while( cl2chan )
993 0c471b84 2002-11-30 alex {
994 0c471b84 2002-11-30 alex c = Channel_GetClient( cl2chan );
995 0c471b84 2002-11-30 alex
996 8adff592 2005-03-19 fw if( strchr( Client_Modes( c ), 'i' )) is_visible = false;
997 8adff592 2005-03-19 fw else is_visible = true;
998 0c471b84 2002-11-30 alex
999 0c471b84 2002-11-30 alex if( is_member || is_visible )
1000 0c471b84 2002-11-30 alex {
1001 0c471b84 2002-11-30 alex /* Flags zusammenbasteln */
1002 0c471b84 2002-11-30 alex strcpy( flags, "H" );
1003 6626395c 2002-12-26 alex if( strchr( Client_Modes( c ), 'o' )) strlcat( flags, "*", sizeof( flags ));
1004 6626395c 2002-12-26 alex if( strchr( Channel_UserModes( Chan, c ), 'o' )) strlcat( flags, "@", sizeof( flags ));
1005 6626395c 2002-12-26 alex else if( strchr( Channel_UserModes( Chan, c ), 'v' )) strlcat( flags, "+", sizeof( flags ));
1006 0c471b84 2002-11-30 alex
1007 0c471b84 2002-11-30 alex /* ausgeben */
1008 0c471b84 2002-11-30 alex if(( ! OnlyOps ) || ( strchr( Client_Modes( c ), 'o' )))
1009 0c471b84 2002-11-30 alex {
1010 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( Client, RPL_WHOREPLY_MSG, Client_ID( Client ), Channel_Name( Chan ), Client_User( c ), Client_Hostname( c ), Client_ID( Client_Introducer( c )), Client_ID( c ), flags, Client_Hops( c ), Client_Info( c ))) return DISCONNECTED;
1011 0c471b84 2002-11-30 alex }
1012 0c471b84 2002-11-30 alex }
1013 0c471b84 2002-11-30 alex
1014 0c471b84 2002-11-30 alex /* naechstes Mitglied suchen */
1015 0c471b84 2002-11-30 alex cl2chan = Channel_NextMember( Chan, cl2chan );
1016 0c471b84 2002-11-30 alex }
1017 0c471b84 2002-11-30 alex return CONNECTED;
1018 0c471b84 2002-11-30 alex } /* IRC_Send_WHO */
1019 0c471b84 2002-11-30 alex
1020 0c471b84 2002-11-30 alex
1021 0c471b84 2002-11-30 alex /* -eof- */