#include "Mode.hpp" #include "../IRC.hpp" #include bool Mode::validate(const User &user, const std::string &msg) { std::istringstream iss(msg); std::string word; std::string permissions; iss >> word; // should be MODE iss >> word; // should be the channel you want to adjust permissions to this->targetChannel = IRCManager::getChannelByName(word); iss >> word; // should be the permissions to adjust permissions = word; iss >> word; // should be the user that gets affected this->targetUser = IRCManager::getUserByName(word); if (this->targetChannel) // Check if the channel exists { if (this->targetUser) // Check if the user exists { if (this->targetChannel->checkOper(user)) // Check if we have operator permissions in the channel { if (permissions.find("+") != permissions.npos()) // we are going to give a mode { if (permissions.find("v") != permissions.npos()) // we are going to give voice this->voice = 1; else if (permissions.find("b") != permissions.npos()) // we are going to give ban this->ban = 1; else if (permissions.find("o") != permissions.npos()) // we are going to give oper this->oper = 1; } else if (permissions.find("-") != permissions.npos()) // we are going to take a mode { if (permissions.find("v") != permissions.npos()) // we are going to take voice this->voice = 2; else if (permissions.find("b") != permissions.npos()) // we are going to take ban this->ban = 2; else if (permissions.find("o") != permissions.npos()) // we are going to take oper this->oper = 2; } if (this->voice || this->ban || this->oper) // if we need to change anything return (true); } } } return (false); } int Mode::run(User &user, IRC::t_send_f &send) { if (this->voice) { if (this->voice == 1) this->targetChannel->giveVoice(this->targetUser); if (this->voice == 2) this->targetChannel->takeVoice(this->targetUser); } if (this->ban) { if (this->ban == 1) this->targetChannel->giveBan(this->targetUser); if (this->ban == 2) this->targetChannel->takeBan(this->targetUser); } if (this->oper) { if (this->oper == 1) this->targetChannel->giveOper(this->targetUser); if (this->oper == 2) this->targetChannel->takeOper(this->targetUser); } return (0); }