This commit is contained in:
aortigos
2026-04-19 01:47:20 +02:00
parent 1c8ad9ba68
commit 94028a5215
7 changed files with 58 additions and 7 deletions

View File

@@ -57,4 +57,14 @@ void Channel::removeMember(int fd)
std::vector<int> Channel::getMembers() const
{
return (this->members);
}
bool Channel::isMember(int fd) const
{
for (size_t i = 0; i < members.size(); i++)
{
if (members[i] == fd)
return (true);
}
return (false);
}

View File

@@ -30,6 +30,8 @@ class Channel
void addMember(int fd);
void removeMember(int fd);
std::vector<int> getMembers() const;
bool isMember(int fd) const;
};
#endif

View File

@@ -3,7 +3,8 @@ 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 commands/privmsg.cpp
commands/join.cpp commands/privmsg.cpp \
commands/part.cpp
OBJ = $(SRC:.cpp=.o)

View File

@@ -160,4 +160,6 @@ void Server::parseCommand(int fd, std::string line)
cmd_join(fd, ss);
else if (command == "PRIVMSG")
cmd_privmsg(fd, ss);
else if (command == "PART")
cmd_part(fd, ss);
}

View File

@@ -6,7 +6,7 @@
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/04/17 16:26:18 by aortigos #+# #+# */
/* Updated: 2026/04/17 18:54:46 by aortigos ### ########.fr */
/* Updated: 2026/04/19 01:37:10 by aortigos ### ########.fr */
/* */
/* ************************************************************************** */
@@ -38,8 +38,5 @@ void Server::cmd_join(int fd, std::istringstream &ss)
std::string msg = "Channel already exists\r\n";
send(fd, msg.c_str(), msg.size(), 0);
return ;
}
}

View File

@@ -0,0 +1,39 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* part.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/04/19 01:31:40 by aortigos #+# #+# */
/* Updated: 2026/04/19 01:44:14 by aortigos ### ########.fr */
/* */
/* ************************************************************************** */
#include "../Server/Server.hpp"
void Server::cmd_part(int fd, std::istringstream &ss)
{
std::string args;
ss >> args;
if (!clients[fd].isRegistered())
{
std::string msg = "You are not registered\r\n";
send(fd, msg.c_str(), msg.size(), 0);
return ;
}
if (channels.find(args) != channels.end() && channels[args].isMember(fd))
{
channels[args].removeMember(fd);
std::string msg = "You left the channel\r\n";
send(fd, msg.c_str(), msg.size(), 0);
} else {
std::string msg = "You dont belong to this channel\r\n";
send(fd, msg.c_str(), msg.size(), 0);
}
}

View File

@@ -6,7 +6,7 @@
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/04/17 19:02:55 by aortigos #+# #+# */
/* Updated: 2026/04/17 19:11:54 by aortigos ### ########.fr */
/* Updated: 2026/04/19 01:45:32 by aortigos ### ########.fr */
/* */
/* ************************************************************************** */
@@ -19,7 +19,7 @@ void Server::cmd_privmsg(int fd, std::istringstream &ss)
ss >> channel;
std::getline(ss, message);
message += "\r\n"
message += "\r\n";
std::vector<int> members = channels[channel].getMembers();