Parser accept server functions, and first stage for implementing client.send function
This commit is contained in:
@@ -3,10 +3,10 @@
|
||||
/* ::: :::::::: */
|
||||
/* Server.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: iherman- <iherman-@student.42malaga.com +#+ +:+ +#+ */
|
||||
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/05/06 17:19:12 by iherman- #+# #+# */
|
||||
/* Updated: 2026/05/12 20:34:58 by iherman- ### ########.fr */
|
||||
/* Updated: 2026/05/14 17:00:22 by aortigos ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -35,13 +35,6 @@
|
||||
|
||||
const int Server::kConnectionQueueLimit = 10;
|
||||
|
||||
// TEMPORARY TESTING FUNCTION
|
||||
void echo(User& client, std::istringstream& input)
|
||||
{
|
||||
std::string message = "Server received: " + input.str();
|
||||
send(client.getFd(), message.c_str(), message.size(), 0);
|
||||
}
|
||||
|
||||
Server::Server() :
|
||||
port_(PORT_DEFAULT),
|
||||
password_("password")
|
||||
@@ -119,7 +112,7 @@ Server::Server(int port, const std::string& password) :
|
||||
}
|
||||
|
||||
// Add all new commands to commands_ here
|
||||
commands_["echo"] = &echo;
|
||||
commands_["PASS"] = &Server::pass_cmd;
|
||||
|
||||
std::cout << "Server port: " << port_
|
||||
<< "\nServer Password: " << password_
|
||||
@@ -154,7 +147,7 @@ void Server::parseCommand(User& client)
|
||||
|
||||
args >> command;
|
||||
|
||||
std::map<std::string, void (*)(User&, std::istringstream&)>::iterator it = commands_.find(command);
|
||||
std::map<std::string, void (Server::*)(User&, std::istringstream&)>::iterator it = commands_.find(command);
|
||||
if (it == commands_.end())
|
||||
{
|
||||
std::string message = "Error: command not found!\n";
|
||||
@@ -162,7 +155,7 @@ void Server::parseCommand(User& client)
|
||||
client.clearBuffer();
|
||||
return ;
|
||||
}
|
||||
it->second(client, args);
|
||||
(this->*(it->second))(client, args);
|
||||
client.clearBuffer();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user