]> arthur.barton.de Git - ngircd-alex.git/blob - src/ngircd/irc-op.c
Fixed handling of already existent entries in invite and ban lists:
[ngircd-alex.git] / src / ngircd / irc-op.c
1 /*
2  * ngIRCd -- The Next Generation IRC Daemon
3  * Copyright (c)2001-2003 by Alexander Barton (alex@barton.de)
4  *
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.
10  *
11  * Channel operator commands
12  */
13
14
15 #include "portab.h"
16
17 static char UNUSED id[] = "$Id: irc-op.c,v 1.13 2004/04/09 21:41:52 alex Exp $";
18
19 #include "imp.h"
20 #include <assert.h>
21 #include <string.h>
22 #include <stdio.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 "lists.h"
30 #include "log.h"
31 #include "messages.h"
32 #include "parse.h"
33
34 #include "exp.h"
35 #include "irc-op.h"
36
37
38 GLOBAL BOOLEAN
39 IRC_KICK( CLIENT *Client, REQUEST *Req )
40 {
41         CLIENT *target, *from;
42         
43         assert( Client != NULL );
44         assert( Req != NULL );
45
46         /* Falsche Anzahl Parameter? */
47         if(( Req->argc < 2) || ( Req->argc > 3 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
48
49         if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
50         else from = Client;
51         if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
52         
53         /* Ziel-User suchen */
54         target = Client_Search( Req->argv[1] );
55         if( ! target ) return IRC_WriteStrClient( from, ERR_NOSUCHNICK_MSG, Client_ID( from ), Req->argv[1] );
56
57         Channel_Kick( target, from, Req->argv[0], Req->argc == 3 ? Req->argv[2] : Client_ID( from ));
58         return CONNECTED;
59 } /* IRC_KICK */        
60
61
62 GLOBAL BOOLEAN
63 IRC_INVITE( CLIENT *Client, REQUEST *Req )
64 {
65         CHANNEL *chan;
66         CLIENT *target, *from;
67         BOOLEAN remember = FALSE;
68
69         assert( Client != NULL );
70         assert( Req != NULL );
71
72         /* Wrong number of parameters? */
73         if( Req->argc != 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
74
75         if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
76         else from = Client;
77         if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
78         
79         /* Search user */
80         target = Client_Search( Req->argv[0] );
81         if(( ! target ) || ( Client_Type( target ) != CLIENT_USER )) return IRC_WriteStrClient( from, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->argv[0] );
82
83         chan = Channel_Search( Req->argv[1] );
84
85         if( chan )
86         {
87                 /* Channel exists. Is the user a valid member of the channel? */
88                 if( ! Channel_IsMemberOf( chan, from )) return IRC_WriteStrClient( from, ERR_NOTONCHANNEL_MSG, Client_ID( Client ), Req->argv[1] );
89
90                 /* Is the channel "invite-only"? */
91                 if( strchr( Channel_Modes( chan ), 'i' ))
92                 {
93                         /* Yes. The user must be channel operator! */
94                         if( ! strchr( Channel_UserModes( chan, from ), 'o' )) return IRC_WriteStrClient( from, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( from ), Channel_Name( chan ));
95                         remember = TRUE;
96                 }
97
98                 /* Is the target user already member of the channel? */
99                 if( Channel_IsMemberOf( chan, target )) return IRC_WriteStrClient( from, ERR_USERONCHANNEL_MSG, Client_ID( from ), Req->argv[0], Req->argv[1] );
100
101                 /* If the target user is banned on that channel: remember invite */
102                 if( Lists_CheckBanned( target, chan )) remember = TRUE;
103
104                 if( remember )
105                 {
106                         /* We must memember this invite */
107                         if( ! Lists_AddInvited( Client_Mask( target ), chan, TRUE )) return CONNECTED;
108                 }
109         }
110
111         Log( LOG_DEBUG, "User \"%s\" invites \"%s\" to \"%s\" ...", Client_Mask( from ), Req->argv[0], Req->argv[1] );
112         
113         /* Inform target client */
114         IRC_WriteStrClientPrefix( target, from, "INVITE %s %s", Req->argv[0], Req->argv[1] );
115
116         if( Client_Conn( target ) > NONE )
117         {
118                 /* The target user is local, so we have to send the status code */
119                 if( ! IRC_WriteStrClientPrefix( from, target, RPL_INVITING_MSG, Client_ID( from ), Req->argv[0], Req->argv[1] )) return DISCONNECTED;
120         }
121         
122         return CONNECTED;
123 } /* IRC_INVITE */
124
125
126 /* -eof- */