/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* kick.cpp :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: aortigos > channel >> user; getline(ss, reason); if (!client.isRegistered()) return (client.send(":" SERVER_NAME " 451 " + client.getNick() + " :You have not registered\r\n")); if (channel.empty() || user.empty()) return (client.send(":" SERVER_NAME " 461 " + client.getNick() + " KICK :not enough parameters\r\n")); if (!reason.empty() && reason[0] == ' ') reason = reason.substr(1); if (!reason.empty() && reason[0] == ':') reason = reason.substr(1); if (reason.empty()) reason = "Kicked"; if (channel[0] != '#') return (client.send("")); std::map::iterator it_channels = channels_.find(channel); if (it_channels == channels_.end()) return (client.send(":" SERVER_NAME " 403 " + client.getNick() + " " + channel + " :No such channel\r\n")); if (!it_channels->second.hasOperator(client.getFd())) return (client.send(":" SERVER_NAME " 482 " + client.getNick() + " " + channel + " :You're not channel operator\r\n")); int userId = -1; for (std::map::iterator it_clients = clients_.begin(); it_clients != clients_.end(); it_clients++) { if (it_clients->second.getNick() == user) userId = it_clients->second.getFd(); } if (userId == -1) return (client.send(":" SERVER_NAME " 401 " + client.getNick() + " " + user + " :No such nick\r\n")); if (!it_channels->second.hasMember(userId)) return (client.send(":" SERVER_NAME " 441 " + client.getNick() + " " + user + " " + channel + " :They aren't on that channel\r\n")); it_channels->second.broadcast(":" + client.getNick() + "!" + client.getUsername() + "@localhost KICK " + channel + " " + user + " :" + reason + "\r\n", clients_, -1); clients_[userId].leaveChannel(channel); it_channels->second.removeMember(userId); }