jss trop beau srx

This commit is contained in:
2024-01-26 02:32:56 +01:00
parent b07f2a7a22
commit a8d7148d39
6 changed files with 55 additions and 21 deletions

View File

@@ -6,7 +6,7 @@
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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> >::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)
{
@@ -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 = "+";
@@ -109,14 +124,9 @@ namespace irc
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);
client->sendCode(RPL_CHANNELMODEIS, modes);
}
void Channel::changeMode(unstd::SharedPtr<class Client> client, const Message& msg)
{
bool modevalue = (msg.getTokens()[2][0] != '-');
@@ -159,7 +169,7 @@ namespace irc
_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();
showModesModify(client, msg);
}
bool Channel::hasClient(std::string client) const

View File

@@ -6,7 +6,7 @@
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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)
{
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
logs::report(log_message, "sending '%s'", command.c_str());
#endif

View File

@@ -6,7 +6,7 @@
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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->setNewNickName(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;
}
@@ -78,7 +80,8 @@ namespace irc
if(msg.getTokens()[1] == _password)
{
client->login();
client->sendCode("Welcome to", "yipiirc :)\n");
if (client->getNickName().size() != 0)
client->sendCode(RPL_WELCOME, "Welcome to yipiirc :)\n");
}
else
{
@@ -395,14 +398,24 @@ namespace irc
void Server::handleMode(unstd::SharedPtr<class Client> client, const Message& msg)
{
logs::report(log_message, "Mode requested");
if (msg.getTokens().size() < 3)
irc::Channel *chan;
if (msg.getTokens().size() < 2)
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");
channel_it it;
for (it = _channels.begin(); it != _channels.end() && it->getName() != msg.getTokens()[1]; ++it);
if (it == _channels.end())
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");
if (msg.getTokens()[2][0] != '-' && msg.getTokens()[2][0] != '+')
return ;