Starting Channel class

This commit is contained in:
aortigos
2026-04-17 18:43:52 +02:00
parent c84178c9bc
commit 4faa83eb89
7 changed files with 148 additions and 7 deletions

60
Channel/Channel.cpp Normal file
View File

@@ -0,0 +1,60 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Channel.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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<int> Channel::getMembers() const
{
return (this->members);
}

35
Channel/Channel.hpp Normal file
View File

@@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Channel.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <iostream>
# include <vector>
class Channel
{
private:
std::string name;
std::vector<int> members;
public:
Channel();
Channel(std::string name);
~Channel();
std::string getName() const;
void addMember(int fd);
void removeMember(int fd);
std::vector<int> getMembers() const;
};
#endif

View File

@@ -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)

View File

@@ -20,30 +20,39 @@
# include <unistd.h>
# include <vector>
# include <poll.h>
# include "../Client/Client.hpp"
# include <map>
# include <sstream>
# include "../Client/Client.hpp"
# include "../Channel/Channel.hpp"
class Server
{
private:
int port;
std::string password;
int server_fd;
std::vector<pollfd> fds;
std::map<int, Client> clients;
int port;
std::string password;
int server_fd;
std::vector<pollfd> fds;
std::map<int, Client> clients;
std::map<std::string, Channel> 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);

35
commands/join.cpp Normal file
View File

@@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* join.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/04/17 16:26:18 by aortigos #+# #+# */
/* Updated: 2026/04/17 18:43:39 by aortigos ### ########.fr */
/* */
/* ************************************************************************** */
#include "../Server/Server.hpp"
void Server::cmd_join(int fd, std::istringstream &ss)
{
std::string args;
ss >> 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 {
}
}

0
commands/part.cpp Normal file
View File

0
commands/privmsg.cpp Normal file
View File