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)
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 06caecb0 2005-05-16 alex static char UNUSED id[] = "$Id: irc-info.c,v 1.29 2005/05/16 12:25:15 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 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>
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"
42 0c471b84 2002-11-30 alex #include "exp.h"
43 0c471b84 2002-11-30 alex #include "irc-info.h"
47 0c471b84 2002-11-30 alex IRC_ADMIN(CLIENT *Client, REQUEST *Req )
49 0c471b84 2002-11-30 alex CLIENT *target, *prefix;
51 0c471b84 2002-11-30 alex assert( Client != NULL );
52 0c471b84 2002-11-30 alex assert( Req != NULL );
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 );
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( );
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 );
66 0c471b84 2002-11-30 alex /* An anderen Server weiterleiten? */
67 0c471b84 2002-11-30 alex if( target != Client_ThisServer( ))
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] );
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;
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;
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 */
88 0c471b84 2002-11-30 alex IRC_ISON( CLIENT *Client, REQUEST *Req )
90 8adff592 2005-03-19 fw char rpl[COMMAND_LEN];
95 0c471b84 2002-11-30 alex assert( Client != NULL );
96 0c471b84 2002-11-30 alex assert( Req != NULL );
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 );
101 0c471b84 2002-11-30 alex strcpy( rpl, RPL_ISON_MSG );
102 0c471b84 2002-11-30 alex for( i = 0; i < Req->argc; i++ )
104 0c471b84 2002-11-30 alex ptr = strtok( Req->argv[i], " " );
105 0c471b84 2002-11-30 alex while( ptr )
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 ))
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 ));
115 0c471b84 2002-11-30 alex ptr = strtok( NULL, " " );
118 85acb824 2005-02-04 alex ngt_TrimLastChr(rpl, ' ');
120 f0349f52 2002-12-02 alex return IRC_WriteStrClient( Client, rpl, Client_ID( Client ) );
121 0c471b84 2002-11-30 alex } /* IRC_ISON */
125 0c471b84 2002-11-30 alex IRC_LINKS( CLIENT *Client, REQUEST *Req )
127 0c471b84 2002-11-30 alex CLIENT *target, *from, *c;
130 0c471b84 2002-11-30 alex assert( Client != NULL );
131 0c471b84 2002-11-30 alex assert( Req != NULL );
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 );
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 = "*";
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 );
145 0c471b84 2002-11-30 alex /* An anderen Server forwarden? */
146 0c471b84 2002-11-30 alex if( Req->argc == 2 )
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] );
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 );
158 0c471b84 2002-11-30 alex c = Client_First( );
161 0c471b84 2002-11-30 alex if( Client_Type( c ) == CLIENT_SERVER )
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;
165 0c471b84 2002-11-30 alex c = Client_Next( c );
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 */
174 0c471b84 2002-11-30 alex IRC_LUSERS( CLIENT *Client, REQUEST *Req )
176 0c471b84 2002-11-30 alex CLIENT *target, *from;
178 0c471b84 2002-11-30 alex assert( Client != NULL );
179 0c471b84 2002-11-30 alex assert( Req != NULL );
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 );
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 );
189 0c471b84 2002-11-30 alex /* An anderen Server forwarden? */
190 0c471b84 2002-11-30 alex if( Req->argc == 2 )
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] );
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 );
202 0c471b84 2002-11-30 alex IRC_Send_LUSERS( target );
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 */
210 0c471b84 2002-11-30 alex IRC_MOTD( CLIENT *Client, REQUEST *Req )
212 0c471b84 2002-11-30 alex CLIENT *from, *target;
214 0c471b84 2002-11-30 alex assert( Client != NULL );
215 0c471b84 2002-11-30 alex assert( Req != NULL );
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 );
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 );
225 0c471b84 2002-11-30 alex if( Req->argc == 1 )
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] );
231 0c471b84 2002-11-30 alex if( target != Client_ThisServer( ))
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] );
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 */
244 0c471b84 2002-11-30 alex IRC_NAMES( CLIENT *Client, REQUEST *Req )
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;
250 0c471b84 2002-11-30 alex assert( Client != NULL );
251 0c471b84 2002-11-30 alex assert( Req != NULL );
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 );
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 );
261 0c471b84 2002-11-30 alex if( Req->argc == 2 )
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] );
267 0c471b84 2002-11-30 alex if( target != Client_ThisServer( ))
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] );
274 0c471b84 2002-11-30 alex if( Req->argc > 0 )
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 )
280 0c471b84 2002-11-30 alex chan = Channel_Search( ptr );
283 0c471b84 2002-11-30 alex /* Namen ausgeben */
284 0c471b84 2002-11-30 alex if( ! IRC_Send_NAMES( from, chan )) return DISCONNECTED;
286 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( from, RPL_ENDOFNAMES_MSG, Client_ID( from ), ptr )) return DISCONNECTED;
288 0c471b84 2002-11-30 alex /* naechsten Namen ermitteln */
289 0c471b84 2002-11-30 alex ptr = strtok( NULL, "," );
291 0c471b84 2002-11-30 alex return CONNECTED;
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 )
298 0c471b84 2002-11-30 alex /* Namen ausgeben */
299 0c471b84 2002-11-30 alex if( ! IRC_Send_NAMES( from, chan )) return DISCONNECTED;
301 0c471b84 2002-11-30 alex /* naechster Channel */
302 0c471b84 2002-11-30 alex chan = Channel_Next( chan );
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 ), "*", "*" );
310 0c471b84 2002-11-30 alex if(( Client_Type( c ) == CLIENT_USER ) && ( Channel_FirstChannelOf( c ) == NULL ) && ( ! strchr( Client_Modes( c ), 'i' )))
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 ));
316 0c471b84 2002-11-30 alex if( strlen( rpl ) > ( LINE_LEN - CLIENT_NICK_LEN - 4 ))
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 ), "*", "*" );
324 0c471b84 2002-11-30 alex /* naechster Client */
325 0c471b84 2002-11-30 alex c = Client_Next( c );
327 0c471b84 2002-11-30 alex if( rpl[strlen( rpl ) - 1] != ':')
329 0c471b84 2002-11-30 alex /* es wurden User gefunden */
330 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( from, "%s", rpl )) return DISCONNECTED;
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 */
339 0c471b84 2002-11-30 alex IRC_STATS( CLIENT *Client, REQUEST *Req )
341 bad7ac62 2002-12-02 alex CLIENT *from, *target, *cl;
342 bad7ac62 2002-12-02 alex CONN_ID con;
344 210282d0 2002-12-18 alex COMMAND *cmd;
346 0c471b84 2002-11-30 alex assert( Client != NULL );
347 0c471b84 2002-11-30 alex assert( Req != NULL );
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 );
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 );
357 0c471b84 2002-11-30 alex if( Req->argc == 2 )
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] );
363 0c471b84 2002-11-30 alex if( target != Client_ThisServer( ))
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] );
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 = '*';
373 bad7ac62 2002-12-02 alex switch ( query )
375 bad7ac62 2002-12-02 alex case 'l': /* Links */
377 bad7ac62 2002-12-02 alex con = Conn_First( );
378 bad7ac62 2002-12-02 alex while( con != NONE )
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 )))
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 )
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;
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;
395 bad7ac62 2002-12-02 alex con = Conn_Next( con );
398 bad7ac62 2002-12-02 alex case 'm': /* IRC-Befehle */
400 210282d0 2002-12-18 alex cmd = Parse_GetCommandStruct( );
401 210282d0 2002-12-18 alex while( cmd->name )
403 210282d0 2002-12-18 alex if( cmd->lcount > 0 || cmd->rcount > 0 )
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;
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 */
418 0c471b84 2002-11-30 alex IRC_TIME( CLIENT *Client, REQUEST *Req )
420 0c471b84 2002-11-30 alex CLIENT *from, *target;
421 8adff592 2005-03-19 fw char t_str[64];
424 0c471b84 2002-11-30 alex assert( Client != NULL );
425 0c471b84 2002-11-30 alex assert( Req != NULL );
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 );
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 );
435 0c471b84 2002-11-30 alex if( Req->argc == 1 )
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] );
441 0c471b84 2002-11-30 alex if( target != Client_ThisServer( ))
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] );
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 */
455 0c471b84 2002-11-30 alex IRC_USERHOST( CLIENT *Client, REQUEST *Req )
457 8adff592 2005-03-19 fw char rpl[COMMAND_LEN];
461 0c471b84 2002-11-30 alex assert( Client != NULL );
462 0c471b84 2002-11-30 alex assert( Req != NULL );
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 );
467 0c471b84 2002-11-30 alex if( Req->argc > 5 ) max = 5;
468 0c471b84 2002-11-30 alex else max = Req->argc;
470 0c471b84 2002-11-30 alex strcpy( rpl, RPL_USERHOST_MSG );
471 0c471b84 2002-11-30 alex for( i = 0; i < max; i++ )
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 ))
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 ));
488 85acb824 2005-02-04 alex ngt_TrimLastChr( rpl, ' ');
490 f0349f52 2002-12-02 alex return IRC_WriteStrClient( Client, rpl, Client_ID( Client ) );
491 0c471b84 2002-11-30 alex } /* IRC_USERHOST */
495 0c471b84 2002-11-30 alex IRC_VERSION( CLIENT *Client, REQUEST *Req )
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];
502 0c471b84 2002-11-30 alex assert( Client != NULL );
503 0c471b84 2002-11-30 alex assert( Req != NULL );
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 );
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( );
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 );
517 0c471b84 2002-11-30 alex /* An anderen Server weiterleiten? */
518 0c471b84 2002-11-30 alex if( target != Client_ThisServer( ))
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] );
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;
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 );
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 );
538 0c471b84 2002-11-30 alex } /* IRC_VERSION */
542 0c471b84 2002-11-30 alex IRC_WHO( CLIENT *Client, REQUEST *Req )
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;
550 0c471b84 2002-11-30 alex assert( Client != NULL );
551 0c471b84 2002-11-30 alex assert( Req != NULL );
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 );
556 8adff592 2005-03-19 fw only_ops = false;
557 0c471b84 2002-11-30 alex chan = NULL;
559 0c471b84 2002-11-30 alex if( Req->argc == 2 )
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 );
568 0c471b84 2002-11-30 alex if( Req->argc >= 1 )
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] );
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;
580 0c471b84 2002-11-30 alex c = Client_First( );
583 0c471b84 2002-11-30 alex if(( Client_Type( c ) == CLIENT_USER ) && ( ! strchr( Client_Modes( c ), 'i' )))
586 8adff592 2005-03-19 fw if( Req->argc == 0 ) ok = true;
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;
593 0c471b84 2002-11-30 alex if( ok && (( ! only_ops ) || ( strchr( Client_Modes( c ), 'o' ))))
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 ));
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 )
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' ))
607 4ef172d6 2005-03-02 alex ptr = Channel_Name( cn );
610 4ef172d6 2005-03-02 alex cl2chan = Channel_NextChannelOf( c, cl2chan );
612 4ef172d6 2005-03-02 alex if( ! cl2chan ) ptr = "*";
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;
618 0c471b84 2002-11-30 alex /* naechster Client */
619 0c471b84 2002-11-30 alex c = Client_Next( c );
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 */
629 0c471b84 2002-11-30 alex IRC_WHOIS( CLIENT *Client, REQUEST *Req )
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;
636 0c471b84 2002-11-30 alex assert( Client != NULL );
637 0c471b84 2002-11-30 alex assert( Req != NULL );
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 );
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] );
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 );
651 e17976a1 2003-01-01 alex /* Forward to other server? */
652 0c471b84 2002-11-30 alex if( Req->argc > 1 )
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] );
658 0c471b84 2002-11-30 alex else target = Client_ThisServer( );
660 0c471b84 2002-11-30 alex assert( target != NULL );
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] );
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;
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;
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 )
675 0c471b84 2002-11-30 alex chan = Channel_GetChannel( cl2chan );
676 0c471b84 2002-11-30 alex assert( chan != NULL );
679 4ef172d6 2005-03-02 alex cl2chan = Channel_NextChannelOf( c, cl2chan );
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;
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 ));
690 0c471b84 2002-11-30 alex if( strlen( str ) > ( LINE_LEN - CHANNEL_NAME_LEN - 4 ))
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 ));
697 0c471b84 2002-11-30 alex if( str[strlen( str ) - 1] != ':')
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;
703 0c471b84 2002-11-30 alex /* IRC-Operator? */
704 0c471b84 2002-11-30 alex if( Client_HasMode( c, 'o' ))
706 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( from, RPL_WHOISOPERATOR_MSG, Client_ID( from ), Client_ID( c ))) return DISCONNECTED;
709 e17976a1 2003-01-01 alex /* Idle (only local clients) */
710 0c471b84 2002-11-30 alex if( Client_Conn( c ) > NONE )
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;
715 0c471b84 2002-11-30 alex /* Away? */
716 0c471b84 2002-11-30 alex if( Client_HasMode( c, 'a' ))
718 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( from, RPL_AWAY_MSG, Client_ID( from ), Client_ID( c ), Client_Away( c ))) return DISCONNECTED;
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 */
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.
732 0c471b84 2002-11-30 alex IRC_WHOWAS( CLIENT *Client, REQUEST *Req )
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];
739 0c471b84 2002-11-30 alex assert( Client != NULL );
740 0c471b84 2002-11-30 alex assert( Req != NULL );
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 );
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] );
751 06caecb0 2005-05-16 alex target = Client_ThisServer( );
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 );
757 06caecb0 2005-05-16 alex prefix = Client;
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 );
763 06caecb0 2005-05-16 alex /* Forward to other server? */
764 06caecb0 2005-05-16 alex if( target != Client_ThisServer( ))
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] );
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;
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;
782 06caecb0 2005-05-16 alex if( Req->argc > 1 )
784 06caecb0 2005-05-16 alex max = atoi( Req->argv[1] );
785 06caecb0 2005-05-16 alex if( max < 1 ) max = MAX_WHOWAS;
788 06caecb0 2005-05-16 alex max = DEFAULT_WHOWAS;
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 )
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 ));
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;
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;
817 06caecb0 2005-05-16 alex if( count >= max ) break;
820 06caecb0 2005-05-16 alex /* previos entry */
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 );
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 */
833 0c471b84 2002-11-30 alex IRC_Send_LUSERS( CLIENT *Client )
837 0c471b84 2002-11-30 alex assert( Client != NULL );
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;
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 )
846 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( Client, RPL_LUSEROP_MSG, Client_ID( Client ), cnt )) return DISCONNECTED;
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 )
853 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( Client, RPL_LUSERUNKNOWN_MSG, Client_ID( Client ), cnt )) return DISCONNECTED;
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;
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;
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;
869 0c471b84 2002-11-30 alex return CONNECTED;
870 0c471b84 2002-11-30 alex } /* IRC_Send_LUSERS */
874 0c471b84 2002-11-30 alex IRC_Show_MOTD( CLIENT *Client )
877 8adff592 2005-03-19 fw char line[127];
880 0c471b84 2002-11-30 alex assert( Client != NULL );
882 7281b8dd 2004-05-07 alex if( Conf_MotdPhrase[0] )
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 ));
889 0c471b84 2002-11-30 alex fd = fopen( Conf_MotdFile, "r" );
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 ) );
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 )
899 44172a8c 2005-01-24 alex if( ! fgets( line, sizeof( line ), fd )) break;
901 85acb824 2005-02-04 alex ngt_TrimLastChr( line, '\n');
903 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( Client, RPL_MOTD_MSG, Client_ID( Client ), line ))
905 0c471b84 2002-11-30 alex fclose( fd );
906 8adff592 2005-03-19 fw return false;
909 0c471b84 2002-11-30 alex ok = IRC_WriteStrClient( Client, RPL_ENDOFMOTD_MSG, Client_ID( Client ) );
911 0c471b84 2002-11-30 alex fclose( fd );
914 0c471b84 2002-11-30 alex } /* IRC_Show_MOTD */
918 0c471b84 2002-11-30 alex IRC_Send_NAMES( CLIENT *Client, CHANNEL *Chan )
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;
925 0c471b84 2002-11-30 alex assert( Client != NULL );
926 0c471b84 2002-11-30 alex assert( Chan != NULL );
928 8adff592 2005-03-19 fw if( Channel_IsMemberOf( Chan, Client )) is_member = true;
929 8adff592 2005-03-19 fw else is_member = false;
931 4ef172d6 2005-03-02 alex /* Secret channel? */
932 4ef172d6 2005-03-02 alex if( ! is_member && strchr( Channel_Modes( Chan ), 's' )) return CONNECTED;
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 )
939 0c471b84 2002-11-30 alex cl = Channel_GetClient( cl2chan );
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;
944 0c471b84 2002-11-30 alex if( is_member || is_visible )
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 ));
952 0c471b84 2002-11-30 alex if( strlen( str ) > ( LINE_LEN - CLIENT_NICK_LEN - 4 ))
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 ));
960 0c471b84 2002-11-30 alex /* naechstes Mitglied suchen */
961 0c471b84 2002-11-30 alex cl2chan = Channel_NextMember( Chan, cl2chan );
963 0c471b84 2002-11-30 alex if( str[strlen( str ) - 1] != ':')
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;
969 0c471b84 2002-11-30 alex return CONNECTED;
970 0c471b84 2002-11-30 alex } /* IRC_Send_NAMES */
974 8adff592 2005-03-19 fw IRC_Send_WHO( CLIENT *Client, CHANNEL *Chan, bool OnlyOps )
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];
981 0c471b84 2002-11-30 alex assert( Client != NULL );
982 0c471b84 2002-11-30 alex assert( Chan != NULL );
984 8adff592 2005-03-19 fw if( Channel_IsMemberOf( Chan, Client )) is_member = true;
985 8adff592 2005-03-19 fw else is_member = false;
987 4ef172d6 2005-03-02 alex /* Secret channel? */
988 4ef172d6 2005-03-02 alex if( ! is_member && strchr( Channel_Modes( Chan ), 's' )) return CONNECTED;
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 )
994 0c471b84 2002-11-30 alex c = Channel_GetClient( cl2chan );
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;
999 0c471b84 2002-11-30 alex if( is_member || is_visible )
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 ));
1007 0c471b84 2002-11-30 alex /* ausgeben */
1008 0c471b84 2002-11-30 alex if(( ! OnlyOps ) || ( strchr( Client_Modes( c ), 'o' )))
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;
1014 0c471b84 2002-11-30 alex /* naechstes Mitglied suchen */
1015 0c471b84 2002-11-30 alex cl2chan = Channel_NextMember( Chan, cl2chan );
1017 0c471b84 2002-11-30 alex return CONNECTED;
1018 0c471b84 2002-11-30 alex } /* IRC_Send_WHO */
1021 0c471b84 2002-11-30 alex /* -eof- */