IRC_INVITE: coding style cleanup.
[ngircd-alex.git] / src / ngircd / irc-op.c
1 /*
2  * ngIRCd -- The Next Generation IRC Daemon
3  * Copyright (c)2001-2005 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.17 2006/12/07 17:57:20 fw Exp $";
18
19 #include "imp.h"
20 #include <assert.h>
21 #include <string.h>
22 #include <stdio.h>
23
24 #include "defines.h"
25 #include "conn.h"
26 #include "client.h"
27 #include "channel.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 bool
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 bool
63 IRC_INVITE(CLIENT *Client, REQUEST *Req)
64 {
65         CHANNEL *chan;
66         CLIENT *target, *from;
67         bool remember = false;
68
69         assert( Client != NULL );
70         assert( Req != NULL );
71
72         if (Req->argc != 2)
73                 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
74                                         Client_ID(Client), Req->command);
75
76         if (Client_Type(Client) == CLIENT_SERVER)
77                 from = Client_Search(Req->prefix);
78         else
79                 from = Client;
80         if (!from)
81                 return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG,
82                                         Client_ID(Client), Req->prefix);
83
84         /* Search user */
85         target = Client_Search(Req->argv[0]);
86         if (!target || (Client_Type(target) != CLIENT_USER))
87                 return IRC_WriteStrClient(from, ERR_NOSUCHNICK_MSG,
88                                 Client_ID(Client), Req->argv[0]);
89
90         chan = Channel_Search(Req->argv[1]);
91         if (chan) {
92                 /* Channel exists. Is the user a valid member of the channel? */
93                 if (!Channel_IsMemberOf(chan, from))
94                         return IRC_WriteStrClient(from, ERR_NOTONCHANNEL_MSG, Client_ID(Client), Req->argv[1]);
95
96                 /* Is the channel "invite-only"? */
97                 if (strchr(Channel_Modes(chan), 'i')) {
98                         /* Yes. The user must be channel operator! */
99                         if (!strchr(Channel_UserModes(chan, from), 'o'))
100                                 return IRC_WriteStrClient(from, ERR_CHANOPRIVSNEEDED_MSG,
101                                                 Client_ID(from), Channel_Name(chan));
102                         remember = true;
103                 }
104
105                 /* Is the target user already member of the channel? */
106                 if (Channel_IsMemberOf(chan, target))
107                         return IRC_WriteStrClient(from, ERR_USERONCHANNEL_MSG,
108                                         Client_ID(from), Req->argv[0], Req->argv[1]);
109
110                 /* If the target user is banned on that channel: remember invite */
111                 if (Lists_Check(Channel_GetListBans(chan), target))
112                         remember = true;
113
114                 if (remember) {
115                         /* We must remember this invite */
116                         if (!Channel_AddInvite(chan, Client_Mask(target), true))
117                                 return CONNECTED;
118                 }
119         }
120
121         LogDebug("User \"%s\" invites \"%s\" to \"%s\" ...", Client_Mask(from), Req->argv[0], Req->argv[1]);
122
123         /* Inform target client */
124         IRC_WriteStrClientPrefix(target, from, "INVITE %s %s", Req->argv[0], Req->argv[1]);
125
126         if (Client_Conn(target) > NONE) {
127                 /* The target user is local, so we have to send the status code */
128                 if (!IRC_WriteStrClientPrefix(from, target, RPL_INVITING_MSG, Client_ID(from), Req->argv[0], Req->argv[1]))
129                         return DISCONNECTED;
130         }
131         return CONNECTED;
132 } /* IRC_INVITE */
133
134
135 /* -eof- */