push_Channel_class
This commit is contained in:
parent
6b978d0673
commit
f221c92fec
1
Makefile
1
Makefile
|
|
@ -5,6 +5,7 @@ INCLUDES = -I includes
|
|||
|
||||
SRCS = main.cpp \
|
||||
srcs/Server.cpp \
|
||||
srcs/Channel.cpp \
|
||||
srcs/ParseBuffer.cpp \
|
||||
srcs/IrcParser.cpp \
|
||||
srcs/IrcMessage.cpp \
|
||||
|
|
|
|||
|
|
@ -0,0 +1,55 @@
|
|||
#ifndef CHANNEL_HPP
|
||||
# define CHANNEL_HPP
|
||||
|
||||
# include <string>
|
||||
# include <vector>
|
||||
|
||||
class Channel
|
||||
{
|
||||
private:
|
||||
std::string _name;
|
||||
std::string _topic;
|
||||
std::string _key;
|
||||
std::vector<int> _members;
|
||||
std::vector<int> _operators;
|
||||
std::vector<int> _invited;
|
||||
bool _inviteOnly;
|
||||
bool _topicRestricted;
|
||||
size_t _userLimit;
|
||||
|
||||
public:
|
||||
Channel(void);
|
||||
explicit Channel(const std::string &name);
|
||||
Channel(const Channel &other);
|
||||
Channel &operator=(const Channel &other);
|
||||
~Channel(void);
|
||||
|
||||
const std::string &getName(void) const;
|
||||
const std::string &getTopic(void) const;
|
||||
const std::string &getKey(void) const;
|
||||
size_t getUserLimit(void) const;
|
||||
bool isInviteOnly(void) const;
|
||||
bool isTopicRestricted(void) const;
|
||||
|
||||
void setTopic(const std::string &topic);
|
||||
void setKey(const std::string &key);
|
||||
void setUserLimit(size_t limit);
|
||||
void setInviteOnly(bool val);
|
||||
void setTopicRestricted(bool val);
|
||||
|
||||
bool hasMember(int fd) const;
|
||||
bool isOperator(int fd) const;
|
||||
bool isInvited(int fd) const;
|
||||
|
||||
void addMember(int fd);
|
||||
void removeMember(int fd);
|
||||
void addOperator(int fd);
|
||||
void removeOperator(int fd);
|
||||
void addInvited(int fd);
|
||||
void removeInvited(int fd);
|
||||
|
||||
const std::vector<int> &getMembers(void) const;
|
||||
size_t memberCount(void) const;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -15,6 +15,7 @@
|
|||
# include <cstring>
|
||||
# include <cerrno>
|
||||
# include "CommandValidator.hpp"
|
||||
# include "Channel.hpp"
|
||||
|
||||
struct ConnectedUser
|
||||
{
|
||||
|
|
@ -39,18 +40,28 @@ class Server
|
|||
int _serverFd;
|
||||
int _port;
|
||||
std::string _password;
|
||||
std::vector<struct pollfd> _fds;
|
||||
std::vector<struct pollfd> _fds;
|
||||
std::map<int, ConnectedUser> _users;
|
||||
std::map<std::string, Channel> _channels;
|
||||
|
||||
void acceptNew(void);
|
||||
void handleRecv(int fd);
|
||||
void removeUser(int fd);
|
||||
void dispatch(int fd, const IrcMessage &msg);
|
||||
void handlePass(int fd, const IrcMessage &msg);
|
||||
void handleNick(int fd, const IrcMessage &msg);
|
||||
void handleUser(int fd, const IrcMessage &msg);
|
||||
void handlePing(int fd, const IrcMessage &msg);
|
||||
void handleQuit(int fd, const IrcMessage &msg);
|
||||
void broadcastToChannel(const std::string &chanName, const std::string &msg, int exceptFd);
|
||||
|
||||
void handlePass(int fd, const IrcMessage &msg);
|
||||
void handleNick(int fd, const IrcMessage &msg);
|
||||
void handleUser(int fd, const IrcMessage &msg);
|
||||
void handlePing(int fd, const IrcMessage &msg);
|
||||
void handleQuit(int fd, const IrcMessage &msg);
|
||||
void handleJoin(int fd, const IrcMessage &msg);
|
||||
void handlePart(int fd, const IrcMessage &msg);
|
||||
void handlePrivmsg(int fd, const IrcMessage &msg);
|
||||
void handleKick(int fd, const IrcMessage &msg);
|
||||
void handleInvite(int fd, const IrcMessage &msg);
|
||||
void handleTopic(int fd, const IrcMessage &msg);
|
||||
void handleMode(int fd, const IrcMessage &msg);
|
||||
|
||||
public:
|
||||
Server(int port, const std::string &password);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,189 @@
|
|||
#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 ;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue