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* from, const char *nick, const char *channel, const char *reason)
39 CLIENT *target = Client_Search(nick);
42 return IRC_WriteStrClient(from, ERR_NOSUCHNICK_MSG, Client_ID(from), nick);
44 Channel_Kick(target, from, channel, reason);
50 IRC_KICK(CLIENT *Client, REQUEST *Req)
53 char *itemList = Req->argv[0];
54 const char* currentNick, *currentChannel, *reason;
55 unsigned int channelCount = 1;
56 unsigned int nickCount = 1;
58 assert( Client != NULL );
59 assert( Req != NULL );
61 if ((Req->argc < 2) || (Req->argc > 3))
62 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
63 Client_ID(Client), Req->command);
66 if (*itemList == ',') {
73 itemList = Req->argv[1];
75 if (*itemList == ',') {
82 if (Client_Type(Client) == CLIENT_SERVER)
83 from = Client_Search(Req->prefix);
88 return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG,
89 Client_ID(Client), Req->prefix);
91 reason = Req->argc == 3 ? Req->argv[2] : Client_ID(from);
92 currentNick = Req->argv[1];
93 currentChannel = Req->argv[0];
94 if (channelCount == 1) {
95 while (nickCount > 0) {
96 if (!try_kick(from, currentNick, currentChannel, reason))
105 } else if (channelCount == nickCount) {
106 while (nickCount > 0) {
107 if (!try_kick(from, currentNick, currentChannel, reason))
113 while (*currentChannel)
121 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
122 Client_ID(Client), Req->command);
129 IRC_INVITE(CLIENT *Client, REQUEST *Req)
132 CLIENT *target, *from;
133 bool remember = false;
135 assert( Client != NULL );
136 assert( Req != NULL );
139 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
140 Client_ID(Client), Req->command);
142 if (Client_Type(Client) == CLIENT_SERVER)
143 from = Client_Search(Req->prefix);
147 return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG,
148 Client_ID(Client), Req->prefix);
151 target = Client_Search(Req->argv[0]);
152 if (!target || (Client_Type(target) != CLIENT_USER))
153 return IRC_WriteStrClient(from, ERR_NOSUCHNICK_MSG,
154 Client_ID(Client), Req->argv[0]);
156 chan = Channel_Search(Req->argv[1]);
158 /* Channel exists. Is the user a valid member of the channel? */
159 if (!Channel_IsMemberOf(chan, from))
160 return IRC_WriteStrClient(from, ERR_NOTONCHANNEL_MSG, Client_ID(Client), Req->argv[1]);
162 /* Is the channel "invite-only"? */
163 if (strchr(Channel_Modes(chan), 'i')) {
164 /* Yes. The user must be channel operator! */
165 if (!strchr(Channel_UserModes(chan, from), 'o'))
166 return IRC_WriteStrClient(from, ERR_CHANOPRIVSNEEDED_MSG,
167 Client_ID(from), Channel_Name(chan));
171 /* Is the target user already member of the channel? */
172 if (Channel_IsMemberOf(chan, target))
173 return IRC_WriteStrClient(from, ERR_USERONCHANNEL_MSG,
174 Client_ID(from), Req->argv[0], Req->argv[1]);
176 /* If the target user is banned on that channel: remember invite */
177 if (Lists_Check(Channel_GetListBans(chan), target))
181 /* We must remember this invite */
182 if (!Channel_AddInvite(chan, Client_Mask(target), true))
187 LogDebug("User \"%s\" invites \"%s\" to \"%s\" ...", Client_Mask(from), Req->argv[0], Req->argv[1]);
189 /* Inform target client */
190 IRC_WriteStrClientPrefix(target, from, "INVITE %s %s", Req->argv[0], Req->argv[1]);
192 if (Client_Conn(target) > NONE) {
193 /* The target user is local, so we have to send the status code */
194 if (!IRC_WriteStrClientPrefix(from, target, RPL_INVITING_MSG,
195 Client_ID(from), Req->argv[0], Req->argv[1]))
198 if (strchr(Client_Modes(target), 'a') &&
199 !IRC_WriteStrClient(from, RPL_AWAY_MSG, Client_ID(from),
200 Client_ID(target), Client_Away(target)))