Fixed error messages in commands

This commit is contained in:
2026-04-17 13:12:22 +02:00
parent bb66fcc097
commit 49fa432411
6 changed files with 69 additions and 33 deletions

View File

@@ -6,7 +6,7 @@
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/04/17 11:56:55 by aortigos #+# #+# */
/* Updated: 2026/04/17 11:59:33 by aortigos ### ########.fr */
/* Updated: 2026/04/17 12:45:36 by aortigos ### ########.fr */
/* */
/* ************************************************************************** */
@@ -20,19 +20,40 @@ void Server::cmd_nick(int fd, std::istringstream &ss)
if(!clients[fd].isAuthenticated())
{
send(fd, ERR_NOPASS.c_str(), ERR_NOPASS.size(), 0);
std::string msg = ":ircserv 451 * :You have not registered\r\n";
send(fd, msg.c_str(), msg.size(), 0);
return ;
}
if (!args.empty())
if (args.empty())
{
clients[fd].setNick(args);
std::string msg = "Your nick has been updated!\r\n";
std::string msg = ":ircserv 431 * :No nickname given\r\n";
send(fd, msg.c_str(), msg.size(), 0);
return ;
}
else
for (std::map<int, Client>::iterator it = clients.begin(); it != clients.end(); it++)
{
send(fd, ERR_NONICK.c_str(), ERR_NONICK.size(), 0);
if (it->second.getNick() == args)
{
std::string msg = ":ircserv 433 * "
+ clients[fd].getNick()
+ " :Nickname is already in use\r\n";
send(fd, msg.c_str(), msg.size(), 0);
return;
}
}
clients[fd].setNick(args);
std::string msg = ":"
+ clients[fd].getNick()
+ " NICK "
+ args
+ "\r\n";
send(fd, msg.c_str(), msg.size(), 0);
}