caca
This commit is contained in:
57
.vscode/settings.json
vendored
Normal file
57
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"array": "cpp",
|
||||
"atomic": "cpp",
|
||||
"bit": "cpp",
|
||||
"*.tcc": "cpp",
|
||||
"cctype": "cpp",
|
||||
"clocale": "cpp",
|
||||
"cmath": "cpp",
|
||||
"compare": "cpp",
|
||||
"concepts": "cpp",
|
||||
"csignal": "cpp",
|
||||
"cstdarg": "cpp",
|
||||
"cstddef": "cpp",
|
||||
"cstdint": "cpp",
|
||||
"cstdio": "cpp",
|
||||
"cstdlib": "cpp",
|
||||
"cstring": "cpp",
|
||||
"cwchar": "cpp",
|
||||
"cwctype": "cpp",
|
||||
"deque": "cpp",
|
||||
"map": "cpp",
|
||||
"set": "cpp",
|
||||
"unordered_map": "cpp",
|
||||
"vector": "cpp",
|
||||
"exception": "cpp",
|
||||
"algorithm": "cpp",
|
||||
"functional": "cpp",
|
||||
"iterator": "cpp",
|
||||
"memory": "cpp",
|
||||
"memory_resource": "cpp",
|
||||
"numeric": "cpp",
|
||||
"optional": "cpp",
|
||||
"random": "cpp",
|
||||
"string": "cpp",
|
||||
"string_view": "cpp",
|
||||
"system_error": "cpp",
|
||||
"tuple": "cpp",
|
||||
"type_traits": "cpp",
|
||||
"utility": "cpp",
|
||||
"initializer_list": "cpp",
|
||||
"iosfwd": "cpp",
|
||||
"iostream": "cpp",
|
||||
"istream": "cpp",
|
||||
"limits": "cpp",
|
||||
"new": "cpp",
|
||||
"numbers": "cpp",
|
||||
"ostream": "cpp",
|
||||
"ranges": "cpp",
|
||||
"span": "cpp",
|
||||
"sstream": "cpp",
|
||||
"stdexcept": "cpp",
|
||||
"streambuf": "cpp",
|
||||
"cinttypes": "cpp",
|
||||
"typeinfo": "cpp"
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/21 10:33:17 by maldavid #+# #+# */
|
||||
/* Updated: 2024/01/24 15:00:39 by maldavid ### ########.fr */
|
||||
/* Updated: 2024/01/24 18:34:36 by vvaas ### ########.fr */
|
||||
/* */
|
||||
/******************************************************************************/
|
||||
|
||||
@@ -53,6 +53,7 @@ namespace irc
|
||||
void sendPlainText(const std::string& str);
|
||||
void sendCode(const std::string& code, const std::string& msg);
|
||||
void sendMsg(const std::string& sender, const std::string& cmd, const std::string& trailing);
|
||||
void sendModular(std::string message, ...);
|
||||
|
||||
~Client();
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
#define ERR_NEEDMOREPARAMS "461"
|
||||
#define ERR_ALREADYREGISTRED "462", "Unauthorized command (already registered)"
|
||||
#define ERR_NOPERMFORHOST "463"
|
||||
#define ERR_PASSWDMISMATCH "464", "Password incorrect"
|
||||
#define ERR_PASSWDMISMATCH "464", "Password incorrect\n"
|
||||
#define ERR_YOUREBANNEDCREEP "465"
|
||||
#define ERR_YOUWILLBEBANNED "466"
|
||||
#define ERR_KEYSET "467"
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/21 10:35:52 by maldavid #+# #+# */
|
||||
/* Updated: 2024/01/24 15:01:44 by maldavid ### ########.fr */
|
||||
/* Updated: 2024/01/24 18:42:31 by vvaas ### ########.fr */
|
||||
/* */
|
||||
/******************************************************************************/
|
||||
|
||||
@@ -15,6 +15,11 @@
|
||||
#include <iostream>
|
||||
#include <logs.hpp>
|
||||
#include <irc.hpp>
|
||||
#include <config.hpp>
|
||||
#include <cstdarg>
|
||||
#include <cstring>
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
|
||||
namespace irc
|
||||
{
|
||||
@@ -42,6 +47,18 @@ namespace irc
|
||||
logs::report(log_error, "server failed to send a message from '%s' to '%s' (:sadge:)", sender.c_str(), _username.c_str());
|
||||
}
|
||||
|
||||
void Client::sendModular(std::string message, ...)
|
||||
{
|
||||
char buffer[LOGS_BUFFER_SIZE];
|
||||
|
||||
va_list al;
|
||||
va_start(al, message);
|
||||
vsnprintf(buffer, LOGS_BUFFER_SIZE, message.c_str(), al);
|
||||
va_end(al);
|
||||
|
||||
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());
|
||||
}
|
||||
void Client::printUserHeader() const
|
||||
{
|
||||
std::cout << AnsiColor::green << "[User " << _id;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/21 09:31:17 by maldavid #+# #+# */
|
||||
/* Updated: 2024/01/24 15:14:19 by maldavid ### ########.fr */
|
||||
/* Updated: 2024/01/24 19:06:59 by vvaas ### ########.fr */
|
||||
/* */
|
||||
/******************************************************************************/
|
||||
|
||||
@@ -70,7 +70,7 @@ namespace irc
|
||||
while(recv((*it)->getFD(), buffer, INPUT_SIZE, 0) > 0) // read() but for socket fd
|
||||
{
|
||||
(*it)->newMsgInFlight(buffer);
|
||||
//std::cout << buffer << std::endl;
|
||||
std::cout << buffer << std::endl;
|
||||
while(handleMessage(*it));
|
||||
std::memset(buffer, 0, sizeof(buffer)); // clear the buffer to avoid trash remaining
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/22 17:31:06 by maldavid #+# #+# */
|
||||
/* Updated: 2024/01/24 15:35:06 by maldavid ### ########.fr */
|
||||
/* Updated: 2024/01/24 19:23:56 by vvaas ### ########.fr */
|
||||
/* */
|
||||
/******************************************************************************/
|
||||
|
||||
@@ -76,7 +76,8 @@ namespace irc
|
||||
if(msg.getTokens()[1] == _password)
|
||||
{
|
||||
client->login();
|
||||
client->sendCode(RPL_WELCOME, "Welcome :)\n");
|
||||
client->sendCode(RPL_WELCOME, "\n");
|
||||
client->sendPlainText("Welcome to yipiirc :)\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -177,6 +178,28 @@ namespace irc
|
||||
return;
|
||||
}
|
||||
channel_it it;
|
||||
if (msg.getTokens()[1][0] != '&' && msg.getTokens()[1][0] != '#')
|
||||
{
|
||||
for (client_it itc = _client.begin(); itc != _client.end(); ++itc)
|
||||
{
|
||||
if ((*itc)->getNickName() == msg.getTokens()[1] && (*itc)->getNickName() != client->getNickName())
|
||||
{
|
||||
std::string complete_msg;
|
||||
if(msg.getTokens().size() > 2)
|
||||
{
|
||||
for(std::vector<std::string>::const_iterator tit = msg.getTokens().begin() + 2; tit < msg.getTokens().end(); ++tit)
|
||||
{
|
||||
complete_msg.append(*tit);
|
||||
complete_msg.append(" ");
|
||||
}
|
||||
complete_msg.erase(complete_msg.begin());
|
||||
}
|
||||
(*itc)->sendMsg(client->getNickName(), "PRIVMSG " + (*itc)->getNickName(), complete_msg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ;
|
||||
}
|
||||
for(it = _channels.begin(); it != _channels.end(); ++it)
|
||||
{
|
||||
if(msg.getTokens()[1] == it->getName())
|
||||
|
||||
Reference in New Issue
Block a user