Blame


1 ea9b72ef 2002-05-27 alex /*
2 ea9b72ef 2002-05-27 alex * ngIRCd -- The Next Generation IRC Daemon
3 aa25cd7d 2005-04-27 alex * Copyright (c)2001-2005 by Alexander Barton (alex@barton.de)
4 ea9b72ef 2002-05-27 alex *
5 490f28ff 2002-12-12 alex * This program is free software; you can redistribute it and/or modify
6 490f28ff 2002-12-12 alex * it under the terms of the GNU General Public License as published by
7 490f28ff 2002-12-12 alex * the Free Software Foundation; either version 2 of the License, or
8 490f28ff 2002-12-12 alex * (at your option) any later version.
9 490f28ff 2002-12-12 alex * Please read the file COPYING, README and AUTHORS for more information.
10 ea9b72ef 2002-05-27 alex *
11 490f28ff 2002-12-12 alex * Channel operator commands
12 ea9b72ef 2002-05-27 alex */
13 ea9b72ef 2002-05-27 alex
14 ea9b72ef 2002-05-27 alex
15 ea9b72ef 2002-05-27 alex #include "portab.h"
16 ea9b72ef 2002-05-27 alex
17 aa25cd7d 2005-04-27 alex static char UNUSED id[] = "$Id: irc-op.c,v 1.15 2005/04/27 07:39:18 alex Exp $";
18 490f28ff 2002-12-12 alex
19 ea9b72ef 2002-05-27 alex #include "imp.h"
20 ea9b72ef 2002-05-27 alex #include <assert.h>
21 ea9b72ef 2002-05-27 alex #include <string.h>
22 234f9472 2002-06-01 alex #include <stdio.h>
23 ea9b72ef 2002-05-27 alex
24 aa25cd7d 2005-04-27 alex #include "defines.h"
25 ea9b72ef 2002-05-27 alex #include "conn.h"
26 ea9b72ef 2002-05-27 alex #include "client.h"
27 ea9b72ef 2002-05-27 alex #include "channel.h"
28 ea9b72ef 2002-05-27 alex #include "irc-write.h"
29 adc1eedd 2002-06-02 alex #include "lists.h"
30 ea9b72ef 2002-05-27 alex #include "log.h"
31 ea9b72ef 2002-05-27 alex #include "messages.h"
32 ea9b72ef 2002-05-27 alex #include "parse.h"
33 ea9b72ef 2002-05-27 alex
34 ea9b72ef 2002-05-27 alex #include "exp.h"
35 ea9b72ef 2002-05-27 alex #include "irc-op.h"
36 ea9b72ef 2002-05-27 alex
37 ea9b72ef 2002-05-27 alex
38 8adff592 2005-03-19 fw GLOBAL bool
39 ea9b72ef 2002-05-27 alex IRC_KICK( CLIENT *Client, REQUEST *Req )
40 ea9b72ef 2002-05-27 alex {
41 234f9472 2002-06-01 alex CLIENT *target, *from;
42 234f9472 2002-06-01 alex
43 ea9b72ef 2002-05-27 alex assert( Client != NULL );
44 ea9b72ef 2002-05-27 alex assert( Req != NULL );
45 ea9b72ef 2002-05-27 alex
46 234f9472 2002-06-01 alex /* Falsche Anzahl Parameter? */
47 234f9472 2002-06-01 alex if(( Req->argc < 2) || ( Req->argc > 3 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
48 ea9b72ef 2002-05-27 alex
49 234f9472 2002-06-01 alex if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
50 234f9472 2002-06-01 alex else from = Client;
51 234f9472 2002-06-01 alex if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
52 234f9472 2002-06-01 alex
53 234f9472 2002-06-01 alex /* Ziel-User suchen */
54 234f9472 2002-06-01 alex target = Client_Search( Req->argv[1] );
55 234f9472 2002-06-01 alex if( ! target ) return IRC_WriteStrClient( from, ERR_NOSUCHNICK_MSG, Client_ID( from ), Req->argv[1] );
56 234f9472 2002-06-01 alex
57 234f9472 2002-06-01 alex Channel_Kick( target, from, Req->argv[0], Req->argc == 3 ? Req->argv[2] : Client_ID( from ));
58 ea9b72ef 2002-05-27 alex return CONNECTED;
59 ea9b72ef 2002-05-27 alex } /* IRC_KICK */
60 ea9b72ef 2002-05-27 alex
61 ea9b72ef 2002-05-27 alex
62 8adff592 2005-03-19 fw GLOBAL bool
63 ea9b72ef 2002-05-27 alex IRC_INVITE( CLIENT *Client, REQUEST *Req )
64 ea9b72ef 2002-05-27 alex {
65 adc1eedd 2002-06-02 alex CHANNEL *chan;
66 adc1eedd 2002-06-02 alex CLIENT *target, *from;
67 8adff592 2005-03-19 fw bool remember = false;
68 adc1eedd 2002-06-02 alex
69 ea9b72ef 2002-05-27 alex assert( Client != NULL );
70 ea9b72ef 2002-05-27 alex assert( Req != NULL );
71 ea9b72ef 2002-05-27 alex
72 ff2c1efa 2003-12-05 alex /* Wrong number of parameters? */
73 adc1eedd 2002-06-02 alex if( Req->argc != 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
74 ea9b72ef 2002-05-27 alex
75 adc1eedd 2002-06-02 alex if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
76 adc1eedd 2002-06-02 alex else from = Client;
77 adc1eedd 2002-06-02 alex if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
78 adc1eedd 2002-06-02 alex
79 ff2c1efa 2003-12-05 alex /* Search user */
80 adc1eedd 2002-06-02 alex target = Client_Search( Req->argv[0] );
81 151babd1 2002-06-11 alex if(( ! target ) || ( Client_Type( target ) != CLIENT_USER )) return IRC_WriteStrClient( from, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->argv[0] );
82 adc1eedd 2002-06-02 alex
83 adc1eedd 2002-06-02 alex chan = Channel_Search( Req->argv[1] );
84 adc1eedd 2002-06-02 alex
85 adc1eedd 2002-06-02 alex if( chan )
86 adc1eedd 2002-06-02 alex {
87 ff2c1efa 2003-12-05 alex /* Channel exists. Is the user a valid member of the channel? */
88 adc1eedd 2002-06-02 alex if( ! Channel_IsMemberOf( chan, from )) return IRC_WriteStrClient( from, ERR_NOTONCHANNEL_MSG, Client_ID( Client ), Req->argv[1] );
89 adc1eedd 2002-06-02 alex
90 ff2c1efa 2003-12-05 alex /* Is the channel "invite-only"? */
91 adc1eedd 2002-06-02 alex if( strchr( Channel_Modes( chan ), 'i' ))
92 adc1eedd 2002-06-02 alex {
93 ff2c1efa 2003-12-05 alex /* Yes. The user must be channel operator! */
94 adc1eedd 2002-06-02 alex if( ! strchr( Channel_UserModes( chan, from ), 'o' )) return IRC_WriteStrClient( from, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( from ), Channel_Name( chan ));
95 8adff592 2005-03-19 fw remember = true;
96 adc1eedd 2002-06-02 alex }
97 adc1eedd 2002-06-02 alex
98 ff2c1efa 2003-12-05 alex /* Is the target user already member of the channel? */
99 adc1eedd 2002-06-02 alex if( Channel_IsMemberOf( chan, target )) return IRC_WriteStrClient( from, ERR_USERONCHANNEL_MSG, Client_ID( from ), Req->argv[0], Req->argv[1] );
100 adc1eedd 2002-06-02 alex
101 ff2c1efa 2003-12-05 alex /* If the target user is banned on that channel: remember invite */
102 8adff592 2005-03-19 fw if( Lists_CheckBanned( target, chan )) remember = true;
103 ce4b7194 2002-09-08 alex
104 ff2c1efa 2003-12-05 alex if( remember )
105 ff2c1efa 2003-12-05 alex {
106 ff2c1efa 2003-12-05 alex /* We must memember this invite */
107 8adff592 2005-03-19 fw if( ! Lists_AddInvited( Client_Mask( target ), chan, true)) return CONNECTED;
108 ff2c1efa 2003-12-05 alex }
109 81a26d98 2002-07-15 alex }
110 ff2c1efa 2003-12-05 alex
111 ff2c1efa 2003-12-05 alex Log( LOG_DEBUG, "User \"%s\" invites \"%s\" to \"%s\" ...", Client_Mask( from ), Req->argv[0], Req->argv[1] );
112 b1f42006 2002-07-25 alex
113 ff2c1efa 2003-12-05 alex /* Inform target client */
114 adc1eedd 2002-06-02 alex IRC_WriteStrClientPrefix( target, from, "INVITE %s %s", Req->argv[0], Req->argv[1] );
115 adc1eedd 2002-06-02 alex
116 adc1eedd 2002-06-02 alex if( Client_Conn( target ) > NONE )
117 adc1eedd 2002-06-02 alex {
118 ff2c1efa 2003-12-05 alex /* The target user is local, so we have to send the status code */
119 b1f42006 2002-07-25 alex if( ! IRC_WriteStrClientPrefix( from, target, RPL_INVITING_MSG, Client_ID( from ), Req->argv[0], Req->argv[1] )) return DISCONNECTED;
120 adc1eedd 2002-06-02 alex }
121 adc1eedd 2002-06-02 alex
122 ea9b72ef 2002-05-27 alex return CONNECTED;
123 ea9b72ef 2002-05-27 alex } /* IRC_INVITE */
124 ea9b72ef 2002-05-27 alex
125 ea9b72ef 2002-05-27 alex
126 ea9b72ef 2002-05-27 alex /* -eof- */