2 0c471b84 2002-11-30 alex * ngIRCd -- The Next Generation IRC Daemon
3 0c471b84 2002-11-30 alex * Copyright (c)2001,2002 by Alexander Barton (alex@barton.de)
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.
11 490f28ff 2002-12-12 alex * IRC info commands
15 0c471b84 2002-11-30 alex #include "portab.h"
17 7281b8dd 2004-05-07 alex static char UNUSED id[] = "$Id: irc-info.c,v 1.22 2004/05/07 11:19:21 alex Exp $";
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 0c471b84 2002-11-30 alex #include <string.h>
24 57c7e236 2004-01-17 alex #include <strings.h>
26 0c471b84 2002-11-30 alex #include "ngircd.h"
27 260b8e5f 2003-06-06 alex #include "cvs-version.h"
28 b8d7dcec 2002-12-30 alex #include "conn-func.h"
29 437f2c33 2002-12-30 alex #include "conn-zip.h"
30 0c471b84 2002-11-30 alex #include "client.h"
31 0c471b84 2002-11-30 alex #include "channel.h"
32 0c471b84 2002-11-30 alex #include "resolve.h"
33 0c471b84 2002-11-30 alex #include "conf.h"
34 0c471b84 2002-11-30 alex #include "defines.h"
35 0c471b84 2002-11-30 alex #include "log.h"
36 0c471b84 2002-11-30 alex #include "messages.h"
37 0c471b84 2002-11-30 alex #include "tool.h"
38 0c471b84 2002-11-30 alex #include "parse.h"
39 0c471b84 2002-11-30 alex #include "irc-write.h"
41 0c471b84 2002-11-30 alex #include "exp.h"
42 0c471b84 2002-11-30 alex #include "irc-info.h"
45 0c471b84 2002-11-30 alex GLOBAL BOOLEAN
46 0c471b84 2002-11-30 alex IRC_ADMIN(CLIENT *Client, REQUEST *Req )
48 0c471b84 2002-11-30 alex CLIENT *target, *prefix;
50 0c471b84 2002-11-30 alex assert( Client != NULL );
51 0c471b84 2002-11-30 alex assert( Req != NULL );
53 0c471b84 2002-11-30 alex /* Falsche Anzahl Parameter? */
54 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 /* Ziel suchen */
57 0c471b84 2002-11-30 alex if( Req->argc == 1 ) target = Client_Search( Req->argv[0] );
58 0c471b84 2002-11-30 alex else target = Client_ThisServer( );
60 0c471b84 2002-11-30 alex /* Prefix ermitteln */
61 0c471b84 2002-11-30 alex if( Client_Type( Client ) == CLIENT_SERVER ) prefix = Client_Search( Req->prefix );
62 0c471b84 2002-11-30 alex else prefix = Client;
63 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 /* An anderen Server weiterleiten? */
66 0c471b84 2002-11-30 alex if( target != Client_ThisServer( ))
68 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 /* forwarden */
71 0c471b84 2002-11-30 alex IRC_WriteStrClientPrefix( target, prefix, "ADMIN %s", Req->argv[0] );
72 0c471b84 2002-11-30 alex return CONNECTED;
75 0c471b84 2002-11-30 alex /* mit Versionsinfo antworten */
76 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( Client, RPL_ADMINME_MSG, Client_ID( prefix ), Conf_ServerName )) return DISCONNECTED;
77 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( Client, RPL_ADMINLOC1_MSG, Client_ID( prefix ), Conf_ServerAdmin1 )) return DISCONNECTED;
78 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( Client, RPL_ADMINLOC2_MSG, Client_ID( prefix ), Conf_ServerAdmin2 )) return DISCONNECTED;
79 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( Client, RPL_ADMINEMAIL_MSG, Client_ID( prefix ), Conf_ServerAdminMail )) return DISCONNECTED;
81 7b6e2662 2003-11-05 alex IRC_SetPenalty( Client, 1 );
82 0c471b84 2002-11-30 alex return CONNECTED;
83 0c471b84 2002-11-30 alex } /* IRC_ADMIN */
86 0c471b84 2002-11-30 alex GLOBAL BOOLEAN
87 0c471b84 2002-11-30 alex IRC_ISON( CLIENT *Client, REQUEST *Req )
89 0c471b84 2002-11-30 alex CHAR rpl[COMMAND_LEN];
94 0c471b84 2002-11-30 alex assert( Client != NULL );
95 0c471b84 2002-11-30 alex assert( Req != NULL );
97 0c471b84 2002-11-30 alex /* Falsche Anzahl Parameter? */
98 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 strcpy( rpl, RPL_ISON_MSG );
101 0c471b84 2002-11-30 alex for( i = 0; i < Req->argc; i++ )
103 0c471b84 2002-11-30 alex ptr = strtok( Req->argv[i], " " );
104 0c471b84 2002-11-30 alex while( ptr )
106 0c471b84 2002-11-30 alex ngt_TrimStr( ptr );
107 0c471b84 2002-11-30 alex c = Client_Search( ptr );
108 0c471b84 2002-11-30 alex if( c && ( Client_Type( c ) == CLIENT_USER ))
110 0c471b84 2002-11-30 alex /* Dieser Nick ist "online" */
111 6626395c 2002-12-26 alex strlcat( rpl, ptr, sizeof( rpl ));
112 6626395c 2002-12-26 alex strlcat( rpl, " ", sizeof( rpl ));
114 0c471b84 2002-11-30 alex ptr = strtok( NULL, " " );
117 0c471b84 2002-11-30 alex if( rpl[strlen( rpl ) - 1] == ' ' ) rpl[strlen( rpl ) - 1] = '\0';
119 f0349f52 2002-12-02 alex return IRC_WriteStrClient( Client, rpl, Client_ID( Client ) );
120 0c471b84 2002-11-30 alex } /* IRC_ISON */
123 0c471b84 2002-11-30 alex GLOBAL BOOLEAN
124 0c471b84 2002-11-30 alex IRC_LINKS( CLIENT *Client, REQUEST *Req )
126 0c471b84 2002-11-30 alex CLIENT *target, *from, *c;
127 0c471b84 2002-11-30 alex CHAR *mask;
129 0c471b84 2002-11-30 alex assert( Client != NULL );
130 0c471b84 2002-11-30 alex assert( Req != NULL );
132 0c471b84 2002-11-30 alex /* Falsche Anzahl Parameter? */
133 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 /* Server-Mask ermitteln */
136 0c471b84 2002-11-30 alex if( Req->argc > 0 ) mask = Req->argv[Req->argc - 1];
137 0c471b84 2002-11-30 alex else mask = "*";
139 0c471b84 2002-11-30 alex /* Absender ermitteln */
140 0c471b84 2002-11-30 alex if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
141 0c471b84 2002-11-30 alex else from = Client;
142 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 /* An anderen Server forwarden? */
145 0c471b84 2002-11-30 alex if( Req->argc == 2 )
147 0c471b84 2002-11-30 alex target = Client_Search( Req->argv[0] );
148 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] );
149 0c471b84 2002-11-30 alex else if( target != Client_ThisServer( )) return IRC_WriteStrClientPrefix( target, from, "LINKS %s %s", Req->argv[0], Req->argv[1] );
152 0c471b84 2002-11-30 alex /* Wer ist der Absender? */
153 0c471b84 2002-11-30 alex if( Client_Type( Client ) == CLIENT_SERVER ) target = Client_Search( Req->prefix );
154 0c471b84 2002-11-30 alex else target = Client;
155 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 c = Client_First( );
160 0c471b84 2002-11-30 alex if( Client_Type( c ) == CLIENT_SERVER )
162 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 c = Client_Next( c );
167 7b6e2662 2003-11-05 alex IRC_SetPenalty( target, 1 );
168 0c471b84 2002-11-30 alex return IRC_WriteStrClient( target, RPL_ENDOFLINKS_MSG, Client_ID( target ), mask );
169 0c471b84 2002-11-30 alex } /* IRC_LINKS */
172 0c471b84 2002-11-30 alex GLOBAL BOOLEAN
173 0c471b84 2002-11-30 alex IRC_LUSERS( CLIENT *Client, REQUEST *Req )
175 0c471b84 2002-11-30 alex CLIENT *target, *from;
177 0c471b84 2002-11-30 alex assert( Client != NULL );
178 0c471b84 2002-11-30 alex assert( Req != NULL );
180 0c471b84 2002-11-30 alex /* Falsche Anzahl Parameter? */
181 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 /* Absender ermitteln */
184 0c471b84 2002-11-30 alex if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
185 0c471b84 2002-11-30 alex else from = Client;
186 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 /* An anderen Server forwarden? */
189 0c471b84 2002-11-30 alex if( Req->argc == 2 )
191 0c471b84 2002-11-30 alex target = Client_Search( Req->argv[1] );
192 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] );
193 0c471b84 2002-11-30 alex else if( target != Client_ThisServer( )) return IRC_WriteStrClientPrefix( target, from, "LUSERS %s %s", Req->argv[0], Req->argv[1] );
196 0c471b84 2002-11-30 alex /* Wer ist der Absender? */
197 0c471b84 2002-11-30 alex if( Client_Type( Client ) == CLIENT_SERVER ) target = Client_Search( Req->prefix );
198 0c471b84 2002-11-30 alex else target = Client;
199 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 IRC_Send_LUSERS( target );
203 7b6e2662 2003-11-05 alex IRC_SetPenalty( target, 1 );
204 0c471b84 2002-11-30 alex return CONNECTED;
205 0c471b84 2002-11-30 alex } /* IRC_LUSERS */
208 0c471b84 2002-11-30 alex GLOBAL BOOLEAN
209 0c471b84 2002-11-30 alex IRC_MOTD( CLIENT *Client, REQUEST *Req )
211 0c471b84 2002-11-30 alex CLIENT *from, *target;
213 0c471b84 2002-11-30 alex assert( Client != NULL );
214 0c471b84 2002-11-30 alex assert( Req != NULL );
216 0c471b84 2002-11-30 alex /* Falsche Anzahl Parameter? */
217 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 /* From aus Prefix ermitteln */
220 0c471b84 2002-11-30 alex if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
221 0c471b84 2002-11-30 alex else from = Client;
222 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 if( Req->argc == 1 )
226 0c471b84 2002-11-30 alex /* an anderen Server forwarden */
227 0c471b84 2002-11-30 alex target = Client_Search( Req->argv[0] );
228 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 if( target != Client_ThisServer( ))
232 0c471b84 2002-11-30 alex /* Ok, anderer Server ist das Ziel: forwarden */
233 0c471b84 2002-11-30 alex return IRC_WriteStrClientPrefix( target, from, "MOTD %s", Req->argv[0] );
237 7b6e2662 2003-11-05 alex IRC_SetPenalty( from, 3 );
238 0c471b84 2002-11-30 alex return IRC_Show_MOTD( from );
239 0c471b84 2002-11-30 alex } /* IRC_MOTD */
242 0c471b84 2002-11-30 alex GLOBAL BOOLEAN
243 0c471b84 2002-11-30 alex IRC_NAMES( CLIENT *Client, REQUEST *Req )
245 0c471b84 2002-11-30 alex CHAR rpl[COMMAND_LEN], *ptr;
246 0c471b84 2002-11-30 alex CLIENT *target, *from, *c;
247 0c471b84 2002-11-30 alex CHANNEL *chan;
249 0c471b84 2002-11-30 alex assert( Client != NULL );
250 0c471b84 2002-11-30 alex assert( Req != NULL );
252 0c471b84 2002-11-30 alex /* Falsche Anzahl Parameter? */
253 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 /* From aus Prefix ermitteln */
256 0c471b84 2002-11-30 alex if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
257 0c471b84 2002-11-30 alex else from = Client;
258 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 if( Req->argc == 2 )
262 0c471b84 2002-11-30 alex /* an anderen Server forwarden */
263 0c471b84 2002-11-30 alex target = Client_Search( Req->argv[1] );
264 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 if( target != Client_ThisServer( ))
268 0c471b84 2002-11-30 alex /* Ok, anderer Server ist das Ziel: forwarden */
269 0c471b84 2002-11-30 alex return IRC_WriteStrClientPrefix( target, from, "NAMES %s :%s", Req->argv[0], Req->argv[1] );
273 0c471b84 2002-11-30 alex if( Req->argc > 0 )
275 0c471b84 2002-11-30 alex /* bestimmte Channels durchgehen */
276 0c471b84 2002-11-30 alex ptr = strtok( Req->argv[0], "," );
277 0c471b84 2002-11-30 alex while( ptr )
279 0c471b84 2002-11-30 alex chan = Channel_Search( ptr );
282 0c471b84 2002-11-30 alex /* Namen ausgeben */
283 0c471b84 2002-11-30 alex if( ! IRC_Send_NAMES( from, chan )) return DISCONNECTED;
285 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( from, RPL_ENDOFNAMES_MSG, Client_ID( from ), ptr )) return DISCONNECTED;
287 0c471b84 2002-11-30 alex /* naechsten Namen ermitteln */
288 0c471b84 2002-11-30 alex ptr = strtok( NULL, "," );
290 0c471b84 2002-11-30 alex return CONNECTED;
293 0c471b84 2002-11-30 alex /* alle Channels durchgehen */
294 0c471b84 2002-11-30 alex chan = Channel_First( );
295 0c471b84 2002-11-30 alex while( chan )
297 0c471b84 2002-11-30 alex /* Namen ausgeben */
298 0c471b84 2002-11-30 alex if( ! IRC_Send_NAMES( from, chan )) return DISCONNECTED;
300 0c471b84 2002-11-30 alex /* naechster Channel */
301 0c471b84 2002-11-30 alex chan = Channel_Next( chan );
304 0c471b84 2002-11-30 alex /* Nun noch alle Clients ausgeben, die in keinem Channel sind */
305 0c471b84 2002-11-30 alex c = Client_First( );
306 b316c380 2002-12-26 alex snprintf( rpl, sizeof( rpl ), RPL_NAMREPLY_MSG, Client_ID( from ), "*", "*" );
309 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 /* Okay, das ist ein User: anhaengen */
312 6626395c 2002-12-26 alex if( rpl[strlen( rpl ) - 1] != ':' ) strlcat( rpl, " ", sizeof( rpl ));
313 6626395c 2002-12-26 alex strlcat( rpl, Client_ID( c ), sizeof( rpl ));
315 0c471b84 2002-11-30 alex if( strlen( rpl ) > ( LINE_LEN - CLIENT_NICK_LEN - 4 ))
317 0c471b84 2002-11-30 alex /* Zeile wird zu lang: senden! */
318 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( from, "%s", rpl )) return DISCONNECTED;
319 b316c380 2002-12-26 alex snprintf( rpl, sizeof( rpl ), RPL_NAMREPLY_MSG, Client_ID( from ), "*", "*" );
323 0c471b84 2002-11-30 alex /* naechster Client */
324 0c471b84 2002-11-30 alex c = Client_Next( c );
326 0c471b84 2002-11-30 alex if( rpl[strlen( rpl ) - 1] != ':')
328 0c471b84 2002-11-30 alex /* es wurden User gefunden */
329 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( from, "%s", rpl )) return DISCONNECTED;
332 7b6e2662 2003-11-05 alex IRC_SetPenalty( from, 1 );
333 0c471b84 2002-11-30 alex return IRC_WriteStrClient( from, RPL_ENDOFNAMES_MSG, Client_ID( from ), "*" );
334 0c471b84 2002-11-30 alex } /* IRC_NAMES */
337 0c471b84 2002-11-30 alex GLOBAL BOOLEAN
338 0c471b84 2002-11-30 alex IRC_STATS( CLIENT *Client, REQUEST *Req )
340 bad7ac62 2002-12-02 alex CLIENT *from, *target, *cl;
341 bad7ac62 2002-12-02 alex CONN_ID con;
342 0c471b84 2002-11-30 alex CHAR query;
343 210282d0 2002-12-18 alex COMMAND *cmd;
345 0c471b84 2002-11-30 alex assert( Client != NULL );
346 0c471b84 2002-11-30 alex assert( Req != NULL );
348 0c471b84 2002-11-30 alex /* Falsche Anzahl Parameter? */
349 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 /* From aus Prefix ermitteln */
352 0c471b84 2002-11-30 alex if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
353 0c471b84 2002-11-30 alex else from = Client;
354 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 if( Req->argc == 2 )
358 0c471b84 2002-11-30 alex /* an anderen Server forwarden */
359 e50d568f 2002-11-30 alex target = Client_Search( Req->argv[1] );
360 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 if( target != Client_ThisServer( ))
364 0c471b84 2002-11-30 alex /* Ok, anderer Server ist das Ziel: forwarden */
365 7924fafb 2002-12-16 alex return IRC_WriteStrClientPrefix( target, from, "STATS %s %s", Req->argv[0], Req->argv[1] );
369 0c471b84 2002-11-30 alex if( Req->argc > 0 ) query = Req->argv[0][0] ? Req->argv[0][0] : '*';
370 0c471b84 2002-11-30 alex else query = '*';
372 bad7ac62 2002-12-02 alex switch ( query )
374 bad7ac62 2002-12-02 alex case 'l': /* Links */
376 bad7ac62 2002-12-02 alex con = Conn_First( );
377 bad7ac62 2002-12-02 alex while( con != NONE )
379 bad7ac62 2002-12-02 alex cl = Client_GetFromConn( con );
380 98677b43 2002-12-18 alex if( cl && (( Client_Type( cl ) == CLIENT_SERVER ) || ( cl == Client )))
382 98677b43 2002-12-18 alex /* Server link or our own connection */
383 c40592d2 2003-12-26 alex #ifdef ZLIB
384 bad7ac62 2002-12-02 alex if( Conn_Options( con ) & CONN_ZIP )
386 437f2c33 2002-12-30 alex 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;
391 bad7ac62 2002-12-02 alex 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;
394 bad7ac62 2002-12-02 alex con = Conn_Next( con );
397 bad7ac62 2002-12-02 alex case 'm': /* IRC-Befehle */
399 210282d0 2002-12-18 alex cmd = Parse_GetCommandStruct( );
400 210282d0 2002-12-18 alex while( cmd->name )
402 210282d0 2002-12-18 alex if( cmd->lcount > 0 || cmd->rcount > 0 )
404 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;
411 7b6e2662 2003-11-05 alex IRC_SetPenalty( from, 2 );
412 0c471b84 2002-11-30 alex return IRC_WriteStrClient( from, RPL_ENDOFSTATS_MSG, Client_ID( from ), query );
413 0c471b84 2002-11-30 alex } /* IRC_STATS */
416 0c471b84 2002-11-30 alex GLOBAL BOOLEAN
417 0c471b84 2002-11-30 alex IRC_TIME( CLIENT *Client, REQUEST *Req )
419 0c471b84 2002-11-30 alex CLIENT *from, *target;
420 0c471b84 2002-11-30 alex CHAR t_str[64];
423 0c471b84 2002-11-30 alex assert( Client != NULL );
424 0c471b84 2002-11-30 alex assert( Req != NULL );
426 0c471b84 2002-11-30 alex /* Falsche Anzahl Parameter? */
427 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 /* From aus Prefix ermitteln */
430 0c471b84 2002-11-30 alex if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
431 0c471b84 2002-11-30 alex else from = Client;
432 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 if( Req->argc == 1 )
436 0c471b84 2002-11-30 alex /* an anderen Server forwarden */
437 0c471b84 2002-11-30 alex target = Client_Search( Req->argv[0] );
438 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 if( target != Client_ThisServer( ))
442 0c471b84 2002-11-30 alex /* Ok, anderer Server ist das Ziel: forwarden */
443 0c471b84 2002-11-30 alex return IRC_WriteStrClientPrefix( target, from, "TIME %s", Req->argv[0] );
447 0c471b84 2002-11-30 alex t = time( NULL );
448 489d8c5c 2003-04-21 alex (VOID)strftime( t_str, 60, "%A %B %d %Y -- %H:%M %Z", localtime( &t ));
449 0c471b84 2002-11-30 alex return IRC_WriteStrClient( from, RPL_TIME_MSG, Client_ID( from ), Client_ID( Client_ThisServer( )), t_str );
450 0c471b84 2002-11-30 alex } /* IRC_TIME */
453 0c471b84 2002-11-30 alex GLOBAL BOOLEAN
454 0c471b84 2002-11-30 alex IRC_USERHOST( CLIENT *Client, REQUEST *Req )
456 0c471b84 2002-11-30 alex CHAR rpl[COMMAND_LEN];
458 0c471b84 2002-11-30 alex INT max, i;
460 0c471b84 2002-11-30 alex assert( Client != NULL );
461 0c471b84 2002-11-30 alex assert( Req != NULL );
463 0c471b84 2002-11-30 alex /* Falsche Anzahl Parameter? */
464 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 if( Req->argc > 5 ) max = 5;
467 0c471b84 2002-11-30 alex else max = Req->argc;
469 0c471b84 2002-11-30 alex strcpy( rpl, RPL_USERHOST_MSG );
470 0c471b84 2002-11-30 alex for( i = 0; i < max; i++ )
472 0c471b84 2002-11-30 alex c = Client_Search( Req->argv[i] );
473 0c471b84 2002-11-30 alex if( c && ( Client_Type( c ) == CLIENT_USER ))
475 0c471b84 2002-11-30 alex /* Dieser Nick ist "online" */
476 6626395c 2002-12-26 alex strlcat( rpl, Client_ID( c ), sizeof( rpl ));
477 6626395c 2002-12-26 alex if( Client_HasMode( c, 'o' )) strlcat( rpl, "*", sizeof( rpl ));
478 6626395c 2002-12-26 alex strlcat( rpl, "=", sizeof( rpl ));
479 6626395c 2002-12-26 alex if( Client_HasMode( c, 'a' )) strlcat( rpl, "-", sizeof( rpl ));
480 6626395c 2002-12-26 alex else strlcat( rpl, "+", sizeof( rpl ));
481 6626395c 2002-12-26 alex strlcat( rpl, Client_User( c ), sizeof( rpl ));
482 6626395c 2002-12-26 alex strlcat( rpl, "@", sizeof( rpl ));
483 6626395c 2002-12-26 alex strlcat( rpl, Client_Hostname( c ), sizeof( rpl ));
484 6626395c 2002-12-26 alex strlcat( rpl, " ", sizeof( rpl ));
487 0c471b84 2002-11-30 alex if( rpl[strlen( rpl ) - 1] == ' ' ) rpl[strlen( rpl ) - 1] = '\0';
489 f0349f52 2002-12-02 alex return IRC_WriteStrClient( Client, rpl, Client_ID( Client ) );
490 0c471b84 2002-11-30 alex } /* IRC_USERHOST */
493 0c471b84 2002-11-30 alex GLOBAL BOOLEAN
494 0c471b84 2002-11-30 alex IRC_VERSION( CLIENT *Client, REQUEST *Req )
496 0c471b84 2002-11-30 alex CLIENT *target, *prefix;
497 260b8e5f 2003-06-06 alex #ifdef CVSDATE
498 05e2c0f0 2003-12-04 alex CHAR ver[12], vertxt[30];
501 0c471b84 2002-11-30 alex assert( Client != NULL );
502 0c471b84 2002-11-30 alex assert( Req != NULL );
504 0c471b84 2002-11-30 alex /* Falsche Anzahl Parameter? */
505 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 /* Ziel suchen */
508 0c471b84 2002-11-30 alex if( Req->argc == 1 ) target = Client_Search( Req->argv[0] );
509 0c471b84 2002-11-30 alex else target = Client_ThisServer( );
511 0c471b84 2002-11-30 alex /* Prefix ermitteln */
512 0c471b84 2002-11-30 alex if( Client_Type( Client ) == CLIENT_SERVER ) prefix = Client_Search( Req->prefix );
513 0c471b84 2002-11-30 alex else prefix = Client;
514 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 /* An anderen Server weiterleiten? */
517 0c471b84 2002-11-30 alex if( target != Client_ThisServer( ))
519 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 /* forwarden */
522 0c471b84 2002-11-30 alex IRC_WriteStrClientPrefix( target, prefix, "VERSION %s", Req->argv[0] );
523 0c471b84 2002-11-30 alex return CONNECTED;
526 0c471b84 2002-11-30 alex /* mit Versionsinfo antworten */
527 7b6e2662 2003-11-05 alex IRC_SetPenalty( Client, 1 );
528 260b8e5f 2003-06-06 alex #ifdef CVSDATE
529 260b8e5f 2003-06-06 alex strlcpy( ver, CVSDATE, sizeof( ver ));
530 260b8e5f 2003-06-06 alex strncpy( ver + 4, ver + 5, 2 );
531 260b8e5f 2003-06-06 alex strncpy( ver + 6, ver + 8, 3 );
532 05e2c0f0 2003-12-04 alex snprintf( vertxt, sizeof( vertxt ), "%s(%s)", PACKAGE_VERSION, ver );
533 05e2c0f0 2003-12-04 alex return IRC_WriteStrClient( Client, RPL_VERSION_MSG, Client_ID( prefix ), PACKAGE_NAME, vertxt, NGIRCd_DebugLevel, Conf_ServerName, NGIRCd_VersionAddition( ));
535 62796722 2003-03-31 alex return IRC_WriteStrClient( Client, RPL_VERSION_MSG, Client_ID( prefix ), PACKAGE_NAME, PACKAGE_VERSION, NGIRCd_DebugLevel, Conf_ServerName, NGIRCd_VersionAddition( ));
537 0c471b84 2002-11-30 alex } /* IRC_VERSION */
540 0c471b84 2002-11-30 alex GLOBAL BOOLEAN
541 0c471b84 2002-11-30 alex IRC_WHO( CLIENT *Client, REQUEST *Req )
543 0c471b84 2002-11-30 alex BOOLEAN ok, only_ops;
544 0c471b84 2002-11-30 alex CHAR flags[8], *ptr;
545 0c471b84 2002-11-30 alex CL2CHAN *cl2chan;
546 0c471b84 2002-11-30 alex CHANNEL *chan;
549 0c471b84 2002-11-30 alex assert( Client != NULL );
550 0c471b84 2002-11-30 alex assert( Req != NULL );
552 0c471b84 2002-11-30 alex /* Falsche Anzahl Parameter? */
553 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 only_ops = FALSE;
556 0c471b84 2002-11-30 alex chan = NULL;
558 0c471b84 2002-11-30 alex if( Req->argc == 2 )
560 0c471b84 2002-11-30 alex /* Nur OPs anzeigen? */
561 0c471b84 2002-11-30 alex if( strcmp( Req->argv[1], "o" ) == 0 ) only_ops = TRUE;
562 0c471b84 2002-11-30 alex #ifdef STRICT_RFC
563 0c471b84 2002-11-30 alex else return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
567 0c471b84 2002-11-30 alex if( Req->argc >= 1 )
569 0c471b84 2002-11-30 alex /* wurde ein Channel oder Nick-Mask angegeben? */
570 0c471b84 2002-11-30 alex chan = Channel_Search( Req->argv[0] );
575 0c471b84 2002-11-30 alex /* User eines Channels ausgeben */
576 0c471b84 2002-11-30 alex if( ! IRC_Send_WHO( Client, chan, only_ops )) return DISCONNECTED;
579 0c471b84 2002-11-30 alex c = Client_First( );
582 0c471b84 2002-11-30 alex if(( Client_Type( c ) == CLIENT_USER ) && ( ! strchr( Client_Modes( c ), 'i' )))
584 0c471b84 2002-11-30 alex ok = FALSE;
585 0c471b84 2002-11-30 alex if( Req->argc == 0 ) ok = TRUE;
588 0c471b84 2002-11-30 alex if( strcasecmp( Req->argv[0], Client_ID( c )) == 0 ) ok = TRUE;
589 0c471b84 2002-11-30 alex else if( strcmp( Req->argv[0], "0" ) == 0 ) ok = TRUE;
592 0c471b84 2002-11-30 alex if( ok && (( ! only_ops ) || ( strchr( Client_Modes( c ), 'o' ))))
594 0c471b84 2002-11-30 alex /* Flags zusammenbasteln */
595 0c471b84 2002-11-30 alex strcpy( flags, "H" );
596 6626395c 2002-12-26 alex if( strchr( Client_Modes( c ), 'o' )) strlcat( flags, "*", sizeof( flags ));
598 0c471b84 2002-11-30 alex /* ausgeben */
599 0c471b84 2002-11-30 alex cl2chan = Channel_FirstChannelOf( c );
600 0c471b84 2002-11-30 alex if( cl2chan ) ptr = Channel_Name( Channel_GetChannel( cl2chan ));
601 0c471b84 2002-11-30 alex else ptr = "*";
602 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;
606 0c471b84 2002-11-30 alex /* naechster Client */
607 0c471b84 2002-11-30 alex c = Client_Next( c );
610 0c471b84 2002-11-30 alex if( chan ) return IRC_WriteStrClient( Client, RPL_ENDOFWHO_MSG, Client_ID( Client ), Channel_Name( chan ));
611 0c471b84 2002-11-30 alex else if( Req->argc == 0 ) return IRC_WriteStrClient( Client, RPL_ENDOFWHO_MSG, Client_ID( Client ), "*" );
612 0c471b84 2002-11-30 alex else return IRC_WriteStrClient( Client, RPL_ENDOFWHO_MSG, Client_ID( Client ), Req->argv[0] );
613 0c471b84 2002-11-30 alex } /* IRC_WHO */
616 0c471b84 2002-11-30 alex GLOBAL BOOLEAN
617 0c471b84 2002-11-30 alex IRC_WHOIS( CLIENT *Client, REQUEST *Req )
619 0c471b84 2002-11-30 alex CLIENT *from, *target, *c;
620 e17976a1 2003-01-01 alex CHAR str[LINE_LEN + 1];
621 0c471b84 2002-11-30 alex CL2CHAN *cl2chan;
622 0c471b84 2002-11-30 alex CHANNEL *chan;
624 0c471b84 2002-11-30 alex assert( Client != NULL );
625 0c471b84 2002-11-30 alex assert( Req != NULL );
627 e17976a1 2003-01-01 alex /* Bad number of parameters? */
628 0c471b84 2002-11-30 alex if(( Req->argc < 1 ) || ( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
630 e17976a1 2003-01-01 alex /* Search client */
631 0c471b84 2002-11-30 alex c = Client_Search( Req->argv[Req->argc - 1] );
632 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] );
634 e17976a1 2003-01-01 alex /* Search sender of the WHOIS */
635 0c471b84 2002-11-30 alex if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
636 0c471b84 2002-11-30 alex else from = Client;
637 0c471b84 2002-11-30 alex if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
639 e17976a1 2003-01-01 alex /* Forward to other server? */
640 0c471b84 2002-11-30 alex if( Req->argc > 1 )
642 e17976a1 2003-01-01 alex /* Search target server (can be specified as nick of that server!) */
643 e17976a1 2003-01-01 alex target = Client_Search( Req->argv[0] );
644 e17976a1 2003-01-01 alex if( ! target ) return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[0] );
646 0c471b84 2002-11-30 alex else target = Client_ThisServer( );
648 0c471b84 2002-11-30 alex assert( target != NULL );
650 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] );
652 e17976a1 2003-01-01 alex /* Nick, user and name */
653 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;
655 0c471b84 2002-11-30 alex /* Server */
656 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;
658 0c471b84 2002-11-30 alex /* Channels */
659 b316c380 2002-12-26 alex snprintf( str, sizeof( str ), RPL_WHOISCHANNELS_MSG, Client_ID( from ), Client_ID( c ));
660 0c471b84 2002-11-30 alex cl2chan = Channel_FirstChannelOf( c );
661 0c471b84 2002-11-30 alex while( cl2chan )
663 0c471b84 2002-11-30 alex chan = Channel_GetChannel( cl2chan );
664 0c471b84 2002-11-30 alex assert( chan != NULL );
666 e17976a1 2003-01-01 alex /* Concatenate channel names */
667 6626395c 2002-12-26 alex if( str[strlen( str ) - 1] != ':' ) strlcat( str, " ", sizeof( str ));
668 6626395c 2002-12-26 alex if( strchr( Channel_UserModes( chan, c ), 'o' )) strlcat( str, "@", sizeof( str ));
669 6626395c 2002-12-26 alex else if( strchr( Channel_UserModes( chan, c ), 'v' )) strlcat( str, "+", sizeof( str ));
670 6626395c 2002-12-26 alex strlcat( str, Channel_Name( chan ), sizeof( str ));
672 0c471b84 2002-11-30 alex if( strlen( str ) > ( LINE_LEN - CHANNEL_NAME_LEN - 4 ))
674 e17976a1 2003-01-01 alex /* Line becomes too long: send it! */
675 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( Client, "%s", str )) return DISCONNECTED;
676 b316c380 2002-12-26 alex snprintf( str, sizeof( str ), RPL_WHOISCHANNELS_MSG, Client_ID( from ), Client_ID( c ));
680 0c471b84 2002-11-30 alex cl2chan = Channel_NextChannelOf( c, cl2chan );
682 0c471b84 2002-11-30 alex if( str[strlen( str ) - 1] != ':')
684 e17976a1 2003-01-01 alex /* There is data left to send: */
685 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( Client, "%s", str )) return DISCONNECTED;
688 0c471b84 2002-11-30 alex /* IRC-Operator? */
689 0c471b84 2002-11-30 alex if( Client_HasMode( c, 'o' ))
691 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( from, RPL_WHOISOPERATOR_MSG, Client_ID( from ), Client_ID( c ))) return DISCONNECTED;
694 e17976a1 2003-01-01 alex /* Idle (only local clients) */
695 0c471b84 2002-11-30 alex if( Client_Conn( c ) > NONE )
697 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;
700 0c471b84 2002-11-30 alex /* Away? */
701 0c471b84 2002-11-30 alex if( Client_HasMode( c, 'a' ))
703 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( from, RPL_AWAY_MSG, Client_ID( from ), Client_ID( c ), Client_Away( c ))) return DISCONNECTED;
706 0c471b84 2002-11-30 alex /* End of Whois */
707 0c471b84 2002-11-30 alex return IRC_WriteStrClient( from, RPL_ENDOFWHOIS_MSG, Client_ID( from ), Client_ID( c ));
708 0c471b84 2002-11-30 alex } /* IRC_WHOIS */
711 0c471b84 2002-11-30 alex GLOBAL BOOLEAN
712 0c471b84 2002-11-30 alex IRC_WHOWAS( CLIENT *Client, REQUEST *Req )
714 0c471b84 2002-11-30 alex assert( Client != NULL );
715 0c471b84 2002-11-30 alex assert( Req != NULL );
717 0c471b84 2002-11-30 alex /* Falsche Anzahl Parameter? */
718 0c471b84 2002-11-30 alex if(( Req->argc < 1 ) || ( Req->argc > 3 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
722 0c471b84 2002-11-30 alex return CONNECTED;
723 0c471b84 2002-11-30 alex } /* IRC_WHOWAS */
726 0c471b84 2002-11-30 alex GLOBAL BOOLEAN
727 0c471b84 2002-11-30 alex IRC_Send_LUSERS( CLIENT *Client )
731 0c471b84 2002-11-30 alex assert( Client != NULL );
733 212d36a3 2002-12-22 alex /* Users, services and serevers in the network */
734 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( Client, RPL_LUSERCLIENT_MSG, Client_ID( Client ), Client_UserCount( ), Client_ServiceCount( ), Client_ServerCount( ))) return DISCONNECTED;
736 212d36a3 2002-12-22 alex /* Number of IRC operators */
737 0c471b84 2002-11-30 alex cnt = Client_OperCount( );
738 0c471b84 2002-11-30 alex if( cnt > 0 )
740 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( Client, RPL_LUSEROP_MSG, Client_ID( Client ), cnt )) return DISCONNECTED;
743 212d36a3 2002-12-22 alex /* Unknown connections */
744 0c471b84 2002-11-30 alex cnt = Client_UnknownCount( );
745 0c471b84 2002-11-30 alex if( cnt > 0 )
747 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( Client, RPL_LUSERUNKNOWN_MSG, Client_ID( Client ), cnt )) return DISCONNECTED;
750 212d36a3 2002-12-22 alex /* Number of created channels */
751 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( Client, RPL_LUSERCHANNELS_MSG, Client_ID( Client ), Channel_Count( ))) return DISCONNECTED;
753 212d36a3 2002-12-22 alex /* Number of local users, services and servers */
754 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( Client, RPL_LUSERME_MSG, Client_ID( Client ), Client_MyUserCount( ), Client_MyServiceCount( ), Client_MyServerCount( ))) return DISCONNECTED;
756 212d36a3 2002-12-22 alex #ifndef STRICT_RFC
757 212d36a3 2002-12-22 alex /* Maximum number of local users */
758 212d36a3 2002-12-22 alex if( ! IRC_WriteStrClient( Client, RPL_LOCALUSERS_MSG, Client_ID( Client ), Client_MyUserCount( ), Client_MyMaxUserCount( ))) return DISCONNECTED;
759 212d36a3 2002-12-22 alex /* Maximum number of users in the network */
760 212d36a3 2002-12-22 alex if( ! IRC_WriteStrClient( Client, RPL_NETUSERS_MSG, Client_ID( Client ), Client_UserCount( ), Client_MaxUserCount( ))) return DISCONNECTED;
763 0c471b84 2002-11-30 alex return CONNECTED;
764 0c471b84 2002-11-30 alex } /* IRC_Send_LUSERS */
767 0c471b84 2002-11-30 alex GLOBAL BOOLEAN
768 0c471b84 2002-11-30 alex IRC_Show_MOTD( CLIENT *Client )
770 0c471b84 2002-11-30 alex BOOLEAN ok;
771 0c471b84 2002-11-30 alex CHAR line[127];
774 0c471b84 2002-11-30 alex assert( Client != NULL );
776 7281b8dd 2004-05-07 alex if( Conf_MotdPhrase[0] )
778 7281b8dd 2004-05-07 alex if( ! IRC_WriteStrClient( Client, RPL_MOTDSTART_MSG, Client_ID( Client ), Client_ID( Client_ThisServer( )))) return DISCONNECTED;
779 7281b8dd 2004-05-07 alex if( ! IRC_WriteStrClient( Client, RPL_MOTD_MSG, Client_ID( Client ), Conf_MotdPhrase )) return DISCONNECTED;
780 7281b8dd 2004-05-07 alex return IRC_WriteStrClient( Client, RPL_ENDOFMOTD_MSG, Client_ID( Client ));
783 0c471b84 2002-11-30 alex fd = fopen( Conf_MotdFile, "r" );
786 0c471b84 2002-11-30 alex Log( LOG_WARNING, "Can't read MOTD file \"%s\": %s", Conf_MotdFile, strerror( errno ));
787 0c471b84 2002-11-30 alex return IRC_WriteStrClient( Client, ERR_NOMOTD_MSG, Client_ID( Client ) );
790 7281b8dd 2004-05-07 alex if( ! IRC_WriteStrClient( Client, RPL_MOTDSTART_MSG, Client_ID( Client ), Client_ID( Client_ThisServer( )))) return DISCONNECTED;
791 0c471b84 2002-11-30 alex while( TRUE )
793 0c471b84 2002-11-30 alex if( ! fgets( line, 126, fd )) break;
794 0c471b84 2002-11-30 alex if( line[strlen( line ) - 1] == '\n' ) line[strlen( line ) - 1] = '\0';
795 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( Client, RPL_MOTD_MSG, Client_ID( Client ), line ))
797 0c471b84 2002-11-30 alex fclose( fd );
798 0c471b84 2002-11-30 alex return FALSE;
801 0c471b84 2002-11-30 alex ok = IRC_WriteStrClient( Client, RPL_ENDOFMOTD_MSG, Client_ID( Client ) );
803 0c471b84 2002-11-30 alex fclose( fd );
806 0c471b84 2002-11-30 alex } /* IRC_Show_MOTD */
809 0c471b84 2002-11-30 alex GLOBAL BOOLEAN
810 0c471b84 2002-11-30 alex IRC_Send_NAMES( CLIENT *Client, CHANNEL *Chan )
812 0c471b84 2002-11-30 alex BOOLEAN is_visible, is_member;
813 0c471b84 2002-11-30 alex CHAR str[LINE_LEN + 1];
814 0c471b84 2002-11-30 alex CL2CHAN *cl2chan;
815 0c471b84 2002-11-30 alex CLIENT *cl;
817 0c471b84 2002-11-30 alex assert( Client != NULL );
818 0c471b84 2002-11-30 alex assert( Chan != NULL );
820 0c471b84 2002-11-30 alex if( Channel_IsMemberOf( Chan, Client )) is_member = TRUE;
821 0c471b84 2002-11-30 alex else is_member = FALSE;
823 0c471b84 2002-11-30 alex /* Alle Mitglieder suchen */
824 b316c380 2002-12-26 alex snprintf( str, sizeof( str ), RPL_NAMREPLY_MSG, Client_ID( Client ), "=", Channel_Name( Chan ));
825 0c471b84 2002-11-30 alex cl2chan = Channel_FirstMember( Chan );
826 0c471b84 2002-11-30 alex while( cl2chan )
828 0c471b84 2002-11-30 alex cl = Channel_GetClient( cl2chan );
830 0c471b84 2002-11-30 alex if( strchr( Client_Modes( cl ), 'i' )) is_visible = FALSE;
831 0c471b84 2002-11-30 alex else is_visible = TRUE;
833 0c471b84 2002-11-30 alex if( is_member || is_visible )
835 0c471b84 2002-11-30 alex /* Nick anhaengen */
836 6626395c 2002-12-26 alex if( str[strlen( str ) - 1] != ':' ) strlcat( str, " ", sizeof( str ));
837 6626395c 2002-12-26 alex if( strchr( Channel_UserModes( Chan, cl ), 'o' )) strlcat( str, "@", sizeof( str ));
838 6626395c 2002-12-26 alex else if( strchr( Channel_UserModes( Chan, cl ), 'v' )) strlcat( str, "+", sizeof( str ));
839 6626395c 2002-12-26 alex strlcat( str, Client_ID( cl ), sizeof( str ));
841 0c471b84 2002-11-30 alex if( strlen( str ) > ( LINE_LEN - CLIENT_NICK_LEN - 4 ))
843 0c471b84 2002-11-30 alex /* Zeile wird zu lang: senden! */
844 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( Client, "%s", str )) return DISCONNECTED;
845 b316c380 2002-12-26 alex snprintf( str, sizeof( str ), RPL_NAMREPLY_MSG, Client_ID( Client ), "=", Channel_Name( Chan ));
849 0c471b84 2002-11-30 alex /* naechstes Mitglied suchen */
850 0c471b84 2002-11-30 alex cl2chan = Channel_NextMember( Chan, cl2chan );
852 0c471b84 2002-11-30 alex if( str[strlen( str ) - 1] != ':')
854 0c471b84 2002-11-30 alex /* Es sind noch Daten da, die gesendet werden muessen */
855 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( Client, "%s", str )) return DISCONNECTED;
858 0c471b84 2002-11-30 alex return CONNECTED;
859 0c471b84 2002-11-30 alex } /* IRC_Send_NAMES */
862 0c471b84 2002-11-30 alex GLOBAL BOOLEAN
863 0c471b84 2002-11-30 alex IRC_Send_WHO( CLIENT *Client, CHANNEL *Chan, BOOLEAN OnlyOps )
865 0c471b84 2002-11-30 alex BOOLEAN is_visible, is_member;
866 0c471b84 2002-11-30 alex CL2CHAN *cl2chan;
867 0c471b84 2002-11-30 alex CHAR flags[8];
870 0c471b84 2002-11-30 alex assert( Client != NULL );
871 0c471b84 2002-11-30 alex assert( Chan != NULL );
873 0c471b84 2002-11-30 alex if( Channel_IsMemberOf( Chan, Client )) is_member = TRUE;
874 0c471b84 2002-11-30 alex else is_member = FALSE;
876 0c471b84 2002-11-30 alex /* Alle Mitglieder suchen */
877 0c471b84 2002-11-30 alex cl2chan = Channel_FirstMember( Chan );
878 0c471b84 2002-11-30 alex while( cl2chan )
880 0c471b84 2002-11-30 alex c = Channel_GetClient( cl2chan );
882 0c471b84 2002-11-30 alex if( strchr( Client_Modes( c ), 'i' )) is_visible = FALSE;
883 0c471b84 2002-11-30 alex else is_visible = TRUE;
885 0c471b84 2002-11-30 alex if( is_member || is_visible )
887 0c471b84 2002-11-30 alex /* Flags zusammenbasteln */
888 0c471b84 2002-11-30 alex strcpy( flags, "H" );
889 6626395c 2002-12-26 alex if( strchr( Client_Modes( c ), 'o' )) strlcat( flags, "*", sizeof( flags ));
890 6626395c 2002-12-26 alex if( strchr( Channel_UserModes( Chan, c ), 'o' )) strlcat( flags, "@", sizeof( flags ));
891 6626395c 2002-12-26 alex else if( strchr( Channel_UserModes( Chan, c ), 'v' )) strlcat( flags, "+", sizeof( flags ));
893 0c471b84 2002-11-30 alex /* ausgeben */
894 0c471b84 2002-11-30 alex if(( ! OnlyOps ) || ( strchr( Client_Modes( c ), 'o' )))
896 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;
900 0c471b84 2002-11-30 alex /* naechstes Mitglied suchen */
901 0c471b84 2002-11-30 alex cl2chan = Channel_NextMember( Chan, cl2chan );
903 0c471b84 2002-11-30 alex return CONNECTED;
904 0c471b84 2002-11-30 alex } /* IRC_Send_WHO */
907 0c471b84 2002-11-30 alex /* -eof- */