Skip to content

Commit

Permalink
Merge pull request #144 from jdomingu98/125-nick-bug-respuestas
Browse files Browse the repository at this point in the history
125 nick bug respuestas
  • Loading branch information
jdomingu98 authored Apr 28, 2024
2 parents 3186d78 + 98f25a8 commit d99baa2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions includes/Responses.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Channel;
# define JOIN_MSG(channelName) " JOIN " + (channelName)
# define KICK_MSG(channelName, kickedUser, comment) " KICK " + (channelName) + " " + (kickedUser) + " :" + (comment)
# define MODE_MSG(channel, flag, modeParams) " MODE " + (channel) + " " + (flag) + " " + (modeParams)
# define NICK_MSG(nickname) " NICK " + (nickname)
# define PART_MSG(channelName) " PART " + (channelName)
# define PRIVMSG_MSG(destination, message) " PRIVMSG " + (destination) + " :" + (message)
# define QUIT_MSG(message) " QUIT :" + (message)
Expand Down
13 changes: 11 additions & 2 deletions src/commands/NickCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,23 @@ void NickCommand::execute(int clientFd) {

User &user = server.getUserByFd(clientFd);

if (server.isNicknameInUse(this->_nickname))
if (user.getNickname() != this->_nickname && server.isNicknameInUse(this->_nickname))
throw NicknameInUseException(this->_nickname);

if (!NickCommand::isValidNickname())
throw ErroneousNicknameException(this->_nickname);

if (user.isRegistered() && user.getNickname() != this->_nickname) {
std::vector<Channel> userChannels = server.getChannels();
for (std::vector<Channel>::iterator it = userChannels.begin(); it != userChannels.end(); it++) {
if (it->isUserInChannel(user.getNickname()))
it->broadcastToChannel(CMD_MSG(user.getNickname(), user.getUsername(), user.getHostname(), NICK_MSG(this->_nickname)));
}
}

user.setNickname(this->_nickname);
if (user.canRegister())

if (!user.isRegistered() && user.canRegister())
server.attemptUserRegistration(clientFd);
}

Expand Down

0 comments on commit d99baa2

Please sign in to comment.