One file per command

This commit is contained in:
2026-04-17 12:01:16 +02:00
parent 00a08b4f30
commit bb66fcc097
8 changed files with 169 additions and 4 deletions

View File

@@ -109,6 +109,19 @@ void Server::readClient(int fd)
clients[fd].appendBuffer(buf);
std::cout << "fd=" << fd << " dice: " << buf;
std::string &clientBuf = clients[fd].getBuffer();
size_t pos;
while ((pos = clientBuf.find('\n')) != std::string::npos)
{
std::string line = clientBuf.substr(0, pos);
clients[fd].clearBuffer();
if (!line.empty() && line[line.size() - 1] == '\r')
line.erase(line.size() - 1);
if (!line.empty())
parseCommand(fd, line);
}
}
void Server::removeClient(int fd)
@@ -126,4 +139,22 @@ void Server::removeClient(int fd)
clients.erase(fd);
close(fd);
}
void Server::parseCommand(int fd, std::string line)
{
(void)fd;
std::istringstream ss(line);
std::string command;
ss >> command;
if (command == "PASS")
cmd_pass(fd, ss);
else if (command == "NICK")
cmd_nick(fd, ss);
else if (command == "USER")
cmd_user(fd, ss);
else
std::cout << "Comando desconocido: " << command << "\n";
}