jss trop beau srx
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 23:04:45 by maldavid ### ########.fr */
|
/* Updated: 2024/01/26 02:08:19 by vvaas ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
@@ -55,8 +55,8 @@ namespace irc
|
|||||||
|
|
||||||
void setTopic(unstd::SharedPtr<Client> client, const std::string& new_topic);
|
void setTopic(unstd::SharedPtr<Client> client, const std::string& new_topic);
|
||||||
void relayTopic(unstd::SharedPtr<Client> client);
|
void relayTopic(unstd::SharedPtr<Client> client);
|
||||||
void showModes() const;
|
void showModesModify(unstd::SharedPtr<Client> client, const Message& msg) const;
|
||||||
|
void showModes(unstd::SharedPtr<Client> client);
|
||||||
bool kick(unstd::SharedPtr<Client> op, unstd::SharedPtr<Client> target, const std::string& reason);
|
bool kick(unstd::SharedPtr<Client> op, unstd::SharedPtr<Client> target, const std::string& reason);
|
||||||
|
|
||||||
~Channel();
|
~Channel();
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/01/21 10:33:17 by maldavid #+# #+# */
|
/* Created: 2024/01/21 10:33:17 by maldavid #+# #+# */
|
||||||
/* Updated: 2024/01/24 18:34:36 by vvaas ### ########.fr */
|
/* Updated: 2024/01/26 00:58:20 by vvaas ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
@@ -52,6 +52,7 @@ namespace irc
|
|||||||
|
|
||||||
void sendPlainText(const std::string& str);
|
void sendPlainText(const std::string& str);
|
||||||
void sendCode(const std::string& code, const std::string& msg);
|
void sendCode(const std::string& code, const std::string& msg);
|
||||||
|
void sendCode(const std::string& code, const std::string& msg0, const std::string& msg1);
|
||||||
void sendMsg(const std::string& sender, const std::string& cmd, const std::string& trailing);
|
void sendMsg(const std::string& sender, const std::string& cmd, const std::string& trailing);
|
||||||
void sendModular(std::string message, ...);
|
void sendModular(std::string message, ...);
|
||||||
|
|
||||||
|
|||||||
@@ -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 18:44:01 by vvaas ### ########.fr */
|
/* Updated: 2024/01/26 00:42:56 by vvaas ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
|
|||||||
@@ -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 22:45:17 by vvaas ### ########.fr */
|
/* Updated: 2024/01/26 02:10:11 by vvaas ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
@@ -21,7 +21,7 @@ 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;
|
typedef std::set<unstd::SharedPtr<Client> >::const_iterator client_const_it;
|
||||||
|
|
||||||
Channel::Channel(const std::string& name) : _name(name), _channel_size(-1), _topic_op_restrict(false) {}
|
Channel::Channel(const std::string& name) : _name(name), _channel_size(-1), _invite_only(false), _topic_op_restrict(false) {}
|
||||||
|
|
||||||
void Channel::addClient(unstd::SharedPtr<Client> client, bool op)
|
void Channel::addClient(unstd::SharedPtr<Client> client, bool op)
|
||||||
{
|
{
|
||||||
@@ -98,7 +98,22 @@ namespace irc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Channel::showModes(void) const
|
void Channel::showModesModify(unstd::SharedPtr<Client> client, const Message& msg) const
|
||||||
|
{
|
||||||
|
std::vector<std::string> mode = msg.getArgs();
|
||||||
|
std::string modes;
|
||||||
|
std::string out = "MODE ";
|
||||||
|
|
||||||
|
for (std::vector<std::string>::iterator it = mode.begin() + 1; it != mode.end(); ++it)
|
||||||
|
{
|
||||||
|
modes += *it;
|
||||||
|
modes += " ";
|
||||||
|
}
|
||||||
|
out += getName();
|
||||||
|
for(client_it it = _clients.begin(); it != _clients.end(); ++it)
|
||||||
|
const_cast<unstd::SharedPtr<irc::Client>&>(*it)->sendMsg(client->getNickName(), out, modes);
|
||||||
|
}
|
||||||
|
void Channel::showModes(unstd::SharedPtr<Client> client)
|
||||||
{
|
{
|
||||||
std::string modes = "+";
|
std::string modes = "+";
|
||||||
|
|
||||||
@@ -109,14 +124,9 @@ namespace irc
|
|||||||
if (_password.size() > 0)
|
if (_password.size() > 0)
|
||||||
modes += 'k';
|
modes += 'k';
|
||||||
if (_channel_size != -1)
|
if (_channel_size != -1)
|
||||||
{
|
|
||||||
modes += 'l';
|
modes += 'l';
|
||||||
modes += " " + unstd::toString(_channel_size);
|
client->sendCode(RPL_CHANNELMODEIS, modes);
|
||||||
}
|
|
||||||
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)
|
void Channel::changeMode(unstd::SharedPtr<class Client> client, const Message& msg)
|
||||||
{
|
{
|
||||||
bool modevalue = (msg.getTokens()[2][0] != '-');
|
bool modevalue = (msg.getTokens()[2][0] != '-');
|
||||||
@@ -159,7 +169,7 @@ namespace irc
|
|||||||
_channel_size = -1;
|
_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);
|
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();
|
showModesModify(client, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Channel::hasClient(std::string client) const
|
bool Channel::hasClient(std::string client) const
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/01/21 10:35:52 by maldavid #+# #+# */
|
/* Created: 2024/01/21 10:35:52 by maldavid #+# #+# */
|
||||||
/* Updated: 2024/01/25 21:55:52 by maldavid ### ########.fr */
|
/* Updated: 2024/01/26 02:26:04 by vvaas ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
@@ -28,7 +28,17 @@ namespace irc
|
|||||||
|
|
||||||
void Client::sendCode(const std::string& code, const std::string& msg)
|
void Client::sendCode(const std::string& code, const std::string& msg)
|
||||||
{
|
{
|
||||||
const std::string command = code + " : " + msg + "\r";
|
const std::string command = ":yipirc " + code + " " + getNickName() + " :" + msg + "\r\n";
|
||||||
|
#ifdef DEBUG
|
||||||
|
logs::report(log_message, "sending '%s'", command.c_str());
|
||||||
|
#endif
|
||||||
|
if(send(_fd, command.c_str(), command.size(), 0) != static_cast<ssize_t>(command.length()))
|
||||||
|
logs::report(log_error, "server failed to send a code to '%s' (:sadge:)", _username.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
void Client::sendCode(const std::string& code, const std::string& msg0, const std::string& msg1)
|
||||||
|
{
|
||||||
|
const std::string command = code + " " + msg0 + " :" + msg1 + "\r\n";
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
logs::report(log_message, "sending '%s'", command.c_str());
|
logs::report(log_message, "sending '%s'", command.c_str());
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -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 23:01:42 by maldavid ### ########.fr */
|
/* Updated: 2024/01/26 02:29:06 by vvaas ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
@@ -52,6 +52,8 @@ namespace irc
|
|||||||
client->printUserHeader();
|
client->printUserHeader();
|
||||||
client->setNewNickName(msg.getTokens()[1]);
|
client->setNewNickName(msg.getTokens()[1]);
|
||||||
client->sendMsg(oldNick, "NICK", msg.getTokens()[1]);
|
client->sendMsg(oldNick, "NICK", msg.getTokens()[1]);
|
||||||
|
if (client->isLogged())
|
||||||
|
client->sendCode(RPL_WELCOME, "Welcome to yipiirc :)\n");
|
||||||
std::cout << "new nickname, " << client->getNickName() << std::endl;
|
std::cout << "new nickname, " << client->getNickName() << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,7 +80,8 @@ namespace irc
|
|||||||
if(msg.getTokens()[1] == _password)
|
if(msg.getTokens()[1] == _password)
|
||||||
{
|
{
|
||||||
client->login();
|
client->login();
|
||||||
client->sendCode("Welcome to", "yipiirc :)\n");
|
if (client->getNickName().size() != 0)
|
||||||
|
client->sendCode(RPL_WELCOME, "Welcome to yipiirc :)\n");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -395,14 +398,24 @@ namespace irc
|
|||||||
void Server::handleMode(unstd::SharedPtr<class Client> client, const Message& msg)
|
void Server::handleMode(unstd::SharedPtr<class Client> client, const Message& msg)
|
||||||
{
|
{
|
||||||
logs::report(log_message, "Mode requested");
|
logs::report(log_message, "Mode requested");
|
||||||
if (msg.getTokens().size() < 3)
|
irc::Channel *chan;
|
||||||
|
if (msg.getTokens().size() < 2)
|
||||||
return ;
|
return ;
|
||||||
|
if (msg.getTokens().size() == 2 && (msg.getTokens()[1][0] == '#' || msg.getTokens()[1][0] == '&'))
|
||||||
|
{
|
||||||
|
chan = getChannelByName(msg.getTokens()[1]);
|
||||||
|
if (chan == NULL)
|
||||||
|
client->sendCode(ERR_NOSUCHCHANNEL, "No such channel");
|
||||||
|
else
|
||||||
|
chan->showModes(client);
|
||||||
|
return ;
|
||||||
|
}
|
||||||
logs::report(log_message, "Mode parsing ok");
|
logs::report(log_message, "Mode parsing ok");
|
||||||
channel_it it;
|
channel_it it;
|
||||||
for (it = _channels.begin(); it != _channels.end() && it->getName() != msg.getTokens()[1]; ++it);
|
for (it = _channels.begin(); it != _channels.end() && it->getName() != msg.getTokens()[1]; ++it);
|
||||||
if (it == _channels.end())
|
if (it == _channels.end())
|
||||||
client->sendCode(ERR_NOSUCHCHANNEL, "No such channel");
|
client->sendCode(ERR_NOSUCHCHANNEL, "No such channel");
|
||||||
if (!it->isOp(client))
|
if (getChannelByName(msg.getTokens()[1]) && !it->isOp(client))
|
||||||
client->sendCode(ERR_CHANOPRIVSNEEDED, "You need operator privileges to execute this command");
|
client->sendCode(ERR_CHANOPRIVSNEEDED, "You need operator privileges to execute this command");
|
||||||
if (msg.getTokens()[2][0] != '-' && msg.getTokens()[2][0] != '+')
|
if (msg.getTokens()[2][0] != '-' && msg.getTokens()[2][0] != '+')
|
||||||
return ;
|
return ;
|
||||||
|
|||||||
Reference in New Issue
Block a user