]> arthur.barton.de Git - ngircd-alex.git/blob - src/ngircd/irc.c
- neues Source-Modul "irc-info"; neuer Befehl STATS.
[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.104 2002/11/30 17:39:56 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 <string.h>
23
24 #include "conn.h"
25 #include "client.h"
26 #include "channel.h"
27 #include "defines.h"
28 #include "irc-write.h"
29 #include "log.h"
30 #include "messages.h"
31 #include "parse.h"
32
33 #include "exp.h"
34 #include "irc.h"
35
36
37 GLOBAL BOOLEAN
38 IRC_ERROR( CLIENT *Client, REQUEST *Req )
39 {
40         assert( Client != NULL );
41         assert( Req != NULL );
42
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] );
45
46         return CONNECTED;
47 } /* IRC_ERROR */
48
49
50 GLOBAL BOOLEAN
51 IRC_KILL( CLIENT *Client, REQUEST *Req )
52 {
53         CLIENT *prefix, *c;
54
55         assert( Client != NULL );
56         assert( Req != NULL );
57
58         /* Falsche Anzahl Parameter? */
59         if(( Req->argc != 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
60
61         prefix = Client_Search( Req->prefix );
62         if( ! prefix )
63         {
64                 Log( LOG_WARNING, "Got KILL with invalid prefix: \"%s\"!", Req->prefix );
65                 prefix = Client_ThisServer( );
66         }
67
68         Log( LOG_NOTICE, "Got KILL command from \"%s\" for \"%s\": %s", Client_Mask( prefix ), Req->argv[0], Req->argv[1] );
69
70         /* andere Server benachrichtigen */
71         IRC_WriteStrServersPrefix( Client, prefix, "KILL %s :%s", Req->argv[0], Req->argv[1] );
72
73         /* haben wir selber einen solchen Client? */
74         c = Client_Search( Req->argv[0] );
75         if( c )
76         {
77                 /* Ja, wir haben einen solchen Client */
78                 if( Client_Conn( c ) != NONE ) Conn_Close( Client_Conn( c ), NULL, Req->argv[1], TRUE );
79                 else Client_Destroy( c, NULL, Req->argv[1], TRUE );
80         }
81         else Log( LOG_NOTICE, "Client with nick \"%s\" is unknown here.", Req->argv[0] );
82
83         return CONNECTED;
84 } /* IRC_KILL */
85
86
87 GLOBAL BOOLEAN
88 IRC_NOTICE( CLIENT *Client, REQUEST *Req )
89 {
90         CLIENT *to, *from;
91
92         assert( Client != NULL );
93         assert( Req != NULL );
94
95         if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return CONNECTED;
96
97         /* Falsche Anzahl Parameter? */
98         if( Req->argc != 2 ) return CONNECTED;
99
100         if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
101         else from = Client;
102         if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
103
104         to = Client_Search( Req->argv[0] );
105         if(( to ) && ( Client_Type( to ) == CLIENT_USER ))
106         {
107                 /* Okay, Ziel ist ein User */
108                 return IRC_WriteStrClientPrefix( to, from, "NOTICE %s :%s", Client_ID( to ), Req->argv[1] );
109         }
110         else return CONNECTED;
111 } /* IRC_NOTICE */
112
113
114 GLOBAL BOOLEAN
115 IRC_PRIVMSG( CLIENT *Client, REQUEST *Req )
116 {
117         CLIENT *cl, *from;
118         CHANNEL *chan;
119         
120         assert( Client != NULL );
121         assert( Req != NULL );
122
123         /* Falsche Anzahl Parameter? */
124         if( Req->argc == 0 ) return IRC_WriteStrClient( Client, ERR_NORECIPIENT_MSG, Client_ID( Client ), Req->command );
125         if( Req->argc == 1 ) return IRC_WriteStrClient( Client, ERR_NOTEXTTOSEND_MSG, Client_ID( Client ));
126         if( Req->argc > 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
127
128         if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
129         else from = Client;
130         if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
131
132         cl = Client_Search( Req->argv[0] );
133         if( cl )
134         {
135                 /* Okay, Ziel ist ein Client. Aber ist es auch ein User? */
136                 if( Client_Type( cl ) != CLIENT_USER ) return IRC_WriteStrClient( from, ERR_NOSUCHNICK_MSG, Client_ID( from ), Req->argv[0] );
137
138                 /* Okay, Ziel ist ein User */
139                 if(( Client_Type( Client ) != CLIENT_SERVER ) && ( strchr( Client_Modes( cl ), 'a' )))
140                 {
141                         /* Ziel-User ist AWAY: Meldung verschicken */
142                         if( ! IRC_WriteStrClient( from, RPL_AWAY_MSG, Client_ID( from ), Client_ID( cl ), Client_Away( cl ))) return DISCONNECTED;
143                 }
144
145                 /* Text senden */
146                 if( Client_Conn( from ) > NONE ) Conn_UpdateIdle( Client_Conn( from ));
147                 return IRC_WriteStrClientPrefix( cl, from, "PRIVMSG %s :%s", Client_ID( cl ), Req->argv[1] );
148         }
149
150         chan = Channel_Search( Req->argv[0] );
151         if( chan ) return Channel_Write( chan, from, Client, Req->argv[1] );
152
153         return IRC_WriteStrClient( from, ERR_NOSUCHNICK_MSG, Client_ID( from ), Req->argv[0] );
154 } /* IRC_PRIVMSG */
155
156
157 /* -eof- */