now broadcast send message to every member of channel, excluding the author of message
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/05/15 15:35:16 by aortigos #+# #+# */
|
||||
/* Updated: 2026/05/15 22:06:36 by aortigos ### ########.fr */
|
||||
/* Updated: 2026/05/15 22:18:52 by aortigos ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -18,14 +18,13 @@ void Server::join_cmd(User &client, std::istringstream &ss)
|
||||
std::string args;
|
||||
|
||||
ss >> args;
|
||||
if (!client.isRegistered()) return (client.send("You are not registered"));
|
||||
if (!client.isRegistered()) return (client.send("You are not registered\r\n"));
|
||||
if (args.empty()) return (client.send("No name specified\r\n"));
|
||||
|
||||
std::map<std::string, Channel>::iterator it = channels_.find(args);
|
||||
|
||||
if (it == channels_.end())
|
||||
{
|
||||
// Channel doesnt exists, create and join
|
||||
channels_[args] = Channel(args);
|
||||
channels_[args].addMember(client.getFd());
|
||||
channels_[args].addOperator(client.getFd());
|
||||
@@ -33,7 +32,9 @@ void Server::join_cmd(User &client, std::istringstream &ss)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (it->second.hasMember(client.getFd())) return (client.send("You are already in this channel\r\n"));
|
||||
it->second.addMember(client.getFd());
|
||||
if (it->second.hasMember(client.getFd()))
|
||||
client.send("You are already in this channel\r\n");
|
||||
else
|
||||
it->second.addMember(client.getFd());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/05/10 22:06:22 by aortigos #+# #+# */
|
||||
/* Updated: 2026/05/15 22:08:10 by aortigos ### ########.fr */
|
||||
/* Updated: 2026/05/15 23:04:35 by aortigos ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -34,7 +34,7 @@ void Server::nick_cmd(User &client, std::istringstream &ss)
|
||||
ss >> args;
|
||||
if (!client.isAuthenticated()) return (client.send(":" SERVER_NAME " 451 * :You have not registered\r\n"));
|
||||
if (args.empty()) return (client.send(":" SERVER_NAME " 431 * :Not nickname given\r\n"));
|
||||
if (!isValidNick(args)) return (client.send(":" SERVER_NAME " 432 * " + args + " Erroneous nickname\r\n"));
|
||||
if (!isValidNick(args)) return (client.send(":" SERVER_NAME " 432 * " + args + " :Erroneous nickname\r\n"));
|
||||
for (std::map<int, User>::iterator it = clients_.begin(); it != clients_.end(); it++)
|
||||
{
|
||||
if (it->second.getNick() == args)
|
||||
|
||||
41
cmds/privmsg.cpp
Normal file
41
cmds/privmsg.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* privmsg.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/05/15 15:35:16 by aortigos #+# #+# */
|
||||
/* Updated: 2026/05/15 23:09:57 by aortigos ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
#include "../Server/Server.hpp"
|
||||
|
||||
|
||||
// Test function, need to change all the error messages
|
||||
|
||||
void Server::privmsg_cmd(User &client, std::istringstream &ss)
|
||||
{
|
||||
std::string channel;
|
||||
std::string message;
|
||||
|
||||
ss >> channel;
|
||||
getline(ss, message);
|
||||
|
||||
if (!client.isRegistered()) return (client.send(":" SERVER_NAME " 451 " + client.getNick() + " :You have not registered\r\n"));
|
||||
|
||||
std::map<std::string, Channel>::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() + " PRIVMSG " + channel + " :" + message + "\r\n";
|
||||
return (it->second.broadcast(msg, clients_, client.getFd()));
|
||||
}
|
||||
Reference in New Issue
Block a user