new methodes on class Channel(), command INVITE finished.
This commit is contained in:
parent
c94837e9dc
commit
a10815e1e2
3 changed files with 35 additions and 10 deletions
|
|
@ -6,12 +6,13 @@
|
|||
/* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/05/20 22:43:24 by rparodi #+# #+# */
|
||||
/* Updated: 2025/06/19 11:33:25 by rparodi ### ########.fr */
|
||||
/* Updated: 2025/06/19 13:46:05 by sben-tay ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "channel.hpp"
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
|
||||
Channel::Channel(const std::string &name, User *owner, size_t maxUsers, bool needInvite) : _name(name), _owner(owner), _maxUsers(maxUsers), _needInvite(needInvite) {
|
||||
this->_protectTopic = false;
|
||||
|
|
@ -60,7 +61,7 @@ std::list<User *>& Channel::getUsers() {
|
|||
*
|
||||
* @return list of Operators in the channel
|
||||
*/
|
||||
std::list<User *> Channel::getOperators() const {
|
||||
std::list<User *>& Channel::getOperators() {
|
||||
return this->_operators;
|
||||
}
|
||||
|
||||
|
|
@ -242,3 +243,18 @@ void Channel::sendAllClientInAChannel(const std::string &toSend, User *exclude)
|
|||
(*it)->appendToWriteBuffer(toSend);
|
||||
}
|
||||
}
|
||||
|
||||
void Channel::addInvited(User *user) {
|
||||
if (user && !isInvited(user))
|
||||
_invited.push_back(user);
|
||||
}
|
||||
|
||||
bool Channel::isInvited(User *user) const {
|
||||
if (user)
|
||||
{
|
||||
if (std::find(_invited.begin(), _invited.end(), user) != _invited.end())
|
||||
return true;
|
||||
}
|
||||
std::cerr << user->getName() << " is not invited to the channel " << this->_name << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */
|
||||
/* Updated: 2025/06/18 12:52:35 by rparodi ### ########.fr */
|
||||
/* Updated: 2025/06/19 13:53:17 by sben-tay ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -28,14 +28,13 @@ e_code Invite::checkArgs() {
|
|||
return ERR_NOSUCHCHANNEL;
|
||||
} else
|
||||
_args.at(1).erase(0, 1);
|
||||
_cTarget = searchList(_channels, _args.at(1));
|
||||
_cTarget = searchList(_server->getChannelsList(), _args.at(1));
|
||||
if (_cTarget == NULL) {
|
||||
WARNING_MSG("Channel not found for INVITE command");
|
||||
INFO_MSG("You can only invite users to channels you are in");
|
||||
return ERR_NOSUCHCHANNEL;
|
||||
} else
|
||||
_args.at(1).erase(0, 1);
|
||||
if (searchList(_cTarget->getOperators(), _sender->getName()) != NULL) {
|
||||
}
|
||||
if (searchList(_cTarget->getOperators(), _sender->getName()) == NULL) {
|
||||
WARNING_MSG("You are not an operator in the channel for INVITE command");
|
||||
return ERR_NOPRIVILEGES;
|
||||
}
|
||||
|
|
@ -61,10 +60,18 @@ e_code Invite::checkArgs() {
|
|||
* @brief Execute the invite command
|
||||
* @note To invite a peapol to join a channel (from an operator)
|
||||
*/
|
||||
|
||||
void Invite::execute() {
|
||||
if (checkArgs() != _PARSING_OK) {
|
||||
ERROR_MSG("Invalid arguments for INVITE command (see warning message)");
|
||||
return;
|
||||
}
|
||||
// check how the com
|
||||
|
||||
_cTarget->addInvited(_uTarget);
|
||||
|
||||
std::string msgToInvited = ":" + _sender->getPrefix() + " INVITE " + _uTarget->getNickname() + " #" + _cTarget->getName() + "\r\n";
|
||||
_uTarget->appendToWriteBuffer(msgToInvited);
|
||||
|
||||
std::string msg341 = ":localhost 341 " + _sender->getNickname() + " " + _uTarget->getNickname() + " #" + _cTarget->getName() + "\r\n";
|
||||
_sender->appendToWriteBuffer(msg341);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue