less lines, same code #27

Merged
aortigos merged 1 commits from re-factoring-code into main 2026-05-15 20:09:40 +00:00
3 changed files with 12 additions and 19 deletions

View File

@@ -6,7 +6,7 @@
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */ /* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2026/05/10 22:06:22 by aortigos #+# #+# */ /* Created: 2026/05/10 22:06:22 by aortigos #+# #+# */
/* Updated: 2026/05/15 12:49:37 by aortigos ### ########.fr */ /* Updated: 2026/05/15 22:08:10 by aortigos ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -32,12 +32,9 @@ void Server::nick_cmd(User &client, std::istringstream &ss)
std::string args; std::string args;
ss >> args; ss >> args;
if (!client.isAuthenticated()) if (!client.isAuthenticated()) return (client.send(":" SERVER_NAME " 451 * :You have not registered\r\n"));
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 (args.empty()) if (!isValidNick(args)) return (client.send(":" SERVER_NAME " 432 * " + args + " Erroneous nickname\r\n"));
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"));
for (std::map<int, User>::iterator it = clients_.begin(); it != clients_.end(); it++) for (std::map<int, User>::iterator it = clients_.begin(); it != clients_.end(); it++)
{ {
if (it->second.getNick() == args) if (it->second.getNick() == args)

View File

@@ -6,7 +6,7 @@
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */ /* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2026/05/10 22:06:22 by aortigos #+# #+# */ /* Created: 2026/05/10 22:06:22 by aortigos #+# #+# */
/* Updated: 2026/05/14 20:21:31 by aortigos ### ########.fr */ /* Updated: 2026/05/15 22:08:49 by aortigos ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -17,13 +17,11 @@ void Server::pass_cmd(User &client, std::istringstream &ss)
std::string args; std::string args;
ss >> args; ss >> args;
if (args.empty()) if (args.empty()) return (client.send(":" SERVER_NAME " 461 * PASS :Not enough parameters\r\n"));
return (client.send(":" SERVER_NAME " 461 * PASS :Not enough parameters\r\n")); if (client.isAuthenticated()) return (client.send(":" SERVER_NAME " 462 " + client.getNick() + " :Unauthorized command (already registered)\r\n"));
if (client.isAuthenticated())
return (client.send(":" SERVER_NAME " 462 " + client.getNick() + " :Unauthorized command (already registered)\r\n"));
if (this->password_ == args) if (this->password_ == args)
client.setAuthenticated(true); client.setAuthenticated(true);
else { else
client.send(":" SERVER_NAME " 464 * :Password incorrect\r\n"); client.send(":" SERVER_NAME " 464 * :Password incorrect\r\n");
}
} }

View File

@@ -6,7 +6,7 @@
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */ /* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2026/05/10 22:06:22 by aortigos #+# #+# */ /* Created: 2026/05/10 22:06:22 by aortigos #+# #+# */
/* Updated: 2026/05/15 12:49:49 by aortigos ### ########.fr */ /* Updated: 2026/05/15 22:08:59 by aortigos ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -22,10 +22,8 @@ void Server::user_cmd(User &client, std::istringstream &ss)
ss >> username >> hostname >> servername; ss >> username >> hostname >> servername;
std::getline(ss, realname); std::getline(ss, realname);
if (!client.isAuthenticated()) if (!client.isAuthenticated()) return (client.send(":" SERVER_NAME " 451 * :You have not registered\r\n"));
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 (client.isRegistered())
return (client.send(":" SERVER_NAME " 462 " + client.getNick() + " :Unauthorized command (already registered)\r\n"));
if (!realname.empty() && realname[0] == ' ') if (!realname.empty() && realname[0] == ' ')
realname = realname.substr(1); realname = realname.substr(1);