From b7487c193dd02243c5e2ecc6faa792b11d51477f Mon Sep 17 00:00:00 2001 From: aortigos Date: Fri, 15 May 2026 22:07:05 +0200 Subject: [PATCH] Doing join command --- Channel/Channel.cpp | 14 ++++---------- Channel/Channel.hpp | 6 +++--- Makefile | 2 ++ Server/Server.cpp | 3 ++- Server/Server.hpp | 3 ++- cmds/join.cpp | 22 +++++++++++++++++++++- 6 files changed, 34 insertions(+), 16 deletions(-) diff --git a/Channel/Channel.cpp b/Channel/Channel.cpp index 0603b5f..104fec5 100644 --- a/Channel/Channel.cpp +++ b/Channel/Channel.cpp @@ -41,11 +41,11 @@ 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) { /* std::cout << "Channel with name constructor called" << std::endl; */ } // Getters -std::string Channel::getName() const { return (this->name); } +std::string Channel::getName() const { return (this->name_); } // Members void Channel::addMember(int fd) { this->members_.insert(fd); } @@ -57,13 +57,7 @@ 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& clients_, int excludeFd) +void Channel::broadcast() { - for(std::set::iterator it = members_.begin(); it != members_.end(); it++) - { - if (*it == excludeFd) continue; - std::map::const_iterator user = clients_.find(*it); - if (user != client_.end()) - user->second.send(msg); - } + return ; } \ No newline at end of file diff --git a/Channel/Channel.hpp b/Channel/Channel.hpp index a62aea5..60202b3 100644 --- a/Channel/Channel.hpp +++ b/Channel/Channel.hpp @@ -29,14 +29,14 @@ class Channel public: Channel(); - Channel(std::string name); + Channel(std::string &name); Channel(const Channel &other); Channel& operator=(const Channel &other); ~Channel(); // Getters - std::string getName() const { return (this->name); } + std::string getName() const; // Users @@ -49,7 +49,7 @@ class Channel void removeOperator(int fd); bool hasOperator(int fd) const; - void broadcast(const std::string &msg, const std::map& clients_, int excludeFd); + void broadcast(); }; diff --git a/Makefile b/Makefile index dd2a42d..5b956c1 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,9 @@ NAME = ircserv SRC = main.cpp Server/Server.cpp User/User.cpp \ + Channel/Channel.cpp \ cmds/pass.cpp cmds/nick.cpp cmds/user.cpp \ + cmds/join.cpp HEADERS = Server/Server.hpp User/User.hpp diff --git a/Server/Server.cpp b/Server/Server.cpp index fe8065a..865b4c1 100644 --- a/Server/Server.cpp +++ b/Server/Server.cpp @@ -6,7 +6,7 @@ /* By: aortigos > args; + if (!client.isRegistered()) return (client.send("You are not registered")); + if (args.empty()) return (client.send("No name specified\r\n")); + std::map::iterator it = channels_.find(args); + + if (it == channels_.end()) + { + // Channel doesnt exists, create and join + channels_[args] = Channel(args); + channels_[args].addMember(client.getFd()); + channels_[args].addOperator(client.getFd()); + return (client.send("Channel created\r\n")); + } + else + { + if (it->second.hasMember(client.getFd())) return (client.send("You are already in this channel\r\n")); + it->second.addMember(client.getFd()); + } }