From 94028a5215581cde75a00437989ea48deee91a82 Mon Sep 17 00:00:00 2001 From: aortigos Date: Sun, 19 Apr 2026 01:47:20 +0200 Subject: [PATCH] part cmd --- Channel/Channel.cpp | 10 ++++++++++ Channel/Channel.hpp | 2 ++ Makefile | 3 ++- Server/Server.cpp | 2 ++ commands/join.cpp | 5 +---- commands/part.cpp | 39 +++++++++++++++++++++++++++++++++++++++ commands/privmsg.cpp | 4 ++-- 7 files changed, 58 insertions(+), 7 deletions(-) diff --git a/Channel/Channel.cpp b/Channel/Channel.cpp index 47e9e45..fe29fda 100644 --- a/Channel/Channel.cpp +++ b/Channel/Channel.cpp @@ -57,4 +57,14 @@ void Channel::removeMember(int fd) std::vector 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); } \ No newline at end of file diff --git a/Channel/Channel.hpp b/Channel/Channel.hpp index 4958d2a..759a4f5 100644 --- a/Channel/Channel.hpp +++ b/Channel/Channel.hpp @@ -30,6 +30,8 @@ class Channel void addMember(int fd); void removeMember(int fd); std::vector getMembers() const; + + bool isMember(int fd) const; }; #endif diff --git a/Makefile b/Makefile index 9bcaac3..c587bed 100644 --- a/Makefile +++ b/Makefile @@ -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) diff --git a/Server/Server.cpp b/Server/Server.cpp index 2bded9b..768d6b1 100644 --- a/Server/Server.cpp +++ b/Server/Server.cpp @@ -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); } \ No newline at end of file diff --git a/commands/join.cpp b/commands/join.cpp index f2c975d..0580ff6 100644 --- a/commands/join.cpp +++ b/commands/join.cpp @@ -6,7 +6,7 @@ /* By: aortigos > 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); + } +} \ No newline at end of file diff --git a/commands/privmsg.cpp b/commands/privmsg.cpp index 23f6773..574c4c8 100644 --- a/commands/privmsg.cpp +++ b/commands/privmsg.cpp @@ -6,7 +6,7 @@ /* By: aortigos > channel; std::getline(ss, message); - message += "\r\n" + message += "\r\n"; std::vector members = channels[channel].getMembers();