]> arthur.barton.de Git - ngircd-alex.git/blob - src/ngircd/irc.c
b638a90a69014a281ba876b01d578ea44be8cffa
[ngircd-alex.git] / src / ngircd / irc.c
1 /*
2  * ngIRCd -- The Next Generation IRC Daemon
3  * Copyright (c)2001,2002 by Alexander Barton (alex@barton.de)
4  *
5  * Dieses Programm ist freie Software. Sie koennen es unter den Bedingungen
6  * der GNU General Public License (GPL), wie von der Free Software Foundation
7  * herausgegeben, weitergeben und/oder modifizieren, entweder unter Version 2
8  * der Lizenz oder (wenn Sie es wuenschen) jeder spaeteren Version.
9  * Naehere Informationen entnehmen Sie bitter der Datei COPYING. Eine Liste
10  * der an ngIRCd beteiligten Autoren finden Sie in der Datei AUTHORS.
11  *
12  * $Id: irc.c,v 1.106 2002/12/12 11:40:41 alex Exp $
13  *
14  * irc.c: IRC-Befehle
15  */
16
17
18 #include "portab.h"
19
20 #include "imp.h"
21 #include <assert.h>
22 #include <stdio.h>
23 #include <string.h>
24
25 #include "conn.h"
26 #include "client.h"
27 #include "channel.h"
28 #include "defines.h"
29 #include "irc-write.h"
30 #include "log.h"
31 #include "messages.h"
32 #include "parse.h"
33
34 #include "exp.h"
35 #include "irc.h"
36
37
38 GLOBAL BOOLEAN
39 IRC_ERROR( CLIENT *Client, REQUEST *Req )
40 {
41         assert( Client != NULL );
42         assert( Req != NULL );
43
44         if( Req->argc < 1 ) Log( LOG_NOTICE, "Got ERROR from \"%s\"!", Client_Mask( Client ));
45         else Log( LOG_NOTICE, "Got ERROR from \"%s\": %s!", Client_Mask( Client ), Req->argv[0] );
46
47         return CONNECTED;
48 } /* IRC_ERROR */
49
50
51 GLOBAL BOOLEAN
52 IRC_KILL( CLIENT *Client, REQUEST *Req )
53 {
54         CLIENT *prefix, *c;
55         CHAR reason[COMMAND_LEN];
56
57         assert( Client != NULL );
58         assert( Req != NULL );
59
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 ));
62
63         /* Falsche Anzahl Parameter? */
64         if(( Req->argc != 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
65
66         if( Req->prefix ) prefix = Client_Search( Req->prefix );
67         else prefix = Client;
68         if( ! prefix )
69         {
70                 Log( LOG_WARNING, "Got KILL with invalid prefix: \"%s\"!", Req->prefix );
71                 prefix = Client_ThisServer( );
72         }
73
74         Log( LOG_NOTICE|LOG_snotice, "Got KILL command from \"%s\" for \"%s\": %s", Client_Mask( prefix ), Req->argv[0], Req->argv[1] );
75
76         /* build reason string */
77         if( Client_Type( Client ) == CLIENT_USER ) sprintf( reason, "KILLed by %s: %s", Client_ID( Client ), Req->argv[1] );
78         else strcpy( reason, Req->argv[1] );
79
80         /* andere Server benachrichtigen */
81         IRC_WriteStrServersPrefix( Client, prefix, "KILL %s :%s", Req->argv[0], reason );
82
83         /* haben wir selber einen solchen Client? */
84         c = Client_Search( Req->argv[0] );
85         if( c )
86         {
87                 /* Ja, wir haben einen solchen Client */
88                 if( Client_Conn( c ) != NONE ) Conn_Close( Client_Conn( c ), NULL, reason, TRUE );
89                 else Client_Destroy( c, NULL, reason, TRUE );
90         }
91         else Log( LOG_NOTICE, "Client with nick \"%s\" is unknown here.", Req->argv[0] );
92
93         return CONNECTED;
94 } /* IRC_KILL */
95
96
97 GLOBAL BOOLEAN
98 IRC_NOTICE( CLIENT *Client, REQUEST *Req )
99 {
100         CLIENT *to, *from;
101
102         assert( Client != NULL );
103         assert( Req != NULL );
104
105         if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return CONNECTED;
106
107         /* Falsche Anzahl Parameter? */
108         if( Req->argc != 2 ) return CONNECTED;
109
110         if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
111         else from = Client;
112         if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
113
114         to = Client_Search( Req->argv[0] );
115         if(( to ) && ( Client_Type( to ) == CLIENT_USER ))
116         {
117                 /* Okay, Ziel ist ein User */
118                 return IRC_WriteStrClientPrefix( to, from, "NOTICE %s :%s", Client_ID( to ), Req->argv[1] );
119         }
120         else return CONNECTED;
121 } /* IRC_NOTICE */
122
123
124 GLOBAL BOOLEAN
125 IRC_PRIVMSG( CLIENT *Client, REQUEST *Req )
126 {
127         CLIENT *cl, *from;
128         CHANNEL *chan;
129         
130         assert( Client != NULL );
131         assert( Req != NULL );
132
133         /* Falsche Anzahl Parameter? */
134         if( Req->argc == 0 ) return IRC_WriteStrClient( Client, ERR_NORECIPIENT_MSG, Client_ID( Client ), Req->command );
135         if( Req->argc == 1 ) return IRC_WriteStrClient( Client, ERR_NOTEXTTOSEND_MSG, Client_ID( Client ));
136         if( Req->argc > 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
137
138         if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
139         else from = Client;
140         if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
141
142         cl = Client_Search( Req->argv[0] );
143         if( cl )
144         {
145                 /* Okay, Ziel ist ein Client. Aber ist es auch ein User? */
146                 if( Client_Type( cl ) != CLIENT_USER ) return IRC_WriteStrClient( from, ERR_NOSUCHNICK_MSG, Client_ID( from ), Req->argv[0] );
147
148                 /* Okay, Ziel ist ein User */
149                 if(( Client_Type( Client ) != CLIENT_SERVER ) && ( strchr( Client_Modes( cl ), 'a' )))
150                 {
151                         /* Ziel-User ist AWAY: Meldung verschicken */
152                         if( ! IRC_WriteStrClient( from, RPL_AWAY_MSG, Client_ID( from ), Client_ID( cl ), Client_Away( cl ))) return DISCONNECTED;
153                 }
154
155                 /* Text senden */
156                 if( Client_Conn( from ) > NONE ) Conn_UpdateIdle( Client_Conn( from ));
157                 return IRC_WriteStrClientPrefix( cl, from, "PRIVMSG %s :%s", Client_ID( cl ), Req->argv[1] );
158         }
159
160         chan = Channel_Search( Req->argv[0] );
161         if( chan ) return Channel_Write( chan, from, Client, Req->argv[1] );
162
163         return IRC_WriteStrClient( from, ERR_NOSUCHNICK_MSG, Client_ID( from ), Req->argv[0] );
164 } /* IRC_PRIVMSG */
165
166
167 /* -eof- */