One file per command
This commit is contained in:
47
commands/user.cpp
Normal file
47
commands/user.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* user.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/04/17 11:58:23 by aortigos #+# #+# */
|
||||
/* Updated: 2026/04/17 11:58:40 by aortigos ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../Server/Server.hpp"
|
||||
|
||||
void Server::cmd_user(int fd, std::istringstream &ss)
|
||||
{
|
||||
std::string username, unused1, unused2, realname;
|
||||
|
||||
ss >> username >> unused1 >> unused2;
|
||||
std::getline(ss, realname);
|
||||
|
||||
if (clients[fd].getNick().empty())
|
||||
{
|
||||
send(fd, ERR_NONICK.c_str(), ERR_NONICK.size(), 0);
|
||||
return ;
|
||||
}
|
||||
|
||||
if(clients[fd].isRegistered())
|
||||
{
|
||||
send(fd, ERR_REREGISTER.c_str(), ERR_REREGISTER.size(), 0);
|
||||
return ;
|
||||
}
|
||||
|
||||
if (username.empty())
|
||||
{
|
||||
send(fd, ERR_NOUSER.c_str(), ERR_NOUSER.size(), 0);
|
||||
return ;
|
||||
}
|
||||
|
||||
|
||||
clients[fd].setUsername(username);
|
||||
clients[fd].setRealname(realname);
|
||||
clients[fd].setRegistered(true);
|
||||
|
||||
std::string msg = "You has been registered!\r\n";
|
||||
send(fd, msg.c_str(), msg.size(), 0);
|
||||
}
|
||||
Reference in New Issue
Block a user