user command has been init
This commit is contained in:
@@ -6,25 +6,42 @@
|
||||
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/05/10 22:06:22 by aortigos #+# #+# */
|
||||
/* Updated: 2026/05/15 11:46:03 by aortigos ### ########.fr */
|
||||
/* Updated: 2026/05/15 12:49:37 by aortigos ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../Server/Server.hpp"
|
||||
|
||||
|
||||
static bool isValidNick(const std::string &nick)
|
||||
{
|
||||
const std::string special = "[]\\`_^{|}";
|
||||
|
||||
if (!isalpha(nick[0]) && special.find(nick[0]) == std::string::npos)
|
||||
return (false);
|
||||
for (size_t i = 1; i < nick.size(); i++)
|
||||
{
|
||||
if (!isalnum(nick[i]) && special.find(nick[i]) == std::string::npos && nick[i] != '-')
|
||||
return (false);
|
||||
}
|
||||
return (true);
|
||||
}
|
||||
|
||||
void Server::nick_cmd(User &client, std::istringstream &ss)
|
||||
{
|
||||
std::string args;
|
||||
|
||||
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"))
|
||||
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)
|
||||
return (client.send(":" SERVER_NAME " 433 * " + args + " :Nickname is already in use\r\n"))
|
||||
return (client.send(":" SERVER_NAME " 433 * " + args + " :Nickname is already in use\r\n"));
|
||||
}
|
||||
|
||||
std::string oldNick = client.getNick();
|
||||
@@ -47,17 +64,3 @@ void Server::nick_cmd(User &client, std::istringstream &ss)
|
||||
client.send(":" SERVER_NAME " 004 " + args + " :" SERVER_NAME " 1.0\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
static bool isValidNick(const std::string &nick)
|
||||
{
|
||||
const std::string special = "[]\\`_^{|}";
|
||||
|
||||
if (!isalpha(nick[0]) && special.find(nick[0]) == std::string::npos)
|
||||
return (false);
|
||||
for (size_t i = 1; i < nick.size(); i++)
|
||||
{
|
||||
if (!isalnum(nick[i])) && special.find(nick[i] == std::string::npos && nick[i] != '-')
|
||||
return (false);
|
||||
}
|
||||
return (true);
|
||||
}
|
||||
Reference in New Issue
Block a user