51 lines
2.3 KiB
C++
51 lines
2.3 KiB
C++
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* topic.cpp :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2026/05/25 10:04:16 by aortigos #+# #+# */
|
|
/* Updated: 2026/05/25 10:19:53 by aortigos ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "../Server/Server.hpp"
|
|
|
|
void Server::topic_cmd(User &client, std::istringstream &ss)
|
|
{
|
|
std::string channel;
|
|
std::string message;
|
|
|
|
ss >> channel;
|
|
getline(ss, message);
|
|
|
|
if (!client.isRegistered()) return (client.send(":" SERVER_NAME " 451 " + client.getNick() + " :You have not registered\r\n"));
|
|
|
|
|
|
std::map<std::string, Channel>::iterator it = channels_.find(channel);
|
|
|
|
if (it == channels_.end())
|
|
return (client.send(":" SERVER_NAME " 403 " + client.getNick() + " " + channel + " :No such channel\r\n"));
|
|
|
|
if (!it->second.hasMember(client.getFd()))
|
|
return (client.send(":" SERVER_NAME " 404 " + client.getNick() + " " + channel + " :Cannot send to channel\r\n"));
|
|
|
|
if (message.empty())
|
|
{
|
|
std::string res = it->second.getTopic();
|
|
if (res.empty())
|
|
return (client.send(":" SERVER_NAME " 331 " + client.getNick() + " " + channel + " :No topic is set\r\n"));
|
|
client.send(":" SERVER_NAME " 332 " + client.getNick() + " " + channel + " :" + res + "\r\n");
|
|
}
|
|
else
|
|
{
|
|
if (!message.empty() && message[0] == ' ')
|
|
message = message.substr(1);
|
|
if (!it->second.hasOperator(client.getFd()))
|
|
return (client.send(":" SERVER_NAME " 482 " + client.getNick() + " " + channel + " :You're not channel operator\r\n"));
|
|
it->second.setTopic(message);
|
|
it->second.broadcast(":" + client.getNick() + "!" + client.getUsername() + "@localhost TOPIC " + channel + " :" + message + "\r\n", clients_, -1);
|
|
}
|
|
|
|
} |