blabla/Join.cpp
Danny Jonker d426297b2a bla
2024-08-03 21:04:44 +02:00

53 lines
1.4 KiB
C++

#include "Join.hpp"
#include "../IRC.hpp"
#include <string>
bool Join::validate(const User &user, const std::string &msg)
{
size_t pos;
size_t leng;
leng = msg.length();
pos = msg.find(" ");
name = msg.substr(pos + 1, leng - pos);
this->channel = IRCManager::getChannel(name);
if (this->channel) // Check if the channel exists
{
if (this->channel->getInviteStatus()) // If it exists do we need an invite?
{
if (this->channel->checkUserInvite(user)) // Does the user have the invite to join this chat?
{
return (true);
}
return (false);
}
}
else // The Channel doesn't exist yet
return (true);
}
int Join::run(User &user, IRC::t_send_f &send)
{
if (!this->channel) // Check if the channel exists
{
IRCManager::addChannel(name); // create the channel
this->channel = IRCManager::getChannel(name);
this->channel->AddUser(user);
IRCManager::makeOper(user, this->channel);
}
else // Channel exists
{
this->channel->AddUser(user);
}
std::istringstream iss(this->channel->getUserList());
std::string target;
iss >> target;
while (target[0])
{
send(IRCManager::getUserFromName(target), user.getNickName() + "!~" + user.getUserName() + "@" + user.getHostName() + " JOIN " + this->targetChannel->getChannelName() + " * :" + user->getRealName());
iss >> target;
}
std::cout << user.getUserName() + " Joined " + this->channel->getChannelName();
return (0);
}