diff --git a/includes/Channel.hpp b/includes/Channel.hpp index 3f7cc15..9807146 100644 --- a/includes/Channel.hpp +++ b/includes/Channel.hpp @@ -7,7 +7,7 @@ # include "User.hpp" # define MAX_CHANNEL_NAME_LENGTH 20 -# define NO_LIMIT -1 +# define NO_LIMIT 0 # define BELL_CHAR '\a' class User; diff --git a/src/Channel.cpp b/src/Channel.cpp index 975625d..1005777 100644 --- a/src/Channel.cpp +++ b/src/Channel.cpp @@ -260,7 +260,7 @@ bool Channel::hasLimit() const { * @return `true` if the channel is full, `false` otherwise. */ bool Channel::isFull() const { - return (int) (this->_users.size() + this->_operators.size()) == this->_limit; + return (int) (this->_users.size() + this->_operators.size()) >= this->_limit && this->_limit != NO_LIMIT; } /** diff --git a/src/Utils.cpp b/src/Utils.cpp index e5067ba..83a905d 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -39,7 +39,7 @@ std::vector Utils::split(const std::string &s, char delim) { bool Utils::isNumber(const std::string& s) { std::string::const_iterator it = s.begin(); - while (it != s.end() && std::isdigit(*it)) + while (it != s.end() && (std::isdigit(*it) || (*it == '-' && it == s.begin()))) ++it; return !s.empty() && it == s.end(); } \ No newline at end of file diff --git a/src/commands/ModeCommand.cpp b/src/commands/ModeCommand.cpp index f0f1297..f832e8f 100644 --- a/src/commands/ModeCommand.cpp +++ b/src/commands/ModeCommand.cpp @@ -58,36 +58,31 @@ void ModeCommand::execute(int clientFd) { std::string flag = _plus ? "+" : "-"; std::vector::iterator paramIterator = _modeParams.begin(); std::string param = NONE; + std::string modeParams = NONE; for (size_t i = 0; i < _modes.size(); i++) { flag += _modes[i]; - + if (ModeCommand::modeNeedsParam(_modes[i])) { if (paramIterator == _modeParams.end()) throw NeedMoreParamsException("MODE"); param = *(paramIterator++); + modeParams += param + " "; } - switch (_modes[i]) { - case INVITE_ONLY: - ModeCommand::inviteOnly(); - break; - case TOPIC_PROTECTED: - ModeCommand::topicProtected(); - break; - case CHANNEL_KEY: - ModeCommand::channelKey(param); - break; - case CHANNEL_OPERATOR: - ModeCommand::channelOperator(param); - break; - case USER_LIMIT: - ModeCommand::userLimit(param); - break; - default: - throw UnknownModeException(std::string(1, _modes[i])); + try { + switch (_modes[i]) { + case INVITE_ONLY: ModeCommand::inviteOnly(); break; + case TOPIC_PROTECTED: ModeCommand::topicProtected(); break; + case CHANNEL_KEY: ModeCommand::channelKey(param); break; + case CHANNEL_OPERATOR: ModeCommand::channelOperator(param); break; + case USER_LIMIT: ModeCommand::userLimit(param); break; + default: throw UnknownModeException(std::string(1, _modes[i])); + } + } catch (IRCException &e) { + server.sendExceptionMessage(clientFd, e); } } _channel.broadcastToChannel( - CMD_MSG(me.getNickname(), me.getUsername(), me.getHostname(), MODE_MSG(_channel.getName(), flag, param)) + CMD_MSG(me.getNickname(), me.getUsername(), me.getHostname(), MODE_MSG(_channel.getName(), flag, modeParams)) ); } @@ -129,6 +124,7 @@ void ModeCommand::channelKey(const std::string & param) { * Sets the user as an operator of the channel. */ void ModeCommand::channelOperator(const std::string ¶m) { + Server::getInstance().getUserByNickname(param); if (!_channel.isUserInChannel(param)) throw UserNotInChannelException(param, _channel.getName()); if (_plus)