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.110 2002/12/26 18:41:00 alex Exp $";
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];
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 /* Do we host such a client? */
84 c = Client_Search( Req->argv[0] );
87 /* Ja, wir haben einen solchen Client */
88 conn = Client_Conn( c );
89 Client_Destroy( c, NULL, reason, FALSE );
90 if( conn != NONE ) Conn_Close( Client_Conn( c ), NULL, reason, TRUE );
92 else Log( LOG_NOTICE, "Client with nick \"%s\" is unknown here.", Req->argv[0] );
94 /* Are we still connected or were we killed, too? */
95 if( Client_Search( Req->argv[0] )) return CONNECTED;
96 else return DISCONNECTED;
101 IRC_NOTICE( CLIENT *Client, REQUEST *Req )
105 assert( Client != NULL );
106 assert( Req != NULL );
108 if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return CONNECTED;
110 /* Falsche Anzahl Parameter? */
111 if( Req->argc != 2 ) return CONNECTED;
113 if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
115 if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
117 to = Client_Search( Req->argv[0] );
118 if(( to ) && ( Client_Type( to ) == CLIENT_USER ))
120 /* Okay, Ziel ist ein User */
121 return IRC_WriteStrClientPrefix( to, from, "NOTICE %s :%s", Client_ID( to ), Req->argv[1] );
123 else return CONNECTED;
128 IRC_PRIVMSG( CLIENT *Client, REQUEST *Req )
133 assert( Client != NULL );
134 assert( Req != NULL );
136 /* Falsche Anzahl Parameter? */
137 if( Req->argc == 0 ) return IRC_WriteStrClient( Client, ERR_NORECIPIENT_MSG, Client_ID( Client ), Req->command );
138 if( Req->argc == 1 ) return IRC_WriteStrClient( Client, ERR_NOTEXTTOSEND_MSG, Client_ID( Client ));
139 if( Req->argc > 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
141 if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
143 if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
145 cl = Client_Search( Req->argv[0] );
148 /* Okay, Ziel ist ein Client. Aber ist es auch ein User? */
149 if( Client_Type( cl ) != CLIENT_USER ) return IRC_WriteStrClient( from, ERR_NOSUCHNICK_MSG, Client_ID( from ), Req->argv[0] );
151 /* Okay, Ziel ist ein User */
152 if(( Client_Type( Client ) != CLIENT_SERVER ) && ( strchr( Client_Modes( cl ), 'a' )))
154 /* Ziel-User ist AWAY: Meldung verschicken */
155 if( ! IRC_WriteStrClient( from, RPL_AWAY_MSG, Client_ID( from ), Client_ID( cl ), Client_Away( cl ))) return DISCONNECTED;
159 if( Client_Conn( from ) > NONE ) Conn_UpdateIdle( Client_Conn( from ));
160 return IRC_WriteStrClientPrefix( cl, from, "PRIVMSG %s :%s", Client_ID( cl ), Req->argv[1] );
163 chan = Channel_Search( Req->argv[0] );
164 if( chan ) return Channel_Write( chan, from, Client, Req->argv[1] );
166 return IRC_WriteStrClient( from, ERR_NOSUCHNICK_MSG, Client_ID( from ), Req->argv[0] );