part cmd
This commit is contained in:
@@ -58,3 +58,13 @@ std::vector<int> Channel::getMembers() const
|
|||||||
{
|
{
|
||||||
return (this->members);
|
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);
|
||||||
|
}
|
||||||
@@ -30,6 +30,8 @@ class Channel
|
|||||||
void addMember(int fd);
|
void addMember(int fd);
|
||||||
void removeMember(int fd);
|
void removeMember(int fd);
|
||||||
std::vector<int> getMembers() const;
|
std::vector<int> getMembers() const;
|
||||||
|
|
||||||
|
bool isMember(int fd) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
3
Makefile
3
Makefile
@@ -3,7 +3,8 @@ NAME = ircserv
|
|||||||
SRC = main.cpp Server/Server.cpp Client/Client.cpp \
|
SRC = main.cpp Server/Server.cpp Client/Client.cpp \
|
||||||
Channel/Channel.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 commands/privmsg.cpp
|
commands/join.cpp commands/privmsg.cpp \
|
||||||
|
commands/part.cpp
|
||||||
|
|
||||||
|
|
||||||
OBJ = $(SRC:.cpp=.o)
|
OBJ = $(SRC:.cpp=.o)
|
||||||
|
|||||||
@@ -160,4 +160,6 @@ void Server::parseCommand(int fd, std::string line)
|
|||||||
cmd_join(fd, ss);
|
cmd_join(fd, ss);
|
||||||
else if (command == "PRIVMSG")
|
else if (command == "PRIVMSG")
|
||||||
cmd_privmsg(fd, ss);
|
cmd_privmsg(fd, ss);
|
||||||
|
else if (command == "PART")
|
||||||
|
cmd_part(fd, ss);
|
||||||
}
|
}
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2026/04/17 16:26:18 by aortigos #+# #+# */
|
/* 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";
|
std::string msg = "Channel already exists\r\n";
|
||||||
send(fd, msg.c_str(), msg.size(), 0);
|
send(fd, msg.c_str(), msg.size(), 0);
|
||||||
|
|
||||||
return ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2026/04/17 19:02:55 by aortigos #+# #+# */
|
/* 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;
|
ss >> channel;
|
||||||
std::getline(ss, message);
|
std::getline(ss, message);
|
||||||
message += "\r\n"
|
message += "\r\n";
|
||||||
|
|
||||||
std::vector<int> members = channels[channel].getMembers();
|
std::vector<int> members = channels[channel].getMembers();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user