From 4faa83eb893c64c8f60c42c665848ca9abcf9702 Mon Sep 17 00:00:00 2001 From: aortigos Date: Fri, 17 Apr 2026 18:43:52 +0200 Subject: [PATCH] Starting Channel class --- Channel/Channel.cpp | 60 ++++++++++++++++++++++++++++++++++++++++++++ Channel/Channel.hpp | 35 ++++++++++++++++++++++++++ Makefile | 2 ++ Server/Server.hpp | 23 +++++++++++------ commands/join.cpp | 35 ++++++++++++++++++++++++++ commands/part.cpp | 0 commands/privmsg.cpp | 0 7 files changed, 148 insertions(+), 7 deletions(-) create mode 100644 Channel/Channel.cpp create mode 100644 Channel/Channel.hpp create mode 100644 commands/join.cpp create mode 100644 commands/part.cpp create mode 100644 commands/privmsg.cpp diff --git a/Channel/Channel.cpp b/Channel/Channel.cpp new file mode 100644 index 0000000..47e9e45 --- /dev/null +++ b/Channel/Channel.cpp @@ -0,0 +1,60 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Channel.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2026/04/17 14:36:43 by aortigos #+# #+# */ +/* Updated: 2026/04/17 14:36:43 by aortigos ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Channel.hpp" + +////////////////// +// Constructors // +////////////////// + +Channel::Channel() +{ + // std::cout << "Channel default constructor called" << std::endl; +} + +Channel::Channel(std::string name) : name(name) +{ + +} + +Channel::~Channel() +{ + // std::cout << "Channel destructor called" << std::endl; +} + + +std::string Channel::getName() const +{ + return (this->name); +} + +void Channel::addMember(int fd) +{ + this->members.push_back(fd); +} + +void Channel::removeMember(int fd) +{ + for (size_t i = 0; i < this->members.size(); i++) + { + if (this->members[i] == fd) + { + members.erase(members.begin() + 1); + return ; + } + } +} + +std::vector Channel::getMembers() const +{ + return (this->members); +} \ No newline at end of file diff --git a/Channel/Channel.hpp b/Channel/Channel.hpp new file mode 100644 index 0000000..4958d2a --- /dev/null +++ b/Channel/Channel.hpp @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Channel.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2026/04/17 14:36:43 by aortigos #+# #+# */ +/* Updated: 2026/04/17 14:36:43 by aortigos ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef CHANNEL_HPP +# define CHANNEL_HPP + +# include +# include + +class Channel +{ + private: + std::string name; + std::vector members; + public: + Channel(); + Channel(std::string name); + ~Channel(); + + std::string getName() const; + void addMember(int fd); + void removeMember(int fd); + std::vector getMembers() const; +}; + +#endif diff --git a/Makefile b/Makefile index b749a96..6092931 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,9 @@ NAME = ircserv SRC = main.cpp Server/Server.cpp Client/Client.cpp \ + Channel/Channel.cpp \ commands/pass.cpp commands/nick.cpp commands/user.cpp \ + commands/join.cpp OBJ = $(SRC:.cpp=.o) diff --git a/Server/Server.hpp b/Server/Server.hpp index 7fd67f5..4e46dbb 100644 --- a/Server/Server.hpp +++ b/Server/Server.hpp @@ -20,30 +20,39 @@ # include # include # include - -# include "../Client/Client.hpp" # include # include +# include "../Client/Client.hpp" +# include "../Channel/Channel.hpp" + class Server { private: - int port; - std::string password; - int server_fd; - std::vector fds; - std::map clients; + int port; + std::string password; + int server_fd; + std::vector fds; + std::map clients; + std::map channels; void acceptClient(); void readClient(int fd); void removeClient(int fd); + void addChannel(std::string name); + void deleteChannel(); + void parseCommand(int fd, std::string line); void cmd_pass(int fd, std::istringstream &ss); void cmd_nick(int fd, std::istringstream &ss); void cmd_user(int fd, std::istringstream &ss); + void cmd_join(int fd, std::istringstream &ss); + void cmd_privmsg(int fd, std::istringstream &ss); + void cmd_part(int fd, std::istringstream &ss); + public: Server(); Server(int port, std::string password); diff --git a/commands/join.cpp b/commands/join.cpp new file mode 100644 index 0000000..ebe8129 --- /dev/null +++ b/commands/join.cpp @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* join.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos > args; + + if (!clients[fd].isRegistered()) + { + std::string msg = "You are not registered"; + send(fd, msg.c_str(), msg.size(), 0); + } + + if (channels.find(channelName) == channels.end()) + { + + } else { + + } + + +} \ No newline at end of file diff --git a/commands/part.cpp b/commands/part.cpp new file mode 100644 index 0000000..e69de29 diff --git a/commands/privmsg.cpp b/commands/privmsg.cpp new file mode 100644 index 0000000..e69de29