gg
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/21 10:36:21 by maldavid #+# #+# */
|
||||
/* Updated: 2024/01/25 21:21:12 by maldavid ### ########.fr */
|
||||
/* Updated: 2024/01/25 21:46:29 by vvaas ### ########.fr */
|
||||
/* */
|
||||
/******************************************************************************/
|
||||
|
||||
@@ -72,14 +72,15 @@ namespace irc
|
||||
|
||||
void Channel::sendWho(unstd::SharedPtr<Client> client)
|
||||
{
|
||||
std::string clientlist(RPL_NAMREPLY " " + client->getNickName() + " = " + getName() + ": ");
|
||||
std::string clientlist(":yipirc " 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());
|
||||
logs::report(log_message, "%s", clientlist.c_str());
|
||||
client->sendModular("%s\r\n", clientlist.c_str());
|
||||
client->sendModular("%s %s %s : End of names list\r\n", RPL_ENDOFNAMES, client->getNickName().c_str(), getName().c_str());
|
||||
}
|
||||
|
||||
void Channel::handleMessage(const std::string& msg, unstd::SharedPtr<Client> client, bool notice) const
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/21 10:35:52 by maldavid #+# #+# */
|
||||
/* Updated: 2024/01/25 21:22:34 by maldavid ### ########.fr */
|
||||
/* Updated: 2024/01/25 21:55:14 by vvaas ### ########.fr */
|
||||
/* */
|
||||
/******************************************************************************/
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include <cstring>
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
#include <vector>
|
||||
|
||||
namespace irc
|
||||
{
|
||||
@@ -27,7 +28,7 @@ namespace irc
|
||||
|
||||
void Client::sendCode(const std::string& code, const std::string& msg)
|
||||
{
|
||||
const std::string command = code + " :" + msg + "\r\n";
|
||||
const std::string command = ":yipirc " + code + " : " + msg + "\r";
|
||||
#ifdef DEBUG
|
||||
logs::report(log_message, "sending '%s'", command.c_str());
|
||||
#endif
|
||||
@@ -56,15 +57,30 @@ namespace irc
|
||||
|
||||
void Client::sendModular(std::string message, ...)
|
||||
{
|
||||
char buffer[LOGS_BUFFER_SIZE];
|
||||
std::string buffer;
|
||||
|
||||
va_list al;
|
||||
va_list al_copy;
|
||||
|
||||
va_start(al, message);
|
||||
vsnprintf(buffer, LOGS_BUFFER_SIZE, message.c_str(), al);
|
||||
__builtin_va_copy(al_copy, al);
|
||||
|
||||
int len = vsnprintf(NULL, 0, message.c_str(), al);
|
||||
|
||||
if(len > 0)
|
||||
{
|
||||
std::vector<char> tmp(len + 1);
|
||||
vsnprintf(&tmp[0], tmp.size(), message.c_str(), al_copy);
|
||||
buffer = std::string(&tmp[0], len);
|
||||
buffer += "\r";
|
||||
}
|
||||
va_end(al_copy);
|
||||
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)))
|
||||
#ifdef DEBUG
|
||||
logs::report(log_message,"sending '%s'", buffer.c_str());
|
||||
#endif
|
||||
if (send(_fd, buffer.c_str(), buffer.length(), 0) < static_cast<ssize_t>(buffer.length()))
|
||||
logs::report(log_error, "server failed to send a message to '%s'", _nickname.c_str());
|
||||
}
|
||||
void Client::printUserHeader() const
|
||||
|
||||
Reference in New Issue
Block a user