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 e17976a1 2003-01-01 alex static char UNUSED id[] = "$Id: irc-info.c,v 1.14 2003/01/01 13:30:35 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>
25 0c471b84 2002-11-30 alex #include "ngircd.h"
26 b8d7dcec 2002-12-30 alex #include "conn-func.h"
27 437f2c33 2002-12-30 alex #include "conn-zip.h"
28 0c471b84 2002-11-30 alex #include "client.h"
29 0c471b84 2002-11-30 alex #include "channel.h"
30 0c471b84 2002-11-30 alex #include "resolve.h"
31 0c471b84 2002-11-30 alex #include "conf.h"
32 0c471b84 2002-11-30 alex #include "defines.h"
33 0c471b84 2002-11-30 alex #include "log.h"
34 0c471b84 2002-11-30 alex #include "messages.h"
35 0c471b84 2002-11-30 alex #include "tool.h"
36 0c471b84 2002-11-30 alex #include "parse.h"
37 0c471b84 2002-11-30 alex #include "irc-write.h"
39 0c471b84 2002-11-30 alex #include "exp.h"
40 0c471b84 2002-11-30 alex #include "irc-info.h"
43 0c471b84 2002-11-30 alex GLOBAL BOOLEAN
44 0c471b84 2002-11-30 alex IRC_ADMIN(CLIENT *Client, REQUEST *Req )
46 0c471b84 2002-11-30 alex CLIENT *target, *prefix;
48 0c471b84 2002-11-30 alex assert( Client != NULL );
49 0c471b84 2002-11-30 alex assert( Req != NULL );
51 0c471b84 2002-11-30 alex /* Falsche Anzahl Parameter? */
52 0c471b84 2002-11-30 alex if(( Req->argc > 1 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
54 0c471b84 2002-11-30 alex /* Ziel suchen */
55 0c471b84 2002-11-30 alex if( Req->argc == 1 ) target = Client_Search( Req->argv[0] );
56 0c471b84 2002-11-30 alex else target = Client_ThisServer( );
58 0c471b84 2002-11-30 alex /* Prefix ermitteln */
59 0c471b84 2002-11-30 alex if( Client_Type( Client ) == CLIENT_SERVER ) prefix = Client_Search( Req->prefix );
60 0c471b84 2002-11-30 alex else prefix = Client;
61 7924fafb 2002-12-16 alex if( ! prefix ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
63 0c471b84 2002-11-30 alex /* An anderen Server weiterleiten? */
64 0c471b84 2002-11-30 alex if( target != Client_ThisServer( ))
66 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] );
68 0c471b84 2002-11-30 alex /* forwarden */
69 0c471b84 2002-11-30 alex IRC_WriteStrClientPrefix( target, prefix, "ADMIN %s", Req->argv[0] );
70 0c471b84 2002-11-30 alex return CONNECTED;
73 0c471b84 2002-11-30 alex /* mit Versionsinfo antworten */
74 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( Client, RPL_ADMINME_MSG, Client_ID( prefix ), Conf_ServerName )) return DISCONNECTED;
75 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( Client, RPL_ADMINLOC1_MSG, Client_ID( prefix ), Conf_ServerAdmin1 )) return DISCONNECTED;
76 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( Client, RPL_ADMINLOC2_MSG, Client_ID( prefix ), Conf_ServerAdmin2 )) return DISCONNECTED;
77 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( Client, RPL_ADMINEMAIL_MSG, Client_ID( prefix ), Conf_ServerAdminMail )) return DISCONNECTED;
79 0c471b84 2002-11-30 alex return CONNECTED;
80 0c471b84 2002-11-30 alex } /* IRC_ADMIN */
83 0c471b84 2002-11-30 alex GLOBAL BOOLEAN
84 0c471b84 2002-11-30 alex IRC_ISON( CLIENT *Client, REQUEST *Req )
86 0c471b84 2002-11-30 alex CHAR rpl[COMMAND_LEN];
91 0c471b84 2002-11-30 alex assert( Client != NULL );
92 0c471b84 2002-11-30 alex assert( Req != NULL );
94 0c471b84 2002-11-30 alex /* Falsche Anzahl Parameter? */
95 0c471b84 2002-11-30 alex if(( Req->argc < 1 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
97 0c471b84 2002-11-30 alex strcpy( rpl, RPL_ISON_MSG );
98 0c471b84 2002-11-30 alex for( i = 0; i < Req->argc; i++ )
100 0c471b84 2002-11-30 alex ptr = strtok( Req->argv[i], " " );
101 0c471b84 2002-11-30 alex while( ptr )
103 0c471b84 2002-11-30 alex ngt_TrimStr( ptr );
104 0c471b84 2002-11-30 alex c = Client_Search( ptr );
105 0c471b84 2002-11-30 alex if( c && ( Client_Type( c ) == CLIENT_USER ))
107 0c471b84 2002-11-30 alex /* Dieser Nick ist "online" */
108 6626395c 2002-12-26 alex strlcat( rpl, ptr, sizeof( rpl ));
109 6626395c 2002-12-26 alex strlcat( rpl, " ", sizeof( rpl ));
111 0c471b84 2002-11-30 alex ptr = strtok( NULL, " " );
114 0c471b84 2002-11-30 alex if( rpl[strlen( rpl ) - 1] == ' ' ) rpl[strlen( rpl ) - 1] = '\0';
116 f0349f52 2002-12-02 alex return IRC_WriteStrClient( Client, rpl, Client_ID( Client ) );
117 0c471b84 2002-11-30 alex } /* IRC_ISON */
120 0c471b84 2002-11-30 alex GLOBAL BOOLEAN
121 0c471b84 2002-11-30 alex IRC_LINKS( CLIENT *Client, REQUEST *Req )
123 0c471b84 2002-11-30 alex CLIENT *target, *from, *c;
124 0c471b84 2002-11-30 alex CHAR *mask;
126 0c471b84 2002-11-30 alex assert( Client != NULL );
127 0c471b84 2002-11-30 alex assert( Req != NULL );
129 0c471b84 2002-11-30 alex /* Falsche Anzahl Parameter? */
130 0c471b84 2002-11-30 alex if(( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
132 0c471b84 2002-11-30 alex /* Server-Mask ermitteln */
133 0c471b84 2002-11-30 alex if( Req->argc > 0 ) mask = Req->argv[Req->argc - 1];
134 0c471b84 2002-11-30 alex else mask = "*";
136 0c471b84 2002-11-30 alex /* Absender ermitteln */
137 0c471b84 2002-11-30 alex if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
138 0c471b84 2002-11-30 alex else from = Client;
139 0c471b84 2002-11-30 alex if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
141 0c471b84 2002-11-30 alex /* An anderen Server forwarden? */
142 0c471b84 2002-11-30 alex if( Req->argc == 2 )
144 0c471b84 2002-11-30 alex target = Client_Search( Req->argv[0] );
145 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] );
146 0c471b84 2002-11-30 alex else if( target != Client_ThisServer( )) return IRC_WriteStrClientPrefix( target, from, "LINKS %s %s", Req->argv[0], Req->argv[1] );
149 0c471b84 2002-11-30 alex /* Wer ist der Absender? */
150 0c471b84 2002-11-30 alex if( Client_Type( Client ) == CLIENT_SERVER ) target = Client_Search( Req->prefix );
151 0c471b84 2002-11-30 alex else target = Client;
152 0c471b84 2002-11-30 alex if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
154 0c471b84 2002-11-30 alex c = Client_First( );
157 0c471b84 2002-11-30 alex if( Client_Type( c ) == CLIENT_SERVER )
159 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;
161 0c471b84 2002-11-30 alex c = Client_Next( c );
164 0c471b84 2002-11-30 alex return IRC_WriteStrClient( target, RPL_ENDOFLINKS_MSG, Client_ID( target ), mask );
165 0c471b84 2002-11-30 alex } /* IRC_LINKS */
168 0c471b84 2002-11-30 alex GLOBAL BOOLEAN
169 0c471b84 2002-11-30 alex IRC_LUSERS( CLIENT *Client, REQUEST *Req )
171 0c471b84 2002-11-30 alex CLIENT *target, *from;
173 0c471b84 2002-11-30 alex assert( Client != NULL );
174 0c471b84 2002-11-30 alex assert( Req != NULL );
176 0c471b84 2002-11-30 alex /* Falsche Anzahl Parameter? */
177 0c471b84 2002-11-30 alex if(( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
179 0c471b84 2002-11-30 alex /* Absender ermitteln */
180 0c471b84 2002-11-30 alex if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
181 0c471b84 2002-11-30 alex else from = Client;
182 0c471b84 2002-11-30 alex if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
184 0c471b84 2002-11-30 alex /* An anderen Server forwarden? */
185 0c471b84 2002-11-30 alex if( Req->argc == 2 )
187 0c471b84 2002-11-30 alex target = Client_Search( Req->argv[1] );
188 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] );
189 0c471b84 2002-11-30 alex else if( target != Client_ThisServer( )) return IRC_WriteStrClientPrefix( target, from, "LUSERS %s %s", Req->argv[0], Req->argv[1] );
192 0c471b84 2002-11-30 alex /* Wer ist der Absender? */
193 0c471b84 2002-11-30 alex if( Client_Type( Client ) == CLIENT_SERVER ) target = Client_Search( Req->prefix );
194 0c471b84 2002-11-30 alex else target = Client;
195 0c471b84 2002-11-30 alex if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
197 0c471b84 2002-11-30 alex IRC_Send_LUSERS( target );
199 0c471b84 2002-11-30 alex return CONNECTED;
200 0c471b84 2002-11-30 alex } /* IRC_LUSERS */
203 0c471b84 2002-11-30 alex GLOBAL BOOLEAN
204 0c471b84 2002-11-30 alex IRC_MOTD( CLIENT *Client, REQUEST *Req )
206 0c471b84 2002-11-30 alex CLIENT *from, *target;
208 0c471b84 2002-11-30 alex assert( Client != NULL );
209 0c471b84 2002-11-30 alex assert( Req != NULL );
211 0c471b84 2002-11-30 alex /* Falsche Anzahl Parameter? */
212 0c471b84 2002-11-30 alex if( Req->argc > 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
214 0c471b84 2002-11-30 alex /* From aus Prefix ermitteln */
215 0c471b84 2002-11-30 alex if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
216 0c471b84 2002-11-30 alex else from = Client;
217 7924fafb 2002-12-16 alex if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
219 0c471b84 2002-11-30 alex if( Req->argc == 1 )
221 0c471b84 2002-11-30 alex /* an anderen Server forwarden */
222 0c471b84 2002-11-30 alex target = Client_Search( Req->argv[0] );
223 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] );
225 0c471b84 2002-11-30 alex if( target != Client_ThisServer( ))
227 0c471b84 2002-11-30 alex /* Ok, anderer Server ist das Ziel: forwarden */
228 0c471b84 2002-11-30 alex return IRC_WriteStrClientPrefix( target, from, "MOTD %s", Req->argv[0] );
232 0c471b84 2002-11-30 alex return IRC_Show_MOTD( from );
233 0c471b84 2002-11-30 alex } /* IRC_MOTD */
236 0c471b84 2002-11-30 alex GLOBAL BOOLEAN
237 0c471b84 2002-11-30 alex IRC_NAMES( CLIENT *Client, REQUEST *Req )
239 0c471b84 2002-11-30 alex CHAR rpl[COMMAND_LEN], *ptr;
240 0c471b84 2002-11-30 alex CLIENT *target, *from, *c;
241 0c471b84 2002-11-30 alex CHANNEL *chan;
243 0c471b84 2002-11-30 alex assert( Client != NULL );
244 0c471b84 2002-11-30 alex assert( Req != NULL );
246 0c471b84 2002-11-30 alex /* Falsche Anzahl Parameter? */
247 0c471b84 2002-11-30 alex if( Req->argc > 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
249 0c471b84 2002-11-30 alex /* From aus Prefix ermitteln */
250 0c471b84 2002-11-30 alex if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
251 0c471b84 2002-11-30 alex else from = Client;
252 7924fafb 2002-12-16 alex if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
254 0c471b84 2002-11-30 alex if( Req->argc == 2 )
256 0c471b84 2002-11-30 alex /* an anderen Server forwarden */
257 0c471b84 2002-11-30 alex target = Client_Search( Req->argv[1] );
258 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] );
260 0c471b84 2002-11-30 alex if( target != Client_ThisServer( ))
262 0c471b84 2002-11-30 alex /* Ok, anderer Server ist das Ziel: forwarden */
263 0c471b84 2002-11-30 alex return IRC_WriteStrClientPrefix( target, from, "NAMES %s :%s", Req->argv[0], Req->argv[1] );
267 0c471b84 2002-11-30 alex if( Req->argc > 0 )
269 0c471b84 2002-11-30 alex /* bestimmte Channels durchgehen */
270 0c471b84 2002-11-30 alex ptr = strtok( Req->argv[0], "," );
271 0c471b84 2002-11-30 alex while( ptr )
273 0c471b84 2002-11-30 alex chan = Channel_Search( ptr );
276 0c471b84 2002-11-30 alex /* Namen ausgeben */
277 0c471b84 2002-11-30 alex if( ! IRC_Send_NAMES( from, chan )) return DISCONNECTED;
279 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( from, RPL_ENDOFNAMES_MSG, Client_ID( from ), ptr )) return DISCONNECTED;
281 0c471b84 2002-11-30 alex /* naechsten Namen ermitteln */
282 0c471b84 2002-11-30 alex ptr = strtok( NULL, "," );
284 0c471b84 2002-11-30 alex return CONNECTED;
287 0c471b84 2002-11-30 alex /* alle Channels durchgehen */
288 0c471b84 2002-11-30 alex chan = Channel_First( );
289 0c471b84 2002-11-30 alex while( chan )
291 0c471b84 2002-11-30 alex /* Namen ausgeben */
292 0c471b84 2002-11-30 alex if( ! IRC_Send_NAMES( from, chan )) return DISCONNECTED;
294 0c471b84 2002-11-30 alex /* naechster Channel */
295 0c471b84 2002-11-30 alex chan = Channel_Next( chan );
298 0c471b84 2002-11-30 alex /* Nun noch alle Clients ausgeben, die in keinem Channel sind */
299 0c471b84 2002-11-30 alex c = Client_First( );
300 b316c380 2002-12-26 alex snprintf( rpl, sizeof( rpl ), RPL_NAMREPLY_MSG, Client_ID( from ), "*", "*" );
303 0c471b84 2002-11-30 alex if(( Client_Type( c ) == CLIENT_USER ) && ( Channel_FirstChannelOf( c ) == NULL ) && ( ! strchr( Client_Modes( c ), 'i' )))
305 0c471b84 2002-11-30 alex /* Okay, das ist ein User: anhaengen */
306 6626395c 2002-12-26 alex if( rpl[strlen( rpl ) - 1] != ':' ) strlcat( rpl, " ", sizeof( rpl ));
307 6626395c 2002-12-26 alex strlcat( rpl, Client_ID( c ), sizeof( rpl ));
309 0c471b84 2002-11-30 alex if( strlen( rpl ) > ( LINE_LEN - CLIENT_NICK_LEN - 4 ))
311 0c471b84 2002-11-30 alex /* Zeile wird zu lang: senden! */
312 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( from, "%s", rpl )) return DISCONNECTED;
313 b316c380 2002-12-26 alex snprintf( rpl, sizeof( rpl ), RPL_NAMREPLY_MSG, Client_ID( from ), "*", "*" );
317 0c471b84 2002-11-30 alex /* naechster Client */
318 0c471b84 2002-11-30 alex c = Client_Next( c );
320 0c471b84 2002-11-30 alex if( rpl[strlen( rpl ) - 1] != ':')
322 0c471b84 2002-11-30 alex /* es wurden User gefunden */
323 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( from, "%s", rpl )) return DISCONNECTED;
326 0c471b84 2002-11-30 alex return IRC_WriteStrClient( from, RPL_ENDOFNAMES_MSG, Client_ID( from ), "*" );
327 0c471b84 2002-11-30 alex } /* IRC_NAMES */
330 0c471b84 2002-11-30 alex GLOBAL BOOLEAN
331 0c471b84 2002-11-30 alex IRC_STATS( CLIENT *Client, REQUEST *Req )
333 bad7ac62 2002-12-02 alex CLIENT *from, *target, *cl;
334 bad7ac62 2002-12-02 alex CONN_ID con;
335 0c471b84 2002-11-30 alex CHAR query;
336 210282d0 2002-12-18 alex COMMAND *cmd;
338 0c471b84 2002-11-30 alex assert( Client != NULL );
339 0c471b84 2002-11-30 alex assert( Req != NULL );
341 0c471b84 2002-11-30 alex /* Falsche Anzahl Parameter? */
342 0c471b84 2002-11-30 alex if( Req->argc > 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
344 0c471b84 2002-11-30 alex /* From aus Prefix ermitteln */
345 0c471b84 2002-11-30 alex if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
346 0c471b84 2002-11-30 alex else from = Client;
347 7924fafb 2002-12-16 alex if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
349 0c471b84 2002-11-30 alex if( Req->argc == 2 )
351 0c471b84 2002-11-30 alex /* an anderen Server forwarden */
352 e50d568f 2002-11-30 alex target = Client_Search( Req->argv[1] );
353 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] );
355 0c471b84 2002-11-30 alex if( target != Client_ThisServer( ))
357 0c471b84 2002-11-30 alex /* Ok, anderer Server ist das Ziel: forwarden */
358 7924fafb 2002-12-16 alex return IRC_WriteStrClientPrefix( target, from, "STATS %s %s", Req->argv[0], Req->argv[1] );
362 0c471b84 2002-11-30 alex if( Req->argc > 0 ) query = Req->argv[0][0] ? Req->argv[0][0] : '*';
363 0c471b84 2002-11-30 alex else query = '*';
365 bad7ac62 2002-12-02 alex switch ( query )
367 bad7ac62 2002-12-02 alex case 'l': /* Links */
369 bad7ac62 2002-12-02 alex con = Conn_First( );
370 bad7ac62 2002-12-02 alex while( con != NONE )
372 bad7ac62 2002-12-02 alex cl = Client_GetFromConn( con );
373 98677b43 2002-12-18 alex if( cl && (( Client_Type( cl ) == CLIENT_SERVER ) || ( cl == Client )))
375 98677b43 2002-12-18 alex /* Server link or our own connection */
376 bad7ac62 2002-12-02 alex #ifdef USE_ZLIB
377 bad7ac62 2002-12-02 alex if( Conn_Options( con ) & CONN_ZIP )
379 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;
384 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;
387 bad7ac62 2002-12-02 alex con = Conn_Next( con );
390 bad7ac62 2002-12-02 alex case 'm': /* IRC-Befehle */
392 210282d0 2002-12-18 alex cmd = Parse_GetCommandStruct( );
393 210282d0 2002-12-18 alex while( cmd->name )
395 210282d0 2002-12-18 alex if( cmd->lcount > 0 || cmd->rcount > 0 )
397 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;
404 0c471b84 2002-11-30 alex return IRC_WriteStrClient( from, RPL_ENDOFSTATS_MSG, Client_ID( from ), query );
405 0c471b84 2002-11-30 alex } /* IRC_STATS */
408 0c471b84 2002-11-30 alex GLOBAL BOOLEAN
409 0c471b84 2002-11-30 alex IRC_TIME( CLIENT *Client, REQUEST *Req )
411 0c471b84 2002-11-30 alex CLIENT *from, *target;
412 0c471b84 2002-11-30 alex CHAR t_str[64];
415 0c471b84 2002-11-30 alex assert( Client != NULL );
416 0c471b84 2002-11-30 alex assert( Req != NULL );
418 0c471b84 2002-11-30 alex /* Falsche Anzahl Parameter? */
419 0c471b84 2002-11-30 alex if( Req->argc > 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
421 0c471b84 2002-11-30 alex /* From aus Prefix ermitteln */
422 0c471b84 2002-11-30 alex if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
423 0c471b84 2002-11-30 alex else from = Client;
424 7924fafb 2002-12-16 alex if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
426 0c471b84 2002-11-30 alex if( Req->argc == 1 )
428 0c471b84 2002-11-30 alex /* an anderen Server forwarden */
429 0c471b84 2002-11-30 alex target = Client_Search( Req->argv[0] );
430 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] );
432 0c471b84 2002-11-30 alex if( target != Client_ThisServer( ))
434 0c471b84 2002-11-30 alex /* Ok, anderer Server ist das Ziel: forwarden */
435 0c471b84 2002-11-30 alex return IRC_WriteStrClientPrefix( target, from, "TIME %s", Req->argv[0] );
439 0c471b84 2002-11-30 alex t = time( NULL );
440 0c471b84 2002-11-30 alex (VOID)strftime( t_str, 60, "%A %B %d %Y -- %H:%M %z", localtime( &t ));
441 0c471b84 2002-11-30 alex return IRC_WriteStrClient( from, RPL_TIME_MSG, Client_ID( from ), Client_ID( Client_ThisServer( )), t_str );
442 0c471b84 2002-11-30 alex } /* IRC_TIME */
445 0c471b84 2002-11-30 alex GLOBAL BOOLEAN
446 0c471b84 2002-11-30 alex IRC_USERHOST( CLIENT *Client, REQUEST *Req )
448 0c471b84 2002-11-30 alex CHAR rpl[COMMAND_LEN];
450 0c471b84 2002-11-30 alex INT max, i;
452 0c471b84 2002-11-30 alex assert( Client != NULL );
453 0c471b84 2002-11-30 alex assert( Req != NULL );
455 0c471b84 2002-11-30 alex /* Falsche Anzahl Parameter? */
456 0c471b84 2002-11-30 alex if(( Req->argc < 1 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
458 0c471b84 2002-11-30 alex if( Req->argc > 5 ) max = 5;
459 0c471b84 2002-11-30 alex else max = Req->argc;
461 0c471b84 2002-11-30 alex strcpy( rpl, RPL_USERHOST_MSG );
462 0c471b84 2002-11-30 alex for( i = 0; i < max; i++ )
464 0c471b84 2002-11-30 alex c = Client_Search( Req->argv[i] );
465 0c471b84 2002-11-30 alex if( c && ( Client_Type( c ) == CLIENT_USER ))
467 0c471b84 2002-11-30 alex /* Dieser Nick ist "online" */
468 6626395c 2002-12-26 alex strlcat( rpl, Client_ID( c ), sizeof( rpl ));
469 6626395c 2002-12-26 alex if( Client_HasMode( c, 'o' )) strlcat( rpl, "*", sizeof( rpl ));
470 6626395c 2002-12-26 alex strlcat( rpl, "=", sizeof( rpl ));
471 6626395c 2002-12-26 alex if( Client_HasMode( c, 'a' )) strlcat( rpl, "-", sizeof( rpl ));
472 6626395c 2002-12-26 alex else strlcat( rpl, "+", sizeof( rpl ));
473 6626395c 2002-12-26 alex strlcat( rpl, Client_User( c ), sizeof( rpl ));
474 6626395c 2002-12-26 alex strlcat( rpl, "@", sizeof( rpl ));
475 6626395c 2002-12-26 alex strlcat( rpl, Client_Hostname( c ), sizeof( rpl ));
476 6626395c 2002-12-26 alex strlcat( rpl, " ", sizeof( rpl ));
479 0c471b84 2002-11-30 alex if( rpl[strlen( rpl ) - 1] == ' ' ) rpl[strlen( rpl ) - 1] = '\0';
481 f0349f52 2002-12-02 alex return IRC_WriteStrClient( Client, rpl, Client_ID( Client ) );
482 0c471b84 2002-11-30 alex } /* IRC_USERHOST */
485 0c471b84 2002-11-30 alex GLOBAL BOOLEAN
486 0c471b84 2002-11-30 alex IRC_VERSION( CLIENT *Client, REQUEST *Req )
488 0c471b84 2002-11-30 alex CLIENT *target, *prefix;
490 0c471b84 2002-11-30 alex assert( Client != NULL );
491 0c471b84 2002-11-30 alex assert( Req != NULL );
493 0c471b84 2002-11-30 alex /* Falsche Anzahl Parameter? */
494 0c471b84 2002-11-30 alex if(( Req->argc > 1 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
496 0c471b84 2002-11-30 alex /* Ziel suchen */
497 0c471b84 2002-11-30 alex if( Req->argc == 1 ) target = Client_Search( Req->argv[0] );
498 0c471b84 2002-11-30 alex else target = Client_ThisServer( );
500 0c471b84 2002-11-30 alex /* Prefix ermitteln */
501 0c471b84 2002-11-30 alex if( Client_Type( Client ) == CLIENT_SERVER ) prefix = Client_Search( Req->prefix );
502 0c471b84 2002-11-30 alex else prefix = Client;
503 7924fafb 2002-12-16 alex if( ! prefix ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
505 0c471b84 2002-11-30 alex /* An anderen Server weiterleiten? */
506 0c471b84 2002-11-30 alex if( target != Client_ThisServer( ))
508 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] );
510 0c471b84 2002-11-30 alex /* forwarden */
511 0c471b84 2002-11-30 alex IRC_WriteStrClientPrefix( target, prefix, "VERSION %s", Req->argv[0] );
512 0c471b84 2002-11-30 alex return CONNECTED;
515 0c471b84 2002-11-30 alex /* mit Versionsinfo antworten */
516 0c471b84 2002-11-30 alex return IRC_WriteStrClient( Client, RPL_VERSION_MSG, Client_ID( prefix ), PACKAGE, VERSION, NGIRCd_DebugLevel, Conf_ServerName, NGIRCd_VersionAddition( ));
517 0c471b84 2002-11-30 alex } /* IRC_VERSION */
520 0c471b84 2002-11-30 alex GLOBAL BOOLEAN
521 0c471b84 2002-11-30 alex IRC_WHO( CLIENT *Client, REQUEST *Req )
523 0c471b84 2002-11-30 alex BOOLEAN ok, only_ops;
524 0c471b84 2002-11-30 alex CHAR flags[8], *ptr;
525 0c471b84 2002-11-30 alex CL2CHAN *cl2chan;
526 0c471b84 2002-11-30 alex CHANNEL *chan;
529 0c471b84 2002-11-30 alex assert( Client != NULL );
530 0c471b84 2002-11-30 alex assert( Req != NULL );
532 0c471b84 2002-11-30 alex /* Falsche Anzahl Parameter? */
533 0c471b84 2002-11-30 alex if(( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
535 0c471b84 2002-11-30 alex only_ops = FALSE;
536 0c471b84 2002-11-30 alex chan = NULL;
538 0c471b84 2002-11-30 alex if( Req->argc == 2 )
540 0c471b84 2002-11-30 alex /* Nur OPs anzeigen? */
541 0c471b84 2002-11-30 alex if( strcmp( Req->argv[1], "o" ) == 0 ) only_ops = TRUE;
542 0c471b84 2002-11-30 alex #ifdef STRICT_RFC
543 0c471b84 2002-11-30 alex else return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
547 0c471b84 2002-11-30 alex if( Req->argc >= 1 )
549 0c471b84 2002-11-30 alex /* wurde ein Channel oder Nick-Mask angegeben? */
550 0c471b84 2002-11-30 alex chan = Channel_Search( Req->argv[0] );
555 0c471b84 2002-11-30 alex /* User eines Channels ausgeben */
556 0c471b84 2002-11-30 alex if( ! IRC_Send_WHO( Client, chan, only_ops )) return DISCONNECTED;
559 0c471b84 2002-11-30 alex c = Client_First( );
562 0c471b84 2002-11-30 alex if(( Client_Type( c ) == CLIENT_USER ) && ( ! strchr( Client_Modes( c ), 'i' )))
564 0c471b84 2002-11-30 alex ok = FALSE;
565 0c471b84 2002-11-30 alex if( Req->argc == 0 ) ok = TRUE;
568 0c471b84 2002-11-30 alex if( strcasecmp( Req->argv[0], Client_ID( c )) == 0 ) ok = TRUE;
569 0c471b84 2002-11-30 alex else if( strcmp( Req->argv[0], "0" ) == 0 ) ok = TRUE;
572 0c471b84 2002-11-30 alex if( ok && (( ! only_ops ) || ( strchr( Client_Modes( c ), 'o' ))))
574 0c471b84 2002-11-30 alex /* Flags zusammenbasteln */
575 0c471b84 2002-11-30 alex strcpy( flags, "H" );
576 6626395c 2002-12-26 alex if( strchr( Client_Modes( c ), 'o' )) strlcat( flags, "*", sizeof( flags ));
578 0c471b84 2002-11-30 alex /* ausgeben */
579 0c471b84 2002-11-30 alex cl2chan = Channel_FirstChannelOf( c );
580 0c471b84 2002-11-30 alex if( cl2chan ) ptr = Channel_Name( Channel_GetChannel( cl2chan ));
581 0c471b84 2002-11-30 alex else ptr = "*";
582 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;
586 0c471b84 2002-11-30 alex /* naechster Client */
587 0c471b84 2002-11-30 alex c = Client_Next( c );
590 0c471b84 2002-11-30 alex if( chan ) return IRC_WriteStrClient( Client, RPL_ENDOFWHO_MSG, Client_ID( Client ), Channel_Name( chan ));
591 0c471b84 2002-11-30 alex else if( Req->argc == 0 ) return IRC_WriteStrClient( Client, RPL_ENDOFWHO_MSG, Client_ID( Client ), "*" );
592 0c471b84 2002-11-30 alex else return IRC_WriteStrClient( Client, RPL_ENDOFWHO_MSG, Client_ID( Client ), Req->argv[0] );
593 0c471b84 2002-11-30 alex } /* IRC_WHO */
596 0c471b84 2002-11-30 alex GLOBAL BOOLEAN
597 0c471b84 2002-11-30 alex IRC_WHOIS( CLIENT *Client, REQUEST *Req )
599 0c471b84 2002-11-30 alex CLIENT *from, *target, *c;
600 e17976a1 2003-01-01 alex CHAR str[LINE_LEN + 1];
601 0c471b84 2002-11-30 alex CL2CHAN *cl2chan;
602 0c471b84 2002-11-30 alex CHANNEL *chan;
604 0c471b84 2002-11-30 alex assert( Client != NULL );
605 0c471b84 2002-11-30 alex assert( Req != NULL );
607 e17976a1 2003-01-01 alex /* Bad number of parameters? */
608 0c471b84 2002-11-30 alex if(( Req->argc < 1 ) || ( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
610 e17976a1 2003-01-01 alex /* Search client */
611 0c471b84 2002-11-30 alex c = Client_Search( Req->argv[Req->argc - 1] );
612 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] );
614 e17976a1 2003-01-01 alex /* Search sender of the WHOIS */
615 0c471b84 2002-11-30 alex if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
616 0c471b84 2002-11-30 alex else from = Client;
617 0c471b84 2002-11-30 alex if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
619 e17976a1 2003-01-01 alex /* Forward to other server? */
620 0c471b84 2002-11-30 alex if( Req->argc > 1 )
622 e17976a1 2003-01-01 alex /* Search target server (can be specified as nick of that server!) */
623 e17976a1 2003-01-01 alex target = Client_Search( Req->argv[0] );
624 e17976a1 2003-01-01 alex if( ! target ) return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[0] );
626 0c471b84 2002-11-30 alex else target = Client_ThisServer( );
628 0c471b84 2002-11-30 alex assert( target != NULL );
630 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] );
632 e17976a1 2003-01-01 alex /* Nick, user and name */
633 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;
635 0c471b84 2002-11-30 alex /* Server */
636 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;
638 0c471b84 2002-11-30 alex /* Channels */
639 b316c380 2002-12-26 alex snprintf( str, sizeof( str ), RPL_WHOISCHANNELS_MSG, Client_ID( from ), Client_ID( c ));
640 0c471b84 2002-11-30 alex cl2chan = Channel_FirstChannelOf( c );
641 0c471b84 2002-11-30 alex while( cl2chan )
643 0c471b84 2002-11-30 alex chan = Channel_GetChannel( cl2chan );
644 0c471b84 2002-11-30 alex assert( chan != NULL );
646 e17976a1 2003-01-01 alex /* Concatenate channel names */
647 6626395c 2002-12-26 alex if( str[strlen( str ) - 1] != ':' ) strlcat( str, " ", sizeof( str ));
648 6626395c 2002-12-26 alex if( strchr( Channel_UserModes( chan, c ), 'o' )) strlcat( str, "@", sizeof( str ));
649 6626395c 2002-12-26 alex else if( strchr( Channel_UserModes( chan, c ), 'v' )) strlcat( str, "+", sizeof( str ));
650 6626395c 2002-12-26 alex strlcat( str, Channel_Name( chan ), sizeof( str ));
652 0c471b84 2002-11-30 alex if( strlen( str ) > ( LINE_LEN - CHANNEL_NAME_LEN - 4 ))
654 e17976a1 2003-01-01 alex /* Line becomes too long: send it! */
655 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( Client, "%s", str )) return DISCONNECTED;
656 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_NextChannelOf( c, cl2chan );
662 0c471b84 2002-11-30 alex if( str[strlen( str ) - 1] != ':')
664 e17976a1 2003-01-01 alex /* There is data left to send: */
665 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( Client, "%s", str )) return DISCONNECTED;
668 0c471b84 2002-11-30 alex /* IRC-Operator? */
669 0c471b84 2002-11-30 alex if( Client_HasMode( c, 'o' ))
671 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( from, RPL_WHOISOPERATOR_MSG, Client_ID( from ), Client_ID( c ))) return DISCONNECTED;
674 e17976a1 2003-01-01 alex /* Idle (only local clients) */
675 0c471b84 2002-11-30 alex if( Client_Conn( c ) > NONE )
677 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;
680 0c471b84 2002-11-30 alex /* Away? */
681 0c471b84 2002-11-30 alex if( Client_HasMode( c, 'a' ))
683 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( from, RPL_AWAY_MSG, Client_ID( from ), Client_ID( c ), Client_Away( c ))) return DISCONNECTED;
686 0c471b84 2002-11-30 alex /* End of Whois */
687 0c471b84 2002-11-30 alex return IRC_WriteStrClient( from, RPL_ENDOFWHOIS_MSG, Client_ID( from ), Client_ID( c ));
688 0c471b84 2002-11-30 alex } /* IRC_WHOIS */
691 0c471b84 2002-11-30 alex GLOBAL BOOLEAN
692 0c471b84 2002-11-30 alex IRC_WHOWAS( CLIENT *Client, REQUEST *Req )
694 0c471b84 2002-11-30 alex assert( Client != NULL );
695 0c471b84 2002-11-30 alex assert( Req != NULL );
697 0c471b84 2002-11-30 alex /* Falsche Anzahl Parameter? */
698 0c471b84 2002-11-30 alex if(( Req->argc < 1 ) || ( Req->argc > 3 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
702 0c471b84 2002-11-30 alex return CONNECTED;
703 0c471b84 2002-11-30 alex } /* IRC_WHOWAS */
706 0c471b84 2002-11-30 alex GLOBAL BOOLEAN
707 0c471b84 2002-11-30 alex IRC_Send_LUSERS( CLIENT *Client )
711 0c471b84 2002-11-30 alex assert( Client != NULL );
713 212d36a3 2002-12-22 alex /* Users, services and serevers in the network */
714 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( Client, RPL_LUSERCLIENT_MSG, Client_ID( Client ), Client_UserCount( ), Client_ServiceCount( ), Client_ServerCount( ))) return DISCONNECTED;
716 212d36a3 2002-12-22 alex /* Number of IRC operators */
717 0c471b84 2002-11-30 alex cnt = Client_OperCount( );
718 0c471b84 2002-11-30 alex if( cnt > 0 )
720 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( Client, RPL_LUSEROP_MSG, Client_ID( Client ), cnt )) return DISCONNECTED;
723 212d36a3 2002-12-22 alex /* Unknown connections */
724 0c471b84 2002-11-30 alex cnt = Client_UnknownCount( );
725 0c471b84 2002-11-30 alex if( cnt > 0 )
727 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( Client, RPL_LUSERUNKNOWN_MSG, Client_ID( Client ), cnt )) return DISCONNECTED;
730 212d36a3 2002-12-22 alex /* Number of created channels */
731 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( Client, RPL_LUSERCHANNELS_MSG, Client_ID( Client ), Channel_Count( ))) return DISCONNECTED;
733 212d36a3 2002-12-22 alex /* Number of local users, services and servers */
734 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( Client, RPL_LUSERME_MSG, Client_ID( Client ), Client_MyUserCount( ), Client_MyServiceCount( ), Client_MyServerCount( ))) return DISCONNECTED;
736 212d36a3 2002-12-22 alex #ifndef STRICT_RFC
737 212d36a3 2002-12-22 alex /* Maximum number of local users */
738 212d36a3 2002-12-22 alex if( ! IRC_WriteStrClient( Client, RPL_LOCALUSERS_MSG, Client_ID( Client ), Client_MyUserCount( ), Client_MyMaxUserCount( ))) return DISCONNECTED;
739 212d36a3 2002-12-22 alex /* Maximum number of users in the network */
740 212d36a3 2002-12-22 alex if( ! IRC_WriteStrClient( Client, RPL_NETUSERS_MSG, Client_ID( Client ), Client_UserCount( ), Client_MaxUserCount( ))) return DISCONNECTED;
743 0c471b84 2002-11-30 alex return CONNECTED;
744 0c471b84 2002-11-30 alex } /* IRC_Send_LUSERS */
747 0c471b84 2002-11-30 alex GLOBAL BOOLEAN
748 0c471b84 2002-11-30 alex IRC_Show_MOTD( CLIENT *Client )
750 0c471b84 2002-11-30 alex BOOLEAN ok;
751 0c471b84 2002-11-30 alex CHAR line[127];
754 0c471b84 2002-11-30 alex assert( Client != NULL );
756 0c471b84 2002-11-30 alex fd = fopen( Conf_MotdFile, "r" );
759 0c471b84 2002-11-30 alex Log( LOG_WARNING, "Can't read MOTD file \"%s\": %s", Conf_MotdFile, strerror( errno ));
760 0c471b84 2002-11-30 alex return IRC_WriteStrClient( Client, ERR_NOMOTD_MSG, Client_ID( Client ) );
763 0c471b84 2002-11-30 alex IRC_WriteStrClient( Client, RPL_MOTDSTART_MSG, Client_ID( Client ), Client_ID( Client_ThisServer( )));
764 0c471b84 2002-11-30 alex while( TRUE )
766 0c471b84 2002-11-30 alex if( ! fgets( line, 126, fd )) break;
767 0c471b84 2002-11-30 alex if( line[strlen( line ) - 1] == '\n' ) line[strlen( line ) - 1] = '\0';
768 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( Client, RPL_MOTD_MSG, Client_ID( Client ), line ))
770 0c471b84 2002-11-30 alex fclose( fd );
771 0c471b84 2002-11-30 alex return FALSE;
774 0c471b84 2002-11-30 alex ok = IRC_WriteStrClient( Client, RPL_ENDOFMOTD_MSG, Client_ID( Client ) );
776 0c471b84 2002-11-30 alex fclose( fd );
779 0c471b84 2002-11-30 alex } /* IRC_Show_MOTD */
782 0c471b84 2002-11-30 alex GLOBAL BOOLEAN
783 0c471b84 2002-11-30 alex IRC_Send_NAMES( CLIENT *Client, CHANNEL *Chan )
785 0c471b84 2002-11-30 alex BOOLEAN is_visible, is_member;
786 0c471b84 2002-11-30 alex CHAR str[LINE_LEN + 1];
787 0c471b84 2002-11-30 alex CL2CHAN *cl2chan;
788 0c471b84 2002-11-30 alex CLIENT *cl;
790 0c471b84 2002-11-30 alex assert( Client != NULL );
791 0c471b84 2002-11-30 alex assert( Chan != NULL );
793 0c471b84 2002-11-30 alex if( Channel_IsMemberOf( Chan, Client )) is_member = TRUE;
794 0c471b84 2002-11-30 alex else is_member = FALSE;
796 0c471b84 2002-11-30 alex /* Alle Mitglieder suchen */
797 b316c380 2002-12-26 alex snprintf( str, sizeof( str ), RPL_NAMREPLY_MSG, Client_ID( Client ), "=", Channel_Name( Chan ));
798 0c471b84 2002-11-30 alex cl2chan = Channel_FirstMember( Chan );
799 0c471b84 2002-11-30 alex while( cl2chan )
801 0c471b84 2002-11-30 alex cl = Channel_GetClient( cl2chan );
803 0c471b84 2002-11-30 alex if( strchr( Client_Modes( cl ), 'i' )) is_visible = FALSE;
804 0c471b84 2002-11-30 alex else is_visible = TRUE;
806 0c471b84 2002-11-30 alex if( is_member || is_visible )
808 0c471b84 2002-11-30 alex /* Nick anhaengen */
809 6626395c 2002-12-26 alex if( str[strlen( str ) - 1] != ':' ) strlcat( str, " ", sizeof( str ));
810 6626395c 2002-12-26 alex if( strchr( Channel_UserModes( Chan, cl ), 'o' )) strlcat( str, "@", sizeof( str ));
811 6626395c 2002-12-26 alex else if( strchr( Channel_UserModes( Chan, cl ), 'v' )) strlcat( str, "+", sizeof( str ));
812 6626395c 2002-12-26 alex strlcat( str, Client_ID( cl ), sizeof( str ));
814 0c471b84 2002-11-30 alex if( strlen( str ) > ( LINE_LEN - CLIENT_NICK_LEN - 4 ))
816 0c471b84 2002-11-30 alex /* Zeile wird zu lang: senden! */
817 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( Client, "%s", str )) return DISCONNECTED;
818 b316c380 2002-12-26 alex snprintf( str, sizeof( str ), RPL_NAMREPLY_MSG, Client_ID( Client ), "=", Channel_Name( Chan ));
822 0c471b84 2002-11-30 alex /* naechstes Mitglied suchen */
823 0c471b84 2002-11-30 alex cl2chan = Channel_NextMember( Chan, cl2chan );
825 0c471b84 2002-11-30 alex if( str[strlen( str ) - 1] != ':')
827 0c471b84 2002-11-30 alex /* Es sind noch Daten da, die gesendet werden muessen */
828 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( Client, "%s", str )) return DISCONNECTED;
831 0c471b84 2002-11-30 alex return CONNECTED;
832 0c471b84 2002-11-30 alex } /* IRC_Send_NAMES */
835 0c471b84 2002-11-30 alex GLOBAL BOOLEAN
836 0c471b84 2002-11-30 alex IRC_Send_WHO( CLIENT *Client, CHANNEL *Chan, BOOLEAN OnlyOps )
838 0c471b84 2002-11-30 alex BOOLEAN is_visible, is_member;
839 0c471b84 2002-11-30 alex CL2CHAN *cl2chan;
840 0c471b84 2002-11-30 alex CHAR flags[8];
843 0c471b84 2002-11-30 alex assert( Client != NULL );
844 0c471b84 2002-11-30 alex assert( Chan != NULL );
846 0c471b84 2002-11-30 alex if( Channel_IsMemberOf( Chan, Client )) is_member = TRUE;
847 0c471b84 2002-11-30 alex else is_member = FALSE;
849 0c471b84 2002-11-30 alex /* Alle Mitglieder suchen */
850 0c471b84 2002-11-30 alex cl2chan = Channel_FirstMember( Chan );
851 0c471b84 2002-11-30 alex while( cl2chan )
853 0c471b84 2002-11-30 alex c = Channel_GetClient( cl2chan );
855 0c471b84 2002-11-30 alex if( strchr( Client_Modes( c ), 'i' )) is_visible = FALSE;
856 0c471b84 2002-11-30 alex else is_visible = TRUE;
858 0c471b84 2002-11-30 alex if( is_member || is_visible )
860 0c471b84 2002-11-30 alex /* Flags zusammenbasteln */
861 0c471b84 2002-11-30 alex strcpy( flags, "H" );
862 6626395c 2002-12-26 alex if( strchr( Client_Modes( c ), 'o' )) strlcat( flags, "*", sizeof( flags ));
863 6626395c 2002-12-26 alex if( strchr( Channel_UserModes( Chan, c ), 'o' )) strlcat( flags, "@", sizeof( flags ));
864 6626395c 2002-12-26 alex else if( strchr( Channel_UserModes( Chan, c ), 'v' )) strlcat( flags, "+", sizeof( flags ));
866 0c471b84 2002-11-30 alex /* ausgeben */
867 0c471b84 2002-11-30 alex if(( ! OnlyOps ) || ( strchr( Client_Modes( c ), 'o' )))
869 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;
873 0c471b84 2002-11-30 alex /* naechstes Mitglied suchen */
874 0c471b84 2002-11-30 alex cl2chan = Channel_NextMember( Chan, cl2chan );
876 0c471b84 2002-11-30 alex return CONNECTED;
877 0c471b84 2002-11-30 alex } /* IRC_Send_WHO */
880 0c471b84 2002-11-30 alex /* -eof- */