42 lines
1.9 KiB
C++
42 lines
1.9 KiB
C++
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* mode.cpp :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: iherman- <iherman-@student.42malaga.com +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2026/05/23 17:15:27 by iherman- #+# #+# */
|
|
/* Updated: 2026/05/23 20:25:02 by iherman- ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "../Server/Server.hpp"
|
|
|
|
void Server::mode_cmd(User &client, std::istringstream &ss)
|
|
{
|
|
std::string target;
|
|
std::string mode;
|
|
std::string args;
|
|
|
|
ss >> target >> mode;
|
|
std::getline(ss, args); // might include space in channel name, need to fix
|
|
|
|
if (!client.isRegistered()) return (client.send(":" SERVER_NAME " 451 * :You have not registered\r\n"));
|
|
if (target.empty() || mode.empty()) return (client.send(":" SERVER_NAME " 461 " + client.getNick() + " MODE :Not enough parameters\r\n"));
|
|
|
|
std::map<std::string, Channel>::iterator channel = channels_.find(target);
|
|
if (channel == channels_.end())
|
|
{
|
|
client.send(":" SERVER_NAME " 403 " + client.getNick() + target + ":No such channel\r\n");
|
|
return ;
|
|
}
|
|
|
|
if (!channel->second.hasOperator(client.getFd()))
|
|
{
|
|
client.send(std::string(":") + SERVER_NAME + " 482 " + client.getNick() + " " + channel->second.getName() + " :You're not channel operator\r\n");
|
|
return ;
|
|
}
|
|
|
|
channel->second.setMode(mode, args); // args should prob be a stringstream :(
|
|
}
|