Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"files.associations": {
"iosfwd": "cpp",
"sstream": "cpp",
"vector": "cpp",
"algorithm": "cpp",
"string": "cpp",
"__bit_reference": "cpp",
"__config": "cpp",
"__debug": "cpp",
Expand All @@ -13,8 +18,8 @@
"__split_buffer": "cpp",
"__string": "cpp",
"__threading_support": "cpp",
"__tree": "cpp",
"__tuple": "cpp",
"algorithm": "cpp",
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
Expand All @@ -36,29 +41,30 @@
"functional": "cpp",
"initializer_list": "cpp",
"ios": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"iterator": "cpp",
"limits": "cpp",
"locale": "cpp",
"map": "cpp",
"memory": "cpp",
"mutex": "cpp",
"new": "cpp",
"optional": "cpp",
"ostream": "cpp",
"ratio": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"string": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"typeinfo": "cpp",
"unordered_map": "cpp",
"utility": "cpp",
"vector": "cpp"
"typescript.tsserver.maxTsServerIdleTime": "600000",
"editor.folding": "false",
"cpp.memoryLimit": "8192",
"editor.renderWhitespace": "all"
}
}
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,15 @@
| Notice | The NOTICE command is used to send notices between users, as well as to send notices to channels. The difference between NOTICE and PRIVMSG is that automatic replies must never be sent in response to a NOTICE message. |


// ./IRC 6667 123456789

· i: Set/remove Invite-only channel

· t: Set/remove the restrictions of the TOPIC command to channel operators

· k: Set/remove the channel key (password)

· o: Give/take channel operator privilege

· l: Set/remove the user limit to channel

40 changes: 39 additions & 1 deletion tests/Channel.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#include "Channel.hpp"
# include "Channel.hpp"
# include <sys/socket.h>



/*
** ------------------------------- CONSTRUCTOR --------------------------------
Expand Down Expand Up @@ -52,6 +55,18 @@ std::ostream & operator<<( std::ostream & o, Channel const & i )
** --------------------------------- METHODS ----------------------------------
*/


void Channel::prodcastToChannel(std::string &message, User *client)
{
for (std::vector<User *>::iterator it = _users.begin(); it != _users.end(); it++)
{
User *user = *it;
if (user != client)
send(user->getFd(), message.c_str(), message.size(), 0);
}

}

void Channel::addUser( User *user)
{
_users.push_back(user);
Expand All @@ -62,6 +77,29 @@ void Channel::removeUser(const User *user)
_users.erase(std::remove(_users.begin(), _users.end(), user), _users.end());
}

std::string Channel::getName() const
{
return _name;
}

std::vector<User *> Channel::getUsers() const
{
return _users;
}


int Channel::count_membres() {
return _users.size();
}

std::string Channel::get_topic() {
// Replace with your actual implementation
return _topic; // assuming topic is a string variable holding the topic of the channel
}

void Channel::setTopic(const std::string& newTopic) {
_topic = newTopic;
}

/*
** --------------------------------- ACCESSOR ---------------------------------
Expand Down
78 changes: 77 additions & 1 deletion tests/Channel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,99 @@
# include <string>
# include <vector>
# include "User.hpp"
#include <set>
# include <map> // Add this line

class Channel
{

int userLimit;
bool invite_only;
bool topic_restricted;
std::string key;
std::set<std::string> voice_users;
std::set<std::string> operators;
std::map<std::string, bool> modes;

public:

void setInviteOnly() {
invite_only = true;
}

void removeInviteOnly() {
invite_only = false;
}

bool isInviteOnly() const {
return invite_only;
}

void restrictTopic() {
topic_restricted = true;
}

void removeTopicRestriction() {
topic_restricted = false;
}

bool isTopicRestricted() const {
return topic_restricted;
}

void setKey(const std::string& newKey) {
key = newKey;
}

void removeKey() {
key.clear();
}

const std::string& getKey() const {
return key;
}

void addOperator(const std::string& user) {
operators.insert(user);
}

void removeOperator(const std::string& user) {
operators.erase(user);
}

bool isOperator(const std::string& user) const {
return operators.find(user) != operators.end();
}

void addMode(std::string mode) { modes[mode] = true; } // Add this method
void removeMode(std::string mode) { modes.erase(mode); } // Add this method

void setUserLimit(int limit) { userLimit = limit; } // Add this method
void removeUserLimit() { userLimit = -1; } // Add this method
int getUserLimit() { return userLimit; } // Add this method

Channel();
Channel(const std::string &name);
Channel( Channel const & src );
void addUser( User *user);
void removeUser(const User *user);

std::string getName() const;
std::vector<User *> getUsers() const;

~Channel();

Channel & operator=( Channel const & rhs );

void prodcastToChannel(std::string &message, User *client);

void prodcastToChannel(std::string &message);

int count_membres();
std::string get_topic();
void setTopic(const std::string& newTopic);
private:
std::string _name;
std::string _topic; // new member variable for the topic
std::vector<User *> _users;


Expand Down
Binary file removed tests/IRC
Binary file not shown.
Loading