This commit is contained in:
2024-01-30 17:15:10 +01:00
parent 640b2991c8
commit 65557cc1c0
7 changed files with 69 additions and 57 deletions

1
.gitignore vendored
View File

@@ -21,3 +21,4 @@ ircserv
.vscode/ .vscode/
objs_bonus/ objs_bonus/
greg greg
ft_irc-tester/

View File

@@ -1,12 +1,12 @@
/******************************************************************************/ /******************************************************************************/
/* */ /* */
/* ::: :::::::: */ /* ::: :::::::: */
/* Bot.hpp :+: :+: :+: */ /* bot.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/30 01:54:36 by vvaas #+# #+# */ /* Created: 2024/01/30 01:54:36 by vvaas #+# #+# */
/* Updated: 2024/01/30 02:39:52 by vvaas ### ########.fr */ /* Updated: 2024/01/30 16:56:57 by vvaas ### ########.fr */
/* */ /* */
/******************************************************************************/ /******************************************************************************/
@@ -24,6 +24,7 @@ class bot
bot(); bot();
void init(void); void init(void);
void connect_to_server(void); void connect_to_server(void);
void handle_response(std::string buffer);
~bot(); ~bot();
private : private :
struct sockaddr_in _serv_addr; struct sockaddr_in _serv_addr;

View File

@@ -6,7 +6,7 @@
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/21 10:33:17 by maldavid #+# #+# */ /* Created: 2024/01/21 10:33:17 by maldavid #+# #+# */
/* Updated: 2024/01/30 01:45:23 by vvaas ### ########.fr */ /* Updated: 2024/01/30 17:06:21 by vvaas ### ########.fr */
/* */ /* */
/******************************************************************************/ /******************************************************************************/
@@ -17,6 +17,7 @@
#include <string> #include <string>
#include <set> #include <set>
#include <errorscode.hpp> #include <errorscode.hpp>
#include <logs.hpp>
namespace irc namespace irc
{ {
@@ -40,7 +41,7 @@ namespace irc
inline void login() { _logged = true; } inline void login() { _logged = true; }
inline void register_user() { _registered = true; } inline void register_user() { _registered = true; }
inline void welcome() { if (isLogged() && !isWelcomed()) return ; _welcomed = true; sendCode(RPL_WELCOME, "Welcome to yipirc :), " + _nickname); } inline void welcome() { if (!isLogged() || isWelcomed() || _nickname.empty()) return ; _welcomed = true; sendCode(RPL_WELCOME, "Welcome to yipirc :), " + _nickname); }
inline void requireDisconnect() { _disconnect_required = true; } inline void requireDisconnect() { _disconnect_required = true; }
inline bool isLogged() const { return _logged; } inline bool isLogged() const { return _logged; }

View File

@@ -1,14 +1,14 @@
/* ************************************************************************** */ /******************************************************************************/
/* */ /* */
/* ::: :::::::: */ /* ::: :::::::: */
/* logs.cpp :+: :+: :+: */ /* logs.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */ /* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/21 09:17:47 by maldavid #+# #+# */ /* Created: 2024/01/21 09:17:47 by maldavid #+# #+# */
/* Updated: 2024/01/30 00:38:44 by maldavid ### ########.fr */ /* Updated: 2024/01/30 17:07:07 by vvaas ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /******************************************************************************/
#include <logs.hpp> #include <logs.hpp>
#include <ansi.hpp> #include <ansi.hpp>

View File

@@ -6,7 +6,7 @@
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/21 09:31:17 by maldavid #+# #+# */ /* Created: 2024/01/21 09:31:17 by maldavid #+# #+# */
/* Updated: 2024/01/30 02:41:02 by vvaas ### ########.fr */ /* Updated: 2024/01/30 17:15:03 by vvaas ### ########.fr */
/* */ /* */
/******************************************************************************/ /******************************************************************************/

View File

@@ -6,7 +6,7 @@
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/22 17:31:06 by maldavid #+# #+# */ /* Created: 2024/01/22 17:31:06 by maldavid #+# #+# */
/* Updated: 2024/01/30 02:32:17 by vvaas ### ########.fr */ /* Updated: 2024/01/30 16:59:42 by vvaas ### ########.fr */
/* */ /* */
/******************************************************************************/ /******************************************************************************/
@@ -62,7 +62,6 @@ namespace irc
client->setNewNickName(msg.getTokens()[1]); client->setNewNickName(msg.getTokens()[1]);
for (client_it it = _client.begin(); it != _client.end(); ++it) for (client_it it = _client.begin(); it != _client.end(); ++it)
(*it)->sendMsg(oldNick, "NICK", msg.getTokens()[1]); (*it)->sendMsg(oldNick, "NICK", msg.getTokens()[1]);
std::string welcome_msg = "Welcome to yipirc :), " + client->getNickName();
client->welcome(); client->welcome();
std::cout << "new nickname, " << client->getNickName() << std::endl; std::cout << "new nickname, " << client->getNickName() << std::endl;
} }
@@ -103,7 +102,6 @@ namespace irc
void Server::handlePass(unstd::SharedPtr<class Client> client, const Message& msg) void Server::handlePass(unstd::SharedPtr<class Client> client, const Message& msg)
{ {
std::string welcome_msg = "Welcome to yipirc :), " + client->getNickName();
if(client->isLogged()) if(client->isLogged())
return; return;
if(msg.getTokens()[1] == _password) if(msg.getTokens()[1] == _password)

View File

@@ -6,7 +6,7 @@
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/30 01:54:56 by vvaas #+# #+# */ /* Created: 2024/01/30 01:54:56 by vvaas #+# #+# */
/* Updated: 2024/01/30 02:41:49 by vvaas ### ########.fr */ /* Updated: 2024/01/30 17:07:02 by vvaas ### ########.fr */
/* */ /* */
/******************************************************************************/ /******************************************************************************/
@@ -14,7 +14,9 @@
#include <logs.hpp> #include <logs.hpp>
#include <string> #include <string>
#include <iostream> #include <iostream>
#include <errno.h> #include <unistd.h>
#include <fcntl.h>
#include <cstring>
bot::bot() {} bot::bot() {}
@@ -33,6 +35,14 @@ void bot::init()
_serv_addr.sin_addr.s_addr = inet_addr(IP); _serv_addr.sin_addr.s_addr = inet_addr(IP);
if (connect(_fd, (struct sockaddr*)&_serv_addr, sizeof(_serv_addr)) < 0) if (connect(_fd, (struct sockaddr*)&_serv_addr, sizeof(_serv_addr)) < 0)
irc::logs::report(irc::log_fatal_error, "connect error"); irc::logs::report(irc::log_fatal_error, "connect error");
if(fcntl(_fd, F_SETFL, O_NONBLOCK) < 0)
irc::logs::report(irc::log_fatal_error, "fcntl() error");
}
void bot::handle_response(std::string buffer)
{
if (buffer == ":yipirc 001 greg :Welcome to yipirc :), greg\r\n")
return ;
} }
void bot::connect_to_server() void bot::connect_to_server()
@@ -45,7 +55,8 @@ void bot::connect_to_server()
} }
while (true) while (true)
{ {
while (recv(_fd, buffer, 1024, 0) < 0) if (recv(_fd, buffer, 1024, 0) > 0)
std::cout << buffer << std::endl; handle_response(buffer);
std::memset(buffer, 0, sizeof(buffer));
} }
} }