From 905227811eaa798deabb4a7267fea428bbe8fcbe Mon Sep 17 00:00:00 2001 From: PrStein Date: Thu, 23 Feb 2023 20:36:01 +0100 Subject: [PATCH] modification mode k --- srcs/commands/channel_op/mode.cpp | 52 +++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/srcs/commands/channel_op/mode.cpp b/srcs/commands/channel_op/mode.cpp index 34eab32..a8d29c8 100644 --- a/srcs/commands/channel_op/mode.cpp +++ b/srcs/commands/channel_op/mode.cpp @@ -6,11 +6,12 @@ /* By: sadjigui +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 int search_and_erase(std::string &str, std::string toFind) { @@ -27,19 +28,28 @@ int search_and_erase(std::string &str, std::string toFind) return 1; } -int ft_stoi(std::string str) +bool str_to_int(int &i, const std::string s) { - int i = 0; - int result = 0; - - while (str[i] >= '0' && str[i] <= '9') - { - result = result * 10 +str[i] - 48; - i++; - } - return result; + std::stringstream ss(s); + ss >> i; + if (ss.fail()) + return false; + return true; } +// int ft_stoi(std::string str) +// { +// int i = 0; +// int result = 0; + +// 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)allFds; @@ -101,6 +111,18 @@ void chan_opt_o(fdList &allFds, int userNbr, std::vector opt, int c std::cout << "-------> " << opt[3] << std::endl; } +void chan_opt_k(fdList &allFds, std::vector opt, int chanNbr, bool sign) +{ + if (opt.size() != 4) + { + std::cout << "ERR_NEEDMOREPARAMS" << std::endl; + std::cout << "how to use it :/MODE +k " << std::endl; + return ; + } + if (sign == true) + allFds.channelList[chanNbr].password = opt[3]; +} + void do_chan_opt(fdList &allFds, int userNbr, std::vector opt, int chanNbr /*, channel (string or direct reference or pointer but no copy)*/) { (void)allFds; @@ -133,17 +155,15 @@ void do_chan_opt(fdList &allFds, int userNbr, std::vector opt, int break ; case 6: if (sign == true) - allFds.channelList[chanNbr].maxUser = ft_stoi(opt[3]); + str_to_int(allFds.channelList[chanNbr].maxUser, opt[3]); break ; case 7: std::cout << "launching option: " << opt[2][i] << std::endl; break ; case 8: std::cout << "launching option: " << opt[2][i] << std::endl; break ; - case 9: std::cout << "launching option: " << opt[2][i] << std::endl; + case 9: std::cout << "launching option: v " << std::endl; break ; - case 10: - if (sign == true) - allFds.channelList[chanNbr].password = opt[3]; + case 10: chan_opt_k(allFds, opt, chanNbr, sign); break ; default : std::cout << "Not launching option" << std::endl; break ;