From e5e08d4cd057431ff4035d23758b2c9805b51fcb Mon Sep 17 00:00:00 2001 From: aortigos Date: Mon, 25 May 2026 09:23:05 +0200 Subject: [PATCH] Now users can send privmsg to other user --- cmds/privmsg.cpp | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/cmds/privmsg.cpp b/cmds/privmsg.cpp index 4285738..bee0ba6 100644 --- a/cmds/privmsg.cpp +++ b/cmds/privmsg.cpp @@ -6,7 +6,7 @@ /* By: aortigos ::iterator it = channels_.find(channel); - - if (it == channels_.end()) - return (client.send(":" SERVER_NAME " 403 " + client.getNick() + " " + channel + " :No such channel\r\n")); - if (!it->second.hasMember(client.getFd())) - return (client.send(":" SERVER_NAME " 404 " + client.getNick() + " " + channel + " :Cannot send to channel\r\n")); if (message.empty()) return (client.send(":" SERVER_NAME " 412 " + client.getNick() + " :No text to send\r\n")); + if (message[0] == ' ') message = message.substr(1); - std::string msg = ":" + client.getNick() + "!" + client.getUsername() + "@localhost PRIVMSG " + channel + " :" + message + "\r\n"; - return (it->second.broadcast(msg, clients_, client.getFd())); + if (channel[0] == '#') + { + std::map::iterator it = channels_.find(channel); + + if (it == channels_.end()) + return (client.send(":" SERVER_NAME " 403 " + client.getNick() + " " + channel + " :No such channel\r\n")); + if (!it->second.hasMember(client.getFd())) + return (client.send(":" SERVER_NAME " 404 " + client.getNick() + " " + channel + " :Cannot send to channel\r\n")); + + std::string msg = ":" + client.getNick() + "!" + client.getUsername() + "@localhost PRIVMSG " + channel + " :" + message + "\r\n"; + it->second.broadcast(msg, clients_, client.getFd()); + } else { + for(std::map::iterator it = clients_.begin(); it != clients_.end(); it++) + { + if (it->second.getNick() == channel) + { + return (it->second.send(":" + client.getNick() + "!" + client.getUsername() + "@localhost PRIVMSG " + channel + " :" + message + "\r\n")); + } + } + return (client.send(":" SERVER_NAME " 401 " + client.getNick() + " " + channel + " :No such nick\r\n")); + } }