Merge branch 'save' of github.com:Ladebeze66/ft_irc into jcheca

This commit is contained in:
jon357 2024-06-05 10:59:32 +02:00
commit ad3f0bae39
13 changed files with 136 additions and 75 deletions

View File

@ -104,6 +104,8 @@
"streambuf": "cpp",
"typeinfo": "cpp",
"ctime": "cpp",
"map": "cpp"
"map": "cpp",
"set": "cpp",
"fstream": "cpp"
}
}

View File

@ -6,7 +6,7 @@
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/15 12:41:35 by fgras-ca #+# #+# */
/* Updated: 2024/06/01 18:49:53 by fgras-ca ### ########.fr */
/* Updated: 2024/06/04 16:12:23 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
@ -51,6 +51,7 @@ class Channel
const std::string &getTopicSetter() const;
time_t getTopicTime() const;
void setTopic(const std::string &topic, const std::string &setter);
std::string getKey();
void setClientLimit(size_t limit);
size_t getClientLimit() const;

View File

@ -6,7 +6,7 @@
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/15 12:15:42 by fgras-ca #+# #+# */
/* Updated: 2024/06/01 18:47:36 by fgras-ca ### ########.fr */
/* Updated: 2024/06/05 09:34:30 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
@ -43,7 +43,6 @@ public:
void setAway(bool away);
std::string getKey() const;
void setkey(const std::string &key);
char buffer[1024];
char buffer2[1024];

View File

@ -6,7 +6,7 @@
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/15 18:30:07 by fgras-ca #+# #+# */
/* Updated: 2024/06/01 18:50:30 by fgras-ca ### ########.fr */
/* Updated: 2024/06/05 09:37:10 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */

View File

@ -6,7 +6,7 @@
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/30 11:12:57 by fgras-ca #+# #+# */
/* Updated: 2024/06/01 18:52:10 by fgras-ca ### ########.fr */
/* Updated: 2024/06/04 14:00:47 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
@ -43,7 +43,7 @@ class ModeHandler
void setChannelMode(Client *client, Channel* channel, const std::string& mode, bool adding, const std::string& argument);
void applyModeL(Client *client, Channel* channel, bool adding, const std::string& argument);
void applyModeI(Channel* channel, bool adding);
void applyModeI(Client *client, Channel* channel, bool adding);
void applyModeK(Client *client, Channel* channel, bool adding, const std::string& argument);
void applyModeT(Channel* channel, bool adding);
void applyModeO(Client *client, Channel* channel, bool adding, const std::string& argument);

View File

@ -6,7 +6,7 @@
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/19 15:12:47 by fgras-ca #+# #+# */
/* Updated: 2024/06/01 18:58:37 by fgras-ca ### ########.fr */
/* Updated: 2024/06/04 16:06:40 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
@ -18,6 +18,7 @@
#include "Client.hpp"
#include "Utils.hpp"
#include "Channel.hpp"
#define SERVER_NAME "IRC_Server"
#define SERVER_VERSION "1.0"
@ -411,6 +412,22 @@ inline std::string ERR_INVALIDKEY(Client* client, const std::string& channel)
return oss.str();
}
inline std::string ERR_KEYSET(Client* client, const std::string& channel)
{
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 467 " << CLIENT_NICK(client) << " " << channel
<< " :Channel key already set\r\n";
return oss.str();
}
inline std::string ERR_LINKSET(Client* client, const std::string& channel)
{
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 469 " << CLIENT_NICK(client) << " " << channel
<< " :No key set\r\n";
return oss.str();
}
inline std::string ERR_CHANNELISFULL(Client* client, const std::string& channel)
{
std::ostringstream oss;
@ -517,4 +534,11 @@ inline std::string RPL_CAPEND(Client *client)
return oss.str();
}
inline std::string MODEACCEPTMESSAGE(Client *client, std::string channel, const std::string& mode)
{
std::ostringstream oss;
oss << ":" << client->getNickname() << " MODE " << channel << " " << mode << " :" << "\r\n";
return oss.str();
}
#endif

View File

@ -6,7 +6,7 @@
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/15 12:15:13 by fgras-ca #+# #+# */
/* Updated: 2024/06/01 19:01:40 by fgras-ca ### ########.fr */
/* Updated: 2024/06/04 15:03:28 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
@ -83,9 +83,6 @@ class Server
private:
void initServer();
void handleServerCommands();
void acceptClient();
void removeClient(int client_fd);
};
#endif

View File

@ -6,7 +6,7 @@
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/16 15:27:29 by fgras-ca #+# #+# */
/* Updated: 2024/06/01 19:05:15 by fgras-ca ### ########.fr */
/* Updated: 2024/06/04 13:55:09 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */

View File

