#include "User.hpp" #include "../User.hpp" #include "../Connection.hpp" #include "../IRC.hpp" #include UserCMD::UserCMD() {} UserCMD::~UserCMD() {} bool UserCMD::validate(const User &user, const std::string &msg) { size_t pos; size_t leng; std::istringstream iss(msg); std::string word; leng = msg.length(); pos = msg.find(":") + 1; this->realName = msg.substr(pos, leng - pos); iss >> word; // should be USER iss >> word; // should be the Nickname this->nickName = word; // perhaps we should check the real and username on length and illegal characters return true; } bool UserCMD::validate(const Connection &conn, const std::string &msg) { size_t pos; size_t leng; std::istringstream iss(msg); std::string word; leng = msg.length(); pos = msg.find(":") + 1; this->realName = msg.substr(pos, leng - pos); iss >> word; // should be USER iss >> word; // should be the Nickname this->nickName = word; return true; // perhaps we should check the real and username on length and illegal characters } int UserCMD::run(User &user, IRC::t_send_f &send) { user->setUserName(this->userName); user->setRealName(this->realName); return (0); } int UserCMD::run(Connection &conn, IRC::t_send_f &send) { if (conn->getNickName()) // Nick was called before and we will create the user here { user = IRCManager::addUser(conn, this->userName, this->realName, conn->getNickName()); user->setUserName(this->userName); user->setRealName(this->realName); } else // User was called before Nick and User will be created in Nick { user->setUserName(this->userName); user->setRealName(this->realName); } return (0); }