ft_irc/srcs/Channel.cpp

189 lines
2.9 KiB
C++

#include "Channel.hpp"
Channel::Channel(void)
{
_inviteOnly = false;
_topicRestricted = false;
_userLimit = 0;
}
Channel::Channel(const std::string &name)
{
_inviteOnly = false;
_topicRestricted = false;
_userLimit = 0;
_name = name;
}
Channel::Channel(const Channel &other)
{
*this = other;
}
Channel &Channel::operator=(const Channel &other)
{
if (this != &other)
{
_name = other._name;
_topic = other._topic;
_key = other._key;
_members = other._members;
_operators = other._operators;
_invited = other._invited;
_inviteOnly = other._inviteOnly;
_topicRestricted = other._topicRestricted;
_userLimit = other._userLimit;
}
return *this;
}
Channel::~Channel(void)
{}
const std::string &Channel::getName(void) const
{
return _name;
}
const std::string &Channel::getTopic(void) const
{
return _topic;
}
const std::string &Channel::getKey(void) const
{
return _key;
}
size_t Channel::getUserLimit(void) const
{
return _userLimit;
}
bool Channel::isInviteOnly(void) const
{
return _inviteOnly;
}
bool Channel::isTopicRestricted(void) const
{
return _topicRestricted;
}
const std::vector<int> &Channel::getMembers(void) const
{
return _members;
}
size_t Channel::memberCount(void) const
{
return _members.size();
}
void Channel::setTopic(const std::string &topic)
{
_topic = topic;
}
void Channel::setKey(const std::string &key)
{
_key = key;
}
void Channel::setUserLimit(size_t limit)
{
_userLimit = limit;
}
void Channel::setInviteOnly(bool val)
{
_inviteOnly = val;
}
void Channel::setTopicRestricted(bool val)
{
_topicRestricted = val;
}
bool Channel::hasMember(int fd) const
{
for (std::vector<int>::const_iterator it = _members.begin(); it != _members.end(); ++it)
{
if(*it == fd)
return true;
}
return false;
}
bool Channel::isOperator(int fd) const
{
for (std::vector<int>::const_iterator it = _operators.begin(); it != _operators.end(); ++it)
{
if(*it == fd)
return true;
}
return false;
}
bool Channel::isInvited(int fd) const
{
for (std::vector<int>::const_iterator it = _invited.begin(); it != _invited.end(); ++it)
{
if(*it == fd)
return true;
}
return false;
}
void Channel::addMember(int fd)
{
_members.push_back(fd);
}
void Channel::addOperator(int fd)
{
_operators.push_back(fd);
}
void Channel::addInvited(int fd)
{
_invited.push_back(fd);
}
void Channel::removeMember(int fd)
{
for (std::vector<int>::iterator it = _members.begin(); it != _members.end(); ++it)
{
if(*it == fd)
{
_members.erase(it);
break ;
}
}
}
void Channel::removeOperator(int fd)
{
for (std::vector<int>::iterator it = _operators.begin(); it != _operators.end(); ++it)
{
if(*it == fd)
{
_operators.erase(it);
break ;
}
}
}
void Channel::removeInvited(int fd)
{
for (std::vector<int>::iterator it = _invited.begin(); it != _invited.end(); ++it)
{
if(*it == fd)
{
_invited.erase(it);
break ;
}
}
}