From da836982d9777f36d3bbf6f387000f2ef02be0ed Mon Sep 17 00:00:00 2001 From: mochaoui Date: Sun, 21 Apr 2024 10:53:49 -0500 Subject: [PATCH] make the invited user if it kicked from the channed and the channel is restrected by the +i need to be invited again to join the channel again --- Server.cpp | 6 ++++-- channel.hpp | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Server.cpp b/Server.cpp index b30b1b5..ef17c08 100644 --- a/Server.cpp +++ b/Server.cpp @@ -754,7 +754,7 @@ void Server::handleClientData(int fd) { std::map::iterator it = channels.find(channelName); if (it != channels.end()) { // Channel already exists - if ((isinveted == 1 && it->second.isInvited(nick)) || it->second.isOperator(fd)) { + if ((isinveted == 1 && channels[channelName].isInvited(nick)) || channels[channelName].isOperator(fd)) { // User is invited, create the channel std::cout << "ha huwa dkhaal l ******** lwla ***********" << std::endl; createChannel(channelName, nick, fd); @@ -823,7 +823,9 @@ void Server::handleClientData(int fd) { if (userFd != -1) { // Kick the user // kickUser(userFd); - channels[channelName].ejectUser(userFd); + channels[channelName].ejectUserfromusers(userFd); + channels[channelName].ejectUserfromivited(userToKick); + // isinveted = 0; std::string kickMessage = ":" + channels[channelName].getNickname(fd) + " KICK #" + channelName + " " + userToKick + " :" + reason + "\n"; smallbroadcastMessagefortheckick(channels[channelName].getNickname(fd), channelName, userToKick, reason); send(fd, kickMessage.c_str(), kickMessage.length(), 0); diff --git a/channel.hpp b/channel.hpp index ecd898d..75920c5 100644 --- a/channel.hpp +++ b/channel.hpp @@ -130,7 +130,7 @@ public: } - void ejectUser(int fd) { + void ejectUserfromusers(int fd) { // Iterate over the map to find the user with the given file descriptor std::map::iterator it; for (it = userFdMap.begin(); it != userFdMap.end(); ++it) { @@ -143,6 +143,19 @@ public: } } + void ejectUserfromivited(std::string nickname) { + // Iterate over the map to find the user with the given file descriptor + std::map::iterator it; + for (it = invitedUsers.begin(); it != invitedUsers.end(); ++it) { + if (it->first == nickname) { + // Erase the user from the map + invitedUsers.erase(it); + std::cout << "the user earased " << std::endl; + return; // Exit the function after removing the user + } + } +} + std::string getOperatorNickname(int fd) const { std::map::const_iterator it; for (it = operators.begin(); it != operators.end(); ++it) {