This commit is contained in:
Kbz-8
2024-01-29 23:28:00 +01:00
parent 9e72c90b32
commit 9fc30f5ec9
4 changed files with 21 additions and 13 deletions

View File

@@ -6,7 +6,7 @@
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/21 10:33:17 by maldavid #+# #+# */
/* Updated: 2024/01/29 21:16:38 by vvaas ### ########.fr */
/* Updated: 2024/01/29 22:57:10 by maldavid ### ########.fr */
/* */
/******************************************************************************/
@@ -15,6 +15,7 @@
#include <irc.hpp>
#include <string>
#include <set>
namespace irc
{
@@ -57,9 +58,13 @@ namespace irc
void sendModular(std::string message, ...);
void sendCodeInChannel(const std::string& code, const class Channel &chan, const std::string& msg);
inline void inviteToChannel(const std::string& channel) { _invites.insert(channel); }
inline bool hasBeenInvitedTo(const std::string& channel) { return _invites.erase(channel); }
~Client();
private:
std::set<std::string> _invites;
std::string _nickname;
std::string _username;
std::string _realname;

View File

@@ -6,7 +6,7 @@
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/21 10:35:52 by maldavid #+# #+# */
/* Updated: 2024/01/29 23:10:37 by vvaas ### ########.fr */
/* Updated: 2024/01/29 23:27:33 by maldavid ### ########.fr */
/* */
/******************************************************************************/
@@ -39,7 +39,7 @@ namespace irc
void Client::sendCode(const std::string& code, const std::string& msg0, const std::string& msg1)
{
const std::string command = code + " " + msg0 + " :" + msg1 + "\r\n";
const std::string command = ":yipirc " + 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/21 09:31:17 by maldavid #+# #+# */
/* Updated: 2024/01/29 23:09:30 by vvaas ### ########.fr */
/* Updated: 2024/01/29 23:27:51 by maldavid ### ########.fr */
/* */
/******************************************************************************/
@@ -150,7 +150,7 @@ namespace irc
else if(msg.getCmd() == "JOIN")
handleJoin(client, msg);
else if(msg.getCmd() == "INVITE")
handlePrivMsg(client, msg);
handleInvite(client, msg);
else if(msg.getCmd() == "PRIVMSG")
handlePrivMsg(client, msg);
else if(msg.getCmd() == "NOTICE")

View File

@@ -6,7 +6,7 @@
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/22 17:31:06 by maldavid #+# #+# */
/* Updated: 2024/01/29 23:26:02 by vvaas ### ########.fr */
/* Updated: 2024/01/29 23:27:39 by maldavid ### ########.fr */
/* */
/******************************************************************************/
@@ -170,17 +170,16 @@ namespace irc
logs::report(log_message, "channel '%s' has been created", msg.getTokens()[1].c_str());
return ;
}
if (msg.getTokens().size() == 3 && msg.getTokens()[2] != it->getPassword())
if(msg.getTokens().size() == 3 && msg.getTokens()[2] != it->getPassword())
client->sendCode(ERR_BADCHANNELKEY, "Invalid password");
else if (it->getChannelSize() != -1 && it->getChannelSize() >= static_cast<int>(it->getNumberOfClients()))
else if(it->getChannelSize() != -1 && it->getChannelSize() >= static_cast<int>(it->getNumberOfClients()))
client->sendCode(ERR_CHANNELISFULL, "Channel is full");
else if (it->getPassword().size() == 0)
else if(it->isInviteOnly() && !client->hasBeenInvitedTo(it->getName()))
client->sendCode(ERR_INVITEONLYCHAN, "channel is invite only and you have not been invited u looser");
else if(it->getPassword().size() == 0)
it->addClient(client);
else if (it->getPassword().size() > 0 && msg.getTokens()[2] == it->getPassword())
else if(it->getPassword().size() > 0 && msg.getTokens()[2] == it->getPassword())
it->addClient(client);
// client->printUserHeader();
// std::cout << "joining new channel, " << msg.getTokens()[1] << std::endl;
}
void Server::handlePrivMsg(unstd::SharedPtr<class Client> client, const Message& msg)
@@ -336,6 +335,10 @@ namespace irc
client->sendCode(ERR_CHANOPRIVSNEEDED, msg.getArgs()[1], "you're not channel operator");
return;
}
client_target->inviteToChannel(channel_target->getName());
client_target->sendMsg(client->getNickName(), "INVITE " + msg.getArgs()[0] + ' ' + msg.getArgs()[1], "");
client->sendCode(RPL_INVITING, msg.getArgs()[1] + ' ' + msg.getArgs()[0], "");
}
void Server::handleKick(unstd::SharedPtr<class Client> client, const Message& msg)