Fixed error messages in commands
This commit is contained in:
@@ -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);
|
||||
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/04/17 11:53:56 by aortigos #+# #+# */
|
||||
/* Updated: 2026/04/17 11:56:21 by aortigos ### ########.fr */
|
||||
/* Updated: 2026/04/17 13:04:05 by aortigos ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -18,16 +18,32 @@ void Server::cmd_pass(int fd, std::istringstream &ss)
|
||||
|
||||
ss >> args;
|
||||
|
||||
if (args == this->password)
|
||||
if (clients[fd].isAuthenticated())
|
||||
{
|
||||
clients[fd].setAuthenticated(true);
|
||||
|
||||
std::string msg = "You have been authenticated!\r\n";
|
||||
std::string msg = ":ircserv 462 "
|
||||
+ clients[fd].getNick()
|
||||
+ " :You may not reregister\r\n";
|
||||
send(fd, msg.c_str(), msg.size(), 0);
|
||||
|
||||
return ;
|
||||
}
|
||||
else
|
||||
|
||||
if (args.empty())
|
||||
{
|
||||
send(fd, ERR_PASSWORD.c_str(), ERR_PASSWORD.size(), 0);
|
||||
removeClient(fd);
|
||||
std::string msg = ":ircserv 461 * PASS :Not enough parameters\r\n";
|
||||
send(fd, msg.c_str(), msg.size(), 0);
|
||||
|
||||
return ;
|
||||
}
|
||||
|
||||
if (args != this->password)
|
||||
{
|
||||
std::string msg = ":ircserv 464 * :Password incorrect\r\n";
|
||||
send(fd, msg.c_str(), msg.size(), 0);
|
||||
removeClient(fd);
|
||||
return ;
|
||||
}
|
||||
|
||||
clients[fd].setAuthenticated(true);
|
||||
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
/* 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 */
|
||||
/* Updated: 2026/04/17 13:10:07 by aortigos ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -21,19 +21,24 @@ void Server::cmd_user(int fd, std::istringstream &ss)
|
||||
|
||||
if (clients[fd].getNick().empty())
|
||||
{
|
||||
send(fd, ERR_NONICK.c_str(), ERR_NONICK.size(), 0);
|
||||
std::string msg = ":ircserv 451 * :You have not registered\r\n";
|
||||
send(fd, msg.c_str(), msg.size(), 0);
|
||||
return ;
|
||||
}
|
||||
|
||||
if(clients[fd].isRegistered())
|
||||
{
|
||||
send(fd, ERR_REREGISTER.c_str(), ERR_REREGISTER.size(), 0);
|
||||
std::string msg = ":ircserv 462 "
|
||||
+ clients[fd].getNick()
|
||||
+ " :You may not reregister\r\n";
|
||||
send(fd, msg.c_str(), msg.size(), 0);
|
||||
return ;
|
||||
}
|
||||
|
||||
if (username.empty())
|
||||
{
|
||||
send(fd, ERR_NOUSER.c_str(), ERR_NOUSER.size(), 0);
|
||||
std::string msg = ":ircserv 461 * USER :Not enough parameters\r\n";
|
||||
send(fd, msg.c_str(), msg.size(), 0);
|
||||
return ;
|
||||
}
|
||||
|
||||
@@ -42,6 +47,10 @@ void Server::cmd_user(int fd, std::istringstream &ss)
|
||||
clients[fd].setRealname(realname);
|
||||
clients[fd].setRegistered(true);
|
||||
|
||||
std::string msg = "You has been registered!\r\n";
|
||||
std::string msg = ":ircserv 001 "
|
||||
+ clients[fd].getNick()
|
||||
+ " :Welcome to IRC "
|
||||
+ clients[fd].getNick()
|
||||
+ "\r\n";
|
||||
send(fd, msg.c_str(), msg.size(), 0);
|
||||
}
|
||||
Reference in New Issue
Block a user