the password mode is working, and the invite mode bug is fixed

This commit is contained in:
Mmokane
2024-04-21 20:55:31 +01:00
parent 7440b0c891
commit 11789fe633
3 changed files with 63 additions and 62 deletions

56
.vscode/settings.json vendored
View File

@@ -1,56 +0,0 @@
{
"files.associations": {
"ostream": "cpp",
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"*.tcc": "cpp",
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"compare": "cpp",
"concepts": "cpp",
"csignal": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"string": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"optional": "cpp",
"random": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"initializer_list": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"new": "cpp",
"numbers": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"cinttypes": "cpp",
"typeinfo": "cpp",
"map": "cpp",
"sstream": "cpp",
"ctime": "cpp",
"iomanip": "cpp"
}
}

View File

@@ -3,6 +3,7 @@ int a = 0;
int opperatorfd = 0; int opperatorfd = 0;
int issettop = 0; int issettop = 0;
int isinveted = 0; int isinveted = 0;
int itHasPass = 0;
bool Server::_signal = false; bool Server::_signal = false;
@@ -759,9 +760,14 @@ void Server::handleClientData(int fd) {
break; break;
} }
} }
std::string channelName, pass ;
std::string channelName = command.substr(6); // std::string channelName = command.substr(6);
std::istringstream iss(command.substr(5));
iss >> channelName ;
channelName = channelName.substr(1);
channelName = trim(channelName); channelName = trim(channelName);
std::getline(iss, pass);
pass = trim(pass);
// Check if the channel already exists // Check if the channel already exists
std::map<std::string, Channel>::iterator it = channels.find(channelName); std::map<std::string, Channel>::iterator it = channels.find(channelName);
@@ -774,15 +780,27 @@ void Server::handleClientData(int fd) {
} }
else if (isinveted == 0){ else if (isinveted == 0){
std::cout << "ha huwa dkhaal l ******** ltania ***********" << std::endl; std::cout << "ha huwa dkhaal l ******** ltania ***********" << std::endl;
std::cout << "this is the geted pass " << channels[channelName].getPass() << std::endl;
std::cout << "IM PASS " << pass << std::endl;
std::cout << "PASS MODE IS ON" << std::endl;
if (itHasPass == 1 && channels[channelName].getPass() == pass)
createChannel(channelName, nick, fd); createChannel(channelName, nick, fd);
else if (itHasPass == 0)
createChannel(channelName, nick, fd);
else if (itHasPass == 1 && channels[channelName].getPass() != pass)
std::cout << "ZAPI " << std::endl;
} }
else { else {
// User is not invited, send error message // User is not invited, send error message
std::string errorMessage = ":server.host NOTICE " + nick + " :Error: you are not invited\r\n"; std::string errorMessage = ":server.host NOTICE " + nick + " :Error: you are not invited\r\n";
send(fd, errorMessage.c_str(), errorMessage.length(), 0); send(fd, errorMessage.c_str(), errorMessage.length(), 0);
} }
} else {
}
else
{
std::cout << "ha huwa dkhal l ********* tania *********** " << std::endl; std::cout << "ha huwa dkhal l ********* tania *********** " << std::endl;
// Channel does not exist, create the channel // Channel does not exist, create the channel
@@ -992,9 +1010,38 @@ void Server::handleClientData(int fd) {
send(fd, errorMessage.c_str(), errorMessage.size(), 0); send(fd, errorMessage.c_str(), errorMessage.size(), 0);
} }
} }
else if (mode == "-t") else if (mode == "-k")
{ {
std::string ChanPass = (mode.substr(2));
if (channels.find(channelName) != channels.end() && channels[channelName].isOperator(fd)){
std::string modeChangeMessage = ":server.host MODE #" + channelName + " -k by " + channels[channelName].getNickname(fd) + "\n";
send(fd, modeChangeMessage.c_str(), modeChangeMessage.size(), 0);
smallbroadcastMOOD(channels[channelName].getNickname(fd), channelName, mode, nick);
itHasPass = 0;
}
else
{
std::string errorMessage = ":" + channels[channelName].getNickname(fd) + " PRIVMSG #" + channelName + " :Error7: You are not authorized to execute this command " + "\r\n";
send(fd, errorMessage.c_str(), errorMessage.size(), 0);
}
}
else if (mode == "+k")
{
// std::string ChanPass = (mo.substr(2));
nick = trim(nick);
std::cout << "HI IM TRIMMED PASS " << nick << std::endl;
channels[channelName].setPass(nick);
if (channels.find(channelName) != channels.end() && channels[channelName].isOperator(fd)){
std::string modeChangeMessage = ":server.host MODE #" + channelName + " +k by " + channels[channelName].getNickname(fd) + "\n";
send(fd, modeChangeMessage.c_str(), modeChangeMessage.size(), 0);
smallbroadcastMOOD(channels[channelName].getNickname(fd), channelName, mode, nick);
itHasPass = 1;
}
else
{
std::string errorMessage = ":" + channels[channelName].getNickname(fd) + " PRIVMSG #" + channelName + " :Error8: You are not authorized to execute this command " + "\r\n";
send(fd, errorMessage.c_str(), errorMessage.size(), 0);
}
} }
} }
//**************** STOOOOOOP HERE TOP G ... //**************** STOOOOOOP HERE TOP G ...

View File

@@ -25,6 +25,7 @@ private:
std::string topic; std::string topic;
std::string key; std::string key;
std::vector<std::string> users; std::vector<std::string> users;
std::string pass;
// std::map<int, std::string> nicknames; // Replace unordered_map with map // std::map<int, std::string> nicknames; // Replace unordered_map with map
std::map<std::string, int> userFdMap; // Mapping of usernames to file descriptors std::map<std::string, int> userFdMap; // Mapping of usernames to file descriptors
std::map<std::string, int> invitedUsers; std::map<std::string, int> invitedUsers;
@@ -45,12 +46,21 @@ public:
topic = newTopic; topic = newTopic;
} }
void setPass(const std::string &Newpass)
{
pass = Newpass;
}
// Get topic function // Get topic function
std::string getTopic() const { std::string getTopic() const {
return topic; return topic;
} }
std::string getPass()
{
return pass;
}
void addClient(const std::string& client, int fd) { void addClient(const std::string& client, int fd) {
userFdMap[client] = fd; userFdMap[client] = fd;
} }