From b90d0454f333e528d52e2afe2d0bcce2b9985e95 Mon Sep 17 00:00:00 2001 From: Kbz-8 Date: Mon, 29 Jan 2024 22:14:02 +0100 Subject: [PATCH] caca cimennt --- srcs/server_functions.cpp | 45 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/srcs/server_functions.cpp b/srcs/server_functions.cpp index 2352a9b..2b559d2 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 21:32:24 by vvaas ### ########.fr */ +/* Updated: 2024/01/29 22:13:58 by maldavid ### ########.fr */ /* */ /******************************************************************************/ @@ -288,8 +288,47 @@ namespace irc void Server::handleInvite(unstd::SharedPtr client, const Message& msg) { - (void)client; - (void)msg; + if(msg.getArgs().empty() || msg.getArgs().size() != 2) + { + logs::report(log_error, "INVITE, invalid command '%s'", msg.getRawMsg().c_str()); + return; + } + + if(!isUserKnown(msg.getArgs()[0])) + { + client->sendCode(ERR_NOSUCHNICK, const_cast(msg.getArgs()[0]) + " no such nick"); + return; + } + if(!isChannelKnown(msg.getArgs()[1])) + { + client->sendCode(ERR_NOSUCHCHANNEL, const_cast(msg.getArgs()[1]) + " no such channel"); + return; + } + + Channel* channel_target = getChannelByName(msg.getArgs()[1]); + if(channel_target == NULL) + logs::report(log_fatal_error, "(INVITE), cannot get channel '%s' by name; panic !", msg.getArgs()[1].c_str()); + unstd::SharedPtr client_target = getClientByName(msg.getArgs()[0]); + if(client_target.get() == NULL) + logs::report(log_fatal_error, "(INVITE), cannot get client '%s' by name; panic !", msg.getArgs()[0].c_str()); + + if(!channel_target->hasClient(client)) + { + client->sendCode(ERR_NOTONCHANNEL, msg.getArgs()[0], "you're not on that channel"); + return; + } + + if(channel_target->hasClient(client_target->getNickName())) + { + client->sendCode(ERR_USERONCHANNEL, msg.getArgs()[0] + ' ' + msg.getArgs()[1], "is already on channel"); + return; + } + + if(channel_target->isInviteOnly() && !channel_target->isOp(client)) + { + client->sendCode(ERR_CHANOPRIVSNEEDED, msg.getArgs()[1], "you're not channel operator"); + return; + } } void Server::handleKick(unstd::SharedPtr client, const Message& msg)