mode -o done

This commit is contained in:
mochaoui
2024-04-20 11:31:23 -05:00
parent a1103a37be
commit 52e093f725
2 changed files with 45 additions and 0 deletions

View File

@@ -802,6 +802,38 @@ void Server::handleClientData(int fd) {
send(fd, errorMessage.c_str(), errorMessage.size(), 0); send(fd, errorMessage.c_str(), errorMessage.size(), 0);
} }
} }
else if (startsWith(command, "MODE "))
{
std::string channelName, mode , nick;
std::istringstream iss(command.substr(6));
iss >> channelName >> mode >> nick;
channelName = trim(channelName);
mode = trim(mode);
nick = trim(nick);
std::cout << "this is the mode : " << mode << std::endl;
if (mode == "+o")
{
if (channels.find(channelName) != channels.end() && channels[channelName].isOperator(fd)) {
channels[channelName].addOperator(nick, channels[channelName].getUserFd(nick));
std::string modeMessage = ":" + nick + " MODE #" + channelName + " +o " + nick + "\n";
send(fd, modeMessage.c_str(), modeMessage.length(), 0);
}
}
else if (mode == "-o")
{
if (channels.find(channelName) != channels.end() && channels[channelName].isOperator(fd)) {
channels[channelName].removeOperator(nick);
std::string modeMessage = ":" + nick + " MODE #" + channelName + " -o " + nick + "\n";
send(fd, modeMessage.c_str(), modeMessage.length(), 0);
}
}
// else if (mode == "-i")
// {
// }
}
//**************** STOOOOOOP HERE TOP G ... //**************** STOOOOOOP HERE TOP G ...
break; break;

View File

@@ -142,6 +142,19 @@ std::string getOperatorNickname(int fd) const {
return ""; // Return empty string if operator not found return ""; // Return empty string if operator not found
} }
void removeOperator(const std::string& operatorName )
{
// Iterate through the map to find the operator
std::map<std::string, int>::iterator it;
for (it = operators.begin(); it != operators.end(); ++it) {
if (it->first == operatorName) {
// Erase the operator from the map
operators.erase(it);
return; // Exit the function after removing the operator
}
}
}
// Remove an operator from the channel // Remove an operator from the channel
}; };