Improving commands and added quit
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/05/06 17:19:12 by iherman- #+# #+# */
|
||||
/* Updated: 2026/05/15 22:16:34 by aortigos ### ########.fr */
|
||||
/* Updated: 2026/05/16 11:31:25 by aortigos ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -116,6 +116,7 @@ Server::Server(int port, const std::string& password) :
|
||||
commands_["NICK"] = &Server::nick_cmd;
|
||||
commands_["USER"] = &Server::user_cmd;
|
||||
commands_["JOIN"] = &Server::join_cmd;
|
||||
commands_["QUIT"] = &Server::quit_cmd;
|
||||
commands_["PRIVMSG"] = &Server::privmsg_cmd;
|
||||
|
||||
std::cout << "Server port: " << port_
|
||||
@@ -151,6 +152,12 @@ void Server::parseCommand(User& client)
|
||||
|
||||
args >> command;
|
||||
|
||||
if (command.empty())
|
||||
{
|
||||
client.clearBuffer();
|
||||
return ;
|
||||
}
|
||||
|
||||
std::map<std::string, void (Server::*)(User&, std::istringstream&)>::iterator it = commands_.find(command);
|
||||
if (it == commands_.end())
|
||||
{
|
||||
@@ -180,7 +187,12 @@ bool Server::handleClient(User& client)
|
||||
return true;
|
||||
}
|
||||
|
||||
client.appendBuffer(std::string(buffer, recv_amount));
|
||||
std::string data(buffer, recv_amount);
|
||||
size_t pos = data.find('\r');
|
||||
if (pos != std::string::npos)
|
||||
data.erase(pos, 1);
|
||||
|
||||
client.appendBuffer(data);
|
||||
|
||||
if (client.getBuffer().find('\n') != std::string::npos)
|
||||
parseCommand(client);
|
||||
|
||||
Reference in New Issue
Block a user