This commit is contained in:
Kbz-8
2024-01-23 13:16:52 +01:00
parent 2cda614d92
commit 8042d3db6f
11 changed files with 93 additions and 44 deletions

View File

@@ -6,7 +6,7 @@
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/21 10:35:52 by maldavid #+# #+# */
/* Updated: 2024/01/22 20:52:52 by vvaas ### ########.fr */
/* Updated: 2024/01/23 12:38:15 by maldavid ### ########.fr */
/* */
/******************************************************************************/
@@ -20,17 +20,25 @@ namespace irc
{
Client::Client(int fd, sockaddr_in sock, int id) : _s_data(sock), _fd(fd), _id(id) {}
void Client::sendCode(const std::string& code, const std::string &msg)
void Client::sendCode(const std::string& code, const std::string& msg)
{
const std::string command = code + " :" + msg;
send(_fd, command.c_str(), command.size(), 0);
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::sendMsg(const std::string& sender, const std::string& cmd, const std::string& trailing)
{
const std::string out = ':' + sender + ' ' + cmd + " :" + trailing + "\r\n";
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());
}
void Client::printUserHeader() const
{
std::cout << AnsiColor::green << "[User " << _id;
if(!_realname.empty())
std::cout << " " << _realname;
std::cout << " {realname " << _realname << '}';
if(!_username.empty())
std::cout << " {username " << _username << "}";
if(!_nickname.empty())