Skip to content

Commit

Permalink
fix improving the code
Browse files Browse the repository at this point in the history
He probado con mas de un usuario y  funciona correctamente también he buscado info del set, esta curioso como funciona. Se ordena de forma ascendente, lo parámetros de dentro de un set no se pueden modificar solo insertar o eliminar y en nuestro caso hacerlo único no hay duplicados.
  • Loading branch information
Atrujillo02 committed Apr 23, 2024
1 parent e21b5e3 commit 4222685
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/commands/QuitCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ void QuitCommand::execute(int clientFd) {

std::set<User> allUsers;
std::set<User>::iterator it;

if (user.isRegistered())
allUsers.insert(user);
for (size_t i = 0; i < channels.size(); i++) {
if (!channels[i].isUserInChannel(nickname))
continue;
Expand All @@ -37,14 +40,10 @@ void QuitCommand::execute(int clientFd) {
usersChannel.clear();
}

if (allUsers.empty() && user.isRegistered())
allUsers.insert(user);

for (it = allUsers.begin(); it != allUsers.end(); it++) {
server.sendMessage(it->getFd(),
QUIT_MSG(nickname, user.getUsername(), user.getHostname(),
_message.empty() ? nickname : _message));
}

server.handleClientDisconnection(clientFd);
}

0 comments on commit 4222685

Please sign in to comment.