Improving commands and added quit
This commit is contained in:
@@ -43,6 +43,7 @@ User& User::operator=(const User &other)
|
||||
buffer = other.buffer;
|
||||
authenticated = other.authenticated;
|
||||
registered = other.registered;
|
||||
channels_ = other.channels_;
|
||||
}
|
||||
// std::cout << "User copy assignment operator called" << std::endl;
|
||||
return (*this);
|
||||
@@ -59,6 +60,27 @@ void User::send(const std::string &msg)
|
||||
::send(fd, msg.c_str(), msg.size(), 0);
|
||||
}
|
||||
|
||||
// Channels
|
||||
void User::joinChannel(const std::string &channel)
|
||||
{
|
||||
channels_.insert(channel);
|
||||
}
|
||||
|
||||
void User::leaveChannel(const std::string &channel)
|
||||
{
|
||||
channels_.erase(channel);
|
||||
}
|
||||
|
||||
bool User::isInChannel(const std::string &channel) const
|
||||
{
|
||||
return (channels_.count(channel) > 0);
|
||||
}
|
||||
|
||||
const std::set<std::string> &User::getChannels() const
|
||||
{
|
||||
return (channels_);
|
||||
}
|
||||
|
||||
// Getters
|
||||
|
||||
int User::getFd() const { return (this->fd); }
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
# include <iostream>
|
||||
# include <sys/socket.h>
|
||||
# include <set>
|
||||
|
||||
class User
|
||||
{
|
||||
@@ -28,6 +29,8 @@ class User
|
||||
bool authenticated;
|
||||
bool registered;
|
||||
|
||||
std::set<std::string> channels_;
|
||||
|
||||
public:
|
||||
User();
|
||||
User(int fd);
|
||||
@@ -37,6 +40,12 @@ class User
|
||||
|
||||
void send(const std::string &msg);
|
||||
|
||||
// Channels
|
||||
void joinChannel(const std::string &channel);
|
||||
void leaveChannel( const std::string &channel);
|
||||
bool isInChannel(const std::string &channel) const;
|
||||
const std::set<std::string> &getChannels() const;
|
||||
|
||||
// Getters
|
||||
|
||||
int getFd() const;
|
||||
|
||||
Reference in New Issue
Block a user