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

This commit is contained in:
mochaoui
2024-04-21 10:53:49 -05:00
parent a8b3f537c2
commit da836982d9
2 changed files with 18 additions and 3 deletions

View File

@@ -754,7 +754,7 @@ void Server::handleClientData(int fd) {
std::map<std::string, Channel>::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);

View File

@@ -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<std::string, int>::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<std::string, int>::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<std::string, int>::const_iterator it;
for (it = operators.begin(); it != operators.end(); ++it) {