dfsdkjbsdf
This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/01/21 10:34:25 by maldavid #+# #+# */
|
/* Created: 2024/01/21 10:34:25 by maldavid #+# #+# */
|
||||||
/* Updated: 2024/01/25 17:59:52 by vvaas ### ########.fr */
|
/* Updated: 2024/01/25 18:11:58 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
@@ -45,13 +45,19 @@ namespace irc
|
|||||||
void ModOperator(unstd::SharedPtr<class Client> client, const std::string &clientname, bool mode);
|
void ModOperator(unstd::SharedPtr<class Client> client, const std::string &clientname, bool mode);
|
||||||
inline bool removeOperator(unstd::SharedPtr<Client> op) { return _operators.erase(op); }
|
inline bool removeOperator(unstd::SharedPtr<Client> op) { return _operators.erase(op); }
|
||||||
void changeMode(unstd::SharedPtr<class Client> client, const Message& msg);
|
void changeMode(unstd::SharedPtr<class Client> client, const Message& msg);
|
||||||
bool isOp(unstd::SharedPtr<Client> client);
|
bool isOp(unstd::SharedPtr<Client> client) const;
|
||||||
void handleMessage(const std::string& msg, unstd::SharedPtr<Client> client, bool notice = false) const;
|
void handleMessage(const std::string& msg, unstd::SharedPtr<Client> client, bool notice = false) const;
|
||||||
|
|
||||||
|
inline bool hasClient(unstd::SharedPtr<Client> client) const { return _clients.find(client) != _clients.end(); }
|
||||||
|
bool hasClient(std::string client) const;
|
||||||
|
|
||||||
inline bool isInviteOnly() const { return _invite_only; }
|
inline bool isInviteOnly() const { return _invite_only; }
|
||||||
|
|
||||||
void setTopic(unstd::SharedPtr<Client> client, const std::string& new_topic);
|
void setTopic(unstd::SharedPtr<Client> client, const std::string& new_topic);
|
||||||
void showModes(void) const;
|
void showModes(void) const;
|
||||||
|
|
||||||
|
bool kick(unstd::SharedPtr<Client> op, unstd::SharedPtr<Client> target, const std::string& reason);
|
||||||
|
|
||||||
~Channel();
|
~Channel();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/01/21 09:12:28 by maldavid #+# #+# */
|
/* Created: 2024/01/21 09:12:28 by maldavid #+# #+# */
|
||||||
/* Updated: 2024/01/25 16:39:18 by maldavid ### ########.fr */
|
/* Updated: 2024/01/25 17:21:25 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
@@ -62,6 +62,9 @@ namespace irc
|
|||||||
void handlePing(unstd::SharedPtr<class Client> client, const class Message& msg);
|
void handlePing(unstd::SharedPtr<class Client> client, const class Message& msg);
|
||||||
void handleMode(unstd::SharedPtr<class Client> client, const class Message& msg);
|
void handleMode(unstd::SharedPtr<class Client> client, const class Message& msg);
|
||||||
|
|
||||||
|
class Channel* getChannelByName(const std::string& name);
|
||||||
|
unstd::SharedPtr<class Client> getClientByName(const std::string& name);
|
||||||
|
|
||||||
bool isUserKnown(const std::string& user) const;
|
bool isUserKnown(const std::string& user) const;
|
||||||
bool isChannelKnown(const std::string& channel) const;
|
bool isChannelKnown(const std::string& channel) const;
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/01/21 10:36:21 by maldavid #+# #+# */
|
/* Created: 2024/01/21 10:36:21 by maldavid #+# #+# */
|
||||||
/* Updated: 2024/01/25 18:09:11 by vvaas ### ########.fr */
|
/* Updated: 2024/01/25 18:11:45 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
@@ -19,6 +19,7 @@
|
|||||||
namespace irc
|
namespace irc
|
||||||
{
|
{
|
||||||
typedef std::set<unstd::SharedPtr<Client> >::iterator client_it;
|
typedef std::set<unstd::SharedPtr<Client> >::iterator client_it;
|
||||||
|
typedef std::set<unstd::SharedPtr<Client> >::const_iterator client_const_it;
|
||||||
|
|
||||||
Channel::Channel(const std::string& name) : _name(name), _channel_size(-1) {}
|
Channel::Channel(const std::string& name) : _name(name), _channel_size(-1) {}
|
||||||
|
|
||||||
@@ -57,9 +58,9 @@ namespace irc
|
|||||||
}
|
}
|
||||||
bool Channel::removeClient(unstd::SharedPtr<Client> client)
|
bool Channel::removeClient(unstd::SharedPtr<Client> client)
|
||||||
{
|
{
|
||||||
if (!_clients.erase(client))
|
if(!_clients.erase(client))
|
||||||
return (false);
|
return (false);
|
||||||
for (client_it it = _clients.begin(); it != _clients.end(); ++it)
|
for(client_it it = _clients.begin(); it != _clients.end(); ++it)
|
||||||
const_cast<unstd::SharedPtr<irc::Client>&>(*it)->sendMsg(client->getNickName(), "PART", _name);
|
const_cast<unstd::SharedPtr<irc::Client>&>(*it)->sendMsg(client->getNickName(), "PART", _name);
|
||||||
client->sendMsg(client->getNickName(), "PART", _name);
|
client->sendMsg(client->getNickName(), "PART", _name);
|
||||||
return (true);
|
return (true);
|
||||||
@@ -138,6 +139,16 @@ namespace irc
|
|||||||
showModes();
|
showModes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Channel::hasClient(std::string client) const
|
||||||
|
{
|
||||||
|
for(client_const_it it = _clients.begin(); it != _clients.end(); ++it)
|
||||||
|
{
|
||||||
|
if(const_cast<unstd::SharedPtr<irc::Client>&>(*it)->getNickName() == client)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void Channel::setTopic(unstd::SharedPtr<Client> client, const std::string& new_topic)
|
void Channel::setTopic(unstd::SharedPtr<Client> client, const std::string& new_topic)
|
||||||
{
|
{
|
||||||
if(_topic_op_restrict && !isOp(client))
|
if(_topic_op_restrict && !isOp(client))
|
||||||
@@ -148,14 +159,38 @@ namespace irc
|
|||||||
_topic = new_topic;
|
_topic = new_topic;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Channel::isOp(unstd::SharedPtr<Client> client)
|
bool Channel::isOp(unstd::SharedPtr<Client> client) const
|
||||||
{
|
{
|
||||||
for (client_it it = _clients.begin(); it != _clients.end(); ++it)
|
for(client_const_it it = _clients.begin(); it != _clients.end(); ++it)
|
||||||
{
|
{
|
||||||
if (const_cast<unstd::SharedPtr<irc::Client>&>(*it)->getNickName() == client->getNickName())
|
if(const_cast<unstd::SharedPtr<irc::Client>&>(*it)->getNickName() == client->getNickName())
|
||||||
return (true);
|
return true;
|
||||||
}
|
}
|
||||||
return (false);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Channel::kick(unstd::SharedPtr<Client> op, unstd::SharedPtr<Client> target, const std::string& reason)
|
||||||
|
{
|
||||||
|
if(!hasClient(op))
|
||||||
|
{
|
||||||
|
op->sendCode(ERR_NOTONCHANNEL, _name + " you're not on that channel");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(!hasClient(target))
|
||||||
|
{
|
||||||
|
op->sendCode(ERR_USERNOTINCHANNEL, const_cast<std::string&>(target->getNickName()) + std::string(" " + _name) + " they aren't on that channel");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(!isOp(op))
|
||||||
|
{
|
||||||
|
op->sendCode(ERR_CHANOPRIVSNEEDED, const_cast<std::string&>(_name) + " you're not channel operator");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for(client_it it = _clients.begin(); it != _clients.end(); ++it)
|
||||||
|
const_cast<unstd::SharedPtr<irc::Client>&>(*it)->sendMsg(op->getNickName(), "KICK " + _name + ' ' + target->getNickName(), reason);
|
||||||
|
_clients.erase(target);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
Channel::~Channel() {}
|
Channel::~Channel() {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/01/21 11:38:34 by maldavid #+# #+# */
|
/* Created: 2024/01/21 11:38:34 by maldavid #+# #+# */
|
||||||
/* Updated: 2024/01/25 13:21:33 by maldavid ### ########.fr */
|
/* Updated: 2024/01/25 18:06:49 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -56,7 +56,7 @@ namespace irc
|
|||||||
_command = tokens[0];
|
_command = tokens[0];
|
||||||
_tokens = tokens;
|
_tokens = tokens;
|
||||||
bool reason = false;
|
bool reason = false;
|
||||||
for(std::vector<std::string>::iterator it = tokens.begin(); it != tokens.end(); ++it)
|
for(std::vector<std::string>::iterator it = tokens.begin() + 1; it < tokens.end(); ++it)
|
||||||
{
|
{
|
||||||
if((*it)[0] == ':')
|
if((*it)[0] == ':')
|
||||||
reason = true;
|
reason = true;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/01/21 09:31:17 by maldavid #+# #+# */
|
/* Created: 2024/01/21 09:31:17 by maldavid #+# #+# */
|
||||||
/* Updated: 2024/01/25 16:39:09 by maldavid ### ########.fr */
|
/* Updated: 2024/01/25 17:23:12 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
@@ -184,6 +184,26 @@ namespace irc
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Channel* Server::getChannelByName(const std::string& name)
|
||||||
|
{
|
||||||
|
for(channel_it it = _channels.begin(); it < _channels.end(); ++it)
|
||||||
|
{
|
||||||
|
if(it->getName() == name)
|
||||||
|
return &*it;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
unstd::SharedPtr<Client> Server::getClientByName(const std::string& name)
|
||||||
|
{
|
||||||
|
for(client_it it = _client.begin(); it < _client.end(); ++it)
|
||||||
|
{
|
||||||
|
if((*it)->getNickName() == name)
|
||||||
|
return *it;
|
||||||
|
}
|
||||||
|
return unstd::SharedPtr<Client>(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
Server::~Server()
|
Server::~Server()
|
||||||
{
|
{
|
||||||
closeMainSocket();
|
closeMainSocket();
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/01/22 17:31:06 by maldavid #+# #+# */
|
/* Created: 2024/01/22 17:31:06 by maldavid #+# #+# */
|
||||||
/* Updated: 2024/01/25 18:04:02 by vvaas ### ########.fr */
|
/* Updated: 2024/01/25 18:11:24 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
@@ -293,11 +293,13 @@ namespace irc
|
|||||||
|
|
||||||
void Server::handleKick(unstd::SharedPtr<class Client> client, const Message& msg)
|
void Server::handleKick(unstd::SharedPtr<class Client> client, const Message& msg)
|
||||||
{
|
{
|
||||||
|
std::cout << "kick" << std::endl;
|
||||||
if(msg.getArgs().empty())
|
if(msg.getArgs().empty())
|
||||||
{
|
{
|
||||||
logs::report(log_error, "KICK, invalid command '%s'", msg.getRawMsg().c_str());
|
logs::report(log_error, "KICK, invalid command '%s'", msg.getRawMsg().c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
std::cout << "kick" << std::endl;
|
||||||
|
|
||||||
typedef std::vector<std::string>::iterator name_it;
|
typedef std::vector<std::string>::iterator name_it;
|
||||||
std::vector<std::string> channels = unstd::split(msg.getArgs()[0], ',');
|
std::vector<std::string> channels = unstd::split(msg.getArgs()[0], ',');
|
||||||
@@ -308,18 +310,37 @@ namespace irc
|
|||||||
client->sendCode(ERR_NEEDMOREPARAMS, "KICK : Not enough parameters");
|
client->sendCode(ERR_NEEDMOREPARAMS, "KICK : Not enough parameters");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
std::cout << "kick" << std::endl;
|
||||||
for(name_it user = users.begin(), channel = channels.begin(); user < users.end(); ++user, ++channel)
|
for(name_it user = users.begin(), channel = channels.begin(); user < users.end(); ++user, ++channel)
|
||||||
{
|
{
|
||||||
|
std::cout << *user << " " << *channel << std::endl;
|
||||||
if(!isUserKnown(*user))
|
if(!isUserKnown(*user))
|
||||||
{
|
{
|
||||||
client->sendCode(ERR_NOSUCHNICK, const_cast<std::string&>(*user) + " no such nick");
|
client->sendCode(ERR_NOSUCHNICK, const_cast<std::string&>(*user) + " no such nick");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
std::cout << *user << " " << *channel << std::endl;
|
||||||
if(!isChannelKnown(*channel))
|
if(!isChannelKnown(*channel))
|
||||||
{
|
{
|
||||||
client->sendCode(ERR_NOSUCHNICK, const_cast<std::string&>(*channel) + " no such channel");
|
client->sendCode(ERR_NOSUCHCHANNEL, const_cast<std::string&>(*channel) + " no such channel");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
std::cout << *user << " " << *channel << std::endl;
|
||||||
|
|
||||||
|
Channel* channel_target = getChannelByName(*channel);
|
||||||
|
if(channel_target == NULL)
|
||||||
|
logs::report(log_fatal_error, "(KICK), cannot get channel '%s' by name; panic !", channel->c_str());
|
||||||
|
unstd::SharedPtr<Client> client_target = getClientByName(*user);
|
||||||
|
if(client_target.get() == NULL)
|
||||||
|
logs::report(log_fatal_error, "(KICK), cannot get client '%s' by name; panic !", user->c_str());
|
||||||
|
|
||||||
|
if(!channel_target->kick(client, client_target, msg.getReason()))
|
||||||
|
{
|
||||||
|
logs::report(log_error, "could not kick %s because why not", user->c_str());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
client->printUserHeader();
|
||||||
|
std::cout << "kicked " << *user << " from " << *channel << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user