gg
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/21 10:34:25 by maldavid #+# #+# */
|
||||
/* Updated: 2024/01/25 18:11:58 by maldavid ### ########.fr */
|
||||
/* Updated: 2024/01/25 19:38:50 by vvaas ### ########.fr */
|
||||
/* */
|
||||
/******************************************************************************/
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace irc
|
||||
void changeMode(unstd::SharedPtr<class Client> client, const Message& msg);
|
||||
bool isOp(unstd::SharedPtr<Client> client) const;
|
||||
void handleMessage(const std::string& msg, unstd::SharedPtr<Client> client, bool notice = false) const;
|
||||
|
||||
void sendWho(unstd::SharedPtr<Client> client);
|
||||
inline bool hasClient(unstd::SharedPtr<Client> client) const { return _clients.find(client) != _clients.end(); }
|
||||
bool hasClient(std::string client) const;
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/21 09:12:28 by maldavid #+# #+# */
|
||||
/* Updated: 2024/01/25 17:21:25 by maldavid ### ########.fr */
|
||||
/* Updated: 2024/01/25 18:44:01 by vvaas ### ########.fr */
|
||||
/* */
|
||||
/******************************************************************************/
|
||||
|
||||
@@ -57,6 +57,7 @@ namespace irc
|
||||
void handleInvite(unstd::SharedPtr<class Client> client, const class Message& msg);
|
||||
void handlePrivMsg(unstd::SharedPtr<class Client> client, const class Message& msg);
|
||||
void handleNotice(unstd::SharedPtr<class Client> client, const class Message& msg);
|
||||
void handleWho(unstd::SharedPtr<class Client> client, const class Message& msg);
|
||||
void handleKick(unstd::SharedPtr<class Client> client, const class Message& msg);
|
||||
void handleTopic(unstd::SharedPtr<class Client> client, const class Message& msg);
|
||||
void handlePing(unstd::SharedPtr<class Client> client, const class Message& msg);
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/21 10:36:21 by maldavid #+# #+# */
|
||||
/* Updated: 2024/01/25 18:25:27 by vvaas ### ########.fr */
|
||||
/* Updated: 2024/01/25 21:15:06 by vvaas ### ########.fr */
|
||||
/* */
|
||||
/******************************************************************************/
|
||||
|
||||
@@ -58,14 +58,28 @@ namespace irc
|
||||
}
|
||||
bool Channel::removeClient(unstd::SharedPtr<Client> client)
|
||||
{
|
||||
if(!_clients.erase(client))
|
||||
if (!_clients.erase(client))
|
||||
return (false);
|
||||
if (isOp(client))
|
||||
_operators.erase(client);
|
||||
for(client_it it = _clients.begin(); it != _clients.end(); ++it)
|
||||
const_cast<unstd::SharedPtr<irc::Client>&>(*it)->sendMsg(client->getNickName(), "PART", _name);
|
||||
client->sendMsg(client->getNickName(), "PART", _name);
|
||||
return (true);
|
||||
}
|
||||
|
||||
void Channel::sendWho(unstd::SharedPtr<Client> client)
|
||||
{
|
||||
std::string clientlist(RPL_NAMREPLY " " + client->getNickName() + " = " + getName() + ": ");
|
||||
|
||||
for (client_it it = _clients.begin(); it != _clients.end(); ++it)
|
||||
{
|
||||
clientlist += const_cast<unstd::SharedPtr<irc::Client>&>(*it)->getNickName() + ' ';
|
||||
}
|
||||
client->sendModular("%s", clientlist.c_str());
|
||||
client->sendModular("%s %s %s : End of names list", RPL_ENDOFNAMES, client->getNickName().c_str(), getName().c_str());
|
||||
}
|
||||
|
||||
void Channel::handleMessage(const std::string& msg, unstd::SharedPtr<Client> client, bool notice) const
|
||||
{
|
||||
const std::string sender = client ? client->getNickName() : "";
|
||||
@@ -189,6 +203,8 @@ namespace irc
|
||||
}
|
||||
for(client_it it = _clients.begin(); it != _clients.end(); ++it)
|
||||
const_cast<unstd::SharedPtr<irc::Client>&>(*it)->sendMsg(op->getNickName(), "KICK " + _name + ' ' + target->getNickName(), reason);
|
||||
if (isOp(target))
|
||||
_operators.erase(target);
|
||||
_clients.erase(target);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/21 10:35:52 by maldavid #+# #+# */
|
||||
/* Updated: 2024/01/24 18:42:31 by vvaas ### ########.fr */
|
||||
/* Updated: 2024/01/25 20:24:16 by vvaas ### ########.fr */
|
||||
/* */
|
||||
/******************************************************************************/
|
||||
|
||||
@@ -28,13 +28,14 @@ namespace irc
|
||||
void Client::sendCode(const std::string& code, const std::string& msg)
|
||||
{
|
||||
const std::string command = code + " :" + msg;
|
||||
//logs::report(log_message, "C<-%s", command.c_str());
|
||||
logs::report(log_message, "C<-%s", command.c_str());
|
||||
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::sendPlainText(const std::string& str)
|
||||
{
|
||||
logs::report(log_message,"<- S %s", str.c_str());
|
||||
if(send(_fd, str.c_str(), str.length(), 0) != static_cast<ssize_t>(str.length()))
|
||||
logs::report(log_error, "server failed to send a message to '%s' (:sadge:)", _username.c_str());
|
||||
}
|
||||
@@ -42,7 +43,7 @@ namespace irc
|
||||
void Client::sendMsg(const std::string& sender, const std::string& cmd, const std::string& trailing)
|
||||
{
|
||||
const std::string out = ':' + sender + ' ' + cmd + " :" + trailing + "\r\n";
|
||||
//logs::report(log_message,"<- S %s", out.c_str());
|
||||
logs::report(log_message,"<- S %s", out.c_str());
|
||||
if(send(_fd, out.c_str(), out.length(), 0) != static_cast<ssize_t>(out.length()))
|
||||
logs::report(log_error, "server failed to send a message from '%s' to '%s' (:sadge:)", sender.c_str(), _username.c_str());
|
||||
}
|
||||
@@ -56,6 +57,7 @@ namespace irc
|
||||
vsnprintf(buffer, LOGS_BUFFER_SIZE, message.c_str(), al);
|
||||
va_end(al);
|
||||
|
||||
logs::report(log_message,"<- S %s", buffer);
|
||||
if (send(_fd, buffer, std::strlen(buffer), 0) < static_cast<ssize_t>(std::strlen(buffer)))
|
||||
logs::report(log_error, "server failed to send a message to '%s'", _nickname.c_str());
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/21 09:31:17 by maldavid #+# #+# */
|
||||
/* Updated: 2024/01/25 18:32:27 by vvaas ### ########.fr */
|
||||
/* Updated: 2024/01/25 18:40:10 by vvaas ### ########.fr */
|
||||
/* */
|
||||
/******************************************************************************/
|
||||
|
||||
@@ -143,6 +143,8 @@ namespace irc
|
||||
return true;
|
||||
else if(msg.getCmd() == "QUIT")
|
||||
handleQuit(client, msg);
|
||||
else if(msg.getCmd() == "WHO")
|
||||
handleWho(client, msg);
|
||||
else if(msg.getCmd() == "PART")
|
||||
handlePart(client, msg);
|
||||
else if(msg.getCmd() == "JOIN")
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/22 17:31:06 by maldavid #+# #+# */
|
||||
/* Updated: 2024/01/25 18:15:16 by maldavid ### ########.fr */
|
||||
/* Updated: 2024/01/25 20:28:19 by vvaas ### ########.fr */
|
||||
/* */
|
||||
/******************************************************************************/
|
||||
|
||||
@@ -344,6 +344,17 @@ namespace irc
|
||||
}
|
||||
}
|
||||
|
||||
void Server::handleWho(unstd::SharedPtr<class Client> client, const class Message& msg)
|
||||
{
|
||||
irc::Channel *chan;
|
||||
|
||||
logs::report(log_message, "tokensize ok : %d", msg.getTokens().size());
|
||||
if (msg.getTokens().size() != 2)
|
||||
return;
|
||||
if ((chan = getChannelByName(msg.getTokens()[1])) == NULL)
|
||||
client->sendCode(ERR_NOSUCHCHANNEL, "No such channel");
|
||||
chan->sendWho(client);
|
||||
}
|
||||
void Server::handleTopic(unstd::SharedPtr<class Client> client, const Message& msg)
|
||||
{
|
||||
(void)client;
|
||||
|
||||
Reference in New Issue
Block a user