user command has been init

This commit is contained in:
aortigos
2026-05-15 14:24:46 +02:00
parent dd019163e3
commit 99e4e5cdb3
5 changed files with 76 additions and 20 deletions

50
cmds/user.cpp Normal file
View File

@@ -0,0 +1,50 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* user.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/05/10 22:06:22 by aortigos #+# #+# */
/* Updated: 2026/05/15 12:49:49 by aortigos ### ########.fr */
/* */
/* ************************************************************************** */
#include "../Server/Server.hpp"
void Server::user_cmd(User &client, std::istringstream &ss)
{
std::string username;
std::string hostname;
std::string servername;
std::string realname;
ss >> username >> hostname >> servername;
std::getline(ss, realname);
if (!client.isAuthenticated())
return (client.send(":" SERVER_NAME " 451 * :You have not registered\r\n"));
if (client.isRegistered())
return (client.send(":" SERVER_NAME " 462 " + client.getNick() + " :Unauthorized command (already registered)\r\n"));
if (!realname.empty() && realname[0] == ' ')
realname = realname.substr(1);
if (realname.empty() || realname[0] != ':')
return (client.send(":" SERVER_NAME " 461 * USER :Not enough parameters\r\n"));
if (!realname.empty() && realname[0] == ':')
realname = realname.substr(1);
if (username.empty() || hostname.empty() || servername.empty() || realname.empty())
return (client.send(":" SERVER_NAME " 461 * USER :Not enough parameters\r\n"));
client.setUsername(username);
client.setRealname(realname);
if (!client.getNick().empty())
{
client.setRegistered(true);
client.send(":" SERVER_NAME " 001 " + client.getNick() + " :Welcome to the IRC Network " + client.getNick() + "\r\n");
client.send(":" SERVER_NAME " 002 " + client.getNick() + " :Your host is " SERVER_NAME ", running version 1.0\r\n");
client.send(":" SERVER_NAME " 003 " + client.getNick() + " :This server was created May 2026\r\n");
client.send(":" SERVER_NAME " 004 " + client.getNick() + " :" SERVER_NAME " 1.0\r\n");
}
}