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.
11 * Channel operator commands
26 #include "irc-write.h"
37 try_kick(CLIENT *peer, CLIENT* from, const char *nick, const char *channel,
40 CLIENT *target = Client_Search(nick);
43 return IRC_WriteStrClient(from, ERR_NOSUCHNICK_MSG, Client_ID(from), nick);
45 Channel_Kick(peer, target, from, channel, reason);
51 IRC_KICK(CLIENT *Client, REQUEST *Req)
54 char *itemList = Req->argv[0];
55 const char* currentNick, *currentChannel, *reason;
56 unsigned int channelCount = 1;
57 unsigned int nickCount = 1;
59 assert( Client != NULL );
60 assert( Req != NULL );
62 if ((Req->argc < 2) || (Req->argc > 3))
63 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
64 Client_ID(Client), Req->command);
67 if (*itemList == ',') {
74 itemList = Req->argv[1];
76 if (*itemList == ',') {
83 if (Client_Type(Client) == CLIENT_SERVER)
84 from = Client_Search(Req->prefix);
89 return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG,
90 Client_ID(Client), Req->prefix);
92 reason = Req->argc == 3 ? Req->argv[2] : Client_ID(from);
93 currentNick = Req->argv[1];
94 currentChannel = Req->argv[0];
95 if (channelCount == 1) {
96 while (nickCount > 0) {
97 if (!try_kick(Client, from, currentNick,
98 currentChannel, reason))
107 } else if (channelCount == nickCount) {
108 while (nickCount > 0) {
109 if (!try_kick(Client, from, currentNick,
110 currentChannel, reason))
116 while (*currentChannel)
124 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
125 Client_ID(Client), Req->command);
132 IRC_INVITE(CLIENT *Client, REQUEST *Req)
135 CLIENT *target, *from;
136 const char *colon_if_necessary;
137 bool remember = false;
139 assert( Client != NULL );
140 assert( Req != NULL );
143 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
144 Client_ID(Client), Req->command);
146 if (Client_Type(Client) == CLIENT_SERVER)
147 from = Client_Search(Req->prefix);
151 return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG,
152 Client_ID(Client), Req->prefix);
155 target = Client_Search(Req->argv[0]);
156 if (!target || (Client_Type(target) != CLIENT_USER))
157 return IRC_WriteStrClient(from, ERR_NOSUCHNICK_MSG,
158 Client_ID(Client), Req->argv[0]);
160 chan = Channel_Search(Req->argv[1]);
162 /* Channel exists. Is the user a valid member of the channel? */
163 if (!Channel_IsMemberOf(chan, from))
164 return IRC_WriteStrClient(from, ERR_NOTONCHANNEL_MSG, Client_ID(Client), Req->argv[1]);
166 /* Is the channel "invite-only"? */
167 if (strchr(Channel_Modes(chan), 'i')) {
168 /* Yes. The user must be channel operator! */
169 if (!strchr(Channel_UserModes(chan, from), 'o'))
170 return IRC_WriteStrClient(from, ERR_CHANOPRIVSNEEDED_MSG,
171 Client_ID(from), Channel_Name(chan));
175 /* Is the target user already member of the channel? */
176 if (Channel_IsMemberOf(chan, target))
177 return IRC_WriteStrClient(from, ERR_USERONCHANNEL_MSG,
178 Client_ID(from), Req->argv[0], Req->argv[1]);
180 /* If the target user is banned on that channel: remember invite */
181 if (Lists_Check(Channel_GetListBans(chan), target))
185 /* We must remember this invite */
186 if (!Channel_AddInvite(chan, Client_Mask(target), true))
191 LogDebug("User \"%s\" invites \"%s\" to \"%s\" ...", Client_Mask(from), Req->argv[0], Req->argv[1]);
196 * 'There is no requirement that the channel [..] must exist or be a valid channel'
197 * The problem with this is that this allows the "channel" to contain spaces,
198 * in which case we must prefix its name with a colon to make it clear that
199 * it is only a single argument.
201 colon_if_necessary = strchr(Req->argv[1], ' ') ? ":":"";
202 /* Inform target client */
203 IRC_WriteStrClientPrefix(target, from, "INVITE %s %s%s", Req->argv[0],
204 colon_if_necessary, Req->argv[1]);
206 if (Client_Conn(target) > NONE) {
207 /* The target user is local, so we have to send the status code */
208 if (!IRC_WriteStrClientPrefix(from, target, RPL_INVITING_MSG,
209 Client_ID(from), Req->argv[0], colon_if_necessary, Req->argv[1]))
212 if (strchr(Client_Modes(target), 'a') &&
213 !IRC_WriteStrClient(from, RPL_AWAY_MSG, Client_ID(from),
214 Client_ID(target), Client_Away(target)))