From 20fc70ab90a2e49318c105300ff8a4199524503c Mon Sep 17 00:00:00 2001 From: Kbz-8 Date: Tue, 30 Jan 2024 21:01:28 +0100 Subject: [PATCH] c est metaphysique --- includes/channel.hpp | 4 ++-- srcs/channel.cpp | 12 ++++++------ srcs/server.cpp | 6 +++--- srcs/server_functions.cpp | 6 +++--- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/includes/channel.hpp b/includes/channel.hpp index 1663ada..aee4976 100644 --- a/includes/channel.hpp +++ b/includes/channel.hpp @@ -6,7 +6,7 @@ /* By: vvaas +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/21 10:34:25 by maldavid #+# #+# */ -/* Updated: 2024/01/30 20:14:08 by maldavid ### ########.fr */ +/* Updated: 2024/01/30 20:54:21 by maldavid ### ########.fr */ /* */ /******************************************************************************/ @@ -38,7 +38,7 @@ namespace irc inline const std::string& getPassword() const { return _password; } void addClient(unstd::SharedPtr client, bool op = false); - bool removeClient(unstd::SharedPtr client, std::string reason = ""); + bool removeClient(unstd::SharedPtr client, const std::string& reason, bool quit = false); inline std::size_t getNumberOfClients() const { return _clients.size(); } inline int getChannelSize() const { return _channel_size; } diff --git a/srcs/channel.cpp b/srcs/channel.cpp index 6e01a6b..b4ce4ed 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/30 20:50:31 by vvaas ### ########.fr */ +/* Updated: 2024/01/30 21:01:06 by maldavid ### ########.fr */ /* */ /******************************************************************************/ @@ -71,7 +71,7 @@ namespace irc client->sendCode(ERR_USERNOTINCHANNEL, "User not in channel"); } - bool Channel::removeClient(unstd::SharedPtr client, std::string reason) + bool Channel::removeClient(unstd::SharedPtr client, const std::string& reason, bool quit) { if(!_clients.erase(client)) return false; @@ -79,13 +79,13 @@ namespace irc _operators.erase(client); for(client_it it = _clients.begin(); it != _clients.end(); ++it) { - if(reason.empty()) - const_cast&>(*it)->sendMsg(client->getNickName(), "PART", _name); + if(!quit) + const_cast&>(*it)->sendMsg(client->getNickName(), "PART", _name + ' ' + reason); else const_cast&>(*it)->sendMsg(client->getNickName(), "QUIT", reason); } - if(reason.empty()) - client->sendMsg(client->getNickName(), "PART", _name); + if(!quit) + client->sendMsg(client->getNickName(), "PART", _name + ' ' + reason); return true; } diff --git a/srcs/server.cpp b/srcs/server.cpp index 4d4a422..b3ed7d7 100644 --- a/srcs/server.cpp +++ b/srcs/server.cpp @@ -6,7 +6,7 @@ /* By: vvaas +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/21 09:31:17 by maldavid #+# #+# */ -/* Updated: 2024/01/30 18:08:41 by maldavid ### ########.fr */ +/* Updated: 2024/01/30 20:58:31 by maldavid ### ########.fr */ /* */ /******************************************************************************/ @@ -48,7 +48,7 @@ namespace irc void Server::initSocket() { int opt = 1; - + initSocketData(); if(setsockopt(_main_socket, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) < 0) // SOL_SOCKET : modify socket only, SO_REUSEADDR : Reusable after program ends logs::report(log_fatal_error, "setsockopt() error (tout a pete)"); @@ -87,7 +87,7 @@ namespace irc close((*it)->getFD()); for(channel_it cit = _channels.begin(); cit != _channels.end();) { - cit->removeClient(*it); + cit->removeClient(*it, ""); if(cit->getNumberOfClients() == 0) { logs::report(log_message, "channel '%s' has been destroyed", cit->getName().c_str()); diff --git a/srcs/server_functions.cpp b/srcs/server_functions.cpp index 65f3290..dcd60bb 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/30 20:46:24 by vvaas ### ########.fr */ +/* Updated: 2024/01/30 21:01:20 by maldavid ### ########.fr */ /* */ /******************************************************************************/ @@ -120,7 +120,7 @@ namespace irc void Server::handleQuit(unstd::SharedPtr client, const Message& msg) { for(channel_it it = _channels.begin(); it != _channels.end(); ++it) - it->removeClient(client, (msg.getReason().empty() ? "Leaving" : msg.getReason())); + it->removeClient(client, (msg.getReason().empty() ? "Leaving" : msg.getReason()), true); client->printUserHeader(); std::cout << "quit" << std::endl; } @@ -145,7 +145,7 @@ namespace irc Channel* channel = getChannelByName(msg.getArgs()[0]); if(channel == NULL) logs::report(log_fatal_error, "(KICK), cannot get channel '%s' by name; panic !", channel->getName().c_str()); - if(!channel->removeClient(client)) + if(!channel->removeClient(client, (msg.getReason().empty() ? "" : msg.getReason()))) { client->sendCode(ERR_NOTONCHANNEL, "Not on channel"); return;