Starting Channel class
This commit is contained in:
60
Channel/Channel.cpp
Normal file
60
Channel/Channel.cpp
Normal 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
35
Channel/Channel.hpp
Normal 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
|
||||||
2
Makefile
2
Makefile
@@ -1,7 +1,9 @@
|
|||||||
NAME = ircserv
|
NAME = ircserv
|
||||||
|
|
||||||
SRC = main.cpp Server/Server.cpp Client/Client.cpp \
|
SRC = main.cpp Server/Server.cpp Client/Client.cpp \
|
||||||
|
Channel/Channel.cpp \
|
||||||
commands/pass.cpp commands/nick.cpp commands/user.cpp \
|
commands/pass.cpp commands/nick.cpp commands/user.cpp \
|
||||||
|
commands/join.cpp
|
||||||
|
|
||||||
|
|
||||||
OBJ = $(SRC:.cpp=.o)
|
OBJ = $(SRC:.cpp=.o)
|
||||||
|
|||||||
@@ -20,11 +20,12 @@
|
|||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
# include <vector>
|
# include <vector>
|
||||||
# include <poll.h>
|
# include <poll.h>
|
||||||
|
|
||||||
# include "../Client/Client.hpp"
|
|
||||||
# include <map>
|
# include <map>
|
||||||
# include <sstream>
|
# include <sstream>
|
||||||
|
|
||||||
|
# include "../Client/Client.hpp"
|
||||||
|
# include "../Channel/Channel.hpp"
|
||||||
|
|
||||||
class Server
|
class Server
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
@@ -33,17 +34,25 @@ class Server
|
|||||||
int server_fd;
|
int server_fd;
|
||||||
std::vector<pollfd> fds;
|
std::vector<pollfd> fds;
|
||||||
std::map<int, Client> clients;
|
std::map<int, Client> clients;
|
||||||
|
std::map<std::string, Channel> channels;
|
||||||
|
|
||||||
void acceptClient();
|
void acceptClient();
|
||||||
void readClient(int fd);
|
void readClient(int fd);
|
||||||
void removeClient(int fd);
|
void removeClient(int fd);
|
||||||
|
|
||||||
|
void addChannel(std::string name);
|
||||||
|
void deleteChannel();
|
||||||
|
|
||||||
void parseCommand(int fd, std::string line);
|
void parseCommand(int fd, std::string line);
|
||||||
|
|
||||||
void cmd_pass(int fd, std::istringstream &ss);
|
void cmd_pass(int fd, std::istringstream &ss);
|
||||||
void cmd_nick(int fd, std::istringstream &ss);
|
void cmd_nick(int fd, std::istringstream &ss);
|
||||||
void cmd_user(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:
|
public:
|
||||||
Server();
|
Server();
|
||||||
Server(int port, std::string password);
|
Server(int port, std::string password);
|
||||||
|
|||||||
35
commands/join.cpp
Normal file
35
commands/join.cpp
Normal 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
0
commands/part.cpp
Normal file
0
commands/privmsg.cpp
Normal file
0
commands/privmsg.cpp
Normal file
Reference in New Issue
Block a user