2 38b9cb88 2001-12-14 alex * ngIRCd -- The Next Generation IRC Daemon
3 03d971d9 2002-01-02 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 commands
15 ca33cbda 2002-03-12 alex #include "portab.h"
17 42c4e6c7 2003-01-13 alex static char UNUSED id[] = "$Id: irc.c,v 1.117 2003/01/13 18:56:30 alex Exp $";
19 ca33cbda 2002-03-12 alex #include "imp.h"
20 38b9cb88 2001-12-14 alex #include <assert.h>
21 44a2b3cf 2002-12-12 alex #include <stdio.h>
22 2a13cd22 2001-12-23 alex #include <string.h>
24 42c4e6c7 2003-01-13 alex #include "ngircd.h"
25 42c4e6c7 2003-01-13 alex #include "conn.h"
26 42c4e6c7 2003-01-13 alex #include "resolve.h"
27 42c4e6c7 2003-01-13 alex #include "conf.h"
28 b8d7dcec 2002-12-30 alex #include "conn-func.h"
29 2a13cd22 2001-12-23 alex #include "client.h"
30 c2f60abe 2002-05-27 alex #include "channel.h"
31 0c471b84 2002-11-30 alex #include "defines.h"
32 ef7f7a90 2002-02-27 alex #include "irc-write.h"
33 2a13cd22 2001-12-23 alex #include "log.h"
34 2a13cd22 2001-12-23 alex #include "messages.h"
35 c2f60abe 2002-05-27 alex #include "parse.h"
37 ca33cbda 2002-03-12 alex #include "exp.h"
38 38b9cb88 2001-12-14 alex #include "irc.h"
41 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
42 0c471b84 2002-11-30 alex IRC_ERROR( CLIENT *Client, REQUEST *Req )
44 bbfe9e8b 2001-12-25 alex assert( Client != NULL );
45 bbfe9e8b 2001-12-25 alex assert( Req != NULL );
47 0c471b84 2002-11-30 alex if( Req->argc < 1 ) Log( LOG_NOTICE, "Got ERROR from \"%s\"!", Client_Mask( Client ));
48 0c471b84 2002-11-30 alex else Log( LOG_NOTICE, "Got ERROR from \"%s\": %s!", Client_Mask( Client ), Req->argv[0] );
50 0c471b84 2002-11-30 alex return CONNECTED;
51 0c471b84 2002-11-30 alex } /* IRC_ERROR */
54 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
55 0c471b84 2002-11-30 alex IRC_KILL( CLIENT *Client, REQUEST *Req )
57 0c471b84 2002-11-30 alex CLIENT *prefix, *c;
58 b99af4fa 2002-12-06 alex CHAR reason[COMMAND_LEN];
59 01b58a05 2002-12-31 alex CONN_ID my_conn, conn;
61 72ebf4f2 2001-12-27 alex assert( Client != NULL );
62 72ebf4f2 2001-12-27 alex assert( Req != NULL );
64 4d2f279d 2002-12-26 alex /* Is the user an IRC operator? */
65 b99af4fa 2002-12-06 alex if(( Client_Type( Client ) != CLIENT_SERVER ) && ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
67 4d2f279d 2002-12-26 alex /* Bad number of parameters? */
68 0c471b84 2002-11-30 alex if(( Req->argc != 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
70 b99af4fa 2002-12-06 alex if( Req->prefix ) prefix = Client_Search( Req->prefix );
71 b99af4fa 2002-12-06 alex else prefix = Client;
72 0c471b84 2002-11-30 alex if( ! prefix )
74 0c471b84 2002-11-30 alex Log( LOG_WARNING, "Got KILL with invalid prefix: \"%s\"!", Req->prefix );
75 0c471b84 2002-11-30 alex prefix = Client_ThisServer( );
78 1443bc38 2003-01-08 alex if( Client != Client_ThisServer( )) Log( LOG_NOTICE|LOG_snotice, "Got KILL command from \"%s\" for \"%s\": %s", Client_Mask( prefix ), Req->argv[0], Req->argv[1] );
80 4d2f279d 2002-12-26 alex /* Build reason string */
81 b316c380 2002-12-26 alex if( Client_Type( Client ) == CLIENT_USER ) snprintf( reason, sizeof( reason ), "KILLed by %s: %s", Client_ID( Client ), Req->argv[1] );
82 695631b2 2002-12-26 alex else strlcpy( reason, Req->argv[1], sizeof( reason ));
84 4d2f279d 2002-12-26 alex /* Inform other servers */
85 b99af4fa 2002-12-06 alex IRC_WriteStrServersPrefix( Client, prefix, "KILL %s :%s", Req->argv[0], reason );
87 01b58a05 2002-12-31 alex /* Save ID of this connection */
88 01b58a05 2002-12-31 alex my_conn = Client_Conn( Client );
90 4d2f279d 2002-12-26 alex /* Do we host such a client? */
91 0c471b84 2002-11-30 alex c = Client_Search( Req->argv[0] );
94 01bec0da 2002-12-27 alex /* Yes, there is such a client -- but is it a valid user? */
95 8340e426 2002-12-27 alex if( Client_Type( c ) == CLIENT_SERVER ) IRC_WriteStrClient( Client, ERR_CANTKILLSERVER_MSG, Client_ID( Client ));
96 8340e426 2002-12-27 alex else if( Client_Type( c ) != CLIENT_USER )IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
99 01bec0da 2002-12-27 alex /* Kill user NOW! */
100 01bec0da 2002-12-27 alex conn = Client_Conn( c );
101 01bec0da 2002-12-27 alex Client_Destroy( c, NULL, reason, FALSE );
102 9d82635b 2003-01-08 alex if( conn != NONE ) Conn_Close( conn, NULL, reason, TRUE );
105 0c471b84 2002-11-30 alex else Log( LOG_NOTICE, "Client with nick \"%s\" is unknown here.", Req->argv[0] );
107 4d2f279d 2002-12-26 alex /* Are we still connected or were we killed, too? */
108 1443bc38 2003-01-08 alex if(( my_conn > NONE ) && ( Client_GetFromConn( my_conn ))) return CONNECTED;
109 4d2f279d 2002-12-26 alex else return DISCONNECTED;
110 0c471b84 2002-11-30 alex } /* IRC_KILL */
113 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
114 c2f60abe 2002-05-27 alex IRC_NOTICE( CLIENT *Client, REQUEST *Req )
116 db58d347 2002-01-05 alex CLIENT *to, *from;
118 72ebf4f2 2001-12-27 alex assert( Client != NULL );
119 72ebf4f2 2001-12-27 alex assert( Req != NULL );
121 1e83e666 2002-10-09 alex if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return CONNECTED;
123 72ebf4f2 2001-12-27 alex /* Falsche Anzahl Parameter? */
124 72ebf4f2 2001-12-27 alex if( Req->argc != 2 ) return CONNECTED;
126 c7408364 2002-03-25 alex if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
127 db58d347 2002-01-05 alex else from = Client;
128 c2ee5437 2002-01-11 alex if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
130 72ebf4f2 2001-12-27 alex to = Client_Search( Req->argv[0] );
131 9fd8254a 2002-06-11 alex if(( to ) && ( Client_Type( to ) == CLIENT_USER ))
133 72ebf4f2 2001-12-27 alex /* Okay, Ziel ist ein User */
134 db58d347 2002-01-05 alex return IRC_WriteStrClientPrefix( to, from, "NOTICE %s :%s", Client_ID( to ), Req->argv[1] );
136 db58d347 2002-01-05 alex else return CONNECTED;
137 72ebf4f2 2001-12-27 alex } /* IRC_NOTICE */
140 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
141 0c471b84 2002-11-30 alex IRC_PRIVMSG( CLIENT *Client, REQUEST *Req )
143 0c471b84 2002-11-30 alex CLIENT *cl, *from;
144 180095be 2002-02-27 alex CHANNEL *chan;
146 fb9d6ce1 2001-12-31 alex assert( Client != NULL );
147 fb9d6ce1 2001-12-31 alex assert( Req != NULL );
149 fb9d6ce1 2001-12-31 alex /* Falsche Anzahl Parameter? */
150 0c471b84 2002-11-30 alex if( Req->argc == 0 ) return IRC_WriteStrClient( Client, ERR_NORECIPIENT_MSG, Client_ID( Client ), Req->command );
151 0c471b84 2002-11-30 alex if( Req->argc == 1 ) return IRC_WriteStrClient( Client, ERR_NOTEXTTOSEND_MSG, Client_ID( Client ));
152 180095be 2002-02-27 alex if( Req->argc > 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
154 c7408364 2002-03-25 alex if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
155 180095be 2002-02-27 alex else from = Client;
156 0c471b84 2002-11-30 alex if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
158 0c471b84 2002-11-30 alex cl = Client_Search( Req->argv[0] );
161 0c471b84 2002-11-30 alex /* Okay, Ziel ist ein Client. Aber ist es auch ein User? */
162 0c471b84 2002-11-30 alex if( Client_Type( cl ) != CLIENT_USER ) return IRC_WriteStrClient( from, ERR_NOSUCHNICK_MSG, Client_ID( from ), Req->argv[0] );
164 0c471b84 2002-11-30 alex /* Okay, Ziel ist ein User */
165 0c471b84 2002-11-30 alex if(( Client_Type( Client ) != CLIENT_SERVER ) && ( strchr( Client_Modes( cl ), 'a' )))
167 0c471b84 2002-11-30 alex /* Ziel-User ist AWAY: Meldung verschicken */
168 0c471b84 2002-11-30 alex if( ! IRC_WriteStrClient( from, RPL_AWAY_MSG, Client_ID( from ), Client_ID( cl ), Client_Away( cl ))) return DISCONNECTED;
171 0c471b84 2002-11-30 alex /* Text senden */
172 0c471b84 2002-11-30 alex if( Client_Conn( from ) > NONE ) Conn_UpdateIdle( Client_Conn( from ));
173 0c471b84 2002-11-30 alex return IRC_WriteStrClientPrefix( cl, from, "PRIVMSG %s :%s", Client_ID( cl ), Req->argv[1] );
176 0c471b84 2002-11-30 alex chan = Channel_Search( Req->argv[0] );
177 0c471b84 2002-11-30 alex if( chan ) return Channel_Write( chan, from, Client, Req->argv[1] );
179 0c471b84 2002-11-30 alex return IRC_WriteStrClient( from, ERR_NOSUCHNICK_MSG, Client_ID( from ), Req->argv[0] );
180 0c471b84 2002-11-30 alex } /* IRC_PRIVMSG */
183 42c4e6c7 2003-01-13 alex GLOBAL BOOLEAN
184 42c4e6c7 2003-01-13 alex IRC_TRACE( CLIENT *Client, REQUEST *Req )
186 42c4e6c7 2003-01-13 alex CLIENT *from, *target;
187 42c4e6c7 2003-01-13 alex CONN_ID idx, idx2;
188 42c4e6c7 2003-01-13 alex CHAR ver[64], *ptr;
190 42c4e6c7 2003-01-13 alex assert( Client != NULL );
191 42c4e6c7 2003-01-13 alex assert( Req != NULL );
193 42c4e6c7 2003-01-13 alex /* Bad number of arguments? */
194 42c4e6c7 2003-01-13 alex if( Req->argc > 1 ) return IRC_WriteStrClient( Client, ERR_NORECIPIENT_MSG, Client_ID( Client ), Req->command );
196 42c4e6c7 2003-01-13 alex /* Search sender */
197 42c4e6c7 2003-01-13 alex if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
198 42c4e6c7 2003-01-13 alex else from = Client;
199 42c4e6c7 2003-01-13 alex if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
201 42c4e6c7 2003-01-13 alex /* Search target */
202 42c4e6c7 2003-01-13 alex if( Req->argc == 1 ) target = Client_Search( Req->argv[0] );
203 42c4e6c7 2003-01-13 alex else target = Client_ThisServer( );
205 42c4e6c7 2003-01-13 alex strlcpy( ver, NGIRCd_VersionAddition( ), sizeof( ver ));
206 42c4e6c7 2003-01-13 alex ptr = strchr( ver, '-' );
207 42c4e6c7 2003-01-13 alex if( ptr ) *ptr = '\0';
209 42c4e6c7 2003-01-13 alex /* Forward command to other server? */
210 42c4e6c7 2003-01-13 alex if( target != Client_ThisServer( ))
212 42c4e6c7 2003-01-13 alex if(( ! target ) || ( Client_Type( target ) != CLIENT_SERVER )) return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[0] );
214 42c4e6c7 2003-01-13 alex /* Send RPL_TRACELINK back to initiator */
215 42c4e6c7 2003-01-13 alex idx = Client_Conn( Client ); assert( idx > NONE );
216 42c4e6c7 2003-01-13 alex idx2 = Client_Conn( Client_NextHop( target )); assert( idx2 > NONE );
217 42c4e6c7 2003-01-13 alex if( ! IRC_WriteStrClient( from, RPL_TRACELINK_MSG, Client_ID( from ), PACKAGE, VERSION, Client_ID( target ), Client_ID( Client_NextHop( target )), ver, time( NULL ) - Conn_StartTime( idx ), Conn_SendQ( idx ), Conn_SendQ( idx2 ))) return DISCONNECTED;
219 42c4e6c7 2003-01-13 alex /* Forward command */
220 42c4e6c7 2003-01-13 alex IRC_WriteStrClientPrefix( target, from, "TRACE %s", Req->argv[0] );
221 42c4e6c7 2003-01-13 alex return CONNECTED;
224 42c4e6c7 2003-01-13 alex if( ! IRC_WriteStrClient( from, RPL_TRACESERVER_MSG, Client_ID( from ), Conf_ServerName, Client_Mask( Client_ThisServer( )), ver )) return DISCONNECTED;
225 42c4e6c7 2003-01-13 alex return IRC_WriteStrClient( from, RPL_TRACEEND_MSG, Client_ID( from ), Conf_ServerName, PACKAGE, VERSION, NGIRCd_DebugLevel );
226 42c4e6c7 2003-01-13 alex } /* IRC_TRACE */
229 38b9cb88 2001-12-14 alex /* -eof- */