From cd455bf3f6f7b2f9893e4892c077455c2a68c33b Mon Sep 17 00:00:00 2001 From: Namonay Date: Mon, 29 Jan 2024 21:20:02 +0100 Subject: [PATCH] gg --- Makefile | 2 +- includes/client.hpp | 3 ++- srcs/channel.cpp | 6 +++++- srcs/client.cpp | 13 ++++++++++++- srcs/server_functions.cpp | 4 ++-- srcs_bonus/main.cpp | 31 +++++++++++++++++++++++++++++++ 6 files changed, 53 insertions(+), 6 deletions(-) create mode 100644 srcs_bonus/main.cpp diff --git a/Makefile b/Makefile index dc89e0d..b31aa0d 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: vvaas +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2023/08/09 15:08:49 by vavaas #+# #+# # -# Updated: 2024/01/25 15:22:06 by maldavid ### ########.fr # +# Updated: 2024/01/29 20:44:32 by vvaas ### ########.fr # # # #******************************************************************************# diff --git a/includes/client.hpp b/includes/client.hpp index 62257ee..e381c0a 100644 --- a/includes/client.hpp +++ b/includes/client.hpp @@ -6,7 +6,7 @@ /* By: vvaas +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/21 10:33:17 by maldavid #+# #+# */ -/* Updated: 2024/01/26 00:58:20 by vvaas ### ########.fr */ +/* Updated: 2024/01/29 21:16:38 by vvaas ### ########.fr */ /* */ /******************************************************************************/ @@ -55,6 +55,7 @@ namespace irc void sendCode(const std::string& code, const std::string& msg0, const std::string& msg1); void sendMsg(const std::string& sender, const std::string& cmd, const std::string& trailing); void sendModular(std::string message, ...); + void sendCodeInChannel(const std::string& code, const class Channel &chan, const std::string& msg); ~Client(); diff --git a/srcs/channel.cpp b/srcs/channel.cpp index 4b265ad..6fc86d1 100644 --- a/srcs/channel.cpp +++ b/srcs/channel.cpp @@ -6,7 +6,7 @@ /* By: vvaas +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/21 10:36:21 by maldavid #+# #+# */ -/* Updated: 2024/01/29 20:16:47 by maldavid ### ########.fr */ +/* Updated: 2024/01/29 21:08:18 by vvaas ### ########.fr */ /* */ /******************************************************************************/ @@ -166,6 +166,10 @@ namespace irc } if (modevalue) _channel_size = std::atoi(msg.getTokens()[3].c_str()); + break ; + default : + client->sendCode(":yipirc " ERR_UNKNOWNMODE " @", getName().c_str(), "Unknown mode"); + return ; } logs::report(log_message, "%s MODES : i:%d t:%d k:%s l:%d", getName().c_str(), _invite_only, _topic_op_restrict, _password.c_str(), _channel_size); showModesModify(client, msg); diff --git a/srcs/client.cpp b/srcs/client.cpp index 099e9cf..88164e4 100644 --- a/srcs/client.cpp +++ b/srcs/client.cpp @@ -6,7 +6,7 @@ /* By: vvaas +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/21 10:35:52 by maldavid #+# #+# */ -/* Updated: 2024/01/26 02:26:04 by vvaas ### ########.fr */ +/* Updated: 2024/01/29 21:18:33 by vvaas ### ########.fr */ /* */ /******************************************************************************/ @@ -21,6 +21,7 @@ #include #include #include +#include namespace irc { @@ -46,6 +47,16 @@ namespace irc logs::report(log_error, "server failed to send a code to '%s' (:sadge:)", _username.c_str()); } + void Client::sendCodeInChannel(const std::string& code, const Channel &chan, const std::string& msg) + { + const std::string command = ":yipirc " + code + " " + getNickName() + " " + chan.getName() + " :" + msg + "\r\n"; +#ifdef DEBUG + logs::report(log_message, "sending '%s'", command.c_str()); +#endif + if(send(_fd, command.c_str(), command.size(), 0) != static_cast(command.length())) + logs::report(log_error, "server failed to send a code to '%s' (:sadge:)", _username.c_str()); + } + void Client::sendPlainText(const std::string& str) { #ifdef DEBUG diff --git a/srcs/server_functions.cpp b/srcs/server_functions.cpp index d364853..d0d9bbd 100644 --- a/srcs/server_functions.cpp +++ b/srcs/server_functions.cpp @@ -6,7 +6,7 @@ /* By: vvaas +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/22 17:31:06 by maldavid #+# #+# */ -/* Updated: 2024/01/29 20:01:48 by vvaas ### ########.fr */ +/* Updated: 2024/01/29 21:16:00 by vvaas ### ########.fr */ /* */ /******************************************************************************/ @@ -429,7 +429,7 @@ namespace irc return ; } if(!chan->isOp(client)) - client->sendCode(ERR_CHANOPRIVSNEEDED, "You need operator privileges to execute this command"); + client->sendCodeInChannel(ERR_CHANOPRIVSNEEDED, *chan, "You need operator privileges to execute this command"); if(msg.getTokens()[2][0] != '-' && msg.getTokens()[2][0] != '+') return ; chan->changeMode(client, msg); diff --git a/srcs_bonus/main.cpp b/srcs_bonus/main.cpp new file mode 100644 index 0000000..cbbdff0 --- /dev/null +++ b/srcs_bonus/main.cpp @@ -0,0 +1,31 @@ +/******************************************************************************/ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: vvaas +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/01/29 20:36:23 by vvaas #+# #+# */ +/* Updated: 2024/01/29 20:41:45 by vvaas ### ########.fr */ +/* */ +/******************************************************************************/ + +#include +#include + +#define IP "127.0.0.1" +#define PORT 6667 +int main() +{ + struct sockaddr_in serv_addr; + int fd = socket(AF_LOCAL, SOCK_STREAM, 0); + if (fd == -1) + irc::logs::report(irc::log_fatal_error, "FD error"); + serv_addr.sin_family = AF_INET; + serv_addr.sin_port = htons(PORT); + if (connect(fd, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) < 0) + { + irc::logs::report(irc::log_fatal_error, "connect error"); + return -1; + } +} \ No newline at end of file