mirror of
https://github.com/Ladebeze66/ft_irc.git
synced 2025-12-17 06:28:03 +01:00
dermodif
This commit is contained in:
parent
0c3c24a2f1
commit
975373f1d8
6
.vscode/settings.json
vendored
6
.vscode/settings.json
vendored
@ -104,6 +104,8 @@
|
|||||||
"streambuf": "cpp",
|
"streambuf": "cpp",
|
||||||
"typeinfo": "cpp",
|
"typeinfo": "cpp",
|
||||||
"ctime": "cpp",
|
"ctime": "cpp",
|
||||||
"map": "cpp"
|
"map": "cpp",
|
||||||
}
|
"set": "cpp",
|
||||||
|
"fstream": "cpp"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/05/15 12:41:35 by fgras-ca #+# #+# */
|
/* 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;
|
const std::string &getTopicSetter() const;
|
||||||
time_t getTopicTime() const;
|
time_t getTopicTime() const;
|
||||||
void setTopic(const std::string &topic, const std::string &setter);
|
void setTopic(const std::string &topic, const std::string &setter);
|
||||||
|
std::string getKey();
|
||||||
|
|
||||||
void setClientLimit(size_t limit);
|
void setClientLimit(size_t limit);
|
||||||
size_t getClientLimit() const;
|
size_t getClientLimit() const;
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/05/15 12:15:42 by fgras-ca #+# #+# */
|
/* 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,6 +43,8 @@ public:
|
|||||||
void setAway(bool away);
|
void setAway(bool away);
|
||||||
std::string getKey() const;
|
std::string getKey() const;
|
||||||
void setkey(const std::string &key);
|
void setkey(const std::string &key);
|
||||||
|
char buffer[1024];
|
||||||
|
char buffer2[1024];
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int _fd;
|
int _fd;
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/05/15 18:30:07 by fgras-ca #+# #+# */
|
/* 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 */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -42,6 +42,7 @@ class ClientManager
|
|||||||
public:
|
public:
|
||||||
ClientManager(Server *server);
|
ClientManager(Server *server);
|
||||||
void acceptClient();
|
void acceptClient();
|
||||||
|
void handleClientNext(int client_fd, char * buffer, int bytes_received);
|
||||||
void handleClient(int client_fd);
|
void handleClient(int client_fd);
|
||||||
void removeClient(int client_fd);
|
void removeClient(int client_fd);
|
||||||
|
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/05/30 11:12:57 by fgras-ca #+# #+# */
|
/* 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 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 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 applyModeK(Client *client, Channel* channel, bool adding, const std::string& argument);
|
||||||
void applyModeT(Channel* channel, bool adding);
|
void applyModeT(Channel* channel, bool adding);
|
||||||
void applyModeO(Client *client, Channel* channel, bool adding, const std::string& argument);
|
void applyModeO(Client *client, Channel* channel, bool adding, const std::string& argument);
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/05/19 15:12:47 by fgras-ca #+# #+# */
|
/* 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 "Client.hpp"
|
||||||
#include "Utils.hpp"
|
#include "Utils.hpp"
|
||||||
|
#include "Channel.hpp"
|
||||||
|
|
||||||
#define SERVER_NAME "IRC_Server"
|
#define SERVER_NAME "IRC_Server"
|
||||||
#define SERVER_VERSION "1.0"
|
#define SERVER_VERSION "1.0"
|
||||||
@ -411,6 +412,22 @@ inline std::string ERR_INVALIDKEY(Client* client, const std::string& channel)
|
|||||||
return oss.str();
|
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)
|
inline std::string ERR_CHANNELISFULL(Client* client, const std::string& channel)
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
@ -517,4 +534,11 @@ inline std::string RPL_CAPEND(Client *client)
|
|||||||
return oss.str();
|
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
|
#endif
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/05/15 12:15:13 by fgras-ca #+# #+# */
|
/* 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 */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -59,7 +59,6 @@ class Server
|
|||||||
void broadcast(const std::string &message);
|
void broadcast(const std::string &message);
|
||||||
Client* getClientByName(const std::string &name);
|
Client* getClientByName(const std::string &name);
|
||||||
Channel* getChannelByName(const std::string &name);
|
Channel* getChannelByName(const std::string &name);
|
||||||
void sendChannelListToClient(Client *client);
|
|
||||||
void disconnectClient(int clientFd);
|
void disconnectClient(int clientFd);
|
||||||
bool MatchFd(const pollfd& pfd, int clientFd);
|
bool MatchFd(const pollfd& pfd, int clientFd);
|
||||||
void removePollFd(int clientFd);
|
void removePollFd(int clientFd);
|
||||||
@ -84,9 +83,6 @@ class Server
|
|||||||
private:
|
private:
|
||||||
void initServer();
|
void initServer();
|
||||||
void handleServerCommands();
|
void handleServerCommands();
|
||||||
void acceptClient();
|
|
||||||
void removeClient(int client_fd);
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/05/16 15:27:29 by fgras-ca #+# #+# */
|
/* 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 */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -65,7 +65,7 @@ void AdditionalCommands::broadcastChannelList(Client *client, Server *server)
|
|||||||
std::map<std::string, Channel *> &channels = server->getChannels();
|
std::map<std::string, Channel *> &channels = server->getChannels();
|
||||||
for (std::map<std::string, Channel *>::iterator it = channels.begin(); it != channels.end(); ++it)
|
for (std::map<std::string, Channel *>::iterator it = channels.begin(); it != channels.end(); ++it)
|
||||||
{
|
{
|
||||||
server->sendToClient(client->getFd(), RPL_LIST(client, it->first, it->second->getClients().size(), "Existing channel"));
|
server->sendToClient(client->getFd(), RPL_LIST(client, it->first, it->second->getClients().size(), it->second->getTopic()));
|
||||||
}
|
}
|
||||||
server->sendToClient(client->getFd(), RPL_LISTEND(client));
|
server->sendToClient(client->getFd(), RPL_LISTEND(client));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/05/15 12:42:57 by fgras-ca #+# #+# */
|
/* 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;
|
_key = key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string Channel::getKey()
|
||||||
|
{
|
||||||
|
return _key;
|
||||||
|
}
|
||||||
|
|
||||||
void Channel::setTopicProtection(bool protection)
|
void Channel::setTopicProtection(bool protection)
|
||||||
{
|
{
|
||||||
_topicProtection = protection;
|
_topicProtection = protection;
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/05/15 18:32:23 by fgras-ca #+# #+# */
|
/* 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 */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -38,9 +38,12 @@ void ClientManager::acceptClient()
|
|||||||
|
|
||||||
void ClientManager::handleClient(int client_fd)
|
void ClientManager::handleClient(int client_fd)
|
||||||
{
|
{
|
||||||
char buffer[1024];
|
Client* client = _server->getClients()[client_fd];
|
||||||
std::memset(buffer, 0, sizeof(buffer));
|
// char buffer[1024];
|
||||||
int bytes_received = recv(client_fd, buffer, sizeof(buffer), 0);
|
// char buffer2[1024];
|
||||||
|
|
||||||
|
std::memset(client->buffer, 0, sizeof(client->buffer));
|
||||||
|
int bytes_received = recv(client_fd, client->buffer, sizeof(client->buffer), 0);
|
||||||
|
|
||||||
if (bytes_received <= 0)
|
if (bytes_received <= 0)
|
||||||
{
|
{
|
||||||
@ -51,6 +54,33 @@ void ClientManager::handleClient(int client_fd)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::cout << std::string(client->buffer).size() << " client->buffer " << std::string(client->buffer).find('\n') << std::endl;
|
||||||
|
|
||||||
|
for (size_t i = 0; client->buffer[i];i++)
|
||||||
|
{
|
||||||
|
std::cout << client->buffer[i] << " .. ";
|
||||||
|
}
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
if (std::string(client->buffer).find('\n') != std::string::npos)
|
||||||
|
{
|
||||||
|
strcat(client->buffer2, client->buffer);
|
||||||
|
handleClientNext(client_fd, client->buffer2, std::string(client->buffer2).size());
|
||||||
|
std::memset(client->buffer2, 0, std::string(client->buffer2).size());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
strcat(client->buffer2, client->buffer);
|
||||||
|
for (size_t i = 0; client->buffer2[i];i++)
|
||||||
|
{
|
||||||
|
std::cout << client->buffer2[i] << " . ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::cout << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ClientManager::handleClientNext(int client_fd, char * buffer, int bytes_received)
|
||||||
|
{
|
||||||
std::string message(buffer, bytes_received);
|
std::string message(buffer, bytes_received);
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << "Received from client " << client_fd << ": " << message;
|
oss << "Received from client " << client_fd << ": " << message;
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/05/15 18:26:34 by fgras-ca #+# #+# */
|
/* 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 */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -201,6 +201,7 @@ void CommandHandler::handleNick(Client* client, const std::vector<std::string>&
|
|||||||
std::string nickMessage = ":" + oldNick + " NICK " + newNick + "\r\n";
|
std::string nickMessage = ":" + oldNick + " NICK " + newNick + "\r\n";
|
||||||
for (std::map<int, Client*>::iterator it = _server->_clients.begin(); it != _server->_clients.end(); ++it)
|
for (std::map<int, Client*>::iterator it = _server->_clients.begin(); it != _server->_clients.end(); ++it)
|
||||||
{
|
{
|
||||||
|
if (it->second->isAuthenticated())
|
||||||
_server->sendToClient(it->second->getFd(), nickMessage);
|
_server->sendToClient(it->second->getFd(), nickMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/05/30 11:13:08 by fgras-ca #+# #+# */
|
/* 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")
|
else if (mode == "i")
|
||||||
{
|
{
|
||||||
applyModeI(channel, adding);
|
applyModeI(client, channel, adding);
|
||||||
}
|
}
|
||||||
else if (mode == "k")
|
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);
|
_server->log("Applying mode I: " + std::string(adding ? "Setting invite-only" : "Removing invite-only"), GREEN);
|
||||||
channel->setInviteOnly(adding);
|
channel->setInviteOnly(adding);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModeHandler::applyModeK(Client *client, Channel* channel, bool adding, const std::string& argument)
|
void ModeHandler::applyModeK(Client *client, Channel *channel, bool adding, const std::string &argument)
|
||||||
{
|
{
|
||||||
|
bool isAlreadyProtected;
|
||||||
|
|
||||||
|
isAlreadyProtected = !channel->getKey().empty();
|
||||||
if (adding)
|
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())
|
if (argument.empty())
|
||||||
{
|
{
|
||||||
_server->sendToClient(client->getFd(), ERR_NEEDMOREPARAMS(client, "MODE +k"));
|
_server->sendToClient(client->getFd(), ERR_NEEDMOREPARAMS(client, "MODE +k"));
|
||||||
@ -193,11 +211,19 @@ void ModeHandler::applyModeK(Client *client, Channel* channel, bool adding, cons
|
|||||||
_server->log("Invalid key for mode +k: contains spaces", RED);
|
_server->log("Invalid key for mode +k: contains spaces", RED);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
_server->sendToClient(client->getFd(), MODEACCEPTMESSAGE(client, channel->getName(), "+k " + argument));
|
||||||
_server->log("Applying mode K: Setting key to " + argument, GREEN);
|
_server->log("Applying mode K: Setting key to " + argument, GREEN);
|
||||||
channel->setKey(argument);
|
channel->setKey(argument);
|
||||||
}
|
}
|
||||||
else
|
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);
|
_server->log("Applying mode K: Removing key", RED);
|
||||||
channel->setKey("");
|
channel->setKey("");
|
||||||
}
|
}
|
||||||
@ -205,8 +231,16 @@ void ModeHandler::applyModeK(Client *client, Channel* channel, bool adding, cons
|
|||||||
|
|
||||||
void ModeHandler::applyModeT(Channel* channel, bool adding)
|
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);
|
_server->log("Applying mode T: " + std::string(adding ? "Setting topic protection" : "Removing topic protection"), GREEN);
|
||||||
channel->setTopicProtection(adding);
|
channel->setTopicProtection(adding);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModeHandler::applyModeO(Client* client, Channel* channel, bool adding, const std::string& argument)
|
void ModeHandler::applyModeO(Client* client, Channel* channel, bool adding, const std::string& argument)
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/05/15 12:17:12 by fgras-ca #+# #+# */
|
/* 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 */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -218,16 +218,6 @@ Channel* Server::getChannelByName(const std::string &name)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::sendChannelListToClient(Client *client)
|
|
||||||
{
|
|
||||||
std::map<std::string, Channel *> &channels = getChannels();
|
|
||||||
for (std::map<std::string, Channel *>::iterator it = channels.begin(); it != channels.end(); ++it)
|
|
||||||
{
|
|
||||||
sendToClient(client->getFd(), RPL_LIST(client, it->first, it->second->getClients().size(), "Existing channel"));
|
|
||||||
}
|
|
||||||
sendToClient(client->getFd(), RPL_LISTEND(client));
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Server::MatchFd(const pollfd& pfd, int clientFd)
|
bool Server::MatchFd(const pollfd& pfd, int clientFd)
|
||||||
{
|
{
|
||||||
return pfd.fd == clientFd;
|
return pfd.fd == clientFd;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user