2 * ngIRCd -- The Next Generation IRC Daemon
3 * Copyright (c)2001-2013 Alexander Barton (alex@barton.de) and Contributors.
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.
16 * Channel operator commands
27 #include "irc-write.h"
39 try_kick(CLIENT *peer, CLIENT* from, const char *nick, const char *channel,
42 CLIENT *target = Client_Search(nick);
45 return IRC_WriteStrClient(from, ERR_NOSUCHNICK_MSG, Client_ID(from), nick);
47 Channel_Kick(peer, target, from, channel, reason);
51 /* Global functions */
54 * Handler for the IRC command "KICK".
56 * @param Client The client from which this command has been received.
57 * @param Req Request structure with prefix and all parameters.
58 * @return CONNECTED or DISCONNECTED.
61 IRC_KICK(CLIENT *Client, REQUEST *Req)
64 char *itemList = Req->argv[0];
65 const char* currentNick, *currentChannel, *reason;
66 unsigned int channelCount = 1;
67 unsigned int nickCount = 1;
69 assert( Client != NULL );
70 assert( Req != NULL );
72 if ((Req->argc < 2) || (Req->argc > 3))
73 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
74 Client_ID(Client), Req->command);
77 if (*itemList == ',') {
84 itemList = Req->argv[1];
86 if (*itemList == ',') {
93 if (Client_Type(Client) == CLIENT_SERVER)
94 from = Client_Search(Req->prefix);
99 return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG,
100 Client_ID(Client), Req->prefix);
102 reason = Req->argc == 3 ? Req->argv[2] : Client_ID(from);
103 currentNick = Req->argv[1];
104 currentChannel = Req->argv[0];
105 if (channelCount == 1) {
106 while (nickCount > 0) {
107 if (!try_kick(Client, from, currentNick,
108 currentChannel, reason))
117 } else if (channelCount == nickCount) {
118 while (nickCount > 0) {
119 if (!try_kick(Client, from, currentNick,
120 currentChannel, reason))
126 while (*currentChannel)
134 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
135 Client_ID(Client), Req->command);
141 * Handler for the IRC command "INVITE".
143 * @param Client The client from which this command has been received.
144 * @param Req Request structure with prefix and all parameters.
145 * @return CONNECTED or DISCONNECTED.
148 IRC_INVITE(CLIENT *Client, REQUEST *Req)
151 CLIENT *target, *from;
152 const char *colon_if_necessary;
153 bool remember = false;
155 assert( Client != NULL );
156 assert( Req != NULL );
159 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
160 Client_ID(Client), Req->command);
162 if (Client_Type(Client) == CLIENT_SERVER)
163 from = Client_Search(Req->prefix);
167 return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG,
168 Client_ID(Client), Req->prefix);
171 target = Client_Search(Req->argv[0]);
172 if (!target || (Client_Type(target) != CLIENT_USER))
173 return IRC_WriteStrClient(from, ERR_NOSUCHNICK_MSG,
174 Client_ID(Client), Req->argv[0]);
176 chan = Channel_Search(Req->argv[1]);
178 /* Channel exists. Is the user a valid member of the channel? */
179 if (!Channel_IsMemberOf(chan, from))
180 return IRC_WriteStrClient(from, ERR_NOTONCHANNEL_MSG, Client_ID(Client), Req->argv[1]);
182 /* Is the channel "invite-disallow"? */
183 if (strchr(Channel_Modes(chan), 'V'))
184 return IRC_WriteStrClient(from, ERR_NOINVITE_MSG,
185 Client_ID(from), Channel_Name(chan));
187 /* Is the channel "invite-only"? */
188 if (strchr(Channel_Modes(chan), 'i')) {
189 /* Yes. The user must be channel owner/admin/operator/halfop! */
190 if (!strchr(Channel_UserModes(chan, from), 'q') &&
191 !strchr(Channel_UserModes(chan, from), 'a') &&
192 !strchr(Channel_UserModes(chan, from), 'o') &&
193 !strchr(Channel_UserModes(chan, from), 'h'))
194 return IRC_WriteStrClient(from, ERR_CHANOPRIVSNEEDED_MSG,
195 Client_ID(from), Channel_Name(chan));
199 /* Is the target user already member of the channel? */
200 if (Channel_IsMemberOf(chan, target))
201 return IRC_WriteStrClient(from, ERR_USERONCHANNEL_MSG,
202 Client_ID(from), Req->argv[0], Req->argv[1]);
204 /* If the target user is banned on that channel: remember invite */
205 if (Lists_Check(Channel_GetListBans(chan), target))
209 /* We must remember this invite */
210 if (!Channel_AddInvite(chan, Client_Mask(target), true))
215 LogDebug("User \"%s\" invites \"%s\" to \"%s\" ...", Client_Mask(from),
216 Req->argv[0], Req->argv[1]);
220 * 'There is no requirement that the channel [..] must exist or be a valid channel'
221 * The problem with this is that this allows the "channel" to contain spaces,
222 * in which case we must prefix its name with a colon to make it clear that
223 * it is only a single argument.
225 colon_if_necessary = strchr(Req->argv[1], ' ') ? ":":"";
226 /* Inform target client */
227 IRC_WriteStrClientPrefix(target, from, "INVITE %s %s%s", Req->argv[0],
228 colon_if_necessary, Req->argv[1]);
230 if (Client_Conn(target) > NONE) {
231 /* The target user is local, so we have to send the status code */
232 if (!IRC_WriteStrClientPrefix(from, target, RPL_INVITING_MSG,
233 Client_ID(from), Req->argv[0], colon_if_necessary, Req->argv[1]))
236 if (strchr(Client_Modes(target), 'a') &&
237 !IRC_WriteStrClient(from, RPL_AWAY_MSG, Client_ID(from),
238 Client_ID(target), Client_Away(target)))