2 * ngIRCd -- The Next Generation IRC Daemon
3 * Copyright (c)2001,2002 by Alexander Barton (alex@barton.de)
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 * Please read the file COPYING, README and AUTHORS for more information.
17 static char UNUSED id[] = "$Id: irc.c,v 1.115 2003/01/08 22:07:34 alex Exp $";
24 #include "conn-func.h"
28 #include "irc-write.h"
38 IRC_ERROR( CLIENT *Client, REQUEST *Req )
40 assert( Client != NULL );
41 assert( Req != NULL );
43 if( Req->argc < 1 ) Log( LOG_NOTICE, "Got ERROR from \"%s\"!", Client_Mask( Client ));
44 else Log( LOG_NOTICE, "Got ERROR from \"%s\": %s!", Client_Mask( Client ), Req->argv[0] );
51 IRC_KILL( CLIENT *Client, REQUEST *Req )
54 CHAR reason[COMMAND_LEN];
55 CONN_ID my_conn, conn;
57 assert( Client != NULL );
58 assert( Req != NULL );
60 /* Is the user an IRC operator? */
61 if(( Client_Type( Client ) != CLIENT_SERVER ) && ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
63 /* Bad number of parameters? */
64 if(( Req->argc != 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
66 if( Req->prefix ) prefix = Client_Search( Req->prefix );
70 Log( LOG_WARNING, "Got KILL with invalid prefix: \"%s\"!", Req->prefix );
71 prefix = Client_ThisServer( );
74 Log( LOG_NOTICE|LOG_snotice, "Got KILL command from \"%s\" for \"%s\": %s", Client_Mask( prefix ), Req->argv[0], Req->argv[1] );
76 /* Build reason string */
77 if( Client_Type( Client ) == CLIENT_USER ) snprintf( reason, sizeof( reason ), "KILLed by %s: %s", Client_ID( Client ), Req->argv[1] );
78 else strlcpy( reason, Req->argv[1], sizeof( reason ));
80 /* Inform other servers */
81 IRC_WriteStrServersPrefix( Client, prefix, "KILL %s :%s", Req->argv[0], reason );
83 /* Save ID of this connection */
84 my_conn = Client_Conn( Client );
86 /* Do we host such a client? */
87 c = Client_Search( Req->argv[0] );
90 /* Yes, there is such a client -- but is it a valid user? */
91 if( Client_Type( c ) == CLIENT_SERVER ) IRC_WriteStrClient( Client, ERR_CANTKILLSERVER_MSG, Client_ID( Client ));
92 else if( Client_Type( c ) != CLIENT_USER )IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
96 conn = Client_Conn( c );
97 Client_Destroy( c, NULL, reason, FALSE );
98 if( conn != NONE ) Conn_Close( conn, NULL, reason, TRUE );
101 else Log( LOG_NOTICE, "Client with nick \"%s\" is unknown here.", Req->argv[0] );
103 /* Are we still connected or were we killed, too? */
104 if( Client_GetFromConn( my_conn )) return CONNECTED;
105 else return DISCONNECTED;
110 IRC_NOTICE( CLIENT *Client, REQUEST *Req )
114 assert( Client != NULL );
115 assert( Req != NULL );
117 if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return CONNECTED;
119 /* Falsche Anzahl Parameter? */
120 if( Req->argc != 2 ) return CONNECTED;
122 if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
124 if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
126 to = Client_Search( Req->argv[0] );
127 if(( to ) && ( Client_Type( to ) == CLIENT_USER ))
129 /* Okay, Ziel ist ein User */
130 return IRC_WriteStrClientPrefix( to, from, "NOTICE %s :%s", Client_ID( to ), Req->argv[1] );
132 else return CONNECTED;
137 IRC_PRIVMSG( CLIENT *Client, REQUEST *Req )
142 assert( Client != NULL );
143 assert( Req != NULL );
145 /* Falsche Anzahl Parameter? */
146 if( Req->argc == 0 ) return IRC_WriteStrClient( Client, ERR_NORECIPIENT_MSG, Client_ID( Client ), Req->command );
147 if( Req->argc == 1 ) return IRC_WriteStrClient( Client, ERR_NOTEXTTOSEND_MSG, Client_ID( Client ));
148 if( Req->argc > 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
150 if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
152 if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
154 cl = Client_Search( Req->argv[0] );
157 /* Okay, Ziel ist ein Client. Aber ist es auch ein User? */
158 if( Client_Type( cl ) != CLIENT_USER ) return IRC_WriteStrClient( from, ERR_NOSUCHNICK_MSG, Client_ID( from ), Req->argv[0] );
160 /* Okay, Ziel ist ein User */
161 if(( Client_Type( Client ) != CLIENT_SERVER ) && ( strchr( Client_Modes( cl ), 'a' )))
163 /* Ziel-User ist AWAY: Meldung verschicken */
164 if( ! IRC_WriteStrClient( from, RPL_AWAY_MSG, Client_ID( from ), Client_ID( cl ), Client_Away( cl ))) return DISCONNECTED;
168 if( Client_Conn( from ) > NONE ) Conn_UpdateIdle( Client_Conn( from ));
169 return IRC_WriteStrClientPrefix( cl, from, "PRIVMSG %s :%s", Client_ID( cl ), Req->argv[1] );
172 chan = Channel_Search( Req->argv[0] );
173 if( chan ) return Channel_Write( chan, from, Client, Req->argv[1] );
175 return IRC_WriteStrClient( from, ERR_NOSUCHNICK_MSG, Client_ID( from ), Req->argv[0] );