#include "Topic.hpp" #include "../IRC.hpp" #include bool Topic::validate(const User &user, const std::string &msg) { size_t pos; size_t leng; leng = msg.length(); pos = msg.find(":") + 1; std::istringstream iss(msg); std::string word; this->topic = msg.substr(pos, leng - pos); iss >> word; // should be TOPIC iss >> word; // should be the Channel you want to change this->targetChannel = IRCManager::getChannelByName(word); if (this->targetChannel) // Check if the channel exists { if (this->targetChannel->getUserChangeTopic()) // Check if a user has permission to change the topic return (true); if (this->targetChannel->checkOperator(user)) // Check if we have operator permissions in the channel return (true); } return (false); } int Topic::run(User &user, IRC::t_send_f &send) { this->targetChannel->setTopic(this->topic); std::istringstream iss(this->targetChannel->getUserList()); std::string target; iss >> target; while (target[0]) { send(IRCManager::getUserFromName(target), user.getNickName() + "!~" + user.getUserName() + "@" + user.getHostName() + " TOPIC " + this->targetChannel->getChannelName() + " * :" + this->topic; iss >> target; } return (0); } //TOPIC #testtesttest :test123 //@time=2024-07-22T14:57:54.693Z :HoutwormNick!~HoutwormU@84-86-79-218.fixed.kpn.net TOPIC #testtesttest :test123