modification mode k

This commit is contained in:
PrStein 2023-02-23 20:36:01 +01:00
parent 8754b6ab9c
commit 905227811e

View File

@ -6,11 +6,12 @@
/* By: sadjigui <sadjigui@student.42.fr> +#+ +:+ +#+ */ /* By: sadjigui <sadjigui@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/11 19:19:30 by apommier #+# #+# */ /* Created: 2023/02/11 19:19:30 by apommier #+# #+# */
/* Updated: 2023/02/23 00:41:10 by sadjigui ### ########.fr */ /* Updated: 2023/02/23 20:35:05 by sadjigui ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "../../../includes/ft_irc.hpp" #include "../../../includes/ft_irc.hpp"
#include <sstream>
int search_and_erase(std::string &str, std::string toFind) int search_and_erase(std::string &str, std::string toFind)
{ {
@ -27,18 +28,27 @@ int search_and_erase(std::string &str, std::string toFind)
return 1; return 1;
} }
int ft_stoi(std::string str) bool str_to_int(int &i, const std::string s)
{ {
int i = 0; std::stringstream ss(s);
int result = 0; ss >> i;
if (ss.fail())
return false;
return true;
}
while (str[i] >= '0' && str[i] <= '9') // int ft_stoi(std::string str)
{ // {
result = result * 10 +str[i] - 48; // int i = 0;
i++; // int result = 0;
}
return result; // while (str[i] >= '0' && str[i] <= '9')
} // {
// result = result * 10 +str[i] - 48;
// i++;
// }
// return result;
// }
// void exec_chan_opt(fdList &allFds, char opt, bool sign) // void exec_chan_opt(fdList &allFds, char opt, bool sign)
// { // {
@ -101,6 +111,18 @@ void chan_opt_o(fdList &allFds, int userNbr, std::vector<std::string> opt, int c
std::cout << "-------> " << opt[3] << std::endl; std::cout << "-------> " << opt[3] << std::endl;
} }
void chan_opt_k(fdList &allFds, std::vector<std::string> opt, int chanNbr, bool sign)
{
if (opt.size() != 4)
{
std::cout << "ERR_NEEDMOREPARAMS" << std::endl;
std::cout << "how to use it :/MODE +k <password>" << std::endl;
return ;
}
if (sign == true)
allFds.channelList[chanNbr].password = opt[3];
}
void do_chan_opt(fdList &allFds, int userNbr, std::vector<std::string> opt, int chanNbr /*, channel (string or direct reference or pointer but no copy)*/) void do_chan_opt(fdList &allFds, int userNbr, std::vector<std::string> opt, int chanNbr /*, channel (string or direct reference or pointer but no copy)*/)
{ {
(void)allFds; (void)allFds;
@ -133,17 +155,15 @@ void do_chan_opt(fdList &allFds, int userNbr, std::vector<std::string> opt, int
break ; break ;
case 6: case 6:
if (sign == true) if (sign == true)
allFds.channelList[chanNbr].maxUser = ft_stoi(opt[3]); str_to_int(allFds.channelList[chanNbr].maxUser, opt[3]);
break ; break ;
case 7: std::cout << "launching option: " << opt[2][i] << std::endl; case 7: std::cout << "launching option: " << opt[2][i] << std::endl;
break ; break ;
case 8: std::cout << "launching option: " << opt[2][i] << std::endl; case 8: std::cout << "launching option: " << opt[2][i] << std::endl;
break ; break ;
case 9: std::cout << "launching option: " << opt[2][i] << std::endl; case 9: std::cout << "launching option: v " << std::endl;
break ; break ;
case 10: case 10: chan_opt_k(allFds, opt, chanNbr, sign);
if (sign == true)
allFds.channelList[chanNbr].password = opt[3];
break ; break ;
default : std::cout << "Not launching option" << std::endl; default : std::cout << "Not launching option" << std::endl;
break ; break ;