Files
irc/commands/nick.cpp
2026-04-17 14:34:15 +02:00

61 lines
1.8 KiB
C++

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* nick.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/04/17 11:56:55 by aortigos #+# #+# */
/* Updated: 2026/04/17 14:19:29 by aortigos ### ########.fr */
/* */
/* ************************************************************************** */
#include "../Server/Server.hpp"
void Server::cmd_nick(int fd, std::istringstream &ss)
{
std::string args;
ss >> args;
if(!clients[fd].isAuthenticated())
{
std::string msg = ":ircserv 451 * :You have not registered\r\n";
send(fd, msg.c_str(), msg.size(), 0);
return ;
}
if (args.empty())
{
std::string msg = ":ircserv 431 * :No nickname given\r\n";
send(fd, msg.c_str(), msg.size(), 0);
return ;
}
for (std::map<int, Client>::iterator it = clients.begin(); it != clients.end(); it++)
{
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;
}
}
std::string msg = ":"
+ clients[fd].getNick()
+ " NICK "
+ args
+ "\r\n";
clients[fd].setNick(args);
send(fd, msg.c_str(), msg.size(), 0);
}