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-macros.h"
28 #include "irc-write.h"
40 try_kick(CLIENT *peer, CLIENT* from, const char *nick, const char *channel,
43 CLIENT *target = Client_Search(nick);
46 return IRC_WriteErrClient(from, ERR_NOSUCHNICK_MSG,
47 Client_ID(from), nick);
49 Channel_Kick(peer, target, from, channel, reason);
53 /* Global functions */
56 * Handler for the IRC command "KICK".
58 * @param Client The client from which this command has been received.
59 * @param Req Request structure with prefix and all parameters.
60 * @return CONNECTED or DISCONNECTED.
63 IRC_KICK(CLIENT *Client, REQUEST *Req)
66 char *itemList = Req->argv[0];
67 const char* currentNick, *currentChannel, *reason;
68 unsigned int channelCount = 1;
69 unsigned int nickCount = 1;
71 assert( Client != NULL );
72 assert( Req != NULL );
74 _IRC_GET_SENDER_OR_RETURN_(from, Req, Client)
77 if (*itemList == ',') {
84 itemList = Req->argv[1];
86 if (*itemList == ',') {
93 reason = Req->argc == 3 ? Req->argv[2] : Client_ID(from);
94 currentNick = Req->argv[1];
95 currentChannel = Req->argv[0];
96 if (channelCount == 1) {
97 while (nickCount > 0) {
98 if (!try_kick(Client, from, currentNick,
99 currentChannel, reason))
108 } else if (channelCount == nickCount) {
109 while (nickCount > 0) {
110 if (!try_kick(Client, from, currentNick,
111 currentChannel, reason))
117 while (*currentChannel)
125 return IRC_WriteErrClient(Client, ERR_NEEDMOREPARAMS_MSG,
126 Client_ID(Client), Req->command);
132 * Handler for the IRC command "INVITE".
134 * @param Client The client from which this command has been received.
135 * @param Req Request structure with prefix and all parameters.
136 * @return CONNECTED or DISCONNECTED.
139 IRC_INVITE(CLIENT *Client, REQUEST *Req)
142 CLIENT *target, *from;
143 const char *colon_if_necessary;
144 bool remember = false;
146 assert( Client != NULL );
147 assert( Req != NULL );
149 _IRC_GET_SENDER_OR_RETURN_(from, Req, Client)
152 target = Client_Search(Req->argv[0]);
153 if (!target || (Client_Type(target) != CLIENT_USER))
154 return IRC_WriteErrClient(from, ERR_NOSUCHNICK_MSG,
155 Client_ID(Client), Req->argv[0]);
157 chan = Channel_Search(Req->argv[1]);
159 /* Channel exists. Is the user a valid member of the channel? */
160 if (!Channel_IsMemberOf(chan, from))
161 return IRC_WriteErrClient(from, ERR_NOTONCHANNEL_MSG,
165 /* Is the channel "invite-disallow"? */
166 if (Channel_HasMode(chan, 'V'))
167 return IRC_WriteErrClient(from, ERR_NOINVITE_MSG,
171 /* Is the channel "invite-only"? */
172 if (Channel_HasMode(chan, 'i')) {
173 /* Yes. The user issuing the INVITE command must be
174 * channel owner/admin/operator/halfop! */
175 if (!Channel_UserHasMode(chan, from, 'q') &&
176 !Channel_UserHasMode(chan, from, 'a') &&
177 !Channel_UserHasMode(chan, from, 'o') &&
178 !Channel_UserHasMode(chan, from, 'h'))
179 return IRC_WriteErrClient(from,
180 ERR_CHANOPRIVSNEEDED_MSG,
186 /* Is the target user already member of the channel? */
187 if (Channel_IsMemberOf(chan, target))
188 return IRC_WriteErrClient(from, ERR_USERONCHANNEL_MSG,
190 Req->argv[0], Req->argv[1]);
192 /* If the target user is banned on that channel: remember invite */
193 if (Lists_Check(Channel_GetListBans(chan), target))
197 /* We must remember this invite */
198 if (!Channel_AddInvite(chan, Client_MaskCloaked(target),
204 LogDebug("User \"%s\" invites \"%s\" to \"%s\" ...", Client_Mask(from),
205 Req->argv[0], Req->argv[1]);
209 * 'There is no requirement that the channel [..] must exist or be a
210 * valid channel'. The problem with this is that this allows the
211 * "channel" to contain spaces, in which case we must prefix its name
212 * with a colon to make it clear that it is only a single argument.
214 colon_if_necessary = strchr(Req->argv[1], ' ') ? ":":"";
215 /* Inform target client */
216 IRC_WriteStrClientPrefix(target, from, "INVITE %s %s%s", Req->argv[0],
217 colon_if_necessary, Req->argv[1]);
219 if (Client_Conn(target) > NONE) {
220 /* The target user is local, so we have to send the status code */
221 if (!IRC_WriteStrClientPrefix(from, target, RPL_INVITING_MSG,
222 Client_ID(from), Req->argv[0],
223 colon_if_necessary, Req->argv[1]))
226 if (Client_HasMode(target, 'a') &&
227 !IRC_WriteStrClient(from, RPL_AWAY_MSG, Client_ID(from),
228 Client_ID(target), Client_Away(target)))