2 * ngIRCd -- The Next Generation IRC Daemon
3 * Copyright (c)2001-2005 by Alexander Barton (alex@barton.de)
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.
17 * Channel operator commands
28 #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);
53 IRC_KICK(CLIENT *Client, REQUEST *Req)
56 char *itemList = Req->argv[0];
57 const char* currentNick, *currentChannel, *reason;
58 unsigned int channelCount = 1;
59 unsigned int nickCount = 1;
61 assert( Client != NULL );
62 assert( Req != NULL );
64 if ((Req->argc < 2) || (Req->argc > 3))
65 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
66 Client_ID(Client), Req->command);
69 if (*itemList == ',') {
76 itemList = Req->argv[1];
78 if (*itemList == ',') {
85 if (Client_Type(Client) == CLIENT_SERVER)
86 from = Client_Search(Req->prefix);
91 return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG,
92 Client_ID(Client), Req->prefix);
94 reason = Req->argc == 3 ? Req->argv[2] : Client_ID(from);
95 currentNick = Req->argv[1];
96 currentChannel = Req->argv[0];
97 if (channelCount == 1) {
98 while (nickCount > 0) {
99 if (!try_kick(Client, from, currentNick,
100 currentChannel, reason))
109 } else if (channelCount == nickCount) {
110 while (nickCount > 0) {
111 if (!try_kick(Client, from, currentNick,
112 currentChannel, reason))
118 while (*currentChannel)
126 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
127 Client_ID(Client), Req->command);
134 IRC_INVITE(CLIENT *Client, REQUEST *Req)
137 CLIENT *target, *from;
138 const char *colon_if_necessary;
139 bool remember = false;
141 assert( Client != NULL );
142 assert( Req != NULL );
145 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
146 Client_ID(Client), Req->command);
148 if (Client_Type(Client) == CLIENT_SERVER)
149 from = Client_Search(Req->prefix);
153 return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG,
154 Client_ID(Client), Req->prefix);
157 target = Client_Search(Req->argv[0]);
158 if (!target || (Client_Type(target) != CLIENT_USER))
159 return IRC_WriteStrClient(from, ERR_NOSUCHNICK_MSG,
160 Client_ID(Client), Req->argv[0]);
162 chan = Channel_Search(Req->argv[1]);
164 /* Channel exists. Is the user a valid member of the channel? */
165 if (!Channel_IsMemberOf(chan, from))
166 return IRC_WriteStrClient(from, ERR_NOTONCHANNEL_MSG, Client_ID(Client), Req->argv[1]);
168 /* Is the channel "invite-only"? */
169 if (strchr(Channel_Modes(chan), 'i')) {
170 /* Yes. The user must be channel operator! */
171 if (!strchr(Channel_UserModes(chan, from), 'o'))
172 return IRC_WriteStrClient(from, ERR_CHANOPRIVSNEEDED_MSG,
173 Client_ID(from), Channel_Name(chan));
177 /* Is the target user already member of the channel? */
178 if (Channel_IsMemberOf(chan, target))
179 return IRC_WriteStrClient(from, ERR_USERONCHANNEL_MSG,
180 Client_ID(from), Req->argv[0], Req->argv[1]);
182 /* If the target user is banned on that channel: remember invite */
183 if (Lists_Check(Channel_GetListBans(chan), target))
187 /* We must remember this invite */
188 if (!Channel_AddInvite(chan, Client_Mask(target), true))
193 LogDebug("User \"%s\" invites \"%s\" to \"%s\" ...", Client_Mask(from), Req->argv[0], Req->argv[1]);
198 * 'There is no requirement that the channel [..] must exist or be a valid channel'
199 * The problem with this is that this allows the "channel" to contain spaces,
200 * in which case we must prefix its name with a colon to make it clear that
201 * it is only a single argument.
203 colon_if_necessary = strchr(Req->argv[1], ' ') ? ":":"";
204 /* Inform target client */
205 IRC_WriteStrClientPrefix(target, from, "INVITE %s %s%s", Req->argv[0],
206 colon_if_necessary, Req->argv[1]);
208 if (Client_Conn(target) > NONE) {
209 /* The target user is local, so we have to send the status code */
210 if (!IRC_WriteStrClientPrefix(from, target, RPL_INVITING_MSG,
211 Client_ID(from), Req->argv[0], colon_if_necessary, Req->argv[1]))
214 if (strchr(Client_Modes(target), 'a') &&
215 !IRC_WriteStrClient(from, RPL_AWAY_MSG, Client_ID(from),
216 Client_ID(target), Client_Away(target)))