Added MODE and invite only functionality
This commit is contained in:
@@ -33,6 +33,8 @@ Channel& Channel::operator=(const Channel &other)
|
||||
name_ = other.name_;
|
||||
members_ = other.members_;
|
||||
operators_ = other.operators_;
|
||||
isInviteOnly_ = other.isInviteOnly_;
|
||||
invitedMembers_ = other.invitedMembers_;
|
||||
}
|
||||
// std::cout << "Channel copy assignment operator called" << std::endl;
|
||||
return (*this);
|
||||
@@ -41,7 +43,7 @@ Channel& Channel::operator=(const Channel &other)
|
||||
|
||||
// Constructor with name
|
||||
|
||||
Channel::Channel(std::string &name) : name_(name) { /* std::cout << "Channel with name constructor called" << std::endl; */ }
|
||||
Channel::Channel(std::string &name) : name_(name), isInviteOnly_(false) { /* std::cout << "Channel with name constructor called" << std::endl; */ }
|
||||
|
||||
|
||||
// Getters
|
||||
@@ -62,14 +64,35 @@ void Channel::addOperator(int fd) { this->operators_.insert(fd); }
|
||||
void Channel::removeOperator(int fd) { this->operators_.erase(fd); }
|
||||
bool Channel::hasOperator(int fd) const { return (this->operators_.count(fd) > 0); }
|
||||
|
||||
void Channel::broadcast(const std::string &msg, std::map<int, User> &clients, int excludedFd)
|
||||
void Channel::broadcast(const std::string &msg, const std::map<int, User> &clients, int excludedFd)
|
||||
{
|
||||
for (std::set<int>::iterator member = members_.begin(); member != members_.end(); member++)
|
||||
{
|
||||
if ((*member) == excludedFd) continue;
|
||||
std::map<int, User>::iterator user = clients.find(*member);
|
||||
std::map<int, User>::const_iterator user = clients.find(*member);
|
||||
|
||||
if (user != clients.end())
|
||||
user->second.send(msg);
|
||||
}
|
||||
}
|
||||
|
||||
void Channel::setMode(std::string& mode, std::string& args)
|
||||
{
|
||||
bool value;
|
||||
if (mode[0] == '+')
|
||||
value = true;
|
||||
else
|
||||
value = false;
|
||||
|
||||
// very simple to test
|
||||
if (mode[1] == 'i')
|
||||
{
|
||||
isInviteOnly_ = value;
|
||||
return ;
|
||||
}
|
||||
|
||||
(void) args;
|
||||
}
|
||||
|
||||
bool Channel::isInviteOnly() const { return isInviteOnly_; }
|
||||
bool Channel::isInvited(int fd) const { return invitedMembers_.count(fd) > 0; }
|
||||
|
||||
Reference in New Issue
Block a user