gg
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/21 10:34:25 by maldavid #+# #+# */
|
||||
/* Updated: 2024/01/25 02:18:30 by vvaas ### ########.fr */
|
||||
/* Updated: 2024/01/25 17:59:52 by vvaas ### ########.fr */
|
||||
/* */
|
||||
/******************************************************************************/
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace irc
|
||||
|
||||
inline std::size_t getNumberOfClients() const { return _clients.size(); }
|
||||
inline int getChannelSize() const { return _channel_size; }
|
||||
inline void addOperator(unstd::SharedPtr<Client> op) { _operators.insert(op); }
|
||||
void ModOperator(unstd::SharedPtr<class Client> client, const std::string &clientname, bool mode);
|
||||
inline bool removeOperator(unstd::SharedPtr<Client> op) { return _operators.erase(op); }
|
||||
void changeMode(unstd::SharedPtr<class Client> client, const Message& msg);
|
||||
bool isOp(unstd::SharedPtr<Client> client);
|
||||
@@ -51,7 +51,7 @@ namespace irc
|
||||
inline bool isInviteOnly() const { return _invite_only; }
|
||||
|
||||
void setTopic(unstd::SharedPtr<Client> client, const std::string& new_topic);
|
||||
|
||||
void showModes(void) const;
|
||||
~Channel();
|
||||
|
||||
private:
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/21 10:36:21 by maldavid #+# #+# */
|
||||
/* Updated: 2024/01/25 12:46:20 by maldavid ### ########.fr */
|
||||
/* Updated: 2024/01/25 18:09:11 by vvaas ### ########.fr */
|
||||
/* */
|
||||
/******************************************************************************/
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
#include <logs.hpp>
|
||||
#include <errorscode.hpp>
|
||||
#include <cstdlib>
|
||||
#include <unstd/string.hpp>
|
||||
|
||||
namespace irc
|
||||
{
|
||||
typedef std::set<unstd::SharedPtr<Client> >::iterator client_it;
|
||||
@@ -32,6 +34,27 @@ namespace irc
|
||||
for(client_it it = _clients.begin(); it != _clients.end(); ++it)
|
||||
const_cast<unstd::SharedPtr<irc::Client>&>(*it)->sendMsg(client->getNickName(), "JOIN", _name);
|
||||
}
|
||||
void Channel::ModOperator(unstd::SharedPtr<class Client> client, const std::string &clientname, bool mode)
|
||||
{
|
||||
client_it it;
|
||||
for (it = _clients.begin(); it != _clients.end(); ++it)
|
||||
{
|
||||
if (const_cast<unstd::SharedPtr<irc::Client>&>(*it)->getNickName() == clientname)
|
||||
_operators.insert(const_cast<unstd::SharedPtr<irc::Client>&>(*it));
|
||||
}
|
||||
if (it == _clients.end())
|
||||
client->sendCode(ERR_USERNOTINCHANNEL, "User not in channel");
|
||||
else
|
||||
{
|
||||
std::string out;
|
||||
if (mode)
|
||||
out = clientname + ": +o";
|
||||
else
|
||||
out = clientname + ": -o";
|
||||
for (it = _clients.begin(); it != _clients.end(); ++it)
|
||||
const_cast<unstd::SharedPtr<irc::Client>&>(*it)->sendMsg(client->getNickName(), "MODE", out);
|
||||
}
|
||||
}
|
||||
bool Channel::removeClient(unstd::SharedPtr<Client> client)
|
||||
{
|
||||
if (!_clients.erase(client))
|
||||
@@ -53,6 +76,24 @@ namespace irc
|
||||
}
|
||||
}
|
||||
|
||||
void Channel::showModes(void) const
|
||||
{
|
||||
std::string modes = "+";
|
||||
|
||||
if (_invite_only)
|
||||
modes += 'i';
|
||||
if (_topic_op_restrict)
|
||||
modes += 't';
|
||||
if (_password.size() > 0)
|
||||
modes += 'k';
|
||||
if (_channel_size != -1)
|
||||
{
|
||||
modes += 'l';
|
||||
modes += " " + unstd::toString(_channel_size);
|
||||
}
|
||||
for(client_it it = _clients.begin(); it != _clients.end(); ++it)
|
||||
const_cast<unstd::SharedPtr<irc::Client>&>(*it)->sendCode(RPL_CHANNELMODEIS, modes);
|
||||
}
|
||||
void Channel::changeMode(unstd::SharedPtr<class Client> client, const Message& msg)
|
||||
{
|
||||
bool modevalue = (msg.getTokens()[2][0] != '-');
|
||||
@@ -66,16 +107,26 @@ namespace irc
|
||||
_topic_op_restrict = modevalue;
|
||||
break;
|
||||
case 'k':
|
||||
logs::report(log_message, "%s password set as %s", getName().c_str(), msg.getTokens()[3].c_str());
|
||||
_password = msg.getTokens()[3];
|
||||
if (modevalue && msg.getTokens().size() < 3)
|
||||
{
|
||||
logs::report(log_message, "%s password set as %s", getName().c_str(), msg.getTokens()[3].c_str());
|
||||
_password = msg.getTokens()[3];
|
||||
}
|
||||
else if (msg.getTokens().size() < 2)
|
||||
{
|
||||
_password = "";
|
||||
logs::report(log_message, "password removed on %s", getName().c_str());
|
||||
}
|
||||
break;
|
||||
case 'o':
|
||||
if (isOp(client))
|
||||
modevalue = !modevalue; // todo sa me clc :(
|
||||
if (isOp(client) && modevalue)
|
||||
ModOperator(client, msg.getTokens()[3], modevalue);
|
||||
else
|
||||
client->sendCode(ERR_CHANOPRIVSNEEDED, "You need to be operator to execute this command");
|
||||
break;
|
||||
case 'l':
|
||||
if (msg.getTokens().size() < 3 && modevalue)
|
||||
return ;
|
||||
if (static_cast<int>(getNumberOfClients()) > std::atoi(msg.getTokens()[3].c_str()))
|
||||
return ;
|
||||
if (modevalue)
|
||||
@@ -83,6 +134,8 @@ namespace irc
|
||||
if (!modevalue)
|
||||
_channel_size = -1;
|
||||
}
|
||||
logs::report(log_message, "%s MODES : i:%d t:%d k:%s l:%d", getName().c_str(), _invite_only, _topic_op_restrict, _password.c_str(), _channel_size);
|
||||
showModes();
|
||||
}
|
||||
|
||||
void Channel::setTopic(unstd::SharedPtr<Client> client, const std::string& new_topic)
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/22 17:31:06 by maldavid #+# #+# */
|
||||
/* Updated: 2024/01/25 17:03:18 by maldavid ### ########.fr */
|
||||
/* Updated: 2024/01/25 18:04:02 by vvaas ### ########.fr */
|
||||
/* */
|
||||
/******************************************************************************/
|
||||
|
||||
@@ -357,7 +357,7 @@ namespace irc
|
||||
void Server::handleMode(unstd::SharedPtr<class Client> client, const Message& msg)
|
||||
{
|
||||
logs::report(log_message, "Mode requested");
|
||||
if (msg.getTokens().size() != 3 || (msg.getTokens().size() != 4 && !std::strchr("koi", msg.getTokens()[2][1])))
|
||||
if (msg.getTokens().size() < 3)
|
||||
return ;
|
||||
logs::report(log_message, "Mode parsing ok");
|
||||
channel_it it;
|
||||
|
||||
Reference in New Issue
Block a user