Channel changes and init JOIN command
This commit is contained in:
@@ -44,6 +44,9 @@ Channel& Channel::operator=(const Channel &other)
|
||||
Channel::Channel(std::string name) : name_(name) { /* std::cout << "Channel with name constructor called" << std::endl; */ }
|
||||
|
||||
|
||||
// Getters
|
||||
std::string Channel::getName() const { return (this->name); }
|
||||
|
||||
// Members
|
||||
void Channel::addMember(int fd) { this->members_.insert(fd); }
|
||||
void Channel::removeMember(int fd) { this->members_.erase(fd); }
|
||||
@@ -53,3 +56,14 @@ bool Channel::hasMember(int fd) const { return (this->members_.count(fd) > 0);
|
||||
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, const std::map<int, User>& clients_, int excludeFd)
|
||||
{
|
||||
for(std::set<int>::iterator it = members_.begin(); it != members_.end(); it++)
|
||||
{
|
||||
if (*it == excludeFd) continue;
|
||||
std::map<int, User>::const_iterator user = clients_.find(*it);
|
||||
if (user != client_.end())
|
||||
user->second.send(msg);
|
||||
}
|
||||
}
|
||||
@@ -16,13 +16,16 @@
|
||||
|
||||
# include <iostream>
|
||||
# include <set>
|
||||
# include <map>
|
||||
|
||||
# include "../User/User.hpp"
|
||||
|
||||
class Channel
|
||||
{
|
||||
private:
|
||||
std::string name_;
|
||||
std::set<int> members_;
|
||||
std::set<int> operators_;
|
||||
std::set<int> members_;
|
||||
std::set<int> operators_;
|
||||
|
||||
public:
|
||||
Channel();
|
||||
@@ -31,15 +34,22 @@ class Channel
|
||||
Channel& operator=(const Channel &other);
|
||||
~Channel();
|
||||
|
||||
|
||||
// Getters
|
||||
std::string getName() const { return (this->name); }
|
||||
|
||||
|
||||
// Users
|
||||
void addMember(int fd);
|
||||
void removeMember(int fd);
|
||||
bool hasMember(int fd) const;
|
||||
|
||||
void addMember(int fd);
|
||||
void removeMember(int fd);
|
||||
bool hasMember(int fd) const;
|
||||
|
||||
// Operators
|
||||
void addOperator(int fd);
|
||||
void removeOperator(int fd);
|
||||
bool hasOperator(int fd) const;
|
||||
void addOperator(int fd);
|
||||
void removeOperator(int fd);
|
||||
bool hasOperator(int fd) const;
|
||||
|
||||
void broadcast(const std::string &msg, const std::map<int, User>& clients_, int excludeFd);
|
||||
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user