@ -6,7 +6,7 @@
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/15 12:42:57 by fgras-ca #+# #+# */
/* Updated: 2024/06/01 19:06:40 by fgras-ca ### ########.fr */
/* Updated: 2024/06/04 16:12:22 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
@ -141,6 +141,11 @@ void Channel::setKey(const std::string &key)
_key = key;
}
std::string Channel::getKey()
{
return _key;
}
void Channel::setTopicProtection(bool protection)
{
_topicProtection = protection;

View File

@ -6,7 +6,7 @@
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/15 18:32:23 by fgras-ca #+# #+# */
/* Updated: 2024/06/01 19:07:39 by fgras-ca ### ########.fr */
/* Updated: 2024/06/05 10:12:30 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
@ -79,7 +79,6 @@ void ClientManager::handleClient(int client_fd)
std::cout << std::endl;
}
void ClientManager::handleClientNext(int client_fd, char * buffer, int bytes_received)
{
std::string message(buffer, bytes_received);

View File

@ -6,7 +6,7 @@
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/15 18:26:34 by fgras-ca #+# #+# */
/* Updated: 2024/06/01 19:10:48 by fgras-ca ### ########.fr */
/* Updated: 2024/06/05 09:57:55 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */

View File

@ -6,7 +6,7 @@
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/30 11:13:08 by fgras-ca #+# #+# */
/* Updated: 2024/06/01 19:15:05 by fgras-ca ### ########.fr */
/* Updated: 2024/06/04 16:12:50 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
@ -134,7 +134,7 @@ void ModeHandler::setChannelMode(Client *client, Channel* channel, const std::st
}
else if (mode == "i")
{
applyModeI(channel, adding);
applyModeI(client, channel, adding);
}
else if (mode == "k")
{
@ -171,16 +171,34 @@ void ModeHandler::applyModeL(Client *client, Channel* channel, bool adding, cons
}
}
void ModeHandler::applyModeI(Channel* channel, bool adding)
void ModeHandler::applyModeI(Client *client, Channel *channel, bool adding)
{
std::string modeChange;
bool isAlreadySet;
modeChange = adding ? "+i" : "-i";
isAlreadySet = channel->isInviteOnly() == adding;
if (!isAlreadySet)
{
_server->sendToClient(client->getFd(), MODEACCEPTMESSAGE(client, channel->getName(), modeChange));
_server->log("Applying mode I: " + std::string(adding ? "Setting invite-only" : "Removing invite-only"), GREEN);
channel->setInviteOnly(adding);
}
}
void ModeHandler::applyModeK(Client *client, Channel *channel, bool adding, const std::string &argument)
{
bool isAlreadyProtected;
isAlreadyProtected = !channel->getKey().empty();
if (adding)
{
if (isAlreadyProtected)
{
_server->sendToClient(client->getFd(), ERR_KEYSET(client, channel->getName()));
_server->log("Mode +k error: Channel already has a key set", RED);
return;
}
if (argument.empty())
{
_server->sendToClient(client->getFd(), ERR_NEEDMOREPARAMS(client, "MODE +k"));
@ -193,21 +211,37 @@ void ModeHandler::applyModeK(Client *client, Channel* channel, bool adding, cons
_server->log("Invalid key for mode +k: contains spaces", RED);
return;
}
_server->sendToClient(client->getFd(), MODEACCEPTMESSAGE(client, channel->getName(), "+k " + argument));
_server->log("Applying mode K: Setting key to " + argument, GREEN);
channel->setKey(argument);
}
else
{
if (!isAlreadyProtected)
{
_server->sendToClient(client->getFd(), ERR_LINKSET(client, channel->getName()));
_server->log("Mode -k error: No key to remove", RED);
return;
}
_server->sendToClient(client->getFd(), MODEACCEPTMESSAGE(client, channel->getName(), "-k"));
_server->log("Applying mode K: Removing key", RED);
channel->setKey("");
}
}
void ModeHandler::applyModeT(Channel* channel, bool adding)
{
std::string modeChange;
bool isAlreadySet;
modeChange = adding ? "+t" : "-t";
isAlreadySet = channel->isInviteOnly() == adding;
if (!isAlreadySet)
{
_server->log("Applying mode T: " + std::string(adding ? "Setting topic protection" : "Removing topic protection"), GREEN);
channel->setTopicProtection(adding);
}
}
void ModeHandler::applyModeO(Client* client, Channel* channel, bool adding, const std::string& argument)
{

View File

@ -6,7 +6,7 @@
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/15 12:17:12 by fgras-ca #+# #+# */
/* Updated: 2024/06/01 19:16:36 by fgras-ca ### ########.fr */
/* Updated: 2024/06/05 10:18:02 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */