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.107 2002/12/12 12:24:18 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];
56 assert( Client != NULL );
57 assert( Req != NULL );
59 /* is the user an IRC operator? */
60 if(( Client_Type( Client ) != CLIENT_SERVER ) && ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
62 /* Falsche Anzahl Parameter? */
63 if(( Req->argc != 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
65 if( Req->prefix ) prefix = Client_Search( Req->prefix );
69 Log( LOG_WARNING, "Got KILL with invalid prefix: \"%s\"!", Req->prefix );
70 prefix = Client_ThisServer( );
73 Log( LOG_NOTICE|LOG_snotice, "Got KILL command from \"%s\" for \"%s\": %s", Client_Mask( prefix ), Req->argv[0], Req->argv[1] );
75 /* build reason string */
76 if( Client_Type( Client ) == CLIENT_USER ) sprintf( reason, "KILLed by %s: %s", Client_ID( Client ), Req->argv[1] );
77 else strcpy( reason, Req->argv[1] );
79 /* andere Server benachrichtigen */
80 IRC_WriteStrServersPrefix( Client, prefix, "KILL %s :%s", Req->argv[0], reason );
82 /* haben wir selber einen solchen Client? */
83 c = Client_Search( Req->argv[0] );
86 /* Ja, wir haben einen solchen Client */
87 if( Client_Conn( c ) != NONE ) Conn_Close( Client_Conn( c ), NULL, reason, TRUE );
88 else Client_Destroy( c, NULL, reason, TRUE );
90 else Log( LOG_NOTICE, "Client with nick \"%s\" is unknown here.", Req->argv[0] );
97 IRC_NOTICE( CLIENT *Client, REQUEST *Req )
101 assert( Client != NULL );
102 assert( Req != NULL );
104 if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return CONNECTED;
106 /* Falsche Anzahl Parameter? */
107 if( Req->argc != 2 ) return CONNECTED;
109 if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
111 if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
113 to = Client_Search( Req->argv[0] );
114 if(( to ) && ( Client_Type( to ) == CLIENT_USER ))
116 /* Okay, Ziel ist ein User */
117 return IRC_WriteStrClientPrefix( to, from, "NOTICE %s :%s", Client_ID( to ), Req->argv[1] );
119 else return CONNECTED;
124 IRC_PRIVMSG( CLIENT *Client, REQUEST *Req )
129 assert( Client != NULL );
130 assert( Req != NULL );
132 /* Falsche Anzahl Parameter? */
133 if( Req->argc == 0 ) return IRC_WriteStrClient( Client, ERR_NORECIPIENT_MSG, Client_ID( Client ), Req->command );
134 if( Req->argc == 1 ) return IRC_WriteStrClient( Client, ERR_NOTEXTTOSEND_MSG, Client_ID( Client ));
135 if( Req->argc > 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
137 if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
139 if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
141 cl = Client_Search( Req->argv[0] );
144 /* Okay, Ziel ist ein Client. Aber ist es auch ein User? */
145 if( Client_Type( cl ) != CLIENT_USER ) return IRC_WriteStrClient( from, ERR_NOSUCHNICK_MSG, Client_ID( from ), Req->argv[0] );
147 /* Okay, Ziel ist ein User */
148 if(( Client_Type( Client ) != CLIENT_SERVER ) && ( strchr( Client_Modes( cl ), 'a' )))
150 /* Ziel-User ist AWAY: Meldung verschicken */
151 if( ! IRC_WriteStrClient( from, RPL_AWAY_MSG, Client_ID( from ), Client_ID( cl ), Client_Away( cl ))) return DISCONNECTED;
155 if( Client_Conn( from ) > NONE ) Conn_UpdateIdle( Client_Conn( from ));
156 return IRC_WriteStrClientPrefix( cl, from, "PRIVMSG %s :%s", Client_ID( cl ), Req->argv[1] );
159 chan = Channel_Search( Req->argv[0] );
160 if( chan ) return Channel_Write( chan, from, Client, Req->argv[1] );
162 return IRC_WriteStrClient( from, ERR_NOSUCHNICK_MSG, Client_ID( from ), Req->argv[0] );