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.
16 * Channel operator commands
27 #include "irc-write.h"
38 try_kick(CLIENT *peer, CLIENT* from, const char *nick, const char *channel,
41 CLIENT *target = Client_Search(nick);
44 return IRC_WriteStrClient(from, ERR_NOSUCHNICK_MSG, Client_ID(from), nick);
46 Channel_Kick(peer, target, from, channel, reason);
52 IRC_KICK(CLIENT *Client, REQUEST *Req)
55 char *itemList = Req->argv[0];
56 const char* currentNick, *currentChannel, *reason;
57 unsigned int channelCount = 1;
58 unsigned int nickCount = 1;
60 assert( Client != NULL );
61 assert( Req != NULL );
63 if ((Req->argc < 2) || (Req->argc > 3))
64 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
65 Client_ID(Client), Req->command);
68 if (*itemList == ',') {
75 itemList = Req->argv[1];
77 if (*itemList == ',') {
84 if (Client_Type(Client) == CLIENT_SERVER)
85 from = Client_Search(Req->prefix);
90 return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG,
91 Client_ID(Client), Req->prefix);
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_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
126 Client_ID(Client), Req->command);
133 IRC_INVITE(CLIENT *Client, REQUEST *Req)
136 CLIENT *target, *from;
137 const char *colon_if_necessary;
138 bool remember = false;
140 assert( Client != NULL );
141 assert( Req != NULL );
144 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
145 Client_ID(Client), Req->command);
147 if (Client_Type(Client) == CLIENT_SERVER)
148 from = Client_Search(Req->prefix);
152 return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG,
153 Client_ID(Client), Req->prefix);
156 target = Client_Search(Req->argv[0]);
157 if (!target || (Client_Type(target) != CLIENT_USER))
158 return IRC_WriteStrClient(from, ERR_NOSUCHNICK_MSG,
159 Client_ID(Client), Req->argv[0]);
161 chan = Channel_Search(Req->argv[1]);
163 /* Channel exists. Is the user a valid member of the channel? */
164 if (!Channel_IsMemberOf(chan, from))
165 return IRC_WriteStrClient(from, ERR_NOTONCHANNEL_MSG, Client_ID(Client), Req->argv[1]);
167 /* Is the channel "invite-only"? */
168 if (strchr(Channel_Modes(chan), 'i')) {
169 /* Yes. The user must be channel operator! */
170 if (!strchr(Channel_UserModes(chan, from), 'o'))
171 return IRC_WriteStrClient(from, ERR_CHANOPRIVSNEEDED_MSG,
172 Client_ID(from), Channel_Name(chan));
176 /* Is the target user already member of the channel? */
177 if (Channel_IsMemberOf(chan, target))
178 return IRC_WriteStrClient(from, ERR_USERONCHANNEL_MSG,
179 Client_ID(from), Req->argv[0], Req->argv[1]);
181 /* If the target user is banned on that channel: remember invite */
182 if (Lists_Check(Channel_GetListBans(chan), target))
186 /* We must remember this invite */
187 if (!Channel_AddInvite(chan, Client_Mask(target), true))
192 LogDebug("User \"%s\" invites \"%s\" to \"%s\" ...", Client_Mask(from), Req->argv[0], Req->argv[1]);
197 * 'There is no requirement that the channel [..] must exist or be a valid channel'
198 * The problem with this is that this allows the "channel" to contain spaces,
199 * in which case we must prefix its name with a colon to make it clear that
200 * it is only a single argument.
202 colon_if_necessary = strchr(Req->argv[1], ' ') ? ":":"";
203 /* Inform target client */
204 IRC_WriteStrClientPrefix(target, from, "INVITE %s %s%s", Req->argv[0],
205 colon_if_necessary, Req->argv[1]);
207 if (Client_Conn(target) > NONE) {
208 /* The target user is local, so we have to send the status code */
209 if (!IRC_WriteStrClientPrefix(from, target, RPL_INVITING_MSG,
210 Client_ID(from), Req->argv[0], colon_if_necessary, Req->argv[1]))
213 if (strchr(Client_Modes(target), 'a') &&
214 !IRC_WriteStrClient(from, RPL_AWAY_MSG, Client_ID(from),
215 Client_ID(target), Client_Away(target)))