blabla/Nick.cpp

66 lines
1.7 KiB
C++
Raw Permalink Normal View History

2024-08-03 21:04:44 +02:00
#include "Nick.hpp"
#include "../IRC.hpp"
#include <string>
Nick::Nick() {}
Nick::~Nick() {}
bool Nick::validate(const User &user, const std::string &msg)
{
size_t pos;
size_t leng;
leng = msg.length();
pos = msg.find(" ");
this->nickName = msg.substr(pos + 1, leng - pos);
// probably need to check for length and illegal characters
return true;
}
bool Nick::validate(const Connection &conn, const std::string &msg)
{
size_t pos;
size_t leng;
leng = msg.length();
pos = msg.find(" ");
this->nickName = msg.substr(pos, leng - pos);
// probably need to check for length and illegal characters
return true;
}
int Nick::run(User &user, IRC::t_send_f &send)
{
user->setNickName(this->nickName);
std::istringstream issc(user->getChannelList());
std::string targetchannel;
issc >> targetchannel;
while (targetchannel[0])
{
std::istringstream issu(IRCManager::getChannelFromName(targetchannel)->getUserList());
std::string targetuser;
iss >> targetuser;
while (targetuser[0])
{
send(IRCManager::getUserFromName(targetuser), user.getNickName() + "!~" + user.getUserName() + "@" + user.getHostName() + " NICK " + " :" + user->getNickName());
issu >> targetuser;
}
issc >> targetchannel;
}
return (0);
}
int Nick::run(Connection &conn, IRC::t_send_f &send) // second run function with Connection argument is for when user is not created yet
{
if (conn->getNickName()) // User was called before and we will create the user here
{
IRCManager::addUser(conn, conn->getUserName(), conn->getRealName(), this->nickName());
}
else // Nick was called before User and User will be created in User
{
conn->setNickName(this->nickName);
}
return (0);
}